Completed
Branch BUG-10626-dst-unit-test (cc62a6)
by
unknown
37:15 queued 23:58
created
core/libraries/messages/EE_Message_Resource_Manager.lib.php 2 patches
Indentation   +1112 added lines, -1112 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,1117 +17,1117 @@  discard block
 block discarded – undo
17 17
 class EE_Message_Resource_Manager
18 18
 {
19 19
 
20
-    /**
21
-     * This option in the database is used to keep a record of message types that have been activated for a messenger
22
-     * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
23
-     * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
24
-     * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
25
-     * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
26
-     * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
27
-     * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
28
-     * automated process (when an add-on registering the message type deactivates, or when some other code calls the
29
-     * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
30
-     * the "force" flag is respected if that message type is later re-registered.
31
-     *
32
-     * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
33
-     *
34
-     * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
35
-     * option that got superseded by later behaviour requirements.
36
-     */
37
-    const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
38
-
39
-    /**
40
-     * @type boolean $_initialized
41
-     */
42
-    protected $_initialized = false;
43
-
44
-    /**
45
-     * @type EE_Messenger_Collection $_messenger_collection_loader
46
-     */
47
-    protected $_messenger_collection_loader;
48
-
49
-    /**
50
-     * @type EE_Message_Type_Collection $_message_type_collection_loader
51
-     */
52
-    protected $_message_type_collection_loader;
53
-
54
-    /**
55
-     * @type EEM_Message_Template_Group $_message_template_group_model
56
-     */
57
-    protected $_message_template_group_model;
58
-
59
-    /**
60
-     * @type EE_messenger[]
61
-     */
62
-    protected $_installed_messengers = array();
63
-
64
-    /**
65
-     * @type EE_message_type[]
66
-     */
67
-    protected $_installed_message_types = array();
68
-
69
-    /**
70
-     * Array of active messengers.
71
-     * Format is this:
72
-     * array(
73
-     *      'messenger_name' => EE_messenger
74
-     * )
75
-     *
76
-     * @type EE_messenger[]
77
-     */
78
-    protected $_active_messengers = array();
79
-
80
-    /**
81
-     * Formatted array of active message types grouped per messenger.
82
-     * Format is this:
83
-     * array(
84
-     *      'messenger_name' => array(
85
-     *          'settings' => array(
86
-     *              '{messenger_name}-message_types' => array(
87
-     *                  'message_type_name' => array() //variable array of settings corresponding to message type.
88
-     *              )
89
-     *          )
90
-     *      )
91
-     * )
92
-     *
93
-     * @type array
94
-     */
95
-    protected $_active_message_types = array();
96
-
97
-
98
-    /**
99
-     * This holds the array of messengers and their corresponding message types that have
100
-     * been activated on a site at some point.  This is an important record that helps the messages system
101
-     * not accidentally reactivate something that was intentionally deactivated by a user.
102
-     *
103
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
104
-     *
105
-     * @type array
106
-     */
107
-    protected $_has_activated_messengers_and_message_types = array();
108
-
109
-    /**
110
-     * An array of unique message type contexts across all active message types.
111
-     * The array will be indexed by either 'slugs' or 'all'.
112
-     * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
113
-     * slug. array(
114
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
115
-     * );
116
-     * The all index returns an array in this format:
117
-     * array(
118
-     *      'message_type_name' => array(
119
-     *          'context_slug' => array(
120
-     *              'label' => 'localized label for context',
121
-     *              'description' => 'localized description for context'
122
-     *          )
123
-     *      )
124
-     * );
125
-     *
126
-     * @type array
127
-     */
128
-    protected $_contexts = array();
129
-
130
-
131
-    /**
132
-     * EE_Message_Resource_Manager constructor.
133
-     *
134
-     * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
135
-     * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
136
-     * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
137
-     */
138
-    function __construct(
139
-        EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
140
-        EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
141
-        EEM_Message_Template_Group $Message_Template_Group_Model
142
-    ) {
143
-        $this->_messenger_collection_loader    = $Messenger_Collection_Loader;
144
-        $this->_message_type_collection_loader = $Message_Type_Collection_Loader;
145
-        $this->_message_template_group_model   = $Message_Template_Group_Model;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return void
151
-     */
152
-    protected function _initialize_collections()
153
-    {
154
-        if ($this->_initialized) {
155
-            return;
156
-        }
157
-        $this->_initialized = true;
158
-        $this->_messenger_collection_loader->load_messengers_from_folder();
159
-        $this->_message_type_collection_loader->load_message_types_from_folder();
160
-        $this->get_has_activated_messengers_option(true);
161
-        $this->_set_active_messengers_and_message_types();
162
-    }
163
-
164
-
165
-    /**
166
-     * @return EE_Messenger_Collection
167
-     */
168
-    public function messenger_collection()
169
-    {
170
-        $this->_initialize_collections();
171
-        return $this->_messenger_collection_loader->messenger_collection();
172
-    }
173
-
174
-
175
-    /**
176
-     * @return EE_messenger[]
177
-     */
178
-    public function active_messengers()
179
-    {
180
-        $this->_initialize_collections();
181
-        return $this->_active_messengers;
182
-    }
183
-
184
-
185
-    /**
186
-     * @param string $messenger_name
187
-     * @return \EE_messenger
188
-     */
189
-    public function get_messenger($messenger_name)
190
-    {
191
-        return $this->messenger_collection()->get_by_info($messenger_name);
192
-    }
193
-
194
-
195
-    /**
196
-     * This returns the corresponding EE_messenger object for the given string if it is active.
197
-     *
198
-     * @param string $messenger
199
-     * @return EE_messenger | null
200
-     */
201
-    public function get_active_messenger($messenger)
202
-    {
203
-        $this->_initialize_collections();
204
-        return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
205
-    }
206
-
207
-
208
-    /**
209
-     * @return \EE_messenger[]
210
-     */
211
-    public function installed_messengers()
212
-    {
213
-        if (empty($this->_installed_messengers)) {
214
-            $this->_installed_messengers = array();
215
-            $this->messenger_collection()->rewind();
216
-            while ($this->messenger_collection()->valid()) {
217
-                $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
218
-                $this->messenger_collection()->next();
219
-            }
220
-        }
221
-        return $this->_installed_messengers;
222
-    }
223
-
224
-
225
-    /**
226
-     * @param string $messenger_name
227
-     * @return \EE_messenger
228
-     * @throws \EE_Error
229
-     */
230
-    public function valid_messenger($messenger_name)
231
-    {
232
-        $messenger = $this->get_messenger($messenger_name);
233
-        if ($messenger instanceof EE_messenger) {
234
-            return $messenger;
235
-        }
236
-        throw new EE_Error(
237
-            sprintf(
238
-                __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
239
-                $messenger_name
240
-            )
241
-        );
242
-    }
243
-
244
-
245
-    /**
246
-     * @return EE_Message_Type_Collection
247
-     */
248
-    public function message_type_collection()
249
-    {
250
-        $this->_initialize_collections();
251
-        return $this->_message_type_collection_loader->message_type_collection();
252
-    }
253
-
254
-
255
-    /**
256
-     * @return array
257
-     */
258
-    public function active_message_types()
259
-    {
260
-        $this->_initialize_collections();
261
-        return $this->_active_message_types;
262
-    }
263
-
264
-
265
-    /**
266
-     * @param string $message_type_name
267
-     * @return \EE_message_type
268
-     */
269
-    public function get_message_type($message_type_name)
270
-    {
271
-        return $this->message_type_collection()->get_by_info($message_type_name);
272
-    }
273
-
274
-
275
-    /**
276
-     * This returns the EE_message_type from the active message types array ( if present );
277
-     *
278
-     * @param string $messenger_name
279
-     * @param string $message_type_name
280
-     * @return \EE_message_type|null
281
-     */
282
-    public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
283
-    {
284
-        return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
285
-            ? $this->get_message_type($message_type_name)
286
-            : null;
287
-    }
288
-
289
-
290
-    /**
291
-     * Returns whether the given message type is active for the given messenger.
292
-     *
293
-     * @param string $messenger_name
294
-     * @param string $message_type_name
295
-     * @return bool
296
-     */
297
-    public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298
-    {
299
-        $this->_initialize_collections();
300
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
301
-    }
302
-
303
-
304
-    /**
305
-     * Returns whether the given messenger is active.
306
-     *
307
-     * @param string $messenger_name the name of the messenger to check if active.
308
-     * @return bool
309
-     */
310
-    public function is_messenger_active($messenger_name)
311
-    {
312
-        $this->_initialize_collections();
313
-        return ! empty($this->_active_message_types[$messenger_name]);
314
-    }
315
-
316
-
317
-    /**
318
-     * This returns any settings that might be on a message type for a messenger
319
-     *
320
-     * @param string $messenger_name    The slug of the messenger
321
-     * @param string $message_type_name The slug of the message type getting the settings for.
322
-     * @return array
323
-     */
324
-    public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
325
-    {
326
-        $settings = array();
327
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
330
-                : array();
331
-        }
332
-        return $settings;
333
-    }
334
-
335
-
336
-    /**
337
-     * Returns whether the given messenger name has active message types on it.
338
-     * Infers whether the messenger is active or not as well.
339
-     *
340
-     * @param string $messenger_name
341
-     * @return bool
342
-     */
343
-    public function messenger_has_active_message_types($messenger_name)
344
-    {
345
-        $this->_initialize_collections();
346
-        return
347
-            ! empty($this->_active_message_types[$messenger_name])
348
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
349
-    }
350
-
351
-
352
-    /**
353
-     * This checks the _active_message_types property for any active message types
354
-     * that are present for the given messenger and returns them.
355
-     *
356
-     * @since 4.9.0
357
-     * @param string $messenger_name The messenger being checked
358
-     * @return EE_message_type[]|array    (empty array if no active_message_types)
359
-     */
360
-    public function get_active_message_types_for_messenger($messenger_name)
361
-    {
362
-        $message_types = array();
363
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
364
-            return $message_types;
365
-        }
366
-        $installed_message_types = $this->installed_message_types();
367
-        foreach ($installed_message_types as $message_type_name => $message_type) {
368
-            if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
369
-                $message_types[$message_type_name] = $message_type;
370
-            }
371
-        }
372
-        return $message_types;
373
-    }
374
-
375
-
376
-    /**
377
-     * This does NOT return the _active_message_types property but
378
-     * simply returns an array of active message type names from that property.
379
-     * (The _active_message_types property is indexed by messenger and active message_types per messenger).
380
-     *
381
-     * @return array message_type references (string)
382
-     */
383
-    public function list_of_active_message_types()
384
-    {
385
-        $active_message_type_names = array();
386
-        $this->_initialize_collections();
387
-        foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
389
-                continue;
390
-            }
391
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
-                if (! in_array($message_type_name, $active_message_type_names)) {
393
-                    $active_message_type_names[] = $message_type_name;
394
-                }
395
-            }
396
-        }
397
-        return $active_message_type_names;
398
-    }
399
-
400
-
401
-    /**
402
-     * Same as list_of_active_message_types() except this returns actual EE_message_type objects
403
-     *
404
-     * @since 4.9.0
405
-     * @return \EE_message_type[]
406
-     */
407
-    public function get_active_message_type_objects()
408
-    {
409
-        $active_message_types      = array();
410
-        $installed_message_types   = $this->installed_message_types();
411
-        $active_message_type_names = $this->list_of_active_message_types();
412
-        foreach ($active_message_type_names as $active_message_type_name) {
413
-            if (isset($installed_message_types[$active_message_type_name])) {
414
-                $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
415
-            }
416
-        }
417
-        return $active_message_types;
418
-    }
419
-
420
-
421
-    /**
422
-     * @return \EE_message_type[]
423
-     */
424
-    public function installed_message_types()
425
-    {
426
-        if (empty($this->_installed_message_types)) {
427
-            $this->message_type_collection()->rewind();
428
-            while ($this->message_type_collection()->valid()) {
429
-                $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
430
-                $this->message_type_collection()->next();
431
-            }
432
-        }
433
-        return $this->_installed_message_types;
434
-    }
435
-
436
-
437
-    /**
438
-     * @param string $message_type_name
439
-     * @return \EE_message_type
440
-     * @throws \EE_Error
441
-     */
442
-    public function valid_message_type($message_type_name)
443
-    {
444
-        $message_type = $this->get_message_type($message_type_name);
445
-        if ($message_type instanceof EE_message_type) {
446
-            return $message_type;
447
-        }
448
-        throw new EE_Error(
449
-            sprintf(
450
-                __('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
451
-                $message_type_name
452
-            )
453
-        );
454
-    }
455
-
456
-
457
-    /**
458
-     * valid_message_type_for_messenger
459
-     *
460
-     * @param EE_messenger $messenger
461
-     * @param string       $message_type_name
462
-     * @return boolean
463
-     * @throws \EE_Error
464
-     */
465
-    public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466
-    {
467
-        $valid_message_types = $messenger->get_valid_message_types();
468
-        if (! in_array($message_type_name, $valid_message_types)) {
469
-            throw new EE_Error(
470
-                sprintf(
471
-                    __(
472
-                        'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
473
-                        'event_espresso'
474
-                    ),
475
-                    $message_type_name,
476
-                    __METHOD__,
477
-                    $messenger->name
478
-                )
479
-            );
480
-        }
481
-        return true;
482
-    }
483
-
484
-
485
-    /**
486
-     * Used to return active messengers array stored in the wp options table.
487
-     * If no value is present in the option then an empty array is returned.
488
-     *
489
-     * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
490
-     *                          property and pull directly from the db.  Otherwise whatever is currently on the
491
-     *                          $_active_message_types property is pulled.
492
-     * @return array
493
-     */
494
-    public function get_active_messengers_option($reset = false)
495
-    {
496
-        if ($reset) {
497
-            $this->_active_message_types = get_option('ee_active_messengers', array());
498
-        }
499
-        return $this->_active_message_types;
500
-    }
501
-
502
-
503
-    /**
504
-     * Used to update the active messengers array stored in the wp options table.
505
-     *
506
-     * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
507
-     *                                         representing this data is used.
508
-     * @return bool FALSE if not updated, TRUE if updated.
509
-     */
510
-    public function update_active_messengers_option($active_messenger_settings = array())
511
-    {
512
-        $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
513
-        //make sure _active_message_types is updated (this is the internal cache for the settings).
514
-        $this->_active_message_types = $active_messenger_settings;
515
-        return update_option('ee_active_messengers', $active_messenger_settings);
516
-    }
517
-
518
-
519
-    /**
520
-     * Used to return has activated message types for messengers array stored in the wp options table.
521
-     * If no value is present in the option then an empty array is returned.
522
-     * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
523
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
524
-     *
525
-     * @param   bool $reset Used to indicate that any cached value should be ignored.
526
-     * @return array
527
-     */
528
-    public function get_has_activated_messengers_option($reset = false)
529
-    {
530
-        if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
531
-            $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
532
-        }
533
-        return $this->_has_activated_messengers_and_message_types;
534
-    }
535
-
536
-
537
-    /**
538
-     * Used to update the has activated option in the db.
539
-     *
540
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
541
-     *
542
-     * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
543
-     *                                        representing this data is used.
544
-     * @return bool FALSE if not updated, TRUE if updated.
545
-     */
546
-    public function update_has_activated_messengers_option($has_activated_messengers = array())
547
-    {
548
-        //make sure the option has been retrieved from first so we don't overwrite it accidentally.
549
-        if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
550
-            $this->get_has_activated_messengers_option();
551
-        }
552
-        $has_activated_messengers = empty($has_activated_messengers)
553
-            ? $this->_has_activated_messengers_and_message_types
554
-            : $has_activated_messengers;
555
-        return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
556
-    }
557
-
558
-
559
-    /**
560
-     * wrapper for _set_active_messengers_and_message_types()
561
-     */
562
-    public function reset_active_messengers_and_message_types()
563
-    {
564
-        $this->_set_active_messengers_and_message_types();
565
-    }
566
-
567
-
568
-    /**
569
-     * Generate list of active messengers and message types from collection.
570
-     * This sets up the active messengers from what is present in the database.
571
-     */
572
-    protected function _set_active_messengers_and_message_types()
573
-    {
574
-        //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
575
-        // list of activated messengers as set via the admin
576
-        // note calling `get_active_messengers_options` also initializes the _active_message_types property.
577
-        $this->get_active_messengers_option(true);
578
-        $this->ensure_messengers_are_active(array(), false, true);
579
-        $this->update_active_messengers_option();
580
-        $this->update_has_activated_messengers_option();
581
-    }
582
-
583
-
584
-    /**
585
-     * Ensures that the specified messenger is currently active.
586
-     * If not, activates it and its default message types.
587
-     *
588
-     * @param string $messenger_name
589
-     * @param bool   $update_option Whether to update the option in the db or not.
590
-     * @return boolean true if either already active or successfully activated.
591
-     */
592
-    public function ensure_messenger_is_active($messenger_name, $update_option = true)
593
-    {
594
-        if (! isset($this->_active_messengers[$messenger_name])) {
595
-            try {
596
-                $this->activate_messenger($messenger_name, array(), $update_option);
597
-            } catch (EE_Error $e) {
598
-                EE_Error::add_error(
599
-                    $e->getMessage(),
600
-                    __FILE__,
601
-                    __FUNCTION__,
602
-                    __LINE__
603
-                );
604
-                return false;
605
-            }
606
-        }
607
-        return true;
608
-    }
609
-
610
-
611
-    /**
612
-     * This ensures the given array of messenger names is active in the system.
613
-     * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
614
-     * it will automatically activate the default message types for the messenger if its not active.
615
-     *
616
-     * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
617
-     *                                (default) then will attempt to set the active messengers from the
618
-     *                                activated_messengers option
619
-     *                                (stored in $_active_message_types property).
620
-     * @param bool  $update_option    Whether to update the related active messengers option.
621
-     * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
622
-     *                                set to true and a messenger is indicated as active, but is NOT installed, then it
623
-     *                                will automatically be deactivated.
624
-     */
625
-    public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
626
-    {
627
-        $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
628
-
629
-        $not_installed = array();
630
-        foreach ($messenger_names as $messenger_name) {
631
-            if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
632
-                $not_installed[] = $messenger_name;
633
-                $this->deactivate_messenger($messenger_name);
634
-                continue;
635
-            }
636
-            $this->ensure_messenger_is_active($messenger_name, $update_option);
637
-        }
638
-
639
-        if (! empty($not_installed)) {
640
-            EE_Error::add_error(
641
-                sprintf(
642
-                    __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
643
-                    '<br />',
644
-                    implode(', ', $not_installed)
645
-                ),
646
-                __FILE__, __FUNCTION__, __LINE__
647
-            );
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * Ensures that the specified message type for the given messenger is currently active, if not activates it.
654
-     * This ALSO ensures that the given messenger is active as well!
655
-     *
656
-     * @param string $message_type_name message type name.
657
-     * @param        $messenger_name
658
-     * @param bool   $update_option     Whether to update the option in the db or not.
659
-     * @return bool  Returns true if already is active or if was activated successfully.
660
-     * @throws \EE_Error
661
-     */
662
-    public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
663
-    {
664
-        // grab the messenger to work with.
665
-        $messenger = $this->valid_messenger($messenger_name);
666
-        if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
667
-            //ensure messenger is active (that's an inherent coupling between active message types and the
668
-            //messenger they are being activated for.
669
-            try {
670
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671
-                    //all is good so let's just get it active
672
-                    $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673
-                }
674
-            } catch (EE_Error $e) {
675
-                EE_Error::add_error(
676
-                    $e->getMessage(),
677
-                    __FILE__,
678
-                    __FUNCTION__,
679
-                    __LINE__
680
-                );
681
-                return false;
682
-            }
683
-        }
684
-        return true;
685
-    }
686
-
687
-
688
-    /**
689
-     * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
690
-     * messenger are active in one go.
691
-     *
692
-     * @param array  $message_type_names Array of message type names to ensure are active.
693
-     * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
694
-     * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
695
-     */
696
-    public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697
-    {
698
-        $message_type_names = (array)$message_type_names;
699
-        foreach ($message_type_names as $message_type_name) {
700
-            // note, intentionally not updating option here because we're in a loop.
701
-            // We'll follow the instructions of the incoming $update_option argument after the loop.
702
-            $this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
703
-        }
704
-        if ($update_option) {
705
-            $this->update_active_messengers_option();
706
-            $this->update_has_activated_messengers_option();
707
-        }
708
-    }
709
-
710
-
711
-    /**
712
-     * Activates the specified messenger.
713
-     *
714
-     * @param string $messenger_name
715
-     * @param array  $message_type_names        An array of message type names to activate with this messenger.
716
-     *                                          If included we do NOT setup the default message types
717
-     *                                          (assuming they are already setup.)
718
-     * @param bool   $update_active_messengers_option
719
-     * @return array of generated templates
720
-     * @throws \EE_Error
721
-     */
722
-    public function activate_messenger(
723
-        $messenger_name,
724
-        $message_type_names = array(),
725
-        $update_active_messengers_option = true
726
-    ) {
727
-        $templates = array();
728
-        // grab the messenger to work with.
729
-        $messenger = $this->messenger_collection()->get_by_info($messenger_name);
730
-        // it's inactive. Activate it.
731
-        if ($messenger instanceof EE_messenger) {
732
-            $this->_active_messengers[$messenger->name] = $messenger;
733
-            //activate incoming message types set to be activated with messenger.
734
-            $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
735
-            // setup any initial settings for the messenger if necessary.
736
-            $this->add_settings_for_messenger($messenger->name);
737
-            if ($update_active_messengers_option) {
738
-                $this->update_active_messengers_option();
739
-                $this->update_has_activated_messengers_option();
740
-            }
741
-            //generate new templates if necessary and ensure all related templates that are already in the database are
742
-            //marked active.  Note, this will also deactivate a message type for a messenger if the template
743
-            //cannot be successfully created during its attempt (only happens for global template attempts).
744
-            if (! empty($message_type_names)) {
745
-                $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746
-                EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747
-            }
748
-        }
749
-        return $templates;
750
-    }
751
-
752
-
753
-    /**
754
-     * Activates given message types for the given EE_messenger object.
755
-     * Note: (very important) This method does not persist the activation to the database.
756
-     * See code implementing this method in this class for examples of how to persist.
757
-     *
758
-     * @param \EE_messenger $messenger
759
-     * @param  array        $message_type_names
760
-     * @return array
761
-     */
762
-    protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
763
-    {
764
-        //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
765
-        //things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
766
-        //So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
767
-        //only override _active_message_types when an explicit array of $message_type_names has been provided.
768
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769
-            ? $messenger->get_default_message_types()
770
-            : (array)$message_type_names;
771
-
772
-        //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
-        if (! isset($this->_active_message_types[$messenger->name])) {
774
-            $this->_active_message_types[$messenger->name]['settings'] = array();
775
-        }
776
-
777
-        if ($message_type_names) {
778
-            // cycle thru message types
779
-            foreach ($message_type_names as $message_type_name) {
780
-                //only register the message type as active IF it isn't already active
781
-                //and if its actually installed.
782
-                if (
783
-                ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
784
-                ) {
785
-                    $this->add_settings_for_message_type($messenger->name, $message_type_name);
786
-                    $this->_set_messenger_has_activated_message_type(
787
-                        $messenger,
788
-                        $message_type_name
789
-                    );
790
-                }
791
-            }
792
-        }
793
-        return $message_type_names;
794
-    }
795
-
796
-
797
-    /**
798
-     * add_settings_for_message_type
799
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
800
-     * $this->update_active_messengers_option to persist.
801
-     *
802
-     * @param  string $messenger_name    The name of the messenger adding the settings for
803
-     * @param  string $message_type_name The name of the message type adding the settings for
804
-     * @param  array  $new_settings      Any new settings being set for the message type and messenger
805
-     */
806
-    public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
807
-    {
808
-        // get installed message type from collection
809
-        $message_type      = $this->message_type_collection()->get_by_info($message_type_name);
810
-        $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
811
-        //we need to setup any initial settings for message types
812
-        if ($message_type instanceof EE_message_type) {
813
-            $default_settings = $message_type->get_admin_settings_fields();
814
-            foreach ($default_settings as $field => $values) {
815
-                if (isset($new_settings[$field])) {
816
-                    $existing_settings[$field] = $new_settings[$field];
817
-                    continue;
818
-                }
819
-                if (! isset($existing_settings[$field])) {
820
-                    $existing_settings[$field] = $values['default'];
821
-                }
822
-            }
823
-        }
824
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
825
-    }
826
-
827
-
828
-    /**
829
-     * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
830
-     * and message type.
831
-     *
832
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
833
-     *
834
-     * @access protected
835
-     * @param \EE_messenger $messenger
836
-     * @param string        $message_type_name
837
-     */
838
-    protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
839
-    {
840
-
841
-        //if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
842
-        if (empty($this->_has_activated_messengers_and_message_types)) {
843
-            $this->get_has_activated_messengers_option();
844
-        }
845
-
846
-        // make sure this messenger has a record in the has_activated array
847
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
-            $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849
-        }
850
-        // check if message type has already been added
851
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852
-            $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853
-        }
854
-    }
855
-
856
-
857
-    /**
858
-     * add_settings_for_messenger
859
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
860
-     * $this->update_active_messengers_option to persist.
861
-     *
862
-     * @param string $messenger_name The name of the messenger the settings is being added for.
863
-     * @param array  $new_settings   An array of settings to update the existing settings.
864
-     */
865
-    public function add_settings_for_messenger($messenger_name, $new_settings = array())
866
-    {
867
-        $messenger = $this->get_messenger($messenger_name);
868
-        if ($messenger instanceof EE_messenger) {
869
-            $msgr_settings = $messenger->get_admin_settings_fields();
870
-            if (! empty($msgr_settings)) {
871
-                foreach ($msgr_settings as $field => $value) {
872
-                    //is there a new setting for this?
873
-                    if (isset($new_settings[$field])) {
874
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
875
-                        continue;
876
-                    }
877
-                    //only set the default if it isn't already set.
878
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880
-                    }
881
-                }
882
-            }
883
-        }
884
-    }
885
-
886
-
887
-    /**
888
-     * deactivate_messenger
889
-     *
890
-     * @param  string|EE_messenger $messenger_name name of messenger
891
-     * @return void
892
-     */
893
-    public function deactivate_messenger($messenger_name)
894
-    {
895
-        $this->_initialize_collections();
896
-        if ($messenger_name instanceof EE_messenger) {
897
-            $messenger_name = $messenger_name->name;
898
-        }
899
-        unset($this->_active_messengers[$messenger_name]);
900
-        unset($this->_active_message_types[$messenger_name]);
901
-        $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
902
-        $this->update_active_messengers_option();
903
-    }
904
-
905
-
906
-    /**
907
-     * Deactivates a message type (note this will deactivate across all messenger's it is active on.
908
-     *
909
-     * @param  string $message_type_name     name of message type being deactivated
910
-     * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
911
-     *                                       type.  However, this can be overridden if we don't want this set (usually when
912
-     *                                       this is called as a part of deregistration of a custom message type)
913
-     */
914
-    public function deactivate_message_type($message_type_name, $set_has_active_record = true)
915
-    {
916
-        $this->_initialize_collections();
917
-        if ($message_type_name instanceof EE_message_type) {
918
-            $message_type_name = $message_type_name->name;
919
-        }
920
-        foreach ($this->_active_message_types as $messenger_name => $settings) {
921
-            unset(
922
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
923
-            );
924
-
925
-            //we always record (even on deactivation) that a message type has been activated because there should at
926
-            //least be a record in the "has_activated" option that it WAS active at one point.
927
-            if ($set_has_active_record) {
928
-                $messenger = $this->get_messenger($messenger_name);
929
-                $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
930
-            }
931
-        }
932
-        $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
933
-        $this->update_active_messengers_option();
934
-        $this->update_has_activated_messengers_option();
935
-    }
936
-
937
-
938
-    /**
939
-     * Deactivates a message type for a specific messenger as opposed to all messengers.
940
-     *
941
-     * @param string $message_type_name Name of message type being deactivated.
942
-     * @param string $messenger_name    Name of messenger the message type is being deactivated for.
943
-     */
944
-    public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
945
-    {
946
-        $this->_initialize_collections();
947
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
949
-        }
950
-        $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951
-            array($message_type_name));
952
-        $this->update_active_messengers_option();
953
-    }
954
-
955
-
956
-    /**
957
-     * Used to verify if a message can be sent for the given messenger and message type
958
-     * and that it is a generating messenger (used for generating message templates).
959
-     *
960
-     * @param EE_messenger    $messenger    messenger used in trigger
961
-     * @param EE_message_type $message_type message type used in trigger
962
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
963
-     */
964
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
965
-    {
966
-        //get the $messengers the message type says it can be used with.
967
-        foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
968
-            if (
969
-                $messenger->name === $generating_messenger
970
-                && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
971
-            ) {
972
-                return true;
973
-            }
974
-        }
975
-        return false;
976
-    }
977
-
978
-
979
-    /**
980
-     * This returns all the contexts that are registered by all message types.
981
-     * If $slugs_only is true,
982
-     * then just an array indexed by unique context slugs with the latest label representation for that slug.
983
-     * array(
984
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
985
-     * );
986
-     * If $slugs_only is false, then the format is:
987
-     * array(
988
-     *      'message_type_name' => array(
989
-     *          'context_slug' => array(
990
-     *              'label' => 'localized label for context',
991
-     *              'description' => 'localized description for context'
992
-     *          )
993
-     *      )
994
-     * );
995
-     * Keep in mind that although different message types may share the same context slugs,
996
-     * it is possible that the context is described differently by the message type.
997
-     *
998
-     * @since 4.9.0
999
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1000
-     *                           or all contexts indexed by message type.
1001
-     * @return array
1002
-     */
1003
-    public function get_all_contexts($slugs_only = true)
1004
-    {
1005
-        $key = $slugs_only ? 'slugs' : 'all';
1006
-        // check if contexts has been setup yet.
1007
-        if (empty($this->_contexts[$key])) {
1008
-            // So let's get all active message type objects and loop through to get all unique contexts
1009
-            foreach ($this->get_active_message_type_objects() as $message_type) {
1010
-                if ($message_type instanceof EE_message_type) {
1011
-                    $message_type_contexts = $message_type->get_contexts();
1012
-                    if ($slugs_only) {
1013
-                        foreach ($message_type_contexts as $context => $context_details) {
1014
-                            $this->_contexts[$key][$context] = $context_details['label'];
1015
-                        }
1016
-                    } else {
1017
-                        $this->_contexts[$key][$message_type->name] = $message_type_contexts;
1018
-                    }
1019
-                }
1020
-            }
1021
-        }
1022
-        return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * This checks the internal record of what message types are considered "active" and verifies that
1028
-     * there is an installed class definition for that message type.  If the active message type does not have a
1029
-     * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1030
-     * any related message templates will be inactivated as well.
1031
-     *
1032
-     * @return bool   true means all active message types are valid, false means at least one message type was
1033
-     *                deactivated.
1034
-     */
1035
-    public function validate_active_message_types_are_installed()
1036
-    {
1037
-        $list_of_active_message_type_names = $this->list_of_active_message_types();
1038
-        $installed_message_types           = $this->installed_message_types();
1039
-        $all_message_types_valid           = true;
1040
-        //loop through list of active message types and verify they are installed.
1041
-        foreach ($list_of_active_message_type_names as $message_type_name) {
1042
-            if (! isset($installed_message_types[$message_type_name])) {
1043
-                $this->remove_message_type_has_been_activated_from_all_messengers(
1044
-                    $message_type_name,
1045
-                    true
1046
-                );
1047
-                $this->deactivate_message_type($message_type_name, false);
1048
-                $all_message_types_valid = false;
1049
-            }
1050
-        }
1051
-        return $all_message_types_valid;
1052
-    }
1053
-
1054
-
1055
-    /**
1056
-     * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1057
-     * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1058
-     * to attempt automatically reactivating message types that should be activated by default or not.
1059
-     *
1060
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1061
-     *
1062
-     * @param $message_type_name
1063
-     * @param $messenger_name
1064
-     * @return bool
1065
-     */
1066
-    public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1067
-    {
1068
-        $has_activated = $this->get_has_activated_messengers_option();
1069
-        return isset($has_activated[$messenger_name])
1070
-               && in_array($message_type_name, $has_activated[$messenger_name]);
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * This method unsets a message type from the given messenger has activated option.
1076
-     *
1077
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1078
-     *
1079
-     * @param string $message_type_name
1080
-     * @param string $messenger_name
1081
-     * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1082
-     *                                        If it is currently active, then remove.  Otherwise leave it alone.
1083
-     */
1084
-    public function remove_message_type_has_been_activated_for_messenger(
1085
-        $message_type_name,
1086
-        $messenger_name,
1087
-        $consider_current_state = false
1088
-    ) {
1089
-        if ($consider_current_state
1090
-            && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1091
-        ) {
1092
-            //when consider current state is true, this means we don't want to change anything on the "has_activated"
1093
-            //record if the message type is currently active for this messenger.  This is used when we want to retain
1094
-            //the record for user initiated inactivations of the message type.
1095
-            return;
1096
-        }
1097
-        $has_activated = $this->get_has_activated_messengers_option();
1098
-        $key_for_message_type = isset($has_activated[$messenger_name])
1099
-            ? array_search($message_type_name, $has_activated[$messenger_name], true)
1100
-            : false;
1101
-        if ($key_for_message_type !== false) {
1102
-            unset($has_activated[$messenger_name][$key_for_message_type]);
1103
-            $this->update_has_activated_messengers_option($has_activated);
1104
-            //reset the internal cached property
1105
-            $this->get_has_activated_messengers_option(true);
1106
-        }
1107
-    }
1108
-
1109
-
1110
-    /**
1111
-     * Removes a message type active record from all messengers it is attached to.
1112
-     *
1113
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1114
-     *
1115
-     * @param      $message_type_name
1116
-     * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1117
-     *                                      If it is currently active, then remove.  Otherwise leave it alone.
1118
-     */
1119
-    public function remove_message_type_has_been_activated_from_all_messengers(
1120
-        $message_type_name,
1121
-        $consider_current_state = false
1122
-    ) {
1123
-        foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124
-            $this->remove_message_type_has_been_activated_for_messenger(
1125
-                $message_type_name,
1126
-                $messenger_name,
1127
-                $consider_current_state
1128
-            );
1129
-        }
1130
-    }
20
+	/**
21
+	 * This option in the database is used to keep a record of message types that have been activated for a messenger
22
+	 * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
23
+	 * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
24
+	 * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
25
+	 * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
26
+	 * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
27
+	 * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
28
+	 * automated process (when an add-on registering the message type deactivates, or when some other code calls the
29
+	 * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
30
+	 * the "force" flag is respected if that message type is later re-registered.
31
+	 *
32
+	 * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
33
+	 *
34
+	 * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
35
+	 * option that got superseded by later behaviour requirements.
36
+	 */
37
+	const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
38
+
39
+	/**
40
+	 * @type boolean $_initialized
41
+	 */
42
+	protected $_initialized = false;
43
+
44
+	/**
45
+	 * @type EE_Messenger_Collection $_messenger_collection_loader
46
+	 */
47
+	protected $_messenger_collection_loader;
48
+
49
+	/**
50
+	 * @type EE_Message_Type_Collection $_message_type_collection_loader
51
+	 */
52
+	protected $_message_type_collection_loader;
53
+
54
+	/**
55
+	 * @type EEM_Message_Template_Group $_message_template_group_model
56
+	 */
57
+	protected $_message_template_group_model;
58
+
59
+	/**
60
+	 * @type EE_messenger[]
61
+	 */
62
+	protected $_installed_messengers = array();
63
+
64
+	/**
65
+	 * @type EE_message_type[]
66
+	 */
67
+	protected $_installed_message_types = array();
68
+
69
+	/**
70
+	 * Array of active messengers.
71
+	 * Format is this:
72
+	 * array(
73
+	 *      'messenger_name' => EE_messenger
74
+	 * )
75
+	 *
76
+	 * @type EE_messenger[]
77
+	 */
78
+	protected $_active_messengers = array();
79
+
80
+	/**
81
+	 * Formatted array of active message types grouped per messenger.
82
+	 * Format is this:
83
+	 * array(
84
+	 *      'messenger_name' => array(
85
+	 *          'settings' => array(
86
+	 *              '{messenger_name}-message_types' => array(
87
+	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
88
+	 *              )
89
+	 *          )
90
+	 *      )
91
+	 * )
92
+	 *
93
+	 * @type array
94
+	 */
95
+	protected $_active_message_types = array();
96
+
97
+
98
+	/**
99
+	 * This holds the array of messengers and their corresponding message types that have
100
+	 * been activated on a site at some point.  This is an important record that helps the messages system
101
+	 * not accidentally reactivate something that was intentionally deactivated by a user.
102
+	 *
103
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
104
+	 *
105
+	 * @type array
106
+	 */
107
+	protected $_has_activated_messengers_and_message_types = array();
108
+
109
+	/**
110
+	 * An array of unique message type contexts across all active message types.
111
+	 * The array will be indexed by either 'slugs' or 'all'.
112
+	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
113
+	 * slug. array(
114
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
115
+	 * );
116
+	 * The all index returns an array in this format:
117
+	 * array(
118
+	 *      'message_type_name' => array(
119
+	 *          'context_slug' => array(
120
+	 *              'label' => 'localized label for context',
121
+	 *              'description' => 'localized description for context'
122
+	 *          )
123
+	 *      )
124
+	 * );
125
+	 *
126
+	 * @type array
127
+	 */
128
+	protected $_contexts = array();
129
+
130
+
131
+	/**
132
+	 * EE_Message_Resource_Manager constructor.
133
+	 *
134
+	 * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
135
+	 * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
136
+	 * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
137
+	 */
138
+	function __construct(
139
+		EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
140
+		EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
141
+		EEM_Message_Template_Group $Message_Template_Group_Model
142
+	) {
143
+		$this->_messenger_collection_loader    = $Messenger_Collection_Loader;
144
+		$this->_message_type_collection_loader = $Message_Type_Collection_Loader;
145
+		$this->_message_template_group_model   = $Message_Template_Group_Model;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return void
151
+	 */
152
+	protected function _initialize_collections()
153
+	{
154
+		if ($this->_initialized) {
155
+			return;
156
+		}
157
+		$this->_initialized = true;
158
+		$this->_messenger_collection_loader->load_messengers_from_folder();
159
+		$this->_message_type_collection_loader->load_message_types_from_folder();
160
+		$this->get_has_activated_messengers_option(true);
161
+		$this->_set_active_messengers_and_message_types();
162
+	}
163
+
164
+
165
+	/**
166
+	 * @return EE_Messenger_Collection
167
+	 */
168
+	public function messenger_collection()
169
+	{
170
+		$this->_initialize_collections();
171
+		return $this->_messenger_collection_loader->messenger_collection();
172
+	}
173
+
174
+
175
+	/**
176
+	 * @return EE_messenger[]
177
+	 */
178
+	public function active_messengers()
179
+	{
180
+		$this->_initialize_collections();
181
+		return $this->_active_messengers;
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param string $messenger_name
187
+	 * @return \EE_messenger
188
+	 */
189
+	public function get_messenger($messenger_name)
190
+	{
191
+		return $this->messenger_collection()->get_by_info($messenger_name);
192
+	}
193
+
194
+
195
+	/**
196
+	 * This returns the corresponding EE_messenger object for the given string if it is active.
197
+	 *
198
+	 * @param string $messenger
199
+	 * @return EE_messenger | null
200
+	 */
201
+	public function get_active_messenger($messenger)
202
+	{
203
+		$this->_initialize_collections();
204
+		return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
205
+	}
206
+
207
+
208
+	/**
209
+	 * @return \EE_messenger[]
210
+	 */
211
+	public function installed_messengers()
212
+	{
213
+		if (empty($this->_installed_messengers)) {
214
+			$this->_installed_messengers = array();
215
+			$this->messenger_collection()->rewind();
216
+			while ($this->messenger_collection()->valid()) {
217
+				$this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
218
+				$this->messenger_collection()->next();
219
+			}
220
+		}
221
+		return $this->_installed_messengers;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @param string $messenger_name
227
+	 * @return \EE_messenger
228
+	 * @throws \EE_Error
229
+	 */
230
+	public function valid_messenger($messenger_name)
231
+	{
232
+		$messenger = $this->get_messenger($messenger_name);
233
+		if ($messenger instanceof EE_messenger) {
234
+			return $messenger;
235
+		}
236
+		throw new EE_Error(
237
+			sprintf(
238
+				__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
239
+				$messenger_name
240
+			)
241
+		);
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return EE_Message_Type_Collection
247
+	 */
248
+	public function message_type_collection()
249
+	{
250
+		$this->_initialize_collections();
251
+		return $this->_message_type_collection_loader->message_type_collection();
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return array
257
+	 */
258
+	public function active_message_types()
259
+	{
260
+		$this->_initialize_collections();
261
+		return $this->_active_message_types;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param string $message_type_name
267
+	 * @return \EE_message_type
268
+	 */
269
+	public function get_message_type($message_type_name)
270
+	{
271
+		return $this->message_type_collection()->get_by_info($message_type_name);
272
+	}
273
+
274
+
275
+	/**
276
+	 * This returns the EE_message_type from the active message types array ( if present );
277
+	 *
278
+	 * @param string $messenger_name
279
+	 * @param string $message_type_name
280
+	 * @return \EE_message_type|null
281
+	 */
282
+	public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
283
+	{
284
+		return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
285
+			? $this->get_message_type($message_type_name)
286
+			: null;
287
+	}
288
+
289
+
290
+	/**
291
+	 * Returns whether the given message type is active for the given messenger.
292
+	 *
293
+	 * @param string $messenger_name
294
+	 * @param string $message_type_name
295
+	 * @return bool
296
+	 */
297
+	public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298
+	{
299
+		$this->_initialize_collections();
300
+		return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
301
+	}
302
+
303
+
304
+	/**
305
+	 * Returns whether the given messenger is active.
306
+	 *
307
+	 * @param string $messenger_name the name of the messenger to check if active.
308
+	 * @return bool
309
+	 */
310
+	public function is_messenger_active($messenger_name)
311
+	{
312
+		$this->_initialize_collections();
313
+		return ! empty($this->_active_message_types[$messenger_name]);
314
+	}
315
+
316
+
317
+	/**
318
+	 * This returns any settings that might be on a message type for a messenger
319
+	 *
320
+	 * @param string $messenger_name    The slug of the messenger
321
+	 * @param string $message_type_name The slug of the message type getting the settings for.
322
+	 * @return array
323
+	 */
324
+	public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
325
+	{
326
+		$settings = array();
327
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
+			$settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
+				? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
330
+				: array();
331
+		}
332
+		return $settings;
333
+	}
334
+
335
+
336
+	/**
337
+	 * Returns whether the given messenger name has active message types on it.
338
+	 * Infers whether the messenger is active or not as well.
339
+	 *
340
+	 * @param string $messenger_name
341
+	 * @return bool
342
+	 */
343
+	public function messenger_has_active_message_types($messenger_name)
344
+	{
345
+		$this->_initialize_collections();
346
+		return
347
+			! empty($this->_active_message_types[$messenger_name])
348
+			&& ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
349
+	}
350
+
351
+
352
+	/**
353
+	 * This checks the _active_message_types property for any active message types
354
+	 * that are present for the given messenger and returns them.
355
+	 *
356
+	 * @since 4.9.0
357
+	 * @param string $messenger_name The messenger being checked
358
+	 * @return EE_message_type[]|array    (empty array if no active_message_types)
359
+	 */
360
+	public function get_active_message_types_for_messenger($messenger_name)
361
+	{
362
+		$message_types = array();
363
+		if (! $this->messenger_has_active_message_types($messenger_name)) {
364
+			return $message_types;
365
+		}
366
+		$installed_message_types = $this->installed_message_types();
367
+		foreach ($installed_message_types as $message_type_name => $message_type) {
368
+			if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
369
+				$message_types[$message_type_name] = $message_type;
370
+			}
371
+		}
372
+		return $message_types;
373
+	}
374
+
375
+
376
+	/**
377
+	 * This does NOT return the _active_message_types property but
378
+	 * simply returns an array of active message type names from that property.
379
+	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
380
+	 *
381
+	 * @return array message_type references (string)
382
+	 */
383
+	public function list_of_active_message_types()
384
+	{
385
+		$active_message_type_names = array();
386
+		$this->_initialize_collections();
387
+		foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
+			if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
389
+				continue;
390
+			}
391
+			foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
+				if (! in_array($message_type_name, $active_message_type_names)) {
393
+					$active_message_type_names[] = $message_type_name;
394
+				}
395
+			}
396
+		}
397
+		return $active_message_type_names;
398
+	}
399
+
400
+
401
+	/**
402
+	 * Same as list_of_active_message_types() except this returns actual EE_message_type objects
403
+	 *
404
+	 * @since 4.9.0
405
+	 * @return \EE_message_type[]
406
+	 */
407
+	public function get_active_message_type_objects()
408
+	{
409
+		$active_message_types      = array();
410
+		$installed_message_types   = $this->installed_message_types();
411
+		$active_message_type_names = $this->list_of_active_message_types();
412
+		foreach ($active_message_type_names as $active_message_type_name) {
413
+			if (isset($installed_message_types[$active_message_type_name])) {
414
+				$active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
415
+			}
416
+		}
417
+		return $active_message_types;
418
+	}
419
+
420
+
421
+	/**
422
+	 * @return \EE_message_type[]
423
+	 */
424
+	public function installed_message_types()
425
+	{
426
+		if (empty($this->_installed_message_types)) {
427
+			$this->message_type_collection()->rewind();
428
+			while ($this->message_type_collection()->valid()) {
429
+				$this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
430
+				$this->message_type_collection()->next();
431
+			}
432
+		}
433
+		return $this->_installed_message_types;
434
+	}
435
+
436
+
437
+	/**
438
+	 * @param string $message_type_name
439
+	 * @return \EE_message_type
440
+	 * @throws \EE_Error
441
+	 */
442
+	public function valid_message_type($message_type_name)
443
+	{
444
+		$message_type = $this->get_message_type($message_type_name);
445
+		if ($message_type instanceof EE_message_type) {
446
+			return $message_type;
447
+		}
448
+		throw new EE_Error(
449
+			sprintf(
450
+				__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
451
+				$message_type_name
452
+			)
453
+		);
454
+	}
455
+
456
+
457
+	/**
458
+	 * valid_message_type_for_messenger
459
+	 *
460
+	 * @param EE_messenger $messenger
461
+	 * @param string       $message_type_name
462
+	 * @return boolean
463
+	 * @throws \EE_Error
464
+	 */
465
+	public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466
+	{
467
+		$valid_message_types = $messenger->get_valid_message_types();
468
+		if (! in_array($message_type_name, $valid_message_types)) {
469
+			throw new EE_Error(
470
+				sprintf(
471
+					__(
472
+						'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
473
+						'event_espresso'
474
+					),
475
+					$message_type_name,
476
+					__METHOD__,
477
+					$messenger->name
478
+				)
479
+			);
480
+		}
481
+		return true;
482
+	}
483
+
484
+
485
+	/**
486
+	 * Used to return active messengers array stored in the wp options table.
487
+	 * If no value is present in the option then an empty array is returned.
488
+	 *
489
+	 * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
490
+	 *                          property and pull directly from the db.  Otherwise whatever is currently on the
491
+	 *                          $_active_message_types property is pulled.
492
+	 * @return array
493
+	 */
494
+	public function get_active_messengers_option($reset = false)
495
+	{
496
+		if ($reset) {
497
+			$this->_active_message_types = get_option('ee_active_messengers', array());
498
+		}
499
+		return $this->_active_message_types;
500
+	}
501
+
502
+
503
+	/**
504
+	 * Used to update the active messengers array stored in the wp options table.
505
+	 *
506
+	 * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
507
+	 *                                         representing this data is used.
508
+	 * @return bool FALSE if not updated, TRUE if updated.
509
+	 */
510
+	public function update_active_messengers_option($active_messenger_settings = array())
511
+	{
512
+		$active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
513
+		//make sure _active_message_types is updated (this is the internal cache for the settings).
514
+		$this->_active_message_types = $active_messenger_settings;
515
+		return update_option('ee_active_messengers', $active_messenger_settings);
516
+	}
517
+
518
+
519
+	/**
520
+	 * Used to return has activated message types for messengers array stored in the wp options table.
521
+	 * If no value is present in the option then an empty array is returned.
522
+	 * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
523
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
524
+	 *
525
+	 * @param   bool $reset Used to indicate that any cached value should be ignored.
526
+	 * @return array
527
+	 */
528
+	public function get_has_activated_messengers_option($reset = false)
529
+	{
530
+		if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
531
+			$this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
532
+		}
533
+		return $this->_has_activated_messengers_and_message_types;
534
+	}
535
+
536
+
537
+	/**
538
+	 * Used to update the has activated option in the db.
539
+	 *
540
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
541
+	 *
542
+	 * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
543
+	 *                                        representing this data is used.
544
+	 * @return bool FALSE if not updated, TRUE if updated.
545
+	 */
546
+	public function update_has_activated_messengers_option($has_activated_messengers = array())
547
+	{
548
+		//make sure the option has been retrieved from first so we don't overwrite it accidentally.
549
+		if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
550
+			$this->get_has_activated_messengers_option();
551
+		}
552
+		$has_activated_messengers = empty($has_activated_messengers)
553
+			? $this->_has_activated_messengers_and_message_types
554
+			: $has_activated_messengers;
555
+		return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
556
+	}
557
+
558
+
559
+	/**
560
+	 * wrapper for _set_active_messengers_and_message_types()
561
+	 */
562
+	public function reset_active_messengers_and_message_types()
563
+	{
564
+		$this->_set_active_messengers_and_message_types();
565
+	}
566
+
567
+
568
+	/**
569
+	 * Generate list of active messengers and message types from collection.
570
+	 * This sets up the active messengers from what is present in the database.
571
+	 */
572
+	protected function _set_active_messengers_and_message_types()
573
+	{
574
+		//echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
575
+		// list of activated messengers as set via the admin
576
+		// note calling `get_active_messengers_options` also initializes the _active_message_types property.
577
+		$this->get_active_messengers_option(true);
578
+		$this->ensure_messengers_are_active(array(), false, true);
579
+		$this->update_active_messengers_option();
580
+		$this->update_has_activated_messengers_option();
581
+	}
582
+
583
+
584
+	/**
585
+	 * Ensures that the specified messenger is currently active.
586
+	 * If not, activates it and its default message types.
587
+	 *
588
+	 * @param string $messenger_name
589
+	 * @param bool   $update_option Whether to update the option in the db or not.
590
+	 * @return boolean true if either already active or successfully activated.
591
+	 */
592
+	public function ensure_messenger_is_active($messenger_name, $update_option = true)
593
+	{
594
+		if (! isset($this->_active_messengers[$messenger_name])) {
595
+			try {
596
+				$this->activate_messenger($messenger_name, array(), $update_option);
597
+			} catch (EE_Error $e) {
598
+				EE_Error::add_error(
599
+					$e->getMessage(),
600
+					__FILE__,
601
+					__FUNCTION__,
602
+					__LINE__
603
+				);
604
+				return false;
605
+			}
606
+		}
607
+		return true;
608
+	}
609
+
610
+
611
+	/**
612
+	 * This ensures the given array of messenger names is active in the system.
613
+	 * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
614
+	 * it will automatically activate the default message types for the messenger if its not active.
615
+	 *
616
+	 * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
617
+	 *                                (default) then will attempt to set the active messengers from the
618
+	 *                                activated_messengers option
619
+	 *                                (stored in $_active_message_types property).
620
+	 * @param bool  $update_option    Whether to update the related active messengers option.
621
+	 * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
622
+	 *                                set to true and a messenger is indicated as active, but is NOT installed, then it
623
+	 *                                will automatically be deactivated.
624
+	 */
625
+	public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
626
+	{
627
+		$messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
628
+
629
+		$not_installed = array();
630
+		foreach ($messenger_names as $messenger_name) {
631
+			if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
632
+				$not_installed[] = $messenger_name;
633
+				$this->deactivate_messenger($messenger_name);
634
+				continue;
635
+			}
636
+			$this->ensure_messenger_is_active($messenger_name, $update_option);
637
+		}
638
+
639
+		if (! empty($not_installed)) {
640
+			EE_Error::add_error(
641
+				sprintf(
642
+					__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
643
+					'<br />',
644
+					implode(', ', $not_installed)
645
+				),
646
+				__FILE__, __FUNCTION__, __LINE__
647
+			);
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
654
+	 * This ALSO ensures that the given messenger is active as well!
655
+	 *
656
+	 * @param string $message_type_name message type name.
657
+	 * @param        $messenger_name
658
+	 * @param bool   $update_option     Whether to update the option in the db or not.
659
+	 * @return bool  Returns true if already is active or if was activated successfully.
660
+	 * @throws \EE_Error
661
+	 */
662
+	public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
663
+	{
664
+		// grab the messenger to work with.
665
+		$messenger = $this->valid_messenger($messenger_name);
666
+		if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
667
+			//ensure messenger is active (that's an inherent coupling between active message types and the
668
+			//messenger they are being activated for.
669
+			try {
670
+				if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671
+					//all is good so let's just get it active
672
+					$this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673
+				}
674
+			} catch (EE_Error $e) {
675
+				EE_Error::add_error(
676
+					$e->getMessage(),
677
+					__FILE__,
678
+					__FUNCTION__,
679
+					__LINE__
680
+				);
681
+				return false;
682
+			}
683
+		}
684
+		return true;
685
+	}
686
+
687
+
688
+	/**
689
+	 * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
690
+	 * messenger are active in one go.
691
+	 *
692
+	 * @param array  $message_type_names Array of message type names to ensure are active.
693
+	 * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
694
+	 * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
695
+	 */
696
+	public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697
+	{
698
+		$message_type_names = (array)$message_type_names;
699
+		foreach ($message_type_names as $message_type_name) {
700
+			// note, intentionally not updating option here because we're in a loop.
701
+			// We'll follow the instructions of the incoming $update_option argument after the loop.
702
+			$this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
703
+		}
704
+		if ($update_option) {
705
+			$this->update_active_messengers_option();
706
+			$this->update_has_activated_messengers_option();
707
+		}
708
+	}
709
+
710
+
711
+	/**
712
+	 * Activates the specified messenger.
713
+	 *
714
+	 * @param string $messenger_name
715
+	 * @param array  $message_type_names        An array of message type names to activate with this messenger.
716
+	 *                                          If included we do NOT setup the default message types
717
+	 *                                          (assuming they are already setup.)
718
+	 * @param bool   $update_active_messengers_option
719
+	 * @return array of generated templates
720
+	 * @throws \EE_Error
721
+	 */
722
+	public function activate_messenger(
723
+		$messenger_name,
724
+		$message_type_names = array(),
725
+		$update_active_messengers_option = true
726
+	) {
727
+		$templates = array();
728
+		// grab the messenger to work with.
729
+		$messenger = $this->messenger_collection()->get_by_info($messenger_name);
730
+		// it's inactive. Activate it.
731
+		if ($messenger instanceof EE_messenger) {
732
+			$this->_active_messengers[$messenger->name] = $messenger;
733
+			//activate incoming message types set to be activated with messenger.
734
+			$message_type_names = $this->_activate_message_types($messenger, $message_type_names);
735
+			// setup any initial settings for the messenger if necessary.
736
+			$this->add_settings_for_messenger($messenger->name);
737
+			if ($update_active_messengers_option) {
738
+				$this->update_active_messengers_option();
739
+				$this->update_has_activated_messengers_option();
740
+			}
741
+			//generate new templates if necessary and ensure all related templates that are already in the database are
742
+			//marked active.  Note, this will also deactivate a message type for a messenger if the template
743
+			//cannot be successfully created during its attempt (only happens for global template attempts).
744
+			if (! empty($message_type_names)) {
745
+				$templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746
+				EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747
+			}
748
+		}
749
+		return $templates;
750
+	}
751
+
752
+
753
+	/**
754
+	 * Activates given message types for the given EE_messenger object.
755
+	 * Note: (very important) This method does not persist the activation to the database.
756
+	 * See code implementing this method in this class for examples of how to persist.
757
+	 *
758
+	 * @param \EE_messenger $messenger
759
+	 * @param  array        $message_type_names
760
+	 * @return array
761
+	 */
762
+	protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
763
+	{
764
+		//If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
765
+		//things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
766
+		//So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
767
+		//only override _active_message_types when an explicit array of $message_type_names has been provided.
768
+		$message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769
+			? $messenger->get_default_message_types()
770
+			: (array)$message_type_names;
771
+
772
+		//now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
+		if (! isset($this->_active_message_types[$messenger->name])) {
774
+			$this->_active_message_types[$messenger->name]['settings'] = array();
775
+		}
776
+
777
+		if ($message_type_names) {
778
+			// cycle thru message types
779
+			foreach ($message_type_names as $message_type_name) {
780
+				//only register the message type as active IF it isn't already active
781
+				//and if its actually installed.
782
+				if (
783
+				! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
784
+				) {
785
+					$this->add_settings_for_message_type($messenger->name, $message_type_name);
786
+					$this->_set_messenger_has_activated_message_type(
787
+						$messenger,
788
+						$message_type_name
789
+					);
790
+				}
791
+			}
792
+		}
793
+		return $message_type_names;
794
+	}
795
+
796
+
797
+	/**
798
+	 * add_settings_for_message_type
799
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
800
+	 * $this->update_active_messengers_option to persist.
801
+	 *
802
+	 * @param  string $messenger_name    The name of the messenger adding the settings for
803
+	 * @param  string $message_type_name The name of the message type adding the settings for
804
+	 * @param  array  $new_settings      Any new settings being set for the message type and messenger
805
+	 */
806
+	public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
807
+	{
808
+		// get installed message type from collection
809
+		$message_type      = $this->message_type_collection()->get_by_info($message_type_name);
810
+		$existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
811
+		//we need to setup any initial settings for message types
812
+		if ($message_type instanceof EE_message_type) {
813
+			$default_settings = $message_type->get_admin_settings_fields();
814
+			foreach ($default_settings as $field => $values) {
815
+				if (isset($new_settings[$field])) {
816
+					$existing_settings[$field] = $new_settings[$field];
817
+					continue;
818
+				}
819
+				if (! isset($existing_settings[$field])) {
820
+					$existing_settings[$field] = $values['default'];
821
+				}
822
+			}
823
+		}
824
+		$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
825
+	}
826
+
827
+
828
+	/**
829
+	 * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
830
+	 * and message type.
831
+	 *
832
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
833
+	 *
834
+	 * @access protected
835
+	 * @param \EE_messenger $messenger
836
+	 * @param string        $message_type_name
837
+	 */
838
+	protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
839
+	{
840
+
841
+		//if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
842
+		if (empty($this->_has_activated_messengers_and_message_types)) {
843
+			$this->get_has_activated_messengers_option();
844
+		}
845
+
846
+		// make sure this messenger has a record in the has_activated array
847
+		if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
+			$this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849
+		}
850
+		// check if message type has already been added
851
+		if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852
+			$this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853
+		}
854
+	}
855
+
856
+
857
+	/**
858
+	 * add_settings_for_messenger
859
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
860
+	 * $this->update_active_messengers_option to persist.
861
+	 *
862
+	 * @param string $messenger_name The name of the messenger the settings is being added for.
863
+	 * @param array  $new_settings   An array of settings to update the existing settings.
864
+	 */
865
+	public function add_settings_for_messenger($messenger_name, $new_settings = array())
866
+	{
867
+		$messenger = $this->get_messenger($messenger_name);
868
+		if ($messenger instanceof EE_messenger) {
869
+			$msgr_settings = $messenger->get_admin_settings_fields();
870
+			if (! empty($msgr_settings)) {
871
+				foreach ($msgr_settings as $field => $value) {
872
+					//is there a new setting for this?
873
+					if (isset($new_settings[$field])) {
874
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
875
+						continue;
876
+					}
877
+					//only set the default if it isn't already set.
878
+					if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880
+					}
881
+				}
882
+			}
883
+		}
884
+	}
885
+
886
+
887
+	/**
888
+	 * deactivate_messenger
889
+	 *
890
+	 * @param  string|EE_messenger $messenger_name name of messenger
891
+	 * @return void
892
+	 */
893
+	public function deactivate_messenger($messenger_name)
894
+	{
895
+		$this->_initialize_collections();
896
+		if ($messenger_name instanceof EE_messenger) {
897
+			$messenger_name = $messenger_name->name;
898
+		}
899
+		unset($this->_active_messengers[$messenger_name]);
900
+		unset($this->_active_message_types[$messenger_name]);
901
+		$this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
902
+		$this->update_active_messengers_option();
903
+	}
904
+
905
+
906
+	/**
907
+	 * Deactivates a message type (note this will deactivate across all messenger's it is active on.
908
+	 *
909
+	 * @param  string $message_type_name     name of message type being deactivated
910
+	 * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
911
+	 *                                       type.  However, this can be overridden if we don't want this set (usually when
912
+	 *                                       this is called as a part of deregistration of a custom message type)
913
+	 */
914
+	public function deactivate_message_type($message_type_name, $set_has_active_record = true)
915
+	{
916
+		$this->_initialize_collections();
917
+		if ($message_type_name instanceof EE_message_type) {
918
+			$message_type_name = $message_type_name->name;
919
+		}
920
+		foreach ($this->_active_message_types as $messenger_name => $settings) {
921
+			unset(
922
+				$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
923
+			);
924
+
925
+			//we always record (even on deactivation) that a message type has been activated because there should at
926
+			//least be a record in the "has_activated" option that it WAS active at one point.
927
+			if ($set_has_active_record) {
928
+				$messenger = $this->get_messenger($messenger_name);
929
+				$this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
930
+			}
931
+		}
932
+		$this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
933
+		$this->update_active_messengers_option();
934
+		$this->update_has_activated_messengers_option();
935
+	}
936
+
937
+
938
+	/**
939
+	 * Deactivates a message type for a specific messenger as opposed to all messengers.
940
+	 *
941
+	 * @param string $message_type_name Name of message type being deactivated.
942
+	 * @param string $messenger_name    Name of messenger the message type is being deactivated for.
943
+	 */
944
+	public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
945
+	{
946
+		$this->_initialize_collections();
947
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
+			unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
949
+		}
950
+		$this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951
+			array($message_type_name));
952
+		$this->update_active_messengers_option();
953
+	}
954
+
955
+
956
+	/**
957
+	 * Used to verify if a message can be sent for the given messenger and message type
958
+	 * and that it is a generating messenger (used for generating message templates).
959
+	 *
960
+	 * @param EE_messenger    $messenger    messenger used in trigger
961
+	 * @param EE_message_type $message_type message type used in trigger
962
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
963
+	 */
964
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
965
+	{
966
+		//get the $messengers the message type says it can be used with.
967
+		foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
968
+			if (
969
+				$messenger->name === $generating_messenger
970
+				&& $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
971
+			) {
972
+				return true;
973
+			}
974
+		}
975
+		return false;
976
+	}
977
+
978
+
979
+	/**
980
+	 * This returns all the contexts that are registered by all message types.
981
+	 * If $slugs_only is true,
982
+	 * then just an array indexed by unique context slugs with the latest label representation for that slug.
983
+	 * array(
984
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
985
+	 * );
986
+	 * If $slugs_only is false, then the format is:
987
+	 * array(
988
+	 *      'message_type_name' => array(
989
+	 *          'context_slug' => array(
990
+	 *              'label' => 'localized label for context',
991
+	 *              'description' => 'localized description for context'
992
+	 *          )
993
+	 *      )
994
+	 * );
995
+	 * Keep in mind that although different message types may share the same context slugs,
996
+	 * it is possible that the context is described differently by the message type.
997
+	 *
998
+	 * @since 4.9.0
999
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1000
+	 *                           or all contexts indexed by message type.
1001
+	 * @return array
1002
+	 */
1003
+	public function get_all_contexts($slugs_only = true)
1004
+	{
1005
+		$key = $slugs_only ? 'slugs' : 'all';
1006
+		// check if contexts has been setup yet.
1007
+		if (empty($this->_contexts[$key])) {
1008
+			// So let's get all active message type objects and loop through to get all unique contexts
1009
+			foreach ($this->get_active_message_type_objects() as $message_type) {
1010
+				if ($message_type instanceof EE_message_type) {
1011
+					$message_type_contexts = $message_type->get_contexts();
1012
+					if ($slugs_only) {
1013
+						foreach ($message_type_contexts as $context => $context_details) {
1014
+							$this->_contexts[$key][$context] = $context_details['label'];
1015
+						}
1016
+					} else {
1017
+						$this->_contexts[$key][$message_type->name] = $message_type_contexts;
1018
+					}
1019
+				}
1020
+			}
1021
+		}
1022
+		return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * This checks the internal record of what message types are considered "active" and verifies that
1028
+	 * there is an installed class definition for that message type.  If the active message type does not have a
1029
+	 * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1030
+	 * any related message templates will be inactivated as well.
1031
+	 *
1032
+	 * @return bool   true means all active message types are valid, false means at least one message type was
1033
+	 *                deactivated.
1034
+	 */
1035
+	public function validate_active_message_types_are_installed()
1036
+	{
1037
+		$list_of_active_message_type_names = $this->list_of_active_message_types();
1038
+		$installed_message_types           = $this->installed_message_types();
1039
+		$all_message_types_valid           = true;
1040
+		//loop through list of active message types and verify they are installed.
1041
+		foreach ($list_of_active_message_type_names as $message_type_name) {
1042
+			if (! isset($installed_message_types[$message_type_name])) {
1043
+				$this->remove_message_type_has_been_activated_from_all_messengers(
1044
+					$message_type_name,
1045
+					true
1046
+				);
1047
+				$this->deactivate_message_type($message_type_name, false);
1048
+				$all_message_types_valid = false;
1049
+			}
1050
+		}
1051
+		return $all_message_types_valid;
1052
+	}
1053
+
1054
+
1055
+	/**
1056
+	 * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1057
+	 * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1058
+	 * to attempt automatically reactivating message types that should be activated by default or not.
1059
+	 *
1060
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1061
+	 *
1062
+	 * @param $message_type_name
1063
+	 * @param $messenger_name
1064
+	 * @return bool
1065
+	 */
1066
+	public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1067
+	{
1068
+		$has_activated = $this->get_has_activated_messengers_option();
1069
+		return isset($has_activated[$messenger_name])
1070
+			   && in_array($message_type_name, $has_activated[$messenger_name]);
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * This method unsets a message type from the given messenger has activated option.
1076
+	 *
1077
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1078
+	 *
1079
+	 * @param string $message_type_name
1080
+	 * @param string $messenger_name
1081
+	 * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1082
+	 *                                        If it is currently active, then remove.  Otherwise leave it alone.
1083
+	 */
1084
+	public function remove_message_type_has_been_activated_for_messenger(
1085
+		$message_type_name,
1086
+		$messenger_name,
1087
+		$consider_current_state = false
1088
+	) {
1089
+		if ($consider_current_state
1090
+			&& ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1091
+		) {
1092
+			//when consider current state is true, this means we don't want to change anything on the "has_activated"
1093
+			//record if the message type is currently active for this messenger.  This is used when we want to retain
1094
+			//the record for user initiated inactivations of the message type.
1095
+			return;
1096
+		}
1097
+		$has_activated = $this->get_has_activated_messengers_option();
1098
+		$key_for_message_type = isset($has_activated[$messenger_name])
1099
+			? array_search($message_type_name, $has_activated[$messenger_name], true)
1100
+			: false;
1101
+		if ($key_for_message_type !== false) {
1102
+			unset($has_activated[$messenger_name][$key_for_message_type]);
1103
+			$this->update_has_activated_messengers_option($has_activated);
1104
+			//reset the internal cached property
1105
+			$this->get_has_activated_messengers_option(true);
1106
+		}
1107
+	}
1108
+
1109
+
1110
+	/**
1111
+	 * Removes a message type active record from all messengers it is attached to.
1112
+	 *
1113
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1114
+	 *
1115
+	 * @param      $message_type_name
1116
+	 * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1117
+	 *                                      If it is currently active, then remove.  Otherwise leave it alone.
1118
+	 */
1119
+	public function remove_message_type_has_been_activated_from_all_messengers(
1120
+		$message_type_name,
1121
+		$consider_current_state = false
1122
+	) {
1123
+		foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124
+			$this->remove_message_type_has_been_activated_for_messenger(
1125
+				$message_type_name,
1126
+				$messenger_name,
1127
+				$consider_current_state
1128
+			);
1129
+		}
1130
+	}
1131 1131
 }
1132 1132
 // End of file EE_Message_Resource_Manager.lib.php
1133 1133
 // Location: /EE_Message_Resource_Manager.lib.php
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298 298
     {
299 299
         $this->_initialize_collections();
300
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
300
+        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
301 301
     }
302 302
 
303 303
 
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
     {
326 326
         $settings = array();
327 327
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
328
+            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'])
329
+                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']
330 330
                 : array();
331 331
         }
332 332
         return $settings;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
         $this->_initialize_collections();
346 346
         return
347 347
             ! empty($this->_active_message_types[$messenger_name])
348
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
348
+            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']);
349 349
     }
350 350
 
351 351
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
     public function get_active_message_types_for_messenger($messenger_name)
361 361
     {
362 362
         $message_types = array();
363
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
363
+        if ( ! $this->messenger_has_active_message_types($messenger_name)) {
364 364
             return $message_types;
365 365
         }
366 366
         $installed_message_types = $this->installed_message_types();
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
         $active_message_type_names = array();
386 386
         $this->_initialize_collections();
387 387
         foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
388
+            if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) {
389 389
                 continue;
390 390
             }
391
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
-                if (! in_array($message_type_name, $active_message_type_names)) {
391
+            foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) {
392
+                if ( ! in_array($message_type_name, $active_message_type_names)) {
393 393
                     $active_message_type_names[] = $message_type_name;
394 394
                 }
395 395
             }
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
     public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466 466
     {
467 467
         $valid_message_types = $messenger->get_valid_message_types();
468
-        if (! in_array($message_type_name, $valid_message_types)) {
468
+        if ( ! in_array($message_type_name, $valid_message_types)) {
469 469
             throw new EE_Error(
470 470
                 sprintf(
471 471
                     __(
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
      */
592 592
     public function ensure_messenger_is_active($messenger_name, $update_option = true)
593 593
     {
594
-        if (! isset($this->_active_messengers[$messenger_name])) {
594
+        if ( ! isset($this->_active_messengers[$messenger_name])) {
595 595
             try {
596 596
                 $this->activate_messenger($messenger_name, array(), $update_option);
597 597
             } catch (EE_Error $e) {
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
             $this->ensure_messenger_is_active($messenger_name, $update_option);
637 637
         }
638 638
 
639
-        if (! empty($not_installed)) {
639
+        if ( ! empty($not_installed)) {
640 640
             EE_Error::add_error(
641 641
                 sprintf(
642 642
                     __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
             //ensure messenger is active (that's an inherent coupling between active message types and the
668 668
             //messenger they are being activated for.
669 669
             try {
670
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
670
+                if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671 671
                     //all is good so let's just get it active
672 672
                     $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673 673
                 }
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
      */
696 696
     public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697 697
     {
698
-        $message_type_names = (array)$message_type_names;
698
+        $message_type_names = (array) $message_type_names;
699 699
         foreach ($message_type_names as $message_type_name) {
700 700
             // note, intentionally not updating option here because we're in a loop.
701 701
             // We'll follow the instructions of the incoming $update_option argument after the loop.
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
             //generate new templates if necessary and ensure all related templates that are already in the database are
742 742
             //marked active.  Note, this will also deactivate a message type for a messenger if the template
743 743
             //cannot be successfully created during its attempt (only happens for global template attempts).
744
-            if (! empty($message_type_names)) {
744
+            if ( ! empty($message_type_names)) {
745 745
                 $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746 746
                 EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747 747
             }
@@ -767,10 +767,10 @@  discard block
 block discarded – undo
767 767
         //only override _active_message_types when an explicit array of $message_type_names has been provided.
768 768
         $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769 769
             ? $messenger->get_default_message_types()
770
-            : (array)$message_type_names;
770
+            : (array) $message_type_names;
771 771
 
772 772
         //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
-        if (! isset($this->_active_message_types[$messenger->name])) {
773
+        if ( ! isset($this->_active_message_types[$messenger->name])) {
774 774
             $this->_active_message_types[$messenger->name]['settings'] = array();
775 775
         }
776 776
 
@@ -816,12 +816,12 @@  discard block
 block discarded – undo
816 816
                     $existing_settings[$field] = $new_settings[$field];
817 817
                     continue;
818 818
                 }
819
-                if (! isset($existing_settings[$field])) {
819
+                if ( ! isset($existing_settings[$field])) {
820 820
                     $existing_settings[$field] = $values['default'];
821 821
                 }
822 822
             }
823 823
         }
824
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
824
+        $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings;
825 825
     }
826 826
 
827 827
 
@@ -844,11 +844,11 @@  discard block
 block discarded – undo
844 844
         }
845 845
 
846 846
         // make sure this messenger has a record in the has_activated array
847
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
847
+        if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848 848
             $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849 849
         }
850 850
         // check if message type has already been added
851
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
851
+        if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852 852
             $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853 853
         }
854 854
     }
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
         $messenger = $this->get_messenger($messenger_name);
868 868
         if ($messenger instanceof EE_messenger) {
869 869
             $msgr_settings = $messenger->get_admin_settings_fields();
870
-            if (! empty($msgr_settings)) {
870
+            if ( ! empty($msgr_settings)) {
871 871
                 foreach ($msgr_settings as $field => $value) {
872 872
                     //is there a new setting for this?
873 873
                     if (isset($new_settings[$field])) {
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
                         continue;
876 876
                     }
877 877
                     //only set the default if it isn't already set.
878
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
878
+                    if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879 879
                         $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880 880
                     }
881 881
                 }
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
         }
920 920
         foreach ($this->_active_message_types as $messenger_name => $settings) {
921 921
             unset(
922
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
922
+                $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]
923 923
             );
924 924
 
925 925
             //we always record (even on deactivation) that a message type has been activated because there should at
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
     {
946 946
         $this->_initialize_collections();
947 947
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
948
+            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
949 949
         }
950 950
         $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951 951
             array($message_type_name));
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
         $all_message_types_valid           = true;
1040 1040
         //loop through list of active message types and verify they are installed.
1041 1041
         foreach ($list_of_active_message_type_names as $message_type_name) {
1042
-            if (! isset($installed_message_types[$message_type_name])) {
1042
+            if ( ! isset($installed_message_types[$message_type_name])) {
1043 1043
                 $this->remove_message_type_has_been_activated_from_all_messengers(
1044 1044
                     $message_type_name,
1045 1045
                     true
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
         $message_type_name,
1121 1121
         $consider_current_state = false
1122 1122
     ) {
1123
-        foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1123
+        foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124 1124
             $this->remove_message_type_has_been_activated_for_messenger(
1125 1125
                 $message_type_name,
1126 1126
                 $messenger_name,
Please login to merge, or discard this patch.
core/services/loaders/LoaderFactory.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
      */
35 35
     public static function getLoader()
36 36
     {
37
-        if (! LoaderFactory::$loader instanceof LoaderInterface) {
37
+        if ( ! LoaderFactory::$loader instanceof LoaderInterface) {
38 38
             LoaderFactory::$loader = new Loader();
39 39
         }
40 40
         return LoaderFactory::$loader;
Please login to merge, or discard this patch.
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -77,26 +77,26 @@
 block discarded – undo
77 77
 class LoaderFactory
78 78
 {
79 79
 
80
-    /**
81
-     * @var LoaderInterface $loader ;
82
-     */
83
-    private static $loader;
80
+	/**
81
+	 * @var LoaderInterface $loader ;
82
+	 */
83
+	private static $loader;
84 84
 
85 85
 
86 86
 
87
-    /**
88
-     * @return LoaderInterface
89
-     * @throws InvalidArgumentException
90
-     * @throws InvalidInterfaceException
91
-     * @throws InvalidDataTypeException
92
-     */
93
-    public static function getLoader()
94
-    {
95
-        if (! LoaderFactory::$loader instanceof LoaderInterface) {
96
-            LoaderFactory::$loader = new Loader();
97
-        }
98
-        return LoaderFactory::$loader;
99
-    }
87
+	/**
88
+	 * @return LoaderInterface
89
+	 * @throws InvalidArgumentException
90
+	 * @throws InvalidInterfaceException
91
+	 * @throws InvalidDataTypeException
92
+	 */
93
+	public static function getLoader()
94
+	{
95
+		if (! LoaderFactory::$loader instanceof LoaderInterface) {
96
+			LoaderFactory::$loader = new Loader();
97
+		}
98
+		return LoaderFactory::$loader;
99
+	}
100 100
 
101 101
 
102 102
 }
Please login to merge, or discard this patch.
core/EE_Maintenance_Mode.core.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     public static function instance()
59 59
     {
60 60
         // check if class object is instantiated
61
-        if (! self::$_instance instanceof EE_Maintenance_Mode) {
61
+        if ( ! self::$_instance instanceof EE_Maintenance_Mode) {
62 62
             self::$_instance = new self();
63 63
         }
64 64
         return self::$_instance;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     public function set_maintenance_level($level)
178 178
     {
179 179
         do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
180
-        update_option(self::option_name_maintenance_mode, (int)$level);
180
+        update_option(self::option_name_maintenance_mode, (int) $level);
181 181
     }
182 182
 
183 183
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      */
190 190
     public static function disable_frontend_for_maintenance()
191 191
     {
192
-        return (! is_admin() && EE_Maintenance_Mode::instance()->level());
192
+        return ( ! is_admin() && EE_Maintenance_Mode::instance()->level());
193 193
     }
194 194
 
195 195
 
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
         ) {
206 206
             wp_register_style(
207 207
                 'espresso_default',
208
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
208
+                EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
209 209
                 array('dashicons'),
210 210
                 EVENT_ESPRESSO_VERSION
211 211
             );
212 212
             wp_enqueue_style('espresso_default');
213 213
             wp_register_script(
214 214
                 'espresso_core',
215
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
215
+                EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
216 216
                 array('jquery'),
217 217
                 EVENT_ESPRESSO_VERSION,
218 218
                 true
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     public static function template_include()
234 234
     {
235 235
         // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
236
-        return get_template_directory() . '/index.php';
236
+        return get_template_directory().'/index.php';
237 237
     }
238 238
 
239 239
 
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
                 ),
286 286
                 '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
287 287
                 '"><span class="dashicons dashicons-no"></span></a><p>',
288
-                ' &raquo; <a href="' . add_query_arg(
288
+                ' &raquo; <a href="'.add_query_arg(
289 289
                     array('page' => 'espresso_maintenance_settings'), admin_url('admin.php')
290
-                ) . '">',
290
+                ).'">',
291 291
                 '</a></p></div>'
292 292
             );
293 293
         }
Please login to merge, or discard this patch.
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -17,362 +17,362 @@
 block discarded – undo
17 17
 class EE_Maintenance_Mode implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
22
-     * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
23
-     */
24
-    const level_0_not_in_maintenance = 0;
25
-
26
-    /**
27
-     * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
28
-     * but the admin backend should be running as normal. Maybe an admin can view the frontend though
29
-     */
30
-    const level_1_frontend_only_maintenance = 1;
31
-
32
-    /**
33
-     * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
34
-     * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
35
-     * migration scripts before taking the site out of maintenance mode
36
-     */
37
-    const level_2_complete_maintenance = 2;
38
-
39
-    /**
40
-     * the name of the option which stores the current level of maintenance mode
41
-     */
42
-    const option_name_maintenance_mode = 'ee_maintenance_mode';
43
-
44
-
45
-    /**
46
-     * @var EE_Maintenance_Mode $_instance
47
-     */
48
-    private static $_instance;
49
-
50
-    /**
51
-     * @var EE_Registry $EE
52
-     */
53
-    protected $EE;
54
-
55
-
56
-
57
-    /**
58
-     * @singleton method used to instantiate class object
59
-     * @return EE_Maintenance_Mode
60
-     */
61
-    public static function instance()
62
-    {
63
-        // check if class object is instantiated
64
-        if (! self::$_instance instanceof EE_Maintenance_Mode) {
65
-            self::$_instance = new self();
66
-        }
67
-        return self::$_instance;
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode)
74
-     *
75
-     * @return EE_Maintenance_Mode
76
-     */
77
-    public static function reset()
78
-    {
79
-        self::instance()->set_maintenance_mode_if_db_old();
80
-        return self::instance();
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     *private constructor to prevent direct creation
87
-     */
88
-    private function __construct()
89
-    {
90
-        // if M-Mode level 2 is engaged, we still need basic assets loaded
91
-        add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode'));
92
-        // shut 'er down down for maintenance ?
93
-        add_filter('the_content', array($this, 'the_content'), 2);
94
-        // add powered by EE msg
95
-        add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10);
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * retrieves the maintenance mode option value from the db
102
-     *
103
-     * @return int
104
-     */
105
-    public function real_level()
106
-    {
107
-        return get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Returns whether or not the models reportedly are able to run queries or not
114
-     * (ie, if the system thinks their tables are present and up-to-date).
115
-     *
116
-     * @return boolean
117
-     */
118
-    public function models_can_query()
119
-    {
120
-        return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * Determines whether or not we're in maintenance mode and what level. However, while the site
127
-     * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
128
-     * to them as if teh site isn't in maintenance mode.
129
-     * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
130
-     * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
131
-     * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
132
-     *
133
-     * @return int
134
-     */
135
-    public function level()
136
-    {
137
-        $maintenance_mode_level = $this->real_level();
138
-        // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
139
-        if (
140
-            $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
141
-            && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
142
-            && current_user_can('administrator') // when the user is an admin
143
-        ) {
144
-            $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
145
-        }
146
-        return $maintenance_mode_level;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * Determines if we need to put EE in maintenance mode because the database needs updating
153
-     *
154
-     * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
155
-     */
156
-    public function set_maintenance_mode_if_db_old()
157
-    {
158
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
159
-        if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
160
-            update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
161
-            return true;
162
-        }
163
-        if ($this->level() === self::level_2_complete_maintenance) {
164
-            //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
165
-            //then we shouldn't be in mm2. (Maybe an addon got deactivated?)
166
-            update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
167
-            return false;
168
-        }
169
-        return false;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Updates the maintenance level on the site
176
-     *
177
-     * @param int $level
178
-     * @return void
179
-     */
180
-    public function set_maintenance_level($level)
181
-    {
182
-        do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
183
-        update_option(self::option_name_maintenance_mode, (int)$level);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * returns TRUE if M-Mode is engaged and the current request is not for the admin
190
-     *
191
-     * @return    string
192
-     */
193
-    public static function disable_frontend_for_maintenance()
194
-    {
195
-        return (! is_admin() && EE_Maintenance_Mode::instance()->level());
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @return void
202
-     */
203
-    public function load_assets_required_for_m_mode()
204
-    {
205
-        if (
206
-            $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
207
-            && ! wp_script_is('espresso_core')
208
-        ) {
209
-            wp_register_style(
210
-                'espresso_default',
211
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
212
-                array('dashicons'),
213
-                EVENT_ESPRESSO_VERSION
214
-            );
215
-            wp_enqueue_style('espresso_default');
216
-            wp_register_script(
217
-                'espresso_core',
218
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
219
-                array('jquery'),
220
-                EVENT_ESPRESSO_VERSION,
221
-                true
222
-            );
223
-            wp_enqueue_script('espresso_core');
224
-        }
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * replacement EE CPT template that displays message notifying site visitors
231
-     * that EE has been temporarily placed into maintenance mode
232
-     * does NOT get called on non-EE-CPT requests
233
-     *
234
-     * @return    string
235
-     */
236
-    public static function template_include()
237
-    {
238
-        // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
239
-        return get_template_directory() . '/index.php';
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * displays message notifying site visitors that EE has been temporarily
246
-     * placed into maintenance mode when post_type != EE CPT
247
-     *
248
-     * @param string $the_content
249
-     * @return string
250
-     */
251
-    public function the_content($the_content)
252
-    {
253
-        // check if M-mode is engaged and for EE shortcode
254
-        if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
255
-            // this can eventually be moved to a template, or edited via admin. But for now...
256
-            $the_content = sprintf(
257
-                esc_html__(
258
-                    '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s',
259
-                    'event_espresso'
260
-                ),
261
-                '<h3>',
262
-                '</h3><p>',
263
-                '</p>'
264
-            );
265
-        }
266
-        return $the_content;
267
-    }
20
+	/**
21
+	 * constants available to client code for interpreting the values of EE_Maintenance_Mode::level().
22
+	 * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal)
23
+	 */
24
+	const level_0_not_in_maintenance = 0;
25
+
26
+	/**
27
+	 * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled
28
+	 * but the admin backend should be running as normal. Maybe an admin can view the frontend though
29
+	 */
30
+	const level_1_frontend_only_maintenance = 1;
31
+
32
+	/**
33
+	 * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running
34
+	 * is the maintenance mode stuff, which will require users to update all addons, and then finish running all
35
+	 * migration scripts before taking the site out of maintenance mode
36
+	 */
37
+	const level_2_complete_maintenance = 2;
38
+
39
+	/**
40
+	 * the name of the option which stores the current level of maintenance mode
41
+	 */
42
+	const option_name_maintenance_mode = 'ee_maintenance_mode';
43
+
44
+
45
+	/**
46
+	 * @var EE_Maintenance_Mode $_instance
47
+	 */
48
+	private static $_instance;
49
+
50
+	/**
51
+	 * @var EE_Registry $EE
52
+	 */
53
+	protected $EE;
54
+
55
+
56
+
57
+	/**
58
+	 * @singleton method used to instantiate class object
59
+	 * @return EE_Maintenance_Mode
60
+	 */
61
+	public static function instance()
62
+	{
63
+		// check if class object is instantiated
64
+		if (! self::$_instance instanceof EE_Maintenance_Mode) {
65
+			self::$_instance = new self();
66
+		}
67
+		return self::$_instance;
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode)
74
+	 *
75
+	 * @return EE_Maintenance_Mode
76
+	 */
77
+	public static function reset()
78
+	{
79
+		self::instance()->set_maintenance_mode_if_db_old();
80
+		return self::instance();
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 *private constructor to prevent direct creation
87
+	 */
88
+	private function __construct()
89
+	{
90
+		// if M-Mode level 2 is engaged, we still need basic assets loaded
91
+		add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode'));
92
+		// shut 'er down down for maintenance ?
93
+		add_filter('the_content', array($this, 'the_content'), 2);
94
+		// add powered by EE msg
95
+		add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10);
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * retrieves the maintenance mode option value from the db
102
+	 *
103
+	 * @return int
104
+	 */
105
+	public function real_level()
106
+	{
107
+		return get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance);
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Returns whether or not the models reportedly are able to run queries or not
114
+	 * (ie, if the system thinks their tables are present and up-to-date).
115
+	 *
116
+	 * @return boolean
117
+	 */
118
+	public function models_can_query()
119
+	{
120
+		return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * Determines whether or not we're in maintenance mode and what level. However, while the site
127
+	 * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear
128
+	 * to them as if teh site isn't in maintenance mode.
129
+	 * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode)
130
+	 * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode
131
+	 * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode
132
+	 *
133
+	 * @return int
134
+	 */
135
+	public function level()
136
+	{
137
+		$maintenance_mode_level = $this->real_level();
138
+		// if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend
139
+		if (
140
+			$maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1
141
+			&& ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests
142
+			&& current_user_can('administrator') // when the user is an admin
143
+		) {
144
+			$maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance;
145
+		}
146
+		return $maintenance_mode_level;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * Determines if we need to put EE in maintenance mode because the database needs updating
153
+	 *
154
+	 * @return boolean true if DB is old and maintenance mode was triggered; false otherwise
155
+	 */
156
+	public function set_maintenance_mode_if_db_old()
157
+	{
158
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
159
+		if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
160
+			update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance);
161
+			return true;
162
+		}
163
+		if ($this->level() === self::level_2_complete_maintenance) {
164
+			//we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run
165
+			//then we shouldn't be in mm2. (Maybe an addon got deactivated?)
166
+			update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance);
167
+			return false;
168
+		}
169
+		return false;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Updates the maintenance level on the site
176
+	 *
177
+	 * @param int $level
178
+	 * @return void
179
+	 */
180
+	public function set_maintenance_level($level)
181
+	{
182
+		do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level);
183
+		update_option(self::option_name_maintenance_mode, (int)$level);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * returns TRUE if M-Mode is engaged and the current request is not for the admin
190
+	 *
191
+	 * @return    string
192
+	 */
193
+	public static function disable_frontend_for_maintenance()
194
+	{
195
+		return (! is_admin() && EE_Maintenance_Mode::instance()->level());
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @return void
202
+	 */
203
+	public function load_assets_required_for_m_mode()
204
+	{
205
+		if (
206
+			$this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance
207
+			&& ! wp_script_is('espresso_core')
208
+		) {
209
+			wp_register_style(
210
+				'espresso_default',
211
+				EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
212
+				array('dashicons'),
213
+				EVENT_ESPRESSO_VERSION
214
+			);
215
+			wp_enqueue_style('espresso_default');
216
+			wp_register_script(
217
+				'espresso_core',
218
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
219
+				array('jquery'),
220
+				EVENT_ESPRESSO_VERSION,
221
+				true
222
+			);
223
+			wp_enqueue_script('espresso_core');
224
+		}
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * replacement EE CPT template that displays message notifying site visitors
231
+	 * that EE has been temporarily placed into maintenance mode
232
+	 * does NOT get called on non-EE-CPT requests
233
+	 *
234
+	 * @return    string
235
+	 */
236
+	public static function template_include()
237
+	{
238
+		// shut 'er down down for maintenance ? then don't use any of our templates for our endpoints
239
+		return get_template_directory() . '/index.php';
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * displays message notifying site visitors that EE has been temporarily
246
+	 * placed into maintenance mode when post_type != EE CPT
247
+	 *
248
+	 * @param string $the_content
249
+	 * @return string
250
+	 */
251
+	public function the_content($the_content)
252
+	{
253
+		// check if M-mode is engaged and for EE shortcode
254
+		if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) {
255
+			// this can eventually be moved to a template, or edited via admin. But for now...
256
+			$the_content = sprintf(
257
+				esc_html__(
258
+					'%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s',
259
+					'event_espresso'
260
+				),
261
+				'<h3>',
262
+				'</h3><p>',
263
+				'</p>'
264
+			);
265
+		}
266
+		return $the_content;
267
+	}
268 268
 
269 269
 
270 270
 
271
-    /**
272
-     * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
273
-     */
274
-    public function display_maintenance_mode_notice()
275
-    {
276
-        // check if M-mode is engaged and for EE shortcode
277
-        if (
278
-            ! (defined('DOING_AJAX') && DOING_AJAX)
279
-            && $this->real_level()
280
-            && ! is_admin()
281
-            && current_user_can('administrator')
282
-            && EE_Registry::instance()->REQ->is_espresso_page()
283
-        ) {
284
-            printf(
285
-                esc_html__(
286
-                    '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s',
287
-                    'event_espresso'
288
-                ),
289
-                '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
290
-                '"><span class="dashicons dashicons-no"></span></a><p>',
291
-                ' &raquo; <a href="' . add_query_arg(
292
-                    array('page' => 'espresso_maintenance_settings'), admin_url('admin.php')
293
-                ) . '">',
294
-                '</a></p></div>'
295
-            );
296
-        }
297
-    }
298
-    // espresso-notices important-notice ee-attention
271
+	/**
272
+	 * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
273
+	 */
274
+	public function display_maintenance_mode_notice()
275
+	{
276
+		// check if M-mode is engaged and for EE shortcode
277
+		if (
278
+			! (defined('DOING_AJAX') && DOING_AJAX)
279
+			&& $this->real_level()
280
+			&& ! is_admin()
281
+			&& current_user_can('administrator')
282
+			&& EE_Registry::instance()->REQ->is_espresso_page()
283
+		) {
284
+			printf(
285
+				esc_html__(
286
+					'%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s',
287
+					'event_espresso'
288
+				),
289
+				'<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="',
290
+				'"><span class="dashicons dashicons-no"></span></a><p>',
291
+				' &raquo; <a href="' . add_query_arg(
292
+					array('page' => 'espresso_maintenance_settings'), admin_url('admin.php')
293
+				) . '">',
294
+				'</a></p></div>'
295
+			);
296
+		}
297
+	}
298
+	// espresso-notices important-notice ee-attention
299 299
 
300 300
 
301 301
 
302
-    /**
303
-     * override magic methods
304
-     */
305
-    final public function __destruct()
306
-    {
307
-    }
302
+	/**
303
+	 * override magic methods
304
+	 */
305
+	final public function __destruct()
306
+	{
307
+	}
308 308
 
309 309
 
310 310
 
311
-    final public function __call($a, $b)
312
-    {
313
-    }
311
+	final public function __call($a, $b)
312
+	{
313
+	}
314 314
 
315 315
 
316 316
 
317
-    final public function __get($a)
318
-    {
319
-    }
317
+	final public function __get($a)
318
+	{
319
+	}
320 320
 
321 321
 
322 322
 
323
-    final public function __set($a, $b)
324
-    {
325
-    }
323
+	final public function __set($a, $b)
324
+	{
325
+	}
326 326
 
327 327
 
328 328
 
329
-    final public function __isset($a)
330
-    {
331
-    }
329
+	final public function __isset($a)
330
+	{
331
+	}
332 332
 
333 333
 
334 334
 
335
-    final public function __unset($a)
336
-    {
337
-    }
335
+	final public function __unset($a)
336
+	{
337
+	}
338 338
 
339 339
 
340 340
 
341
-    final public function __sleep()
342
-    {
343
-        return array();
344
-    }
341
+	final public function __sleep()
342
+	{
343
+		return array();
344
+	}
345 345
 
346 346
 
347 347
 
348
-    final public function __wakeup()
349
-    {
350
-    }
348
+	final public function __wakeup()
349
+	{
350
+	}
351 351
 
352 352
 
353 353
 
354
-    final public function __invoke()
355
-    {
356
-    }
354
+	final public function __invoke()
355
+	{
356
+	}
357 357
 
358 358
 
359 359
 
360
-    final public static function __set_state($a = null)
361
-    {
362
-        return EE_Maintenance_Mode::instance();
363
-    }
360
+	final public static function __set_state($a = null)
361
+	{
362
+		return EE_Maintenance_Mode::instance();
363
+	}
364 364
 
365 365
 
366 366
 
367
-    final public function __clone()
368
-    {
369
-    }
367
+	final public function __clone()
368
+	{
369
+	}
370 370
 
371 371
 
372 372
 
373
-    final public static function __callStatic($a, $b)
374
-    {
375
-    }
373
+	final public static function __callStatic($a, $b)
374
+	{
375
+	}
376 376
 
377 377
 }
378 378
 // End of file EE_Maintenance_Mode.core.php
Please login to merge, or discard this patch.
core/db_models/EEM_Attendee.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -351,7 +351,7 @@
 block discarded – undo
351 351
      * retrieve  a single attendee from db via their ID
352 352
      *
353 353
      * @param $ATT_ID
354
-     * @return mixed array on success, FALSE on fail
354
+     * @return EE_Base_Class|null array on success, FALSE on fail
355 355
      * @deprecated
356 356
      */
357 357
     public function get_attendee_by_ID($ATT_ID = false)
Please login to merge, or discard this patch.
Indentation   +417 added lines, -417 removed lines patch added patch discarded remove patch
@@ -16,431 +16,431 @@
 block discarded – undo
16 16
 class EEM_Attendee extends EEM_CPT_Base
17 17
 {
18 18
 
19
-    // private instance of the Attendee object
20
-    protected static $_instance = null;
19
+	// private instance of the Attendee object
20
+	protected static $_instance = null;
21 21
 
22
-    /**
23
-     * QST_system for questions are strings not integers now,
24
-     * so these constants are deprecated.
25
-     * Please instead use the EEM_Attendee::system_question_* constants
26
-     *
27
-     * @deprecated
28
-     */
29
-    const fname_question_id = 1;
22
+	/**
23
+	 * QST_system for questions are strings not integers now,
24
+	 * so these constants are deprecated.
25
+	 * Please instead use the EEM_Attendee::system_question_* constants
26
+	 *
27
+	 * @deprecated
28
+	 */
29
+	const fname_question_id = 1;
30 30
 
31
-    /**
32
-     * @deprecated
33
-     */
34
-    const lname_question_id = 2;
31
+	/**
32
+	 * @deprecated
33
+	 */
34
+	const lname_question_id = 2;
35 35
 
36 36
 
37
-    /**
38
-     * @deprecated
39
-     */
40
-    const email_question_id = 3;
37
+	/**
38
+	 * @deprecated
39
+	 */
40
+	const email_question_id = 3;
41 41
 
42 42
 
43
-    /**
44
-     * @deprecated
45
-     */
46
-    const address_question_id = 4;
43
+	/**
44
+	 * @deprecated
45
+	 */
46
+	const address_question_id = 4;
47 47
 
48 48
 
49
-    /**
50
-     * @deprecated
51
-     */
52
-    const address2_question_id = 5;
53
-
54
-
55
-    /**
56
-     * @deprecated
57
-     */
58
-    const city_question_id = 6;
59
-
60
-
61
-    /**
62
-     * @deprecated
63
-     */
64
-    const state_question_id = 7;
65
-
66
-
67
-    /**
68
-     * @deprecated
69
-     */
70
-    const country_question_id = 8;
71
-
72
-
73
-    /**
74
-     * @deprecated
75
-     */
76
-    const zip_question_id = 9;
77
-
78
-
79
-    /**
80
-     * @deprecated
81
-     */
82
-    const phone_question_id = 10;
83
-
84
-    /**
85
-     * When looking for questions that correspond to attendee fields,
86
-     * look for the question with this QST_system value.
87
-     * These replace the old constants like EEM_Attendee::*_question_id
88
-     */
89
-    const system_question_fname = 'fname';
90
-
91
-    const system_question_lname = 'lname';
92
-
93
-    const system_question_email = 'email';
94
-
95
-    const system_question_address = 'address';
96
-
97
-    const system_question_address2 = 'address2';
98
-
99
-    const system_question_city = 'city';
100
-
101
-    const system_question_state = 'state';
102
-
103
-    const system_question_country = 'country';
104
-
105
-    const system_question_zip = 'zip';
106
-
107
-    const system_question_phone = 'phone';
108
-
109
-    /**
110
-     * Keys are all the EEM_Attendee::system_question_* constants, which are
111
-     * also all the values of QST_system in the questions table, and values
112
-     * are their corresponding Attendee field names
113
-     *
114
-     * @var array
115
-     */
116
-    protected $_system_question_to_attendee_field_name = array(
117
-        EEM_Attendee::system_question_fname    => 'ATT_fname',
118
-        EEM_Attendee::system_question_lname    => 'ATT_lname',
119
-        EEM_Attendee::system_question_email    => 'ATT_email',
120
-        EEM_Attendee::system_question_address  => 'ATT_address',
121
-        EEM_Attendee::system_question_address2 => 'ATT_address2',
122
-        EEM_Attendee::system_question_city     => 'ATT_city',
123
-        EEM_Attendee::system_question_state    => 'STA_ID',
124
-        EEM_Attendee::system_question_country  => 'CNT_ISO',
125
-        EEM_Attendee::system_question_zip      => 'ATT_zip',
126
-        EEM_Attendee::system_question_phone    => 'ATT_phone',
127
-    );
128
-
129
-
130
-
131
-    /**
132
-     * EEM_Attendee constructor.
133
-     *
134
-     * @param null $timezone
135
-     * @throws EE_Error
136
-     */
137
-    protected function __construct($timezone = null)
138
-    {
139
-        $this->singular_item = esc_html__('Attendee', 'event_espresso');
140
-        $this->plural_item = esc_html__('Attendees', 'event_espresso');
141
-        $this->_tables = array(
142
-            'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
143
-            'Attendee_Meta' => new EE_Secondary_Table(
144
-                'esp_attendee_meta',
145
-                'ATTM_ID',
146
-                'ATT_ID'
147
-            ),
148
-        );
149
-        $this->_fields = array(
150
-            'Attendee_CPT'  => array(
151
-                'ATT_ID'        => new EE_Primary_Key_Int_Field(
152
-                    'ID',
153
-                    esc_html__('Attendee ID', 'event_espresso')
154
-                ),
155
-                'ATT_full_name' => new EE_Plain_Text_Field(
156
-                    'post_title',
157
-                    esc_html__('Attendee Full Name', 'event_espresso'),
158
-                    false,
159
-                    esc_html__('Unknown', 'event_espresso')
160
-                ),
161
-                'ATT_bio'       => new EE_Post_Content_Field(
162
-                    'post_content',
163
-                    esc_html__('Attendee Biography', 'event_espresso'),
164
-                    false,
165
-                    esc_html__('No Biography Provided', 'event_espresso')
166
-                ),
167
-                'ATT_slug'      => new EE_Slug_Field(
168
-                    'post_name',
169
-                    esc_html__('Attendee URL Slug', 'event_espresso'),
170
-                    false
171
-                ),
172
-                'ATT_created'   => new EE_Datetime_Field(
173
-                    'post_date',
174
-                    esc_html__('Time Attendee Created', 'event_espresso'),
175
-                    false,
176
-                    EE_Datetime_Field::now
177
-                ),
178
-                'ATT_short_bio' => new EE_Simple_HTML_Field(
179
-                    'post_excerpt',
180
-                    esc_html__('Attendee Short Biography', 'event_espresso'),
181
-                    true,
182
-                    esc_html__('No Biography Provided', 'event_espresso')
183
-                ),
184
-                'ATT_modified'  => new EE_Datetime_Field(
185
-                    'post_modified',
186
-                    esc_html__('Time Attendee Last Modified', 'event_espresso'),
187
-                    false,
188
-                    EE_Datetime_Field::now
189
-                ),
190
-                'ATT_author'    => new EE_WP_User_Field(
191
-                    'post_author',
192
-                    esc_html__('Creator ID of the first Event attended', 'event_espresso'),
193
-                    false
194
-                ),
195
-                'ATT_parent'    => new EE_DB_Only_Int_Field(
196
-                    'post_parent',
197
-                    esc_html__('Parent Attendee (unused)', 'event_espresso'),
198
-                    false,
199
-                    0
200
-                ),
201
-                'post_type'     => new EE_WP_Post_Type_Field('espresso_attendees'),
202
-                'status'        => new EE_WP_Post_Status_Field(
203
-                    'post_status',
204
-                    esc_html__('Attendee Status', 'event_espresso'),
205
-                    false,
206
-                    'publish'
207
-                ),
208
-            ),
209
-            'Attendee_Meta' => array(
210
-                'ATTM_ID'      => new EE_DB_Only_Int_Field(
211
-                    'ATTM_ID',
212
-                    esc_html__('Attendee Meta Row ID', 'event_espresso'),
213
-                    false
214
-                ),
215
-                'ATT_ID_fk'    => new EE_DB_Only_Int_Field(
216
-                    'ATT_ID',
217
-                    esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'),
218
-                    false
219
-                ),
220
-                'ATT_fname'    => new EE_Plain_Text_Field(
221
-                    'ATT_fname',
222
-                    esc_html__('First Name', 'event_espresso'),
223
-                    true,
224
-                    ''
225
-                ),
226
-                'ATT_lname'    => new EE_Plain_Text_Field(
227
-                    'ATT_lname', esc_html__('Last Name', 'event_espresso'),
228
-                    true,
229
-                    ''
230
-                ),
231
-                'ATT_address'  => new EE_Plain_Text_Field(
232
-                    'ATT_address',
233
-                    esc_html__('Address Part 1', 'event_espresso'),
234
-                    true,
235
-                    ''
236
-                ),
237
-                'ATT_address2' => new EE_Plain_Text_Field(
238
-                    'ATT_address2',
239
-                    esc_html__('Address Part 2', 'event_espresso'),
240
-                    true,
241
-                    ''
242
-                ),
243
-                'ATT_city'     => new EE_Plain_Text_Field(
244
-                    'ATT_city',
245
-                    esc_html__('City', 'event_espresso'),
246
-                    true,
247
-                    ''
248
-                ),
249
-                'STA_ID'       => new EE_Foreign_Key_Int_Field(
250
-                    'STA_ID',
251
-                    esc_html__('State', 'event_espresso'),
252
-                    true,
253
-                    0,
254
-                    'State'
255
-                ),
256
-                'CNT_ISO'      => new EE_Foreign_Key_String_Field(
257
-                    'CNT_ISO',
258
-                    esc_html__('Country', 'event_espresso'),
259
-                    true,
260
-                    '',
261
-                    'Country'
262
-                ),
263
-                'ATT_zip'      => new EE_Plain_Text_Field(
264
-                    'ATT_zip',
265
-                    esc_html__('ZIP/Postal Code', 'event_espresso'),
266
-                    true,
267
-                    ''
268
-                ),
269
-                'ATT_email'    => new EE_Email_Field(
270
-                    'ATT_email',
271
-                    esc_html__('Email Address', 'event_espresso'),
272
-                    true,
273
-                    ''
274
-                ),
275
-                'ATT_phone'    => new EE_Plain_Text_Field(
276
-                    'ATT_phone',
277
-                    esc_html__('Phone', 'event_espresso'),
278
-                    true,
279
-                    ''
280
-                ),
281
-            ),
282
-        );
283
-        $this->_model_relations = array(
284
-            'Registration'      => new EE_Has_Many_Relation(),
285
-            'State'             => new EE_Belongs_To_Relation(),
286
-            'Country'           => new EE_Belongs_To_Relation(),
287
-            'Event'             => new EE_HABTM_Relation('Registration', false),
288
-            'WP_User'           => new EE_Belongs_To_Relation(),
289
-            'Message'           => new EE_Has_Many_Any_Relation(false),
290
-            //allow deletion of attendees even if they have messages in the queue for them.
291
-            'Term_Relationship' => new EE_Has_Many_Relation(),
292
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
293
-        );
294
-        $this->_caps_slug = 'contacts';
295
-        parent::__construct($timezone);
296
-    }
297
-
298
-
299
-
300
-    /**
301
-     * Gets the name of the field on the attendee model corresponding to the system question string
302
-     * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
303
-     *
304
-     * @param string $system_question_string
305
-     * @return string|null if not found
306
-     */
307
-    public function get_attendee_field_for_system_question($system_question_string)
308
-    {
309
-        return isset($this->_system_question_to_attendee_field_name[$system_question_string])
310
-            ? $this->_system_question_to_attendee_field_name[$system_question_string]
311
-            : null;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
318
-     *
319
-     * @return array
320
-     */
321
-    public function system_question_to_attendee_field_mapping()
322
-    {
323
-        return $this->_system_question_to_attendee_field_name;
324
-    }
325
-
326
-
327
-
328
-    /**
329
-     * Gets all the attendees for a transaction (by using the esp_registration as a join table)
330
-     *
331
-     * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
332
-     * @return EE_Attendee[]|EE_Base_Class[]
333
-     * @throws EE_Error
334
-     */
335
-    public function get_attendees_for_transaction($transaction_id_or_obj)
336
-    {
337
-        return $this->get_all(
338
-            array(
339
-                array(
340
-                    'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
341
-                        ? $transaction_id_or_obj->ID()
342
-                        : $transaction_id_or_obj,
343
-                ),
344
-            )
345
-        );
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * retrieve  a single attendee from db via their ID
352
-     *
353
-     * @param $ATT_ID
354
-     * @return mixed array on success, FALSE on fail
355
-     * @deprecated
356
-     */
357
-    public function get_attendee_by_ID($ATT_ID = false)
358
-    {
359
-        // retrieve a particular EE_Attendee
360
-        return $this->get_one_by_ID($ATT_ID);
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * retrieve  a single attendee from db via their ID
367
-     *
368
-     * @param array $where_cols_n_values
369
-     * @return mixed array on success, FALSE on fail
370
-     * @throws EE_Error
371
-     */
372
-    public function get_attendee($where_cols_n_values = array())
373
-    {
374
-        if (empty($where_cols_n_values)) {
375
-            return false;
376
-        }
377
-        $attendee = $this->get_all(array($where_cols_n_values));
378
-        if (! empty($attendee)) {
379
-            return array_shift($attendee);
380
-        }
381
-        return false;
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     * Search for an existing Attendee record in the DB
388
-     *
389
-     * @param array $where_cols_n_values
390
-     * @return bool|mixed
391
-     * @throws EE_Error
392
-     */
393
-    public function find_existing_attendee($where_cols_n_values = null)
394
-    {
395
-        // search by combo of first and last names plus the email address
396
-        $attendee_data_keys = array(
397
-            'ATT_fname' => $this->_ATT_fname,
398
-            'ATT_lname' => $this->_ATT_lname,
399
-            'ATT_email' => $this->_ATT_email,
400
-        );
401
-        // no search params means attendee object already exists.
402
-        $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values)
403
-            ? $where_cols_n_values
404
-            : $attendee_data_keys;
405
-        $valid_data = true;
406
-        // check for required values
407
-        $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
408
-            ? $valid_data
409
-            : false;
410
-        $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
411
-            ? $valid_data
412
-            : false;
413
-        $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
414
-            ? $valid_data
415
-            : false;
416
-        if ($valid_data) {
417
-            $attendee = $this->get_attendee($where_cols_n_values);
418
-            if ($attendee instanceof EE_Attendee) {
419
-                return $attendee;
420
-            }
421
-        }
422
-        return false;
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * Takes an incoming array of EE_Registration ids
429
-     * and sends back a list of corresponding non duplicate EE_Attendee objects.
430
-     *
431
-     * @since  4.3.0
432
-     * @param  array $ids array of EE_Registration ids
433
-     * @return EE_Attendee[]|EE_Base_Class[]
434
-     * @throws EE_Error
435
-     */
436
-    public function get_array_of_contacts_from_reg_ids($ids)
437
-    {
438
-        $ids = (array)$ids;
439
-        $_where = array(
440
-            'Registration.REG_ID' => array('in', $ids),
441
-        );
442
-        return $this->get_all(array($_where));
443
-    }
49
+	/**
50
+	 * @deprecated
51
+	 */
52
+	const address2_question_id = 5;
53
+
54
+
55
+	/**
56
+	 * @deprecated
57
+	 */
58
+	const city_question_id = 6;
59
+
60
+
61
+	/**
62
+	 * @deprecated
63
+	 */
64
+	const state_question_id = 7;
65
+
66
+
67
+	/**
68
+	 * @deprecated
69
+	 */
70
+	const country_question_id = 8;
71
+
72
+
73
+	/**
74
+	 * @deprecated
75
+	 */
76
+	const zip_question_id = 9;
77
+
78
+
79
+	/**
80
+	 * @deprecated
81
+	 */
82
+	const phone_question_id = 10;
83
+
84
+	/**
85
+	 * When looking for questions that correspond to attendee fields,
86
+	 * look for the question with this QST_system value.
87
+	 * These replace the old constants like EEM_Attendee::*_question_id
88
+	 */
89
+	const system_question_fname = 'fname';
90
+
91
+	const system_question_lname = 'lname';
92
+
93
+	const system_question_email = 'email';
94
+
95
+	const system_question_address = 'address';
96
+
97
+	const system_question_address2 = 'address2';
98
+
99
+	const system_question_city = 'city';
100
+
101
+	const system_question_state = 'state';
102
+
103
+	const system_question_country = 'country';
104
+
105
+	const system_question_zip = 'zip';
106
+
107
+	const system_question_phone = 'phone';
108
+
109
+	/**
110
+	 * Keys are all the EEM_Attendee::system_question_* constants, which are
111
+	 * also all the values of QST_system in the questions table, and values
112
+	 * are their corresponding Attendee field names
113
+	 *
114
+	 * @var array
115
+	 */
116
+	protected $_system_question_to_attendee_field_name = array(
117
+		EEM_Attendee::system_question_fname    => 'ATT_fname',
118
+		EEM_Attendee::system_question_lname    => 'ATT_lname',
119
+		EEM_Attendee::system_question_email    => 'ATT_email',
120
+		EEM_Attendee::system_question_address  => 'ATT_address',
121
+		EEM_Attendee::system_question_address2 => 'ATT_address2',
122
+		EEM_Attendee::system_question_city     => 'ATT_city',
123
+		EEM_Attendee::system_question_state    => 'STA_ID',
124
+		EEM_Attendee::system_question_country  => 'CNT_ISO',
125
+		EEM_Attendee::system_question_zip      => 'ATT_zip',
126
+		EEM_Attendee::system_question_phone    => 'ATT_phone',
127
+	);
128
+
129
+
130
+
131
+	/**
132
+	 * EEM_Attendee constructor.
133
+	 *
134
+	 * @param null $timezone
135
+	 * @throws EE_Error
136
+	 */
137
+	protected function __construct($timezone = null)
138
+	{
139
+		$this->singular_item = esc_html__('Attendee', 'event_espresso');
140
+		$this->plural_item = esc_html__('Attendees', 'event_espresso');
141
+		$this->_tables = array(
142
+			'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
143
+			'Attendee_Meta' => new EE_Secondary_Table(
144
+				'esp_attendee_meta',
145
+				'ATTM_ID',
146
+				'ATT_ID'
147
+			),
148
+		);
149
+		$this->_fields = array(
150
+			'Attendee_CPT'  => array(
151
+				'ATT_ID'        => new EE_Primary_Key_Int_Field(
152
+					'ID',
153
+					esc_html__('Attendee ID', 'event_espresso')
154
+				),
155
+				'ATT_full_name' => new EE_Plain_Text_Field(
156
+					'post_title',
157
+					esc_html__('Attendee Full Name', 'event_espresso'),
158
+					false,
159
+					esc_html__('Unknown', 'event_espresso')
160
+				),
161
+				'ATT_bio'       => new EE_Post_Content_Field(
162
+					'post_content',
163
+					esc_html__('Attendee Biography', 'event_espresso'),
164
+					false,
165
+					esc_html__('No Biography Provided', 'event_espresso')
166
+				),
167
+				'ATT_slug'      => new EE_Slug_Field(
168
+					'post_name',
169
+					esc_html__('Attendee URL Slug', 'event_espresso'),
170
+					false
171
+				),
172
+				'ATT_created'   => new EE_Datetime_Field(
173
+					'post_date',
174
+					esc_html__('Time Attendee Created', 'event_espresso'),
175
+					false,
176
+					EE_Datetime_Field::now
177
+				),
178
+				'ATT_short_bio' => new EE_Simple_HTML_Field(
179
+					'post_excerpt',
180
+					esc_html__('Attendee Short Biography', 'event_espresso'),
181
+					true,
182
+					esc_html__('No Biography Provided', 'event_espresso')
183
+				),
184
+				'ATT_modified'  => new EE_Datetime_Field(
185
+					'post_modified',
186
+					esc_html__('Time Attendee Last Modified', 'event_espresso'),
187
+					false,
188
+					EE_Datetime_Field::now
189
+				),
190
+				'ATT_author'    => new EE_WP_User_Field(
191
+					'post_author',
192
+					esc_html__('Creator ID of the first Event attended', 'event_espresso'),
193
+					false
194
+				),
195
+				'ATT_parent'    => new EE_DB_Only_Int_Field(
196
+					'post_parent',
197
+					esc_html__('Parent Attendee (unused)', 'event_espresso'),
198
+					false,
199
+					0
200
+				),
201
+				'post_type'     => new EE_WP_Post_Type_Field('espresso_attendees'),
202
+				'status'        => new EE_WP_Post_Status_Field(
203
+					'post_status',
204
+					esc_html__('Attendee Status', 'event_espresso'),
205
+					false,
206
+					'publish'
207
+				),
208
+			),
209
+			'Attendee_Meta' => array(
210
+				'ATTM_ID'      => new EE_DB_Only_Int_Field(
211
+					'ATTM_ID',
212
+					esc_html__('Attendee Meta Row ID', 'event_espresso'),
213
+					false
214
+				),
215
+				'ATT_ID_fk'    => new EE_DB_Only_Int_Field(
216
+					'ATT_ID',
217
+					esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'),
218
+					false
219
+				),
220
+				'ATT_fname'    => new EE_Plain_Text_Field(
221
+					'ATT_fname',
222
+					esc_html__('First Name', 'event_espresso'),
223
+					true,
224
+					''
225
+				),
226
+				'ATT_lname'    => new EE_Plain_Text_Field(
227
+					'ATT_lname', esc_html__('Last Name', 'event_espresso'),
228
+					true,
229
+					''
230
+				),
231
+				'ATT_address'  => new EE_Plain_Text_Field(
232
+					'ATT_address',
233
+					esc_html__('Address Part 1', 'event_espresso'),
234
+					true,
235
+					''
236
+				),
237
+				'ATT_address2' => new EE_Plain_Text_Field(
238
+					'ATT_address2',
239
+					esc_html__('Address Part 2', 'event_espresso'),
240
+					true,
241
+					''
242
+				),
243
+				'ATT_city'     => new EE_Plain_Text_Field(
244
+					'ATT_city',
245
+					esc_html__('City', 'event_espresso'),
246
+					true,
247
+					''
248
+				),
249
+				'STA_ID'       => new EE_Foreign_Key_Int_Field(
250
+					'STA_ID',
251
+					esc_html__('State', 'event_espresso'),
252
+					true,
253
+					0,
254
+					'State'
255
+				),
256
+				'CNT_ISO'      => new EE_Foreign_Key_String_Field(
257
+					'CNT_ISO',
258
+					esc_html__('Country', 'event_espresso'),
259
+					true,
260
+					'',
261
+					'Country'
262
+				),
263
+				'ATT_zip'      => new EE_Plain_Text_Field(
264
+					'ATT_zip',
265
+					esc_html__('ZIP/Postal Code', 'event_espresso'),
266
+					true,
267
+					''
268
+				),
269
+				'ATT_email'    => new EE_Email_Field(
270
+					'ATT_email',
271
+					esc_html__('Email Address', 'event_espresso'),
272
+					true,
273
+					''
274
+				),
275
+				'ATT_phone'    => new EE_Plain_Text_Field(
276
+					'ATT_phone',
277
+					esc_html__('Phone', 'event_espresso'),
278
+					true,
279
+					''
280
+				),
281
+			),
282
+		);
283
+		$this->_model_relations = array(
284
+			'Registration'      => new EE_Has_Many_Relation(),
285
+			'State'             => new EE_Belongs_To_Relation(),
286
+			'Country'           => new EE_Belongs_To_Relation(),
287
+			'Event'             => new EE_HABTM_Relation('Registration', false),
288
+			'WP_User'           => new EE_Belongs_To_Relation(),
289
+			'Message'           => new EE_Has_Many_Any_Relation(false),
290
+			//allow deletion of attendees even if they have messages in the queue for them.
291
+			'Term_Relationship' => new EE_Has_Many_Relation(),
292
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
293
+		);
294
+		$this->_caps_slug = 'contacts';
295
+		parent::__construct($timezone);
296
+	}
297
+
298
+
299
+
300
+	/**
301
+	 * Gets the name of the field on the attendee model corresponding to the system question string
302
+	 * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
303
+	 *
304
+	 * @param string $system_question_string
305
+	 * @return string|null if not found
306
+	 */
307
+	public function get_attendee_field_for_system_question($system_question_string)
308
+	{
309
+		return isset($this->_system_question_to_attendee_field_name[$system_question_string])
310
+			? $this->_system_question_to_attendee_field_name[$system_question_string]
311
+			: null;
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
318
+	 *
319
+	 * @return array
320
+	 */
321
+	public function system_question_to_attendee_field_mapping()
322
+	{
323
+		return $this->_system_question_to_attendee_field_name;
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 * Gets all the attendees for a transaction (by using the esp_registration as a join table)
330
+	 *
331
+	 * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
332
+	 * @return EE_Attendee[]|EE_Base_Class[]
333
+	 * @throws EE_Error
334
+	 */
335
+	public function get_attendees_for_transaction($transaction_id_or_obj)
336
+	{
337
+		return $this->get_all(
338
+			array(
339
+				array(
340
+					'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
341
+						? $transaction_id_or_obj->ID()
342
+						: $transaction_id_or_obj,
343
+				),
344
+			)
345
+		);
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * retrieve  a single attendee from db via their ID
352
+	 *
353
+	 * @param $ATT_ID
354
+	 * @return mixed array on success, FALSE on fail
355
+	 * @deprecated
356
+	 */
357
+	public function get_attendee_by_ID($ATT_ID = false)
358
+	{
359
+		// retrieve a particular EE_Attendee
360
+		return $this->get_one_by_ID($ATT_ID);
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * retrieve  a single attendee from db via their ID
367
+	 *
368
+	 * @param array $where_cols_n_values
369
+	 * @return mixed array on success, FALSE on fail
370
+	 * @throws EE_Error
371
+	 */
372
+	public function get_attendee($where_cols_n_values = array())
373
+	{
374
+		if (empty($where_cols_n_values)) {
375
+			return false;
376
+		}
377
+		$attendee = $this->get_all(array($where_cols_n_values));
378
+		if (! empty($attendee)) {
379
+			return array_shift($attendee);
380
+		}
381
+		return false;
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 * Search for an existing Attendee record in the DB
388
+	 *
389
+	 * @param array $where_cols_n_values
390
+	 * @return bool|mixed
391
+	 * @throws EE_Error
392
+	 */
393
+	public function find_existing_attendee($where_cols_n_values = null)
394
+	{
395
+		// search by combo of first and last names plus the email address
396
+		$attendee_data_keys = array(
397
+			'ATT_fname' => $this->_ATT_fname,
398
+			'ATT_lname' => $this->_ATT_lname,
399
+			'ATT_email' => $this->_ATT_email,
400
+		);
401
+		// no search params means attendee object already exists.
402
+		$where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values)
403
+			? $where_cols_n_values
404
+			: $attendee_data_keys;
405
+		$valid_data = true;
406
+		// check for required values
407
+		$valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
408
+			? $valid_data
409
+			: false;
410
+		$valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
411
+			? $valid_data
412
+			: false;
413
+		$valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
414
+			? $valid_data
415
+			: false;
416
+		if ($valid_data) {
417
+			$attendee = $this->get_attendee($where_cols_n_values);
418
+			if ($attendee instanceof EE_Attendee) {
419
+				return $attendee;
420
+			}
421
+		}
422
+		return false;
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * Takes an incoming array of EE_Registration ids
429
+	 * and sends back a list of corresponding non duplicate EE_Attendee objects.
430
+	 *
431
+	 * @since  4.3.0
432
+	 * @param  array $ids array of EE_Registration ids
433
+	 * @return EE_Attendee[]|EE_Base_Class[]
434
+	 * @throws EE_Error
435
+	 */
436
+	public function get_array_of_contacts_from_reg_ids($ids)
437
+	{
438
+		$ids = (array)$ids;
439
+		$_where = array(
440
+			'Registration.REG_ID' => array('in', $ids),
441
+		);
442
+		return $this->get_all(array($_where));
443
+	}
444 444
 
445 445
 
446 446
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
4 4
 
5
-require_once(EE_MODELS . 'EEM_Base.model.php');
5
+require_once(EE_MODELS.'EEM_Base.model.php');
6 6
 
7 7
 
8 8
 
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
             return false;
376 376
         }
377 377
         $attendee = $this->get_all(array($where_cols_n_values));
378
-        if (! empty($attendee)) {
378
+        if ( ! empty($attendee)) {
379 379
             return array_shift($attendee);
380 380
         }
381 381
         return false;
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
      */
436 436
     public function get_array_of_contacts_from_reg_ids($ids)
437 437
     {
438
-        $ids = (array)$ids;
438
+        $ids = (array) $ids;
439 439
         $_where = array(
440 440
             'Registration.REG_ID' => array('in', $ids),
441 441
         );
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket.class.php 1 patch
Indentation   +591 added lines, -591 removed lines patch added patch discarded remove patch
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * @param array  $props_n_values          incoming values
66
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
-     *                                        used.)
68
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
-     *                                        date_format and the second value is the time format
70
-     * @return EE_Ticket
71
-     * @throws \EE_Error
72
-     */
64
+	/**
65
+	 * @param array  $props_n_values          incoming values
66
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
+	 *                                        used.)
68
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
+	 *                                        date_format and the second value is the time format
70
+	 * @return EE_Ticket
71
+	 * @throws \EE_Error
72
+	 */
73 73
 	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74 74
 		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75 75
 		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
@@ -77,36 +77,36 @@  discard block
 block discarded – undo
77 77
 
78 78
 
79 79
 
80
-    /**
81
-     * @param array  $props_n_values  incoming values from the database
82
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
-     *                                the website will be used.
84
-     * @return EE_Ticket
85
-     * @throws \EE_Error
86
-     */
80
+	/**
81
+	 * @param array  $props_n_values  incoming values from the database
82
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
+	 *                                the website will be used.
84
+	 * @return EE_Ticket
85
+	 * @throws \EE_Error
86
+	 */
87 87
 	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88 88
 		return new self( $props_n_values, TRUE, $timezone );
89 89
 	}
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * @return bool
95
-     * @throws \EE_Error
96
-     */
93
+	/**
94
+	 * @return bool
95
+	 * @throws \EE_Error
96
+	 */
97 97
 	public function parent() {
98 98
 		return $this->get( 'TKT_parent' );
99 99
 	}
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * return if a ticket has quantities available for purchase
105
-     *
106
-     * @param  int $DTT_ID the primary key for a particular datetime
107
-     * @return boolean
108
-     * @throws \EE_Error
109
-     */
103
+	/**
104
+	 * return if a ticket has quantities available for purchase
105
+	 *
106
+	 * @param  int $DTT_ID the primary key for a particular datetime
107
+	 * @return boolean
108
+	 * @throws \EE_Error
109
+	 */
110 110
 	public function available( $DTT_ID = 0 ) {
111 111
 		// are we checking availability for a particular datetime ?
112 112
 		if ( $DTT_ID ) {
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 
125 125
 
126
-    /**
127
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
-     *
129
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
-     * @return mixed status int if the display string isn't requested
132
-     * @throws \EE_Error
133
-     */
126
+	/**
127
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
+	 *
129
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
+	 * @return mixed status int if the display string isn't requested
132
+	 * @throws \EE_Error
133
+	 */
134 134
 	public function ticket_status( $display = FALSE, $remaining = null ) {
135 135
 		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136 136
 		if ( ! $remaining ) {
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 
154 154
 
155 155
 
156
-    /**
157
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
-     *
159
-     * @access public
160
-     * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
-     * @return boolean         true = tickets remaining, false not.
162
-     * @throws \EE_Error
163
-     */
156
+	/**
157
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
+	 *
159
+	 * @access public
160
+	 * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
+	 * @return boolean         true = tickets remaining, false not.
162
+	 * @throws \EE_Error
163
+	 */
164 164
 	public function is_remaining( $DTT_ID = 0 ) {
165 165
 		$num_remaining = $this->remaining( $DTT_ID );
166 166
 		if ( $num_remaining === 0 ) {
@@ -174,76 +174,76 @@  discard block
 block discarded – undo
174 174
 
175 175
 
176 176
 
177
-    /**
178
-     * return the total number of tickets available for purchase
179
-     *
180
-     * @param  int $DTT_ID the primary key for a particular datetime.
181
-     *                     set to 0 for all related datetimes
182
-     * @return int
183
-     * @throws \EE_Error
184
-     */
177
+	/**
178
+	 * return the total number of tickets available for purchase
179
+	 *
180
+	 * @param  int $DTT_ID the primary key for a particular datetime.
181
+	 *                     set to 0 for all related datetimes
182
+	 * @return int
183
+	 * @throws \EE_Error
184
+	 */
185 185
 	public function remaining( $DTT_ID = 0 ) {
186 186
 		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
187 187
 	}
188 188
 
189 189
 
190 190
 
191
-    /**
192
-     * Gets min
193
-     *
194
-     * @return int
195
-     * @throws \EE_Error
196
-     */
191
+	/**
192
+	 * Gets min
193
+	 *
194
+	 * @return int
195
+	 * @throws \EE_Error
196
+	 */
197 197
 	public function min() {
198 198
 		return $this->get( 'TKT_min' );
199 199
 	}
200 200
 
201 201
 
202 202
 
203
-    /**
204
-     * return if a ticket is no longer available cause its available dates have expired.
205
-     *
206
-     * @return boolean
207
-     * @throws \EE_Error
208
-     */
203
+	/**
204
+	 * return if a ticket is no longer available cause its available dates have expired.
205
+	 *
206
+	 * @return boolean
207
+	 * @throws \EE_Error
208
+	 */
209 209
 	public function is_expired() {
210 210
 		return ( $this->get_raw( 'TKT_end_date' ) < time() );
211 211
 	}
212 212
 
213 213
 
214 214
 
215
-    /**
216
-     * Return if a ticket is yet to go on sale or not
217
-     *
218
-     * @return boolean
219
-     * @throws \EE_Error
220
-     */
215
+	/**
216
+	 * Return if a ticket is yet to go on sale or not
217
+	 *
218
+	 * @return boolean
219
+	 * @throws \EE_Error
220
+	 */
221 221
 	public function is_pending() {
222 222
 		return ( $this->get_raw( 'TKT_start_date' ) > time() );
223 223
 	}
224 224
 
225 225
 
226 226
 
227
-    /**
228
-     * Return if a ticket is on sale or not
229
-     *
230
-     * @return boolean
231
-     * @throws \EE_Error
232
-     */
227
+	/**
228
+	 * Return if a ticket is on sale or not
229
+	 *
230
+	 * @return boolean
231
+	 * @throws \EE_Error
232
+	 */
233 233
 	public function is_on_sale() {
234 234
 		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
235 235
 	}
236 236
 
237 237
 
238 238
 
239
-    /**
240
-     * This returns the chronologically last datetime that this ticket is associated with
241
-     *
242
-     * @param string $dt_frmt
243
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
-     * @return string
245
-     * @throws \EE_Error
246
-     */
239
+	/**
240
+	 * This returns the chronologically last datetime that this ticket is associated with
241
+	 *
242
+	 * @param string $dt_frmt
243
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
+	 * @return string
245
+	 * @throws \EE_Error
246
+	 */
247 247
 	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248 248
 		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249 249
 		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
 
254 254
 
255 255
 
256
-    /**
257
-     * This returns the chronologically first datetime that this ticket is associated with
258
-     *
259
-     * @return EE_Datetime
260
-     * @throws \EE_Error
261
-     */
256
+	/**
257
+	 * This returns the chronologically first datetime that this ticket is associated with
258
+	 *
259
+	 * @return EE_Datetime
260
+	 * @throws \EE_Error
261
+	 */
262 262
 	public function first_datetime() {
263 263
 		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264 264
 		return reset( $datetimes );
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 
267 267
 
268 268
 
269
-    /**
270
-     * Gets all the datetimes this ticket can be used for attending.
271
-     * Unless otherwise specified, orders datetimes by start date.
272
-     *
273
-     * @param array $query_params see EEM_Base::get_all()
274
-     * @return EE_Datetime[]|EE_Base_Class[]
275
-     * @throws \EE_Error
276
-     */
269
+	/**
270
+	 * Gets all the datetimes this ticket can be used for attending.
271
+	 * Unless otherwise specified, orders datetimes by start date.
272
+	 *
273
+	 * @param array $query_params see EEM_Base::get_all()
274
+	 * @return EE_Datetime[]|EE_Base_Class[]
275
+	 * @throws \EE_Error
276
+	 */
277 277
 	public function datetimes( $query_params = array() ) {
278 278
 		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279 279
 			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
@@ -283,12 +283,12 @@  discard block
 block discarded – undo
283 283
 
284 284
 
285 285
 
286
-    /**
287
-     * This returns the chronologically last datetime that this ticket is associated with
288
-     *
289
-     * @return EE_Datetime
290
-     * @throws \EE_Error
291
-     */
286
+	/**
287
+	 * This returns the chronologically last datetime that this ticket is associated with
288
+	 *
289
+	 * @return EE_Datetime
290
+	 * @throws \EE_Error
291
+	 */
292 292
 	public function last_datetime() {
293 293
 		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294 294
 		return end( $datetimes );
@@ -296,19 +296,19 @@  discard block
 block discarded – undo
296 296
 
297 297
 
298 298
 
299
-    /**
300
-     * This returns the total tickets sold depending on the given parameters.
301
-     *
302
-     * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
306
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
-     * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
-     * @return mixed (array|int)          how many tickets have sold
310
-     * @throws \EE_Error
311
-     */
299
+	/**
300
+	 * This returns the total tickets sold depending on the given parameters.
301
+	 *
302
+	 * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
306
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
+	 * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
+	 * @return mixed (array|int)          how many tickets have sold
310
+	 * @throws \EE_Error
311
+	 */
312 312
 	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
 
334 334
 
335 335
 
336
-    /**
337
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
-     *
339
-     * @return EE_Ticket[]
340
-     * @throws \EE_Error
341
-     */
336
+	/**
337
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
+	 *
339
+	 * @return EE_Ticket[]
340
+	 * @throws \EE_Error
341
+	 */
342 342
 	protected function _all_tickets_sold() {
343 343
 		$datetimes = $this->get_many_related( 'Datetime' );
344 344
 		$tickets_sold = array();
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 
355 355
 
356 356
 
357
-    /**
358
-     * This returns the base price object for the ticket.
359
-     *
360
-     * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
-     * @throws \EE_Error
363
-     */
357
+	/**
358
+	 * This returns the base price object for the ticket.
359
+	 *
360
+	 * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
+	 * @throws \EE_Error
363
+	 */
364 364
 	public function base_price( $return_array = FALSE ) {
365 365
 		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+			? $this->get_many_related( 'Price', array( $_where ) )
368
+			: $this->get_first_related( 'Price', array( $_where ) );
369 369
 	}
370 370
 
371 371
 
372 372
 
373
-    /**
374
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
-     *
376
-     * @access public
377
-     * @return EE_Price[]
378
-     * @throws \EE_Error
379
-     */
373
+	/**
374
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
+	 *
376
+	 * @access public
377
+	 * @return EE_Price[]
378
+	 * @throws \EE_Error
379
+	 */
380 380
 	public function price_modifiers() {
381 381
 		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382 382
 		return $this->prices( $query_params );
@@ -384,132 +384,132 @@  discard block
 block discarded – undo
384 384
 
385 385
 
386 386
 
387
-    /**
388
-     * Gets all the prices that combine to form the final price of this ticket
389
-     *
390
-     * @param array $query_params like EEM_Base::get_all
391
-     * @return EE_Price[]|EE_Base_Class[]
392
-     * @throws \EE_Error
393
-     */
387
+	/**
388
+	 * Gets all the prices that combine to form the final price of this ticket
389
+	 *
390
+	 * @param array $query_params like EEM_Base::get_all
391
+	 * @return EE_Price[]|EE_Base_Class[]
392
+	 * @throws \EE_Error
393
+	 */
394 394
 	public function prices( $query_params = array() ) {
395 395
 		return $this->get_many_related( 'Price', $query_params );
396 396
 	}
397 397
 
398 398
 
399 399
 
400
-    /**
401
-     * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
-     *
403
-     * @param array $query_params see EEM_Base::get_all()
404
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
405
-     * @throws \EE_Error
406
-     */
400
+	/**
401
+	 * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
+	 *
403
+	 * @param array $query_params see EEM_Base::get_all()
404
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
405
+	 * @throws \EE_Error
406
+	 */
407 407
 	public function datetime_tickets( $query_params = array() ) {
408 408
 		return $this->get_many_related( 'Datetime_Ticket', $query_params );
409 409
 	}
410 410
 
411 411
 
412 412
 
413
-    /**
414
-     * Gets all the datetimes from the db ordered by DTT_order
415
-     *
416
-     * @param boolean $show_expired
417
-     * @param boolean $show_deleted
418
-     * @return EE_Datetime[]
419
-     * @throws \EE_Error
420
-     */
413
+	/**
414
+	 * Gets all the datetimes from the db ordered by DTT_order
415
+	 *
416
+	 * @param boolean $show_expired
417
+	 * @param boolean $show_deleted
418
+	 * @return EE_Datetime[]
419
+	 * @throws \EE_Error
420
+	 */
421 421
 	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422 422
 		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
423 423
 	}
424 424
 
425 425
 
426 426
 
427
-    /**
428
-     * Gets ID
429
-     *
430
-     * @return string
431
-     * @throws \EE_Error
432
-     */
427
+	/**
428
+	 * Gets ID
429
+	 *
430
+	 * @return string
431
+	 * @throws \EE_Error
432
+	 */
433 433
 	public function ID() {
434 434
 		return $this->get( 'TKT_ID' );
435 435
 	}
436 436
 
437 437
 
438 438
 
439
-    /**
440
-     * get the author of the ticket.
441
-     *
442
-     * @since 4.5.0
443
-     * @return int
444
-     * @throws \EE_Error
445
-     */
439
+	/**
440
+	 * get the author of the ticket.
441
+	 *
442
+	 * @since 4.5.0
443
+	 * @return int
444
+	 * @throws \EE_Error
445
+	 */
446 446
 	public function wp_user() {
447 447
 		return $this->get('TKT_wp_user');
448 448
 	}
449 449
 
450 450
 
451 451
 
452
-    /**
453
-     * Gets the template for the ticket
454
-     *
455
-     * @return EE_Ticket_Template|EE_Base_Class
456
-     * @throws \EE_Error
457
-     */
452
+	/**
453
+	 * Gets the template for the ticket
454
+	 *
455
+	 * @return EE_Ticket_Template|EE_Base_Class
456
+	 * @throws \EE_Error
457
+	 */
458 458
 	public function template() {
459 459
 		return $this->get_first_related( 'Ticket_Template' );
460 460
 	}
461 461
 
462 462
 
463 463
 
464
-    /**
465
-     * Simply returns an array of EE_Price objects that are taxes.
466
-     *
467
-     * @return EE_Price[]
468
-     * @throws \EE_Error
469
-     */
464
+	/**
465
+	 * Simply returns an array of EE_Price objects that are taxes.
466
+	 *
467
+	 * @return EE_Price[]
468
+	 * @throws \EE_Error
469
+	 */
470 470
 	public function get_ticket_taxes_for_admin() {
471 471
 		return EE_Taxes::get_taxes_for_admin();
472 472
 	}
473 473
 
474 474
 
475 475
 
476
-    /**
477
-     * @return float
478
-     * @throws \EE_Error
479
-     */
476
+	/**
477
+	 * @return float
478
+	 * @throws \EE_Error
479
+	 */
480 480
 	public function ticket_price() {
481 481
 		return $this->get( 'TKT_price' );
482 482
 	}
483 483
 
484 484
 
485 485
 
486
-    /**
487
-     * @return mixed
488
-     * @throws \EE_Error
489
-     */
486
+	/**
487
+	 * @return mixed
488
+	 * @throws \EE_Error
489
+	 */
490 490
 	public function pretty_price() {
491 491
 		return $this->get_pretty( 'TKT_price' );
492 492
 	}
493 493
 
494 494
 
495 495
 
496
-    /**
497
-     * @return bool
498
-     * @throws \EE_Error
499
-     */
496
+	/**
497
+	 * @return bool
498
+	 * @throws \EE_Error
499
+	 */
500 500
 	public function is_free() {
501 501
 		return $this->get_ticket_total_with_taxes() === (float) 0;
502 502
 	}
503 503
 
504 504
 
505 505
 
506
-    /**
507
-     * get_ticket_total_with_taxes
508
-     *
509
-     * @param bool $no_cache
510
-     * @return float
511
-     * @throws \EE_Error
512
-     */
506
+	/**
507
+	 * get_ticket_total_with_taxes
508
+	 *
509
+	 * @param bool $no_cache
510
+	 * @return float
511
+	 * @throws \EE_Error
512
+	 */
513 513
 	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514 514
 		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
@@ -526,201 +526,201 @@  discard block
 block discarded – undo
526 526
 
527 527
 
528 528
 
529
-    /**
530
-     * @return float
531
-     * @throws \EE_Error
532
-     */
529
+	/**
530
+	 * @return float
531
+	 * @throws \EE_Error
532
+	 */
533 533
 	public function get_ticket_subtotal() {
534 534
 		return EE_Taxes::get_subtotal_for_admin( $this );
535 535
 	}
536 536
 
537 537
 
538 538
 
539
-    /**
540
-     * Returns the total taxes applied to this ticket
541
-     *
542
-     * @return float
543
-     * @throws \EE_Error
544
-     */
539
+	/**
540
+	 * Returns the total taxes applied to this ticket
541
+	 *
542
+	 * @return float
543
+	 * @throws \EE_Error
544
+	 */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546 546
 		return EE_Taxes::get_total_taxes_for_admin( $this );
547 547
 	}
548 548
 
549 549
 
550 550
 
551
-    /**
552
-     * Sets name
553
-     *
554
-     * @param string $name
555
-     * @throws \EE_Error
556
-     */
551
+	/**
552
+	 * Sets name
553
+	 *
554
+	 * @param string $name
555
+	 * @throws \EE_Error
556
+	 */
557 557
 	public function set_name( $name ) {
558 558
 		$this->set( 'TKT_name', $name );
559 559
 	}
560 560
 
561 561
 
562 562
 
563
-    /**
564
-     * Gets description
565
-     *
566
-     * @return string
567
-     * @throws \EE_Error
568
-     */
563
+	/**
564
+	 * Gets description
565
+	 *
566
+	 * @return string
567
+	 * @throws \EE_Error
568
+	 */
569 569
 	public function description() {
570 570
 		return $this->get( 'TKT_description' );
571 571
 	}
572 572
 
573 573
 
574 574
 
575
-    /**
576
-     * Sets description
577
-     *
578
-     * @param string $description
579
-     * @throws \EE_Error
580
-     */
575
+	/**
576
+	 * Sets description
577
+	 *
578
+	 * @param string $description
579
+	 * @throws \EE_Error
580
+	 */
581 581
 	public function set_description( $description ) {
582 582
 		$this->set( 'TKT_description', $description );
583 583
 	}
584 584
 
585 585
 
586 586
 
587
-    /**
588
-     * Gets start_date
589
-     *
590
-     * @param string $dt_frmt
591
-     * @param string $tm_frmt
592
-     * @return string
593
-     * @throws \EE_Error
594
-     */
587
+	/**
588
+	 * Gets start_date
589
+	 *
590
+	 * @param string $dt_frmt
591
+	 * @param string $tm_frmt
592
+	 * @return string
593
+	 * @throws \EE_Error
594
+	 */
595 595
 	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596 596
 		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
597 597
 	}
598 598
 
599 599
 
600 600
 
601
-    /**
602
-     * Sets start_date
603
-     *
604
-     * @param string $start_date
605
-     * @return void
606
-     * @throws \EE_Error
607
-     */
601
+	/**
602
+	 * Sets start_date
603
+	 *
604
+	 * @param string $start_date
605
+	 * @return void
606
+	 * @throws \EE_Error
607
+	 */
608 608
 	public function set_start_date( $start_date ) {
609 609
 		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
610 610
 	}
611 611
 
612 612
 
613 613
 
614
-    /**
615
-     * Gets end_date
616
-     *
617
-     * @param string $dt_frmt
618
-     * @param string $tm_frmt
619
-     * @return string
620
-     * @throws \EE_Error
621
-     */
614
+	/**
615
+	 * Gets end_date
616
+	 *
617
+	 * @param string $dt_frmt
618
+	 * @param string $tm_frmt
619
+	 * @return string
620
+	 * @throws \EE_Error
621
+	 */
622 622
 	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623 623
 		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
624 624
 	}
625 625
 
626 626
 
627 627
 
628
-    /**
629
-     * Sets end_date
630
-     *
631
-     * @param string $end_date
632
-     * @return void
633
-     * @throws \EE_Error
634
-     */
628
+	/**
629
+	 * Sets end_date
630
+	 *
631
+	 * @param string $end_date
632
+	 * @return void
633
+	 * @throws \EE_Error
634
+	 */
635 635
 	public function set_end_date( $end_date ) {
636 636
 		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
637 637
 	}
638 638
 
639 639
 
640 640
 
641
-    /**
642
-     * Sets sell until time
643
-     *
644
-     * @since 4.5.0
645
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
-     * @throws \EE_Error
647
-     */
641
+	/**
642
+	 * Sets sell until time
643
+	 *
644
+	 * @since 4.5.0
645
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
+	 * @throws \EE_Error
647
+	 */
648 648
 	public function set_end_time( $time ) {
649 649
 		$this->_set_time_for( $time, 'TKT_end_date' );
650 650
 	}
651 651
 
652 652
 
653 653
 
654
-    /**
655
-     * Sets min
656
-     *
657
-     * @param int $min
658
-     * @return void
659
-     * @throws \EE_Error
660
-     */
654
+	/**
655
+	 * Sets min
656
+	 *
657
+	 * @param int $min
658
+	 * @return void
659
+	 * @throws \EE_Error
660
+	 */
661 661
 	public function set_min( $min ) {
662 662
 		$this->set( 'TKT_min', $min );
663 663
 	}
664 664
 
665 665
 
666 666
 
667
-    /**
668
-     * Gets max
669
-     *
670
-     * @return int
671
-     * @throws \EE_Error
672
-     */
667
+	/**
668
+	 * Gets max
669
+	 *
670
+	 * @return int
671
+	 * @throws \EE_Error
672
+	 */
673 673
 	public function max() {
674 674
 		return $this->get( 'TKT_max' );
675 675
 	}
676 676
 
677 677
 
678 678
 
679
-    /**
680
-     * Sets max
681
-     *
682
-     * @param int $max
683
-     * @return void
684
-     * @throws \EE_Error
685
-     */
679
+	/**
680
+	 * Sets max
681
+	 *
682
+	 * @param int $max
683
+	 * @return void
684
+	 * @throws \EE_Error
685
+	 */
686 686
 	public function set_max( $max ) {
687 687
 		$this->set( 'TKT_max', $max );
688 688
 	}
689 689
 
690 690
 
691 691
 
692
-    /**
693
-     * Sets price
694
-     *
695
-     * @param float $price
696
-     * @return void
697
-     * @throws \EE_Error
698
-     */
692
+	/**
693
+	 * Sets price
694
+	 *
695
+	 * @param float $price
696
+	 * @return void
697
+	 * @throws \EE_Error
698
+	 */
699 699
 	public function set_price( $price ) {
700 700
 		$this->set( 'TKT_price', $price );
701 701
 	}
702 702
 
703 703
 
704 704
 
705
-    /**
706
-     * Gets sold
707
-     *
708
-     * @return int
709
-     * @throws \EE_Error
710
-     */
705
+	/**
706
+	 * Gets sold
707
+	 *
708
+	 * @return int
709
+	 * @throws \EE_Error
710
+	 */
711 711
 	public function sold() {
712 712
 		return $this->get_raw( 'TKT_sold' );
713 713
 	}
714 714
 
715 715
 
716 716
 
717
-    /**
718
-     * Sets sold
719
-     *
720
-     * @param int $sold
721
-     * @return void
722
-     * @throws \EE_Error
723
-     */
717
+	/**
718
+	 * Sets sold
719
+	 *
720
+	 * @param int $sold
721
+	 * @return void
722
+	 * @throws \EE_Error
723
+	 */
724 724
 	public function set_sold( $sold ) {
725 725
 		// sold can not go below zero
726 726
 		$sold = max( 0, $sold );
@@ -729,13 +729,13 @@  discard block
 block discarded – undo
729 729
 
730 730
 
731 731
 
732
-    /**
733
-     * increments sold by amount passed by $qty
734
-     *
735
-     * @param int $qty
736
-     * @return void
737
-     * @throws \EE_Error
738
-     */
732
+	/**
733
+	 * increments sold by amount passed by $qty
734
+	 *
735
+	 * @param int $qty
736
+	 * @return void
737
+	 * @throws \EE_Error
738
+	 */
739 739
 	public function increase_sold( $qty = 1 ) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
@@ -747,13 +747,13 @@  discard block
 block discarded – undo
747 747
 
748 748
 
749 749
 
750
-    /**
751
-     * Increases sold on related datetimes
752
-     *
753
-     * @param int $qty
754
-     * @return void
755
-     * @throws \EE_Error
756
-     */
750
+	/**
751
+	 * Increases sold on related datetimes
752
+	 *
753
+	 * @param int $qty
754
+	 * @return void
755
+	 * @throws \EE_Error
756
+	 */
757 757
 	protected function _increase_sold_for_datetimes( $qty = 1 ) {
758 758
 		$datetimes = $this->datetimes();
759 759
 		if ( is_array( $datetimes ) ) {
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
 
769 769
 
770 770
 
771
-    /**
772
-     * decrements (subtracts) sold by amount passed by $qty
773
-     *
774
-     * @param int $qty
775
-     * @return void
776
-     * @throws \EE_Error
777
-     */
771
+	/**
772
+	 * decrements (subtracts) sold by amount passed by $qty
773
+	 *
774
+	 * @param int $qty
775
+	 * @return void
776
+	 * @throws \EE_Error
777
+	 */
778 778
 	public function decrease_sold( $qty = 1 ) {
779 779
 		$sold = $this->sold() - $qty;
780 780
 		$this->_decrease_sold_for_datetimes( $qty );
@@ -783,13 +783,13 @@  discard block
 block discarded – undo
783 783
 
784 784
 
785 785
 
786
-    /**
787
-     * Decreases sold on related datetimes
788
-     *
789
-     * @param int $qty
790
-     * @return void
791
-     * @throws \EE_Error
792
-     */
786
+	/**
787
+	 * Decreases sold on related datetimes
788
+	 *
789
+	 * @param int $qty
790
+	 * @return void
791
+	 * @throws \EE_Error
792
+	 */
793 793
 	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
794 794
 		$datetimes = $this->datetimes();
795 795
 		if ( is_array( $datetimes ) ) {
@@ -804,25 +804,25 @@  discard block
 block discarded – undo
804 804
 
805 805
 
806 806
 
807
-    /**
808
-     * Gets qty of reserved tickets
809
-     *
810
-     * @return int
811
-     * @throws \EE_Error
812
-     */
807
+	/**
808
+	 * Gets qty of reserved tickets
809
+	 *
810
+	 * @return int
811
+	 * @throws \EE_Error
812
+	 */
813 813
 	public function reserved() {
814 814
 		return $this->get_raw( 'TKT_reserved' );
815 815
 	}
816 816
 
817 817
 
818 818
 
819
-    /**
820
-     * Sets reserved
821
-     *
822
-     * @param int $reserved
823
-     * @return void
824
-     * @throws \EE_Error
825
-     */
819
+	/**
820
+	 * Sets reserved
821
+	 *
822
+	 * @param int $reserved
823
+	 * @return void
824
+	 * @throws \EE_Error
825
+	 */
826 826
 	public function set_reserved( $reserved ) {
827 827
 		// reserved can not go below zero
828 828
 		$reserved = max( 0, (int) $reserved );
@@ -831,13 +831,13 @@  discard block
 block discarded – undo
831 831
 
832 832
 
833 833
 
834
-    /**
835
-     * increments reserved by amount passed by $qty
836
-     *
837
-     * @param int $qty
838
-     * @return void
839
-     * @throws \EE_Error
840
-     */
834
+	/**
835
+	 * increments reserved by amount passed by $qty
836
+	 *
837
+	 * @param int $qty
838
+	 * @return void
839
+	 * @throws \EE_Error
840
+	 */
841 841
 	public function increase_reserved( $qty = 1 ) {
842 842
 		$qty = absint( $qty );
843 843
 		$reserved = $this->reserved() + $qty;
@@ -847,13 +847,13 @@  discard block
 block discarded – undo
847 847
 
848 848
 
849 849
 
850
-    /**
851
-     * Increases sold on related datetimes
852
-     *
853
-     * @param int $qty
854
-     * @return void
855
-     * @throws \EE_Error
856
-     */
850
+	/**
851
+	 * Increases sold on related datetimes
852
+	 *
853
+	 * @param int $qty
854
+	 * @return void
855
+	 * @throws \EE_Error
856
+	 */
857 857
 	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
858 858
 		$datetimes = $this->datetimes();
859 859
 		if ( is_array( $datetimes ) ) {
@@ -868,14 +868,14 @@  discard block
 block discarded – undo
868 868
 
869 869
 
870 870
 
871
-    /**
872
-     * decrements (subtracts) reserved by amount passed by $qty
873
-     *
874
-     * @param int  $qty
875
-     * @param bool $adjust_datetimes
876
-     * @return void
877
-     * @throws \EE_Error
878
-     */
871
+	/**
872
+	 * decrements (subtracts) reserved by amount passed by $qty
873
+	 *
874
+	 * @param int  $qty
875
+	 * @param bool $adjust_datetimes
876
+	 * @return void
877
+	 * @throws \EE_Error
878
+	 */
879 879
 	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
880 880
 		$reserved = $this->reserved() - absint( $qty );
881 881
 		if ( $adjust_datetimes ) {
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
 
887 887
 
888 888
 
889
-    /**
890
-     * Increases sold on related datetimes
891
-     *
892
-     * @param int $qty
893
-     * @return void
894
-     * @throws \EE_Error
895
-     */
889
+	/**
890
+	 * Increases sold on related datetimes
891
+	 *
892
+	 * @param int $qty
893
+	 * @return void
894
+	 * @throws \EE_Error
895
+	 */
896 896
 	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
897 897
 		$datetimes = $this->datetimes();
898 898
 		if ( is_array( $datetimes ) ) {
@@ -907,18 +907,18 @@  discard block
 block discarded – undo
907 907
 
908 908
 
909 909
 
910
-    /**
911
-     * Gets ticket quantity
912
-     *
913
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
914
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
915
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
916
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
917
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
918
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
919
-     * @return int
920
-     * @throws \EE_Error
921
-     */
910
+	/**
911
+	 * Gets ticket quantity
912
+	 *
913
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
914
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
915
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
916
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
917
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
918
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
919
+	 * @return int
920
+	 * @throws \EE_Error
921
+	 */
922 922
 	public function qty( $context = '' ) {
923 923
 		switch ( $context ) {
924 924
 			case 'reg_limit' :
@@ -932,19 +932,19 @@  discard block
 block discarded – undo
932 932
 
933 933
 
934 934
 
935
-    /**
936
-     * Gets ticket quantity
937
-     *
938
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
939
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
940
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
943
-     * @param  int   $DTT_ID      the primary key for a particular datetime.
944
-     *                            set to 0 for all related datetimes
945
-     * @return int
946
-     * @throws \EE_Error
947
-     */
935
+	/**
936
+	 * Gets ticket quantity
937
+	 *
938
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
939
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
940
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
943
+	 * @param  int   $DTT_ID      the primary key for a particular datetime.
944
+	 *                            set to 0 for all related datetimes
945
+	 * @return int
946
+	 * @throws \EE_Error
947
+	 */
948 948
 	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
949 949
 		$raw = $this->get_raw( 'TKT_qty' );
950 950
 		// return immediately if it's zero
@@ -1027,212 +1027,212 @@  discard block
 block discarded – undo
1027 1027
 
1028 1028
 
1029 1029
 
1030
-    /**
1031
-     * Gets uses
1032
-     *
1033
-     * @return int
1034
-     * @throws \EE_Error
1035
-     */
1030
+	/**
1031
+	 * Gets uses
1032
+	 *
1033
+	 * @return int
1034
+	 * @throws \EE_Error
1035
+	 */
1036 1036
 	public function uses() {
1037 1037
 		return $this->get( 'TKT_uses' );
1038 1038
 	}
1039 1039
 
1040 1040
 
1041 1041
 
1042
-    /**
1043
-     * Sets uses
1044
-     *
1045
-     * @param int $uses
1046
-     * @return void
1047
-     * @throws \EE_Error
1048
-     */
1042
+	/**
1043
+	 * Sets uses
1044
+	 *
1045
+	 * @param int $uses
1046
+	 * @return void
1047
+	 * @throws \EE_Error
1048
+	 */
1049 1049
 	public function set_uses( $uses ) {
1050 1050
 		$this->set( 'TKT_uses', $uses );
1051 1051
 	}
1052 1052
 
1053 1053
 
1054 1054
 
1055
-    /**
1056
-     * returns whether ticket is required or not.
1057
-     *
1058
-     * @return boolean
1059
-     * @throws \EE_Error
1060
-     */
1055
+	/**
1056
+	 * returns whether ticket is required or not.
1057
+	 *
1058
+	 * @return boolean
1059
+	 * @throws \EE_Error
1060
+	 */
1061 1061
 	public function required() {
1062 1062
 		return $this->get( 'TKT_required' );
1063 1063
 	}
1064 1064
 
1065 1065
 
1066 1066
 
1067
-    /**
1068
-     * sets the TKT_required property
1069
-     *
1070
-     * @param boolean $required
1071
-     * @return void
1072
-     * @throws \EE_Error
1073
-     */
1067
+	/**
1068
+	 * sets the TKT_required property
1069
+	 *
1070
+	 * @param boolean $required
1071
+	 * @return void
1072
+	 * @throws \EE_Error
1073
+	 */
1074 1074
 	public function set_required( $required ) {
1075 1075
 		$this->set( 'TKT_required', $required );
1076 1076
 	}
1077 1077
 
1078 1078
 
1079 1079
 
1080
-    /**
1081
-     * Gets taxable
1082
-     *
1083
-     * @return boolean
1084
-     * @throws \EE_Error
1085
-     */
1080
+	/**
1081
+	 * Gets taxable
1082
+	 *
1083
+	 * @return boolean
1084
+	 * @throws \EE_Error
1085
+	 */
1086 1086
 	public function taxable() {
1087 1087
 		return $this->get( 'TKT_taxable' );
1088 1088
 	}
1089 1089
 
1090 1090
 
1091 1091
 
1092
-    /**
1093
-     * Sets taxable
1094
-     *
1095
-     * @param boolean $taxable
1096
-     * @return void
1097
-     * @throws \EE_Error
1098
-     */
1092
+	/**
1093
+	 * Sets taxable
1094
+	 *
1095
+	 * @param boolean $taxable
1096
+	 * @return void
1097
+	 * @throws \EE_Error
1098
+	 */
1099 1099
 	public function set_taxable( $taxable ) {
1100 1100
 		$this->set( 'TKT_taxable', $taxable );
1101 1101
 	}
1102 1102
 
1103 1103
 
1104 1104
 
1105
-    /**
1106
-     * Gets is_default
1107
-     *
1108
-     * @return boolean
1109
-     * @throws \EE_Error
1110
-     */
1105
+	/**
1106
+	 * Gets is_default
1107
+	 *
1108
+	 * @return boolean
1109
+	 * @throws \EE_Error
1110
+	 */
1111 1111
 	public function is_default() {
1112 1112
 		return $this->get( 'TKT_is_default' );
1113 1113
 	}
1114 1114
 
1115 1115
 
1116 1116
 
1117
-    /**
1118
-     * Sets is_default
1119
-     *
1120
-     * @param boolean $is_default
1121
-     * @return void
1122
-     * @throws \EE_Error
1123
-     */
1117
+	/**
1118
+	 * Sets is_default
1119
+	 *
1120
+	 * @param boolean $is_default
1121
+	 * @return void
1122
+	 * @throws \EE_Error
1123
+	 */
1124 1124
 	public function set_is_default( $is_default ) {
1125 1125
 		$this->set( 'TKT_is_default', $is_default );
1126 1126
 	}
1127 1127
 
1128 1128
 
1129 1129
 
1130
-    /**
1131
-     * Gets order
1132
-     *
1133
-     * @return int
1134
-     * @throws \EE_Error
1135
-     */
1130
+	/**
1131
+	 * Gets order
1132
+	 *
1133
+	 * @return int
1134
+	 * @throws \EE_Error
1135
+	 */
1136 1136
 	public function order() {
1137 1137
 		return $this->get( 'TKT_order' );
1138 1138
 	}
1139 1139
 
1140 1140
 
1141 1141
 
1142
-    /**
1143
-     * Sets order
1144
-     *
1145
-     * @param int $order
1146
-     * @return void
1147
-     * @throws \EE_Error
1148
-     */
1142
+	/**
1143
+	 * Sets order
1144
+	 *
1145
+	 * @param int $order
1146
+	 * @return void
1147
+	 * @throws \EE_Error
1148
+	 */
1149 1149
 	public function set_order( $order ) {
1150 1150
 		$this->set( 'TKT_order', $order );
1151 1151
 	}
1152 1152
 
1153 1153
 
1154 1154
 
1155
-    /**
1156
-     * Gets row
1157
-     *
1158
-     * @return int
1159
-     * @throws \EE_Error
1160
-     */
1155
+	/**
1156
+	 * Gets row
1157
+	 *
1158
+	 * @return int
1159
+	 * @throws \EE_Error
1160
+	 */
1161 1161
 	public function row() {
1162 1162
 		return $this->get( 'TKT_row' );
1163 1163
 	}
1164 1164
 
1165 1165
 
1166 1166
 
1167
-    /**
1168
-     * Sets row
1169
-     *
1170
-     * @param int $row
1171
-     * @return void
1172
-     * @throws \EE_Error
1173
-     */
1167
+	/**
1168
+	 * Sets row
1169
+	 *
1170
+	 * @param int $row
1171
+	 * @return void
1172
+	 * @throws \EE_Error
1173
+	 */
1174 1174
 	public function set_row( $row ) {
1175 1175
 		$this->set( 'TKT_row', $row );
1176 1176
 	}
1177 1177
 
1178 1178
 
1179 1179
 
1180
-    /**
1181
-     * Gets deleted
1182
-     *
1183
-     * @return boolean
1184
-     * @throws \EE_Error
1185
-     */
1180
+	/**
1181
+	 * Gets deleted
1182
+	 *
1183
+	 * @return boolean
1184
+	 * @throws \EE_Error
1185
+	 */
1186 1186
 	public function deleted() {
1187 1187
 		return $this->get( 'TKT_deleted' );
1188 1188
 	}
1189 1189
 
1190 1190
 
1191 1191
 
1192
-    /**
1193
-     * Sets deleted
1194
-     *
1195
-     * @param boolean $deleted
1196
-     * @return void
1197
-     * @throws \EE_Error
1198
-     */
1192
+	/**
1193
+	 * Sets deleted
1194
+	 *
1195
+	 * @param boolean $deleted
1196
+	 * @return void
1197
+	 * @throws \EE_Error
1198
+	 */
1199 1199
 	public function set_deleted( $deleted ) {
1200 1200
 		$this->set( 'TKT_deleted', $deleted );
1201 1201
 	}
1202 1202
 
1203 1203
 
1204 1204
 
1205
-    /**
1206
-     * Gets parent
1207
-     *
1208
-     * @return int
1209
-     * @throws \EE_Error
1210
-     */
1205
+	/**
1206
+	 * Gets parent
1207
+	 *
1208
+	 * @return int
1209
+	 * @throws \EE_Error
1210
+	 */
1211 1211
 	public function parent_ID() {
1212 1212
 		return $this->get( 'TKT_parent' );
1213 1213
 	}
1214 1214
 
1215 1215
 
1216 1216
 
1217
-    /**
1218
-     * Sets parent
1219
-     *
1220
-     * @param int $parent
1221
-     * @return void
1222
-     * @throws \EE_Error
1223
-     */
1217
+	/**
1218
+	 * Sets parent
1219
+	 *
1220
+	 * @param int $parent
1221
+	 * @return void
1222
+	 * @throws \EE_Error
1223
+	 */
1224 1224
 	public function set_parent_ID( $parent ) {
1225 1225
 		$this->set( 'TKT_parent', $parent );
1226 1226
 	}
1227 1227
 
1228 1228
 
1229 1229
 
1230
-    /**
1231
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1232
-     *
1233
-     * @return string
1234
-     * @throws \EE_Error
1235
-     */
1230
+	/**
1231
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1232
+	 *
1233
+	 * @return string
1234
+	 * @throws \EE_Error
1235
+	 */
1236 1236
 	public function name_and_info() {
1237 1237
 		$times = array();
1238 1238
 		foreach ( $this->datetimes() as $datetime ) {
@@ -1243,67 +1243,67 @@  discard block
 block discarded – undo
1243 1243
 
1244 1244
 
1245 1245
 
1246
-    /**
1247
-     * Gets name
1248
-     *
1249
-     * @return string
1250
-     * @throws \EE_Error
1251
-     */
1246
+	/**
1247
+	 * Gets name
1248
+	 *
1249
+	 * @return string
1250
+	 * @throws \EE_Error
1251
+	 */
1252 1252
 	public function name() {
1253 1253
 		return $this->get( 'TKT_name' );
1254 1254
 	}
1255 1255
 
1256 1256
 
1257 1257
 
1258
-    /**
1259
-     * Gets price
1260
-     *
1261
-     * @return float
1262
-     * @throws \EE_Error
1263
-     */
1258
+	/**
1259
+	 * Gets price
1260
+	 *
1261
+	 * @return float
1262
+	 * @throws \EE_Error
1263
+	 */
1264 1264
 	public function price() {
1265 1265
 		return $this->get( 'TKT_price' );
1266 1266
 	}
1267 1267
 
1268 1268
 
1269 1269
 
1270
-    /**
1271
-     * Gets all the registrations for this ticket
1272
-     *
1273
-     * @param array $query_params like EEM_Base::get_all's
1274
-     * @return EE_Registration[]|EE_Base_Class[]
1275
-     * @throws \EE_Error
1276
-     */
1270
+	/**
1271
+	 * Gets all the registrations for this ticket
1272
+	 *
1273
+	 * @param array $query_params like EEM_Base::get_all's
1274
+	 * @return EE_Registration[]|EE_Base_Class[]
1275
+	 * @throws \EE_Error
1276
+	 */
1277 1277
 	public function registrations( $query_params = array() ) {
1278 1278
 		return $this->get_many_related( 'Registration', $query_params );
1279 1279
 	}
1280 1280
 
1281 1281
 
1282 1282
 
1283
-    /**
1284
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1285
-     * into account
1286
-     *
1287
-     * @return int
1288
-     * @throws \EE_Error
1289
-     */
1283
+	/**
1284
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1285
+	 * into account
1286
+	 *
1287
+	 * @return int
1288
+	 * @throws \EE_Error
1289
+	 */
1290 1290
 	public function update_tickets_sold() {
1291
-        $count_regs_for_this_ticket = $this->count_registrations(
1292
-            array(
1293
-                array(
1294
-                    'STS_ID'      => EEM_Registration::status_id_approved,
1295
-                    'REG_deleted' => 0,
1296
-                ),
1297
-            )
1298
-        );
1299
-        $sold = $this->sold();
1300
-        if ($count_regs_for_this_ticket > $sold) {
1301
-            $this->increase_sold($count_regs_for_this_ticket - $sold);
1302
-            $this->save();
1303
-        } else if ($count_regs_for_this_ticket < $sold) {
1304
-            $this->decrease_sold($count_regs_for_this_ticket - $sold);
1305
-            $this->save();
1306
-        }
1291
+		$count_regs_for_this_ticket = $this->count_registrations(
1292
+			array(
1293
+				array(
1294
+					'STS_ID'      => EEM_Registration::status_id_approved,
1295
+					'REG_deleted' => 0,
1296
+				),
1297
+			)
1298
+		);
1299
+		$sold = $this->sold();
1300
+		if ($count_regs_for_this_ticket > $sold) {
1301
+			$this->increase_sold($count_regs_for_this_ticket - $sold);
1302
+			$this->save();
1303
+		} else if ($count_regs_for_this_ticket < $sold) {
1304
+			$this->decrease_sold($count_regs_for_this_ticket - $sold);
1305
+			$this->save();
1306
+		}
1307 1307
 		return $count_regs_for_this_ticket;
1308 1308
 	}
1309 1309
 
@@ -1331,21 +1331,21 @@  discard block
 block discarded – undo
1331 1331
 
1332 1332
 
1333 1333
 
1334
-    /**
1335
-     * Implementation of the EEI_Event_Relation interface method
1336
-     *
1337
-     * @see EEI_Event_Relation for comments
1338
-     * @return EE_Event
1339
-     * @throws \EE_Error
1340
-     * @throws UnexpectedEntityException
1341
-     */
1334
+	/**
1335
+	 * Implementation of the EEI_Event_Relation interface method
1336
+	 *
1337
+	 * @see EEI_Event_Relation for comments
1338
+	 * @return EE_Event
1339
+	 * @throws \EE_Error
1340
+	 * @throws UnexpectedEntityException
1341
+	 */
1342 1342
 	public function get_related_event() {
1343 1343
 		//get one datetime to use for getting the event
1344 1344
 		$datetime = $this->first_datetime();
1345 1345
 		if ( ! $datetime instanceof \EE_Datetime ) {
1346 1346
 			throw new UnexpectedEntityException(
1347 1347
 				$datetime,
1348
-                'EE_Datetime',
1348
+				'EE_Datetime',
1349 1349
 				sprintf(
1350 1350
 					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1351 1351
 					$this->name()
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
 		if ( ! $event instanceof \EE_Event ) {
1357 1357
 			throw new UnexpectedEntityException(
1358 1358
 				$event,
1359
-                'EE_Event',
1359
+				'EE_Event',
1360 1360
 				sprintf(
1361 1361
 					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1362 1362
 					$this->name()
@@ -1368,14 +1368,14 @@  discard block
 block discarded – undo
1368 1368
 
1369 1369
 
1370 1370
 
1371
-    /**
1372
-     * Implementation of the EEI_Event_Relation interface method
1373
-     *
1374
-     * @see EEI_Event_Relation for comments
1375
-     * @return string
1376
-     * @throws UnexpectedEntityException
1377
-     * @throws \EE_Error
1378
-     */
1371
+	/**
1372
+	 * Implementation of the EEI_Event_Relation interface method
1373
+	 *
1374
+	 * @see EEI_Event_Relation for comments
1375
+	 * @return string
1376
+	 * @throws UnexpectedEntityException
1377
+	 * @throws \EE_Error
1378
+	 */
1379 1379
 	public function get_event_name() {
1380 1380
 		$event = $this->get_related_event();
1381 1381
 		return $event instanceof EE_Event ? $event->name() : '';
@@ -1383,28 +1383,28 @@  discard block
 block discarded – undo
1383 1383
 
1384 1384
 
1385 1385
 
1386
-    /**
1387
-     * Implementation of the EEI_Event_Relation interface method
1388
-     *
1389
-     * @see EEI_Event_Relation for comments
1390
-     * @return int
1391
-     * @throws UnexpectedEntityException
1392
-     * @throws \EE_Error
1393
-     */
1386
+	/**
1387
+	 * Implementation of the EEI_Event_Relation interface method
1388
+	 *
1389
+	 * @see EEI_Event_Relation for comments
1390
+	 * @return int
1391
+	 * @throws UnexpectedEntityException
1392
+	 * @throws \EE_Error
1393
+	 */
1394 1394
 	public function get_event_ID() {
1395 1395
 		$event = $this->get_related_event();
1396 1396
 		return $event instanceof EE_Event ? $event->ID() : 0;
1397 1397
 	}
1398 1398
 
1399 1399
 
1400
-    /**
1401
-     * This simply returns whether a ticket can be permanently deleted or not.
1402
-     * The criteria for determining this is whether the ticket has any related registrations.
1403
-     * If there are none then it can be permanently deleted.
1404
-     *
1405
-     * @return bool
1406
-     */
1400
+	/**
1401
+	 * This simply returns whether a ticket can be permanently deleted or not.
1402
+	 * The criteria for determining this is whether the ticket has any related registrations.
1403
+	 * If there are none then it can be permanently deleted.
1404
+	 *
1405
+	 * @return bool
1406
+	 */
1407 1407
 	public function is_permanently_deleteable() {
1408
-	    return $this->count_registrations() === 0;
1409
-    }
1408
+		return $this->count_registrations() === 0;
1409
+	}
1410 1410
 } //end EE_Ticket class
Please login to merge, or discard this patch.
admin/extend/messages/espresso_events_Messages_Hooks_Extend.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@
 block discarded – undo
98 98
      *
99 99
      * @param  EE_Event $event EE event object
100 100
      * @param  array    $data  The request data from the form
101
-     * @return bool success or fail
101
+     * @return integer success or fail
102 102
      * @throws EE_Error
103 103
      */
104 104
     public function attach_evt_message_templates($event, $data)
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -14,276 +14,276 @@
 block discarded – undo
14 14
  */
15 15
 class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks
16 16
 {
17
-    /**
18
-     * espresso_events_Messages_Hooks_Extend constructor.
19
-     *
20
-     * @param \EE_Admin_Page $admin_page
21
-     */
22
-    public function __construct(EE_Admin_Page $admin_page)
23
-    {
24
-        /**
25
-         * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
26
-         */
27
-        if (! EE_Registry::instance()->CAP->current_user_can(
28
-            'ee_edit_messages',
29
-            'messages_events_editor_metabox'
30
-        )) {
31
-            return;
32
-        }
33
-        add_filter(
34
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
35
-            array($this, 'caf_updates'),
36
-            10
37
-        );
38
-        add_action(
39
-            'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
40
-            array($this, 'duplicate_custom_message_settings'),
41
-            10,
42
-            2
43
-        );
44
-        parent::__construct($admin_page);
45
-    }
46
-
47
-
48
-    /**
49
-     * extending the properties set in espresso_events_Messages_Hooks
50
-     *
51
-     * @access protected
52
-     * @return void
53
-     */
54
-    protected function _extend_properties()
55
-    {
56
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
57
-        $this->_ajax_func = array(
58
-            'ee_msgs_create_new_custom' => 'create_new_custom',
59
-        );
60
-        $this->_metaboxes = array(
61
-            0 => array(
62
-                'page_route' => array('edit', 'create_new'),
63
-                'func'       => 'messages_metabox',
64
-                'label'      => esc_html__('Notifications', 'event_espresso'),
65
-                'priority'   => 'high',
66
-            ),
67
-        );
68
-
69
-        //see explanation for layout in EE_Admin_Hooks
70
-        $this->_scripts_styles = array(
71
-            'registers' => array(
72
-                'events_msg_admin'     => array(
73
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
74
-                    'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'),
75
-                ),
76
-                'events_msg_admin_css' => array(
77
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
78
-                    'type' => 'css',
79
-                ),
80
-            ),
81
-            'enqueues'  => array(
82
-                'events_msg_admin'     => array('edit', 'create_new'),
83
-                'events_msg_admin_css' => array('edit', 'create_new'),
84
-            ),
85
-        );
86
-    }
87
-
88
-
89
-    public function caf_updates($update_callbacks)
90
-    {
91
-        $update_callbacks[] = array($this, 'attach_evt_message_templates');
92
-        return $update_callbacks;
93
-    }
94
-
95
-
96
-    /**
97
-     * Handles attaching Message Templates to the Event on save.
98
-     *
99
-     * @param  EE_Event $event EE event object
100
-     * @param  array    $data  The request data from the form
101
-     * @return bool success or fail
102
-     * @throws EE_Error
103
-     */
104
-    public function attach_evt_message_templates($event, $data)
105
-    {
106
-        //first we remove all existing relations on the Event for message types.
107
-        $event->_remove_relations('Message_Template_Group');
108
-        //now let's just loop through the selected templates and add relations!
109
-        if (isset($data['event_message_templates_relation'])) {
110
-            foreach ($data['event_message_templates_relation'] as $grp_ID) {
111
-                $event->_add_relation_to($grp_ID, 'Message_Template_Group');
112
-            }
113
-        }
114
-        //now save
115
-        return $event->save();
116
-    }
117
-
118
-
119
-    /**
120
-     * @param $event
121
-     * @param $callback_args
122
-     * @return string
123
-     * @throws \EE_Error
124
-     */
125
-    public function messages_metabox($event, $callback_args)
126
-    {
127
-        //let's get the active messengers (b/c messenger objects have the active message templates)
128
-        //convert 'evt_id' to 'EVT_ID'
129
-        $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
130
-        $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID'])
131
-            ? $this->_req_data['post']
132
-            : $this->_req_data['EVT_ID'];
133
-
134
-        $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id'])
135
-            ? $this->_req_data['evt_id']
136
-            : $this->_req_data['EVT_ID'];
137
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
138
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
139
-        $active_messengers        = $message_resource_manager->active_messengers();
140
-        $tabs                     = array();
141
-
142
-        //empty messengers?
143
-        //Note message types will always have at least one available because every messenger has a default message type
144
-        // associated with it (payment) if no other message types are selected.
145
-        if (empty($active_messengers)) {
146
-            $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
147
-                array('action' => 'settings'),
148
-                EE_MSG_ADMIN_URL
149
-            );
150
-            $error_msg        = sprintf(
151
-                esc_html__(
152
-                    'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
153
-                    'event_espresso'
154
-                ),
155
-                '<strong>',
156
-                '</strong>',
157
-                '<a href="' . $msg_activate_url . '">',
158
-                '</a>'
159
-            );
160
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
161
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
162
-
163
-            echo $error_content;
164
-            echo $internal_content;
165
-            return '';
166
-        }
167
-
168
-        $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
169
-        //get content for active messengers
170
-        foreach ($active_messengers as $name => $messenger) {
171
-            //first check if there are any active message types for this messenger.
172
-            $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
173
-            if (empty($active_mts)) {
174
-                continue;
175
-            }
176
-
177
-            $tab_content = $messenger->get_messenger_admin_page_content(
178
-                'events',
179
-                'edit',
180
-                array('event' => $event_id)
181
-            );
182
-
183
-            if (! empty($tab_content)) {
184
-                $tabs[$name] = $tab_content;
185
-            }
186
-        }
187
-
188
-
189
-        //we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
190
-        $tabbed_content = EEH_Tabbed_Content::display($tabs);
191
-        if ($tabbed_content instanceof WP_Error) {
192
-            $tabbed_content = $tabbed_content->get_error_message();
193
-        }
194
-
195
-        $notices = '
17
+	/**
18
+	 * espresso_events_Messages_Hooks_Extend constructor.
19
+	 *
20
+	 * @param \EE_Admin_Page $admin_page
21
+	 */
22
+	public function __construct(EE_Admin_Page $admin_page)
23
+	{
24
+		/**
25
+		 * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
26
+		 */
27
+		if (! EE_Registry::instance()->CAP->current_user_can(
28
+			'ee_edit_messages',
29
+			'messages_events_editor_metabox'
30
+		)) {
31
+			return;
32
+		}
33
+		add_filter(
34
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
35
+			array($this, 'caf_updates'),
36
+			10
37
+		);
38
+		add_action(
39
+			'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
40
+			array($this, 'duplicate_custom_message_settings'),
41
+			10,
42
+			2
43
+		);
44
+		parent::__construct($admin_page);
45
+	}
46
+
47
+
48
+	/**
49
+	 * extending the properties set in espresso_events_Messages_Hooks
50
+	 *
51
+	 * @access protected
52
+	 * @return void
53
+	 */
54
+	protected function _extend_properties()
55
+	{
56
+		define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
57
+		$this->_ajax_func = array(
58
+			'ee_msgs_create_new_custom' => 'create_new_custom',
59
+		);
60
+		$this->_metaboxes = array(
61
+			0 => array(
62
+				'page_route' => array('edit', 'create_new'),
63
+				'func'       => 'messages_metabox',
64
+				'label'      => esc_html__('Notifications', 'event_espresso'),
65
+				'priority'   => 'high',
66
+			),
67
+		);
68
+
69
+		//see explanation for layout in EE_Admin_Hooks
70
+		$this->_scripts_styles = array(
71
+			'registers' => array(
72
+				'events_msg_admin'     => array(
73
+					'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
74
+					'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'),
75
+				),
76
+				'events_msg_admin_css' => array(
77
+					'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
78
+					'type' => 'css',
79
+				),
80
+			),
81
+			'enqueues'  => array(
82
+				'events_msg_admin'     => array('edit', 'create_new'),
83
+				'events_msg_admin_css' => array('edit', 'create_new'),
84
+			),
85
+		);
86
+	}
87
+
88
+
89
+	public function caf_updates($update_callbacks)
90
+	{
91
+		$update_callbacks[] = array($this, 'attach_evt_message_templates');
92
+		return $update_callbacks;
93
+	}
94
+
95
+
96
+	/**
97
+	 * Handles attaching Message Templates to the Event on save.
98
+	 *
99
+	 * @param  EE_Event $event EE event object
100
+	 * @param  array    $data  The request data from the form
101
+	 * @return bool success or fail
102
+	 * @throws EE_Error
103
+	 */
104
+	public function attach_evt_message_templates($event, $data)
105
+	{
106
+		//first we remove all existing relations on the Event for message types.
107
+		$event->_remove_relations('Message_Template_Group');
108
+		//now let's just loop through the selected templates and add relations!
109
+		if (isset($data['event_message_templates_relation'])) {
110
+			foreach ($data['event_message_templates_relation'] as $grp_ID) {
111
+				$event->_add_relation_to($grp_ID, 'Message_Template_Group');
112
+			}
113
+		}
114
+		//now save
115
+		return $event->save();
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param $event
121
+	 * @param $callback_args
122
+	 * @return string
123
+	 * @throws \EE_Error
124
+	 */
125
+	public function messages_metabox($event, $callback_args)
126
+	{
127
+		//let's get the active messengers (b/c messenger objects have the active message templates)
128
+		//convert 'evt_id' to 'EVT_ID'
129
+		$this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
130
+		$this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID'])
131
+			? $this->_req_data['post']
132
+			: $this->_req_data['EVT_ID'];
133
+
134
+		$this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id'])
135
+			? $this->_req_data['evt_id']
136
+			: $this->_req_data['EVT_ID'];
137
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
138
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
139
+		$active_messengers        = $message_resource_manager->active_messengers();
140
+		$tabs                     = array();
141
+
142
+		//empty messengers?
143
+		//Note message types will always have at least one available because every messenger has a default message type
144
+		// associated with it (payment) if no other message types are selected.
145
+		if (empty($active_messengers)) {
146
+			$msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
147
+				array('action' => 'settings'),
148
+				EE_MSG_ADMIN_URL
149
+			);
150
+			$error_msg        = sprintf(
151
+				esc_html__(
152
+					'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
153
+					'event_espresso'
154
+				),
155
+				'<strong>',
156
+				'</strong>',
157
+				'<a href="' . $msg_activate_url . '">',
158
+				'</a>'
159
+			);
160
+			$error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
161
+			$internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
162
+
163
+			echo $error_content;
164
+			echo $internal_content;
165
+			return '';
166
+		}
167
+
168
+		$event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
169
+		//get content for active messengers
170
+		foreach ($active_messengers as $name => $messenger) {
171
+			//first check if there are any active message types for this messenger.
172
+			$active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
173
+			if (empty($active_mts)) {
174
+				continue;
175
+			}
176
+
177
+			$tab_content = $messenger->get_messenger_admin_page_content(
178
+				'events',
179
+				'edit',
180
+				array('event' => $event_id)
181
+			);
182
+
183
+			if (! empty($tab_content)) {
184
+				$tabs[$name] = $tab_content;
185
+			}
186
+		}
187
+
188
+
189
+		//we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
190
+		$tabbed_content = EEH_Tabbed_Content::display($tabs);
191
+		if ($tabbed_content instanceof WP_Error) {
192
+			$tabbed_content = $tabbed_content->get_error_message();
193
+		}
194
+
195
+		$notices = '
196 196
 	<div id="espresso-ajax-loading" class="ajax-loader-grey">
197 197
 		<span class="ee-spinner ee-spin"></span><span class="hidden">'
198
-        . esc_html__('loading...', 'event_espresso')
199
-        . '</span>
198
+		. esc_html__('loading...', 'event_espresso')
199
+		. '</span>
200 200
 	</div>
201 201
 	<div class="ee-notices"></div>';
202 202
 
203
-        if (defined('DOING_AJAX')) {
204
-            return $tabbed_content;
205
-        }
206
-
207
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
208
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
209
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
210
-    }
211
-
212
-
213
-    /**
214
-     * Ajax callback for ee_msgs_create_new_custom ajax request.
215
-     * Takes incoming GRP_ID and name and description values from ajax request
216
-     * to create a new custom template based off of the incoming GRP_ID.
217
-     *
218
-     * @access public
219
-     * @return string either an html string will be returned or a success message
220
-     * @throws EE_Error
221
-     */
222
-    public function create_new_custom()
223
-    {
224
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
225
-            wp_die(__('You don\'t have privileges to do this action', 'event_espresso'));
226
-        }
227
-
228
-        //let's clean up the _POST global a bit for downstream usage of name and description.
229
-        $_POST['templateName']        = ! empty($this->_req_data['custom_template_args']['MTP_name'])
230
-            ? $this->_req_data['custom_template_args']['MTP_name']
231
-            : '';
232
-        $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description'])
233
-            ? $this->_req_data['custom_template_args']['MTP_description']
234
-            : '';
235
-
236
-
237
-        // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
238
-        $this->_set_page_object();
239
-
240
-        // is this a template switch if so EE_Admin_Page child needs this object
241
-        $this->_page_object->set_hook_object($this);
242
-
243
-        $this->_page_object->add_message_template(
244
-            $this->_req_data['messageType'],
245
-            $this->_req_data['messenger'],
246
-            $this->_req_data['group_ID']
247
-        );
248
-    }
249
-
250
-
251
-    public function create_new_admin_footer()
252
-    {
253
-        $this->edit_admin_footer();
254
-    }
255
-
256
-
257
-    /**
258
-     * This is the dynamic method for this class
259
-     * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
260
-     *
261
-     * @return string
262
-     * @throws DomainException
263
-     */
264
-    public function edit_admin_footer()
265
-    {
266
-        EEH_Template::display_template(
267
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
268
-        );
269
-    }
270
-
271
-
272
-    /**
273
-     * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
274
-     * the assigned custom message templates.
275
-     *
276
-     * @param EE_Event $new_event
277
-     * @param EE_Event $original_event
278
-     * @throws EE_Error
279
-     */
280
-    public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
281
-    {
282
-        $message_template_groups = $original_event->get_many_related('Message_Template_Group');
283
-        foreach ($message_template_groups as $message_template_group) {
284
-            $new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
285
-        }
286
-        //save new event
287
-        $new_event->save();
288
-    }
203
+		if (defined('DOING_AJAX')) {
204
+			return $tabbed_content;
205
+		}
206
+
207
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
208
+		echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
209
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
210
+	}
211
+
212
+
213
+	/**
214
+	 * Ajax callback for ee_msgs_create_new_custom ajax request.
215
+	 * Takes incoming GRP_ID and name and description values from ajax request
216
+	 * to create a new custom template based off of the incoming GRP_ID.
217
+	 *
218
+	 * @access public
219
+	 * @return string either an html string will be returned or a success message
220
+	 * @throws EE_Error
221
+	 */
222
+	public function create_new_custom()
223
+	{
224
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
225
+			wp_die(__('You don\'t have privileges to do this action', 'event_espresso'));
226
+		}
227
+
228
+		//let's clean up the _POST global a bit for downstream usage of name and description.
229
+		$_POST['templateName']        = ! empty($this->_req_data['custom_template_args']['MTP_name'])
230
+			? $this->_req_data['custom_template_args']['MTP_name']
231
+			: '';
232
+		$_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description'])
233
+			? $this->_req_data['custom_template_args']['MTP_description']
234
+			: '';
235
+
236
+
237
+		// set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
238
+		$this->_set_page_object();
239
+
240
+		// is this a template switch if so EE_Admin_Page child needs this object
241
+		$this->_page_object->set_hook_object($this);
242
+
243
+		$this->_page_object->add_message_template(
244
+			$this->_req_data['messageType'],
245
+			$this->_req_data['messenger'],
246
+			$this->_req_data['group_ID']
247
+		);
248
+	}
249
+
250
+
251
+	public function create_new_admin_footer()
252
+	{
253
+		$this->edit_admin_footer();
254
+	}
255
+
256
+
257
+	/**
258
+	 * This is the dynamic method for this class
259
+	 * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
260
+	 *
261
+	 * @return string
262
+	 * @throws DomainException
263
+	 */
264
+	public function edit_admin_footer()
265
+	{
266
+		EEH_Template::display_template(
267
+			EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
268
+		);
269
+	}
270
+
271
+
272
+	/**
273
+	 * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
274
+	 * the assigned custom message templates.
275
+	 *
276
+	 * @param EE_Event $new_event
277
+	 * @param EE_Event $original_event
278
+	 * @throws EE_Error
279
+	 */
280
+	public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
281
+	{
282
+		$message_template_groups = $original_event->get_many_related('Message_Template_Group');
283
+		foreach ($message_template_groups as $message_template_group) {
284
+			$new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
285
+		}
286
+		//save new event
287
+		$new_event->save();
288
+	}
289 289
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
         /**
25 25
          * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
26 26
          */
27
-        if (! EE_Registry::instance()->CAP->current_user_can(
27
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
28 28
             'ee_edit_messages',
29 29
             'messages_events_editor_metabox'
30 30
         )) {
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      */
54 54
     protected function _extend_properties()
55 55
     {
56
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
56
+        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/');
57 57
         $this->_ajax_func = array(
58 58
             'ee_msgs_create_new_custom' => 'create_new_custom',
59 59
         );
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
         $this->_scripts_styles = array(
71 71
             'registers' => array(
72 72
                 'events_msg_admin'     => array(
73
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
73
+                    'url'     => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js',
74 74
                     'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'),
75 75
                 ),
76 76
                 'events_msg_admin_css' => array(
77
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
77
+                    'url'  => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css',
78 78
                     'type' => 'css',
79 79
                 ),
80 80
             ),
@@ -147,18 +147,18 @@  discard block
 block discarded – undo
147 147
                 array('action' => 'settings'),
148 148
                 EE_MSG_ADMIN_URL
149 149
             );
150
-            $error_msg        = sprintf(
150
+            $error_msg = sprintf(
151 151
                 esc_html__(
152 152
                     'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
153 153
                     'event_espresso'
154 154
                 ),
155 155
                 '<strong>',
156 156
                 '</strong>',
157
-                '<a href="' . $msg_activate_url . '">',
157
+                '<a href="'.$msg_activate_url.'">',
158 158
                 '</a>'
159 159
             );
160
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
161
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
160
+            $error_content    = '<div class="error"><p>'.$error_msg.'</p></div>';
161
+            $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>';
162 162
 
163 163
             echo $error_content;
164 164
             echo $internal_content;
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                 array('event' => $event_id)
181 181
             );
182 182
 
183
-            if (! empty($tab_content)) {
183
+            if ( ! empty($tab_content)) {
184 184
                 $tabs[$name] = $tab_content;
185 185
             }
186 186
         }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         }
206 206
 
207 207
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
208
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
208
+        echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>';
209 209
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
210 210
     }
211 211
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      */
222 222
     public function create_new_custom()
223 223
     {
224
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
224
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
225 225
             wp_die(__('You don\'t have privileges to do this action', 'event_espresso'));
226 226
         }
227 227
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
     public function edit_admin_footer()
265 265
     {
266 266
         EEH_Template::display_template(
267
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
267
+            EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php'
268 268
         );
269 269
     }
270 270
 
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -456,7 +456,7 @@
 block discarded – undo
456 456
      * be empty
457 457
      *
458 458
      * @since 4.3.1
459
-     * @return array
459
+     * @return string[]
460 460
      */
461 461
     private function _parse_from()
462 462
     {
Please login to merge, or discard this patch.
Indentation   +543 added lines, -543 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('NO direct script access allowed');
4
+	exit('NO direct script access allowed');
5 5
 }
6 6
 
7 7
 /**
@@ -28,548 +28,548 @@  discard block
 block discarded – undo
28 28
 class EE_Email_messenger extends EE_messenger
29 29
 {
30 30
 
31
-    /**
32
-     * The following are the properties that email requires for the message going out.
33
-     */
34
-    protected $_to;
35
-    protected $_from;
36
-    protected $_subject;
37
-    protected $_content;
38
-
39
-
40
-    /**
41
-     * constructor
42
-     *
43
-     * @access public
44
-     */
45
-    public function __construct()
46
-    {
47
-        //set name and description properties
48
-        $this->name                = 'email';
49
-        $this->description         = __('This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress',
50
-            'event_espresso');
51
-        $this->label               = array(
52
-            'singular' => __('email', 'event_espresso'),
53
-            'plural'   => __('emails', 'event_espresso'),
54
-        );
55
-        $this->activate_on_install = true;
56
-
57
-        //we're using defaults so let's call parent constructor that will take care of setting up all the other properties
58
-        parent::__construct();
59
-    }
60
-
61
-
62
-    /**
63
-     * see abstract declaration in parent class for details.
64
-     */
65
-    protected function _set_admin_pages()
66
-    {
67
-        $this->admin_registered_pages = array(
68
-            'events_edit' => true,
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * see abstract declaration in parent class for details
75
-     */
76
-    protected function _set_valid_shortcodes()
77
-    {
78
-        //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the message type.
79
-        $this->_valid_shortcodes = array(
80
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
81
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
82
-        );
83
-    }
84
-
85
-
86
-    /**
87
-     * see abstract declaration in parent class for details
88
-     *
89
-     * @access protected
90
-     * @return void
91
-     */
92
-    protected function _set_validator_config()
93
-    {
94
-        $valid_shortcodes = $this->get_valid_shortcodes();
95
-
96
-        $this->_validator_config = array(
97
-            'to'            => array(
98
-                'shortcodes' => $valid_shortcodes['to'],
99
-                'type'       => 'email',
100
-            ),
101
-            'from'          => array(
102
-                'shortcodes' => $valid_shortcodes['from'],
103
-                'type'       => 'email',
104
-            ),
105
-            'subject'       => array(
106
-                'shortcodes' => array(
107
-                    'organization',
108
-                    'primary_registration_details',
109
-                    'event_author',
110
-                    'primary_registration_details',
111
-                    'recipient_details',
112
-                ),
113
-            ),
114
-            'content'       => array(
115
-                'shortcodes' => array(
116
-                    'event_list',
117
-                    'attendee_list',
118
-                    'ticket_list',
119
-                    'organization',
120
-                    'primary_registration_details',
121
-                    'primary_registration_list',
122
-                    'event_author',
123
-                    'recipient_details',
124
-                    'recipient_list',
125
-                    'transaction',
126
-                    'messenger',
127
-                ),
128
-            ),
129
-            'attendee_list' => array(
130
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
131
-                'required'   => array('[ATTENDEE_LIST]'),
132
-            ),
133
-            'event_list'    => array(
134
-                'shortcodes' => array(
135
-                    'event',
136
-                    'attendee_list',
137
-                    'ticket_list',
138
-                    'venue',
139
-                    'datetime_list',
140
-                    'attendee',
141
-                    'primary_registration_details',
142
-                    'primary_registration_list',
143
-                    'event_author',
144
-                    'recipient_details',
145
-                    'recipient_list',
146
-                ),
147
-                'required'   => array('[EVENT_LIST]'),
148
-            ),
149
-            'ticket_list'   => array(
150
-                'shortcodes' => array(
151
-                    'event_list',
152
-                    'attendee_list',
153
-                    'ticket',
154
-                    'datetime_list',
155
-                    'primary_registration_details',
156
-                    'recipient_details',
157
-                ),
158
-                'required'   => array('[TICKET_LIST]'),
159
-            ),
160
-            'datetime_list' => array(
161
-                'shortcodes' => array('datetime'),
162
-                'required'   => array('[DATETIME_LIST]'),
163
-            ),
164
-        );
165
-    }
166
-
167
-
168
-    /**
169
-     * @see   parent EE_messenger class for docs
170
-     * @since 4.5.0
171
-     */
172
-    public function do_secondary_messenger_hooks($sending_messenger_name)
173
-    {
174
-        if ($sending_messenger_name = 'html') {
175
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
176
-        }
177
-    }
178
-
179
-
180
-    public function add_email_css(
181
-        $variation_path,
182
-        $messenger,
183
-        $message_type,
184
-        $type,
185
-        $variation,
186
-        $file_extension,
187
-        $url,
188
-        EE_Messages_Template_Pack $template_pack
189
-    ) {
190
-        //prevent recursion on this callback.
191
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
192
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
193
-
194
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
195
-        return $variation;
196
-    }
197
-
198
-
199
-    /**
200
-     * See parent for details
201
-     *
202
-     * @access protected
203
-     * @return void
204
-     */
205
-    protected function _set_test_settings_fields()
206
-    {
207
-        $this->_test_settings_fields = array(
208
-            'to'      => array(
209
-                'input'      => 'text',
210
-                'label'      => __('Send a test email to', 'event_espresso'),
211
-                'type'       => 'email',
212
-                'required'   => true,
213
-                'validation' => true,
214
-                'css_class'  => 'large-text',
215
-                'format'     => '%s',
216
-                'default'    => get_bloginfo('admin_email'),
217
-            ),
218
-            'subject' => array(
219
-                'input'      => 'hidden',
220
-                'label'      => '',
221
-                'type'       => 'string',
222
-                'required'   => false,
223
-                'validation' => false,
224
-                'format'     => '%s',
225
-                'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
226
-                'default'    => '',
227
-                'css_class'  => '',
228
-            ),
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * _set_template_fields
235
-     * This sets up the fields that a messenger requires for the message to go out.
236
-     *
237
-     * @access  protected
238
-     * @return void
239
-     */
240
-    protected function _set_template_fields()
241
-    {
242
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to.  This is important for the Messages_admin to know what fields to display to the user.  Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed.
243
-        $this->_template_fields = array(
244
-            'to'      => array(
245
-                'input'      => 'text',
246
-                'label'      => __('To', 'event_espresso'),
247
-                'type'       => 'string',
248
-                'required'   => true,
249
-                'validation' => true,
250
-                'css_class'  => 'large-text',
251
-                'format'     => '%s',
252
-            ),
253
-            'from'    => array(
254
-                'input'      => 'text',
255
-                'label'      => __('From', 'event_espresso'),
256
-                'type'       => 'string',
257
-                'required'   => true,
258
-                'validation' => true,
259
-                'css_class'  => 'large-text',
260
-                'format'     => '%s',
261
-            ),
262
-            'subject' => array(
263
-                'input'      => 'text',
264
-                'label'      => __('Subject', 'event_espresso'),
265
-                'type'       => 'string',
266
-                'required'   => true,
267
-                'validation' => true,
268
-                'css_class'  => 'large-text',
269
-                'format'     => '%s',
270
-            ),
271
-            'content' => '',
272
-            //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
273
-            'extra'   => array(
274
-                'content' => array(
275
-                    'main'          => array(
276
-                        'input'      => 'wp_editor',
277
-                        'label'      => __('Main Content', 'event_espresso'),
278
-                        'type'       => 'string',
279
-                        'required'   => true,
280
-                        'validation' => true,
281
-                        'format'     => '%s',
282
-                        'rows'       => '15',
283
-                    ),
284
-                    'event_list'    => array(
285
-                        'input'               => 'wp_editor',
286
-                        'label'               => '[EVENT_LIST]',
287
-                        'type'                => 'string',
288
-                        'required'            => true,
289
-                        'validation'          => true,
290
-                        'format'              => '%s',
291
-                        'rows'                => '15',
292
-                        'shortcodes_required' => array('[EVENT_LIST]'),
293
-                    ),
294
-                    'attendee_list' => array(
295
-                        'input'               => 'textarea',
296
-                        'label'               => '[ATTENDEE_LIST]',
297
-                        'type'                => 'string',
298
-                        'required'            => true,
299
-                        'validation'          => true,
300
-                        'format'              => '%s',
301
-                        'css_class'           => 'large-text',
302
-                        'rows'                => '5',
303
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
304
-                    ),
305
-                    'ticket_list'   => array(
306
-                        'input'               => 'textarea',
307
-                        'label'               => '[TICKET_LIST]',
308
-                        'type'                => 'string',
309
-                        'required'            => true,
310
-                        'validation'          => true,
311
-                        'format'              => '%s',
312
-                        'css_class'           => 'large-text',
313
-                        'rows'                => '10',
314
-                        'shortcodes_required' => array('[TICKET_LIST]'),
315
-                    ),
316
-                    'datetime_list' => array(
317
-                        'input'               => 'textarea',
318
-                        'label'               => '[DATETIME_LIST]',
319
-                        'type'                => 'string',
320
-                        'required'            => true,
321
-                        'validation'          => true,
322
-                        'format'              => '%s',
323
-                        'css_class'           => 'large-text',
324
-                        'rows'                => '10',
325
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
326
-                    ),
327
-                ),
328
-            ),
329
-        );
330
-    }
331
-
332
-
333
-    /**
334
-     * See definition of this class in parent
335
-     */
336
-    protected function _set_default_message_types()
337
-    {
338
-        $this->_default_message_types = array(
339
-            'payment',
340
-            'payment_refund',
341
-            'registration',
342
-            'not_approved_registration',
343
-            'pending_approval',
344
-        );
345
-    }
346
-
347
-
348
-    /**
349
-     * @see   definition of this class in parent
350
-     * @since 4.5.0
351
-     */
352
-    protected function _set_valid_message_types()
353
-    {
354
-        $this->_valid_message_types = array(
355
-            'payment',
356
-            'registration',
357
-            'not_approved_registration',
358
-            'declined_registration',
359
-            'cancelled_registration',
360
-            'pending_approval',
361
-            'registration_summary',
362
-            'payment_reminder',
363
-            'payment_declined',
364
-            'payment_refund',
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * setting up admin_settings_fields for messenger.
371
-     */
372
-    protected function _set_admin_settings_fields()
373
-    {
374
-    }
375
-
376
-    /**
377
-     * We just deliver the messages don't kill us!!
378
-     *
379
-     * @return bool | WP_Error  true if message delivered, false if it didn't deliver OR bubble up any error object if
380
-     *              present.
381
-     */
382
-    protected function _send_message()
383
-    {
384
-        $success = wp_mail(
385
-            html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"),
386
-            stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")),
387
-            $this->_body(),
388
-            $this->_headers()
389
-        );
390
-        if (! $success) {
391
-            EE_Error::add_error(
392
-                sprintf(
393
-                    __('The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
394
-                        'event_espresso'),
395
-                    $this->_to,
396
-                    $this->_from,
397
-                    '<br />'
398
-                ),
399
-                __FILE__, __FUNCTION__, __LINE__
400
-            );
401
-        }
402
-        return $success;
403
-    }
404
-
405
-
406
-    /**
407
-     * see parent for definition
408
-     *
409
-     * @return string html body of the message content and the related css.
410
-     */
411
-    protected function _preview()
412
-    {
413
-        return $this->_body(true);
414
-    }
415
-
416
-
417
-    /**
418
-     * Setup headers for email
419
-     *
420
-     * @access protected
421
-     * @return string formatted header for email
422
-     */
423
-    protected function _headers()
424
-    {
425
-        $this->_ensure_has_from_email_address();
426
-        $from    = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));
427
-        $headers = array(
428
-            'MIME-Version: 1.0',
429
-            'From:' . $from,
430
-            'Reply-To:' . $from,
431
-            'Content-Type:text/html; charset=utf-8',
432
-        );
433
-
434
-        //but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the header.
435
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
436
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
437
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
438
-    }
439
-
440
-
441
-    /**
442
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
443
-     * address for the from address to avoid problems with sending emails.
444
-     */
445
-    protected function _ensure_has_from_email_address()
446
-    {
447
-        if (empty($this->_from)) {
448
-            $this->_from = get_bloginfo('admin_email');
449
-        }
450
-    }
451
-
452
-
453
-    /**
454
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
455
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
456
-     * be empty
457
-     *
458
-     * @since 4.3.1
459
-     * @return array
460
-     */
461
-    private function _parse_from()
462
-    {
463
-        if (strpos($this->_from, '<') !== false) {
464
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
465
-            $from_name = str_replace('"', '', $from_name);
466
-            $from_name = trim($from_name);
467
-
468
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
469
-            $from_email = str_replace('>', '', $from_email);
470
-            $from_email = trim($from_email);
471
-        } elseif (trim($this->_from) !== '') {
472
-            $from_name  = '';
473
-            $from_email = trim($this->_from);
474
-        } else {
475
-            $from_name = $from_email = '';
476
-        }
477
-        return array($from_name, $from_email);
478
-    }
479
-
480
-
481
-    /**
482
-     * Callback for the wp_mail_from filter.
483
-     *
484
-     * @since 4.3.1
485
-     * @param string $from_email What the original from_email is.
486
-     */
487
-    public function set_from_address($from_email)
488
-    {
489
-        $parsed_from = $this->_parse_from();
490
-        //includes fallback if the parsing failed.
491
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) ? $parsed_from[1] : get_bloginfo('admin_email');
492
-        return $from_email;
493
-    }
494
-
495
-
496
-    /**
497
-     * Callback fro the wp_mail_from_name filter.
498
-     *
499
-     * @since 4.3.1
500
-     * @param string $from_name The original from_name.
501
-     */
502
-    public function set_from_name($from_name)
503
-    {
504
-        $parsed_from = $this->_parse_from();
505
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
506
-            $from_name = $parsed_from[0];
507
-        }
508
-
509
-        //if from name is "WordPress" let's sub in the site name instead (more friendly!)
510
-        $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name;
511
-
512
-        return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8"));
513
-    }
514
-
515
-
516
-    /**
517
-     * setup body for email
518
-     *
519
-     * @param bool $preview will determine whether this is preview template or not.
520
-     * @return string formatted body for email.
521
-     */
522
-    protected function _body($preview = false)
523
-    {
524
-        //setup template args!
525
-        $this->_template_args = array(
526
-            'subject'   => $this->_subject,
527
-            'from'      => $this->_from,
528
-            'main_body' => wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))),
529
-        );
530
-        $body                 = $this->_get_main_template($preview);
531
-
532
-        /**
533
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
534
-         *
535
-         * @type    bool $preview Indicates whether a preview is being generated or not.
536
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
537
-         */
538
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
539
-
540
-            //require CssToInlineStyles library and its dependencies via composer autoloader
541
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
542
-
543
-            //now if this isn't a preview, let's setup the body so it has inline styles
544
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
545
-                $style = file_get_contents($this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name,
546
-                    false, 'main', $this->_variation), true);
547
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
548
-                $body  = ltrim($CSS->convert(true),
549
-                    ">\n"); //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
550
-                $body  = ltrim($body, "<?"); //see https://events.codebasehq.com/projects/event-espresso/tickets/8609
551
-            }
552
-
553
-        }
554
-        return $body;
555
-    }
556
-
557
-
558
-    /**
559
-     * This just returns any existing test settings that might be saved in the database
560
-     *
561
-     * @access public
562
-     * @return array
563
-     */
564
-    public function get_existing_test_settings()
565
-    {
566
-        $settings = parent::get_existing_test_settings();
567
-        //override subject if present because we always want it to be fresh.
568
-        if (is_array($settings) && ! empty($settings['subject'])) {
569
-            $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
570
-        }
571
-        return $settings;
572
-    }
31
+	/**
32
+	 * The following are the properties that email requires for the message going out.
33
+	 */
34
+	protected $_to;
35
+	protected $_from;
36
+	protected $_subject;
37
+	protected $_content;
38
+
39
+
40
+	/**
41
+	 * constructor
42
+	 *
43
+	 * @access public
44
+	 */
45
+	public function __construct()
46
+	{
47
+		//set name and description properties
48
+		$this->name                = 'email';
49
+		$this->description         = __('This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress',
50
+			'event_espresso');
51
+		$this->label               = array(
52
+			'singular' => __('email', 'event_espresso'),
53
+			'plural'   => __('emails', 'event_espresso'),
54
+		);
55
+		$this->activate_on_install = true;
56
+
57
+		//we're using defaults so let's call parent constructor that will take care of setting up all the other properties
58
+		parent::__construct();
59
+	}
60
+
61
+
62
+	/**
63
+	 * see abstract declaration in parent class for details.
64
+	 */
65
+	protected function _set_admin_pages()
66
+	{
67
+		$this->admin_registered_pages = array(
68
+			'events_edit' => true,
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * see abstract declaration in parent class for details
75
+	 */
76
+	protected function _set_valid_shortcodes()
77
+	{
78
+		//remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the message type.
79
+		$this->_valid_shortcodes = array(
80
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
81
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
82
+		);
83
+	}
84
+
85
+
86
+	/**
87
+	 * see abstract declaration in parent class for details
88
+	 *
89
+	 * @access protected
90
+	 * @return void
91
+	 */
92
+	protected function _set_validator_config()
93
+	{
94
+		$valid_shortcodes = $this->get_valid_shortcodes();
95
+
96
+		$this->_validator_config = array(
97
+			'to'            => array(
98
+				'shortcodes' => $valid_shortcodes['to'],
99
+				'type'       => 'email',
100
+			),
101
+			'from'          => array(
102
+				'shortcodes' => $valid_shortcodes['from'],
103
+				'type'       => 'email',
104
+			),
105
+			'subject'       => array(
106
+				'shortcodes' => array(
107
+					'organization',
108
+					'primary_registration_details',
109
+					'event_author',
110
+					'primary_registration_details',
111
+					'recipient_details',
112
+				),
113
+			),
114
+			'content'       => array(
115
+				'shortcodes' => array(
116
+					'event_list',
117
+					'attendee_list',
118
+					'ticket_list',
119
+					'organization',
120
+					'primary_registration_details',
121
+					'primary_registration_list',
122
+					'event_author',
123
+					'recipient_details',
124
+					'recipient_list',
125
+					'transaction',
126
+					'messenger',
127
+				),
128
+			),
129
+			'attendee_list' => array(
130
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
131
+				'required'   => array('[ATTENDEE_LIST]'),
132
+			),
133
+			'event_list'    => array(
134
+				'shortcodes' => array(
135
+					'event',
136
+					'attendee_list',
137
+					'ticket_list',
138
+					'venue',
139
+					'datetime_list',
140
+					'attendee',
141
+					'primary_registration_details',
142
+					'primary_registration_list',
143
+					'event_author',
144
+					'recipient_details',
145
+					'recipient_list',
146
+				),
147
+				'required'   => array('[EVENT_LIST]'),
148
+			),
149
+			'ticket_list'   => array(
150
+				'shortcodes' => array(
151
+					'event_list',
152
+					'attendee_list',
153
+					'ticket',
154
+					'datetime_list',
155
+					'primary_registration_details',
156
+					'recipient_details',
157
+				),
158
+				'required'   => array('[TICKET_LIST]'),
159
+			),
160
+			'datetime_list' => array(
161
+				'shortcodes' => array('datetime'),
162
+				'required'   => array('[DATETIME_LIST]'),
163
+			),
164
+		);
165
+	}
166
+
167
+
168
+	/**
169
+	 * @see   parent EE_messenger class for docs
170
+	 * @since 4.5.0
171
+	 */
172
+	public function do_secondary_messenger_hooks($sending_messenger_name)
173
+	{
174
+		if ($sending_messenger_name = 'html') {
175
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
176
+		}
177
+	}
178
+
179
+
180
+	public function add_email_css(
181
+		$variation_path,
182
+		$messenger,
183
+		$message_type,
184
+		$type,
185
+		$variation,
186
+		$file_extension,
187
+		$url,
188
+		EE_Messages_Template_Pack $template_pack
189
+	) {
190
+		//prevent recursion on this callback.
191
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
192
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
193
+
194
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
195
+		return $variation;
196
+	}
197
+
198
+
199
+	/**
200
+	 * See parent for details
201
+	 *
202
+	 * @access protected
203
+	 * @return void
204
+	 */
205
+	protected function _set_test_settings_fields()
206
+	{
207
+		$this->_test_settings_fields = array(
208
+			'to'      => array(
209
+				'input'      => 'text',
210
+				'label'      => __('Send a test email to', 'event_espresso'),
211
+				'type'       => 'email',
212
+				'required'   => true,
213
+				'validation' => true,
214
+				'css_class'  => 'large-text',
215
+				'format'     => '%s',
216
+				'default'    => get_bloginfo('admin_email'),
217
+			),
218
+			'subject' => array(
219
+				'input'      => 'hidden',
220
+				'label'      => '',
221
+				'type'       => 'string',
222
+				'required'   => false,
223
+				'validation' => false,
224
+				'format'     => '%s',
225
+				'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
226
+				'default'    => '',
227
+				'css_class'  => '',
228
+			),
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * _set_template_fields
235
+	 * This sets up the fields that a messenger requires for the message to go out.
236
+	 *
237
+	 * @access  protected
238
+	 * @return void
239
+	 */
240
+	protected function _set_template_fields()
241
+	{
242
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to.  This is important for the Messages_admin to know what fields to display to the user.  Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed.
243
+		$this->_template_fields = array(
244
+			'to'      => array(
245
+				'input'      => 'text',
246
+				'label'      => __('To', 'event_espresso'),
247
+				'type'       => 'string',
248
+				'required'   => true,
249
+				'validation' => true,
250
+				'css_class'  => 'large-text',
251
+				'format'     => '%s',
252
+			),
253
+			'from'    => array(
254
+				'input'      => 'text',
255
+				'label'      => __('From', 'event_espresso'),
256
+				'type'       => 'string',
257
+				'required'   => true,
258
+				'validation' => true,
259
+				'css_class'  => 'large-text',
260
+				'format'     => '%s',
261
+			),
262
+			'subject' => array(
263
+				'input'      => 'text',
264
+				'label'      => __('Subject', 'event_espresso'),
265
+				'type'       => 'string',
266
+				'required'   => true,
267
+				'validation' => true,
268
+				'css_class'  => 'large-text',
269
+				'format'     => '%s',
270
+			),
271
+			'content' => '',
272
+			//left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
273
+			'extra'   => array(
274
+				'content' => array(
275
+					'main'          => array(
276
+						'input'      => 'wp_editor',
277
+						'label'      => __('Main Content', 'event_espresso'),
278
+						'type'       => 'string',
279
+						'required'   => true,
280
+						'validation' => true,
281
+						'format'     => '%s',
282
+						'rows'       => '15',
283
+					),
284
+					'event_list'    => array(
285
+						'input'               => 'wp_editor',
286
+						'label'               => '[EVENT_LIST]',
287
+						'type'                => 'string',
288
+						'required'            => true,
289
+						'validation'          => true,
290
+						'format'              => '%s',
291
+						'rows'                => '15',
292
+						'shortcodes_required' => array('[EVENT_LIST]'),
293
+					),
294
+					'attendee_list' => array(
295
+						'input'               => 'textarea',
296
+						'label'               => '[ATTENDEE_LIST]',
297
+						'type'                => 'string',
298
+						'required'            => true,
299
+						'validation'          => true,
300
+						'format'              => '%s',
301
+						'css_class'           => 'large-text',
302
+						'rows'                => '5',
303
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
304
+					),
305
+					'ticket_list'   => array(
306
+						'input'               => 'textarea',
307
+						'label'               => '[TICKET_LIST]',
308
+						'type'                => 'string',
309
+						'required'            => true,
310
+						'validation'          => true,
311
+						'format'              => '%s',
312
+						'css_class'           => 'large-text',
313
+						'rows'                => '10',
314
+						'shortcodes_required' => array('[TICKET_LIST]'),
315
+					),
316
+					'datetime_list' => array(
317
+						'input'               => 'textarea',
318
+						'label'               => '[DATETIME_LIST]',
319
+						'type'                => 'string',
320
+						'required'            => true,
321
+						'validation'          => true,
322
+						'format'              => '%s',
323
+						'css_class'           => 'large-text',
324
+						'rows'                => '10',
325
+						'shortcodes_required' => array('[DATETIME_LIST]'),
326
+					),
327
+				),
328
+			),
329
+		);
330
+	}
331
+
332
+
333
+	/**
334
+	 * See definition of this class in parent
335
+	 */
336
+	protected function _set_default_message_types()
337
+	{
338
+		$this->_default_message_types = array(
339
+			'payment',
340
+			'payment_refund',
341
+			'registration',
342
+			'not_approved_registration',
343
+			'pending_approval',
344
+		);
345
+	}
346
+
347
+
348
+	/**
349
+	 * @see   definition of this class in parent
350
+	 * @since 4.5.0
351
+	 */
352
+	protected function _set_valid_message_types()
353
+	{
354
+		$this->_valid_message_types = array(
355
+			'payment',
356
+			'registration',
357
+			'not_approved_registration',
358
+			'declined_registration',
359
+			'cancelled_registration',
360
+			'pending_approval',
361
+			'registration_summary',
362
+			'payment_reminder',
363
+			'payment_declined',
364
+			'payment_refund',
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * setting up admin_settings_fields for messenger.
371
+	 */
372
+	protected function _set_admin_settings_fields()
373
+	{
374
+	}
375
+
376
+	/**
377
+	 * We just deliver the messages don't kill us!!
378
+	 *
379
+	 * @return bool | WP_Error  true if message delivered, false if it didn't deliver OR bubble up any error object if
380
+	 *              present.
381
+	 */
382
+	protected function _send_message()
383
+	{
384
+		$success = wp_mail(
385
+			html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"),
386
+			stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")),
387
+			$this->_body(),
388
+			$this->_headers()
389
+		);
390
+		if (! $success) {
391
+			EE_Error::add_error(
392
+				sprintf(
393
+					__('The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
394
+						'event_espresso'),
395
+					$this->_to,
396
+					$this->_from,
397
+					'<br />'
398
+				),
399
+				__FILE__, __FUNCTION__, __LINE__
400
+			);
401
+		}
402
+		return $success;
403
+	}
404
+
405
+
406
+	/**
407
+	 * see parent for definition
408
+	 *
409
+	 * @return string html body of the message content and the related css.
410
+	 */
411
+	protected function _preview()
412
+	{
413
+		return $this->_body(true);
414
+	}
415
+
416
+
417
+	/**
418
+	 * Setup headers for email
419
+	 *
420
+	 * @access protected
421
+	 * @return string formatted header for email
422
+	 */
423
+	protected function _headers()
424
+	{
425
+		$this->_ensure_has_from_email_address();
426
+		$from    = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));
427
+		$headers = array(
428
+			'MIME-Version: 1.0',
429
+			'From:' . $from,
430
+			'Reply-To:' . $from,
431
+			'Content-Type:text/html; charset=utf-8',
432
+		);
433
+
434
+		//but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the header.
435
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
436
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
437
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
438
+	}
439
+
440
+
441
+	/**
442
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
443
+	 * address for the from address to avoid problems with sending emails.
444
+	 */
445
+	protected function _ensure_has_from_email_address()
446
+	{
447
+		if (empty($this->_from)) {
448
+			$this->_from = get_bloginfo('admin_email');
449
+		}
450
+	}
451
+
452
+
453
+	/**
454
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
455
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
456
+	 * be empty
457
+	 *
458
+	 * @since 4.3.1
459
+	 * @return array
460
+	 */
461
+	private function _parse_from()
462
+	{
463
+		if (strpos($this->_from, '<') !== false) {
464
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
465
+			$from_name = str_replace('"', '', $from_name);
466
+			$from_name = trim($from_name);
467
+
468
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
469
+			$from_email = str_replace('>', '', $from_email);
470
+			$from_email = trim($from_email);
471
+		} elseif (trim($this->_from) !== '') {
472
+			$from_name  = '';
473
+			$from_email = trim($this->_from);
474
+		} else {
475
+			$from_name = $from_email = '';
476
+		}
477
+		return array($from_name, $from_email);
478
+	}
479
+
480
+
481
+	/**
482
+	 * Callback for the wp_mail_from filter.
483
+	 *
484
+	 * @since 4.3.1
485
+	 * @param string $from_email What the original from_email is.
486
+	 */
487
+	public function set_from_address($from_email)
488
+	{
489
+		$parsed_from = $this->_parse_from();
490
+		//includes fallback if the parsing failed.
491
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1]) ? $parsed_from[1] : get_bloginfo('admin_email');
492
+		return $from_email;
493
+	}
494
+
495
+
496
+	/**
497
+	 * Callback fro the wp_mail_from_name filter.
498
+	 *
499
+	 * @since 4.3.1
500
+	 * @param string $from_name The original from_name.
501
+	 */
502
+	public function set_from_name($from_name)
503
+	{
504
+		$parsed_from = $this->_parse_from();
505
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
506
+			$from_name = $parsed_from[0];
507
+		}
508
+
509
+		//if from name is "WordPress" let's sub in the site name instead (more friendly!)
510
+		$from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name;
511
+
512
+		return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8"));
513
+	}
514
+
515
+
516
+	/**
517
+	 * setup body for email
518
+	 *
519
+	 * @param bool $preview will determine whether this is preview template or not.
520
+	 * @return string formatted body for email.
521
+	 */
522
+	protected function _body($preview = false)
523
+	{
524
+		//setup template args!
525
+		$this->_template_args = array(
526
+			'subject'   => $this->_subject,
527
+			'from'      => $this->_from,
528
+			'main_body' => wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))),
529
+		);
530
+		$body                 = $this->_get_main_template($preview);
531
+
532
+		/**
533
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
534
+		 *
535
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
536
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
537
+		 */
538
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
539
+
540
+			//require CssToInlineStyles library and its dependencies via composer autoloader
541
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
542
+
543
+			//now if this isn't a preview, let's setup the body so it has inline styles
544
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
545
+				$style = file_get_contents($this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name,
546
+					false, 'main', $this->_variation), true);
547
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
548
+				$body  = ltrim($CSS->convert(true),
549
+					">\n"); //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
550
+				$body  = ltrim($body, "<?"); //see https://events.codebasehq.com/projects/event-espresso/tickets/8609
551
+			}
552
+
553
+		}
554
+		return $body;
555
+	}
556
+
557
+
558
+	/**
559
+	 * This just returns any existing test settings that might be saved in the database
560
+	 *
561
+	 * @access public
562
+	 * @return array
563
+	 */
564
+	public function get_existing_test_settings()
565
+	{
566
+		$settings = parent::get_existing_test_settings();
567
+		//override subject if present because we always want it to be fresh.
568
+		if (is_array($settings) && ! empty($settings['subject'])) {
569
+			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
570
+		}
571
+		return $settings;
572
+	}
573 573
 
574 574
 
575 575
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('NO direct script access allowed');
5 5
 }
6 6
 
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
             $this->_body(),
388 388
             $this->_headers()
389 389
         );
390
-        if (! $success) {
390
+        if ( ! $success) {
391 391
             EE_Error::add_error(
392 392
                 sprintf(
393 393
                     __('The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
@@ -426,8 +426,8 @@  discard block
 block discarded – undo
426 426
         $from    = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));
427 427
         $headers = array(
428 428
             'MIME-Version: 1.0',
429
-            'From:' . $from,
430
-            'Reply-To:' . $from,
429
+            'From:'.$from,
430
+            'Reply-To:'.$from,
431 431
             'Content-Type:text/html; charset=utf-8',
432 432
         );
433 433
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
             'from'      => $this->_from,
528 528
             'main_body' => wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))),
529 529
         );
530
-        $body                 = $this->_get_main_template($preview);
530
+        $body = $this->_get_main_template($preview);
531 531
 
532 532
         /**
533 533
          * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
@@ -538,10 +538,10 @@  discard block
 block discarded – undo
538 538
         if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
539 539
 
540 540
             //require CssToInlineStyles library and its dependencies via composer autoloader
541
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
541
+            require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php';
542 542
 
543 543
             //now if this isn't a preview, let's setup the body so it has inline styles
544
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
544
+            if ( ! $preview || ($preview && defined('DOING_AJAX'))) {
545 545
                 $style = file_get_contents($this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name,
546 546
                     false, 'main', $this->_variation), true);
547 547
                 $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Indentation   +732 added lines, -732 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -21,737 +21,737 @@  discard block
 block discarded – undo
21 21
 class EE_Dependency_Map
22 22
 {
23 23
 
24
-    /**
25
-     * This means that the requested class dependency is not present in the dependency map
26
-     */
27
-    const not_registered = 0;
28
-
29
-    /**
30
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
31
-     */
32
-    const load_new_object = 1;
33
-
34
-    /**
35
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
36
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
37
-     */
38
-    const load_from_cache = 2;
39
-
40
-    /**
41
-     * When registering a dependency,
42
-     * this indicates to keep any existing dependencies that already exist,
43
-     * and simply discard any new dependencies declared in the incoming data
44
-     */
45
-    const KEEP_EXISTING_DEPENDENCIES = 0;
46
-
47
-    /**
48
-     * When registering a dependency,
49
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
50
-     */
51
-    const OVERWRITE_DEPENDENCIES = 1;
52
-
53
-
54
-
55
-    /**
56
-     * @type EE_Dependency_Map $_instance
57
-     */
58
-    protected static $_instance;
59
-
60
-    /**
61
-     * @type EE_Request $request
62
-     */
63
-    protected $_request;
64
-
65
-    /**
66
-     * @type EE_Response $response
67
-     */
68
-    protected $_response;
69
-
70
-    /**
71
-     * @type LoaderInterface $loader
72
-     */
73
-    protected $loader;
74
-
75
-    /**
76
-     * @type array $_dependency_map
77
-     */
78
-    protected $_dependency_map = array();
79
-
80
-    /**
81
-     * @type array $_class_loaders
82
-     */
83
-    protected $_class_loaders = array();
84
-
85
-    /**
86
-     * @type array $_aliases
87
-     */
88
-    protected $_aliases = array();
89
-
90
-
91
-
92
-    /**
93
-     * EE_Dependency_Map constructor.
94
-     *
95
-     * @param EE_Request  $request
96
-     * @param EE_Response $response
97
-     */
98
-    protected function __construct(EE_Request $request, EE_Response $response)
99
-    {
100
-        $this->_request = $request;
101
-        $this->_response = $response;
102
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
103
-        do_action('EE_Dependency_Map____construct');
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidInterfaceException
111
-     * @throws InvalidArgumentException
112
-     */
113
-    public function initialize()
114
-    {
115
-        $this->_register_core_dependencies();
116
-        $this->_register_core_class_loaders();
117
-        $this->_register_core_aliases();
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @singleton method used to instantiate class object
124
-     * @access    public
125
-     * @param EE_Request  $request
126
-     * @param EE_Response $response
127
-     * @return EE_Dependency_Map
128
-     */
129
-    public static function instance(EE_Request $request = null, EE_Response $response = null)
130
-    {
131
-        // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
133
-            self::$_instance = new EE_Dependency_Map($request, $response);
134
-        }
135
-        return self::$_instance;
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * @param LoaderInterface $loader
142
-     */
143
-    public function setLoader(LoaderInterface $loader)
144
-    {
145
-        $this->loader = $loader;
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * @param string $class
152
-     * @param array  $dependencies
153
-     * @param int    $overwrite
154
-     * @return bool
155
-     */
156
-    public static function register_dependencies(
157
-        $class,
158
-        array $dependencies,
159
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
160
-    ) {
161
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * Assigns an array of class names and corresponding load sources (new or cached)
168
-     * to the class specified by the first parameter.
169
-     * IMPORTANT !!!
170
-     * The order of elements in the incoming $dependencies array MUST match
171
-     * the order of the constructor parameters for the class in question.
172
-     * This is especially important when overriding any existing dependencies that are registered.
173
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
174
-     *
175
-     * @param string $class
176
-     * @param array  $dependencies
177
-     * @param int    $overwrite
178
-     * @return bool
179
-     */
180
-    public function registerDependencies(
181
-        $class,
182
-        array $dependencies,
183
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
184
-    ) {
185
-        $class = trim($class, '\\');
186
-        $registered = false;
187
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
188
-            self::$_instance->_dependency_map[ $class ] = array();
189
-        }
190
-        // we need to make sure that any aliases used when registering a dependency
191
-        // get resolved to the correct class name
192
-        foreach ((array)$dependencies as $dependency => $load_source) {
193
-            $alias = self::$_instance->get_alias($dependency);
194
-            if (
195
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
196
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
197
-            ) {
198
-                unset($dependencies[$dependency]);
199
-                $dependencies[$alias] = $load_source;
200
-                $registered = true;
201
-            }
202
-        }
203
-        // now add our two lists of dependencies together.
204
-        // using Union (+=) favours the arrays in precedence from left to right,
205
-        // so $dependencies is NOT overwritten because it is listed first
206
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
207
-        // Union is way faster than array_merge() but should be used with caution...
208
-        // especially with numerically indexed arrays
209
-        $dependencies += self::$_instance->_dependency_map[ $class ];
210
-        // now we need to ensure that the resulting dependencies
211
-        // array only has the entries that are required for the class
212
-        // so first count how many dependencies were originally registered for the class
213
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
214
-        // if that count is non-zero (meaning dependencies were already registered)
215
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
216
-            // then truncate the  final array to match that count
217
-            ? array_slice($dependencies, 0, $dependency_count)
218
-            // otherwise just take the incoming array because nothing previously existed
219
-            : $dependencies;
220
-        return $registered;
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * @param string $class_name
227
-     * @param string $loader
228
-     * @return bool
229
-     * @throws DomainException
230
-     */
231
-    public static function register_class_loader($class_name, $loader = 'load_core')
232
-    {
233
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
234
-            throw new DomainException(
235
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
236
-            );
237
-        }
238
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
239
-        if (
240
-            ! is_callable($loader)
241
-            && (
242
-                strpos($loader, 'load_') !== 0
243
-                || ! method_exists('EE_Registry', $loader)
244
-            )
245
-        ) {
246
-            throw new DomainException(
247
-                sprintf(
248
-                    esc_html__(
249
-                        '"%1$s" is not a valid loader method on EE_Registry.',
250
-                        'event_espresso'
251
-                    ),
252
-                    $loader
253
-                )
254
-            );
255
-        }
256
-        $class_name = self::$_instance->get_alias($class_name);
257
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
258
-            self::$_instance->_class_loaders[$class_name] = $loader;
259
-            return true;
260
-        }
261
-        return false;
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     * @return array
268
-     */
269
-    public function dependency_map()
270
-    {
271
-        return $this->_dependency_map;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * returns TRUE if dependency map contains a listing for the provided class name
278
-     *
279
-     * @param string $class_name
280
-     * @return boolean
281
-     */
282
-    public function has($class_name = '')
283
-    {
284
-        return isset($this->_dependency_map[$class_name]) ? true : false;
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
291
-     *
292
-     * @param string $class_name
293
-     * @param string $dependency
294
-     * @return bool
295
-     */
296
-    public function has_dependency_for_class($class_name = '', $dependency = '')
297
-    {
298
-        $dependency = $this->get_alias($dependency);
299
-        return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
300
-            ? true
301
-            : false;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
308
-     *
309
-     * @param string $class_name
310
-     * @param string $dependency
311
-     * @return int
312
-     */
313
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
314
-    {
315
-        $dependency = $this->get_alias($dependency);
316
-        return $this->has_dependency_for_class($class_name, $dependency)
317
-            ? $this->_dependency_map[$class_name][$dependency]
318
-            : EE_Dependency_Map::not_registered;
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * @param string $class_name
325
-     * @return string | Closure
326
-     */
327
-    public function class_loader($class_name)
328
-    {
329
-        $class_name = $this->get_alias($class_name);
330
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * @return array
337
-     */
338
-    public function class_loaders()
339
-    {
340
-        return $this->_class_loaders;
341
-    }
342
-
343
-
344
-
345
-    /**
346
-     * adds an alias for a classname
347
-     *
348
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
349
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
350
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
351
-     */
352
-    public function add_alias($class_name, $alias, $for_class = '')
353
-    {
354
-        if ($for_class !== '') {
355
-            if (! isset($this->_aliases[$for_class])) {
356
-                $this->_aliases[$for_class] = array();
357
-            }
358
-            $this->_aliases[$for_class][$class_name] = $alias;
359
-        }
360
-        $this->_aliases[$class_name] = $alias;
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * returns TRUE if the provided class name has an alias
367
-     *
368
-     * @param string $class_name
369
-     * @param string $for_class
370
-     * @return bool
371
-     */
372
-    public function has_alias($class_name = '', $for_class = '')
373
-    {
374
-        return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
375
-               || (
376
-                   isset($this->_aliases[$class_name])
377
-                   && ! is_array($this->_aliases[$class_name])
378
-               );
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * returns alias for class name if one exists, otherwise returns the original classname
385
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
386
-     *  for example:
387
-     *      if the following two entries were added to the _aliases array:
388
-     *          array(
389
-     *              'interface_alias'           => 'some\namespace\interface'
390
-     *              'some\namespace\interface'  => 'some\namespace\classname'
391
-     *          )
392
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
393
-     *      to load an instance of 'some\namespace\classname'
394
-     *
395
-     * @param string $class_name
396
-     * @param string $for_class
397
-     * @return string
398
-     */
399
-    public function get_alias($class_name = '', $for_class = '')
400
-    {
401
-        if (! $this->has_alias($class_name, $for_class)) {
402
-            return $class_name;
403
-        }
404
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
405
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
406
-        }
407
-        return $this->get_alias($this->_aliases[$class_name]);
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
414
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
415
-     * This is done by using the following class constants:
416
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
417
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
418
-     */
419
-    protected function _register_core_dependencies()
420
-    {
421
-        $this->_dependency_map = array(
422
-            'EE_Request_Handler'                                                                                          => array(
423
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
424
-            ),
425
-            'EE_System'                                                                                                   => array(
426
-                'EE_Registry' => EE_Dependency_Map::load_from_cache,
427
-            ),
428
-            'EE_Session'                                                                                                  => array(
429
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
430
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
431
-            ),
432
-            'EE_Cart'                                                                                                     => array(
433
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
434
-            ),
435
-            'EE_Front_Controller'                                                                                         => array(
436
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
437
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
438
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
439
-            ),
440
-            'EE_Messenger_Collection_Loader'                                                                              => array(
441
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
442
-            ),
443
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
444
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
445
-            ),
446
-            'EE_Message_Resource_Manager'                                                                                 => array(
447
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
448
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
449
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
450
-            ),
451
-            'EE_Message_Factory'                                                                                          => array(
452
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
453
-            ),
454
-            'EE_messages'                                                                                                 => array(
455
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
456
-            ),
457
-            'EE_Messages_Generator'                                                                                       => array(
458
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
459
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
460
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
461
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
462
-            ),
463
-            'EE_Messages_Processor'                                                                                       => array(
464
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
465
-            ),
466
-            'EE_Messages_Queue'                                                                                           => array(
467
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
468
-            ),
469
-            'EE_Messages_Template_Defaults'                                                                               => array(
470
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
471
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
472
-            ),
473
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
474
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
475
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
476
-            ),
477
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
478
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
479
-            ),
480
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
481
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
482
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
483
-            ),
484
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
485
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
488
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
489
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
490
-            ),
491
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
492
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
493
-            ),
494
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
495
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
496
-            ),
497
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
498
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
499
-            ),
500
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
501
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
502
-            ),
503
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
504
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
505
-            ),
506
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
507
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
508
-            ),
509
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
510
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
511
-            ),
512
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
513
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
514
-            ),
515
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
516
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
517
-            ),
518
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
519
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
522
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
525
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
528
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
529
-            ),
530
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
531
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
532
-            ),
533
-            'EE_Data_Migration_Class_Base'                                                                                => array(
534
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
535
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
536
-            ),
537
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
538
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
539
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
540
-            ),
541
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
542
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
543
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
546
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
547
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
548
-            ),
549
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
550
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
551
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
552
-            ),
553
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
554
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
555
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
558
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
559
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
560
-            ),
561
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
562
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
563
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
564
-            ),
565
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
566
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
567
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
568
-            ),
569
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
570
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
571
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
572
-            ),
573
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
574
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
575
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
576
-            ),
577
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
578
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
579
-            ),
580
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
581
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
582
-            ),
583
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
584
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
585
-            ),
586
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
587
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
588
-            ),
589
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
590
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
591
-            ),
592
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
593
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
594
-            ),
595
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
596
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
599
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
600
-            ),
601
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
602
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
603
-            ),
604
-        );
605
-    }
606
-
607
-
608
-
609
-    /**
610
-     * Registers how core classes are loaded.
611
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
612
-     *        'EE_Request_Handler' => 'load_core'
613
-     *        'EE_Messages_Queue'  => 'load_lib'
614
-     *        'EEH_Debug_Tools'    => 'load_helper'
615
-     * or, if greater control is required, by providing a custom closure. For example:
616
-     *        'Some_Class' => function () {
617
-     *            return new Some_Class();
618
-     *        },
619
-     * This is required for instantiating dependencies
620
-     * where an interface has been type hinted in a class constructor. For example:
621
-     *        'Required_Interface' => function () {
622
-     *            return new A_Class_That_Implements_Required_Interface();
623
-     *        },
624
-     */
625
-    protected function _register_core_class_loaders()
626
-    {
627
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
628
-        //be used in a closure.
629
-        $request = &$this->_request;
630
-        $response = &$this->_response;
631
-        $loader = &$this->loader;
632
-        $this->_class_loaders = array(
633
-            //load_core
634
-            'EE_Capabilities'                      => 'load_core',
635
-            'EE_Encryption'                        => 'load_core',
636
-            'EE_Front_Controller'                  => 'load_core',
637
-            'EE_Module_Request_Router'             => 'load_core',
638
-            'EE_Registry'                          => 'load_core',
639
-            'EE_Request'                           => function () use (&$request) {
640
-                return $request;
641
-            },
642
-            'EE_Response'                          => function () use (&$response) {
643
-                return $response;
644
-            },
645
-            'EE_Request_Handler'                   => 'load_core',
646
-            'EE_Session'                           => 'load_core',
647
-            //load_lib
648
-            'EE_Message_Resource_Manager'          => 'load_lib',
649
-            'EE_Message_Type_Collection'           => 'load_lib',
650
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
651
-            'EE_Messenger_Collection'              => 'load_lib',
652
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
653
-            'EE_Messages_Processor'                => 'load_lib',
654
-            'EE_Message_Repository'                => 'load_lib',
655
-            'EE_Messages_Queue'                    => 'load_lib',
656
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
657
-            'EE_Message_Template_Group_Collection' => 'load_lib',
658
-            'EE_Messages_Generator'                => function () {
659
-                return EE_Registry::instance()->load_lib(
660
-                    'Messages_Generator',
661
-                    array(),
662
-                    false,
663
-                    false
664
-                );
665
-            },
666
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
667
-                return EE_Registry::instance()->load_lib(
668
-                    'Messages_Template_Defaults',
669
-                    $arguments,
670
-                    false,
671
-                    false
672
-                );
673
-            },
674
-            //load_model
675
-            'EEM_Attendee'                         => 'load_model',
676
-            'EEM_Message_Template_Group'           => 'load_model',
677
-            'EEM_Message_Template'                 => 'load_model',
678
-            //load_helper
679
-            'EEH_Parse_Shortcodes'                 => function () {
680
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
681
-                    return new EEH_Parse_Shortcodes();
682
-                }
683
-                return null;
684
-            },
685
-            'EE_Template_Config'                   => function () {
686
-                return EE_Config::instance()->template_settings;
687
-            },
688
-            'EE_Currency_Config'                   => function () {
689
-                return EE_Config::instance()->currency;
690
-            },
691
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
692
-                return $loader;
693
-            },
694
-        );
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     * can be used for supplying alternate names for classes,
701
-     * or for connecting interface names to instantiable classes
702
-     */
703
-    protected function _register_core_aliases()
704
-    {
705
-        $this->_aliases = array(
706
-            'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
707
-            'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
708
-            'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
709
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
710
-            'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
711
-            'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
712
-            'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
713
-            'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
714
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
715
-            'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
716
-            'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
717
-            'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
718
-            'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
719
-            'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
720
-            'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
721
-            'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
722
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
723
-            'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
724
-            'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
725
-            'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
726
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
727
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
728
-            'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
729
-            'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
730
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
731
-            'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
732
-            'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
733
-            'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
734
-            'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
735
-            'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
736
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
737
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
738
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
739
-            'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
740
-            'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
741
-        );
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
748
-     * request Primarily used by unit tests.
749
-     */
750
-    public function reset()
751
-    {
752
-        $this->_register_core_class_loaders();
753
-        $this->_register_core_dependencies();
754
-    }
24
+	/**
25
+	 * This means that the requested class dependency is not present in the dependency map
26
+	 */
27
+	const not_registered = 0;
28
+
29
+	/**
30
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
31
+	 */
32
+	const load_new_object = 1;
33
+
34
+	/**
35
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
36
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
37
+	 */
38
+	const load_from_cache = 2;
39
+
40
+	/**
41
+	 * When registering a dependency,
42
+	 * this indicates to keep any existing dependencies that already exist,
43
+	 * and simply discard any new dependencies declared in the incoming data
44
+	 */
45
+	const KEEP_EXISTING_DEPENDENCIES = 0;
46
+
47
+	/**
48
+	 * When registering a dependency,
49
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
50
+	 */
51
+	const OVERWRITE_DEPENDENCIES = 1;
52
+
53
+
54
+
55
+	/**
56
+	 * @type EE_Dependency_Map $_instance
57
+	 */
58
+	protected static $_instance;
59
+
60
+	/**
61
+	 * @type EE_Request $request
62
+	 */
63
+	protected $_request;
64
+
65
+	/**
66
+	 * @type EE_Response $response
67
+	 */
68
+	protected $_response;
69
+
70
+	/**
71
+	 * @type LoaderInterface $loader
72
+	 */
73
+	protected $loader;
74
+
75
+	/**
76
+	 * @type array $_dependency_map
77
+	 */
78
+	protected $_dependency_map = array();
79
+
80
+	/**
81
+	 * @type array $_class_loaders
82
+	 */
83
+	protected $_class_loaders = array();
84
+
85
+	/**
86
+	 * @type array $_aliases
87
+	 */
88
+	protected $_aliases = array();
89
+
90
+
91
+
92
+	/**
93
+	 * EE_Dependency_Map constructor.
94
+	 *
95
+	 * @param EE_Request  $request
96
+	 * @param EE_Response $response
97
+	 */
98
+	protected function __construct(EE_Request $request, EE_Response $response)
99
+	{
100
+		$this->_request = $request;
101
+		$this->_response = $response;
102
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
103
+		do_action('EE_Dependency_Map____construct');
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidInterfaceException
111
+	 * @throws InvalidArgumentException
112
+	 */
113
+	public function initialize()
114
+	{
115
+		$this->_register_core_dependencies();
116
+		$this->_register_core_class_loaders();
117
+		$this->_register_core_aliases();
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @singleton method used to instantiate class object
124
+	 * @access    public
125
+	 * @param EE_Request  $request
126
+	 * @param EE_Response $response
127
+	 * @return EE_Dependency_Map
128
+	 */
129
+	public static function instance(EE_Request $request = null, EE_Response $response = null)
130
+	{
131
+		// check if class object is instantiated, and instantiated properly
132
+		if (! self::$_instance instanceof EE_Dependency_Map) {
133
+			self::$_instance = new EE_Dependency_Map($request, $response);
134
+		}
135
+		return self::$_instance;
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * @param LoaderInterface $loader
142
+	 */
143
+	public function setLoader(LoaderInterface $loader)
144
+	{
145
+		$this->loader = $loader;
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * @param string $class
152
+	 * @param array  $dependencies
153
+	 * @param int    $overwrite
154
+	 * @return bool
155
+	 */
156
+	public static function register_dependencies(
157
+		$class,
158
+		array $dependencies,
159
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
160
+	) {
161
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * Assigns an array of class names and corresponding load sources (new or cached)
168
+	 * to the class specified by the first parameter.
169
+	 * IMPORTANT !!!
170
+	 * The order of elements in the incoming $dependencies array MUST match
171
+	 * the order of the constructor parameters for the class in question.
172
+	 * This is especially important when overriding any existing dependencies that are registered.
173
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
174
+	 *
175
+	 * @param string $class
176
+	 * @param array  $dependencies
177
+	 * @param int    $overwrite
178
+	 * @return bool
179
+	 */
180
+	public function registerDependencies(
181
+		$class,
182
+		array $dependencies,
183
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
184
+	) {
185
+		$class = trim($class, '\\');
186
+		$registered = false;
187
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
188
+			self::$_instance->_dependency_map[ $class ] = array();
189
+		}
190
+		// we need to make sure that any aliases used when registering a dependency
191
+		// get resolved to the correct class name
192
+		foreach ((array)$dependencies as $dependency => $load_source) {
193
+			$alias = self::$_instance->get_alias($dependency);
194
+			if (
195
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
196
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
197
+			) {
198
+				unset($dependencies[$dependency]);
199
+				$dependencies[$alias] = $load_source;
200
+				$registered = true;
201
+			}
202
+		}
203
+		// now add our two lists of dependencies together.
204
+		// using Union (+=) favours the arrays in precedence from left to right,
205
+		// so $dependencies is NOT overwritten because it is listed first
206
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
207
+		// Union is way faster than array_merge() but should be used with caution...
208
+		// especially with numerically indexed arrays
209
+		$dependencies += self::$_instance->_dependency_map[ $class ];
210
+		// now we need to ensure that the resulting dependencies
211
+		// array only has the entries that are required for the class
212
+		// so first count how many dependencies were originally registered for the class
213
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
214
+		// if that count is non-zero (meaning dependencies were already registered)
215
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
216
+			// then truncate the  final array to match that count
217
+			? array_slice($dependencies, 0, $dependency_count)
218
+			// otherwise just take the incoming array because nothing previously existed
219
+			: $dependencies;
220
+		return $registered;
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * @param string $class_name
227
+	 * @param string $loader
228
+	 * @return bool
229
+	 * @throws DomainException
230
+	 */
231
+	public static function register_class_loader($class_name, $loader = 'load_core')
232
+	{
233
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
234
+			throw new DomainException(
235
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
236
+			);
237
+		}
238
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
239
+		if (
240
+			! is_callable($loader)
241
+			&& (
242
+				strpos($loader, 'load_') !== 0
243
+				|| ! method_exists('EE_Registry', $loader)
244
+			)
245
+		) {
246
+			throw new DomainException(
247
+				sprintf(
248
+					esc_html__(
249
+						'"%1$s" is not a valid loader method on EE_Registry.',
250
+						'event_espresso'
251
+					),
252
+					$loader
253
+				)
254
+			);
255
+		}
256
+		$class_name = self::$_instance->get_alias($class_name);
257
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
258
+			self::$_instance->_class_loaders[$class_name] = $loader;
259
+			return true;
260
+		}
261
+		return false;
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 * @return array
268
+	 */
269
+	public function dependency_map()
270
+	{
271
+		return $this->_dependency_map;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * returns TRUE if dependency map contains a listing for the provided class name
278
+	 *
279
+	 * @param string $class_name
280
+	 * @return boolean
281
+	 */
282
+	public function has($class_name = '')
283
+	{
284
+		return isset($this->_dependency_map[$class_name]) ? true : false;
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
291
+	 *
292
+	 * @param string $class_name
293
+	 * @param string $dependency
294
+	 * @return bool
295
+	 */
296
+	public function has_dependency_for_class($class_name = '', $dependency = '')
297
+	{
298
+		$dependency = $this->get_alias($dependency);
299
+		return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
300
+			? true
301
+			: false;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
308
+	 *
309
+	 * @param string $class_name
310
+	 * @param string $dependency
311
+	 * @return int
312
+	 */
313
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
314
+	{
315
+		$dependency = $this->get_alias($dependency);
316
+		return $this->has_dependency_for_class($class_name, $dependency)
317
+			? $this->_dependency_map[$class_name][$dependency]
318
+			: EE_Dependency_Map::not_registered;
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * @param string $class_name
325
+	 * @return string | Closure
326
+	 */
327
+	public function class_loader($class_name)
328
+	{
329
+		$class_name = $this->get_alias($class_name);
330
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * @return array
337
+	 */
338
+	public function class_loaders()
339
+	{
340
+		return $this->_class_loaders;
341
+	}
342
+
343
+
344
+
345
+	/**
346
+	 * adds an alias for a classname
347
+	 *
348
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
349
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
350
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
351
+	 */
352
+	public function add_alias($class_name, $alias, $for_class = '')
353
+	{
354
+		if ($for_class !== '') {
355
+			if (! isset($this->_aliases[$for_class])) {
356
+				$this->_aliases[$for_class] = array();
357
+			}
358
+			$this->_aliases[$for_class][$class_name] = $alias;
359
+		}
360
+		$this->_aliases[$class_name] = $alias;
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * returns TRUE if the provided class name has an alias
367
+	 *
368
+	 * @param string $class_name
369
+	 * @param string $for_class
370
+	 * @return bool
371
+	 */
372
+	public function has_alias($class_name = '', $for_class = '')
373
+	{
374
+		return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
375
+			   || (
376
+				   isset($this->_aliases[$class_name])
377
+				   && ! is_array($this->_aliases[$class_name])
378
+			   );
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * returns alias for class name if one exists, otherwise returns the original classname
385
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
386
+	 *  for example:
387
+	 *      if the following two entries were added to the _aliases array:
388
+	 *          array(
389
+	 *              'interface_alias'           => 'some\namespace\interface'
390
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
391
+	 *          )
392
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
393
+	 *      to load an instance of 'some\namespace\classname'
394
+	 *
395
+	 * @param string $class_name
396
+	 * @param string $for_class
397
+	 * @return string
398
+	 */
399
+	public function get_alias($class_name = '', $for_class = '')
400
+	{
401
+		if (! $this->has_alias($class_name, $for_class)) {
402
+			return $class_name;
403
+		}
404
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
405
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
406
+		}
407
+		return $this->get_alias($this->_aliases[$class_name]);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
414
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
415
+	 * This is done by using the following class constants:
416
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
417
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
418
+	 */
419
+	protected function _register_core_dependencies()
420
+	{
421
+		$this->_dependency_map = array(
422
+			'EE_Request_Handler'                                                                                          => array(
423
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
424
+			),
425
+			'EE_System'                                                                                                   => array(
426
+				'EE_Registry' => EE_Dependency_Map::load_from_cache,
427
+			),
428
+			'EE_Session'                                                                                                  => array(
429
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
430
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
431
+			),
432
+			'EE_Cart'                                                                                                     => array(
433
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
434
+			),
435
+			'EE_Front_Controller'                                                                                         => array(
436
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
437
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
438
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
439
+			),
440
+			'EE_Messenger_Collection_Loader'                                                                              => array(
441
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
442
+			),
443
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
444
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
445
+			),
446
+			'EE_Message_Resource_Manager'                                                                                 => array(
447
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
448
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
449
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
450
+			),
451
+			'EE_Message_Factory'                                                                                          => array(
452
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
453
+			),
454
+			'EE_messages'                                                                                                 => array(
455
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
456
+			),
457
+			'EE_Messages_Generator'                                                                                       => array(
458
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
459
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
460
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
461
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
462
+			),
463
+			'EE_Messages_Processor'                                                                                       => array(
464
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
465
+			),
466
+			'EE_Messages_Queue'                                                                                           => array(
467
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
468
+			),
469
+			'EE_Messages_Template_Defaults'                                                                               => array(
470
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
471
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
472
+			),
473
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
474
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
475
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
476
+			),
477
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
478
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
479
+			),
480
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
481
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
482
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
483
+			),
484
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
485
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
488
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
489
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
490
+			),
491
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
492
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
493
+			),
494
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
495
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
496
+			),
497
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
498
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
499
+			),
500
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
501
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
502
+			),
503
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
504
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
505
+			),
506
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
507
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
508
+			),
509
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
510
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
511
+			),
512
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
513
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
514
+			),
515
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
516
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
517
+			),
518
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
519
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
522
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
525
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
528
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
529
+			),
530
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
531
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
532
+			),
533
+			'EE_Data_Migration_Class_Base'                                                                                => array(
534
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
535
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
536
+			),
537
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
538
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
539
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
540
+			),
541
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
542
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
543
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
546
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
547
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
548
+			),
549
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
550
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
551
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
552
+			),
553
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
554
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
555
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
558
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
559
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
560
+			),
561
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
562
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
563
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
564
+			),
565
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
566
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
567
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
568
+			),
569
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
570
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
571
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
572
+			),
573
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
574
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
575
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
576
+			),
577
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
578
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
579
+			),
580
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
581
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
582
+			),
583
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
584
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
585
+			),
586
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
587
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
588
+			),
589
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
590
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
591
+			),
592
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
593
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
594
+			),
595
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
596
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
599
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
600
+			),
601
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
602
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
603
+			),
604
+		);
605
+	}
606
+
607
+
608
+
609
+	/**
610
+	 * Registers how core classes are loaded.
611
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
612
+	 *        'EE_Request_Handler' => 'load_core'
613
+	 *        'EE_Messages_Queue'  => 'load_lib'
614
+	 *        'EEH_Debug_Tools'    => 'load_helper'
615
+	 * or, if greater control is required, by providing a custom closure. For example:
616
+	 *        'Some_Class' => function () {
617
+	 *            return new Some_Class();
618
+	 *        },
619
+	 * This is required for instantiating dependencies
620
+	 * where an interface has been type hinted in a class constructor. For example:
621
+	 *        'Required_Interface' => function () {
622
+	 *            return new A_Class_That_Implements_Required_Interface();
623
+	 *        },
624
+	 */
625
+	protected function _register_core_class_loaders()
626
+	{
627
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
628
+		//be used in a closure.
629
+		$request = &$this->_request;
630
+		$response = &$this->_response;
631
+		$loader = &$this->loader;
632
+		$this->_class_loaders = array(
633
+			//load_core
634
+			'EE_Capabilities'                      => 'load_core',
635
+			'EE_Encryption'                        => 'load_core',
636
+			'EE_Front_Controller'                  => 'load_core',
637
+			'EE_Module_Request_Router'             => 'load_core',
638
+			'EE_Registry'                          => 'load_core',
639
+			'EE_Request'                           => function () use (&$request) {
640
+				return $request;
641
+			},
642
+			'EE_Response'                          => function () use (&$response) {
643
+				return $response;
644
+			},
645
+			'EE_Request_Handler'                   => 'load_core',
646
+			'EE_Session'                           => 'load_core',
647
+			//load_lib
648
+			'EE_Message_Resource_Manager'          => 'load_lib',
649
+			'EE_Message_Type_Collection'           => 'load_lib',
650
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
651
+			'EE_Messenger_Collection'              => 'load_lib',
652
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
653
+			'EE_Messages_Processor'                => 'load_lib',
654
+			'EE_Message_Repository'                => 'load_lib',
655
+			'EE_Messages_Queue'                    => 'load_lib',
656
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
657
+			'EE_Message_Template_Group_Collection' => 'load_lib',
658
+			'EE_Messages_Generator'                => function () {
659
+				return EE_Registry::instance()->load_lib(
660
+					'Messages_Generator',
661
+					array(),
662
+					false,
663
+					false
664
+				);
665
+			},
666
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
667
+				return EE_Registry::instance()->load_lib(
668
+					'Messages_Template_Defaults',
669
+					$arguments,
670
+					false,
671
+					false
672
+				);
673
+			},
674
+			//load_model
675
+			'EEM_Attendee'                         => 'load_model',
676
+			'EEM_Message_Template_Group'           => 'load_model',
677
+			'EEM_Message_Template'                 => 'load_model',
678
+			//load_helper
679
+			'EEH_Parse_Shortcodes'                 => function () {
680
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
681
+					return new EEH_Parse_Shortcodes();
682
+				}
683
+				return null;
684
+			},
685
+			'EE_Template_Config'                   => function () {
686
+				return EE_Config::instance()->template_settings;
687
+			},
688
+			'EE_Currency_Config'                   => function () {
689
+				return EE_Config::instance()->currency;
690
+			},
691
+			'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
692
+				return $loader;
693
+			},
694
+		);
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 * can be used for supplying alternate names for classes,
701
+	 * or for connecting interface names to instantiable classes
702
+	 */
703
+	protected function _register_core_aliases()
704
+	{
705
+		$this->_aliases = array(
706
+			'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
707
+			'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
708
+			'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
709
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
710
+			'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
711
+			'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
712
+			'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
713
+			'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
714
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
715
+			'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
716
+			'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
717
+			'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
718
+			'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
719
+			'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
720
+			'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
721
+			'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
722
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
723
+			'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
724
+			'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
725
+			'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
726
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
727
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
728
+			'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
729
+			'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
730
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
731
+			'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
732
+			'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
733
+			'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
734
+			'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
735
+			'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
736
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
737
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
738
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
739
+			'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
740
+			'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
741
+		);
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
748
+	 * request Primarily used by unit tests.
749
+	 */
750
+	public function reset()
751
+	{
752
+		$this->_register_core_class_loaders();
753
+		$this->_register_core_dependencies();
754
+	}
755 755
 
756 756
 
757 757
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     public static function instance(EE_Request $request = null, EE_Response $response = null)
130 130
     {
131 131
         // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
132
+        if ( ! self::$_instance instanceof EE_Dependency_Map) {
133 133
             self::$_instance = new EE_Dependency_Map($request, $response);
134 134
         }
135 135
         return self::$_instance;
@@ -184,16 +184,16 @@  discard block
 block discarded – undo
184 184
     ) {
185 185
         $class = trim($class, '\\');
186 186
         $registered = false;
187
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
188
-            self::$_instance->_dependency_map[ $class ] = array();
187
+        if (empty(self::$_instance->_dependency_map[$class])) {
188
+            self::$_instance->_dependency_map[$class] = array();
189 189
         }
190 190
         // we need to make sure that any aliases used when registering a dependency
191 191
         // get resolved to the correct class name
192
-        foreach ((array)$dependencies as $dependency => $load_source) {
192
+        foreach ((array) $dependencies as $dependency => $load_source) {
193 193
             $alias = self::$_instance->get_alias($dependency);
194 194
             if (
195 195
                 $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
196
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
196
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
197 197
             ) {
198 198
                 unset($dependencies[$dependency]);
199 199
                 $dependencies[$alias] = $load_source;
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
207 207
         // Union is way faster than array_merge() but should be used with caution...
208 208
         // especially with numerically indexed arrays
209
-        $dependencies += self::$_instance->_dependency_map[ $class ];
209
+        $dependencies += self::$_instance->_dependency_map[$class];
210 210
         // now we need to ensure that the resulting dependencies
211 211
         // array only has the entries that are required for the class
212 212
         // so first count how many dependencies were originally registered for the class
213
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
213
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
214 214
         // if that count is non-zero (meaning dependencies were already registered)
215
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
215
+        self::$_instance->_dependency_map[$class] = $dependency_count
216 216
             // then truncate the  final array to match that count
217 217
             ? array_slice($dependencies, 0, $dependency_count)
218 218
             // otherwise just take the incoming array because nothing previously existed
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      */
231 231
     public static function register_class_loader($class_name, $loader = 'load_core')
232 232
     {
233
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
233
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
234 234
             throw new DomainException(
235 235
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
236 236
             );
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             );
255 255
         }
256 256
         $class_name = self::$_instance->get_alias($class_name);
257
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
257
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
258 258
             self::$_instance->_class_loaders[$class_name] = $loader;
259 259
             return true;
260 260
         }
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
     public function add_alias($class_name, $alias, $for_class = '')
353 353
     {
354 354
         if ($for_class !== '') {
355
-            if (! isset($this->_aliases[$for_class])) {
355
+            if ( ! isset($this->_aliases[$for_class])) {
356 356
                 $this->_aliases[$for_class] = array();
357 357
             }
358 358
             $this->_aliases[$for_class][$class_name] = $alias;
@@ -398,10 +398,10 @@  discard block
 block discarded – undo
398 398
      */
399 399
     public function get_alias($class_name = '', $for_class = '')
400 400
     {
401
-        if (! $this->has_alias($class_name, $for_class)) {
401
+        if ( ! $this->has_alias($class_name, $for_class)) {
402 402
             return $class_name;
403 403
         }
404
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
404
+        if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) {
405 405
             return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
406 406
         }
407 407
         return $this->get_alias($this->_aliases[$class_name]);
@@ -636,10 +636,10 @@  discard block
 block discarded – undo
636 636
             'EE_Front_Controller'                  => 'load_core',
637 637
             'EE_Module_Request_Router'             => 'load_core',
638 638
             'EE_Registry'                          => 'load_core',
639
-            'EE_Request'                           => function () use (&$request) {
639
+            'EE_Request'                           => function() use (&$request) {
640 640
                 return $request;
641 641
             },
642
-            'EE_Response'                          => function () use (&$response) {
642
+            'EE_Response'                          => function() use (&$response) {
643 643
                 return $response;
644 644
             },
645 645
             'EE_Request_Handler'                   => 'load_core',
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
             'EE_Messages_Queue'                    => 'load_lib',
656 656
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
657 657
             'EE_Message_Template_Group_Collection' => 'load_lib',
658
-            'EE_Messages_Generator'                => function () {
658
+            'EE_Messages_Generator'                => function() {
659 659
                 return EE_Registry::instance()->load_lib(
660 660
                     'Messages_Generator',
661 661
                     array(),
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
                     false
664 664
                 );
665 665
             },
666
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
666
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
667 667
                 return EE_Registry::instance()->load_lib(
668 668
                     'Messages_Template_Defaults',
669 669
                     $arguments,
@@ -676,19 +676,19 @@  discard block
 block discarded – undo
676 676
             'EEM_Message_Template_Group'           => 'load_model',
677 677
             'EEM_Message_Template'                 => 'load_model',
678 678
             //load_helper
679
-            'EEH_Parse_Shortcodes'                 => function () {
679
+            'EEH_Parse_Shortcodes'                 => function() {
680 680
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
681 681
                     return new EEH_Parse_Shortcodes();
682 682
                 }
683 683
                 return null;
684 684
             },
685
-            'EE_Template_Config'                   => function () {
685
+            'EE_Template_Config'                   => function() {
686 686
                 return EE_Config::instance()->template_settings;
687 687
             },
688
-            'EE_Currency_Config'                   => function () {
688
+            'EE_Currency_Config'                   => function() {
689 689
                 return EE_Config::instance()->currency;
690 690
             },
691
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
691
+            'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) {
692 692
                 return $loader;
693 693
             },
694 694
         );
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1417 added lines, -1417 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
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
 /**
@@ -24,470 +24,470 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * This gets set in _setup_cpt
29
-     * It will contain the object for the custom post type.
30
-     *
31
-     * @var EE_CPT_Base
32
-     */
33
-    protected $_cpt_object;
34
-
35
-
36
-
37
-    /**
38
-     * a boolean flag to set whether the current route is a cpt route or not.
39
-     *
40
-     * @var bool
41
-     */
42
-    protected $_cpt_route = false;
43
-
44
-
45
-
46
-    /**
47
-     * This property allows cpt classes to define multiple routes as cpt routes.
48
-     * //in this array we define what the custom post type for this route is.
49
-     * array(
50
-     * 'route_name' => 'custom_post_type_slug'
51
-     * )
52
-     *
53
-     * @var array
54
-     */
55
-    protected $_cpt_routes = array();
56
-
27
+	/**
28
+	 * This gets set in _setup_cpt
29
+	 * It will contain the object for the custom post type.
30
+	 *
31
+	 * @var EE_CPT_Base
32
+	 */
33
+	protected $_cpt_object;
34
+
35
+
36
+
37
+	/**
38
+	 * a boolean flag to set whether the current route is a cpt route or not.
39
+	 *
40
+	 * @var bool
41
+	 */
42
+	protected $_cpt_route = false;
43
+
44
+
45
+
46
+	/**
47
+	 * This property allows cpt classes to define multiple routes as cpt routes.
48
+	 * //in this array we define what the custom post type for this route is.
49
+	 * array(
50
+	 * 'route_name' => 'custom_post_type_slug'
51
+	 * )
52
+	 *
53
+	 * @var array
54
+	 */
55
+	protected $_cpt_routes = array();
56
+
57 57
 
58 58
 
59
-    /**
60
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
-     * in this format:
62
-     * array(
63
-     * 'post_type_slug' => 'edit_route'
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_cpt_edit_routes = array();
69
-
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = array();
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-
89
-
90
-    /**
91
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
-     * Registration of containers should be done before load_page_dependencies() is run.
95
-     *
96
-     * @var array()
97
-     */
98
-    protected $_autosave_containers = array();
99
-    protected $_autosave_fields = array();
100
-
101
-    /**
102
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
-     *
105
-     * @var array
106
-     */
107
-    protected $_pagenow_map;
108
-
109
-
110
-
111
-    /**
112
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
-     *
118
-     * @access protected
119
-     * @abstract
120
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
-     * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
122
-     * @return void
123
-     */
124
-    abstract protected function _insert_update_cpt_item($post_id, $post);
125
-
126
-
127
-
128
-    /**
129
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
-     *
131
-     * @abstract
132
-     * @access public
133
-     * @param  string $post_id The ID of the cpt that was trashed
134
-     * @return void
135
-     */
136
-    abstract public function trash_cpt_item($post_id);
137
-
138
-
139
-
140
-    /**
141
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
-     *
143
-     * @param  string $post_id theID of the cpt that was untrashed
144
-     * @return void
145
-     */
146
-    abstract public function restore_cpt_item($post_id);
147
-
148
-
149
-
150
-    /**
151
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
-     * from the db
153
-     *
154
-     * @param  string $post_id the ID of the cpt that was deleted
155
-     * @return void
156
-     */
157
-    abstract public function delete_cpt_item($post_id);
158
-
159
-
160
-
161
-    /**
162
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
-     *
164
-     * @access protected
165
-     * @return void
166
-     */
167
-    protected function _before_page_setup()
168
-    {
169
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
-        $this->_cpt_routes = array_merge(array(
171
-            'create_new' => $this->page_slug,
172
-            'edit'       => $this->page_slug,
173
-            'trash'      => $this->page_slug,
174
-        ), $this->_cpt_routes);
175
-        //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
-            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
-            : get_post_type_object($page);
179
-        //tweak pagenow for page loading.
180
-        if ( ! $this->_pagenow_map) {
181
-            $this->_pagenow_map = array(
182
-                'create_new' => 'post-new.php',
183
-                'edit'       => 'post.php',
184
-                'trash'      => 'post.php',
185
-            );
186
-        }
187
-        add_action('current_screen', array($this, 'modify_pagenow'));
188
-        //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
-        //get current page from autosave
190
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
-            : null;
193
-        $this->_current_page = isset($this->_req_data['current_page'])
194
-            ? $this->_req_data['current_page']
195
-            : $current_page;
196
-        //autosave... make sure its only for the correct page
197
-        //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
-            //setup autosave ajax hook
199
-            //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
-        //}
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Simply ensure that we simulate the correct post route for cpt screens
207
-     *
208
-     * @param WP_Screen $current_screen
209
-     * @return void
210
-     */
211
-    public function modify_pagenow($current_screen)
212
-    {
213
-        global $pagenow, $hook_suffix;
214
-        //possibly reset pagenow.
215
-        if ( ! empty($this->_req_data['page'])
216
-             && $this->_req_data['page'] == $this->page_slug
217
-             && ! empty($this->_req_data['action'])
218
-             && isset($this->_pagenow_map[$this->_req_data['action']])
219
-        ) {
220
-            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
-            $hook_suffix = $pagenow;
222
-        }
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * This method is used to register additional autosave containers to the _autosave_containers property.
229
-     *
230
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
-     *       automatically register the id for the post metabox as a container.
232
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
-     *                    you would send along the id of a metabox container.
234
-     * @return void
235
-     */
236
-    protected function _register_autosave_containers($ids)
237
-    {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
-     */
247
-    protected function _set_autosave_containers()
248
-    {
249
-        global $wp_meta_boxes;
250
-        $containers = array();
251
-        if (empty($wp_meta_boxes)) {
252
-            return;
253
-        }
254
-        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
-        foreach ($current_metaboxes as $box_context) {
256
-            foreach ($box_context as $box_details) {
257
-                foreach ($box_details as $box) {
258
-                    if (
259
-                        is_array($box['callback'])
260
-                        && (
261
-                            $box['callback'][0] instanceof EE_Admin_Page
262
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
263
-                        )
264
-                    ) {
265
-                        $containers[] = $box['id'];
266
-                    }
267
-                }
268
-            }
269
-        }
270
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
271
-        //add hidden inputs container
272
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
273
-    }
274
-
275
-
276
-
277
-    protected function _load_autosave_scripts_styles()
278
-    {
279
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
59
+	/**
60
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
+	 * in this format:
62
+	 * array(
63
+	 * 'post_type_slug' => 'edit_route'
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_cpt_edit_routes = array();
69
+
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = array();
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+
89
+
90
+	/**
91
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
+	 * Registration of containers should be done before load_page_dependencies() is run.
95
+	 *
96
+	 * @var array()
97
+	 */
98
+	protected $_autosave_containers = array();
99
+	protected $_autosave_fields = array();
100
+
101
+	/**
102
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
+	 *
105
+	 * @var array
106
+	 */
107
+	protected $_pagenow_map;
108
+
109
+
110
+
111
+	/**
112
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
+	 *
118
+	 * @access protected
119
+	 * @abstract
120
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
+	 * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
122
+	 * @return void
123
+	 */
124
+	abstract protected function _insert_update_cpt_item($post_id, $post);
125
+
126
+
127
+
128
+	/**
129
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
+	 *
131
+	 * @abstract
132
+	 * @access public
133
+	 * @param  string $post_id The ID of the cpt that was trashed
134
+	 * @return void
135
+	 */
136
+	abstract public function trash_cpt_item($post_id);
137
+
138
+
139
+
140
+	/**
141
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
+	 *
143
+	 * @param  string $post_id theID of the cpt that was untrashed
144
+	 * @return void
145
+	 */
146
+	abstract public function restore_cpt_item($post_id);
147
+
148
+
149
+
150
+	/**
151
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
+	 * from the db
153
+	 *
154
+	 * @param  string $post_id the ID of the cpt that was deleted
155
+	 * @return void
156
+	 */
157
+	abstract public function delete_cpt_item($post_id);
158
+
159
+
160
+
161
+	/**
162
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
+	 *
164
+	 * @access protected
165
+	 * @return void
166
+	 */
167
+	protected function _before_page_setup()
168
+	{
169
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
+		$this->_cpt_routes = array_merge(array(
171
+			'create_new' => $this->page_slug,
172
+			'edit'       => $this->page_slug,
173
+			'trash'      => $this->page_slug,
174
+		), $this->_cpt_routes);
175
+		//let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
+			? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
+			: get_post_type_object($page);
179
+		//tweak pagenow for page loading.
180
+		if ( ! $this->_pagenow_map) {
181
+			$this->_pagenow_map = array(
182
+				'create_new' => 'post-new.php',
183
+				'edit'       => 'post.php',
184
+				'trash'      => 'post.php',
185
+			);
186
+		}
187
+		add_action('current_screen', array($this, 'modify_pagenow'));
188
+		//TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
+		//get current page from autosave
190
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
+			: null;
193
+		$this->_current_page = isset($this->_req_data['current_page'])
194
+			? $this->_req_data['current_page']
195
+			: $current_page;
196
+		//autosave... make sure its only for the correct page
197
+		//if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
+			//setup autosave ajax hook
199
+			//add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
+		//}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Simply ensure that we simulate the correct post route for cpt screens
207
+	 *
208
+	 * @param WP_Screen $current_screen
209
+	 * @return void
210
+	 */
211
+	public function modify_pagenow($current_screen)
212
+	{
213
+		global $pagenow, $hook_suffix;
214
+		//possibly reset pagenow.
215
+		if ( ! empty($this->_req_data['page'])
216
+			 && $this->_req_data['page'] == $this->page_slug
217
+			 && ! empty($this->_req_data['action'])
218
+			 && isset($this->_pagenow_map[$this->_req_data['action']])
219
+		) {
220
+			$pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
+			$hook_suffix = $pagenow;
222
+		}
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
229
+	 *
230
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
+	 *       automatically register the id for the post metabox as a container.
232
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
+	 *                    you would send along the id of a metabox container.
234
+	 * @return void
235
+	 */
236
+	protected function _register_autosave_containers($ids)
237
+	{
238
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
+	 */
247
+	protected function _set_autosave_containers()
248
+	{
249
+		global $wp_meta_boxes;
250
+		$containers = array();
251
+		if (empty($wp_meta_boxes)) {
252
+			return;
253
+		}
254
+		$current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
+		foreach ($current_metaboxes as $box_context) {
256
+			foreach ($box_context as $box_details) {
257
+				foreach ($box_details as $box) {
258
+					if (
259
+						is_array($box['callback'])
260
+						&& (
261
+							$box['callback'][0] instanceof EE_Admin_Page
262
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
263
+						)
264
+					) {
265
+						$containers[] = $box['id'];
266
+					}
267
+				}
268
+			}
269
+		}
270
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
271
+		//add hidden inputs container
272
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
273
+	}
274
+
275
+
276
+
277
+	protected function _load_autosave_scripts_styles()
278
+	{
279
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
280 280
         wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2
281 281
 
282
-        //filter _autosave_containers
283
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
284
-            $this->_autosave_containers, $this);
285
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
286
-            $containers, $this);
287
-
288
-        wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
289
-            $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
-
291
-        $unsaved_data_msg = array(
292
-            'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
293
-                'event_espresso'), $this->_cpt_object->labels->singular_name),
294
-            'inputChanged' => 0,
295
-        );
296
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
297
-    }
298
-
299
-
300
-
301
-    public function load_page_dependencies()
302
-    {
303
-        try {
304
-            $this->_load_page_dependencies();
305
-        } catch (EE_Error $e) {
306
-            $e->get_error();
307
-        }
308
-    }
309
-
310
-
311
-
312
-    /**
313
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
314
-     *
315
-     * @access protected
316
-     * @return void
317
-     */
318
-    protected function _load_page_dependencies()
319
-    {
320
-        //we only add stuff if this is a cpt_route!
321
-        if ( ! $this->_cpt_route) {
322
-            parent::_load_page_dependencies();
323
-            return;
324
-        }
325
-        // now let's do some automatic filters into the wp_system
326
-        // and we'll check to make sure the CHILD class
327
-        // automatically has the required methods in place.
328
-        // the following filters are for setting all the redirects
329
-        // on DEFAULT WP custom post type actions
330
-        // let's add a hidden input to the post-edit form
331
-        // so we know when we have to trigger our custom redirects!
332
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
333
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
334
-        // inject our Admin page nav tabs...
335
-        // let's make sure the nav tabs are set if they aren't already
336
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
337
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
338
-        // modify the post_updated messages array
339
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
340
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
341
-        // cpts use the same format for shortlinks as posts!
342
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
343
-        // This basically allows us to change the title of the "publish" metabox area
344
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
345
-        if ( ! empty($this->_labels['publishbox'])) {
346
-            $box_label = is_array($this->_labels['publishbox'])
347
-                         && isset($this->_labels['publishbox'][$this->_req_action])
348
-                    ? $this->_labels['publishbox'][$this->_req_action]
349
-                    : $this->_labels['publishbox'];
350
-            add_meta_box(
351
-                'submitdiv',
352
-                $box_label,
353
-                'post_submit_meta_box',
354
-                $this->_cpt_routes[$this->_req_action],
355
-                'side',
356
-                'core'
357
-            );
358
-        }
359
-        //let's add page_templates metabox if this cpt added support for it.
360
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
361
-            add_meta_box(
362
-                'page_templates',
363
-                __('Page Template', 'event_espresso'),
364
-                array($this, 'page_template_meta_box'),
365
-                $this->_cpt_routes[$this->_req_action],
366
-                'side',
367
-                'default'
368
-            );
369
-        }
370
-        //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
371
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
372
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
373
-        }
374
-        //add preview button
375
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
376
-        //insert our own post_stati dropdown
377
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
378
-        //This allows adding additional information to the publish post submitbox on the wp post edit form
379
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
380
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
381
-        }
382
-        // This allows for adding additional stuff after the title field on the wp post edit form.
383
-        // This is also before the wp_editor for post description field.
384
-        if (method_exists($this, 'edit_form_after_title')) {
385
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
386
-        }
387
-        /**
388
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
389
-         */
390
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
391
-        parent::_load_page_dependencies();
392
-        // notice we are ALSO going to load the pagenow hook set for this route
393
-        // (see _before_page_setup for the reset of the pagenow global ).
394
-        // This is for any plugins that are doing things properly
395
-        // and hooking into the load page hook for core wp cpt routes.
396
-        global $pagenow;
397
-        do_action('load-' . $pagenow);
398
-        $this->modify_current_screen();
399
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
400
-        //we route REALLY early.
401
-        try {
402
-            $this->_route_admin_request();
403
-        } catch (EE_Error $e) {
404
-            $e->get_error();
405
-        }
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
412
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
413
-     * route instead.
414
-     *
415
-     * @param string $good_protocol_url The escaped url.
416
-     * @param string $original_url      The original url.
417
-     * @param string $_context          The context sent to the esc_url method.
418
-     * @return string possibly a new url for our route.
419
-     */
420
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
421
-    {
422
-        $routes_to_match = array(
423
-            0 => array(
424
-                'edit.php?post_type=espresso_attendees',
425
-                'admin.php?page=espresso_registrations&action=contact_list',
426
-            ),
427
-            1 => array(
428
-                'edit.php?post_type=' . $this->_cpt_object->name,
429
-                'admin.php?page=' . $this->_cpt_object->name,
430
-            ),
431
-        );
432
-        foreach ($routes_to_match as $route_matches) {
433
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
434
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
435
-            }
436
-        }
437
-        return $good_protocol_url;
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * Determine whether the current cpt supports page templates or not.
444
-     *
445
-     * @since %VER%
446
-     * @param string $cpt_name The cpt slug we're checking on.
447
-     * @return bool True supported, false not.
448
-     */
449
-    private function _supports_page_templates($cpt_name)
450
-    {
451
-
452
-        $cpt_args = EE_Register_CPTs::get_CPTs();
453
-        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
454
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
455
-
456
-        //if the installed version of WP is > 4.7 we do some additional checks.
457
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
458
-            $post_templates = wp_get_theme()->get_post_templates();
459
-            //if there are $post_templates for this cpt, then we return false for this method because
460
-            //that means we aren't going to load our page template manager and leave that up to the native
461
-            //cpt template manager.
462
-            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
463
-        }
464
-
465
-        return $cpt_has_support;
466
-    }
467
-
468
-
469
-    /**
470
-     * Callback for the page_templates metabox selector.
471
-     *
472
-     * @since %VER%
473
-     * @return void
474
-     */
475
-    public function page_template_meta_box()
476
-    {
477
-        global $post;
478
-        $template = '';
479
-
480
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
481
-            $page_template_count = count(get_page_templates());
482
-        } else {
483
-            $page_template_count = count(get_page_templates($post));
484
-        };
485
-
486
-        if ($page_template_count) {
487
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
488
-            $template      = ! empty($page_template) ? $page_template : '';
489
-        }
490
-        ?>
282
+		//filter _autosave_containers
283
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
284
+			$this->_autosave_containers, $this);
285
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
286
+			$containers, $this);
287
+
288
+		wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
289
+			$containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
+
291
+		$unsaved_data_msg = array(
292
+			'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
293
+				'event_espresso'), $this->_cpt_object->labels->singular_name),
294
+			'inputChanged' => 0,
295
+		);
296
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
297
+	}
298
+
299
+
300
+
301
+	public function load_page_dependencies()
302
+	{
303
+		try {
304
+			$this->_load_page_dependencies();
305
+		} catch (EE_Error $e) {
306
+			$e->get_error();
307
+		}
308
+	}
309
+
310
+
311
+
312
+	/**
313
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
314
+	 *
315
+	 * @access protected
316
+	 * @return void
317
+	 */
318
+	protected function _load_page_dependencies()
319
+	{
320
+		//we only add stuff if this is a cpt_route!
321
+		if ( ! $this->_cpt_route) {
322
+			parent::_load_page_dependencies();
323
+			return;
324
+		}
325
+		// now let's do some automatic filters into the wp_system
326
+		// and we'll check to make sure the CHILD class
327
+		// automatically has the required methods in place.
328
+		// the following filters are for setting all the redirects
329
+		// on DEFAULT WP custom post type actions
330
+		// let's add a hidden input to the post-edit form
331
+		// so we know when we have to trigger our custom redirects!
332
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
333
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
334
+		// inject our Admin page nav tabs...
335
+		// let's make sure the nav tabs are set if they aren't already
336
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
337
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
338
+		// modify the post_updated messages array
339
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
340
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
341
+		// cpts use the same format for shortlinks as posts!
342
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
343
+		// This basically allows us to change the title of the "publish" metabox area
344
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
345
+		if ( ! empty($this->_labels['publishbox'])) {
346
+			$box_label = is_array($this->_labels['publishbox'])
347
+						 && isset($this->_labels['publishbox'][$this->_req_action])
348
+					? $this->_labels['publishbox'][$this->_req_action]
349
+					: $this->_labels['publishbox'];
350
+			add_meta_box(
351
+				'submitdiv',
352
+				$box_label,
353
+				'post_submit_meta_box',
354
+				$this->_cpt_routes[$this->_req_action],
355
+				'side',
356
+				'core'
357
+			);
358
+		}
359
+		//let's add page_templates metabox if this cpt added support for it.
360
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
361
+			add_meta_box(
362
+				'page_templates',
363
+				__('Page Template', 'event_espresso'),
364
+				array($this, 'page_template_meta_box'),
365
+				$this->_cpt_routes[$this->_req_action],
366
+				'side',
367
+				'default'
368
+			);
369
+		}
370
+		//this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
371
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
372
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
373
+		}
374
+		//add preview button
375
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
376
+		//insert our own post_stati dropdown
377
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
378
+		//This allows adding additional information to the publish post submitbox on the wp post edit form
379
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
380
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
381
+		}
382
+		// This allows for adding additional stuff after the title field on the wp post edit form.
383
+		// This is also before the wp_editor for post description field.
384
+		if (method_exists($this, 'edit_form_after_title')) {
385
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
386
+		}
387
+		/**
388
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
389
+		 */
390
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
391
+		parent::_load_page_dependencies();
392
+		// notice we are ALSO going to load the pagenow hook set for this route
393
+		// (see _before_page_setup for the reset of the pagenow global ).
394
+		// This is for any plugins that are doing things properly
395
+		// and hooking into the load page hook for core wp cpt routes.
396
+		global $pagenow;
397
+		do_action('load-' . $pagenow);
398
+		$this->modify_current_screen();
399
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
400
+		//we route REALLY early.
401
+		try {
402
+			$this->_route_admin_request();
403
+		} catch (EE_Error $e) {
404
+			$e->get_error();
405
+		}
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
412
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
413
+	 * route instead.
414
+	 *
415
+	 * @param string $good_protocol_url The escaped url.
416
+	 * @param string $original_url      The original url.
417
+	 * @param string $_context          The context sent to the esc_url method.
418
+	 * @return string possibly a new url for our route.
419
+	 */
420
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
421
+	{
422
+		$routes_to_match = array(
423
+			0 => array(
424
+				'edit.php?post_type=espresso_attendees',
425
+				'admin.php?page=espresso_registrations&action=contact_list',
426
+			),
427
+			1 => array(
428
+				'edit.php?post_type=' . $this->_cpt_object->name,
429
+				'admin.php?page=' . $this->_cpt_object->name,
430
+			),
431
+		);
432
+		foreach ($routes_to_match as $route_matches) {
433
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
434
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
435
+			}
436
+		}
437
+		return $good_protocol_url;
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * Determine whether the current cpt supports page templates or not.
444
+	 *
445
+	 * @since %VER%
446
+	 * @param string $cpt_name The cpt slug we're checking on.
447
+	 * @return bool True supported, false not.
448
+	 */
449
+	private function _supports_page_templates($cpt_name)
450
+	{
451
+
452
+		$cpt_args = EE_Register_CPTs::get_CPTs();
453
+		$cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
454
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
455
+
456
+		//if the installed version of WP is > 4.7 we do some additional checks.
457
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
458
+			$post_templates = wp_get_theme()->get_post_templates();
459
+			//if there are $post_templates for this cpt, then we return false for this method because
460
+			//that means we aren't going to load our page template manager and leave that up to the native
461
+			//cpt template manager.
462
+			$cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
463
+		}
464
+
465
+		return $cpt_has_support;
466
+	}
467
+
468
+
469
+	/**
470
+	 * Callback for the page_templates metabox selector.
471
+	 *
472
+	 * @since %VER%
473
+	 * @return void
474
+	 */
475
+	public function page_template_meta_box()
476
+	{
477
+		global $post;
478
+		$template = '';
479
+
480
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
481
+			$page_template_count = count(get_page_templates());
482
+		} else {
483
+			$page_template_count = count(get_page_templates($post));
484
+		};
485
+
486
+		if ($page_template_count) {
487
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
488
+			$template      = ! empty($page_template) ? $page_template : '';
489
+		}
490
+		?>
491 491
         <p><strong><?php _e('Template') ?></strong></p>
492 492
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select
493 493
             name="page_template" id="page_template">
@@ -495,450 +495,450 @@  discard block
 block discarded – undo
495 495
         <?php page_template_dropdown($template); ?>
496 496
     </select>
497 497
         <?php
498
-    }
499
-
500
-
501
-
502
-    /**
503
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
504
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
505
-     *
506
-     * @param  string $return    the current html
507
-     * @param  int    $id        the post id for the page
508
-     * @param  string $new_title What the title is
509
-     * @param  string $new_slug  what the slug is
510
-     * @return string            The new html string for the permalink area
511
-     */
512
-    public function preview_button_html($return, $id, $new_title, $new_slug)
513
-    {
514
-        $post = get_post($id);
515
-        if ('publish' !== get_post_status($post)) {
516
-            //include shims for the `get_preview_post_link` function
517
-            require_once( EE_CORE . 'wordpress-shims.php' );
518
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
519
-                       . get_preview_post_link($id)
520
-                       . '" class="button button-small">'
521
-                       . __('Preview', 'event_espresso')
522
-                       . '</a></span>'
523
-                       . "\n";
524
-        }
525
-        return $return;
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * add our custom post stati dropdown on the wp post page for this cpt
532
-     *
533
-     * @return void
534
-     */
535
-    public function custom_post_stati_dropdown()
536
-    {
537
-
538
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
539
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
540
-            ? $statuses[$this->_cpt_model_obj->status()]
541
-            : '';
542
-        $template_args    = array(
543
-            'cur_status'            => $this->_cpt_model_obj->status(),
544
-            'statuses'              => $statuses,
545
-            'cur_status_label'      => $cur_status_label,
546
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
547
-        );
548
-        //we'll add a trash post status (WP doesn't add one for some reason)
549
-        if ($this->_cpt_model_obj->status() === 'trash') {
550
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
551
-            $statuses['trash']                 = __('Trashed', 'event_espresso');
552
-            $template_args['statuses']         = $statuses;
553
-        }
554
-
555
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
556
-        EEH_Template::display_template($template, $template_args);
557
-    }
558
-
559
-
560
-
561
-    public function setup_autosave_hooks()
562
-    {
563
-        $this->_set_autosave_containers();
564
-        $this->_load_autosave_scripts_styles();
565
-    }
566
-
567
-
568
-
569
-    /**
570
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
571
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
572
-     * for the nonce in here, but then this method looks for two things:
573
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
574
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
575
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
576
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
577
-     * template args.
578
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
579
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
580
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
581
-     *    $this->_template_args['data']['items'] = array(
582
-     *        'event-datetime-ids' => '1,2,3';
583
-     *    );
584
-     *    Keep in mind the following things:
585
-     *    - "where" index is for the input with the id as that string.
586
-     *    - "what" index is what will be used for the value of that input.
587
-     *
588
-     * @return void
589
-     */
590
-    public function do_extra_autosave_stuff()
591
-    {
592
-        //next let's check for the autosave nonce (we'll use _verify_nonce )
593
-        $nonce = isset($this->_req_data['autosavenonce'])
594
-                ? $this->_req_data['autosavenonce']
595
-                : null;
596
-        $this->_verify_nonce($nonce, 'autosave');
597
-        //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
598
-        if ( ! defined('DOING_AUTOSAVE')) {
599
-            define('DOING_AUTOSAVE', true);
600
-        }
601
-        //if we made it here then the nonce checked out.  Let's run our methods and actions
602
-        $autosave = "_ee_autosave_{$this->_current_view}";
603
-        if (method_exists($this, $autosave)) {
604
-            $this->$autosave();
605
-        } else {
606
-            $this->_template_args['success'] = true;
607
-        }
608
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
609
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
610
-        //now let's return json
611
-        $this->_return_json();
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
618
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
619
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
620
-     *
621
-     * @access protected
622
-     * @throws EE_Error
623
-     * @return void
624
-     */
625
-    protected function _extend_page_config_for_cpt()
626
-    {
627
-        //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
628
-        if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
629
-            return;
630
-        }
631
-        //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
-        if ( ! empty($this->_cpt_object)) {
633
-            $this->_page_routes = array_merge(array(
634
-                'create_new' => '_create_new_cpt_item',
635
-                'edit'       => '_edit_cpt_item',
636
-            ), $this->_page_routes);
637
-            $this->_page_config = array_merge(array(
638
-                'create_new' => array(
639
-                    'nav'           => array(
640
-                        'label' => $this->_cpt_object->labels->add_new_item,
641
-                        'order' => 5,
642
-                    ),
643
-                    'require_nonce' => false,
644
-                ),
645
-                'edit'       => array(
646
-                    'nav'           => array(
647
-                        'label'      => $this->_cpt_object->labels->edit_item,
648
-                        'order'      => 5,
649
-                        'persistent' => false,
650
-                        'url'        => '',
651
-                    ),
652
-                    'require_nonce' => false,
653
-                ),
654
-            ),
655
-                $this->_page_config
656
-            );
657
-        }
658
-        //load the next section only if this is a matching cpt route as set in the cpt routes array.
659
-        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
660
-            return;
661
-        }
662
-        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
663
-        //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
664
-        if (empty($this->_cpt_object)) {
665
-            $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
666
-                $this->page_slug, $this->_req_action, get_class($this));
667
-            throw new EE_Error($msg);
668
-        }
669
-        if ($this->_cpt_route) {
670
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
671
-            $this->_set_model_object($id);
672
-        }
673
-    }
674
-
675
-
676
-
677
-    /**
678
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
679
-     *
680
-     * @access protected
681
-     * @param int  $id The id to retrieve the model object for. If empty we set a default object.
682
-     * @param bool $ignore_route_check
683
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
684
-     * @throws EE_Error
685
-     */
686
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
687
-    {
688
-        $model = null;
689
-        if (
690
-            empty($this->_cpt_model_names)
691
-            || (
692
-                ! $ignore_route_check
693
-                && ! isset($this->_cpt_routes[$this->_req_action])
694
-            ) || (
695
-                $this->_cpt_model_obj instanceof EE_CPT_Base
696
-                && $this->_cpt_model_obj->ID() === $id
697
-            )
698
-        ) {
699
-            //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
700
-            return;
701
-        }
702
-        //if ignore_route_check is true, then get the model name via EE_Register_CPTs
703
-        if ($ignore_route_check) {
704
-            $model_names = EE_Register_CPTs::get_cpt_model_names();
705
-            $post_type   = get_post_type($id);
706
-            if (isset($model_names[$post_type])) {
707
-                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
708
-            }
709
-        } else {
710
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
711
-        }
712
-        if ($model instanceof EEM_Base) {
713
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
714
-        }
715
-        do_action(
716
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
717
-            $this->_cpt_model_obj,
718
-            $req_type
719
-        );
720
-    }
721
-
722
-
723
-
724
-    /**
725
-     * admin_init_global
726
-     * This runs all the code that we want executed within the WP admin_init hook.
727
-     * This method executes for ALL EE Admin pages.
728
-     *
729
-     * @access public
730
-     * @return void
731
-     */
732
-    public function admin_init_global()
733
-    {
734
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
735
-        //its possible this is a new save so let's catch that instead
736
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
737
-        $post_type = $post ? $post->post_type : false;
738
-        $current_route = isset($this->_req_data['current_route'])
739
-            ? $this->_req_data['current_route']
740
-            : 'shouldneverwork';
741
-        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
742
-            ? $this->_cpt_routes[$current_route]
743
-            : '';
744
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
745
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
746
-        if ($post_type === $route_to_check) {
747
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
748
-        }
749
-        //now let's filter redirect if we're on a revision page and the revision is for an event CPT.
750
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
751
-        if ( ! empty($revision)) {
752
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
753
-            //doing a restore?
754
-            if ( ! empty($action) && $action === 'restore') {
755
-                //get post for revision
756
-                $rev_post = get_post($revision);
757
-                $rev_parent = get_post($rev_post->post_parent);
758
-                //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
759
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
760
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
761
-                    //restores of revisions
762
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
763
-                }
764
-            }
765
-        }
766
-        //NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
767
-        if ($post_type && $post_type === $route_to_check) {
768
-            //$post_id, $post
769
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
770
-            //$post_id
771
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
772
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
773
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
774
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
775
-        }
776
-    }
777
-
778
-
779
-
780
-    /**
781
-     * Callback for the WordPress trashed_post hook.
782
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
783
-     *
784
-     * @param int $post_id
785
-     * @throws \EE_Error
786
-     */
787
-    public function before_trash_cpt_item($post_id)
788
-    {
789
-        $this->_set_model_object($post_id, true, 'trash');
790
-        //if our cpt object isn't existent then get out immediately.
791
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
792
-            return;
793
-        }
794
-        $this->trash_cpt_item($post_id);
795
-    }
796
-
797
-
798
-
799
-    /**
800
-     * Callback for the WordPress untrashed_post hook.
801
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
802
-     *
803
-     * @param $post_id
804
-     * @throws \EE_Error
805
-     */
806
-    public function before_restore_cpt_item($post_id)
807
-    {
808
-        $this->_set_model_object($post_id, true, 'restore');
809
-        //if our cpt object isn't existent then get out immediately.
810
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
811
-            return;
812
-        }
813
-        $this->restore_cpt_item($post_id);
814
-    }
815
-
816
-
817
-
818
-    /**
819
-     * Callback for the WordPress after_delete_post hook.
820
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
821
-     *
822
-     * @param $post_id
823
-     * @throws \EE_Error
824
-     */
825
-    public function before_delete_cpt_item($post_id)
826
-    {
827
-        $this->_set_model_object($post_id, true, 'delete');
828
-        //if our cpt object isn't existent then get out immediately.
829
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
830
-            return;
831
-        }
832
-        $this->delete_cpt_item($post_id);
833
-    }
834
-
835
-
836
-
837
-    /**
838
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
839
-     * accordingly.
840
-     *
841
-     * @access public
842
-     * @throws EE_Error
843
-     * @return void
844
-     */
845
-    public function verify_cpt_object()
846
-    {
847
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
848
-        // verify event object
849
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
850
-            throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
851
-                    'event_espresso'), $label));
852
-        }
853
-        //if auto-draft then throw an error
854
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
855
-            EE_Error::overwrite_errors();
856
-            EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
857
-                    $label), __FILE__, __FUNCTION__, __LINE__);
858
-        }
859
-    }
860
-
861
-
862
-
863
-    /**
864
-     * admin_footer_scripts_global
865
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
866
-     * will apply on ALL EE_Admin pages.
867
-     *
868
-     * @access public
869
-     * @return void
870
-     */
871
-    public function admin_footer_scripts_global()
872
-    {
873
-        $this->_add_admin_page_ajax_loading_img();
874
-        $this->_add_admin_page_overlay();
875
-    }
876
-
877
-
878
-
879
-    /**
880
-     * add in any global scripts for cpt routes
881
-     *
882
-     * @return void
883
-     */
884
-    public function load_global_scripts_styles()
885
-    {
886
-        parent::load_global_scripts_styles();
887
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
888
-            //setup custom post status object for localize script but only if we've got a cpt object
889
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
890
-            if ( ! empty($statuses)) {
891
-                //get ALL statuses!
892
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
893
-                //setup object
894
-                $ee_cpt_statuses = array();
895
-                foreach ($statuses as $status => $label) {
896
-                    $ee_cpt_statuses[$status] = array(
897
-                        'label'      => $label,
898
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
899
-                    );
900
-                }
901
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
902
-            }
903
-        }
904
-    }
905
-
906
-
907
-
908
-    /**
909
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
910
-     * insert/updates
911
-     *
912
-     * @param  int     $post_id ID of post being updated
913
-     * @param  WP_Post $post    Post object from WP
914
-     * @param  bool    $update  Whether this is an update or a new save.
915
-     * @return void
916
-     * @throws \EE_Error
917
-     */
918
-    public function insert_update($post_id, $post, $update)
919
-    {
920
-        //make sure that if this is a revision OR trash action that we don't do any updates!
921
-        if (
922
-            isset($this->_req_data['action'])
923
-            && (
924
-                $this->_req_data['action'] === 'restore'
925
-                || $this->_req_data['action'] === 'trash'
926
-            )
927
-        ) {
928
-            return;
929
-        }
930
-        $this->_set_model_object($post_id, true, 'insert_update');
931
-        //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
932
-        if ($update
933
-            && (
934
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
935
-                || $this->_cpt_model_obj->ID() !== $post_id
936
-            )
937
-        ) {
938
-            return;
939
-        }
940
-        //check for autosave and update our req_data property accordingly.
941
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
498
+	}
499
+
500
+
501
+
502
+	/**
503
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
504
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
505
+	 *
506
+	 * @param  string $return    the current html
507
+	 * @param  int    $id        the post id for the page
508
+	 * @param  string $new_title What the title is
509
+	 * @param  string $new_slug  what the slug is
510
+	 * @return string            The new html string for the permalink area
511
+	 */
512
+	public function preview_button_html($return, $id, $new_title, $new_slug)
513
+	{
514
+		$post = get_post($id);
515
+		if ('publish' !== get_post_status($post)) {
516
+			//include shims for the `get_preview_post_link` function
517
+			require_once( EE_CORE . 'wordpress-shims.php' );
518
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
519
+					   . get_preview_post_link($id)
520
+					   . '" class="button button-small">'
521
+					   . __('Preview', 'event_espresso')
522
+					   . '</a></span>'
523
+					   . "\n";
524
+		}
525
+		return $return;
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * add our custom post stati dropdown on the wp post page for this cpt
532
+	 *
533
+	 * @return void
534
+	 */
535
+	public function custom_post_stati_dropdown()
536
+	{
537
+
538
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
539
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
540
+			? $statuses[$this->_cpt_model_obj->status()]
541
+			: '';
542
+		$template_args    = array(
543
+			'cur_status'            => $this->_cpt_model_obj->status(),
544
+			'statuses'              => $statuses,
545
+			'cur_status_label'      => $cur_status_label,
546
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
547
+		);
548
+		//we'll add a trash post status (WP doesn't add one for some reason)
549
+		if ($this->_cpt_model_obj->status() === 'trash') {
550
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
551
+			$statuses['trash']                 = __('Trashed', 'event_espresso');
552
+			$template_args['statuses']         = $statuses;
553
+		}
554
+
555
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
556
+		EEH_Template::display_template($template, $template_args);
557
+	}
558
+
559
+
560
+
561
+	public function setup_autosave_hooks()
562
+	{
563
+		$this->_set_autosave_containers();
564
+		$this->_load_autosave_scripts_styles();
565
+	}
566
+
567
+
568
+
569
+	/**
570
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
571
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
572
+	 * for the nonce in here, but then this method looks for two things:
573
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
574
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
575
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
576
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
577
+	 * template args.
578
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
579
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
580
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
581
+	 *    $this->_template_args['data']['items'] = array(
582
+	 *        'event-datetime-ids' => '1,2,3';
583
+	 *    );
584
+	 *    Keep in mind the following things:
585
+	 *    - "where" index is for the input with the id as that string.
586
+	 *    - "what" index is what will be used for the value of that input.
587
+	 *
588
+	 * @return void
589
+	 */
590
+	public function do_extra_autosave_stuff()
591
+	{
592
+		//next let's check for the autosave nonce (we'll use _verify_nonce )
593
+		$nonce = isset($this->_req_data['autosavenonce'])
594
+				? $this->_req_data['autosavenonce']
595
+				: null;
596
+		$this->_verify_nonce($nonce, 'autosave');
597
+		//make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
598
+		if ( ! defined('DOING_AUTOSAVE')) {
599
+			define('DOING_AUTOSAVE', true);
600
+		}
601
+		//if we made it here then the nonce checked out.  Let's run our methods and actions
602
+		$autosave = "_ee_autosave_{$this->_current_view}";
603
+		if (method_exists($this, $autosave)) {
604
+			$this->$autosave();
605
+		} else {
606
+			$this->_template_args['success'] = true;
607
+		}
608
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
609
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
610
+		//now let's return json
611
+		$this->_return_json();
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
618
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
619
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
620
+	 *
621
+	 * @access protected
622
+	 * @throws EE_Error
623
+	 * @return void
624
+	 */
625
+	protected function _extend_page_config_for_cpt()
626
+	{
627
+		//before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
628
+		if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
629
+			return;
630
+		}
631
+		//set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
+		if ( ! empty($this->_cpt_object)) {
633
+			$this->_page_routes = array_merge(array(
634
+				'create_new' => '_create_new_cpt_item',
635
+				'edit'       => '_edit_cpt_item',
636
+			), $this->_page_routes);
637
+			$this->_page_config = array_merge(array(
638
+				'create_new' => array(
639
+					'nav'           => array(
640
+						'label' => $this->_cpt_object->labels->add_new_item,
641
+						'order' => 5,
642
+					),
643
+					'require_nonce' => false,
644
+				),
645
+				'edit'       => array(
646
+					'nav'           => array(
647
+						'label'      => $this->_cpt_object->labels->edit_item,
648
+						'order'      => 5,
649
+						'persistent' => false,
650
+						'url'        => '',
651
+					),
652
+					'require_nonce' => false,
653
+				),
654
+			),
655
+				$this->_page_config
656
+			);
657
+		}
658
+		//load the next section only if this is a matching cpt route as set in the cpt routes array.
659
+		if ( ! isset($this->_cpt_routes[$this->_req_action])) {
660
+			return;
661
+		}
662
+		$this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
663
+		//add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
664
+		if (empty($this->_cpt_object)) {
665
+			$msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
666
+				$this->page_slug, $this->_req_action, get_class($this));
667
+			throw new EE_Error($msg);
668
+		}
669
+		if ($this->_cpt_route) {
670
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
671
+			$this->_set_model_object($id);
672
+		}
673
+	}
674
+
675
+
676
+
677
+	/**
678
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
679
+	 *
680
+	 * @access protected
681
+	 * @param int  $id The id to retrieve the model object for. If empty we set a default object.
682
+	 * @param bool $ignore_route_check
683
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
684
+	 * @throws EE_Error
685
+	 */
686
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
687
+	{
688
+		$model = null;
689
+		if (
690
+			empty($this->_cpt_model_names)
691
+			|| (
692
+				! $ignore_route_check
693
+				&& ! isset($this->_cpt_routes[$this->_req_action])
694
+			) || (
695
+				$this->_cpt_model_obj instanceof EE_CPT_Base
696
+				&& $this->_cpt_model_obj->ID() === $id
697
+			)
698
+		) {
699
+			//get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
700
+			return;
701
+		}
702
+		//if ignore_route_check is true, then get the model name via EE_Register_CPTs
703
+		if ($ignore_route_check) {
704
+			$model_names = EE_Register_CPTs::get_cpt_model_names();
705
+			$post_type   = get_post_type($id);
706
+			if (isset($model_names[$post_type])) {
707
+				$model = EE_Registry::instance()->load_model($model_names[$post_type]);
708
+			}
709
+		} else {
710
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
711
+		}
712
+		if ($model instanceof EEM_Base) {
713
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
714
+		}
715
+		do_action(
716
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
717
+			$this->_cpt_model_obj,
718
+			$req_type
719
+		);
720
+	}
721
+
722
+
723
+
724
+	/**
725
+	 * admin_init_global
726
+	 * This runs all the code that we want executed within the WP admin_init hook.
727
+	 * This method executes for ALL EE Admin pages.
728
+	 *
729
+	 * @access public
730
+	 * @return void
731
+	 */
732
+	public function admin_init_global()
733
+	{
734
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
735
+		//its possible this is a new save so let's catch that instead
736
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
737
+		$post_type = $post ? $post->post_type : false;
738
+		$current_route = isset($this->_req_data['current_route'])
739
+			? $this->_req_data['current_route']
740
+			: 'shouldneverwork';
741
+		$route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
742
+			? $this->_cpt_routes[$current_route]
743
+			: '';
744
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
745
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
746
+		if ($post_type === $route_to_check) {
747
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
748
+		}
749
+		//now let's filter redirect if we're on a revision page and the revision is for an event CPT.
750
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
751
+		if ( ! empty($revision)) {
752
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
753
+			//doing a restore?
754
+			if ( ! empty($action) && $action === 'restore') {
755
+				//get post for revision
756
+				$rev_post = get_post($revision);
757
+				$rev_parent = get_post($rev_post->post_parent);
758
+				//only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
759
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
760
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
761
+					//restores of revisions
762
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
763
+				}
764
+			}
765
+		}
766
+		//NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
767
+		if ($post_type && $post_type === $route_to_check) {
768
+			//$post_id, $post
769
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
770
+			//$post_id
771
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
772
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
773
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
774
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
775
+		}
776
+	}
777
+
778
+
779
+
780
+	/**
781
+	 * Callback for the WordPress trashed_post hook.
782
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
783
+	 *
784
+	 * @param int $post_id
785
+	 * @throws \EE_Error
786
+	 */
787
+	public function before_trash_cpt_item($post_id)
788
+	{
789
+		$this->_set_model_object($post_id, true, 'trash');
790
+		//if our cpt object isn't existent then get out immediately.
791
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
792
+			return;
793
+		}
794
+		$this->trash_cpt_item($post_id);
795
+	}
796
+
797
+
798
+
799
+	/**
800
+	 * Callback for the WordPress untrashed_post hook.
801
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
802
+	 *
803
+	 * @param $post_id
804
+	 * @throws \EE_Error
805
+	 */
806
+	public function before_restore_cpt_item($post_id)
807
+	{
808
+		$this->_set_model_object($post_id, true, 'restore');
809
+		//if our cpt object isn't existent then get out immediately.
810
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
811
+			return;
812
+		}
813
+		$this->restore_cpt_item($post_id);
814
+	}
815
+
816
+
817
+
818
+	/**
819
+	 * Callback for the WordPress after_delete_post hook.
820
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
821
+	 *
822
+	 * @param $post_id
823
+	 * @throws \EE_Error
824
+	 */
825
+	public function before_delete_cpt_item($post_id)
826
+	{
827
+		$this->_set_model_object($post_id, true, 'delete');
828
+		//if our cpt object isn't existent then get out immediately.
829
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
830
+			return;
831
+		}
832
+		$this->delete_cpt_item($post_id);
833
+	}
834
+
835
+
836
+
837
+	/**
838
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
839
+	 * accordingly.
840
+	 *
841
+	 * @access public
842
+	 * @throws EE_Error
843
+	 * @return void
844
+	 */
845
+	public function verify_cpt_object()
846
+	{
847
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
848
+		// verify event object
849
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
850
+			throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
851
+					'event_espresso'), $label));
852
+		}
853
+		//if auto-draft then throw an error
854
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
855
+			EE_Error::overwrite_errors();
856
+			EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
857
+					$label), __FILE__, __FUNCTION__, __LINE__);
858
+		}
859
+	}
860
+
861
+
862
+
863
+	/**
864
+	 * admin_footer_scripts_global
865
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
866
+	 * will apply on ALL EE_Admin pages.
867
+	 *
868
+	 * @access public
869
+	 * @return void
870
+	 */
871
+	public function admin_footer_scripts_global()
872
+	{
873
+		$this->_add_admin_page_ajax_loading_img();
874
+		$this->_add_admin_page_overlay();
875
+	}
876
+
877
+
878
+
879
+	/**
880
+	 * add in any global scripts for cpt routes
881
+	 *
882
+	 * @return void
883
+	 */
884
+	public function load_global_scripts_styles()
885
+	{
886
+		parent::load_global_scripts_styles();
887
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
888
+			//setup custom post status object for localize script but only if we've got a cpt object
889
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
890
+			if ( ! empty($statuses)) {
891
+				//get ALL statuses!
892
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
893
+				//setup object
894
+				$ee_cpt_statuses = array();
895
+				foreach ($statuses as $status => $label) {
896
+					$ee_cpt_statuses[$status] = array(
897
+						'label'      => $label,
898
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
899
+					);
900
+				}
901
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
902
+			}
903
+		}
904
+	}
905
+
906
+
907
+
908
+	/**
909
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
910
+	 * insert/updates
911
+	 *
912
+	 * @param  int     $post_id ID of post being updated
913
+	 * @param  WP_Post $post    Post object from WP
914
+	 * @param  bool    $update  Whether this is an update or a new save.
915
+	 * @return void
916
+	 * @throws \EE_Error
917
+	 */
918
+	public function insert_update($post_id, $post, $update)
919
+	{
920
+		//make sure that if this is a revision OR trash action that we don't do any updates!
921
+		if (
922
+			isset($this->_req_data['action'])
923
+			&& (
924
+				$this->_req_data['action'] === 'restore'
925
+				|| $this->_req_data['action'] === 'trash'
926
+			)
927
+		) {
928
+			return;
929
+		}
930
+		$this->_set_model_object($post_id, true, 'insert_update');
931
+		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
932
+		if ($update
933
+			&& (
934
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
935
+				|| $this->_cpt_model_obj->ID() !== $post_id
936
+			)
937
+		) {
938
+			return;
939
+		}
940
+		//check for autosave and update our req_data property accordingly.
941
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
942 942
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
943 943
 
944 944
                 foreach ( (array) $values as $key => $value ) {
@@ -948,527 +948,527 @@  discard block
 block discarded – undo
948 948
 
949 949
         }/**/ //TODO reactivate after autosave is implemented in 4.2
950 950
 
951
-        //take care of updating any selected page_template IF this cpt supports it.
952
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
953
-            //wp version aware.
954
-            if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
955
-                $page_templates = wp_get_theme()->get_page_templates();
956
-            } else {
957
-                $post->page_template = $this->_req_data['page_template'];
958
-                $page_templates      = wp_get_theme()->get_page_templates($post);
959
-            }
960
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
961
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
962
-            } else {
963
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
964
-            }
965
-        }
966
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
967
-            return;
968
-        } //TODO we'll remove this after reimplementing autosave in 4.2
969
-        $this->_insert_update_cpt_item($post_id, $post);
970
-    }
971
-
972
-
973
-
974
-    /**
975
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
976
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
977
-     * so we don't have to check for our CPT.
978
-     *
979
-     * @param  int $post_id ID of the post
980
-     * @return void
981
-     */
982
-    public function dont_permanently_delete_ee_cpts($post_id)
983
-    {
984
-        //only do this if we're actually processing one of our CPTs
985
-        //if our cpt object isn't existent then get out immediately.
986
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
987
-            return;
988
-        }
989
-        delete_post_meta($post_id, '_wp_trash_meta_status');
990
-        delete_post_meta($post_id, '_wp_trash_meta_time');
991
-        //our cpts may have comments so let's take care of that too
992
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
993
-    }
994
-
995
-
996
-
997
-    /**
998
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
999
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1000
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1001
-     *
1002
-     * @param  int $post_id     ID of cpt item
1003
-     * @param  int $revision_id ID of revision being restored
1004
-     * @return void
1005
-     */
1006
-    public function restore_revision($post_id, $revision_id)
1007
-    {
1008
-        $this->_restore_cpt_item($post_id, $revision_id);
1009
-        //global action
1010
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1011
-        //class specific action so you can limit hooking into a specific page.
1012
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1013
-    }
1014
-
1015
-
1016
-
1017
-    /**
1018
-     * @see restore_revision() for details
1019
-     * @param  int $post_id     ID of cpt item
1020
-     * @param  int $revision_id ID of revision for item
1021
-     * @return void
1022
-     */
1023
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1024
-
1025
-
1026
-
1027
-    /**
1028
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1029
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1030
-     * To fix we have to reset the current_screen using the page_slug
1031
-     * (which is identical - or should be - to our registered_post_type id.)
1032
-     * Also, since the core WP file loads the admin_header.php for WP
1033
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1034
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1035
-     *
1036
-     * @return void
1037
-     */
1038
-    public function modify_current_screen()
1039
-    {
1040
-        //ONLY do this if the current page_route IS a cpt route
1041
-        if ( ! $this->_cpt_route) {
1042
-            return;
1043
-        }
1044
-        //routing things REALLY early b/c this is a cpt admin page
1045
-        set_current_screen($this->_cpt_routes[$this->_req_action]);
1046
-        $this->_current_screen       = get_current_screen();
1047
-        $this->_current_screen->base = 'event-espresso';
1048
-        $this->_add_help_tabs(); //we make sure we add any help tabs back in!
1049
-        /*try {
951
+		//take care of updating any selected page_template IF this cpt supports it.
952
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
953
+			//wp version aware.
954
+			if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
955
+				$page_templates = wp_get_theme()->get_page_templates();
956
+			} else {
957
+				$post->page_template = $this->_req_data['page_template'];
958
+				$page_templates      = wp_get_theme()->get_page_templates($post);
959
+			}
960
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
961
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
962
+			} else {
963
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
964
+			}
965
+		}
966
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
967
+			return;
968
+		} //TODO we'll remove this after reimplementing autosave in 4.2
969
+		$this->_insert_update_cpt_item($post_id, $post);
970
+	}
971
+
972
+
973
+
974
+	/**
975
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
976
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
977
+	 * so we don't have to check for our CPT.
978
+	 *
979
+	 * @param  int $post_id ID of the post
980
+	 * @return void
981
+	 */
982
+	public function dont_permanently_delete_ee_cpts($post_id)
983
+	{
984
+		//only do this if we're actually processing one of our CPTs
985
+		//if our cpt object isn't existent then get out immediately.
986
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
987
+			return;
988
+		}
989
+		delete_post_meta($post_id, '_wp_trash_meta_status');
990
+		delete_post_meta($post_id, '_wp_trash_meta_time');
991
+		//our cpts may have comments so let's take care of that too
992
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
993
+	}
994
+
995
+
996
+
997
+	/**
998
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
999
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1000
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1001
+	 *
1002
+	 * @param  int $post_id     ID of cpt item
1003
+	 * @param  int $revision_id ID of revision being restored
1004
+	 * @return void
1005
+	 */
1006
+	public function restore_revision($post_id, $revision_id)
1007
+	{
1008
+		$this->_restore_cpt_item($post_id, $revision_id);
1009
+		//global action
1010
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1011
+		//class specific action so you can limit hooking into a specific page.
1012
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1013
+	}
1014
+
1015
+
1016
+
1017
+	/**
1018
+	 * @see restore_revision() for details
1019
+	 * @param  int $post_id     ID of cpt item
1020
+	 * @param  int $revision_id ID of revision for item
1021
+	 * @return void
1022
+	 */
1023
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1024
+
1025
+
1026
+
1027
+	/**
1028
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1029
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1030
+	 * To fix we have to reset the current_screen using the page_slug
1031
+	 * (which is identical - or should be - to our registered_post_type id.)
1032
+	 * Also, since the core WP file loads the admin_header.php for WP
1033
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1034
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1035
+	 *
1036
+	 * @return void
1037
+	 */
1038
+	public function modify_current_screen()
1039
+	{
1040
+		//ONLY do this if the current page_route IS a cpt route
1041
+		if ( ! $this->_cpt_route) {
1042
+			return;
1043
+		}
1044
+		//routing things REALLY early b/c this is a cpt admin page
1045
+		set_current_screen($this->_cpt_routes[$this->_req_action]);
1046
+		$this->_current_screen       = get_current_screen();
1047
+		$this->_current_screen->base = 'event-espresso';
1048
+		$this->_add_help_tabs(); //we make sure we add any help tabs back in!
1049
+		/*try {
1050 1050
             $this->_route_admin_request();
1051 1051
         } catch ( EE_Error $e ) {
1052 1052
             $e->get_error();
1053 1053
         }/**/
1054
-    }
1055
-
1056
-
1057
-
1058
-    /**
1059
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1060
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1061
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1062
-     * default to be.
1063
-     *
1064
-     * @param string $title The new title (or existing if there is no editor_title defined)
1065
-     * @return string
1066
-     */
1067
-    public function add_custom_editor_default_title($title)
1068
-    {
1069
-        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1070
-            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1071
-            : $title;
1072
-    }
1073
-
1074
-
1075
-
1076
-    /**
1077
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1078
-     *
1079
-     * @param string $shortlink   The already generated shortlink
1080
-     * @param int    $id          Post ID for this item
1081
-     * @param string $context     The context for the link
1082
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1083
-     * @return string
1084
-     */
1085
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1086
-    {
1087
-        if ( ! empty($id) && get_option('permalink_structure') !== '') {
1088
-            $post = get_post($id);
1089
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1090
-                $shortlink = home_url('?p=' . $post->ID);
1091
-            }
1092
-        }
1093
-        return $shortlink;
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1100
-     * already run in modify_current_screen())
1101
-     *
1102
-     * @return void
1103
-     */
1104
-    public function route_admin_request()
1105
-    {
1106
-        if ($this->_cpt_route) {
1107
-            return;
1108
-        }
1109
-        try {
1110
-            $this->_route_admin_request();
1111
-        } catch (EE_Error $e) {
1112
-            $e->get_error();
1113
-        }
1114
-    }
1115
-
1116
-
1117
-
1118
-    /**
1119
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1120
-     *
1121
-     * @return void
1122
-     */
1123
-    public function cpt_post_form_hidden_input()
1124
-    {
1125
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1126
-        //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1127
-        echo '<div id="ee-cpt-hidden-inputs">';
1128
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1129
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1130
-        echo '</div>';
1131
-    }
1132
-
1133
-
1134
-
1135
-    /**
1136
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1137
-     *
1138
-     * @param  string $location Original location url
1139
-     * @param  int    $status   Status for http header
1140
-     * @return string           new (or original) url to redirect to.
1141
-     */
1142
-    public function revision_redirect($location, $status)
1143
-    {
1144
-        //get revision
1145
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1146
-        //can't do anything without revision so let's get out if not present
1147
-        if (empty($rev_id)) {
1148
-            return $location;
1149
-        }
1150
-        //get rev_post_data
1151
-        $rev = get_post($rev_id);
1152
-        $admin_url = $this->_admin_base_url;
1153
-        $query_args = array(
1154
-            'action'   => 'edit',
1155
-            'post'     => $rev->post_parent,
1156
-            'revision' => $rev_id,
1157
-            'message'  => 5,
1158
-        );
1159
-        $this->_process_notices($query_args, true);
1160
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1161
-    }
1162
-
1163
-
1164
-
1165
-    /**
1166
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1167
-     *
1168
-     * @param  string $link    the original generated link
1169
-     * @param  int    $id      post id
1170
-     * @param  string $context optional, defaults to display.  How to write the '&'
1171
-     * @return string          the link
1172
-     */
1173
-    public function modify_edit_post_link($link, $id, $context)
1174
-    {
1175
-        $post = get_post($id);
1176
-        if ( ! isset($this->_req_data['action'])
1177
-             || ! isset($this->_cpt_routes[$this->_req_data['action']])
1178
-             || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1179
-        ) {
1180
-            return $link;
1181
-        }
1182
-        $query_args = array(
1183
-            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1184
-                ? $this->_cpt_edit_routes[$post->post_type]
1185
-                : 'edit',
1186
-            'post'   => $id,
1187
-        );
1188
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1194
-     * our routes.
1195
-     *
1196
-     * @param  string $delete_link  original delete link
1197
-     * @param  int    $post_id      id of cpt object
1198
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1199
-     * @return string new delete link
1200
-     * @throws EE_Error
1201
-     */
1202
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1203
-    {
1204
-        $post = get_post($post_id);
1205
-
1206
-        if (empty($this->_req_data['action'])
1207
-            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1208
-            || ! $post instanceof WP_Post
1209
-            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1210
-        ) {
1211
-            return $delete_link;
1212
-        }
1213
-        $this->_set_model_object($post->ID, true);
1214
-
1215
-        //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1216
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1217
-
1218
-        return EE_Admin_Page::add_query_args_and_nonce(
1219
-            array(
1220
-                'page' => $this->_req_data['page'],
1221
-                'action' => $action,
1222
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1223
-                    => $post->ID
1224
-            ),
1225
-            admin_url()
1226
-        );
1227
-    }
1228
-
1229
-
1230
-
1231
-    /**
1232
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1233
-     * so that we can hijack the default redirect locations for wp custom post types
1234
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1235
-     *
1236
-     * @param  string $location This is the incoming currently set redirect location
1237
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1238
-     * @return string           the new location to redirect to
1239
-     */
1240
-    public function cpt_post_location_redirect($location, $post_id)
1241
-    {
1242
-        //we DO have a match so let's setup the url
1243
-        //we have to get the post to determine our route
1244
-        $post       = get_post($post_id);
1245
-        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1246
-        //shared query_args
1247
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1248
-        $admin_url  = $this->_admin_base_url;
1249
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1250
-            $status = get_post_status($post_id);
1251
-            if (isset($this->_req_data['publish'])) {
1252
-                switch ($status) {
1253
-                    case 'pending':
1254
-                        $message = 8;
1255
-                        break;
1256
-                    case 'future':
1257
-                        $message = 9;
1258
-                        break;
1259
-                    default:
1260
-                        $message = 6;
1261
-                }
1262
-            } else {
1263
-                $message = 'draft' === $status ? 10 : 1;
1264
-            }
1265
-        } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1266
-            $message = 2;
1267
-            //			$append = '#postcustom';
1268
-        } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1269
-            $message = 3;
1270
-            //			$append = '#postcustom';
1271
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1272
-            $message = 7;
1273
-        } else {
1274
-            $message = 4;
1275
-        }
1276
-        //change the message if the post type is not viewable on the frontend
1277
-        $this->_cpt_object = get_post_type_object($post->post_type);
1278
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1279
-        $query_args = array_merge(array('message' => $message), $query_args);
1280
-        $this->_process_notices($query_args, true);
1281
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1282
-    }
1283
-
1284
-
1285
-
1286
-    /**
1287
-     * This method is called to inject nav tabs on core WP cpt pages
1288
-     *
1289
-     * @access public
1290
-     * @return void
1291
-     */
1292
-    public function inject_nav_tabs()
1293
-    {
1294
-        //can we hijack and insert the nav_tabs?
1295
-        $nav_tabs = $this->_get_main_nav_tabs();
1296
-        //first close off existing form tag
1297
-        $html = '>';
1298
-        $html .= $nav_tabs;
1299
-        //now let's handle the remaining tag ( missing ">" is CORRECT )
1300
-        $html .= '<span></span';
1301
-        echo $html;
1302
-    }
1303
-
1304
-
1305
-
1306
-    /**
1307
-     * This just sets up the post update messages when an update form is loaded
1308
-     *
1309
-     * @access public
1310
-     * @param  array $messages the original messages array
1311
-     * @return array           the new messages array
1312
-     */
1313
-    public function post_update_messages($messages)
1314
-    {
1315
-        global $post;
1316
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1317
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1318
-        //		$post_type = $post ? $post->post_type : false;
1319
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1054
+	}
1055
+
1056
+
1057
+
1058
+	/**
1059
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1060
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1061
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1062
+	 * default to be.
1063
+	 *
1064
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1065
+	 * @return string
1066
+	 */
1067
+	public function add_custom_editor_default_title($title)
1068
+	{
1069
+		return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1070
+			? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1071
+			: $title;
1072
+	}
1073
+
1074
+
1075
+
1076
+	/**
1077
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1078
+	 *
1079
+	 * @param string $shortlink   The already generated shortlink
1080
+	 * @param int    $id          Post ID for this item
1081
+	 * @param string $context     The context for the link
1082
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1083
+	 * @return string
1084
+	 */
1085
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1086
+	{
1087
+		if ( ! empty($id) && get_option('permalink_structure') !== '') {
1088
+			$post = get_post($id);
1089
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1090
+				$shortlink = home_url('?p=' . $post->ID);
1091
+			}
1092
+		}
1093
+		return $shortlink;
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1100
+	 * already run in modify_current_screen())
1101
+	 *
1102
+	 * @return void
1103
+	 */
1104
+	public function route_admin_request()
1105
+	{
1106
+		if ($this->_cpt_route) {
1107
+			return;
1108
+		}
1109
+		try {
1110
+			$this->_route_admin_request();
1111
+		} catch (EE_Error $e) {
1112
+			$e->get_error();
1113
+		}
1114
+	}
1115
+
1116
+
1117
+
1118
+	/**
1119
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1120
+	 *
1121
+	 * @return void
1122
+	 */
1123
+	public function cpt_post_form_hidden_input()
1124
+	{
1125
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1126
+		//we're also going to add the route value and the current page so we can direct autosave parsing correctly
1127
+		echo '<div id="ee-cpt-hidden-inputs">';
1128
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1129
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1130
+		echo '</div>';
1131
+	}
1132
+
1133
+
1134
+
1135
+	/**
1136
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1137
+	 *
1138
+	 * @param  string $location Original location url
1139
+	 * @param  int    $status   Status for http header
1140
+	 * @return string           new (or original) url to redirect to.
1141
+	 */
1142
+	public function revision_redirect($location, $status)
1143
+	{
1144
+		//get revision
1145
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1146
+		//can't do anything without revision so let's get out if not present
1147
+		if (empty($rev_id)) {
1148
+			return $location;
1149
+		}
1150
+		//get rev_post_data
1151
+		$rev = get_post($rev_id);
1152
+		$admin_url = $this->_admin_base_url;
1153
+		$query_args = array(
1154
+			'action'   => 'edit',
1155
+			'post'     => $rev->post_parent,
1156
+			'revision' => $rev_id,
1157
+			'message'  => 5,
1158
+		);
1159
+		$this->_process_notices($query_args, true);
1160
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1161
+	}
1162
+
1163
+
1164
+
1165
+	/**
1166
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1167
+	 *
1168
+	 * @param  string $link    the original generated link
1169
+	 * @param  int    $id      post id
1170
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1171
+	 * @return string          the link
1172
+	 */
1173
+	public function modify_edit_post_link($link, $id, $context)
1174
+	{
1175
+		$post = get_post($id);
1176
+		if ( ! isset($this->_req_data['action'])
1177
+			 || ! isset($this->_cpt_routes[$this->_req_data['action']])
1178
+			 || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1179
+		) {
1180
+			return $link;
1181
+		}
1182
+		$query_args = array(
1183
+			'action' => isset($this->_cpt_edit_routes[$post->post_type])
1184
+				? $this->_cpt_edit_routes[$post->post_type]
1185
+				: 'edit',
1186
+			'post'   => $id,
1187
+		);
1188
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1194
+	 * our routes.
1195
+	 *
1196
+	 * @param  string $delete_link  original delete link
1197
+	 * @param  int    $post_id      id of cpt object
1198
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1199
+	 * @return string new delete link
1200
+	 * @throws EE_Error
1201
+	 */
1202
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1203
+	{
1204
+		$post = get_post($post_id);
1205
+
1206
+		if (empty($this->_req_data['action'])
1207
+			|| ! isset($this->_cpt_routes[$this->_req_data['action']])
1208
+			|| ! $post instanceof WP_Post
1209
+			|| $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1210
+		) {
1211
+			return $delete_link;
1212
+		}
1213
+		$this->_set_model_object($post->ID, true);
1214
+
1215
+		//returns something like `trash_event` or `trash_attendee` or `trash_venue`
1216
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1217
+
1218
+		return EE_Admin_Page::add_query_args_and_nonce(
1219
+			array(
1220
+				'page' => $this->_req_data['page'],
1221
+				'action' => $action,
1222
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1223
+					=> $post->ID
1224
+			),
1225
+			admin_url()
1226
+		);
1227
+	}
1228
+
1229
+
1230
+
1231
+	/**
1232
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1233
+	 * so that we can hijack the default redirect locations for wp custom post types
1234
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1235
+	 *
1236
+	 * @param  string $location This is the incoming currently set redirect location
1237
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1238
+	 * @return string           the new location to redirect to
1239
+	 */
1240
+	public function cpt_post_location_redirect($location, $post_id)
1241
+	{
1242
+		//we DO have a match so let's setup the url
1243
+		//we have to get the post to determine our route
1244
+		$post       = get_post($post_id);
1245
+		$edit_route = $this->_cpt_edit_routes[$post->post_type];
1246
+		//shared query_args
1247
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1248
+		$admin_url  = $this->_admin_base_url;
1249
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1250
+			$status = get_post_status($post_id);
1251
+			if (isset($this->_req_data['publish'])) {
1252
+				switch ($status) {
1253
+					case 'pending':
1254
+						$message = 8;
1255
+						break;
1256
+					case 'future':
1257
+						$message = 9;
1258
+						break;
1259
+					default:
1260
+						$message = 6;
1261
+				}
1262
+			} else {
1263
+				$message = 'draft' === $status ? 10 : 1;
1264
+			}
1265
+		} else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1266
+			$message = 2;
1267
+			//			$append = '#postcustom';
1268
+		} else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1269
+			$message = 3;
1270
+			//			$append = '#postcustom';
1271
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1272
+			$message = 7;
1273
+		} else {
1274
+			$message = 4;
1275
+		}
1276
+		//change the message if the post type is not viewable on the frontend
1277
+		$this->_cpt_object = get_post_type_object($post->post_type);
1278
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1279
+		$query_args = array_merge(array('message' => $message), $query_args);
1280
+		$this->_process_notices($query_args, true);
1281
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1282
+	}
1283
+
1284
+
1285
+
1286
+	/**
1287
+	 * This method is called to inject nav tabs on core WP cpt pages
1288
+	 *
1289
+	 * @access public
1290
+	 * @return void
1291
+	 */
1292
+	public function inject_nav_tabs()
1293
+	{
1294
+		//can we hijack and insert the nav_tabs?
1295
+		$nav_tabs = $this->_get_main_nav_tabs();
1296
+		//first close off existing form tag
1297
+		$html = '>';
1298
+		$html .= $nav_tabs;
1299
+		//now let's handle the remaining tag ( missing ">" is CORRECT )
1300
+		$html .= '<span></span';
1301
+		echo $html;
1302
+	}
1303
+
1304
+
1305
+
1306
+	/**
1307
+	 * This just sets up the post update messages when an update form is loaded
1308
+	 *
1309
+	 * @access public
1310
+	 * @param  array $messages the original messages array
1311
+	 * @return array           the new messages array
1312
+	 */
1313
+	public function post_update_messages($messages)
1314
+	{
1315
+		global $post;
1316
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1317
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1318
+		//		$post_type = $post ? $post->post_type : false;
1319
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1320 1320
 
1321 1321
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1322
-        $messages[$post->post_type] = array(
1323
-            0 => '', //Unused. Messages start at index 1.
1324
-            1 => sprintf(
1325
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1326
-                $this->_cpt_object->labels->singular_name,
1327
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1328
-                '</a>'
1329
-            ),
1330
-            2 => __('Custom field updated'),
1331
-            3 => __('Custom field deleted.'),
1332
-            4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1333
-            5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1334
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1335
-                : false,
1336
-            6 => sprintf(
1337
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1338
-                $this->_cpt_object->labels->singular_name,
1339
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1340
-                '</a>'
1341
-            ),
1342
-            7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1343
-            8 => sprintf(
1344
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1345
-                $this->_cpt_object->labels->singular_name,
1346
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1347
-                '</a>'
1348
-            ),
1349
-            9 => sprintf(
1350
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1351
-                $this->_cpt_object->labels->singular_name,
1352
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1353
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1354
-                '</a>'
1355
-            ),
1356
-            10 => sprintf(
1357
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1358
-                $this->_cpt_object->labels->singular_name,
1359
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1360
-                '</a>'
1361
-            ),
1362
-        );
1363
-        return $messages;
1364
-    }
1365
-
1366
-
1367
-
1368
-    /**
1369
-     * default method for the 'create_new' route for cpt admin pages.
1370
-     * For reference what to include in here, see wp-admin/post-new.php
1371
-     *
1372
-     * @access  protected
1373
-     * @return void
1374
-     */
1375
-    protected function _create_new_cpt_item()
1376
-    {
1377
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1378
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1379
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1380
-        $post_type_object = $this->_cpt_object;
1381
-        $title            = $post_type_object->labels->add_new_item;
1382
-        $editing          = true;
1383
-        wp_enqueue_script('autosave');
1384
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1385
-        $post_ID = $post->ID;
1386
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1387
-        //modify the default editor title field with default title.
1388
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1389
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1390
-    }
1391
-
1392
-
1393
-
1394
-    public function add_new_admin_page_global()
1395
-    {
1396
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1397
-        ?>
1322
+		$messages[$post->post_type] = array(
1323
+			0 => '', //Unused. Messages start at index 1.
1324
+			1 => sprintf(
1325
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1326
+				$this->_cpt_object->labels->singular_name,
1327
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1328
+				'</a>'
1329
+			),
1330
+			2 => __('Custom field updated'),
1331
+			3 => __('Custom field deleted.'),
1332
+			4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1333
+			5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1334
+				$this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1335
+				: false,
1336
+			6 => sprintf(
1337
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1338
+				$this->_cpt_object->labels->singular_name,
1339
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1340
+				'</a>'
1341
+			),
1342
+			7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1343
+			8 => sprintf(
1344
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1345
+				$this->_cpt_object->labels->singular_name,
1346
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1347
+				'</a>'
1348
+			),
1349
+			9 => sprintf(
1350
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1351
+				$this->_cpt_object->labels->singular_name,
1352
+				'<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1353
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1354
+				'</a>'
1355
+			),
1356
+			10 => sprintf(
1357
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1358
+				$this->_cpt_object->labels->singular_name,
1359
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1360
+				'</a>'
1361
+			),
1362
+		);
1363
+		return $messages;
1364
+	}
1365
+
1366
+
1367
+
1368
+	/**
1369
+	 * default method for the 'create_new' route for cpt admin pages.
1370
+	 * For reference what to include in here, see wp-admin/post-new.php
1371
+	 *
1372
+	 * @access  protected
1373
+	 * @return void
1374
+	 */
1375
+	protected function _create_new_cpt_item()
1376
+	{
1377
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1378
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1379
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1380
+		$post_type_object = $this->_cpt_object;
1381
+		$title            = $post_type_object->labels->add_new_item;
1382
+		$editing          = true;
1383
+		wp_enqueue_script('autosave');
1384
+		$post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1385
+		$post_ID = $post->ID;
1386
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1387
+		//modify the default editor title field with default title.
1388
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1389
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1390
+	}
1391
+
1392
+
1393
+
1394
+	public function add_new_admin_page_global()
1395
+	{
1396
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1397
+		?>
1398 1398
         <script type="text/javascript">
1399 1399
             adminpage = '<?php echo $admin_page; ?>';
1400 1400
         </script>
1401 1401
         <?php
1402
-    }
1403
-
1404
-
1405
-
1406
-    /**
1407
-     * default method for the 'edit' route for cpt admin pages
1408
-     * For reference on what to put in here, refer to wp-admin/post.php
1409
-     *
1410
-     * @access protected
1411
-     * @return string   template for edit cpt form
1412
-     */
1413
-    protected function _edit_cpt_item()
1414
-    {
1415
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1416
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1417
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1418
-        if (empty ($post)) {
1419
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1420
-        }
1421
-        if ( ! empty($_GET['get-post-lock'])) {
1422
-            wp_set_post_lock($post_id);
1423
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1424
-            exit();
1425
-        }
1426
-
1427
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1428
-        $editing          = true;
1429
-        $post_ID          = $post_id;
1430
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1431
-        $post_type_object = $this->_cpt_object;
1432
-
1433
-        if ( ! wp_check_post_lock($post->ID)) {
1434
-            $active_post_lock = wp_set_post_lock($post->ID);
1435
-            //wp_enqueue_script('autosave');
1436
-        }
1437
-        $title = $this->_cpt_object->labels->edit_item;
1438
-        add_action('admin_footer', '_admin_notice_post_locked');
1439
-        if (isset($this->_cpt_routes[$this->_req_data['action']])
1440
-            && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1441
-        ) {
1442
-            $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1443
-                'create_new', $this);
1444
-            $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1445
-                'action' => $create_new_action,
1446
-                'page'   => $this->page_slug,
1447
-            ), 'admin.php');
1448
-        }
1449
-        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1450
-            wp_enqueue_script('admin-comments');
1451
-            enqueue_comment_hotkeys_js();
1452
-        }
1453
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1454
-        //modify the default editor title field with default title.
1455
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1456
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1457
-    }
1458
-
1459
-
1460
-
1461
-    /**
1462
-     * some getters
1463
-     */
1464
-    /**
1465
-     * This returns the protected _cpt_model_obj property
1466
-     *
1467
-     * @return EE_CPT_Base
1468
-     */
1469
-    public function get_cpt_model_obj()
1470
-    {
1471
-        return $this->_cpt_model_obj;
1472
-    }
1402
+	}
1403
+
1404
+
1405
+
1406
+	/**
1407
+	 * default method for the 'edit' route for cpt admin pages
1408
+	 * For reference on what to put in here, refer to wp-admin/post.php
1409
+	 *
1410
+	 * @access protected
1411
+	 * @return string   template for edit cpt form
1412
+	 */
1413
+	protected function _edit_cpt_item()
1414
+	{
1415
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1416
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1417
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1418
+		if (empty ($post)) {
1419
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1420
+		}
1421
+		if ( ! empty($_GET['get-post-lock'])) {
1422
+			wp_set_post_lock($post_id);
1423
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1424
+			exit();
1425
+		}
1426
+
1427
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1428
+		$editing          = true;
1429
+		$post_ID          = $post_id;
1430
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1431
+		$post_type_object = $this->_cpt_object;
1432
+
1433
+		if ( ! wp_check_post_lock($post->ID)) {
1434
+			$active_post_lock = wp_set_post_lock($post->ID);
1435
+			//wp_enqueue_script('autosave');
1436
+		}
1437
+		$title = $this->_cpt_object->labels->edit_item;
1438
+		add_action('admin_footer', '_admin_notice_post_locked');
1439
+		if (isset($this->_cpt_routes[$this->_req_data['action']])
1440
+			&& ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1441
+		) {
1442
+			$create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1443
+				'create_new', $this);
1444
+			$post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1445
+				'action' => $create_new_action,
1446
+				'page'   => $this->page_slug,
1447
+			), 'admin.php');
1448
+		}
1449
+		if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1450
+			wp_enqueue_script('admin-comments');
1451
+			enqueue_comment_hotkeys_js();
1452
+		}
1453
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1454
+		//modify the default editor title field with default title.
1455
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1456
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1457
+	}
1458
+
1459
+
1460
+
1461
+	/**
1462
+	 * some getters
1463
+	 */
1464
+	/**
1465
+	 * This returns the protected _cpt_model_obj property
1466
+	 *
1467
+	 * @return EE_CPT_Base
1468
+	 */
1469
+	public function get_cpt_model_obj()
1470
+	{
1471
+		return $this->_cpt_model_obj;
1472
+	}
1473 1473
 
1474 1474
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     protected function _register_autosave_containers($ids)
237 237
     {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
238
+        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
239 239
     }
240 240
 
241 241
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
         //filter _autosave_containers
283 283
         $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
284 284
             $this->_autosave_containers, $this);
285
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
285
+        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
286 286
             $containers, $this);
287 287
 
288 288
         wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
         // This is for any plugins that are doing things properly
395 395
         // and hooking into the load page hook for core wp cpt routes.
396 396
         global $pagenow;
397
-        do_action('load-' . $pagenow);
397
+        do_action('load-'.$pagenow);
398 398
         $this->modify_current_screen();
399 399
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
400 400
         //we route REALLY early.
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
                 'admin.php?page=espresso_registrations&action=contact_list',
426 426
             ),
427 427
             1 => array(
428
-                'edit.php?post_type=' . $this->_cpt_object->name,
429
-                'admin.php?page=' . $this->_cpt_object->name,
428
+                'edit.php?post_type='.$this->_cpt_object->name,
429
+                'admin.php?page='.$this->_cpt_object->name,
430 430
             ),
431 431
         );
432 432
         foreach ($routes_to_match as $route_matches) {
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
         $cpt_has_support = ! empty($cpt_args['page_templates']);
455 455
 
456 456
         //if the installed version of WP is > 4.7 we do some additional checks.
457
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
457
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
458 458
             $post_templates = wp_get_theme()->get_post_templates();
459 459
             //if there are $post_templates for this cpt, then we return false for this method because
460 460
             //that means we aren't going to load our page template manager and leave that up to the native
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
         global $post;
478 478
         $template = '';
479 479
 
480
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
480
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
481 481
             $page_template_count = count(get_page_templates());
482 482
         } else {
483 483
             $page_template_count = count(get_page_templates($post));
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
         $post = get_post($id);
515 515
         if ('publish' !== get_post_status($post)) {
516 516
             //include shims for the `get_preview_post_link` function
517
-            require_once( EE_CORE . 'wordpress-shims.php' );
517
+            require_once(EE_CORE.'wordpress-shims.php');
518 518
             $return .= '<span_id="view-post-btn"><a target="_blank" href="'
519 519
                        . get_preview_post_link($id)
520 520
                        . '" class="button button-small">'
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
             $template_args['statuses']         = $statuses;
553 553
         }
554 554
 
555
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
555
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
556 556
         EEH_Template::display_template($template, $template_args);
557 557
     }
558 558
 
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
             $this->_template_args['success'] = true;
607 607
         }
608 608
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
609
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
609
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
610 610
         //now let's return json
611 611
         $this->_return_json();
612 612
     }
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
         //global action
1010 1010
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1011 1011
         //class specific action so you can limit hooking into a specific page.
1012
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1012
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
1013 1013
     }
1014 1014
 
1015 1015
 
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
         if ( ! empty($id) && get_option('permalink_structure') !== '') {
1088 1088
             $post = get_post($id);
1089 1089
             if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1090
-                $shortlink = home_url('?p=' . $post->ID);
1090
+                $shortlink = home_url('?p='.$post->ID);
1091 1091
             }
1092 1092
         }
1093 1093
         return $shortlink;
@@ -1122,11 +1122,11 @@  discard block
 block discarded – undo
1122 1122
      */
1123 1123
     public function cpt_post_form_hidden_input()
1124 1124
     {
1125
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1125
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1126 1126
         //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1127 1127
         echo '<div id="ee-cpt-hidden-inputs">';
1128
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1129
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1128
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1129
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1130 1130
         echo '</div>';
1131 1131
     }
1132 1132
 
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
         $this->_set_model_object($post->ID, true);
1214 1214
 
1215 1215
         //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1216
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1216
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1217 1217
 
1218 1218
         return EE_Admin_Page::add_query_args_and_nonce(
1219 1219
             array(
@@ -1324,39 +1324,39 @@  discard block
 block discarded – undo
1324 1324
             1 => sprintf(
1325 1325
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1326 1326
                 $this->_cpt_object->labels->singular_name,
1327
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1327
+                '<a href="'.esc_url(get_permalink($id)).'">',
1328 1328
                 '</a>'
1329 1329
             ),
1330 1330
             2 => __('Custom field updated'),
1331 1331
             3 => __('Custom field deleted.'),
1332 1332
             4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1333 1333
             5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1334
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1334
+                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false))
1335 1335
                 : false,
1336 1336
             6 => sprintf(
1337 1337
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1338 1338
                 $this->_cpt_object->labels->singular_name,
1339
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1339
+                '<a href="'.esc_url(get_permalink($id)).'">',
1340 1340
                 '</a>'
1341 1341
             ),
1342 1342
             7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1343 1343
             8 => sprintf(
1344 1344
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1345 1345
                 $this->_cpt_object->labels->singular_name,
1346
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1346
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1347 1347
                 '</a>'
1348 1348
             ),
1349 1349
             9 => sprintf(
1350 1350
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1351 1351
                 $this->_cpt_object->labels->singular_name,
1352
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1353
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1352
+                '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>',
1353
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1354 1354
                 '</a>'
1355 1355
             ),
1356 1356
             10 => sprintf(
1357 1357
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1358 1358
                 $this->_cpt_object->labels->singular_name,
1359
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1359
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1360 1360
                 '</a>'
1361 1361
             ),
1362 1362
         );
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1387 1387
         //modify the default editor title field with default title.
1388 1388
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1389
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1389
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1390 1390
     }
1391 1391
 
1392 1392
 
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1454 1454
         //modify the default editor title field with default title.
1455 1455
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1456
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1456
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1457 1457
     }
1458 1458
 
1459 1459
 
Please login to merge, or discard this patch.