Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
105:07 queued 90:18
created
core/db_models/EEM_Message.model.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
             self::priority_low    => __('low', 'event_espresso'),
128 128
         );
129 129
 
130
-        $this->_fields          = array(
130
+        $this->_fields = array(
131 131
             'Message' => array(
132 132
                 'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')),
133 133
                 'MSG_token'          => new EE_Plain_Text_Field('MSG_token',
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
                         );
358 358
                         break;
359 359
                     default :
360
-                        $query_params[0]['AND**filter_by']['OR**filter_by_' . $request_key][$model_name . '.' . $request_key] = $request_value;
360
+                        $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value;
361 361
                         break;
362 362
                 }
363 363
             }
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
             //prepend to the last element of $label_parts an "and".
421 421
             if (count($label_parts) > 1) {
422 422
                 $label_parts_index_to_prepend               = count($label_parts) - 1;
423
-                $label_parts[$label_parts_index_to_prepend] = 'and' . $label_parts[$label_parts_index_to_prepend];
423
+                $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend];
424 424
             }
425 425
 
426 426
             $pretty_label .= sprintf(
@@ -541,13 +541,13 @@  discard block
 block discarded – undo
541 541
             )
542 542
         );
543 543
 
544
-        if(! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
544
+        if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
545 545
             global $wpdb;
546 546
             $number_deleted = $wpdb->query('
547 547
                 DELETE
548
-                FROM ' . $this->table() . '
548
+                FROM ' . $this->table().'
549 549
                 WHERE
550
-                    MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
550
+                    MSG_ID IN (' . implode(",", $message_ids_to_delete).')
551 551
             ');
552 552
         }
553 553
 
Please login to merge, or discard this patch.
Indentation   +542 added lines, -542 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
 /**
@@ -12,556 +12,556 @@  discard block
 block discarded – undo
12 12
 class EEM_Message extends EEM_Base implements EEI_Query_Filter
13 13
 {
14 14
 
15
-    // private instance of the Message object
16
-    protected static $_instance = null;
15
+	// private instance of the Message object
16
+	protected static $_instance = null;
17 17
 
18 18
 
19
-    /**
20
-     * This priority indicates a message should be generated and sent ASAP
21
-     *
22
-     * @type int
23
-     */
24
-    const priority_high = 10;
19
+	/**
20
+	 * This priority indicates a message should be generated and sent ASAP
21
+	 *
22
+	 * @type int
23
+	 */
24
+	const priority_high = 10;
25 25
 
26 26
 
27
-    /**
28
-     * This priority indicates a message should be generated ASAP and queued for sending.
29
-     *
30
-     * @type
31
-     */
32
-    const priority_medium = 20;
33
-
34
-
35
-    /**
36
-     * This priority indicates a message should be queued for generating.
37
-     *
38
-     * @type int
39
-     */
40
-    const priority_low = 30;
41
-
42
-
43
-    /**
44
-     * indicates this message was sent at the time modified
45
-     */
46
-    const status_sent = 'MSN';
47
-
48
-
49
-    /**
50
-     * indicates this message is waiting to be sent
51
-     */
52
-    const status_idle = 'MID';
53
-
54
-
55
-    /**
56
-     * indicates an attempt was a made to send this message
57
-     * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
58
-     * appear to the end user.
59
-     */
60
-    const status_failed = 'MFL';
61
-
62
-
63
-    /**
64
-     * indicates the message has been flagged for resending (at the time modified).
65
-     */
66
-    const status_resend = 'MRS';
67
-
68
-
69
-    /**
70
-     * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
71
-     * this status when added to the queue.
72
-     */
73
-    const status_incomplete = 'MIC';
74
-
75
-
76
-    /**
77
-     * Indicates everything was generated fine for the message, however, the messenger was unable to send.
78
-     * This status means that its possible to retry sending the message.
79
-     */
80
-    const status_retry = 'MRT';
81
-
82
-
83
-    /**
84
-     * This is used for more informational messages that may not indicate anything is broken but still cannot be
85
-     * generated or sent correctly. An example of a message that would get flagged this way would be when a not
86
-     * approved message was queued for generation, but at time of generation, the attached registration(s) are
87
-     * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
88
-     * in the db and be viewable in the message activity list table when the messages system is in debug mode.
89
-     *
90
-     * @see EEM_Message::debug()
91
-     */
92
-    const status_debug_only = 'MDO';
93
-
94
-
95
-    /**
96
-     * This status is given to messages it is processed by the messenger send method.
97
-     * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
98
-     * indicative of a PHP timeout or memory limit issue.
99
-     */
100
-    const status_messenger_executing = 'MEX';
101
-
102
-
103
-    /**
104
-     *    Private constructor to prevent direct creation.
105
-     *
106
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
107
-     *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
108
-     *                         the date time model field objects.  Default is null (and will be assumed using the set
109
-     *                         timezone in the 'timezone_string' wp option)
110
-     * @return EEM_Message
111
-     */
112
-    protected function __construct($timezone = null)
113
-    {
114
-        $this->singular_item = __('Message', 'event_espresso');
115
-        $this->plural_item   = __('Messages', 'event_espresso');
116
-
117
-        //used for token generator
118
-        EE_Registry::instance()->load_helper('URL');
119
-
120
-        $this->_tables = array(
121
-            'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
122
-        );
123
-
124
-        $allowed_priority = array(
125
-            self::priority_high   => __('high', 'event_espresso'),
126
-            self::priority_medium => __('medium', 'event_espresso'),
127
-            self::priority_low    => __('low', 'event_espresso'),
128
-        );
129
-
130
-        $this->_fields          = array(
131
-            'Message' => array(
132
-                'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')),
133
-                'MSG_token'          => new EE_Plain_Text_Field('MSG_token',
134
-                    __('Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
135
-                        'event_espresso'), false, EEH_URL::generate_unique_token()),
136
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field('GRP_ID',
137
-                    __('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), true, 0,
138
-                    'Message_Template_Group'),
139
-                'TXN_ID'             => new EE_Foreign_Key_Int_Field('TXN_ID',
140
-                    __('Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
141
-                        'event_espresso'), true, 0, 'Transaction'),
142
-                'MSG_messenger'      => new EE_Plain_Text_Field('MSG_messenger',
143
-                    __('Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
144
-                        'event_espresso'), false, 'email'),
145
-                'MSG_message_type'   => new EE_Plain_Text_Field('MSG_message_type',
146
-                    __('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
147
-                    false, 'receipt'),
148
-                'MSG_context'        => new EE_Plain_Text_Field('MSG_context', __('Context', 'event_espresso'), false),
149
-                'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field('MSG_recipient_ID',
150
-                    __('Recipient ID', 'event_espresso'), true, null, array('Registration', 'Attendee', 'WP_User')),
151
-                'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field('MSG_recipient_type',
152
-                    __('Recipient Type', 'event_espresso'), true, null, array('Registration', 'Attendee', 'WP_User')),
153
-                'MSG_content'        => new EE_Maybe_Serialized_Text_Field('MSG_content',
154
-                    __('Content', 'event_espresso'), true, ''),
155
-                'MSG_to'             => new EE_Maybe_Serialized_Text_Field('MSG_to', __('Address To', 'event_espresso'),
156
-                    true),
157
-                'MSG_from'           => new EE_Maybe_Serialized_Text_Field('MSG_from',
158
-                    __('Address From', 'event_espresso'), true),
159
-                'MSG_subject'        => new EE_Maybe_Serialized_Text_Field('MSG_subject',
160
-                    __('Subject', 'event_espresso'), true, ''),
161
-                'MSG_priority'       => new EE_Enum_Integer_Field('MSG_priority', __('Priority', 'event_espresso'),
162
-                    false, self::priority_low, $allowed_priority),
163
-                'STS_ID'             => new EE_Foreign_Key_String_Field('STS_ID', __('Status', 'event_espresso'), false,
164
-                    self::status_incomplete, 'Status'),
165
-                'MSG_created'        => new EE_Datetime_Field('MSG_created', __('Created', 'event_espresso'), false,
166
-                    EE_Datetime_Field::now),
167
-                'MSG_modified'       => new EE_Datetime_Field('MSG_modified', __('Modified', 'event_espresso'), true,
168
-                    EE_Datetime_Field::now),
169
-            ),
170
-        );
171
-        $this->_model_relations = array(
172
-            'Attendee'               => new EE_Belongs_To_Any_Relation(),
173
-            'Registration'           => new EE_Belongs_To_Any_Relation(),
174
-            'WP_User'                => new EE_Belongs_To_Any_Relation(),
175
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
176
-            'Transaction'            => new EE_Belongs_To_Relation(),
177
-        );
178
-        parent::__construct($timezone);
179
-    }
180
-
181
-
182
-    /**
183
-     * @return \EE_Message
184
-     */
185
-    public function create_default_object()
186
-    {
187
-        /** @type EE_Message $message */
188
-        $message = parent::create_default_object();
189
-        if ($message instanceof EE_Message) {
190
-            return EE_Message_Factory::set_messenger_and_message_type($message);
191
-        }
192
-        return null;
193
-    }
194
-
195
-
196
-    /**
197
-     * @param mixed $cols_n_values
198
-     * @return \EE_Message
199
-     */
200
-    public function instantiate_class_from_array_or_object($cols_n_values)
201
-    {
202
-        /** @type EE_Message $message */
203
-        $message = parent::instantiate_class_from_array_or_object($cols_n_values);
204
-        if ($message instanceof EE_Message) {
205
-            return EE_Message_Factory::set_messenger_and_message_type($message);
206
-        }
207
-        return null;
208
-    }
209
-
210
-
211
-    /**
212
-     * Returns whether or not a message of that type was sent for a given attendee.
213
-     *
214
-     * @param EE_Attendee|int $attendee
215
-     * @param string          $message_type the message type slug
216
-     * @return boolean
217
-     */
218
-    public function message_sent_for_attendee($attendee, $message_type)
219
-    {
220
-        $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
221
-        return $this->exists(array(
222
-            array(
223
-                'Attendee.ATT_ID'  => $attendee_ID,
224
-                'MSG_message_type' => $message_type,
225
-                'STS_ID'           => array('IN', $this->stati_indicating_sent()),
226
-            ),
227
-        ));
228
-    }
229
-
230
-
231
-    /**
232
-     * Returns whether or not a message of that type was sent for a given registration
233
-     *
234
-     * @param EE_Registration|int $registration
235
-     * @param string              $message_type the message type slug
236
-     * @return boolean
237
-     */
238
-    public function message_sent_for_registration($registration, $message_type)
239
-    {
240
-        $registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
241
-        return $this->exists(array(
242
-            array(
243
-                'Registration.REG_ID' => $registrationID,
244
-                'MSG_message_type'    => $message_type,
245
-                'STS_ID'              => array('IN', $this->stati_indicating_sent()),
246
-            ),
247
-        ));
248
-    }
249
-
250
-
251
-    /**
252
-     * This retrieves an EE_Message object from the db matching the given token string.
253
-     *
254
-     * @param string $token
255
-     * @return EE_Message
256
-     */
257
-    public function get_one_by_token($token)
258
-    {
259
-        return $this->get_one(array(
260
-            array(
261
-                'MSG_token' => $token,
262
-            ),
263
-        ));
264
-    }
265
-
266
-
267
-    /**
268
-     * Returns stati that indicate the message HAS been sent
269
-     *
270
-     * @return array of strings for possible stati
271
-     */
272
-    public function stati_indicating_sent()
273
-    {
274
-        return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
275
-    }
276
-
277
-
278
-    /**
279
-     * Returns stati that indicate the message is waiting to be sent.
280
-     *
281
-     * @return array of strings for possible stati.
282
-     */
283
-    public function stati_indicating_to_send()
284
-    {
285
-        return apply_filters('FHEE__EEM_Message__stati_indicating_to_send',
286
-            array(self::status_idle, self::status_resend));
287
-    }
288
-
289
-
290
-    /**
291
-     * Returns stati that indicate the message has failed sending
292
-     *
293
-     * @return array  array of strings for possible stati.
294
-     */
295
-    public function stati_indicating_failed_sending()
296
-    {
297
-        $failed_stati = array(
298
-            self::status_failed,
299
-            self::status_retry,
300
-            self::status_messenger_executing,
301
-        );
302
-        //if WP_DEBUG is set, then let's include debug_only fails
303
-        if (WP_DEBUG) {
304
-            $failed_stati[] = self::status_debug_only;
305
-        }
306
-        return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
307
-    }
308
-
309
-
310
-    /**
311
-     * Returns filterable array of all EEM_Message statuses.
312
-     *
313
-     * @return array
314
-     */
315
-    public function all_statuses()
316
-    {
317
-        return apply_filters(
318
-            'FHEE__EEM_Message__all_statuses',
319
-            array(
320
-                EEM_Message::status_sent,
321
-                EEM_Message::status_incomplete,
322
-                EEM_Message::status_idle,
323
-                EEM_Message::status_resend,
324
-                EEM_Message::status_retry,
325
-                EEM_Message::status_failed,
326
-                EEM_Message::status_messenger_executing,
327
-                EEM_Message::status_debug_only,
328
-            )
329
-        );
330
-    }
331
-
332
-    /**
333
-     * Detects any specific query variables in the request and uses those to setup appropriate
334
-     * filter for any queries.
335
-     *
336
-     * @return array
337
-     */
338
-    public function filter_by_query_params()
339
-    {
340
-        // expected possible query_vars, the key in this array matches an expected key in the request,
341
-        // the value, matches the corresponding EEM_Base child reference.
342
-        $expected_vars   = $this->_expected_vars_for_query_inject();
343
-        $query_params[0] = array();
344
-        foreach ($expected_vars as $request_key => $model_name) {
345
-            $request_value = EE_Registry::instance()->REQ->get($request_key);
346
-            if ($request_value) {
347
-                //special case
348
-                switch ($request_key) {
349
-                    case '_REG_ID' :
350
-                        $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
351
-                            'Transaction.Registration.REG_ID' => $request_value,
352
-                        );
353
-                        break;
354
-                    case 'EVT_ID' :
355
-                        $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
356
-                            'Transaction.Registration.EVT_ID' => $request_value,
357
-                        );
358
-                        break;
359
-                    default :
360
-                        $query_params[0]['AND**filter_by']['OR**filter_by_' . $request_key][$model_name . '.' . $request_key] = $request_value;
361
-                        break;
362
-                }
363
-            }
364
-        }
365
-        return $query_params;
366
-    }
367
-
368
-
369
-    /**
370
-     * @return string
371
-     */
372
-    public function get_pretty_label_for_results()
373
-    {
374
-        $expected_vars = $this->_expected_vars_for_query_inject();
375
-        $pretty_label  = '';
376
-        $label_parts   = array();
377
-        foreach ($expected_vars as $request_key => $model_name) {
378
-            $model = EE_Registry::instance()->load_model($model_name);
379
-            if ($model_field_value = EE_Registry::instance()->REQ->get($request_key)) {
380
-                switch ($request_key) {
381
-                    case '_REG_ID' :
382
-                        $label_parts[] = sprintf(
383
-                            esc_html__('Registration with the ID: %s', 'event_espresso'),
384
-                            $model_field_value
385
-                        );
386
-                        break;
387
-                    case 'ATT_ID' :
388
-                        /** @var EE_Attendee $attendee */
389
-                        $attendee      = $model->get_one_by_ID($model_field_value);
390
-                        $label_parts[] = $attendee instanceof EE_Attendee
391
-                            ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
392
-                            : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
393
-                        break;
394
-                    case 'ID' :
395
-                        /** @var EE_WP_User $wpUser */
396
-                        $wpUser        = $model->get_one_by_ID($model_field_value);
397
-                        $label_parts[] = $wpUser instanceof EE_WP_User
398
-                            ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
399
-                            : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
400
-                        break;
401
-                    case 'TXN_ID' :
402
-                        $label_parts[] = sprintf(
403
-                            esc_html__('Transaction with the ID: %s', 'event_espresso'),
404
-                            $model_field_value
405
-                        );
406
-                        break;
407
-                    case 'EVT_ID' :
408
-                        /** @var EE_Event $Event */
409
-                        $Event         = $model->get_one_by_ID($model_field_value);
410
-                        $label_parts[] = $Event instanceof EE_Event
411
-                            ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
412
-                            : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
413
-                        break;
414
-                }
415
-            }
416
-        }
417
-
418
-        if ($label_parts) {
419
-
420
-            //prepend to the last element of $label_parts an "and".
421
-            if (count($label_parts) > 1) {
422
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
423
-                $label_parts[$label_parts_index_to_prepend] = 'and' . $label_parts[$label_parts_index_to_prepend];
424
-            }
425
-
426
-            $pretty_label .= sprintf(
427
-                esc_html_x(
428
-                    'Showing messages for %s',
429
-                    'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
430
-                    'event_espresso'
431
-                ),
432
-                implode(', ', $label_parts)
433
-            );
434
-        }
435
-        return $pretty_label;
436
-    }
437
-
438
-
439
-    /**
440
-     * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
441
-     * The array is in the format:
442
-     * array(
443
-     *  {$field_name} => {$model_name}
444
-     * );
445
-     *
446
-     * @since 4.9.0
447
-     * @return array
448
-     */
449
-    protected function _expected_vars_for_query_inject()
450
-    {
451
-        return array(
452
-            '_REG_ID' => 'Registration',
453
-            'ATT_ID'  => 'Attendee',
454
-            'ID'      => 'WP_User',
455
-            'TXN_ID'  => 'Transaction',
456
-            'EVT_ID'  => 'Event',
457
-        );
458
-    }
459
-
460
-
461
-    /**
462
-     * This returns whether EEM_Message is in debug mode or not.
463
-     * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
464
-     * generating/sending messages. Debug mode can be set by either:
465
-     * 1. Sending in a value for the $set_debug argument
466
-     * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
467
-     * 3. Overriding the above via the provided filter.
468
-     *
469
-     * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
470
-     *                                  provided boolean. When no argument is provided (default null) then the debug
471
-     *                                  mode will be returned.
472
-     * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
473
-     */
474
-    public static function debug($set_debug = null)
475
-    {
476
-        static $is_debugging = null;
477
-
478
-        //initialize (use constant if set).
479
-        if (is_null($set_debug) && is_null($is_debugging)) {
480
-            $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
481
-        }
482
-
483
-        if ( ! is_null($set_debug)) {
484
-            $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
485
-        }
486
-
487
-        //return filtered value
488
-        return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
489
-    }
490
-
491
-
492
-    /**
493
-     * Deletes old messages meeting certain criteria for removal from the database.
494
-     * By default, this will delete messages that:
495
-     * - are older than the value of the delete_threshold in months.
496
-     * - have a STS_ID other than EEM_Message::status_idle
497
-     *
498
-     * @param int $delete_threshold  This integer will be used to set the boundary for what messages are deleted in months.
499
-     * @return bool|false|int Either the number of records affected or false if there was an error (you can call
500
-     *                         $wpdb->last_error to find out what the error was.
501
-     */
502
-    public function delete_old_messages($delete_threshold = 6)
503
-    {
504
-        $number_deleted = 0;
505
-        /**
506
-         * Allows code to change the boundary for what messages are kept.
507
-         * Uses the value of the `delete_threshold` variable by default.
508
-         *
509
-         * @param int $seconds seconds that will be subtracted from the timestamp for now.
510
-         * @return int
511
-         */
512
-        $time_to_leave_alone = absint(
513
-            apply_filters(
514
-                'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
515
-                ((int) $delete_threshold) * MONTH_IN_SECONDS
516
-            )
517
-        );
518
-
519
-
520
-        /**
521
-         * Allows code to change what message stati are ignored when deleting.
522
-         * Defaults to only ignore EEM_Message::status_idle messages.
523
-         *
524
-         * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
525
-         */
526
-        $message_stati_to_keep = (array) apply_filters(
527
-            'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
528
-            array(
529
-                EEM_Message::status_idle
530
-            )
531
-        );
532
-
533
-        //first get all the ids of messages being deleted
534
-        $message_ids_to_delete = EEM_Message::instance()->get_col(
535
-            array(
536
-                0 => array(
537
-                    'STS_ID' => array('NOT_IN', $message_stati_to_keep),
538
-                    'MSG_modified' => array('<', time() - $time_to_leave_alone)
539
-                )
540
-            )
541
-        );
542
-
543
-        if(! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
544
-            global $wpdb;
545
-            $number_deleted = $wpdb->query('
27
+	/**
28
+	 * This priority indicates a message should be generated ASAP and queued for sending.
29
+	 *
30
+	 * @type
31
+	 */
32
+	const priority_medium = 20;
33
+
34
+
35
+	/**
36
+	 * This priority indicates a message should be queued for generating.
37
+	 *
38
+	 * @type int
39
+	 */
40
+	const priority_low = 30;
41
+
42
+
43
+	/**
44
+	 * indicates this message was sent at the time modified
45
+	 */
46
+	const status_sent = 'MSN';
47
+
48
+
49
+	/**
50
+	 * indicates this message is waiting to be sent
51
+	 */
52
+	const status_idle = 'MID';
53
+
54
+
55
+	/**
56
+	 * indicates an attempt was a made to send this message
57
+	 * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
58
+	 * appear to the end user.
59
+	 */
60
+	const status_failed = 'MFL';
61
+
62
+
63
+	/**
64
+	 * indicates the message has been flagged for resending (at the time modified).
65
+	 */
66
+	const status_resend = 'MRS';
67
+
68
+
69
+	/**
70
+	 * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
71
+	 * this status when added to the queue.
72
+	 */
73
+	const status_incomplete = 'MIC';
74
+
75
+
76
+	/**
77
+	 * Indicates everything was generated fine for the message, however, the messenger was unable to send.
78
+	 * This status means that its possible to retry sending the message.
79
+	 */
80
+	const status_retry = 'MRT';
81
+
82
+
83
+	/**
84
+	 * This is used for more informational messages that may not indicate anything is broken but still cannot be
85
+	 * generated or sent correctly. An example of a message that would get flagged this way would be when a not
86
+	 * approved message was queued for generation, but at time of generation, the attached registration(s) are
87
+	 * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
88
+	 * in the db and be viewable in the message activity list table when the messages system is in debug mode.
89
+	 *
90
+	 * @see EEM_Message::debug()
91
+	 */
92
+	const status_debug_only = 'MDO';
93
+
94
+
95
+	/**
96
+	 * This status is given to messages it is processed by the messenger send method.
97
+	 * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
98
+	 * indicative of a PHP timeout or memory limit issue.
99
+	 */
100
+	const status_messenger_executing = 'MEX';
101
+
102
+
103
+	/**
104
+	 *    Private constructor to prevent direct creation.
105
+	 *
106
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
107
+	 *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
108
+	 *                         the date time model field objects.  Default is null (and will be assumed using the set
109
+	 *                         timezone in the 'timezone_string' wp option)
110
+	 * @return EEM_Message
111
+	 */
112
+	protected function __construct($timezone = null)
113
+	{
114
+		$this->singular_item = __('Message', 'event_espresso');
115
+		$this->plural_item   = __('Messages', 'event_espresso');
116
+
117
+		//used for token generator
118
+		EE_Registry::instance()->load_helper('URL');
119
+
120
+		$this->_tables = array(
121
+			'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
122
+		);
123
+
124
+		$allowed_priority = array(
125
+			self::priority_high   => __('high', 'event_espresso'),
126
+			self::priority_medium => __('medium', 'event_espresso'),
127
+			self::priority_low    => __('low', 'event_espresso'),
128
+		);
129
+
130
+		$this->_fields          = array(
131
+			'Message' => array(
132
+				'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')),
133
+				'MSG_token'          => new EE_Plain_Text_Field('MSG_token',
134
+					__('Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
135
+						'event_espresso'), false, EEH_URL::generate_unique_token()),
136
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field('GRP_ID',
137
+					__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), true, 0,
138
+					'Message_Template_Group'),
139
+				'TXN_ID'             => new EE_Foreign_Key_Int_Field('TXN_ID',
140
+					__('Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
141
+						'event_espresso'), true, 0, 'Transaction'),
142
+				'MSG_messenger'      => new EE_Plain_Text_Field('MSG_messenger',
143
+					__('Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
144
+						'event_espresso'), false, 'email'),
145
+				'MSG_message_type'   => new EE_Plain_Text_Field('MSG_message_type',
146
+					__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
147
+					false, 'receipt'),
148
+				'MSG_context'        => new EE_Plain_Text_Field('MSG_context', __('Context', 'event_espresso'), false),
149
+				'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field('MSG_recipient_ID',
150
+					__('Recipient ID', 'event_espresso'), true, null, array('Registration', 'Attendee', 'WP_User')),
151
+				'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field('MSG_recipient_type',
152
+					__('Recipient Type', 'event_espresso'), true, null, array('Registration', 'Attendee', 'WP_User')),
153
+				'MSG_content'        => new EE_Maybe_Serialized_Text_Field('MSG_content',
154
+					__('Content', 'event_espresso'), true, ''),
155
+				'MSG_to'             => new EE_Maybe_Serialized_Text_Field('MSG_to', __('Address To', 'event_espresso'),
156
+					true),
157
+				'MSG_from'           => new EE_Maybe_Serialized_Text_Field('MSG_from',
158
+					__('Address From', 'event_espresso'), true),
159
+				'MSG_subject'        => new EE_Maybe_Serialized_Text_Field('MSG_subject',
160
+					__('Subject', 'event_espresso'), true, ''),
161
+				'MSG_priority'       => new EE_Enum_Integer_Field('MSG_priority', __('Priority', 'event_espresso'),
162
+					false, self::priority_low, $allowed_priority),
163
+				'STS_ID'             => new EE_Foreign_Key_String_Field('STS_ID', __('Status', 'event_espresso'), false,
164
+					self::status_incomplete, 'Status'),
165
+				'MSG_created'        => new EE_Datetime_Field('MSG_created', __('Created', 'event_espresso'), false,
166
+					EE_Datetime_Field::now),
167
+				'MSG_modified'       => new EE_Datetime_Field('MSG_modified', __('Modified', 'event_espresso'), true,
168
+					EE_Datetime_Field::now),
169
+			),
170
+		);
171
+		$this->_model_relations = array(
172
+			'Attendee'               => new EE_Belongs_To_Any_Relation(),
173
+			'Registration'           => new EE_Belongs_To_Any_Relation(),
174
+			'WP_User'                => new EE_Belongs_To_Any_Relation(),
175
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
176
+			'Transaction'            => new EE_Belongs_To_Relation(),
177
+		);
178
+		parent::__construct($timezone);
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return \EE_Message
184
+	 */
185
+	public function create_default_object()
186
+	{
187
+		/** @type EE_Message $message */
188
+		$message = parent::create_default_object();
189
+		if ($message instanceof EE_Message) {
190
+			return EE_Message_Factory::set_messenger_and_message_type($message);
191
+		}
192
+		return null;
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param mixed $cols_n_values
198
+	 * @return \EE_Message
199
+	 */
200
+	public function instantiate_class_from_array_or_object($cols_n_values)
201
+	{
202
+		/** @type EE_Message $message */
203
+		$message = parent::instantiate_class_from_array_or_object($cols_n_values);
204
+		if ($message instanceof EE_Message) {
205
+			return EE_Message_Factory::set_messenger_and_message_type($message);
206
+		}
207
+		return null;
208
+	}
209
+
210
+
211
+	/**
212
+	 * Returns whether or not a message of that type was sent for a given attendee.
213
+	 *
214
+	 * @param EE_Attendee|int $attendee
215
+	 * @param string          $message_type the message type slug
216
+	 * @return boolean
217
+	 */
218
+	public function message_sent_for_attendee($attendee, $message_type)
219
+	{
220
+		$attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
221
+		return $this->exists(array(
222
+			array(
223
+				'Attendee.ATT_ID'  => $attendee_ID,
224
+				'MSG_message_type' => $message_type,
225
+				'STS_ID'           => array('IN', $this->stati_indicating_sent()),
226
+			),
227
+		));
228
+	}
229
+
230
+
231
+	/**
232
+	 * Returns whether or not a message of that type was sent for a given registration
233
+	 *
234
+	 * @param EE_Registration|int $registration
235
+	 * @param string              $message_type the message type slug
236
+	 * @return boolean
237
+	 */
238
+	public function message_sent_for_registration($registration, $message_type)
239
+	{
240
+		$registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
241
+		return $this->exists(array(
242
+			array(
243
+				'Registration.REG_ID' => $registrationID,
244
+				'MSG_message_type'    => $message_type,
245
+				'STS_ID'              => array('IN', $this->stati_indicating_sent()),
246
+			),
247
+		));
248
+	}
249
+
250
+
251
+	/**
252
+	 * This retrieves an EE_Message object from the db matching the given token string.
253
+	 *
254
+	 * @param string $token
255
+	 * @return EE_Message
256
+	 */
257
+	public function get_one_by_token($token)
258
+	{
259
+		return $this->get_one(array(
260
+			array(
261
+				'MSG_token' => $token,
262
+			),
263
+		));
264
+	}
265
+
266
+
267
+	/**
268
+	 * Returns stati that indicate the message HAS been sent
269
+	 *
270
+	 * @return array of strings for possible stati
271
+	 */
272
+	public function stati_indicating_sent()
273
+	{
274
+		return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
275
+	}
276
+
277
+
278
+	/**
279
+	 * Returns stati that indicate the message is waiting to be sent.
280
+	 *
281
+	 * @return array of strings for possible stati.
282
+	 */
283
+	public function stati_indicating_to_send()
284
+	{
285
+		return apply_filters('FHEE__EEM_Message__stati_indicating_to_send',
286
+			array(self::status_idle, self::status_resend));
287
+	}
288
+
289
+
290
+	/**
291
+	 * Returns stati that indicate the message has failed sending
292
+	 *
293
+	 * @return array  array of strings for possible stati.
294
+	 */
295
+	public function stati_indicating_failed_sending()
296
+	{
297
+		$failed_stati = array(
298
+			self::status_failed,
299
+			self::status_retry,
300
+			self::status_messenger_executing,
301
+		);
302
+		//if WP_DEBUG is set, then let's include debug_only fails
303
+		if (WP_DEBUG) {
304
+			$failed_stati[] = self::status_debug_only;
305
+		}
306
+		return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
307
+	}
308
+
309
+
310
+	/**
311
+	 * Returns filterable array of all EEM_Message statuses.
312
+	 *
313
+	 * @return array
314
+	 */
315
+	public function all_statuses()
316
+	{
317
+		return apply_filters(
318
+			'FHEE__EEM_Message__all_statuses',
319
+			array(
320
+				EEM_Message::status_sent,
321
+				EEM_Message::status_incomplete,
322
+				EEM_Message::status_idle,
323
+				EEM_Message::status_resend,
324
+				EEM_Message::status_retry,
325
+				EEM_Message::status_failed,
326
+				EEM_Message::status_messenger_executing,
327
+				EEM_Message::status_debug_only,
328
+			)
329
+		);
330
+	}
331
+
332
+	/**
333
+	 * Detects any specific query variables in the request and uses those to setup appropriate
334
+	 * filter for any queries.
335
+	 *
336
+	 * @return array
337
+	 */
338
+	public function filter_by_query_params()
339
+	{
340
+		// expected possible query_vars, the key in this array matches an expected key in the request,
341
+		// the value, matches the corresponding EEM_Base child reference.
342
+		$expected_vars   = $this->_expected_vars_for_query_inject();
343
+		$query_params[0] = array();
344
+		foreach ($expected_vars as $request_key => $model_name) {
345
+			$request_value = EE_Registry::instance()->REQ->get($request_key);
346
+			if ($request_value) {
347
+				//special case
348
+				switch ($request_key) {
349
+					case '_REG_ID' :
350
+						$query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
351
+							'Transaction.Registration.REG_ID' => $request_value,
352
+						);
353
+						break;
354
+					case 'EVT_ID' :
355
+						$query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
356
+							'Transaction.Registration.EVT_ID' => $request_value,
357
+						);
358
+						break;
359
+					default :
360
+						$query_params[0]['AND**filter_by']['OR**filter_by_' . $request_key][$model_name . '.' . $request_key] = $request_value;
361
+						break;
362
+				}
363
+			}
364
+		}
365
+		return $query_params;
366
+	}
367
+
368
+
369
+	/**
370
+	 * @return string
371
+	 */
372
+	public function get_pretty_label_for_results()
373
+	{
374
+		$expected_vars = $this->_expected_vars_for_query_inject();
375
+		$pretty_label  = '';
376
+		$label_parts   = array();
377
+		foreach ($expected_vars as $request_key => $model_name) {
378
+			$model = EE_Registry::instance()->load_model($model_name);
379
+			if ($model_field_value = EE_Registry::instance()->REQ->get($request_key)) {
380
+				switch ($request_key) {
381
+					case '_REG_ID' :
382
+						$label_parts[] = sprintf(
383
+							esc_html__('Registration with the ID: %s', 'event_espresso'),
384
+							$model_field_value
385
+						);
386
+						break;
387
+					case 'ATT_ID' :
388
+						/** @var EE_Attendee $attendee */
389
+						$attendee      = $model->get_one_by_ID($model_field_value);
390
+						$label_parts[] = $attendee instanceof EE_Attendee
391
+							? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
392
+							: sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
393
+						break;
394
+					case 'ID' :
395
+						/** @var EE_WP_User $wpUser */
396
+						$wpUser        = $model->get_one_by_ID($model_field_value);
397
+						$label_parts[] = $wpUser instanceof EE_WP_User
398
+							? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
399
+							: sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
400
+						break;
401
+					case 'TXN_ID' :
402
+						$label_parts[] = sprintf(
403
+							esc_html__('Transaction with the ID: %s', 'event_espresso'),
404
+							$model_field_value
405
+						);
406
+						break;
407
+					case 'EVT_ID' :
408
+						/** @var EE_Event $Event */
409
+						$Event         = $model->get_one_by_ID($model_field_value);
410
+						$label_parts[] = $Event instanceof EE_Event
411
+							? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
412
+							: sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
413
+						break;
414
+				}
415
+			}
416
+		}
417
+
418
+		if ($label_parts) {
419
+
420
+			//prepend to the last element of $label_parts an "and".
421
+			if (count($label_parts) > 1) {
422
+				$label_parts_index_to_prepend               = count($label_parts) - 1;
423
+				$label_parts[$label_parts_index_to_prepend] = 'and' . $label_parts[$label_parts_index_to_prepend];
424
+			}
425
+
426
+			$pretty_label .= sprintf(
427
+				esc_html_x(
428
+					'Showing messages for %s',
429
+					'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
430
+					'event_espresso'
431
+				),
432
+				implode(', ', $label_parts)
433
+			);
434
+		}
435
+		return $pretty_label;
436
+	}
437
+
438
+
439
+	/**
440
+	 * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
441
+	 * The array is in the format:
442
+	 * array(
443
+	 *  {$field_name} => {$model_name}
444
+	 * );
445
+	 *
446
+	 * @since 4.9.0
447
+	 * @return array
448
+	 */
449
+	protected function _expected_vars_for_query_inject()
450
+	{
451
+		return array(
452
+			'_REG_ID' => 'Registration',
453
+			'ATT_ID'  => 'Attendee',
454
+			'ID'      => 'WP_User',
455
+			'TXN_ID'  => 'Transaction',
456
+			'EVT_ID'  => 'Event',
457
+		);
458
+	}
459
+
460
+
461
+	/**
462
+	 * This returns whether EEM_Message is in debug mode or not.
463
+	 * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
464
+	 * generating/sending messages. Debug mode can be set by either:
465
+	 * 1. Sending in a value for the $set_debug argument
466
+	 * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
467
+	 * 3. Overriding the above via the provided filter.
468
+	 *
469
+	 * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
470
+	 *                                  provided boolean. When no argument is provided (default null) then the debug
471
+	 *                                  mode will be returned.
472
+	 * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
473
+	 */
474
+	public static function debug($set_debug = null)
475
+	{
476
+		static $is_debugging = null;
477
+
478
+		//initialize (use constant if set).
479
+		if (is_null($set_debug) && is_null($is_debugging)) {
480
+			$is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
481
+		}
482
+
483
+		if ( ! is_null($set_debug)) {
484
+			$is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
485
+		}
486
+
487
+		//return filtered value
488
+		return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
489
+	}
490
+
491
+
492
+	/**
493
+	 * Deletes old messages meeting certain criteria for removal from the database.
494
+	 * By default, this will delete messages that:
495
+	 * - are older than the value of the delete_threshold in months.
496
+	 * - have a STS_ID other than EEM_Message::status_idle
497
+	 *
498
+	 * @param int $delete_threshold  This integer will be used to set the boundary for what messages are deleted in months.
499
+	 * @return bool|false|int Either the number of records affected or false if there was an error (you can call
500
+	 *                         $wpdb->last_error to find out what the error was.
501
+	 */
502
+	public function delete_old_messages($delete_threshold = 6)
503
+	{
504
+		$number_deleted = 0;
505
+		/**
506
+		 * Allows code to change the boundary for what messages are kept.
507
+		 * Uses the value of the `delete_threshold` variable by default.
508
+		 *
509
+		 * @param int $seconds seconds that will be subtracted from the timestamp for now.
510
+		 * @return int
511
+		 */
512
+		$time_to_leave_alone = absint(
513
+			apply_filters(
514
+				'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
515
+				((int) $delete_threshold) * MONTH_IN_SECONDS
516
+			)
517
+		);
518
+
519
+
520
+		/**
521
+		 * Allows code to change what message stati are ignored when deleting.
522
+		 * Defaults to only ignore EEM_Message::status_idle messages.
523
+		 *
524
+		 * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
525
+		 */
526
+		$message_stati_to_keep = (array) apply_filters(
527
+			'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
528
+			array(
529
+				EEM_Message::status_idle
530
+			)
531
+		);
532
+
533
+		//first get all the ids of messages being deleted
534
+		$message_ids_to_delete = EEM_Message::instance()->get_col(
535
+			array(
536
+				0 => array(
537
+					'STS_ID' => array('NOT_IN', $message_stati_to_keep),
538
+					'MSG_modified' => array('<', time() - $time_to_leave_alone)
539
+				)
540
+			)
541
+		);
542
+
543
+		if(! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
544
+			global $wpdb;
545
+			$number_deleted = $wpdb->query('
546 546
                 DELETE
547 547
                 FROM ' . $this->table() . '
548 548
                 WHERE
549 549
                     MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
550 550
             ');
551
-        }
552
-
553
-        /**
554
-         * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
555
-         * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
556
-         * below.
557
-         */
558
-        if ($number_deleted !== false) {
559
-            do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
560
-        } else {
561
-            do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
562
-        }
563
-        return $number_deleted;
564
-    }
551
+		}
552
+
553
+		/**
554
+		 * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
555
+		 * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
556
+		 * below.
557
+		 */
558
+		if ($number_deleted !== false) {
559
+			do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
560
+		} else {
561
+			do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
562
+		}
563
+		return $number_deleted;
564
+	}
565 565
 
566 566
 }
567 567
 // End of file EEM_Message.model.php
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Scheduler.lib.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -12,199 +12,199 @@
 block discarded – undo
12 12
 class EE_Messages_Scheduler extends EE_Base
13 13
 {
14 14
 
15
-    /**
16
-     * Number of seconds between batch sends/generates on the cron job.
17
-     * Defaults to 5 minutes in seconds.  If you want to change this interval, you can use the native WordPress
18
-     * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added.
19
-     *
20
-     * @type int
21
-     */
22
-    const message_cron_schedule = 300;
23
-
24
-    /**
25
-     * Constructor
26
-     */
27
-    public function __construct()
28
-    {
29
-        //register tasks (and make sure only registered once).
30
-        if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) {
31
-            add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10);
32
-        }
33
-
34
-        //register callbacks for scheduled events (but make sure they are set only once).
35
-        if (! has_action(
36
-            'AHEE__EE_Messages_Scheduler__generation',
37
-            array('EE_Messages_Scheduler', 'batch_generation')
38
-        )) {
39
-            add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation'));
40
-            add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending'));
41
-            add_action('AHEE__EE_Messages_Scheduler__cleanup', array('EE_Messages_Scheduler', 'cleanup'));
42
-        }
43
-
44
-        //add custom schedules
45
-        add_filter('cron_schedules', array($this, 'custom_schedules'));
46
-    }
47
-
48
-
49
-    /**
50
-     * Add custom schedules for wp_cron
51
-     *
52
-     * @param $schedules
53
-     */
54
-    public function custom_schedules($schedules)
55
-    {
56
-        $schedules['ee_message_cron'] = array(
57
-            'interval' => self::message_cron_schedule,
58
-            'display'  => __(
59
-                'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)',
60
-                'event_espresso'
61
-            ),
62
-        );
63
-        return $schedules;
64
-    }
65
-
66
-
67
-    /**
68
-     * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and
69
-     * remove.
70
-     *
71
-     * @param array $tasks already existing scheduled tasks
72
-     * @return array
73
-     */
74
-    public function register_scheduled_tasks($tasks)
75
-    {
76
-        EE_Registry::instance()->load_helper('DTT_Helper');
77
-        $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
78
-        $tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
79
-        $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily');
80
-        return $tasks;
81
-    }
82
-
83
-
84
-    /**
85
-     * This initiates a non-blocking separate request to execute on a scheduled task.
86
-     * Note: The EED_Messages module has the handlers for these requests.
87
-     *
88
-     * @param string $task The task the request is being generated for.
89
-     */
90
-    public static function initiate_scheduled_non_blocking_request($task)
91
-    {
92
-        if (apply_filters(
93
-            'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
94
-            true
95
-        )) {
96
-            $request_url  = add_query_arg(
97
-                array_merge(
98
-                    array('ee' => 'msg_cron_trigger'),
99
-                    EE_Messages_Scheduler::get_request_params($task)
100
-                ),
101
-                site_url()
102
-            );
103
-            $request_args = array(
104
-                'timeout'     => 300,
105
-                'blocking'    => (defined('DOING_CRON') && DOING_CRON) || (defined('DOING_AJAX') && DOING_AJAX) ? true : false,
106
-                'sslverify'   => false,
107
-                'redirection' => 10,
108
-            );
109
-            $response     = wp_remote_get($request_url, $request_args);
110
-            if (is_wp_error($response)) {
111
-                trigger_error($response->get_error_message());
112
-            }
113
-        } else {
114
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron($task);
115
-        }
116
-    }
117
-
118
-
119
-    /**
120
-     * This returns
121
-     * the request params used for a scheduled message task request.
122
-     *
123
-     * @param string $task The task the request is for.
124
-     * @return array
125
-     */
126
-    public static function get_request_params($task)
127
-    {
128
-        //transient is used for flood control on msg_cron_trigger requests
129
-        $transient_key = 'ee_trans_' . uniqid($task);
130
-        set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
131
-        return array(
132
-            'type' => $task,
133
-            'key'  => $transient_key,
134
-        );
135
-    }
136
-
137
-
138
-    /**
139
-     * This is used to execute an immediate call to the run_cron task performed by EED_Messages
140
-     *
141
-     * @param string $task The task the request is being generated for.
142
-     */
143
-    public static function initiate_immediate_request_on_cron($task)
144
-    {
145
-        $request_args = EE_Messages_Scheduler::get_request_params($task);
146
-        //set those request args in the request so it gets picked up
147
-        foreach ($request_args as $request_key => $request_value) {
148
-            EE_Registry::instance()->REQ->set($request_key, $request_value);
149
-        }
150
-        EED_Messages::instance()->run_cron();
151
-    }
152
-
153
-
154
-    /**
155
-     * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event
156
-     */
157
-    public static function batch_generation()
158
-    {
159
-        /**
160
-         * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
161
-         */
162
-        if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
163
-            || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
164
-        ) {
165
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
166
-        }
167
-    }
168
-
169
-
170
-    /**
171
-     * Callback for scheduled AHEE__EE_Messages_Scheduler__sending
172
-     */
173
-    public static function batch_sending()
174
-    {
175
-        /**
176
-         * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
177
-         */
178
-        if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
179
-            || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
180
-        ) {
181
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
182
-        }
183
-    }
184
-
185
-
186
-    /**
187
-     * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action.
188
-     * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete permanently
189
-     * from the database messages that have a MSG_modified date older than 30 days.
190
-     */
191
-    public static function cleanup()
192
-    {
193
-        //first check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
194
-        //until the next scheduled event.
195
-        if (! EE_Registry::instance()->CFG->messages->delete_threshold
196
-            || ! EE_Maintenance_Mode::instance()->models_can_query()
197
-        ) {
198
-            return;
199
-        }
200
-
201
-        /**
202
-         * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling
203
-         * of deleting messages.
204
-         */
205
-        if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) {
206
-            EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold);
207
-        }
208
-    }
15
+	/**
16
+	 * Number of seconds between batch sends/generates on the cron job.
17
+	 * Defaults to 5 minutes in seconds.  If you want to change this interval, you can use the native WordPress
18
+	 * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added.
19
+	 *
20
+	 * @type int
21
+	 */
22
+	const message_cron_schedule = 300;
23
+
24
+	/**
25
+	 * Constructor
26
+	 */
27
+	public function __construct()
28
+	{
29
+		//register tasks (and make sure only registered once).
30
+		if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) {
31
+			add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10);
32
+		}
33
+
34
+		//register callbacks for scheduled events (but make sure they are set only once).
35
+		if (! has_action(
36
+			'AHEE__EE_Messages_Scheduler__generation',
37
+			array('EE_Messages_Scheduler', 'batch_generation')
38
+		)) {
39
+			add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation'));
40
+			add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending'));
41
+			add_action('AHEE__EE_Messages_Scheduler__cleanup', array('EE_Messages_Scheduler', 'cleanup'));
42
+		}
43
+
44
+		//add custom schedules
45
+		add_filter('cron_schedules', array($this, 'custom_schedules'));
46
+	}
47
+
48
+
49
+	/**
50
+	 * Add custom schedules for wp_cron
51
+	 *
52
+	 * @param $schedules
53
+	 */
54
+	public function custom_schedules($schedules)
55
+	{
56
+		$schedules['ee_message_cron'] = array(
57
+			'interval' => self::message_cron_schedule,
58
+			'display'  => __(
59
+				'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)',
60
+				'event_espresso'
61
+			),
62
+		);
63
+		return $schedules;
64
+	}
65
+
66
+
67
+	/**
68
+	 * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and
69
+	 * remove.
70
+	 *
71
+	 * @param array $tasks already existing scheduled tasks
72
+	 * @return array
73
+	 */
74
+	public function register_scheduled_tasks($tasks)
75
+	{
76
+		EE_Registry::instance()->load_helper('DTT_Helper');
77
+		$tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
78
+		$tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
79
+		$tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily');
80
+		return $tasks;
81
+	}
82
+
83
+
84
+	/**
85
+	 * This initiates a non-blocking separate request to execute on a scheduled task.
86
+	 * Note: The EED_Messages module has the handlers for these requests.
87
+	 *
88
+	 * @param string $task The task the request is being generated for.
89
+	 */
90
+	public static function initiate_scheduled_non_blocking_request($task)
91
+	{
92
+		if (apply_filters(
93
+			'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
94
+			true
95
+		)) {
96
+			$request_url  = add_query_arg(
97
+				array_merge(
98
+					array('ee' => 'msg_cron_trigger'),
99
+					EE_Messages_Scheduler::get_request_params($task)
100
+				),
101
+				site_url()
102
+			);
103
+			$request_args = array(
104
+				'timeout'     => 300,
105
+				'blocking'    => (defined('DOING_CRON') && DOING_CRON) || (defined('DOING_AJAX') && DOING_AJAX) ? true : false,
106
+				'sslverify'   => false,
107
+				'redirection' => 10,
108
+			);
109
+			$response     = wp_remote_get($request_url, $request_args);
110
+			if (is_wp_error($response)) {
111
+				trigger_error($response->get_error_message());
112
+			}
113
+		} else {
114
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron($task);
115
+		}
116
+	}
117
+
118
+
119
+	/**
120
+	 * This returns
121
+	 * the request params used for a scheduled message task request.
122
+	 *
123
+	 * @param string $task The task the request is for.
124
+	 * @return array
125
+	 */
126
+	public static function get_request_params($task)
127
+	{
128
+		//transient is used for flood control on msg_cron_trigger requests
129
+		$transient_key = 'ee_trans_' . uniqid($task);
130
+		set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
131
+		return array(
132
+			'type' => $task,
133
+			'key'  => $transient_key,
134
+		);
135
+	}
136
+
137
+
138
+	/**
139
+	 * This is used to execute an immediate call to the run_cron task performed by EED_Messages
140
+	 *
141
+	 * @param string $task The task the request is being generated for.
142
+	 */
143
+	public static function initiate_immediate_request_on_cron($task)
144
+	{
145
+		$request_args = EE_Messages_Scheduler::get_request_params($task);
146
+		//set those request args in the request so it gets picked up
147
+		foreach ($request_args as $request_key => $request_value) {
148
+			EE_Registry::instance()->REQ->set($request_key, $request_value);
149
+		}
150
+		EED_Messages::instance()->run_cron();
151
+	}
152
+
153
+
154
+	/**
155
+	 * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event
156
+	 */
157
+	public static function batch_generation()
158
+	{
159
+		/**
160
+		 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
161
+		 */
162
+		if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
163
+			|| ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
164
+		) {
165
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
166
+		}
167
+	}
168
+
169
+
170
+	/**
171
+	 * Callback for scheduled AHEE__EE_Messages_Scheduler__sending
172
+	 */
173
+	public static function batch_sending()
174
+	{
175
+		/**
176
+		 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
177
+		 */
178
+		if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
179
+			|| ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
180
+		) {
181
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
182
+		}
183
+	}
184
+
185
+
186
+	/**
187
+	 * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action.
188
+	 * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete permanently
189
+	 * from the database messages that have a MSG_modified date older than 30 days.
190
+	 */
191
+	public static function cleanup()
192
+	{
193
+		//first check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
194
+		//until the next scheduled event.
195
+		if (! EE_Registry::instance()->CFG->messages->delete_threshold
196
+			|| ! EE_Maintenance_Mode::instance()->models_can_query()
197
+		) {
198
+			return;
199
+		}
200
+
201
+		/**
202
+		 * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling
203
+		 * of deleting messages.
204
+		 */
205
+		if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) {
206
+			EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold);
207
+		}
208
+	}
209 209
 
210 210
 } //end EE_Messages_Scheduler
211 211
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@  discard block
 block discarded – undo
27 27
     public function __construct()
28 28
     {
29 29
         //register tasks (and make sure only registered once).
30
-        if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) {
30
+        if ( ! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) {
31 31
             add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10);
32 32
         }
33 33
 
34 34
         //register callbacks for scheduled events (but make sure they are set only once).
35
-        if (! has_action(
35
+        if ( ! has_action(
36 36
             'AHEE__EE_Messages_Scheduler__generation',
37 37
             array('EE_Messages_Scheduler', 'batch_generation')
38 38
         )) {
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         EE_Registry::instance()->load_helper('DTT_Helper');
77 77
         $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
78 78
         $tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
79
-        $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily');
79
+        $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array(EEH_DTT_Helper::tomorrow(), 'daily');
80 80
         return $tasks;
81 81
     }
82 82
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
             'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
94 94
             true
95 95
         )) {
96
-            $request_url  = add_query_arg(
96
+            $request_url = add_query_arg(
97 97
                 array_merge(
98 98
                     array('ee' => 'msg_cron_trigger'),
99 99
                     EE_Messages_Scheduler::get_request_params($task)
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                 'sslverify'   => false,
107 107
                 'redirection' => 10,
108 108
             );
109
-            $response     = wp_remote_get($request_url, $request_args);
109
+            $response = wp_remote_get($request_url, $request_args);
110 110
             if (is_wp_error($response)) {
111 111
                 trigger_error($response->get_error_message());
112 112
             }
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     public static function get_request_params($task)
127 127
     {
128 128
         //transient is used for flood control on msg_cron_trigger requests
129
-        $transient_key = 'ee_trans_' . uniqid($task);
129
+        $transient_key = 'ee_trans_'.uniqid($task);
130 130
         set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
131 131
         return array(
132 132
             'type' => $task,
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         /**
160 160
          * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
161 161
          */
162
-        if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
162
+        if ( ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
163 163
             || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
164 164
         ) {
165 165
             EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
         /**
176 176
          * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
177 177
          */
178
-        if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
178
+        if ( ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
179 179
             || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
180 180
         ) {
181 181
             EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     {
193 193
         //first check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
194 194
         //until the next scheduled event.
195
-        if (! EE_Registry::instance()->CFG->messages->delete_threshold
195
+        if ( ! EE_Registry::instance()->CFG->messages->delete_threshold
196 196
             || ! EE_Maintenance_Mode::instance()->models_can_query()
197 197
         ) {
198 198
             return;
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +3643 added lines, -3643 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
 /**
@@ -17,2213 +17,2213 @@  discard block
 block discarded – undo
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19 19
     
20
-    /**
21
-     * @type EE_Message_Resource_Manager $_message_resource_manager
22
-     */
23
-    protected $_message_resource_manager;
24
-    
25
-    /**
26
-     * @type string $_active_message_type_name
27
-     */
28
-    protected $_active_message_type_name = '';
29
-    
30
-    /**
31
-     * @type EE_messenger $_active_messenger
32
-     */
33
-    protected $_active_messenger;
34
-    protected $_activate_state;
35
-    protected $_activate_meta_box_type;
36
-    protected $_current_message_meta_box;
37
-    protected $_current_message_meta_box_object;
38
-    protected $_context_switcher;
39
-    protected $_shortcodes = array();
40
-    protected $_active_messengers = array();
41
-    protected $_active_message_types = array();
42
-    
43
-    /**
44
-     * @var EE_Message_Template_Group $_message_template_group
45
-     */
46
-    protected $_message_template_group;
47
-    protected $_m_mt_settings = array();
48
-    
49
-    
50
-    /**
51
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
-     * IF there is no group then it gets automatically set to the Default template pack.
53
-     *
54
-     * @since 4.5.0
55
-     *
56
-     * @var EE_Messages_Template_Pack
57
-     */
58
-    protected $_template_pack;
59
-    
60
-    
61
-    /**
62
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
-     * group is.  If there is no group then it automatically gets set to default.
64
-     *
65
-     * @since 4.5.0
66
-     *
67
-     * @var string
68
-     */
69
-    protected $_variation;
70
-    
71
-    
72
-    /**
73
-     * @param bool $routing
74
-     */
75
-    public function __construct($routing = true)
76
-    {
77
-        //make sure messages autoloader is running
78
-        EED_Messages::set_autoloaders();
79
-        parent::__construct($routing);
80
-    }
81
-    
82
-    
83
-    protected function _init_page_props()
84
-    {
85
-        $this->page_slug        = EE_MSG_PG_SLUG;
86
-        $this->page_label       = __('Messages Settings', 'event_espresso');
87
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
-        $this->_admin_base_path = EE_MSG_ADMIN;
89
-        
90
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
-        
92
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
-        $this->_load_message_resource_manager();
94
-    }
95
-    
96
-    
97
-    /**
98
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
-     *
100
-     *
101
-     * @throws EE_Error
102
-     */
103
-    protected function _load_message_resource_manager()
104
-    {
105
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
-    }
107
-    
108
-    
109
-    /**
110
-     * @deprecated 4.9.9.rc.014
111
-     * @return array
112
-     */
113
-    public function get_messengers_for_list_table()
114
-    {
115
-        EE_Error::doing_it_wrong(
116
-            __METHOD__,
117
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
20
+	/**
21
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
22
+	 */
23
+	protected $_message_resource_manager;
24
+    
25
+	/**
26
+	 * @type string $_active_message_type_name
27
+	 */
28
+	protected $_active_message_type_name = '';
29
+    
30
+	/**
31
+	 * @type EE_messenger $_active_messenger
32
+	 */
33
+	protected $_active_messenger;
34
+	protected $_activate_state;
35
+	protected $_activate_meta_box_type;
36
+	protected $_current_message_meta_box;
37
+	protected $_current_message_meta_box_object;
38
+	protected $_context_switcher;
39
+	protected $_shortcodes = array();
40
+	protected $_active_messengers = array();
41
+	protected $_active_message_types = array();
42
+    
43
+	/**
44
+	 * @var EE_Message_Template_Group $_message_template_group
45
+	 */
46
+	protected $_message_template_group;
47
+	protected $_m_mt_settings = array();
48
+    
49
+    
50
+	/**
51
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
+	 * IF there is no group then it gets automatically set to the Default template pack.
53
+	 *
54
+	 * @since 4.5.0
55
+	 *
56
+	 * @var EE_Messages_Template_Pack
57
+	 */
58
+	protected $_template_pack;
59
+    
60
+    
61
+	/**
62
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
+	 * group is.  If there is no group then it automatically gets set to default.
64
+	 *
65
+	 * @since 4.5.0
66
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $_variation;
70
+    
71
+    
72
+	/**
73
+	 * @param bool $routing
74
+	 */
75
+	public function __construct($routing = true)
76
+	{
77
+		//make sure messages autoloader is running
78
+		EED_Messages::set_autoloaders();
79
+		parent::__construct($routing);
80
+	}
81
+    
82
+    
83
+	protected function _init_page_props()
84
+	{
85
+		$this->page_slug        = EE_MSG_PG_SLUG;
86
+		$this->page_label       = __('Messages Settings', 'event_espresso');
87
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
+		$this->_admin_base_path = EE_MSG_ADMIN;
89
+        
90
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
+        
92
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
+		$this->_load_message_resource_manager();
94
+	}
95
+    
96
+    
97
+	/**
98
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
+	 *
100
+	 *
101
+	 * @throws EE_Error
102
+	 */
103
+	protected function _load_message_resource_manager()
104
+	{
105
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
+	}
107
+    
108
+    
109
+	/**
110
+	 * @deprecated 4.9.9.rc.014
111
+	 * @return array
112
+	 */
113
+	public function get_messengers_for_list_table()
114
+	{
115
+		EE_Error::doing_it_wrong(
116
+			__METHOD__,
117
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
118 118
 			values for use in creating a messenger filter dropdown which is now generated differently via
119 119
 			 Messages_Admin_Page::get_messengers_select_input', 'event_espresso'),
120
-            '4.9.9.rc.014'
121
-        );
122
-        
123
-        $m_values          = array();
124
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
-        //setup messengers for selects
126
-        $i = 1;
127
-        foreach ($active_messengers as $active_messenger) {
128
-            if ($active_messenger instanceof EE_Message) {
129
-                $m_values[$i]['id']   = $active_messenger->messenger();
130
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
-                $i++;
132
-            }
133
-        }
134
-        
135
-        return $m_values;
136
-    }
137
-    
138
-    
139
-    /**
140
-     * @deprecated 4.9.9.rc.014
141
-     * @return array
142
-     */
143
-    public function get_message_types_for_list_table()
144
-    {
145
-        EE_Error::doing_it_wrong(
146
-            __METHOD__,
147
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
120
+			'4.9.9.rc.014'
121
+		);
122
+        
123
+		$m_values          = array();
124
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
+		//setup messengers for selects
126
+		$i = 1;
127
+		foreach ($active_messengers as $active_messenger) {
128
+			if ($active_messenger instanceof EE_Message) {
129
+				$m_values[$i]['id']   = $active_messenger->messenger();
130
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
+				$i++;
132
+			}
133
+		}
134
+        
135
+		return $m_values;
136
+	}
137
+    
138
+    
139
+	/**
140
+	 * @deprecated 4.9.9.rc.014
141
+	 * @return array
142
+	 */
143
+	public function get_message_types_for_list_table()
144
+	{
145
+		EE_Error::doing_it_wrong(
146
+			__METHOD__,
147
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
148 148
 			values for use in creating a message type filter dropdown which is now generated differently via
149 149
 			 Messages_Admin_Page::get_message_types_select_input', 'event_espresso'),
150
-            '4.9.9.rc.014'
151
-        );
152
-        
153
-        $mt_values       = array();
154
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
-        $i               = 1;
156
-        foreach ($active_messages as $active_message) {
157
-            if ($active_message instanceof EE_Message) {
158
-                $mt_values[$i]['id']   = $active_message->message_type();
159
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
-                $i++;
161
-            }
162
-        }
163
-        
164
-        return $mt_values;
165
-    }
166
-    
167
-    
168
-    /**
169
-     * @deprecated 4.9.9.rc.014
170
-     * @return array
171
-     */
172
-    public function get_contexts_for_message_types_for_list_table()
173
-    {
174
-        EE_Error::doing_it_wrong(
175
-            __METHOD__,
176
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
150
+			'4.9.9.rc.014'
151
+		);
152
+        
153
+		$mt_values       = array();
154
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
+		$i               = 1;
156
+		foreach ($active_messages as $active_message) {
157
+			if ($active_message instanceof EE_Message) {
158
+				$mt_values[$i]['id']   = $active_message->message_type();
159
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
+				$i++;
161
+			}
162
+		}
163
+        
164
+		return $mt_values;
165
+	}
166
+    
167
+    
168
+	/**
169
+	 * @deprecated 4.9.9.rc.014
170
+	 * @return array
171
+	 */
172
+	public function get_contexts_for_message_types_for_list_table()
173
+	{
174
+		EE_Error::doing_it_wrong(
175
+			__METHOD__,
176
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
177 177
 			values for use in creating a message type context filter dropdown which is now generated differently via
178 178
 			 Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'),
179
-            '4.9.9.rc.014'
180
-        );
181
-        
182
-        $contexts                = array();
183
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
-        foreach ($active_message_contexts as $active_message) {
185
-            if ($active_message instanceof EE_Message) {
186
-                $message_type = $active_message->message_type_object();
187
-                if ($message_type instanceof EE_message_type) {
188
-                    $message_type_contexts = $message_type->get_contexts();
189
-                    foreach ($message_type_contexts as $context => $context_details) {
190
-                        $contexts[$context] = $context_details['label'];
191
-                    }
192
-                }
193
-            }
194
-        }
195
-        
196
-        return $contexts;
197
-    }
198
-    
199
-    
200
-    /**
201
-     * Generate select input with provided messenger options array.
202
-     *
203
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
-     *                                 labels.
205
-     *
206
-     * @return string
207
-     */
208
-    public function get_messengers_select_input($messenger_options)
209
-    {
210
-        //if empty or just one value then just return an empty string
211
-        if (empty($messenger_options)
212
-            || ! is_array($messenger_options)
213
-            || count($messenger_options) === 1
214
-        ) {
215
-            return '';
216
-        }
217
-        //merge in default
218
-        $messenger_options = array_merge(
219
-            array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
-            $messenger_options
221
-        );
222
-        $input             = new EE_Select_Input(
223
-            $messenger_options,
224
-            array(
225
-                'html_name'  => 'ee_messenger_filter_by',
226
-                'html_id'    => 'ee_messenger_filter_by',
227
-                'html_class' => 'wide',
228
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
-                    : 'none_selected'
231
-            )
232
-        );
233
-        
234
-        return $input->get_html_for_input();
235
-    }
236
-    
237
-    
238
-    /**
239
-     * Generate select input with provided message type options array.
240
-     *
241
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
-     *                                    message type labels
243
-     *
244
-     * @return string
245
-     */
246
-    public function get_message_types_select_input($message_type_options)
247
-    {
248
-        //if empty or count of options is 1 then just return an empty string
249
-        if (empty($message_type_options)
250
-            || ! is_array($message_type_options)
251
-            || count($message_type_options) === 1
252
-        ) {
253
-            return '';
254
-        }
255
-        //merge in default
256
-        $message_type_options = array_merge(
257
-            array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
-            $message_type_options
259
-        );
260
-        $input                = new EE_Select_Input(
261
-            $message_type_options,
262
-            array(
263
-                'html_name'  => 'ee_message_type_filter_by',
264
-                'html_id'    => 'ee_message_type_filter_by',
265
-                'html_class' => 'wide',
266
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
-                    : 'none_selected',
269
-            )
270
-        );
271
-        
272
-        return $input->get_html_for_input();
273
-    }
274
-    
275
-    
276
-    /**
277
-     * Generate select input with provide message type contexts array.
278
-     *
279
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
-     *                               context label.
281
-     *
282
-     * @return string
283
-     */
284
-    public function get_contexts_for_message_types_select_input($context_options)
285
-    {
286
-        //if empty or count of options is one then just return empty string
287
-        if (empty($context_options)
288
-            || ! is_array($context_options)
289
-            || count($context_options) === 1
290
-        ) {
291
-            return '';
292
-        }
293
-        //merge in default
294
-        $context_options = array_merge(
295
-            array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
-            $context_options
297
-        );
298
-        $input           = new EE_Select_Input(
299
-            $context_options,
300
-            array(
301
-                'html_name'  => 'ee_context_filter_by',
302
-                'html_id'    => 'ee_context_filter_by',
303
-                'html_class' => 'wide',
304
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
305
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
306
-                    : 'none_selected',
307
-            )
308
-        );
309
-        
310
-        return $input->get_html_for_input();
311
-    }
312
-    
313
-    
314
-    protected function _ajax_hooks()
315
-    {
316
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
-    }
322
-    
323
-    
324
-    protected function _define_page_props()
325
-    {
326
-        $this->_admin_page_title = $this->page_label;
327
-        $this->_labels           = array(
328
-            'buttons'    => array(
329
-                'add'    => __('Add New Message Template', 'event_espresso'),
330
-                'edit'   => __('Edit Message Template', 'event_espresso'),
331
-                'delete' => __('Delete Message Template', 'event_espresso')
332
-            ),
333
-            'publishbox' => __('Update Actions', 'event_espresso')
334
-        );
335
-    }
336
-    
337
-    
338
-    /**
339
-     *        an array for storing key => value pairs of request actions and their corresponding methods
340
-     * @access protected
341
-     * @return void
342
-     */
343
-    protected function _set_page_routes()
344
-    {
345
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
-            ? $this->_req_data['GRP_ID']
347
-            : 0;
348
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
-            ? $this->_req_data['id']
350
-            : $grp_id;
351
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
-            ? $this->_req_data['MSG_ID']
353
-            : 0;
354
-        
355
-        $this->_page_routes = array(
356
-            'default'                          => array(
357
-                'func'       => '_message_queue_list_table',
358
-                'capability' => 'ee_read_global_messages'
359
-            ),
360
-            'global_mtps'                      => array(
361
-                'func'       => '_ee_default_messages_overview_list_table',
362
-                'capability' => 'ee_read_global_messages'
363
-            ),
364
-            'custom_mtps'                      => array(
365
-                'func'       => '_custom_mtps_preview',
366
-                'capability' => 'ee_read_messages'
367
-            ),
368
-            'add_new_message_template'         => array(
369
-                'func'       => '_add_message_template',
370
-                'capability' => 'ee_edit_messages',
371
-                'noheader'   => true
372
-            ),
373
-            'edit_message_template'            => array(
374
-                'func'       => '_edit_message_template',
375
-                'capability' => 'ee_edit_message',
376
-                'obj_id'     => $grp_id
377
-            ),
378
-            'preview_message'                  => array(
379
-                'func'               => '_preview_message',
380
-                'capability'         => 'ee_read_message',
381
-                'obj_id'             => $grp_id,
382
-                'noheader'           => true,
383
-                'headers_sent_route' => 'display_preview_message'
384
-            ),
385
-            'display_preview_message'          => array(
386
-                'func'       => '_display_preview_message',
387
-                'capability' => 'ee_read_message',
388
-                'obj_id'     => $grp_id
389
-            ),
390
-            'insert_message_template'          => array(
391
-                'func'       => '_insert_or_update_message_template',
392
-                'capability' => 'ee_edit_messages',
393
-                'args'       => array('new_template' => true),
394
-                'noheader'   => true
395
-            ),
396
-            'update_message_template'          => array(
397
-                'func'       => '_insert_or_update_message_template',
398
-                'capability' => 'ee_edit_message',
399
-                'obj_id'     => $grp_id,
400
-                'args'       => array('new_template' => false),
401
-                'noheader'   => true
402
-            ),
403
-            'trash_message_template'           => array(
404
-                'func'       => '_trash_or_restore_message_template',
405
-                'capability' => 'ee_delete_message',
406
-                'obj_id'     => $grp_id,
407
-                'args'       => array('trash' => true, 'all' => true),
408
-                'noheader'   => true
409
-            ),
410
-            'trash_message_template_context'   => array(
411
-                'func'       => '_trash_or_restore_message_template',
412
-                'capability' => 'ee_delete_message',
413
-                'obj_id'     => $grp_id,
414
-                'args'       => array('trash' => true),
415
-                'noheader'   => true
416
-            ),
417
-            'restore_message_template'         => array(
418
-                'func'       => '_trash_or_restore_message_template',
419
-                'capability' => 'ee_delete_message',
420
-                'obj_id'     => $grp_id,
421
-                'args'       => array('trash' => false, 'all' => true),
422
-                'noheader'   => true
423
-            ),
424
-            'restore_message_template_context' => array(
425
-                'func'       => '_trash_or_restore_message_template',
426
-                'capability' => 'ee_delete_message',
427
-                'obj_id'     => $grp_id,
428
-                'args'       => array('trash' => false),
429
-                'noheader'   => true
430
-            ),
431
-            'delete_message_template'          => array(
432
-                'func'       => '_delete_message_template',
433
-                'capability' => 'ee_delete_message',
434
-                'obj_id'     => $grp_id,
435
-                'noheader'   => true
436
-            ),
437
-            'reset_to_default'                 => array(
438
-                'func'       => '_reset_to_default_template',
439
-                'capability' => 'ee_edit_message',
440
-                'obj_id'     => $grp_id,
441
-                'noheader'   => true
442
-            ),
443
-            'settings'                         => array(
444
-                'func'       => '_settings',
445
-                'capability' => 'manage_options'
446
-            ),
447
-            'update_global_settings'           => array(
448
-                'func'       => '_update_global_settings',
449
-                'capability' => 'manage_options',
450
-                'noheader'   => true
451
-            ),
452
-            'generate_now'                     => array(
453
-                'func'       => '_generate_now',
454
-                'capability' => 'ee_send_message',
455
-                'noheader'   => true
456
-            ),
457
-            'generate_and_send_now'            => array(
458
-                'func'       => '_generate_and_send_now',
459
-                'capability' => 'ee_send_message',
460
-                'noheader'   => true
461
-            ),
462
-            'queue_for_resending'              => array(
463
-                'func'       => '_queue_for_resending',
464
-                'capability' => 'ee_send_message',
465
-                'noheader'   => true
466
-            ),
467
-            'send_now'                         => array(
468
-                'func'       => '_send_now',
469
-                'capability' => 'ee_send_message',
470
-                'noheader'   => true
471
-            ),
472
-            'delete_ee_message'                => array(
473
-                'func'       => '_delete_ee_messages',
474
-                'capability' => 'ee_delete_message',
475
-                'noheader'   => true
476
-            ),
477
-            'delete_ee_messages'               => array(
478
-                'func'       => '_delete_ee_messages',
479
-                'capability' => 'ee_delete_messages',
480
-                'noheader'   => true,
481
-                'obj_id'     => $msg_id
482
-            )
483
-        );
484
-    }
485
-    
486
-    
487
-    protected function _set_page_config()
488
-    {
489
-        $this->_page_config = array(
490
-            'default'                  => array(
491
-                'nav'           => array(
492
-                    'label' => __('Message Activity', 'event_espresso'),
493
-                    'order' => 10
494
-                ),
495
-                'list_table'    => 'EE_Message_List_Table',
496
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
-                'require_nonce' => false
498
-            ),
499
-            'global_mtps'              => array(
500
-                'nav'           => array(
501
-                    'label' => __('Default Message Templates', 'event_espresso'),
502
-                    'order' => 20
503
-                ),
504
-                'list_table'    => 'Messages_Template_List_Table',
505
-                'help_tabs'     => array(
506
-                    'messages_overview_help_tab'                                => array(
507
-                        'title'    => __('Messages Overview', 'event_espresso'),
508
-                        'filename' => 'messages_overview'
509
-                    ),
510
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
511
-                        'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
-                        'filename' => 'messages_overview_table_column_headings'
513
-                    ),
514
-                    'messages_overview_messages_filters_help_tab'               => array(
515
-                        'title'    => __('Message Filters', 'event_espresso'),
516
-                        'filename' => 'messages_overview_filters'
517
-                    ),
518
-                    'messages_overview_messages_views_help_tab'                 => array(
519
-                        'title'    => __('Message Views', 'event_espresso'),
520
-                        'filename' => 'messages_overview_views'
521
-                    ),
522
-                    'message_overview_message_types_help_tab'                   => array(
523
-                        'title'    => __('Message Types', 'event_espresso'),
524
-                        'filename' => 'messages_overview_types'
525
-                    ),
526
-                    'messages_overview_messengers_help_tab'                     => array(
527
-                        'title'    => __('Messengers', 'event_espresso'),
528
-                        'filename' => 'messages_overview_messengers',
529
-                    ),
530
-                    'messages_overview_other_help_tab'                          => array(
531
-                        'title'    => __('Messages Other', 'event_espresso'),
532
-                        'filename' => 'messages_overview_other',
533
-                    ),
534
-                ),
535
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
536
-                'require_nonce' => false
537
-            ),
538
-            'custom_mtps'              => array(
539
-                'nav'           => array(
540
-                    'label' => __('Custom Message Templates', 'event_espresso'),
541
-                    'order' => 30
542
-                ),
543
-                'help_tabs'     => array(),
544
-                'help_tour'     => array(),
545
-                'require_nonce' => false
546
-            ),
547
-            'add_new_message_template' => array(
548
-                'nav'           => array(
549
-                    'label'      => __('Add New Message Templates', 'event_espresso'),
550
-                    'order'      => 5,
551
-                    'persistent' => false
552
-                ),
553
-                'require_nonce' => false
554
-            ),
555
-            'edit_message_template'    => array(
556
-                'labels'        => array(
557
-                    'buttons'    => array(
558
-                        'reset' => __('Reset Templates'),
559
-                    ),
560
-                    'publishbox' => __('Update Actions', 'event_espresso')
561
-                ),
562
-                'nav'           => array(
563
-                    'label'      => __('Edit Message Templates', 'event_espresso'),
564
-                    'order'      => 5,
565
-                    'persistent' => false,
566
-                    'url'        => ''
567
-                ),
568
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
569
-                'has_metaboxes' => true,
570
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
571
-                'help_tabs'     => array(
572
-                    'edit_message_template'       => array(
573
-                        'title'    => __('Message Template Editor', 'event_espresso'),
574
-                        'callback' => 'edit_message_template_help_tab'
575
-                    ),
576
-                    'message_templates_help_tab'  => array(
577
-                        'title'    => __('Message Templates', 'event_espresso'),
578
-                        'filename' => 'messages_templates'
579
-                    ),
580
-                    'message_template_shortcodes' => array(
581
-                        'title'    => __('Message Shortcodes', 'event_espresso'),
582
-                        'callback' => 'message_template_shortcodes_help_tab'
583
-                    ),
584
-                    'message_preview_help_tab'    => array(
585
-                        'title'    => __('Message Preview', 'event_espresso'),
586
-                        'filename' => 'messages_preview'
587
-                    ),
588
-                ),
589
-                'require_nonce' => false
590
-            ),
591
-            'display_preview_message'  => array(
592
-                'nav'           => array(
593
-                    'label'      => __('Message Preview', 'event_espresso'),
594
-                    'order'      => 5,
595
-                    'url'        => '',
596
-                    'persistent' => false
597
-                ),
598
-                'help_tabs'     => array(
599
-                    'preview_message' => array(
600
-                        'title'    => __('About Previews', 'event_espresso'),
601
-                        'callback' => 'preview_message_help_tab'
602
-                    )
603
-                ),
604
-                'require_nonce' => false
605
-            ),
606
-            'settings'                 => array(
607
-                'nav'           => array(
608
-                    'label' => __('Settings', 'event_espresso'),
609
-                    'order' => 40
610
-                ),
611
-                'metaboxes'     => array('_messages_settings_metaboxes'),
612
-                'help_tabs'     => array(
613
-                    'messages_settings_help_tab'               => array(
614
-                        'title'    => __('Messages Settings', 'event_espresso'),
615
-                        'filename' => 'messages_settings'
616
-                    ),
617
-                    'messages_settings_message_types_help_tab' => array(
618
-                        'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
-                        'filename' => 'messages_settings_message_types'
620
-                    ),
621
-                    'messages_settings_messengers_help_tab'    => array(
622
-                        'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
-                        'filename' => 'messages_settings_messengers'
624
-                    ),
625
-                ),
626
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
627
-                'require_nonce' => false
628
-            )
629
-        );
630
-    }
631
-    
632
-    
633
-    protected function _add_screen_options()
634
-    {
635
-        //todo
636
-    }
637
-    
638
-    
639
-    protected function _add_screen_options_global_mtps()
640
-    {
641
-        /**
642
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
644
-         */
645
-        $page_title              = $this->_admin_page_title;
646
-        $this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
-        $this->_per_page_screen_option();
648
-        $this->_admin_page_title = $page_title;
649
-    }
650
-    
651
-    
652
-    protected function _add_screen_options_default()
653
-    {
654
-        $this->_admin_page_title = __('Message Activity', 'event_espresso');
655
-        $this->_per_page_screen_option();
656
-    }
657
-    
658
-    
659
-    //none of the below group are currently used for Messages
660
-    protected function _add_feature_pointers()
661
-    {
662
-    }
663
-    
664
-    public function admin_init()
665
-    {
666
-    }
667
-    
668
-    public function admin_notices()
669
-    {
670
-    }
671
-    
672
-    public function admin_footer_scripts()
673
-    {
674
-    }
675
-    
676
-    
677
-    public function messages_help_tab()
678
-    {
679
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
-    }
681
-    
682
-    
683
-    public function messengers_help_tab()
684
-    {
685
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
-    }
687
-    
688
-    
689
-    public function message_types_help_tab()
690
-    {
691
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
-    }
693
-    
694
-    
695
-    public function messages_overview_help_tab()
696
-    {
697
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
-    }
699
-    
700
-    
701
-    public function message_templates_help_tab()
702
-    {
703
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
-    }
705
-    
706
-    
707
-    public function edit_message_template_help_tab()
708
-    {
709
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
-                'event_espresso') . '" />';
711
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
-                'event_espresso') . '" />';
713
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
-                'event_espresso') . '" />';
715
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
-                'event_espresso') . '" />';
717
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
-                'event_espresso') . '" />';
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
-            $args);
721
-    }
722
-    
723
-    
724
-    public function message_template_shortcodes_help_tab()
725
-    {
726
-        $this->_set_shortcodes();
727
-        $args['shortcodes'] = $this->_shortcodes;
728
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
-            $args);
730
-    }
179
+			'4.9.9.rc.014'
180
+		);
181
+        
182
+		$contexts                = array();
183
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
+		foreach ($active_message_contexts as $active_message) {
185
+			if ($active_message instanceof EE_Message) {
186
+				$message_type = $active_message->message_type_object();
187
+				if ($message_type instanceof EE_message_type) {
188
+					$message_type_contexts = $message_type->get_contexts();
189
+					foreach ($message_type_contexts as $context => $context_details) {
190
+						$contexts[$context] = $context_details['label'];
191
+					}
192
+				}
193
+			}
194
+		}
195
+        
196
+		return $contexts;
197
+	}
198
+    
199
+    
200
+	/**
201
+	 * Generate select input with provided messenger options array.
202
+	 *
203
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
+	 *                                 labels.
205
+	 *
206
+	 * @return string
207
+	 */
208
+	public function get_messengers_select_input($messenger_options)
209
+	{
210
+		//if empty or just one value then just return an empty string
211
+		if (empty($messenger_options)
212
+			|| ! is_array($messenger_options)
213
+			|| count($messenger_options) === 1
214
+		) {
215
+			return '';
216
+		}
217
+		//merge in default
218
+		$messenger_options = array_merge(
219
+			array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
+			$messenger_options
221
+		);
222
+		$input             = new EE_Select_Input(
223
+			$messenger_options,
224
+			array(
225
+				'html_name'  => 'ee_messenger_filter_by',
226
+				'html_id'    => 'ee_messenger_filter_by',
227
+				'html_class' => 'wide',
228
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
+					: 'none_selected'
231
+			)
232
+		);
233
+        
234
+		return $input->get_html_for_input();
235
+	}
236
+    
237
+    
238
+	/**
239
+	 * Generate select input with provided message type options array.
240
+	 *
241
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
+	 *                                    message type labels
243
+	 *
244
+	 * @return string
245
+	 */
246
+	public function get_message_types_select_input($message_type_options)
247
+	{
248
+		//if empty or count of options is 1 then just return an empty string
249
+		if (empty($message_type_options)
250
+			|| ! is_array($message_type_options)
251
+			|| count($message_type_options) === 1
252
+		) {
253
+			return '';
254
+		}
255
+		//merge in default
256
+		$message_type_options = array_merge(
257
+			array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
+			$message_type_options
259
+		);
260
+		$input                = new EE_Select_Input(
261
+			$message_type_options,
262
+			array(
263
+				'html_name'  => 'ee_message_type_filter_by',
264
+				'html_id'    => 'ee_message_type_filter_by',
265
+				'html_class' => 'wide',
266
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
+					: 'none_selected',
269
+			)
270
+		);
271
+        
272
+		return $input->get_html_for_input();
273
+	}
274
+    
275
+    
276
+	/**
277
+	 * Generate select input with provide message type contexts array.
278
+	 *
279
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
+	 *                               context label.
281
+	 *
282
+	 * @return string
283
+	 */
284
+	public function get_contexts_for_message_types_select_input($context_options)
285
+	{
286
+		//if empty or count of options is one then just return empty string
287
+		if (empty($context_options)
288
+			|| ! is_array($context_options)
289
+			|| count($context_options) === 1
290
+		) {
291
+			return '';
292
+		}
293
+		//merge in default
294
+		$context_options = array_merge(
295
+			array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
+			$context_options
297
+		);
298
+		$input           = new EE_Select_Input(
299
+			$context_options,
300
+			array(
301
+				'html_name'  => 'ee_context_filter_by',
302
+				'html_id'    => 'ee_context_filter_by',
303
+				'html_class' => 'wide',
304
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
305
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
306
+					: 'none_selected',
307
+			)
308
+		);
309
+        
310
+		return $input->get_html_for_input();
311
+	}
312
+    
313
+    
314
+	protected function _ajax_hooks()
315
+	{
316
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
+	}
322
+    
323
+    
324
+	protected function _define_page_props()
325
+	{
326
+		$this->_admin_page_title = $this->page_label;
327
+		$this->_labels           = array(
328
+			'buttons'    => array(
329
+				'add'    => __('Add New Message Template', 'event_espresso'),
330
+				'edit'   => __('Edit Message Template', 'event_espresso'),
331
+				'delete' => __('Delete Message Template', 'event_espresso')
332
+			),
333
+			'publishbox' => __('Update Actions', 'event_espresso')
334
+		);
335
+	}
336
+    
337
+    
338
+	/**
339
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
340
+	 * @access protected
341
+	 * @return void
342
+	 */
343
+	protected function _set_page_routes()
344
+	{
345
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
+			? $this->_req_data['GRP_ID']
347
+			: 0;
348
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
+			? $this->_req_data['id']
350
+			: $grp_id;
351
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
+			? $this->_req_data['MSG_ID']
353
+			: 0;
354
+        
355
+		$this->_page_routes = array(
356
+			'default'                          => array(
357
+				'func'       => '_message_queue_list_table',
358
+				'capability' => 'ee_read_global_messages'
359
+			),
360
+			'global_mtps'                      => array(
361
+				'func'       => '_ee_default_messages_overview_list_table',
362
+				'capability' => 'ee_read_global_messages'
363
+			),
364
+			'custom_mtps'                      => array(
365
+				'func'       => '_custom_mtps_preview',
366
+				'capability' => 'ee_read_messages'
367
+			),
368
+			'add_new_message_template'         => array(
369
+				'func'       => '_add_message_template',
370
+				'capability' => 'ee_edit_messages',
371
+				'noheader'   => true
372
+			),
373
+			'edit_message_template'            => array(
374
+				'func'       => '_edit_message_template',
375
+				'capability' => 'ee_edit_message',
376
+				'obj_id'     => $grp_id
377
+			),
378
+			'preview_message'                  => array(
379
+				'func'               => '_preview_message',
380
+				'capability'         => 'ee_read_message',
381
+				'obj_id'             => $grp_id,
382
+				'noheader'           => true,
383
+				'headers_sent_route' => 'display_preview_message'
384
+			),
385
+			'display_preview_message'          => array(
386
+				'func'       => '_display_preview_message',
387
+				'capability' => 'ee_read_message',
388
+				'obj_id'     => $grp_id
389
+			),
390
+			'insert_message_template'          => array(
391
+				'func'       => '_insert_or_update_message_template',
392
+				'capability' => 'ee_edit_messages',
393
+				'args'       => array('new_template' => true),
394
+				'noheader'   => true
395
+			),
396
+			'update_message_template'          => array(
397
+				'func'       => '_insert_or_update_message_template',
398
+				'capability' => 'ee_edit_message',
399
+				'obj_id'     => $grp_id,
400
+				'args'       => array('new_template' => false),
401
+				'noheader'   => true
402
+			),
403
+			'trash_message_template'           => array(
404
+				'func'       => '_trash_or_restore_message_template',
405
+				'capability' => 'ee_delete_message',
406
+				'obj_id'     => $grp_id,
407
+				'args'       => array('trash' => true, 'all' => true),
408
+				'noheader'   => true
409
+			),
410
+			'trash_message_template_context'   => array(
411
+				'func'       => '_trash_or_restore_message_template',
412
+				'capability' => 'ee_delete_message',
413
+				'obj_id'     => $grp_id,
414
+				'args'       => array('trash' => true),
415
+				'noheader'   => true
416
+			),
417
+			'restore_message_template'         => array(
418
+				'func'       => '_trash_or_restore_message_template',
419
+				'capability' => 'ee_delete_message',
420
+				'obj_id'     => $grp_id,
421
+				'args'       => array('trash' => false, 'all' => true),
422
+				'noheader'   => true
423
+			),
424
+			'restore_message_template_context' => array(
425
+				'func'       => '_trash_or_restore_message_template',
426
+				'capability' => 'ee_delete_message',
427
+				'obj_id'     => $grp_id,
428
+				'args'       => array('trash' => false),
429
+				'noheader'   => true
430
+			),
431
+			'delete_message_template'          => array(
432
+				'func'       => '_delete_message_template',
433
+				'capability' => 'ee_delete_message',
434
+				'obj_id'     => $grp_id,
435
+				'noheader'   => true
436
+			),
437
+			'reset_to_default'                 => array(
438
+				'func'       => '_reset_to_default_template',
439
+				'capability' => 'ee_edit_message',
440
+				'obj_id'     => $grp_id,
441
+				'noheader'   => true
442
+			),
443
+			'settings'                         => array(
444
+				'func'       => '_settings',
445
+				'capability' => 'manage_options'
446
+			),
447
+			'update_global_settings'           => array(
448
+				'func'       => '_update_global_settings',
449
+				'capability' => 'manage_options',
450
+				'noheader'   => true
451
+			),
452
+			'generate_now'                     => array(
453
+				'func'       => '_generate_now',
454
+				'capability' => 'ee_send_message',
455
+				'noheader'   => true
456
+			),
457
+			'generate_and_send_now'            => array(
458
+				'func'       => '_generate_and_send_now',
459
+				'capability' => 'ee_send_message',
460
+				'noheader'   => true
461
+			),
462
+			'queue_for_resending'              => array(
463
+				'func'       => '_queue_for_resending',
464
+				'capability' => 'ee_send_message',
465
+				'noheader'   => true
466
+			),
467
+			'send_now'                         => array(
468
+				'func'       => '_send_now',
469
+				'capability' => 'ee_send_message',
470
+				'noheader'   => true
471
+			),
472
+			'delete_ee_message'                => array(
473
+				'func'       => '_delete_ee_messages',
474
+				'capability' => 'ee_delete_message',
475
+				'noheader'   => true
476
+			),
477
+			'delete_ee_messages'               => array(
478
+				'func'       => '_delete_ee_messages',
479
+				'capability' => 'ee_delete_messages',
480
+				'noheader'   => true,
481
+				'obj_id'     => $msg_id
482
+			)
483
+		);
484
+	}
485
+    
486
+    
487
+	protected function _set_page_config()
488
+	{
489
+		$this->_page_config = array(
490
+			'default'                  => array(
491
+				'nav'           => array(
492
+					'label' => __('Message Activity', 'event_espresso'),
493
+					'order' => 10
494
+				),
495
+				'list_table'    => 'EE_Message_List_Table',
496
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
+				'require_nonce' => false
498
+			),
499
+			'global_mtps'              => array(
500
+				'nav'           => array(
501
+					'label' => __('Default Message Templates', 'event_espresso'),
502
+					'order' => 20
503
+				),
504
+				'list_table'    => 'Messages_Template_List_Table',
505
+				'help_tabs'     => array(
506
+					'messages_overview_help_tab'                                => array(
507
+						'title'    => __('Messages Overview', 'event_espresso'),
508
+						'filename' => 'messages_overview'
509
+					),
510
+					'messages_overview_messages_table_column_headings_help_tab' => array(
511
+						'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
+						'filename' => 'messages_overview_table_column_headings'
513
+					),
514
+					'messages_overview_messages_filters_help_tab'               => array(
515
+						'title'    => __('Message Filters', 'event_espresso'),
516
+						'filename' => 'messages_overview_filters'
517
+					),
518
+					'messages_overview_messages_views_help_tab'                 => array(
519
+						'title'    => __('Message Views', 'event_espresso'),
520
+						'filename' => 'messages_overview_views'
521
+					),
522
+					'message_overview_message_types_help_tab'                   => array(
523
+						'title'    => __('Message Types', 'event_espresso'),
524
+						'filename' => 'messages_overview_types'
525
+					),
526
+					'messages_overview_messengers_help_tab'                     => array(
527
+						'title'    => __('Messengers', 'event_espresso'),
528
+						'filename' => 'messages_overview_messengers',
529
+					),
530
+					'messages_overview_other_help_tab'                          => array(
531
+						'title'    => __('Messages Other', 'event_espresso'),
532
+						'filename' => 'messages_overview_other',
533
+					),
534
+				),
535
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
536
+				'require_nonce' => false
537
+			),
538
+			'custom_mtps'              => array(
539
+				'nav'           => array(
540
+					'label' => __('Custom Message Templates', 'event_espresso'),
541
+					'order' => 30
542
+				),
543
+				'help_tabs'     => array(),
544
+				'help_tour'     => array(),
545
+				'require_nonce' => false
546
+			),
547
+			'add_new_message_template' => array(
548
+				'nav'           => array(
549
+					'label'      => __('Add New Message Templates', 'event_espresso'),
550
+					'order'      => 5,
551
+					'persistent' => false
552
+				),
553
+				'require_nonce' => false
554
+			),
555
+			'edit_message_template'    => array(
556
+				'labels'        => array(
557
+					'buttons'    => array(
558
+						'reset' => __('Reset Templates'),
559
+					),
560
+					'publishbox' => __('Update Actions', 'event_espresso')
561
+				),
562
+				'nav'           => array(
563
+					'label'      => __('Edit Message Templates', 'event_espresso'),
564
+					'order'      => 5,
565
+					'persistent' => false,
566
+					'url'        => ''
567
+				),
568
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
569
+				'has_metaboxes' => true,
570
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
571
+				'help_tabs'     => array(
572
+					'edit_message_template'       => array(
573
+						'title'    => __('Message Template Editor', 'event_espresso'),
574
+						'callback' => 'edit_message_template_help_tab'
575
+					),
576
+					'message_templates_help_tab'  => array(
577
+						'title'    => __('Message Templates', 'event_espresso'),
578
+						'filename' => 'messages_templates'
579
+					),
580
+					'message_template_shortcodes' => array(
581
+						'title'    => __('Message Shortcodes', 'event_espresso'),
582
+						'callback' => 'message_template_shortcodes_help_tab'
583
+					),
584
+					'message_preview_help_tab'    => array(
585
+						'title'    => __('Message Preview', 'event_espresso'),
586
+						'filename' => 'messages_preview'
587
+					),
588
+				),
589
+				'require_nonce' => false
590
+			),
591
+			'display_preview_message'  => array(
592
+				'nav'           => array(
593
+					'label'      => __('Message Preview', 'event_espresso'),
594
+					'order'      => 5,
595
+					'url'        => '',
596
+					'persistent' => false
597
+				),
598
+				'help_tabs'     => array(
599
+					'preview_message' => array(
600
+						'title'    => __('About Previews', 'event_espresso'),
601
+						'callback' => 'preview_message_help_tab'
602
+					)
603
+				),
604
+				'require_nonce' => false
605
+			),
606
+			'settings'                 => array(
607
+				'nav'           => array(
608
+					'label' => __('Settings', 'event_espresso'),
609
+					'order' => 40
610
+				),
611
+				'metaboxes'     => array('_messages_settings_metaboxes'),
612
+				'help_tabs'     => array(
613
+					'messages_settings_help_tab'               => array(
614
+						'title'    => __('Messages Settings', 'event_espresso'),
615
+						'filename' => 'messages_settings'
616
+					),
617
+					'messages_settings_message_types_help_tab' => array(
618
+						'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
+						'filename' => 'messages_settings_message_types'
620
+					),
621
+					'messages_settings_messengers_help_tab'    => array(
622
+						'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
+						'filename' => 'messages_settings_messengers'
624
+					),
625
+				),
626
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
627
+				'require_nonce' => false
628
+			)
629
+		);
630
+	}
631
+    
632
+    
633
+	protected function _add_screen_options()
634
+	{
635
+		//todo
636
+	}
637
+    
638
+    
639
+	protected function _add_screen_options_global_mtps()
640
+	{
641
+		/**
642
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
644
+		 */
645
+		$page_title              = $this->_admin_page_title;
646
+		$this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
+		$this->_per_page_screen_option();
648
+		$this->_admin_page_title = $page_title;
649
+	}
650
+    
651
+    
652
+	protected function _add_screen_options_default()
653
+	{
654
+		$this->_admin_page_title = __('Message Activity', 'event_espresso');
655
+		$this->_per_page_screen_option();
656
+	}
657
+    
658
+    
659
+	//none of the below group are currently used for Messages
660
+	protected function _add_feature_pointers()
661
+	{
662
+	}
663
+    
664
+	public function admin_init()
665
+	{
666
+	}
667
+    
668
+	public function admin_notices()
669
+	{
670
+	}
671
+    
672
+	public function admin_footer_scripts()
673
+	{
674
+	}
675
+    
676
+    
677
+	public function messages_help_tab()
678
+	{
679
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
+	}
681
+    
682
+    
683
+	public function messengers_help_tab()
684
+	{
685
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
+	}
687
+    
688
+    
689
+	public function message_types_help_tab()
690
+	{
691
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
+	}
693
+    
694
+    
695
+	public function messages_overview_help_tab()
696
+	{
697
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
+	}
699
+    
700
+    
701
+	public function message_templates_help_tab()
702
+	{
703
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
+	}
705
+    
706
+    
707
+	public function edit_message_template_help_tab()
708
+	{
709
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
+				'event_espresso') . '" />';
711
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
+				'event_espresso') . '" />';
713
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
+				'event_espresso') . '" />';
715
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
+				'event_espresso') . '" />';
717
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
+				'event_espresso') . '" />';
719
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
+			$args);
721
+	}
722
+    
723
+    
724
+	public function message_template_shortcodes_help_tab()
725
+	{
726
+		$this->_set_shortcodes();
727
+		$args['shortcodes'] = $this->_shortcodes;
728
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
+			$args);
730
+	}
731 731
     
732 732
     
733
-    public function preview_message_help_tab()
734
-    {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
-    }
733
+	public function preview_message_help_tab()
734
+	{
735
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
+	}
737 737
     
738
-    
739
-    public function settings_help_tab()
740
-    {
741
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
-                'event_espresso') . '" />';
743
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
-                'event_espresso') . '" />';
745
-        $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
-        $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
-    }
738
+    
739
+	public function settings_help_tab()
740
+	{
741
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
+				'event_espresso') . '" />';
743
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
+				'event_espresso') . '" />';
745
+		$args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
+		$args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
+	}
749 749
     
750 750
     
751
-    public function load_scripts_styles()
752
-    {
753
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
-        wp_enqueue_style('espresso_ee_msg');
751
+	public function load_scripts_styles()
752
+	{
753
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
+		wp_enqueue_style('espresso_ee_msg');
755 755
         
756
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
-    }
756
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
+	}
761 761
     
762 762
     
763
-    public function load_scripts_styles_default()
764
-    {
765
-        wp_enqueue_script('ee-msg-list-table-js');
766
-    }
763
+	public function load_scripts_styles_default()
764
+	{
765
+		wp_enqueue_script('ee-msg-list-table-js');
766
+	}
767 767
     
768 768
     
769
-    public function wp_editor_css($mce_css)
770
-    {
771
-        //if we're on the edit_message_template route
772
-        if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
-            $message_type_name = $this->_active_message_type_name;
769
+	public function wp_editor_css($mce_css)
770
+	{
771
+		//if we're on the edit_message_template route
772
+		if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
+			$message_type_name = $this->_active_message_type_name;
774 774
             
775
-            //we're going to REPLACE the existing mce css
776
-            //we need to get the css file location from the active messenger
777
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
-                'wpeditor', $this->_variation);
779
-        }
775
+			//we're going to REPLACE the existing mce css
776
+			//we need to get the css file location from the active messenger
777
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
+				'wpeditor', $this->_variation);
779
+		}
780 780
         
781
-        return $mce_css;
782
-    }
783
-    
784
-    
785
-    public function load_scripts_styles_edit_message_template()
786
-    {
787
-        
788
-        $this->_set_shortcodes();
781
+		return $mce_css;
782
+	}
783
+    
784
+    
785
+	public function load_scripts_styles_edit_message_template()
786
+	{
787
+        
788
+		$this->_set_shortcodes();
789 789
         
790
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
-            __('Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
792
-                'event_espresso'),
793
-            $this->_message_template_group->messenger_obj()->label['singular'],
794
-            $this->_message_template_group->message_type_obj()->label['singular']
795
-        );
796
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
797
-            'event_espresso');
798
-        
799
-        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
-            EVENT_ESPRESSO_VERSION);
801
-        
802
-        wp_enqueue_script('ee_admin_js');
803
-        wp_enqueue_script('ee_msgs_edit_js');
804
-        
805
-        //add in special css for tiny_mce
806
-        add_filter('mce_css', array($this, 'wp_editor_css'));
807
-    }
808
-    
809
-    
810
-    public function load_scripts_styles_display_preview_message()
811
-    {
812
-        
813
-        $this->_set_message_template_group();
814
-        
815
-        if (isset($this->_req_data['messenger'])) {
816
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
-        }
818
-        
819
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820
-        
821
-        
822
-        wp_enqueue_style('espresso_preview_css',
823
-            $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
-                $this->_variation));
825
-    }
826
-    
827
-    
828
-    public function load_scripts_styles_settings()
829
-    {
830
-        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
-            EVENT_ESPRESSO_VERSION);
832
-        wp_enqueue_style('ee-text-links');
833
-        wp_enqueue_style('ee-message-settings');
834
-        
835
-        wp_enqueue_script('ee-messages-settings');
836
-    }
837
-    
838
-    
839
-    /**
840
-     * set views array for List Table
841
-     */
842
-    public function _set_list_table_views_global_mtps()
843
-    {
844
-        $this->_views = array(
845
-            'in_use' => array(
846
-                'slug'        => 'in_use',
847
-                'label'       => __('In Use', 'event_espresso'),
848
-                'count'       => 0,
849
-                'bulk_action' => array(
850
-                    'trash_message_template' => __('Move to Trash', 'event_espresso')
851
-                )
852
-            )
853
-        );
854
-    }
855
-    
856
-    
857
-    /**
858
-     * set views array for message queue list table
859
-     */
860
-    public function _set_list_table_views_default()
861
-    {
862
-        EE_Registry::instance()->load_helper('Template');
863
-        
864
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
865
-            'message_list_table_bulk_actions')
866
-            ? array(
867
-                'generate_now'          => __('Generate Now', 'event_espresso'),
868
-                'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
869
-                'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
870
-                'send_now'              => __('Send Now', 'event_espresso')
871
-            )
872
-            : array();
873
-        
874
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
875
-            'message_list_table_bulk_actions')
876
-            ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
877
-            : array();
878
-        
879
-        
880
-        $this->_views = array(
881
-            'all' => array(
882
-                'slug'        => 'all',
883
-                'label'       => __('All', 'event_espresso'),
884
-                'count'       => 0,
885
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
886
-            )
887
-        );
888
-        
889
-        
890
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
891
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
892
-                continue;
893
-            }
894
-            $status_bulk_actions = $common_bulk_actions;
895
-            //unset bulk actions not applying to status
896
-            if (! empty($status_bulk_actions)) {
897
-                switch ($status) {
898
-                    case EEM_Message::status_idle:
899
-                    case EEM_Message::status_resend:
900
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
901
-                        break;
790
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
+			__('Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
792
+				'event_espresso'),
793
+			$this->_message_template_group->messenger_obj()->label['singular'],
794
+			$this->_message_template_group->message_type_obj()->label['singular']
795
+		);
796
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
797
+			'event_espresso');
798
+        
799
+		wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
+			EVENT_ESPRESSO_VERSION);
801
+        
802
+		wp_enqueue_script('ee_admin_js');
803
+		wp_enqueue_script('ee_msgs_edit_js');
804
+        
805
+		//add in special css for tiny_mce
806
+		add_filter('mce_css', array($this, 'wp_editor_css'));
807
+	}
808
+    
809
+    
810
+	public function load_scripts_styles_display_preview_message()
811
+	{
812
+        
813
+		$this->_set_message_template_group();
814
+        
815
+		if (isset($this->_req_data['messenger'])) {
816
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
+		}
818
+        
819
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820
+        
821
+        
822
+		wp_enqueue_style('espresso_preview_css',
823
+			$this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
+				$this->_variation));
825
+	}
826
+    
827
+    
828
+	public function load_scripts_styles_settings()
829
+	{
830
+		wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
+			EVENT_ESPRESSO_VERSION);
832
+		wp_enqueue_style('ee-text-links');
833
+		wp_enqueue_style('ee-message-settings');
834
+        
835
+		wp_enqueue_script('ee-messages-settings');
836
+	}
837
+    
838
+    
839
+	/**
840
+	 * set views array for List Table
841
+	 */
842
+	public function _set_list_table_views_global_mtps()
843
+	{
844
+		$this->_views = array(
845
+			'in_use' => array(
846
+				'slug'        => 'in_use',
847
+				'label'       => __('In Use', 'event_espresso'),
848
+				'count'       => 0,
849
+				'bulk_action' => array(
850
+					'trash_message_template' => __('Move to Trash', 'event_espresso')
851
+				)
852
+			)
853
+		);
854
+	}
855
+    
856
+    
857
+	/**
858
+	 * set views array for message queue list table
859
+	 */
860
+	public function _set_list_table_views_default()
861
+	{
862
+		EE_Registry::instance()->load_helper('Template');
863
+        
864
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
865
+			'message_list_table_bulk_actions')
866
+			? array(
867
+				'generate_now'          => __('Generate Now', 'event_espresso'),
868
+				'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
869
+				'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
870
+				'send_now'              => __('Send Now', 'event_espresso')
871
+			)
872
+			: array();
873
+        
874
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
875
+			'message_list_table_bulk_actions')
876
+			? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
877
+			: array();
878
+        
879
+        
880
+		$this->_views = array(
881
+			'all' => array(
882
+				'slug'        => 'all',
883
+				'label'       => __('All', 'event_espresso'),
884
+				'count'       => 0,
885
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
886
+			)
887
+		);
888
+        
889
+        
890
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
891
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
892
+				continue;
893
+			}
894
+			$status_bulk_actions = $common_bulk_actions;
895
+			//unset bulk actions not applying to status
896
+			if (! empty($status_bulk_actions)) {
897
+				switch ($status) {
898
+					case EEM_Message::status_idle:
899
+					case EEM_Message::status_resend:
900
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
901
+						break;
902 902
                     
903
-                    case EEM_Message::status_failed:
904
-                    case EEM_Message::status_debug_only:
905
-                    case EEM_Message::status_messenger_executing:
906
-                        $status_bulk_actions = array();
907
-                        break;
903
+					case EEM_Message::status_failed:
904
+					case EEM_Message::status_debug_only:
905
+					case EEM_Message::status_messenger_executing:
906
+						$status_bulk_actions = array();
907
+						break;
908 908
                     
909
-                    case EEM_Message::status_incomplete:
910
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
911
-                        break;
909
+					case EEM_Message::status_incomplete:
910
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
911
+						break;
912 912
                     
913
-                    case EEM_Message::status_retry:
914
-                    case EEM_Message::status_sent:
915
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
916
-                        break;
917
-                }
918
-            }
913
+					case EEM_Message::status_retry:
914
+					case EEM_Message::status_sent:
915
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
916
+						break;
917
+				}
918
+			}
919 919
 
920
-            //skip adding messenger executing status to views because it will be included with the Failed view.
921
-            if ( $status === EEM_Message::status_messenger_executing ) {
922
-                continue;
923
-            }
920
+			//skip adding messenger executing status to views because it will be included with the Failed view.
921
+			if ( $status === EEM_Message::status_messenger_executing ) {
922
+				continue;
923
+			}
924 924
             
925
-            $this->_views[strtolower($status)] = array(
926
-                'slug'        => strtolower($status),
927
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
928
-                'count'       => 0,
929
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
930
-            );
931
-        }
932
-    }
933
-    
934
-    
935
-    protected function _ee_default_messages_overview_list_table()
936
-    {
937
-        $this->_admin_page_title = __('Default Message Templates', 'event_espresso');
938
-        $this->display_admin_list_table_page_with_no_sidebar();
939
-    }
940
-    
941
-    
942
-    protected function _message_queue_list_table()
943
-    {
944
-        $this->_search_btn_label                   = __('Message Activity', 'event_espresso');
945
-        $this->_template_args['per_column']        = 6;
946
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
947
-        $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
948
-        $this->display_admin_list_table_page_with_no_sidebar();
949
-    }
950
-    
951
-    
952
-    protected function _message_legend_items()
953
-    {
954
-        
955
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
956
-        $action_items       = array();
957
-        
958
-        foreach ($action_css_classes as $action_item => $action_details) {
959
-            if ($action_item === 'see_notifications_for') {
960
-                continue;
961
-            }
962
-            $action_items[$action_item] = array(
963
-                'class' => $action_details['css_class'],
964
-                'desc'  => $action_details['label']
965
-            );
966
-        }
967
-        
968
-        /** @type array $status_items status legend setup */
969
-        $status_items = array(
970
-            'sent_status'       => array(
971
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
972
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
973
-            ),
974
-            'idle_status'       => array(
975
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
976
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
977
-            ),
978
-            'failed_status'     => array(
979
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
980
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
981
-            ),
982
-            'messenger_executing_status' => array(
983
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
984
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
985
-            ),
986
-            'resend_status'     => array(
987
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
988
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
989
-            ),
990
-            'incomplete_status' => array(
991
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
992
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
993
-            ),
994
-            'retry_status'      => array(
995
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
996
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
997
-            )
998
-        );
999
-        if (EEM_Message::debug()) {
1000
-            $status_items['debug_only_status'] = array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1002
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1003
-            );
1004
-        }
1005
-        
1006
-        return array_merge($action_items, $status_items);
1007
-    }
1008
-    
1009
-    
1010
-    protected function _custom_mtps_preview()
1011
-    {
1012
-        $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1013
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1014
-                'event_espresso') . '" />';
1015
-        $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1016
-                'event_espresso') . '</strong>';
1017
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1018
-    }
1019
-    
1020
-    
1021
-    /**
1022
-     * get_message_templates
1023
-     * This gets all the message templates for listing on the overview list.
1024
-     *
1025
-     * @access public
1026
-     *
1027
-     * @param int    $perpage the amount of templates groups to show per page
1028
-     * @param string $type    the current _view we're getting templates for
1029
-     * @param bool   $count   return count?
1030
-     * @param bool   $all     disregard any paging info (get all data);
1031
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1032
-     *
1033
-     * @return array
1034
-     */
1035
-    public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1036
-    {
1037
-        
1038
-        $MTP = EEM_Message_Template_Group::instance();
1039
-        
1040
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1041
-        $orderby                    = $this->_req_data['orderby'];
1042
-        
1043
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1044
-        
1045
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1046
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1047
-        
1048
-        $offset = ($current_page - 1) * $per_page;
1049
-        $limit  = $all ? null : array($offset, $per_page);
1050
-        
1051
-        
1052
-        //options will match what is in the _views array property
1053
-        switch ($type) {
925
+			$this->_views[strtolower($status)] = array(
926
+				'slug'        => strtolower($status),
927
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
928
+				'count'       => 0,
929
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
930
+			);
931
+		}
932
+	}
933
+    
934
+    
935
+	protected function _ee_default_messages_overview_list_table()
936
+	{
937
+		$this->_admin_page_title = __('Default Message Templates', 'event_espresso');
938
+		$this->display_admin_list_table_page_with_no_sidebar();
939
+	}
940
+    
941
+    
942
+	protected function _message_queue_list_table()
943
+	{
944
+		$this->_search_btn_label                   = __('Message Activity', 'event_espresso');
945
+		$this->_template_args['per_column']        = 6;
946
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
947
+		$this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
948
+		$this->display_admin_list_table_page_with_no_sidebar();
949
+	}
950
+    
951
+    
952
+	protected function _message_legend_items()
953
+	{
954
+        
955
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
956
+		$action_items       = array();
957
+        
958
+		foreach ($action_css_classes as $action_item => $action_details) {
959
+			if ($action_item === 'see_notifications_for') {
960
+				continue;
961
+			}
962
+			$action_items[$action_item] = array(
963
+				'class' => $action_details['css_class'],
964
+				'desc'  => $action_details['label']
965
+			);
966
+		}
967
+        
968
+		/** @type array $status_items status legend setup */
969
+		$status_items = array(
970
+			'sent_status'       => array(
971
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
972
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
973
+			),
974
+			'idle_status'       => array(
975
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
976
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
977
+			),
978
+			'failed_status'     => array(
979
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
980
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
981
+			),
982
+			'messenger_executing_status' => array(
983
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
984
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
985
+			),
986
+			'resend_status'     => array(
987
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
988
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
989
+			),
990
+			'incomplete_status' => array(
991
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
992
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
993
+			),
994
+			'retry_status'      => array(
995
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
996
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
997
+			)
998
+		);
999
+		if (EEM_Message::debug()) {
1000
+			$status_items['debug_only_status'] = array(
1001
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1002
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1003
+			);
1004
+		}
1005
+        
1006
+		return array_merge($action_items, $status_items);
1007
+	}
1008
+    
1009
+    
1010
+	protected function _custom_mtps_preview()
1011
+	{
1012
+		$this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1013
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1014
+				'event_espresso') . '" />';
1015
+		$this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1016
+				'event_espresso') . '</strong>';
1017
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1018
+	}
1019
+    
1020
+    
1021
+	/**
1022
+	 * get_message_templates
1023
+	 * This gets all the message templates for listing on the overview list.
1024
+	 *
1025
+	 * @access public
1026
+	 *
1027
+	 * @param int    $perpage the amount of templates groups to show per page
1028
+	 * @param string $type    the current _view we're getting templates for
1029
+	 * @param bool   $count   return count?
1030
+	 * @param bool   $all     disregard any paging info (get all data);
1031
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1032
+	 *
1033
+	 * @return array
1034
+	 */
1035
+	public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1036
+	{
1037
+        
1038
+		$MTP = EEM_Message_Template_Group::instance();
1039
+        
1040
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1041
+		$orderby                    = $this->_req_data['orderby'];
1042
+        
1043
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1044
+        
1045
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1046
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1047
+        
1048
+		$offset = ($current_page - 1) * $per_page;
1049
+		$limit  = $all ? null : array($offset, $per_page);
1050
+        
1051
+        
1052
+		//options will match what is in the _views array property
1053
+		switch ($type) {
1054 1054
             
1055
-            case 'in_use':
1056
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1057
-                break;
1055
+			case 'in_use':
1056
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1057
+				break;
1058 1058
             
1059
-            default:
1060
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1059
+			default:
1060
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1061 1061
             
1062
-        }
1063
-        
1064
-        return $templates;
1065
-    }
1066
-    
1067
-    
1068
-    /**
1069
-     * filters etc might need a list of installed message_types
1070
-     * @return array an array of message type objects
1071
-     */
1072
-    public function get_installed_message_types()
1073
-    {
1074
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1075
-        $installed               = array();
1076
-        
1077
-        foreach ($installed_message_types as $message_type) {
1078
-            $installed[$message_type->name] = $message_type;
1079
-        }
1080
-        
1081
-        return $installed;
1082
-    }
1083
-    
1084
-    
1085
-    /**
1086
-     * _add_message_template
1087
-     *
1088
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1089
-     *
1090
-     * @param string $message_type
1091
-     * @param string $messenger
1092
-     * @param string $GRP_ID
1093
-     *
1094
-     * @throws EE_error
1095
-     */
1096
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1097
-    {
1098
-        //set values override any request data
1099
-        $message_type = ! empty($message_type) ? $message_type : '';
1100
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1101
-        
1102
-        $messenger = ! empty($messenger) ? $messenger : '';
1103
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1104
-        
1105
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1106
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1107
-        
1108
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1109
-        if (empty($message_type) || empty($messenger)) {
1110
-            throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1111
-                'event_espresso'));
1112
-        }
1113
-        
1114
-        //we need the GRP_ID for the template being used as the base for the new template
1115
-        if (empty($GRP_ID)) {
1116
-            throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1117
-                'event_espresso'));
1118
-        }
1119
-        
1120
-        //let's just make sure the template gets generated!
1121
-        
1122
-        //we need to reassign some variables for what the insert is expecting
1123
-        $this->_req_data['MTP_messenger']    = $messenger;
1124
-        $this->_req_data['MTP_message_type'] = $message_type;
1125
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1126
-        $this->_insert_or_update_message_template(true);
1127
-    }
1128
-    
1129
-    
1130
-    /**
1131
-     * public wrapper for the _add_message_template method
1132
-     *
1133
-     * @param string $message_type     message type slug
1134
-     * @param string $messenger        messenger slug
1135
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1136
-     *                                 off of.
1137
-     */
1138
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1139
-    {
1140
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1141
-    }
1142
-    
1143
-    
1144
-    /**
1145
-     * _edit_message_template
1146
-     *
1147
-     * @access protected
1148
-     * @return void
1149
-     */
1150
-    protected function _edit_message_template()
1151
-    {
1152
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1153
-        $template_fields = '';
1154
-        $sidebar_fields  = '';
1155
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1156
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1157
-        
1158
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1159
-            ? absint($this->_req_data['id'])
1160
-            : false;
1161
-        
1162
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1163
-        $message_template_group = $this->_message_template_group;
1164
-        $c_label                = $message_template_group->context_label();
1165
-        $c_config               = $message_template_group->contexts_config();
1166
-        
1167
-        reset($c_config);
1168
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1169
-            ? strtolower($this->_req_data['context'])
1170
-            : key($c_config);
1171
-        
1172
-        
1173
-        if (empty($GRP_ID)) {
1174
-            $action = 'insert_message_template';
1175
-            //$button_both = false;
1176
-            //$button_text = array( __( 'Save','event_espresso') );
1177
-            //$button_actions = array('something_different');
1178
-            //$referrer = false;
1179
-            $edit_message_template_form_url = add_query_arg(
1180
-                array('action' => $action, 'noheader' => true),
1181
-                EE_MSG_ADMIN_URL
1182
-            );
1183
-        } else {
1184
-            $action = 'update_message_template';
1185
-            //$button_both = true;
1186
-            //$button_text = array();
1187
-            //$button_actions = array();
1188
-            //$referrer = $this->_admin_base_url;
1189
-            $edit_message_template_form_url = add_query_arg(
1190
-                array('action' => $action, 'noheader' => true),
1191
-                EE_MSG_ADMIN_URL
1192
-            );
1193
-        }
1194
-        
1195
-        //set active messenger for this view
1196
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1197
-            $message_template_group->messenger()
1198
-        );
1199
-        $this->_active_message_type_name = $message_template_group->message_type();
1200
-        
1201
-        
1202
-        //Do we have any validation errors?
1203
-        $validators = $this->_get_transient();
1204
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1205
-        
1206
-        
1207
-        //we need to assemble the title from Various details
1208
-        $context_label = sprintf(
1209
-            __('(%s %s)', 'event_espresso'),
1210
-            $c_config[$context]['label'],
1211
-            ucwords($c_label['label'])
1212
-        );
1213
-        
1214
-        $title = sprintf(
1215
-            __(' %s %s Template %s', 'event_espresso'),
1216
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1217
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1218
-            $context_label
1219
-        );
1220
-        
1221
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1222
-        $this->_template_args['message_template'] = $message_template_group;
1223
-        $this->_template_args['is_extra_fields']  = false;
1224
-        
1225
-        
1226
-        //let's get EEH_MSG_Template so we can get template form fields
1227
-        $template_field_structure = EEH_MSG_Template::get_fields(
1228
-            $message_template_group->messenger(),
1229
-            $message_template_group->message_type()
1230
-        );
1231
-        
1232
-        if ( ! $template_field_structure) {
1233
-            $template_field_structure = false;
1234
-            $template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1235
-                'event_espresso');
1236
-        }
1237
-        
1238
-        
1239
-        $message_templates = $message_template_group->context_templates();
1240
-        
1241
-        
1242
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1243
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1244
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1245
-                unset($template_field_structure[$context][$reference_field]);
1246
-            }
1247
-        }
1248
-        
1249
-        //let's loop through the template_field_structure and actually assemble the input fields!
1250
-        if ( ! empty($template_field_structure)) {
1251
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1252
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1253
-                if ($template_field == 'extra') {
1254
-                    $this->_template_args['is_extra_fields'] = true;
1255
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1256
-                        $message_template = $message_templates[$context][$reference_field];
1257
-                        $content          = $message_template instanceof EE_Message_Template
1258
-                            ? $message_template->get('MTP_content')
1259
-                            : '';
1260
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1261
-                            //let's verify if we need this extra field via the shortcodes parameter.
1262
-                            $continue = false;
1263
-                            if (isset($extra_array['shortcodes_required'])) {
1264
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1265
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1266
-                                        $continue = true;
1267
-                                    }
1268
-                                }
1269
-                                if ($continue) {
1270
-                                    continue;
1271
-                                }
1272
-                            }
1062
+		}
1063
+        
1064
+		return $templates;
1065
+	}
1066
+    
1067
+    
1068
+	/**
1069
+	 * filters etc might need a list of installed message_types
1070
+	 * @return array an array of message type objects
1071
+	 */
1072
+	public function get_installed_message_types()
1073
+	{
1074
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1075
+		$installed               = array();
1076
+        
1077
+		foreach ($installed_message_types as $message_type) {
1078
+			$installed[$message_type->name] = $message_type;
1079
+		}
1080
+        
1081
+		return $installed;
1082
+	}
1083
+    
1084
+    
1085
+	/**
1086
+	 * _add_message_template
1087
+	 *
1088
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1089
+	 *
1090
+	 * @param string $message_type
1091
+	 * @param string $messenger
1092
+	 * @param string $GRP_ID
1093
+	 *
1094
+	 * @throws EE_error
1095
+	 */
1096
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1097
+	{
1098
+		//set values override any request data
1099
+		$message_type = ! empty($message_type) ? $message_type : '';
1100
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1101
+        
1102
+		$messenger = ! empty($messenger) ? $messenger : '';
1103
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1104
+        
1105
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1106
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1107
+        
1108
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1109
+		if (empty($message_type) || empty($messenger)) {
1110
+			throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1111
+				'event_espresso'));
1112
+		}
1113
+        
1114
+		//we need the GRP_ID for the template being used as the base for the new template
1115
+		if (empty($GRP_ID)) {
1116
+			throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1117
+				'event_espresso'));
1118
+		}
1119
+        
1120
+		//let's just make sure the template gets generated!
1121
+        
1122
+		//we need to reassign some variables for what the insert is expecting
1123
+		$this->_req_data['MTP_messenger']    = $messenger;
1124
+		$this->_req_data['MTP_message_type'] = $message_type;
1125
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1126
+		$this->_insert_or_update_message_template(true);
1127
+	}
1128
+    
1129
+    
1130
+	/**
1131
+	 * public wrapper for the _add_message_template method
1132
+	 *
1133
+	 * @param string $message_type     message type slug
1134
+	 * @param string $messenger        messenger slug
1135
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1136
+	 *                                 off of.
1137
+	 */
1138
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1139
+	{
1140
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1141
+	}
1142
+    
1143
+    
1144
+	/**
1145
+	 * _edit_message_template
1146
+	 *
1147
+	 * @access protected
1148
+	 * @return void
1149
+	 */
1150
+	protected function _edit_message_template()
1151
+	{
1152
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1153
+		$template_fields = '';
1154
+		$sidebar_fields  = '';
1155
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1156
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1157
+        
1158
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1159
+			? absint($this->_req_data['id'])
1160
+			: false;
1161
+        
1162
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1163
+		$message_template_group = $this->_message_template_group;
1164
+		$c_label                = $message_template_group->context_label();
1165
+		$c_config               = $message_template_group->contexts_config();
1166
+        
1167
+		reset($c_config);
1168
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1169
+			? strtolower($this->_req_data['context'])
1170
+			: key($c_config);
1171
+        
1172
+        
1173
+		if (empty($GRP_ID)) {
1174
+			$action = 'insert_message_template';
1175
+			//$button_both = false;
1176
+			//$button_text = array( __( 'Save','event_espresso') );
1177
+			//$button_actions = array('something_different');
1178
+			//$referrer = false;
1179
+			$edit_message_template_form_url = add_query_arg(
1180
+				array('action' => $action, 'noheader' => true),
1181
+				EE_MSG_ADMIN_URL
1182
+			);
1183
+		} else {
1184
+			$action = 'update_message_template';
1185
+			//$button_both = true;
1186
+			//$button_text = array();
1187
+			//$button_actions = array();
1188
+			//$referrer = $this->_admin_base_url;
1189
+			$edit_message_template_form_url = add_query_arg(
1190
+				array('action' => $action, 'noheader' => true),
1191
+				EE_MSG_ADMIN_URL
1192
+			);
1193
+		}
1194
+        
1195
+		//set active messenger for this view
1196
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1197
+			$message_template_group->messenger()
1198
+		);
1199
+		$this->_active_message_type_name = $message_template_group->message_type();
1200
+        
1201
+        
1202
+		//Do we have any validation errors?
1203
+		$validators = $this->_get_transient();
1204
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1205
+        
1206
+        
1207
+		//we need to assemble the title from Various details
1208
+		$context_label = sprintf(
1209
+			__('(%s %s)', 'event_espresso'),
1210
+			$c_config[$context]['label'],
1211
+			ucwords($c_label['label'])
1212
+		);
1213
+        
1214
+		$title = sprintf(
1215
+			__(' %s %s Template %s', 'event_espresso'),
1216
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1217
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1218
+			$context_label
1219
+		);
1220
+        
1221
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1222
+		$this->_template_args['message_template'] = $message_template_group;
1223
+		$this->_template_args['is_extra_fields']  = false;
1224
+        
1225
+        
1226
+		//let's get EEH_MSG_Template so we can get template form fields
1227
+		$template_field_structure = EEH_MSG_Template::get_fields(
1228
+			$message_template_group->messenger(),
1229
+			$message_template_group->message_type()
1230
+		);
1231
+        
1232
+		if ( ! $template_field_structure) {
1233
+			$template_field_structure = false;
1234
+			$template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1235
+				'event_espresso');
1236
+		}
1237
+        
1238
+        
1239
+		$message_templates = $message_template_group->context_templates();
1240
+        
1241
+        
1242
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1243
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1244
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1245
+				unset($template_field_structure[$context][$reference_field]);
1246
+			}
1247
+		}
1248
+        
1249
+		//let's loop through the template_field_structure and actually assemble the input fields!
1250
+		if ( ! empty($template_field_structure)) {
1251
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1252
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1253
+				if ($template_field == 'extra') {
1254
+					$this->_template_args['is_extra_fields'] = true;
1255
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1256
+						$message_template = $message_templates[$context][$reference_field];
1257
+						$content          = $message_template instanceof EE_Message_Template
1258
+							? $message_template->get('MTP_content')
1259
+							: '';
1260
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1261
+							//let's verify if we need this extra field via the shortcodes parameter.
1262
+							$continue = false;
1263
+							if (isset($extra_array['shortcodes_required'])) {
1264
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1265
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1266
+										$continue = true;
1267
+									}
1268
+								}
1269
+								if ($continue) {
1270
+									continue;
1271
+								}
1272
+							}
1273 1273
                             
1274
-                            $field_id                                = $reference_field . '-' . $extra_field . '-content';
1275
-                            $template_form_fields[$field_id]         = $extra_array;
1276
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1277
-                            $css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1274
+							$field_id                                = $reference_field . '-' . $extra_field . '-content';
1275
+							$template_form_fields[$field_id]         = $extra_array;
1276
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1277
+							$css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1278 1278
                             
1279
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1280
-                                                                            && in_array($extra_field, $v_fields)
1281
-                                                                            &&
1282
-                                                                            (
1283
-                                                                                is_array($validators[$extra_field])
1284
-                                                                                && isset($validators[$extra_field]['msg'])
1285
-                                                                            )
1286
-                                ? 'validate-error ' . $css_class
1287
-                                : $css_class;
1279
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1280
+																			&& in_array($extra_field, $v_fields)
1281
+																			&&
1282
+																			(
1283
+																				is_array($validators[$extra_field])
1284
+																				&& isset($validators[$extra_field]['msg'])
1285
+																			)
1286
+								? 'validate-error ' . $css_class
1287
+								: $css_class;
1288 1288
                             
1289
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1290
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1291
-                                : '';
1289
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1290
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1291
+								: '';
1292 1292
                             
1293
-                            //do we have a validation error?  if we do then let's use that value instead
1294
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1293
+							//do we have a validation error?  if we do then let's use that value instead
1294
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1295 1295
                             
1296 1296
                             
1297
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1297
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1298 1298
                             
1299
-                            //shortcode selector
1300
-                            $field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1301
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1302
-                                $field_name_to_use,
1303
-                                $field_id
1304
-                            );
1299
+							//shortcode selector
1300
+							$field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1301
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1302
+								$field_name_to_use,
1303
+								$field_id
1304
+							);
1305 1305
                             
1306
-                            if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1307
-                                //we want to decode the entities
1308
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1309
-                                    html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1310
-                                );
1306
+							if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1307
+								//we want to decode the entities
1308
+								$template_form_fields[$field_id]['value'] = stripslashes(
1309
+									html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1310
+								);
1311 1311
                                 
1312
-                            }/**/
1313
-                        }
1314
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1315
-                        $templatefield_templatename_id = $reference_field . '-name';
1312
+							}/**/
1313
+						}
1314
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1315
+						$templatefield_templatename_id = $reference_field . '-name';
1316 1316
                         
1317
-                        $template_form_fields[$templatefield_MTP_id] = array(
1318
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1319
-                            'label'      => null,
1320
-                            'input'      => 'hidden',
1321
-                            'type'       => 'int',
1322
-                            'required'   => false,
1323
-                            'validation' => false,
1324
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1325
-                            'css_class'  => '',
1326
-                            'format'     => '%d',
1327
-                            'db-col'     => 'MTP_ID'
1328
-                        );
1317
+						$template_form_fields[$templatefield_MTP_id] = array(
1318
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1319
+							'label'      => null,
1320
+							'input'      => 'hidden',
1321
+							'type'       => 'int',
1322
+							'required'   => false,
1323
+							'validation' => false,
1324
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1325
+							'css_class'  => '',
1326
+							'format'     => '%d',
1327
+							'db-col'     => 'MTP_ID'
1328
+						);
1329 1329
                         
1330
-                        $template_form_fields[$templatefield_templatename_id] = array(
1331
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1332
-                            'label'      => null,
1333
-                            'input'      => 'hidden',
1334
-                            'type'       => 'string',
1335
-                            'required'   => false,
1336
-                            'validation' => true,
1337
-                            'value'      => $reference_field,
1338
-                            'css_class'  => '',
1339
-                            'format'     => '%s',
1340
-                            'db-col'     => 'MTP_template_field'
1341
-                        );
1342
-                    }
1343
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1344
-                } else {
1345
-                    $field_id                                 = $template_field . '-content';
1346
-                    $template_form_fields[$field_id]          = $field_setup_array;
1347
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1348
-                    $message_template                         = isset($message_templates[$context][$template_field])
1349
-                        ? $message_templates[$context][$template_field]
1350
-                        : null;
1351
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1352
-                                                                && is_array($message_templates[$context])
1353
-                                                                && $message_template instanceof EE_Message_Template
1354
-                        ? $message_template->get('MTP_content')
1355
-                        : '';
1330
+						$template_form_fields[$templatefield_templatename_id] = array(
1331
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1332
+							'label'      => null,
1333
+							'input'      => 'hidden',
1334
+							'type'       => 'string',
1335
+							'required'   => false,
1336
+							'validation' => true,
1337
+							'value'      => $reference_field,
1338
+							'css_class'  => '',
1339
+							'format'     => '%s',
1340
+							'db-col'     => 'MTP_template_field'
1341
+						);
1342
+					}
1343
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1344
+				} else {
1345
+					$field_id                                 = $template_field . '-content';
1346
+					$template_form_fields[$field_id]          = $field_setup_array;
1347
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1348
+					$message_template                         = isset($message_templates[$context][$template_field])
1349
+						? $message_templates[$context][$template_field]
1350
+						: null;
1351
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1352
+																&& is_array($message_templates[$context])
1353
+																&& $message_template instanceof EE_Message_Template
1354
+						? $message_template->get('MTP_content')
1355
+						: '';
1356 1356
                     
1357
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1358
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1359
-                        ? $validators[$template_field]['value']
1360
-                        : $template_form_fields[$field_id]['value'];
1357
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1358
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1359
+						? $validators[$template_field]['value']
1360
+						: $template_form_fields[$field_id]['value'];
1361 1361
                     
1362 1362
                     
1363
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1364
-                    $css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1365
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1366
-                                                                    && in_array($template_field, $v_fields)
1367
-                                                                    && isset($validators[$template_field]['msg'])
1368
-                        ? 'validate-error ' . $css_class
1369
-                        : $css_class;
1363
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1364
+					$css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1365
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1366
+																	&& in_array($template_field, $v_fields)
1367
+																	&& isset($validators[$template_field]['msg'])
1368
+						? 'validate-error ' . $css_class
1369
+						: $css_class;
1370 1370
                     
1371
-                    //shortcode selector
1372
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1373
-                        $template_field, $field_id
1374
-                    );
1375
-                }
1371
+					//shortcode selector
1372
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1373
+						$template_field, $field_id
1374
+					);
1375
+				}
1376 1376
                 
1377
-                //k took care of content field(s) now let's take care of others.
1377
+				//k took care of content field(s) now let's take care of others.
1378 1378
                 
1379
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1380
-                $templatefield_field_templatename_id = $template_field . '-name';
1379
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1380
+				$templatefield_field_templatename_id = $template_field . '-name';
1381 1381
                 
1382
-                //foreach template field there are actually two form fields created
1383
-                $template_form_fields[$templatefield_MTP_id] = array(
1384
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1385
-                    'label'      => null,
1386
-                    'input'      => 'hidden',
1387
-                    'type'       => 'int',
1388
-                    'required'   => false,
1389
-                    'validation' => true,
1390
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1391
-                    'css_class'  => '',
1392
-                    'format'     => '%d',
1393
-                    'db-col'     => 'MTP_ID'
1394
-                );
1382
+				//foreach template field there are actually two form fields created
1383
+				$template_form_fields[$templatefield_MTP_id] = array(
1384
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1385
+					'label'      => null,
1386
+					'input'      => 'hidden',
1387
+					'type'       => 'int',
1388
+					'required'   => false,
1389
+					'validation' => true,
1390
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1391
+					'css_class'  => '',
1392
+					'format'     => '%d',
1393
+					'db-col'     => 'MTP_ID'
1394
+				);
1395 1395
                 
1396
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1397
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1398
-                    'label'      => null,
1399
-                    'input'      => 'hidden',
1400
-                    'type'       => 'string',
1401
-                    'required'   => false,
1402
-                    'validation' => true,
1403
-                    'value'      => $template_field,
1404
-                    'css_class'  => '',
1405
-                    'format'     => '%s',
1406
-                    'db-col'     => 'MTP_template_field'
1407
-                );
1396
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1397
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1398
+					'label'      => null,
1399
+					'input'      => 'hidden',
1400
+					'type'       => 'string',
1401
+					'required'   => false,
1402
+					'validation' => true,
1403
+					'value'      => $template_field,
1404
+					'css_class'  => '',
1405
+					'format'     => '%s',
1406
+					'db-col'     => 'MTP_template_field'
1407
+				);
1408 1408
                 
1409
-            }
1409
+			}
1410 1410
             
1411
-            //add other fields
1412
-            $template_form_fields['ee-msg-current-context'] = array(
1413
-                'name'       => 'MTP_context',
1414
-                'label'      => null,
1415
-                'input'      => 'hidden',
1416
-                'type'       => 'string',
1417
-                'required'   => false,
1418
-                'validation' => true,
1419
-                'value'      => $context,
1420
-                'css_class'  => '',
1421
-                'format'     => '%s',
1422
-                'db-col'     => 'MTP_context'
1423
-            );
1411
+			//add other fields
1412
+			$template_form_fields['ee-msg-current-context'] = array(
1413
+				'name'       => 'MTP_context',
1414
+				'label'      => null,
1415
+				'input'      => 'hidden',
1416
+				'type'       => 'string',
1417
+				'required'   => false,
1418
+				'validation' => true,
1419
+				'value'      => $context,
1420
+				'css_class'  => '',
1421
+				'format'     => '%s',
1422
+				'db-col'     => 'MTP_context'
1423
+			);
1424 1424
             
1425
-            $template_form_fields['ee-msg-grp-id'] = array(
1426
-                'name'       => 'GRP_ID',
1427
-                'label'      => null,
1428
-                'input'      => 'hidden',
1429
-                'type'       => 'int',
1430
-                'required'   => false,
1431
-                'validation' => true,
1432
-                'value'      => $GRP_ID,
1433
-                'css_class'  => '',
1434
-                'format'     => '%d',
1435
-                'db-col'     => 'GRP_ID'
1436
-            );
1425
+			$template_form_fields['ee-msg-grp-id'] = array(
1426
+				'name'       => 'GRP_ID',
1427
+				'label'      => null,
1428
+				'input'      => 'hidden',
1429
+				'type'       => 'int',
1430
+				'required'   => false,
1431
+				'validation' => true,
1432
+				'value'      => $GRP_ID,
1433
+				'css_class'  => '',
1434
+				'format'     => '%d',
1435
+				'db-col'     => 'GRP_ID'
1436
+			);
1437 1437
             
1438
-            $template_form_fields['ee-msg-messenger'] = array(
1439
-                'name'       => 'MTP_messenger',
1440
-                'label'      => null,
1441
-                'input'      => 'hidden',
1442
-                'type'       => 'string',
1443
-                'required'   => false,
1444
-                'validation' => true,
1445
-                'value'      => $message_template_group->messenger(),
1446
-                'css_class'  => '',
1447
-                'format'     => '%s',
1448
-                'db-col'     => 'MTP_messenger'
1449
-            );
1438
+			$template_form_fields['ee-msg-messenger'] = array(
1439
+				'name'       => 'MTP_messenger',
1440
+				'label'      => null,
1441
+				'input'      => 'hidden',
1442
+				'type'       => 'string',
1443
+				'required'   => false,
1444
+				'validation' => true,
1445
+				'value'      => $message_template_group->messenger(),
1446
+				'css_class'  => '',
1447
+				'format'     => '%s',
1448
+				'db-col'     => 'MTP_messenger'
1449
+			);
1450 1450
             
1451
-            $template_form_fields['ee-msg-message-type'] = array(
1452
-                'name'       => 'MTP_message_type',
1453
-                'label'      => null,
1454
-                'input'      => 'hidden',
1455
-                'type'       => 'string',
1456
-                'required'   => false,
1457
-                'validation' => true,
1458
-                'value'      => $message_template_group->message_type(),
1459
-                'css_class'  => '',
1460
-                'format'     => '%s',
1461
-                'db-col'     => 'MTP_message_type'
1462
-            );
1451
+			$template_form_fields['ee-msg-message-type'] = array(
1452
+				'name'       => 'MTP_message_type',
1453
+				'label'      => null,
1454
+				'input'      => 'hidden',
1455
+				'type'       => 'string',
1456
+				'required'   => false,
1457
+				'validation' => true,
1458
+				'value'      => $message_template_group->message_type(),
1459
+				'css_class'  => '',
1460
+				'format'     => '%s',
1461
+				'db-col'     => 'MTP_message_type'
1462
+			);
1463 1463
             
1464
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1465
-                'name'       => 'MTP_is_global',
1466
-                'label'      => __('Global Template', 'event_espresso'),
1467
-                'input'      => 'hidden',
1468
-                'type'       => 'int',
1469
-                'required'   => false,
1470
-                'validation' => true,
1471
-                'value'      => $message_template_group->get('MTP_is_global'),
1472
-                'css_class'  => '',
1473
-                'format'     => '%d',
1474
-                'db-col'     => 'MTP_is_global'
1475
-            );
1464
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1465
+				'name'       => 'MTP_is_global',
1466
+				'label'      => __('Global Template', 'event_espresso'),
1467
+				'input'      => 'hidden',
1468
+				'type'       => 'int',
1469
+				'required'   => false,
1470
+				'validation' => true,
1471
+				'value'      => $message_template_group->get('MTP_is_global'),
1472
+				'css_class'  => '',
1473
+				'format'     => '%d',
1474
+				'db-col'     => 'MTP_is_global'
1475
+			);
1476 1476
             
1477
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1478
-                'name'       => 'MTP_is_override',
1479
-                'label'      => __('Override all custom', 'event_espresso'),
1480
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1481
-                'type'       => 'int',
1482
-                'required'   => false,
1483
-                'validation' => true,
1484
-                'value'      => $message_template_group->get('MTP_is_override'),
1485
-                'css_class'  => '',
1486
-                'format'     => '%d',
1487
-                'db-col'     => 'MTP_is_override'
1488
-            );
1477
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1478
+				'name'       => 'MTP_is_override',
1479
+				'label'      => __('Override all custom', 'event_espresso'),
1480
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1481
+				'type'       => 'int',
1482
+				'required'   => false,
1483
+				'validation' => true,
1484
+				'value'      => $message_template_group->get('MTP_is_override'),
1485
+				'css_class'  => '',
1486
+				'format'     => '%d',
1487
+				'db-col'     => 'MTP_is_override'
1488
+			);
1489 1489
             
1490
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1491
-                'name'       => 'MTP_is_active',
1492
-                'label'      => __('Active Template', 'event_espresso'),
1493
-                'input'      => 'hidden',
1494
-                'type'       => 'int',
1495
-                'required'   => false,
1496
-                'validation' => true,
1497
-                'value'      => $message_template_group->is_active(),
1498
-                'css_class'  => '',
1499
-                'format'     => '%d',
1500
-                'db-col'     => 'MTP_is_active'
1501
-            );
1490
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1491
+				'name'       => 'MTP_is_active',
1492
+				'label'      => __('Active Template', 'event_espresso'),
1493
+				'input'      => 'hidden',
1494
+				'type'       => 'int',
1495
+				'required'   => false,
1496
+				'validation' => true,
1497
+				'value'      => $message_template_group->is_active(),
1498
+				'css_class'  => '',
1499
+				'format'     => '%d',
1500
+				'db-col'     => 'MTP_is_active'
1501
+			);
1502 1502
             
1503
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1504
-                'name'       => 'MTP_deleted',
1505
-                'label'      => null,
1506
-                'input'      => 'hidden',
1507
-                'type'       => 'int',
1508
-                'required'   => false,
1509
-                'validation' => true,
1510
-                'value'      => $message_template_group->get('MTP_deleted'),
1511
-                'css_class'  => '',
1512
-                'format'     => '%d',
1513
-                'db-col'     => 'MTP_deleted'
1514
-            );
1515
-            $sidebar_form_fields['ee-msg-author']  = array(
1516
-                'name'       => 'MTP_user_id',
1517
-                'label'      => __('Author', 'event_espresso'),
1518
-                'input'      => 'hidden',
1519
-                'type'       => 'int',
1520
-                'required'   => false,
1521
-                'validation' => false,
1522
-                'value'      => $message_template_group->user(),
1523
-                'format'     => '%d',
1524
-                'db-col'     => 'MTP_user_id'
1525
-            );
1503
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1504
+				'name'       => 'MTP_deleted',
1505
+				'label'      => null,
1506
+				'input'      => 'hidden',
1507
+				'type'       => 'int',
1508
+				'required'   => false,
1509
+				'validation' => true,
1510
+				'value'      => $message_template_group->get('MTP_deleted'),
1511
+				'css_class'  => '',
1512
+				'format'     => '%d',
1513
+				'db-col'     => 'MTP_deleted'
1514
+			);
1515
+			$sidebar_form_fields['ee-msg-author']  = array(
1516
+				'name'       => 'MTP_user_id',
1517
+				'label'      => __('Author', 'event_espresso'),
1518
+				'input'      => 'hidden',
1519
+				'type'       => 'int',
1520
+				'required'   => false,
1521
+				'validation' => false,
1522
+				'value'      => $message_template_group->user(),
1523
+				'format'     => '%d',
1524
+				'db-col'     => 'MTP_user_id'
1525
+			);
1526 1526
             
1527
-            $sidebar_form_fields['ee-msg-route'] = array(
1528
-                'name'  => 'action',
1529
-                'input' => 'hidden',
1530
-                'type'  => 'string',
1531
-                'value' => $action
1532
-            );
1527
+			$sidebar_form_fields['ee-msg-route'] = array(
1528
+				'name'  => 'action',
1529
+				'input' => 'hidden',
1530
+				'type'  => 'string',
1531
+				'value' => $action
1532
+			);
1533 1533
             
1534
-            $sidebar_form_fields['ee-msg-id']        = array(
1535
-                'name'  => 'id',
1536
-                'input' => 'hidden',
1537
-                'type'  => 'int',
1538
-                'value' => $GRP_ID
1539
-            );
1540
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1541
-                'name'  => $action . '_nonce',
1542
-                'input' => 'hidden',
1543
-                'type'  => 'string',
1544
-                'value' => wp_create_nonce($action . '_nonce')
1545
-            );
1534
+			$sidebar_form_fields['ee-msg-id']        = array(
1535
+				'name'  => 'id',
1536
+				'input' => 'hidden',
1537
+				'type'  => 'int',
1538
+				'value' => $GRP_ID
1539
+			);
1540
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1541
+				'name'  => $action . '_nonce',
1542
+				'input' => 'hidden',
1543
+				'type'  => 'string',
1544
+				'value' => wp_create_nonce($action . '_nonce')
1545
+			);
1546 1546
             
1547
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1548
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1549
-                    'name'  => 'template_switch',
1550
-                    'input' => 'hidden',
1551
-                    'type'  => 'int',
1552
-                    'value' => 1
1553
-                );
1554
-            }
1547
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1548
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1549
+					'name'  => 'template_switch',
1550
+					'input' => 'hidden',
1551
+					'type'  => 'int',
1552
+					'value' => 1
1553
+				);
1554
+			}
1555 1555
             
1556 1556
             
1557
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1558
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1557
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1558
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1559 1559
             
1560 1560
             
1561
-        } //end if ( !empty($template_field_structure) )
1561
+		} //end if ( !empty($template_field_structure) )
1562 1562
         
1563
-        //set extra content for publish box
1564
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1565
-        $this->_set_publish_post_box_vars(
1566
-            'id',
1567
-            $GRP_ID,
1568
-            false,
1569
-            add_query_arg(
1570
-                array('action' => 'global_mtps'),
1571
-                $this->_admin_base_url
1572
-            )
1573
-        );
1574
-        
1575
-        //add preview button
1576
-        $preview_url    = parent::add_query_args_and_nonce(
1577
-            array(
1578
-                'message_type' => $message_template_group->message_type(),
1579
-                'messenger'    => $message_template_group->messenger(),
1580
-                'context'      => $context,
1581
-                'GRP_ID'       => $GRP_ID,
1582
-                'action'       => 'preview_message'
1583
-            ),
1584
-            $this->_admin_base_url
1585
-        );
1586
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1587
-                'event_espresso') . '</a>';
1588
-        
1589
-        
1590
-        //setup context switcher
1591
-        $context_switcher_args = array(
1592
-            'page'    => 'espresso_messages',
1593
-            'action'  => 'edit_message_template',
1594
-            'id'      => $GRP_ID,
1595
-            'context' => $context,
1596
-            'extra'   => $preview_button
1597
-        );
1598
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1599
-        
1600
-        
1601
-        //main box
1602
-        $this->_template_args['template_fields']                         = $template_fields;
1603
-        $this->_template_args['sidebar_box_id']                          = 'details';
1604
-        $this->_template_args['action']                                  = $action;
1605
-        $this->_template_args['context']                                 = $context;
1606
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1607
-        $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1608
-        
1609
-        
1610
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1611
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1612
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1613
-        
1614
-        $this->_template_path = $this->_template_args['GRP_ID']
1615
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1616
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1617
-        
1618
-        //send along EE_Message_Template_Group object for further template use.
1619
-        $this->_template_args['MTP'] = $message_template_group;
1620
-        
1621
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1622
-            $this->_template_args, true);
1623
-        
1624
-        
1625
-        //finally, let's set the admin_page title
1626
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1627
-        
1628
-        
1629
-        //we need to take care of setting the shortcodes property for use elsewhere.
1630
-        $this->_set_shortcodes();
1631
-        
1632
-        
1633
-        //final template wrapper
1634
-        $this->display_admin_page_with_sidebar();
1635
-    }
1636
-    
1637
-    
1638
-    public function filter_tinymce_init($mceInit, $editor_id)
1639
-    {
1640
-        return $mceInit;
1641
-    }
1642
-    
1643
-    
1644
-    public function add_context_switcher()
1645
-    {
1646
-        return $this->_context_switcher;
1647
-    }
1648
-    
1649
-    public function _add_form_element_before()
1650
-    {
1651
-        return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1652
-    }
1653
-    
1654
-    public function _add_form_element_after()
1655
-    {
1656
-        return '</form>';
1657
-    }
1658
-    
1659
-    
1660
-    /**
1661
-     * This executes switching the template pack for a message template.
1662
-     *
1663
-     * @since 4.5.0
1664
-     *
1665
-     */
1666
-    public function switch_template_pack()
1667
-    {
1668
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1669
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1670
-        
1671
-        //verify we have needed values.
1672
-        if (empty($GRP_ID) || empty($template_pack)) {
1673
-            $this->_template_args['error'] = true;
1674
-            EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1675
-                __FILE__, __FUNCTION__, __LINE__);
1676
-        } else {
1677
-            //get template, set the new template_pack and then reset to default
1678
-            /** @type EE_Message_Template_Group $message_template_group */
1679
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1563
+		//set extra content for publish box
1564
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1565
+		$this->_set_publish_post_box_vars(
1566
+			'id',
1567
+			$GRP_ID,
1568
+			false,
1569
+			add_query_arg(
1570
+				array('action' => 'global_mtps'),
1571
+				$this->_admin_base_url
1572
+			)
1573
+		);
1574
+        
1575
+		//add preview button
1576
+		$preview_url    = parent::add_query_args_and_nonce(
1577
+			array(
1578
+				'message_type' => $message_template_group->message_type(),
1579
+				'messenger'    => $message_template_group->messenger(),
1580
+				'context'      => $context,
1581
+				'GRP_ID'       => $GRP_ID,
1582
+				'action'       => 'preview_message'
1583
+			),
1584
+			$this->_admin_base_url
1585
+		);
1586
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1587
+				'event_espresso') . '</a>';
1588
+        
1589
+        
1590
+		//setup context switcher
1591
+		$context_switcher_args = array(
1592
+			'page'    => 'espresso_messages',
1593
+			'action'  => 'edit_message_template',
1594
+			'id'      => $GRP_ID,
1595
+			'context' => $context,
1596
+			'extra'   => $preview_button
1597
+		);
1598
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1599
+        
1600
+        
1601
+		//main box
1602
+		$this->_template_args['template_fields']                         = $template_fields;
1603
+		$this->_template_args['sidebar_box_id']                          = 'details';
1604
+		$this->_template_args['action']                                  = $action;
1605
+		$this->_template_args['context']                                 = $context;
1606
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1607
+		$this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1608
+        
1609
+        
1610
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1611
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1612
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1613
+        
1614
+		$this->_template_path = $this->_template_args['GRP_ID']
1615
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1616
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1617
+        
1618
+		//send along EE_Message_Template_Group object for further template use.
1619
+		$this->_template_args['MTP'] = $message_template_group;
1620
+        
1621
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1622
+			$this->_template_args, true);
1623
+        
1624
+        
1625
+		//finally, let's set the admin_page title
1626
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1627
+        
1628
+        
1629
+		//we need to take care of setting the shortcodes property for use elsewhere.
1630
+		$this->_set_shortcodes();
1631
+        
1632
+        
1633
+		//final template wrapper
1634
+		$this->display_admin_page_with_sidebar();
1635
+	}
1636
+    
1637
+    
1638
+	public function filter_tinymce_init($mceInit, $editor_id)
1639
+	{
1640
+		return $mceInit;
1641
+	}
1642
+    
1643
+    
1644
+	public function add_context_switcher()
1645
+	{
1646
+		return $this->_context_switcher;
1647
+	}
1648
+    
1649
+	public function _add_form_element_before()
1650
+	{
1651
+		return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1652
+	}
1653
+    
1654
+	public function _add_form_element_after()
1655
+	{
1656
+		return '</form>';
1657
+	}
1658
+    
1659
+    
1660
+	/**
1661
+	 * This executes switching the template pack for a message template.
1662
+	 *
1663
+	 * @since 4.5.0
1664
+	 *
1665
+	 */
1666
+	public function switch_template_pack()
1667
+	{
1668
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1669
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1670
+        
1671
+		//verify we have needed values.
1672
+		if (empty($GRP_ID) || empty($template_pack)) {
1673
+			$this->_template_args['error'] = true;
1674
+			EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1675
+				__FILE__, __FUNCTION__, __LINE__);
1676
+		} else {
1677
+			//get template, set the new template_pack and then reset to default
1678
+			/** @type EE_Message_Template_Group $message_template_group */
1679
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1680 1680
             
1681
-            $message_template_group->set_template_pack_name($template_pack);
1682
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1683
-            $this->_req_data['mt']   = $message_template_group->message_type();
1681
+			$message_template_group->set_template_pack_name($template_pack);
1682
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1683
+			$this->_req_data['mt']   = $message_template_group->message_type();
1684 1684
             
1685
-            $query_args = $this->_reset_to_default_template();
1685
+			$query_args = $this->_reset_to_default_template();
1686 1686
             
1687
-            if (empty($query_args['id'])) {
1688
-                EE_Error::add_error(
1689
-                    __(
1690
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1691
-                        'event_espresso'
1692
-                    ),
1693
-                    __FILE__, __FUNCTION__, __LINE__
1694
-                );
1695
-                $this->_template_args['error'] = true;
1696
-            } else {
1697
-                $template_label       = $message_template_group->get_template_pack()->label;
1698
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1699
-                EE_Error::add_success(
1700
-                    sprintf(
1701
-                        __(
1702
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1703
-                            'event_espresso'
1704
-                        ),
1705
-                        $template_label,
1706
-                        $template_pack_labels->template_pack
1707
-                    )
1708
-                );
1709
-                //generate the redirect url for js.
1710
-                $url                                          = self::add_query_args_and_nonce($query_args,
1711
-                    $this->_admin_base_url);
1712
-                $this->_template_args['data']['redirect_url'] = $url;
1713
-                $this->_template_args['success']              = true;
1714
-            }
1687
+			if (empty($query_args['id'])) {
1688
+				EE_Error::add_error(
1689
+					__(
1690
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1691
+						'event_espresso'
1692
+					),
1693
+					__FILE__, __FUNCTION__, __LINE__
1694
+				);
1695
+				$this->_template_args['error'] = true;
1696
+			} else {
1697
+				$template_label       = $message_template_group->get_template_pack()->label;
1698
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1699
+				EE_Error::add_success(
1700
+					sprintf(
1701
+						__(
1702
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1703
+							'event_espresso'
1704
+						),
1705
+						$template_label,
1706
+						$template_pack_labels->template_pack
1707
+					)
1708
+				);
1709
+				//generate the redirect url for js.
1710
+				$url                                          = self::add_query_args_and_nonce($query_args,
1711
+					$this->_admin_base_url);
1712
+				$this->_template_args['data']['redirect_url'] = $url;
1713
+				$this->_template_args['success']              = true;
1714
+			}
1715 1715
             
1716
-            $this->_return_json();
1716
+			$this->_return_json();
1717 1717
             
1718
-        }
1719
-    }
1720
-    
1721
-    
1722
-    /**
1723
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1724
-     * they want.
1725
-     *
1726
-     * @access protected
1727
-     * @return array|null
1728
-     */
1729
-    protected function _reset_to_default_template()
1730
-    {
1731
-        
1732
-        $templates = array();
1733
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1734
-        //we need to make sure we've got the info we need.
1735
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1736
-            EE_Error::add_error(
1737
-                __(
1738
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
1739
-                    'event_espresso'
1740
-                ),
1741
-                __FILE__, __FUNCTION__, __LINE__
1742
-            );
1743
-        }
1744
-        
1745
-        // all templates will be reset to whatever the defaults are
1746
-        // for the global template matching the messenger and message type.
1747
-        $success = ! empty($GRP_ID) ? true : false;
1748
-        
1749
-        if ($success) {
1718
+		}
1719
+	}
1720
+    
1721
+    
1722
+	/**
1723
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1724
+	 * they want.
1725
+	 *
1726
+	 * @access protected
1727
+	 * @return array|null
1728
+	 */
1729
+	protected function _reset_to_default_template()
1730
+	{
1731
+        
1732
+		$templates = array();
1733
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1734
+		//we need to make sure we've got the info we need.
1735
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1736
+			EE_Error::add_error(
1737
+				__(
1738
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
1739
+					'event_espresso'
1740
+				),
1741
+				__FILE__, __FUNCTION__, __LINE__
1742
+			);
1743
+		}
1744
+        
1745
+		// all templates will be reset to whatever the defaults are
1746
+		// for the global template matching the messenger and message type.
1747
+		$success = ! empty($GRP_ID) ? true : false;
1748
+        
1749
+		if ($success) {
1750 1750
             
1751
-            //let's first determine if the incoming template is a global template,
1752
-            // if it isn't then we need to get the global template matching messenger and message type.
1753
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1751
+			//let's first determine if the incoming template is a global template,
1752
+			// if it isn't then we need to get the global template matching messenger and message type.
1753
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1754 1754
             
1755 1755
             
1756
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1757
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
1756
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1757
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
1758 1758
             
1759
-            if ($success) {
1760
-                // if successfully deleted, lets generate the new ones.
1761
-                // Note. We set GLOBAL to true, because resets on ANY template
1762
-                // will use the related global template defaults for regeneration.
1763
-                // This means that if a custom template is reset it resets to whatever the related global template is.
1764
-                // HOWEVER, we DO keep the template pack and template variation set
1765
-                // for the current custom template when resetting.
1766
-                $templates = $this->_generate_new_templates(
1767
-                    $this->_req_data['msgr'],
1768
-                    $this->_req_data['mt'],
1769
-                    $GRP_ID,
1770
-                    true
1771
-                );
1772
-            }
1759
+			if ($success) {
1760
+				// if successfully deleted, lets generate the new ones.
1761
+				// Note. We set GLOBAL to true, because resets on ANY template
1762
+				// will use the related global template defaults for regeneration.
1763
+				// This means that if a custom template is reset it resets to whatever the related global template is.
1764
+				// HOWEVER, we DO keep the template pack and template variation set
1765
+				// for the current custom template when resetting.
1766
+				$templates = $this->_generate_new_templates(
1767
+					$this->_req_data['msgr'],
1768
+					$this->_req_data['mt'],
1769
+					$GRP_ID,
1770
+					true
1771
+				);
1772
+			}
1773 1773
             
1774
-        }
1775
-        
1776
-        //any error messages?
1777
-        if ( ! $success) {
1778
-            EE_Error::add_error(
1779
-                __('Something went wrong with deleting existing templates. Unable to reset to default',
1780
-                    'event_espresso'),
1781
-                __FILE__, __FUNCTION__, __LINE__
1782
-            );
1783
-        }
1784
-        
1785
-        //all good, let's add a success message!
1786
-        if ($success && ! empty($templates)) {
1787
-            $templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1788
-            EE_Error::overwrite_success();
1789
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1790
-        }
1791
-        
1792
-        
1793
-        $query_args = array(
1794
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1795
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1796
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1797
-        );
1798
-        
1799
-        //if called via ajax then we return query args otherwise redirect
1800
-        if (defined('DOING_AJAX') && DOING_AJAX) {
1801
-            return $query_args;
1802
-        } else {
1803
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1774
+		}
1775
+        
1776
+		//any error messages?
1777
+		if ( ! $success) {
1778
+			EE_Error::add_error(
1779
+				__('Something went wrong with deleting existing templates. Unable to reset to default',
1780
+					'event_espresso'),
1781
+				__FILE__, __FUNCTION__, __LINE__
1782
+			);
1783
+		}
1784
+        
1785
+		//all good, let's add a success message!
1786
+		if ($success && ! empty($templates)) {
1787
+			$templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1788
+			EE_Error::overwrite_success();
1789
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1790
+		}
1791
+        
1792
+        
1793
+		$query_args = array(
1794
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1795
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1796
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1797
+		);
1798
+        
1799
+		//if called via ajax then we return query args otherwise redirect
1800
+		if (defined('DOING_AJAX') && DOING_AJAX) {
1801
+			return $query_args;
1802
+		} else {
1803
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1804 1804
             
1805
-            return null;
1806
-        }
1807
-    }
1808
-    
1809
-    
1810
-    /**
1811
-     * Retrieve and set the message preview for display.
1812
-     *
1813
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1814
-     *
1815
-     * @return string
1816
-     */
1817
-    public function _preview_message($send = false)
1818
-    {
1819
-        //first make sure we've got the necessary parameters
1820
-        if (
1821
-        ! isset(
1822
-            $this->_req_data['message_type'],
1823
-            $this->_req_data['messenger'],
1824
-            $this->_req_data['messenger'],
1825
-            $this->_req_data['GRP_ID']
1826
-        )
1827
-        ) {
1828
-            EE_Error::add_error(
1829
-                __('Missing necessary parameters for displaying preview', 'event_espresso'),
1830
-                __FILE__, __FUNCTION__, __LINE__
1831
-            );
1832
-        }
1833
-        
1834
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1835
-        
1836
-        
1837
-        //get the preview!
1838
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1839
-            $this->_req_data['messenger'], $send);
1840
-        
1841
-        if ($send) {
1842
-            return $preview;
1843
-        }
1844
-        
1845
-        //let's add a button to go back to the edit view
1846
-        $query_args             = array(
1847
-            'id'      => $this->_req_data['GRP_ID'],
1848
-            'context' => $this->_req_data['context'],
1849
-            'action'  => 'edit_message_template'
1850
-        );
1851
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1852
-        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1853
-                'event_espresso') . '</a>';
1854
-        $message_types          = $this->get_installed_message_types();
1855
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1856
-        $active_messenger_label = $active_messenger instanceof EE_messenger
1857
-            ? ucwords($active_messenger->label['singular'])
1858
-            : esc_html__('Unknown Messenger', 'event_espresso');
1859
-        //let's provide a helpful title for context
1860
-        $preview_title = sprintf(
1861
-            __('Viewing Preview for %s %s Message Template', 'event_espresso'),
1862
-            $active_messenger_label,
1863
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1864
-        );
1865
-        //setup display of preview.
1866
-        $this->_admin_page_title                    = $preview_title;
1867
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1868
-        $this->_template_args['data']['force_json'] = true;
1869
-        
1870
-        return '';
1871
-    }
1872
-    
1873
-    
1874
-    /**
1875
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1876
-     * gets called automatically.
1877
-     *
1878
-     * @since 4.5.0
1879
-     *
1880
-     * @return string
1881
-     */
1882
-    protected function _display_preview_message()
1883
-    {
1884
-        $this->display_admin_page_with_no_sidebar();
1885
-    }
1886
-    
1887
-    
1888
-    /**
1889
-     * registers metaboxes that should show up on the "edit_message_template" page
1890
-     *
1891
-     * @access protected
1892
-     * @return void
1893
-     */
1894
-    protected function _register_edit_meta_boxes()
1895
-    {
1896
-        add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1897
-            array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1898
-        add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1899
-            $this->_current_screen->id, 'side', 'high');
1900
-        add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1901
-            $this->_current_screen->id, 'side', 'high');
1902
-    }
1903
-    
1904
-    
1905
-    /**
1906
-     * metabox content for all template pack and variation selection.
1907
-     *
1908
-     * @since 4.5.0
1909
-     *
1910
-     * @return string
1911
-     */
1912
-    public function template_pack_meta_box()
1913
-    {
1914
-        $this->_set_message_template_group();
1915
-        
1916
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
1917
-        
1918
-        $tp_select_values = array();
1919
-        
1920
-        foreach ($tp_collection as $tp) {
1921
-            //only include template packs that support this messenger and message type!
1922
-            $supports = $tp->get_supports();
1923
-            if (
1924
-                ! isset($supports[$this->_message_template_group->messenger()])
1925
-                || ! in_array(
1926
-                    $this->_message_template_group->message_type(),
1927
-                    $supports[$this->_message_template_group->messenger()]
1928
-                )
1929
-            ) {
1930
-                //not supported
1931
-                continue;
1932
-            }
1805
+			return null;
1806
+		}
1807
+	}
1808
+    
1809
+    
1810
+	/**
1811
+	 * Retrieve and set the message preview for display.
1812
+	 *
1813
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1814
+	 *
1815
+	 * @return string
1816
+	 */
1817
+	public function _preview_message($send = false)
1818
+	{
1819
+		//first make sure we've got the necessary parameters
1820
+		if (
1821
+		! isset(
1822
+			$this->_req_data['message_type'],
1823
+			$this->_req_data['messenger'],
1824
+			$this->_req_data['messenger'],
1825
+			$this->_req_data['GRP_ID']
1826
+		)
1827
+		) {
1828
+			EE_Error::add_error(
1829
+				__('Missing necessary parameters for displaying preview', 'event_espresso'),
1830
+				__FILE__, __FUNCTION__, __LINE__
1831
+			);
1832
+		}
1833
+        
1834
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1835
+        
1836
+        
1837
+		//get the preview!
1838
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1839
+			$this->_req_data['messenger'], $send);
1840
+        
1841
+		if ($send) {
1842
+			return $preview;
1843
+		}
1844
+        
1845
+		//let's add a button to go back to the edit view
1846
+		$query_args             = array(
1847
+			'id'      => $this->_req_data['GRP_ID'],
1848
+			'context' => $this->_req_data['context'],
1849
+			'action'  => 'edit_message_template'
1850
+		);
1851
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1852
+		$preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1853
+				'event_espresso') . '</a>';
1854
+		$message_types          = $this->get_installed_message_types();
1855
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1856
+		$active_messenger_label = $active_messenger instanceof EE_messenger
1857
+			? ucwords($active_messenger->label['singular'])
1858
+			: esc_html__('Unknown Messenger', 'event_espresso');
1859
+		//let's provide a helpful title for context
1860
+		$preview_title = sprintf(
1861
+			__('Viewing Preview for %s %s Message Template', 'event_espresso'),
1862
+			$active_messenger_label,
1863
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1864
+		);
1865
+		//setup display of preview.
1866
+		$this->_admin_page_title                    = $preview_title;
1867
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1868
+		$this->_template_args['data']['force_json'] = true;
1869
+        
1870
+		return '';
1871
+	}
1872
+    
1873
+    
1874
+	/**
1875
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1876
+	 * gets called automatically.
1877
+	 *
1878
+	 * @since 4.5.0
1879
+	 *
1880
+	 * @return string
1881
+	 */
1882
+	protected function _display_preview_message()
1883
+	{
1884
+		$this->display_admin_page_with_no_sidebar();
1885
+	}
1886
+    
1887
+    
1888
+	/**
1889
+	 * registers metaboxes that should show up on the "edit_message_template" page
1890
+	 *
1891
+	 * @access protected
1892
+	 * @return void
1893
+	 */
1894
+	protected function _register_edit_meta_boxes()
1895
+	{
1896
+		add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1897
+			array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1898
+		add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1899
+			$this->_current_screen->id, 'side', 'high');
1900
+		add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1901
+			$this->_current_screen->id, 'side', 'high');
1902
+	}
1903
+    
1904
+    
1905
+	/**
1906
+	 * metabox content for all template pack and variation selection.
1907
+	 *
1908
+	 * @since 4.5.0
1909
+	 *
1910
+	 * @return string
1911
+	 */
1912
+	public function template_pack_meta_box()
1913
+	{
1914
+		$this->_set_message_template_group();
1915
+        
1916
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
1917
+        
1918
+		$tp_select_values = array();
1919
+        
1920
+		foreach ($tp_collection as $tp) {
1921
+			//only include template packs that support this messenger and message type!
1922
+			$supports = $tp->get_supports();
1923
+			if (
1924
+				! isset($supports[$this->_message_template_group->messenger()])
1925
+				|| ! in_array(
1926
+					$this->_message_template_group->message_type(),
1927
+					$supports[$this->_message_template_group->messenger()]
1928
+				)
1929
+			) {
1930
+				//not supported
1931
+				continue;
1932
+			}
1933 1933
             
1934
-            $tp_select_values[] = array(
1935
-                'text' => $tp->label,
1936
-                'id'   => $tp->dbref
1937
-            );
1938
-        }
1939
-        
1940
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1941
-        if (empty($tp_select_values)) {
1942
-            $tp_select_values[] = array(
1943
-                'text' => __('Default', 'event_espresso'),
1944
-                'id'   => 'default'
1945
-            );
1946
-        }
1947
-        
1948
-        //setup variation select values for the currently selected template.
1949
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
1950
-            $this->_message_template_group->messenger(),
1951
-            $this->_message_template_group->message_type()
1952
-        );
1953
-        $variations_select_values = array();
1954
-        foreach ($variations as $variation => $label) {
1955
-            $variations_select_values[] = array(
1956
-                'text' => $label,
1957
-                'id'   => $variation
1958
-            );
1959
-        }
1960
-        
1961
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1962
-        
1963
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1964
-            'MTP_template_pack',
1965
-            $tp_select_values,
1966
-            $this->_message_template_group->get_template_pack_name()
1967
-        );
1968
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
1969
-            'MTP_template_variation',
1970
-            $variations_select_values,
1971
-            $this->_message_template_group->get_template_pack_variation()
1972
-        );
1973
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
1974
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
1975
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1976
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1977
-        
1978
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1979
-        
1980
-        EEH_Template::display_template($template, $template_args);
1981
-    }
1982
-    
1983
-    
1984
-    /**
1985
-     * This meta box holds any extra actions related to Message Templates
1986
-     * For now, this includes Resetting templates to defaults and sending a test email.
1987
-     *
1988
-     * @access  public
1989
-     * @return void
1990
-     * @throws \EE_Error
1991
-     */
1992
-    public function extra_actions_meta_box()
1993
-    {
1994
-        $template_form_fields = array();
1995
-        
1996
-        $extra_args = array(
1997
-            'msgr'   => $this->_message_template_group->messenger(),
1998
-            'mt'     => $this->_message_template_group->message_type(),
1999
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2000
-        );
2001
-        //first we need to see if there are any fields
2002
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2003
-        
2004
-        if ( ! empty($fields)) {
2005
-            //yup there be fields
2006
-            foreach ($fields as $field => $config) {
2007
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2008
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2009
-                $default  = isset($config['default']) ? $config['default'] : '';
2010
-                $default  = isset($config['value']) ? $config['value'] : $default;
1934
+			$tp_select_values[] = array(
1935
+				'text' => $tp->label,
1936
+				'id'   => $tp->dbref
1937
+			);
1938
+		}
1939
+        
1940
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1941
+		if (empty($tp_select_values)) {
1942
+			$tp_select_values[] = array(
1943
+				'text' => __('Default', 'event_espresso'),
1944
+				'id'   => 'default'
1945
+			);
1946
+		}
1947
+        
1948
+		//setup variation select values for the currently selected template.
1949
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
1950
+			$this->_message_template_group->messenger(),
1951
+			$this->_message_template_group->message_type()
1952
+		);
1953
+		$variations_select_values = array();
1954
+		foreach ($variations as $variation => $label) {
1955
+			$variations_select_values[] = array(
1956
+				'text' => $label,
1957
+				'id'   => $variation
1958
+			);
1959
+		}
1960
+        
1961
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1962
+        
1963
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1964
+			'MTP_template_pack',
1965
+			$tp_select_values,
1966
+			$this->_message_template_group->get_template_pack_name()
1967
+		);
1968
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
1969
+			'MTP_template_variation',
1970
+			$variations_select_values,
1971
+			$this->_message_template_group->get_template_pack_variation()
1972
+		);
1973
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
1974
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
1975
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1976
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1977
+        
1978
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1979
+        
1980
+		EEH_Template::display_template($template, $template_args);
1981
+	}
1982
+    
1983
+    
1984
+	/**
1985
+	 * This meta box holds any extra actions related to Message Templates
1986
+	 * For now, this includes Resetting templates to defaults and sending a test email.
1987
+	 *
1988
+	 * @access  public
1989
+	 * @return void
1990
+	 * @throws \EE_Error
1991
+	 */
1992
+	public function extra_actions_meta_box()
1993
+	{
1994
+		$template_form_fields = array();
1995
+        
1996
+		$extra_args = array(
1997
+			'msgr'   => $this->_message_template_group->messenger(),
1998
+			'mt'     => $this->_message_template_group->message_type(),
1999
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2000
+		);
2001
+		//first we need to see if there are any fields
2002
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2003
+        
2004
+		if ( ! empty($fields)) {
2005
+			//yup there be fields
2006
+			foreach ($fields as $field => $config) {
2007
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2008
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2009
+				$default  = isset($config['default']) ? $config['default'] : '';
2010
+				$default  = isset($config['value']) ? $config['value'] : $default;
2011 2011
                 
2012
-                // if type is hidden and the value is empty
2013
-                // something may have gone wrong so let's correct with the defaults
2014
-                $fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2015
-                    ? $default
2016
-                    : '';
2017
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2018
-                    ? $existing[$field]
2019
-                    : $fix;
2012
+				// if type is hidden and the value is empty
2013
+				// something may have gone wrong so let's correct with the defaults
2014
+				$fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2015
+					? $default
2016
+					: '';
2017
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2018
+					? $existing[$field]
2019
+					: $fix;
2020 2020
                 
2021
-                $template_form_fields[$field_id] = array(
2022
-                    'name'       => 'test_settings_fld[' . $field . ']',
2023
-                    'label'      => $config['label'],
2024
-                    'input'      => $config['input'],
2025
-                    'type'       => $config['type'],
2026
-                    'required'   => $config['required'],
2027
-                    'validation' => $config['validation'],
2028
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2029
-                    'css_class'  => $config['css_class'],
2030
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2031
-                    'default'    => $default,
2032
-                    'format'     => $config['format']
2033
-                );
2034
-            }
2035
-        }
2036
-        
2037
-        $test_settings_fields = ! empty($template_form_fields)
2038
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2039
-            : '';
2040
-        
2041
-        $test_settings_html = '';
2042
-        //print out $test_settings_fields
2043
-        if ( ! empty($test_settings_fields)) {
2044
-            echo $test_settings_fields;
2045
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2046
-            $test_settings_html .= 'name="test_button" value="';
2047
-            $test_settings_html .= __('Test Send', 'event_espresso');
2048
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2049
-        }
2050
-        
2051
-        //and button
2052
-        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2053
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2054
-        $test_settings_html .= $this->get_action_link_or_button(
2055
-            'reset_to_default',
2056
-            'reset',
2057
-            $extra_args,
2058
-            'button-primary reset-default-button'
2059
-        );
2060
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2061
-        echo $test_settings_html;
2062
-    }
2063
-    
2064
-    
2065
-    /**
2066
-     * This returns the shortcode selector skeleton for a given context and field.
2067
-     *
2068
-     * @since 4.9.rc.000
2069
-     *
2070
-     * @param string $field           The name of the field retrieving shortcodes for.
2071
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2072
-     *
2073
-     * @return string
2074
-     */
2075
-    protected function _get_shortcode_selector($field, $linked_input_id)
2076
-    {
2077
-        $template_args = array(
2078
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2079
-            'fieldname'       => $field,
2080
-            'linked_input_id' => $linked_input_id
2081
-        );
2082
-        
2083
-        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2084
-            $template_args, true);
2085
-    }
2086
-    
2087
-    
2088
-    /**
2089
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2090
-     * page)
2091
-     *
2092
-     * @access public
2093
-     * @return void
2094
-     */
2095
-    public function shortcode_meta_box()
2096
-    {
2097
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2098
-        //$messenger = $this->_message_template_group->messenger_obj();
2099
-        //now let's set the content depending on the status of the shortcodes array
2100
-        if (empty($shortcodes)) {
2101
-            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2102
-            echo $content;
2103
-        } else {
2104
-            //$alt = 0;
2105
-            ?>
2021
+				$template_form_fields[$field_id] = array(
2022
+					'name'       => 'test_settings_fld[' . $field . ']',
2023
+					'label'      => $config['label'],
2024
+					'input'      => $config['input'],
2025
+					'type'       => $config['type'],
2026
+					'required'   => $config['required'],
2027
+					'validation' => $config['validation'],
2028
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2029
+					'css_class'  => $config['css_class'],
2030
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2031
+					'default'    => $default,
2032
+					'format'     => $config['format']
2033
+				);
2034
+			}
2035
+		}
2036
+        
2037
+		$test_settings_fields = ! empty($template_form_fields)
2038
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2039
+			: '';
2040
+        
2041
+		$test_settings_html = '';
2042
+		//print out $test_settings_fields
2043
+		if ( ! empty($test_settings_fields)) {
2044
+			echo $test_settings_fields;
2045
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2046
+			$test_settings_html .= 'name="test_button" value="';
2047
+			$test_settings_html .= __('Test Send', 'event_espresso');
2048
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2049
+		}
2050
+        
2051
+		//and button
2052
+		$test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2053
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2054
+		$test_settings_html .= $this->get_action_link_or_button(
2055
+			'reset_to_default',
2056
+			'reset',
2057
+			$extra_args,
2058
+			'button-primary reset-default-button'
2059
+		);
2060
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2061
+		echo $test_settings_html;
2062
+	}
2063
+    
2064
+    
2065
+	/**
2066
+	 * This returns the shortcode selector skeleton for a given context and field.
2067
+	 *
2068
+	 * @since 4.9.rc.000
2069
+	 *
2070
+	 * @param string $field           The name of the field retrieving shortcodes for.
2071
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2072
+	 *
2073
+	 * @return string
2074
+	 */
2075
+	protected function _get_shortcode_selector($field, $linked_input_id)
2076
+	{
2077
+		$template_args = array(
2078
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2079
+			'fieldname'       => $field,
2080
+			'linked_input_id' => $linked_input_id
2081
+		);
2082
+        
2083
+		return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2084
+			$template_args, true);
2085
+	}
2086
+    
2087
+    
2088
+	/**
2089
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2090
+	 * page)
2091
+	 *
2092
+	 * @access public
2093
+	 * @return void
2094
+	 */
2095
+	public function shortcode_meta_box()
2096
+	{
2097
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2098
+		//$messenger = $this->_message_template_group->messenger_obj();
2099
+		//now let's set the content depending on the status of the shortcodes array
2100
+		if (empty($shortcodes)) {
2101
+			$content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2102
+			echo $content;
2103
+		} else {
2104
+			//$alt = 0;
2105
+			?>
2106 2106
             <div
2107 2107
                 style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2108 2108
             <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2109
-                    'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2109
+					'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2110 2110
             <?php
2111
-        }
2112
-        
2113
-        
2114
-    }
2115
-    
2116
-    
2117
-    /**
2118
-     * used to set the $_shortcodes property for when its needed elsewhere.
2119
-     *
2120
-     * @access protected
2121
-     * @return void
2122
-     */
2123
-    protected function _set_shortcodes()
2124
-    {
2125
-        
2126
-        //no need to run this if the property is already set
2127
-        if ( ! empty($this->_shortcodes)) {
2128
-            return;
2129
-        }
2130
-        
2131
-        $this->_shortcodes = $this->_get_shortcodes();
2132
-    }
2133
-    
2134
-    
2135
-    /**
2136
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2137
-     * property)
2138
-     *
2139
-     * @access  protected
2140
-     *
2141
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2142
-     *                         for. Defaults to all (for the given context)
2143
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2144
-     *
2145
-     * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2146
-     *                        true just an array of shortcode/label pairs.
2147
-     */
2148
-    protected function _get_shortcodes($fields = array(), $merged = true)
2149
-    {
2150
-        $this->_set_message_template_group();
2151
-        
2152
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2153
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2154
-        $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2155
-        
2156
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2157
-    }
2158
-    
2159
-    
2160
-    /**
2161
-     * This sets the _message_template property (containing the called message_template object)
2162
-     *
2163
-     * @access protected
2164
-     * @return  void
2165
-     */
2166
-    protected function _set_message_template_group()
2167
-    {
2168
-        
2169
-        if ( ! empty($this->_message_template_group)) {
2170
-            return;
2171
-        } //get out if this is already set.
2172
-        
2173
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2174
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2175
-        
2176
-        //let's get the message templates
2177
-        $MTP = EEM_Message_Template_Group::instance();
2178
-        
2179
-        if (empty($GRP_ID)) {
2180
-            $this->_message_template_group = $MTP->create_default_object();
2181
-        } else {
2182
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2183
-        }
2184
-        
2185
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2186
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2187
-        
2188
-    }
2189
-    
2190
-    
2191
-    /**
2192
-     * sets up a context switcher for edit forms
2193
-     *
2194
-     * @access  protected
2195
-     *
2196
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2197
-     * @param array                      $args                  various things the context switcher needs.
2198
-     *
2199
-     */
2200
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2201
-    {
2202
-        $context_details = $template_group_object->contexts_config();
2203
-        $context_label   = $template_group_object->context_label();
2204
-        ob_start();
2205
-        ?>
2111
+		}
2112
+        
2113
+        
2114
+	}
2115
+    
2116
+    
2117
+	/**
2118
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2119
+	 *
2120
+	 * @access protected
2121
+	 * @return void
2122
+	 */
2123
+	protected function _set_shortcodes()
2124
+	{
2125
+        
2126
+		//no need to run this if the property is already set
2127
+		if ( ! empty($this->_shortcodes)) {
2128
+			return;
2129
+		}
2130
+        
2131
+		$this->_shortcodes = $this->_get_shortcodes();
2132
+	}
2133
+    
2134
+    
2135
+	/**
2136
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2137
+	 * property)
2138
+	 *
2139
+	 * @access  protected
2140
+	 *
2141
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2142
+	 *                         for. Defaults to all (for the given context)
2143
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2144
+	 *
2145
+	 * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2146
+	 *                        true just an array of shortcode/label pairs.
2147
+	 */
2148
+	protected function _get_shortcodes($fields = array(), $merged = true)
2149
+	{
2150
+		$this->_set_message_template_group();
2151
+        
2152
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2153
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2154
+		$context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2155
+        
2156
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2157
+	}
2158
+    
2159
+    
2160
+	/**
2161
+	 * This sets the _message_template property (containing the called message_template object)
2162
+	 *
2163
+	 * @access protected
2164
+	 * @return  void
2165
+	 */
2166
+	protected function _set_message_template_group()
2167
+	{
2168
+        
2169
+		if ( ! empty($this->_message_template_group)) {
2170
+			return;
2171
+		} //get out if this is already set.
2172
+        
2173
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2174
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2175
+        
2176
+		//let's get the message templates
2177
+		$MTP = EEM_Message_Template_Group::instance();
2178
+        
2179
+		if (empty($GRP_ID)) {
2180
+			$this->_message_template_group = $MTP->create_default_object();
2181
+		} else {
2182
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2183
+		}
2184
+        
2185
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2186
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2187
+        
2188
+	}
2189
+    
2190
+    
2191
+	/**
2192
+	 * sets up a context switcher for edit forms
2193
+	 *
2194
+	 * @access  protected
2195
+	 *
2196
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2197
+	 * @param array                      $args                  various things the context switcher needs.
2198
+	 *
2199
+	 */
2200
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2201
+	{
2202
+		$context_details = $template_group_object->contexts_config();
2203
+		$context_label   = $template_group_object->context_label();
2204
+		ob_start();
2205
+		?>
2206 2206
         <div class="ee-msg-switcher-container">
2207 2207
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2208 2208
                 <?php
2209
-                foreach ($args as $name => $value) {
2210
-                    if ($name == 'context' || empty($value) || $name == 'extra') {
2211
-                        continue;
2212
-                    }
2213
-                    ?>
2209
+				foreach ($args as $name => $value) {
2210
+					if ($name == 'context' || empty($value) || $name == 'extra') {
2211
+						continue;
2212
+					}
2213
+					?>
2214 2214
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2215 2215
                     <?php
2216
-                }
2217
-                //setup nonce_url
2218
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2219
-                ?>
2216
+				}
2217
+				//setup nonce_url
2218
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2219
+				?>
2220 2220
                 <select name="context">
2221 2221
                     <?php
2222
-                    $context_templates = $template_group_object->context_templates();
2223
-                    if (is_array($context_templates)) :
2224
-                        foreach ($context_templates as $context => $template_fields) :
2225
-                            $checked = ($context == $args['context']) ? 'selected="selected"' : '';
2226
-                            ?>
2222
+					$context_templates = $template_group_object->context_templates();
2223
+					if (is_array($context_templates)) :
2224
+						foreach ($context_templates as $context => $template_fields) :
2225
+							$checked = ($context == $args['context']) ? 'selected="selected"' : '';
2226
+							?>
2227 2227
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2228 2228
                                 <?php echo $context_details[$context]['label']; ?>
2229 2229
                             </option>
@@ -2236,1584 +2236,1584 @@  discard block
 block discarded – undo
2236 2236
             <?php echo $args['extra']; ?>
2237 2237
         </div> <!-- end .ee-msg-switcher-container -->
2238 2238
         <?php
2239
-        $output = ob_get_contents();
2240
-        ob_clean();
2241
-        $this->_context_switcher = $output;
2242
-    }
2243
-    
2244
-    
2245
-    /**
2246
-     * utility for sanitizing new values coming in.
2247
-     * Note: this is only used when updating a context.
2248
-     *
2249
-     * @access protected
2250
-     *
2251
-     * @param int $index This helps us know which template field to select from the request array.
2252
-     *
2253
-     * @return array
2254
-     */
2255
-    protected function _set_message_template_column_values($index)
2256
-    {
2257
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2258
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2259
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2260
-            }
2261
-        } /*else {
2239
+		$output = ob_get_contents();
2240
+		ob_clean();
2241
+		$this->_context_switcher = $output;
2242
+	}
2243
+    
2244
+    
2245
+	/**
2246
+	 * utility for sanitizing new values coming in.
2247
+	 * Note: this is only used when updating a context.
2248
+	 *
2249
+	 * @access protected
2250
+	 *
2251
+	 * @param int $index This helps us know which template field to select from the request array.
2252
+	 *
2253
+	 * @return array
2254
+	 */
2255
+	protected function _set_message_template_column_values($index)
2256
+	{
2257
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2258
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2259
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2260
+			}
2261
+		} /*else {
2262 2262
 			$this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content'];
2263 2263
 		}*/
2264 2264
         
2265 2265
         
2266
-        $set_column_values = array(
2267
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2268
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2269
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2270
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2271
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2272
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2273
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2274
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2275
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2276
-                ? absint($this->_req_data['MTP_is_global'])
2277
-                : 0,
2278
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2279
-                ? absint($this->_req_data['MTP_is_override'])
2280
-                : 0,
2281
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2282
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2283
-        );
2284
-        
2285
-        
2286
-        return $set_column_values;
2287
-    }
2288
-    
2289
-    
2290
-    protected function _insert_or_update_message_template($new = false)
2291
-    {
2292
-        
2293
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2294
-        $success  = 0;
2295
-        $override = false;
2296
-        
2297
-        //setup notices description
2298
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2299
-        
2300
-        //need the message type and messenger objects to be able to use the labels for the notices
2301
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2302
-        $messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2303
-        
2304
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2305
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2306
-        
2307
-        $message_type_label = $message_type_object instanceof EE_message_type
2308
-            ? ucwords($message_type_object->label['singular'])
2309
-            : '';
2310
-        
2311
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2312
-            ? $this->_req_data['MTP_context']
2313
-            : '';
2314
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2315
-        
2316
-        $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2317
-        $item_desc .= 'Message Template';
2318
-        $query_args  = array();
2319
-        $edit_array  = array();
2320
-        $action_desc = '';
2321
-        
2322
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2323
-        if ($new) {
2324
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2325
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2326
-                if (empty($edit_array)) {
2327
-                    $success = 0;
2328
-                } else {
2329
-                    $success    = 1;
2330
-                    $edit_array = $edit_array[0];
2331
-                    $query_args = array(
2332
-                        'id'      => $edit_array['GRP_ID'],
2333
-                        'context' => $edit_array['MTP_context'],
2334
-                        'action'  => 'edit_message_template'
2335
-                    );
2336
-                }
2337
-            }
2338
-            $action_desc = 'created';
2339
-        } else {
2340
-            $MTPG = EEM_Message_Template_Group::instance();
2341
-            $MTP  = EEM_Message_Template::instance();
2266
+		$set_column_values = array(
2267
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2268
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2269
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2270
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2271
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2272
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2273
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2274
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2275
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2276
+				? absint($this->_req_data['MTP_is_global'])
2277
+				: 0,
2278
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2279
+				? absint($this->_req_data['MTP_is_override'])
2280
+				: 0,
2281
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2282
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2283
+		);
2284
+        
2285
+        
2286
+		return $set_column_values;
2287
+	}
2288
+    
2289
+    
2290
+	protected function _insert_or_update_message_template($new = false)
2291
+	{
2292
+        
2293
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2294
+		$success  = 0;
2295
+		$override = false;
2296
+        
2297
+		//setup notices description
2298
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2299
+        
2300
+		//need the message type and messenger objects to be able to use the labels for the notices
2301
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2302
+		$messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2303
+        
2304
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2305
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2306
+        
2307
+		$message_type_label = $message_type_object instanceof EE_message_type
2308
+			? ucwords($message_type_object->label['singular'])
2309
+			: '';
2310
+        
2311
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2312
+			? $this->_req_data['MTP_context']
2313
+			: '';
2314
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2315
+        
2316
+		$item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2317
+		$item_desc .= 'Message Template';
2318
+		$query_args  = array();
2319
+		$edit_array  = array();
2320
+		$action_desc = '';
2321
+        
2322
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2323
+		if ($new) {
2324
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2325
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2326
+				if (empty($edit_array)) {
2327
+					$success = 0;
2328
+				} else {
2329
+					$success    = 1;
2330
+					$edit_array = $edit_array[0];
2331
+					$query_args = array(
2332
+						'id'      => $edit_array['GRP_ID'],
2333
+						'context' => $edit_array['MTP_context'],
2334
+						'action'  => 'edit_message_template'
2335
+					);
2336
+				}
2337
+			}
2338
+			$action_desc = 'created';
2339
+		} else {
2340
+			$MTPG = EEM_Message_Template_Group::instance();
2341
+			$MTP  = EEM_Message_Template::instance();
2342 2342
             
2343 2343
             
2344
-            //run update for each template field in displayed context
2345
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2346
-                EE_Error::add_error(
2347
-                    __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2348
-                        'event_espresso'),
2349
-                    __FILE__, __FUNCTION__, __LINE__
2350
-                );
2351
-                $success = 0;
2344
+			//run update for each template field in displayed context
2345
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2346
+				EE_Error::add_error(
2347
+					__('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2348
+						'event_espresso'),
2349
+					__FILE__, __FUNCTION__, __LINE__
2350
+				);
2351
+				$success = 0;
2352 2352
                 
2353
-            } else {
2354
-                //first validate all fields!
2355
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2356
-                    $message_type_slug);
2353
+			} else {
2354
+				//first validate all fields!
2355
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2356
+					$message_type_slug);
2357 2357
                 
2358
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2359
-                if (is_array($validates) && ! empty($validates)) {
2360
-                    //add the transient so when the form loads we know which fields to highlight
2361
-                    $this->_add_transient('edit_message_template', $validates);
2358
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2359
+				if (is_array($validates) && ! empty($validates)) {
2360
+					//add the transient so when the form loads we know which fields to highlight
2361
+					$this->_add_transient('edit_message_template', $validates);
2362 2362
                     
2363
-                    $success = 0;
2363
+					$success = 0;
2364 2364
                     
2365
-                    //setup notices
2366
-                    foreach ($validates as $field => $error) {
2367
-                        if (isset($error['msg'])) {
2368
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2369
-                        }
2370
-                    }
2365
+					//setup notices
2366
+					foreach ($validates as $field => $error) {
2367
+						if (isset($error['msg'])) {
2368
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2369
+						}
2370
+					}
2371 2371
                     
2372
-                } else {
2373
-                    $set_column_values = array();
2374
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2375
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2372
+				} else {
2373
+					$set_column_values = array();
2374
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2375
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2376 2376
                         
2377
-                        $where_cols_n_values = array(
2378
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2379
-                        );
2377
+						$where_cols_n_values = array(
2378
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2379
+						);
2380 2380
                         
2381
-                        $message_template_fields = array(
2382
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2383
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2384
-                            'MTP_context'        => $set_column_values['MTP_context'],
2385
-                            'MTP_content'        => $set_column_values['MTP_content']
2386
-                        );
2387
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2388
-                            if ($updated === false) {
2389
-                                EE_Error::add_error(
2390
-                                    sprintf(
2391
-                                        __('%s field was NOT updated for some reason', 'event_espresso'),
2392
-                                        $template_field
2393
-                                    ),
2394
-                                    __FILE__, __FUNCTION__, __LINE__
2395
-                                );
2396
-                            } else {
2397
-                                $success = 1;
2398
-                            }
2399
-                        }
2400
-                        $action_desc = 'updated';
2401
-                    }
2381
+						$message_template_fields = array(
2382
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2383
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2384
+							'MTP_context'        => $set_column_values['MTP_context'],
2385
+							'MTP_content'        => $set_column_values['MTP_content']
2386
+						);
2387
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2388
+							if ($updated === false) {
2389
+								EE_Error::add_error(
2390
+									sprintf(
2391
+										__('%s field was NOT updated for some reason', 'event_espresso'),
2392
+										$template_field
2393
+									),
2394
+									__FILE__, __FUNCTION__, __LINE__
2395
+								);
2396
+							} else {
2397
+								$success = 1;
2398
+							}
2399
+						}
2400
+						$action_desc = 'updated';
2401
+					}
2402 2402
                     
2403
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2404
-                    $mtpg_fields = array(
2405
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2406
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2407
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2408
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2409
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2410
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2411
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2412
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2413
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2414
-                            : '',
2415
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2416
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2417
-                            : ''
2418
-                    );
2403
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2404
+					$mtpg_fields = array(
2405
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2406
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2407
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2408
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2409
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2410
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2411
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2412
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2413
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2414
+							: '',
2415
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2416
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2417
+							: ''
2418
+					);
2419 2419
                     
2420
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2421
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2420
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2421
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2422 2422
                     
2423
-                    if ($updated === false) {
2424
-                        EE_Error::add_error(
2425
-                            sprintf(
2426
-                                __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2427
-                                $set_column_values['GRP_ID']
2428
-                            ),
2429
-                            __FILE__, __FUNCTION__, __LINE__
2430
-                        );
2431
-                    } else {
2432
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2433
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2434
-                            ? $this->_req_data['MTP_template_pack']
2435
-                            : 'default';
2423
+					if ($updated === false) {
2424
+						EE_Error::add_error(
2425
+							sprintf(
2426
+								__('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2427
+								$set_column_values['GRP_ID']
2428
+							),
2429
+							__FILE__, __FUNCTION__, __LINE__
2430
+						);
2431
+					} else {
2432
+						//k now we need to ensure the template_pack and template_variation fields are set.
2433
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2434
+							? $this->_req_data['MTP_template_pack']
2435
+							: 'default';
2436 2436
                         
2437
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2438
-                            ? $this->_req_data['MTP_template_variation']
2439
-                            : 'default';
2437
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2438
+							? $this->_req_data['MTP_template_variation']
2439
+							: 'default';
2440 2440
                         
2441
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2442
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2443
-                            $mtpg_obj->set_template_pack_name($template_pack);
2444
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2445
-                        }
2446
-                        $success = 1;
2447
-                    }
2448
-                }
2449
-            }
2441
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2442
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2443
+							$mtpg_obj->set_template_pack_name($template_pack);
2444
+							$mtpg_obj->set_template_pack_variation($template_variation);
2445
+						}
2446
+						$success = 1;
2447
+					}
2448
+				}
2449
+			}
2450 2450
             
2451
-        }
2452
-        
2453
-        //we return things differently if doing ajax
2454
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2455
-            $this->_template_args['success'] = $success;
2456
-            $this->_template_args['error']   = ! $success ? true : false;
2457
-            $this->_template_args['content'] = '';
2458
-            $this->_template_args['data']    = array(
2459
-                'grpID'        => $edit_array['GRP_ID'],
2460
-                'templateName' => $edit_array['template_name']
2461
-            );
2462
-            if ($success) {
2463
-                EE_Error::overwrite_success();
2464
-                EE_Error::add_success(__('The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2465
-                    'event_espresso'));
2466
-            }
2451
+		}
2452
+        
2453
+		//we return things differently if doing ajax
2454
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2455
+			$this->_template_args['success'] = $success;
2456
+			$this->_template_args['error']   = ! $success ? true : false;
2457
+			$this->_template_args['content'] = '';
2458
+			$this->_template_args['data']    = array(
2459
+				'grpID'        => $edit_array['GRP_ID'],
2460
+				'templateName' => $edit_array['template_name']
2461
+			);
2462
+			if ($success) {
2463
+				EE_Error::overwrite_success();
2464
+				EE_Error::add_success(__('The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2465
+					'event_espresso'));
2466
+			}
2467 2467
             
2468
-            $this->_return_json();
2469
-        }
2470
-        
2471
-        
2472
-        //was a test send triggered?
2473
-        if (isset($this->_req_data['test_button'])) {
2474
-            EE_Error::overwrite_success();
2475
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2476
-            $override = true;
2477
-        }
2478
-        
2479
-        if (empty($query_args)) {
2480
-            $query_args = array(
2481
-                'id'      => $this->_req_data['GRP_ID'],
2482
-                'context' => $context_slug,
2483
-                'action'  => 'edit_message_template'
2484
-            );
2485
-        }
2486
-        
2487
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2488
-    }
2489
-    
2490
-    
2491
-    /**
2492
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2493
-     *
2494
-     * @param  string $context      what context being tested
2495
-     * @param  string $messenger    messenger being tested
2496
-     * @param  string $message_type message type being tested
2497
-     *
2498
-     */
2499
-    protected function _do_test_send($context, $messenger, $message_type)
2500
-    {
2501
-        //set things up for preview
2502
-        $this->_req_data['messenger']    = $messenger;
2503
-        $this->_req_data['message_type'] = $message_type;
2504
-        $this->_req_data['context']      = $context;
2505
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2506
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2507
-        
2508
-        //let's save any existing fields that might be required by the messenger
2509
-        if (
2510
-            isset($this->_req_data['test_settings_fld'])
2511
-            && $active_messenger instanceof EE_messenger
2512
-            && apply_filters(
2513
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2514
-                true,
2515
-                $this->_req_data['test_settings_fld'],
2516
-                $active_messenger
2517
-            )
2518
-        ) {
2519
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2520
-        }
2521
-        
2522
-        $success = $this->_preview_message(true);
2523
-        
2524
-        if ($success) {
2525
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2526
-        } else {
2527
-            EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2528
-                __LINE__);
2529
-        }
2530
-    }
2531
-    
2532
-    
2533
-    /**
2534
-     * _generate_new_templates
2535
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2536
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2537
-     * for the event.
2538
-     *
2539
-     *
2540
-     * @param  string $messenger     the messenger we are generating templates for
2541
-     * @param array   $message_types array of message types that the templates are generated for.
2542
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2543
-     *                               indicate the message_template_group being used as the base.
2544
-     *
2545
-     * @param bool    $global
2546
-     *
2547
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2548
-     *                               encountering problems.
2549
-     * @throws \EE_Error
2550
-     */
2551
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2552
-    {
2553
-        
2554
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2555
-        if (empty($message_types)) {
2556
-            return true;
2557
-        }
2558
-        
2559
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2560
-    }
2561
-    
2562
-    
2563
-    /**
2564
-     * [_trash_or_restore_message_template]
2565
-     *
2566
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2567
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2568
-     *                        an individual context (FALSE).
2569
-     *
2570
-     * @return void
2571
-     */
2572
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2573
-    {
2574
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2575
-        $MTP = EEM_Message_Template_Group::instance();
2576
-        
2577
-        $success = 1;
2578
-        
2579
-        //incoming GRP_IDs
2580
-        if ($all) {
2581
-            //Checkboxes
2582
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2583
-                //if array has more than one element then success message should be plural.
2584
-                //todo: what about nonce?
2585
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2468
+			$this->_return_json();
2469
+		}
2470
+        
2471
+        
2472
+		//was a test send triggered?
2473
+		if (isset($this->_req_data['test_button'])) {
2474
+			EE_Error::overwrite_success();
2475
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2476
+			$override = true;
2477
+		}
2478
+        
2479
+		if (empty($query_args)) {
2480
+			$query_args = array(
2481
+				'id'      => $this->_req_data['GRP_ID'],
2482
+				'context' => $context_slug,
2483
+				'action'  => 'edit_message_template'
2484
+			);
2485
+		}
2486
+        
2487
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2488
+	}
2489
+    
2490
+    
2491
+	/**
2492
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2493
+	 *
2494
+	 * @param  string $context      what context being tested
2495
+	 * @param  string $messenger    messenger being tested
2496
+	 * @param  string $message_type message type being tested
2497
+	 *
2498
+	 */
2499
+	protected function _do_test_send($context, $messenger, $message_type)
2500
+	{
2501
+		//set things up for preview
2502
+		$this->_req_data['messenger']    = $messenger;
2503
+		$this->_req_data['message_type'] = $message_type;
2504
+		$this->_req_data['context']      = $context;
2505
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2506
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2507
+        
2508
+		//let's save any existing fields that might be required by the messenger
2509
+		if (
2510
+			isset($this->_req_data['test_settings_fld'])
2511
+			&& $active_messenger instanceof EE_messenger
2512
+			&& apply_filters(
2513
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2514
+				true,
2515
+				$this->_req_data['test_settings_fld'],
2516
+				$active_messenger
2517
+			)
2518
+		) {
2519
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2520
+		}
2521
+        
2522
+		$success = $this->_preview_message(true);
2523
+        
2524
+		if ($success) {
2525
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2526
+		} else {
2527
+			EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2528
+				__LINE__);
2529
+		}
2530
+	}
2531
+    
2532
+    
2533
+	/**
2534
+	 * _generate_new_templates
2535
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2536
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2537
+	 * for the event.
2538
+	 *
2539
+	 *
2540
+	 * @param  string $messenger     the messenger we are generating templates for
2541
+	 * @param array   $message_types array of message types that the templates are generated for.
2542
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2543
+	 *                               indicate the message_template_group being used as the base.
2544
+	 *
2545
+	 * @param bool    $global
2546
+	 *
2547
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2548
+	 *                               encountering problems.
2549
+	 * @throws \EE_Error
2550
+	 */
2551
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2552
+	{
2553
+        
2554
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2555
+		if (empty($message_types)) {
2556
+			return true;
2557
+		}
2558
+        
2559
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2560
+	}
2561
+    
2562
+    
2563
+	/**
2564
+	 * [_trash_or_restore_message_template]
2565
+	 *
2566
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2567
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2568
+	 *                        an individual context (FALSE).
2569
+	 *
2570
+	 * @return void
2571
+	 */
2572
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2573
+	{
2574
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2575
+		$MTP = EEM_Message_Template_Group::instance();
2576
+        
2577
+		$success = 1;
2578
+        
2579
+		//incoming GRP_IDs
2580
+		if ($all) {
2581
+			//Checkboxes
2582
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2583
+				//if array has more than one element then success message should be plural.
2584
+				//todo: what about nonce?
2585
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2586 2586
                 
2587
-                //cycle through checkboxes
2588
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2589
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2590
-                    if ( ! $trashed_or_restored) {
2591
-                        $success = 0;
2592
-                    }
2593
-                }
2594
-            } else {
2595
-                //grab single GRP_ID and handle
2596
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2597
-                if ( ! empty($GRP_ID)) {
2598
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
-                    if ( ! $trashed_or_restored) {
2600
-                        $success = 0;
2601
-                    }
2602
-                } else {
2603
-                    $success = 0;
2604
-                }
2605
-            }
2587
+				//cycle through checkboxes
2588
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2589
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2590
+					if ( ! $trashed_or_restored) {
2591
+						$success = 0;
2592
+					}
2593
+				}
2594
+			} else {
2595
+				//grab single GRP_ID and handle
2596
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2597
+				if ( ! empty($GRP_ID)) {
2598
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
+					if ( ! $trashed_or_restored) {
2600
+						$success = 0;
2601
+					}
2602
+				} else {
2603
+					$success = 0;
2604
+				}
2605
+			}
2606 2606
             
2607
-        }
2607
+		}
2608 2608
         
2609
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2609
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2610 2610
         
2611
-        $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2611
+		$action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2612 2612
         
2613
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2614
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2613
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2614
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2615 2615
         
2616
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2617
-            'event_espresso') : $item_desc;
2616
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2617
+			'event_espresso') : $item_desc;
2618 2618
         
2619
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
2619
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
2620 2620
         
2621
-    }
2621
+	}
2622 2622
     
2623 2623
     
2624
-    /**
2625
-     * [_delete_message_template]
2626
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2627
-     * @return void
2628
-     */
2629
-    protected function _delete_message_template()
2630
-    {
2631
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2624
+	/**
2625
+	 * [_delete_message_template]
2626
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2627
+	 * @return void
2628
+	 */
2629
+	protected function _delete_message_template()
2630
+	{
2631
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2632 2632
         
2633
-        //checkboxes
2634
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2635
-            //if array has more than one element then success message should be plural
2636
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2633
+		//checkboxes
2634
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2635
+			//if array has more than one element then success message should be plural
2636
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2637 2637
             
2638
-            //cycle through bulk action checkboxes
2639
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2640
-                $success = $this->_delete_mtp_permanently($GRP_ID);
2641
-            }
2642
-        } else {
2643
-            //grab single grp_id and delete
2644
-            $GRP_ID  = absint($this->_req_data['id']);
2645
-            $success = $this->_delete_mtp_permanently($GRP_ID);
2646
-        }
2647
-        
2648
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2649
-        
2650
-    }
2651
-    
2652
-    
2653
-    /**
2654
-     * helper for permanently deleting a mtP group and all related message_templates
2655
-     *
2656
-     * @param  int  $GRP_ID        The group being deleted
2657
-     * @param  bool $include_group whether to delete the Message Template Group as well.
2658
-     *
2659
-     * @return bool        boolean to indicate the success of the deletes or not.
2660
-     */
2661
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2662
-    {
2663
-        $success = 1;
2664
-        $MTPG    = EEM_Message_Template_Group::instance();
2665
-        //first let's GET this group
2666
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
2667
-        //then delete permanently all the related Message Templates
2668
-        $deleted = $MTG->delete_related_permanently('Message_Template');
2669
-        
2670
-        if ($deleted === 0) {
2671
-            $success = 0;
2672
-        }
2673
-        
2674
-        //now delete permanently this particular group
2675
-        
2676
-        if ($include_group && ! $MTG->delete_permanently()) {
2677
-            $success = 0;
2678
-        }
2679
-        
2680
-        return $success;
2681
-    }
2682
-    
2683
-    
2684
-    /**
2685
-     *    _learn_more_about_message_templates_link
2686
-     * @access protected
2687
-     * @return string
2688
-     */
2689
-    protected function _learn_more_about_message_templates_link()
2690
-    {
2691
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2692
-            'event_espresso') . '</a>';
2693
-    }
2694
-    
2695
-    
2696
-    /**
2697
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2698
-     * ajax and other routes.
2699
-     * @return void
2700
-     */
2701
-    protected function _settings()
2702
-    {
2703
-        
2704
-        
2705
-        $this->_set_m_mt_settings();
2706
-        
2707
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2708
-        
2709
-        //let's setup the messenger tabs
2710
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2711
-            'messenger_links', '|', $selected_messenger);
2712
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2713
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2714
-        
2715
-        $this->display_admin_page_with_sidebar();
2716
-        
2717
-    }
2718
-    
2719
-    
2720
-    /**
2721
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2722
-     *
2723
-     * @access protected
2724
-     * @return void
2725
-     */
2726
-    protected function _set_m_mt_settings()
2727
-    {
2728
-        //first if this is already set then lets get out no need to regenerate data.
2729
-        if ( ! empty($this->_m_mt_settings)) {
2730
-            return;
2731
-        }
2732
-        
2733
-        //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2734
-        
2735
-        //get all installed messengers and message_types
2736
-        /** @type EE_messenger[] $messengers */
2737
-        $messengers = $this->_message_resource_manager->installed_messengers();
2738
-        /** @type EE_message_type[] $message_types */
2739
-        $message_types = $this->_message_resource_manager->installed_message_types();
2740
-        
2741
-        
2742
-        //assemble the array for the _tab_text_links helper
2743
-        
2744
-        foreach ($messengers as $messenger) {
2745
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2746
-                'label' => ucwords($messenger->label['singular']),
2747
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2748
-                'href'  => $messenger->name,
2749
-                'title' => __('Modify this Messenger', 'event_espresso'),
2750
-                'slug'  => $messenger->name,
2751
-                'obj'   => $messenger
2752
-            );
2638
+			//cycle through bulk action checkboxes
2639
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2640
+				$success = $this->_delete_mtp_permanently($GRP_ID);
2641
+			}
2642
+		} else {
2643
+			//grab single grp_id and delete
2644
+			$GRP_ID  = absint($this->_req_data['id']);
2645
+			$success = $this->_delete_mtp_permanently($GRP_ID);
2646
+		}
2647
+        
2648
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2649
+        
2650
+	}
2651
+    
2652
+    
2653
+	/**
2654
+	 * helper for permanently deleting a mtP group and all related message_templates
2655
+	 *
2656
+	 * @param  int  $GRP_ID        The group being deleted
2657
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
2658
+	 *
2659
+	 * @return bool        boolean to indicate the success of the deletes or not.
2660
+	 */
2661
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2662
+	{
2663
+		$success = 1;
2664
+		$MTPG    = EEM_Message_Template_Group::instance();
2665
+		//first let's GET this group
2666
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
2667
+		//then delete permanently all the related Message Templates
2668
+		$deleted = $MTG->delete_related_permanently('Message_Template');
2669
+        
2670
+		if ($deleted === 0) {
2671
+			$success = 0;
2672
+		}
2673
+        
2674
+		//now delete permanently this particular group
2675
+        
2676
+		if ($include_group && ! $MTG->delete_permanently()) {
2677
+			$success = 0;
2678
+		}
2679
+        
2680
+		return $success;
2681
+	}
2682
+    
2683
+    
2684
+	/**
2685
+	 *    _learn_more_about_message_templates_link
2686
+	 * @access protected
2687
+	 * @return string
2688
+	 */
2689
+	protected function _learn_more_about_message_templates_link()
2690
+	{
2691
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2692
+			'event_espresso') . '</a>';
2693
+	}
2694
+    
2695
+    
2696
+	/**
2697
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2698
+	 * ajax and other routes.
2699
+	 * @return void
2700
+	 */
2701
+	protected function _settings()
2702
+	{
2703
+        
2704
+        
2705
+		$this->_set_m_mt_settings();
2706
+        
2707
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2708
+        
2709
+		//let's setup the messenger tabs
2710
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2711
+			'messenger_links', '|', $selected_messenger);
2712
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2713
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2714
+        
2715
+		$this->display_admin_page_with_sidebar();
2716
+        
2717
+	}
2718
+    
2719
+    
2720
+	/**
2721
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2722
+	 *
2723
+	 * @access protected
2724
+	 * @return void
2725
+	 */
2726
+	protected function _set_m_mt_settings()
2727
+	{
2728
+		//first if this is already set then lets get out no need to regenerate data.
2729
+		if ( ! empty($this->_m_mt_settings)) {
2730
+			return;
2731
+		}
2732
+        
2733
+		//$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2734
+        
2735
+		//get all installed messengers and message_types
2736
+		/** @type EE_messenger[] $messengers */
2737
+		$messengers = $this->_message_resource_manager->installed_messengers();
2738
+		/** @type EE_message_type[] $message_types */
2739
+		$message_types = $this->_message_resource_manager->installed_message_types();
2740
+        
2741
+        
2742
+		//assemble the array for the _tab_text_links helper
2743
+        
2744
+		foreach ($messengers as $messenger) {
2745
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2746
+				'label' => ucwords($messenger->label['singular']),
2747
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2748
+				'href'  => $messenger->name,
2749
+				'title' => __('Modify this Messenger', 'event_espresso'),
2750
+				'slug'  => $messenger->name,
2751
+				'obj'   => $messenger
2752
+			);
2753 2753
             
2754 2754
             
2755
-            $message_types_for_messenger = $messenger->get_valid_message_types();
2755
+			$message_types_for_messenger = $messenger->get_valid_message_types();
2756 2756
             
2757
-            foreach ($message_types as $message_type) {
2758
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2759
-                if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2760
-                    continue;
2761
-                }
2757
+			foreach ($message_types as $message_type) {
2758
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2759
+				if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2760
+					continue;
2761
+				}
2762 2762
                 
2763
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2764
-                    $message_type->name) ? 'active' : 'inactive';
2763
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2764
+					$message_type->name) ? 'active' : 'inactive';
2765 2765
                 
2766
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2767
-                    'label'    => ucwords($message_type->label['singular']),
2768
-                    'class'    => 'message-type-' . $a_or_i,
2769
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2770
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2771
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2772
-                    'title'    => $a_or_i == 'active'
2773
-                        ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2774
-                        : __('Drag this message type to the messenger to activate', 'event_espresso'),
2775
-                    'content'  => $a_or_i == 'active'
2776
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
2777
-                        : $this->_message_type_settings_content($message_type, $messenger),
2778
-                    'slug'     => $message_type->name,
2779
-                    'active'   => $a_or_i == 'active' ? true : false,
2780
-                    'obj'      => $message_type
2781
-                );
2782
-            }
2783
-        }
2784
-    }
2785
-    
2786
-    
2787
-    /**
2788
-     * This just prepares the content for the message type settings
2789
-     *
2790
-     * @param  object  $message_type The message type object
2791
-     * @param  object  $messenger    The messenger object
2792
-     * @param  boolean $active       Whether the message type is active or not
2793
-     *
2794
-     * @return string                html output for the content
2795
-     */
2796
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
2797
-    {
2798
-        //get message type fields
2799
-        $fields                                         = $message_type->get_admin_settings_fields();
2800
-        $settings_template_args['template_form_fields'] = '';
2801
-        
2802
-        if ( ! empty($fields) && $active) {
2766
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2767
+					'label'    => ucwords($message_type->label['singular']),
2768
+					'class'    => 'message-type-' . $a_or_i,
2769
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2770
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2771
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2772
+					'title'    => $a_or_i == 'active'
2773
+						? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2774
+						: __('Drag this message type to the messenger to activate', 'event_espresso'),
2775
+					'content'  => $a_or_i == 'active'
2776
+						? $this->_message_type_settings_content($message_type, $messenger, true)
2777
+						: $this->_message_type_settings_content($message_type, $messenger),
2778
+					'slug'     => $message_type->name,
2779
+					'active'   => $a_or_i == 'active' ? true : false,
2780
+					'obj'      => $message_type
2781
+				);
2782
+			}
2783
+		}
2784
+	}
2785
+    
2786
+    
2787
+	/**
2788
+	 * This just prepares the content for the message type settings
2789
+	 *
2790
+	 * @param  object  $message_type The message type object
2791
+	 * @param  object  $messenger    The messenger object
2792
+	 * @param  boolean $active       Whether the message type is active or not
2793
+	 *
2794
+	 * @return string                html output for the content
2795
+	 */
2796
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
2797
+	{
2798
+		//get message type fields
2799
+		$fields                                         = $message_type->get_admin_settings_fields();
2800
+		$settings_template_args['template_form_fields'] = '';
2801
+        
2802
+		if ( ! empty($fields) && $active) {
2803 2803
             
2804
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2804
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2805 2805
             
2806
-            foreach ($fields as $fldname => $fldprops) {
2807
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2808
-                $template_form_field[$field_id] = array(
2809
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2810
-                    'label'      => $fldprops['label'],
2811
-                    'input'      => $fldprops['field_type'],
2812
-                    'type'       => $fldprops['value_type'],
2813
-                    'required'   => $fldprops['required'],
2814
-                    'validation' => $fldprops['validation'],
2815
-                    'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2816
-                    'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2817
-                    'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2818
-                    'css_class'  => 'no-drag',
2819
-                    'format'     => $fldprops['format']
2820
-                );
2821
-            }
2806
+			foreach ($fields as $fldname => $fldprops) {
2807
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2808
+				$template_form_field[$field_id] = array(
2809
+					'name'       => 'message_type_settings[' . $fldname . ']',
2810
+					'label'      => $fldprops['label'],
2811
+					'input'      => $fldprops['field_type'],
2812
+					'type'       => $fldprops['value_type'],
2813
+					'required'   => $fldprops['required'],
2814
+					'validation' => $fldprops['validation'],
2815
+					'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2816
+					'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2817
+					'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2818
+					'css_class'  => 'no-drag',
2819
+					'format'     => $fldprops['format']
2820
+				);
2821
+			}
2822 2822
             
2823 2823
             
2824
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2825
-                'string', 'ee_mt_activate_form') : '';
2826
-        }
2827
-        
2828
-        $settings_template_args['description'] = $message_type->description;
2829
-        //we also need some hidden fields
2830
-        $settings_template_args['hidden_fields'] = array(
2831
-            'message_type_settings[messenger]'    => array(
2832
-                'type'  => 'hidden',
2833
-                'value' => $messenger->name
2834
-            ),
2835
-            'message_type_settings[message_type]' => array(
2836
-                'type'  => 'hidden',
2837
-                'value' => $message_type->name
2838
-            ),
2839
-            'type'                                => array(
2840
-                'type'  => 'hidden',
2841
-                'value' => 'message_type'
2842
-            )
2843
-        );
2844
-        
2845
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2846
-            'array');
2847
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2848
-        
2849
-        
2850
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2851
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
2852
-        
2853
-        return $content;
2854
-    }
2855
-    
2856
-    
2857
-    /**
2858
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
2859
-     *
2860
-     * @access protected
2861
-     * @return void
2862
-     */
2863
-    protected function _messages_settings_metaboxes()
2864
-    {
2865
-        $this->_set_m_mt_settings();
2866
-        $m_boxes         = $mt_boxes = array();
2867
-        $m_template_args = $mt_template_args = array();
2868
-        
2869
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2870
-        
2871
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
2872
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2873
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2874
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2875
-                //messenger meta boxes
2876
-                $active                                 = $selected_messenger == $messenger ? true : false;
2877
-                $active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2878
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2879
-                    : '';
2880
-                $m_boxes[$messenger . '_a_box']         = sprintf(
2881
-                    __('%s Settings', 'event_espresso'),
2882
-                    $tab_array['label']
2883
-                );
2884
-                $m_template_args[$messenger . '_a_box'] = array(
2885
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2886
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2887
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2888
-                        : '',
2889
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2890
-                    'hidden'                 => $active ? '' : ' hidden',
2891
-                    'hide_on_message'        => $hide_on_message,
2892
-                    'messenger'              => $messenger,
2893
-                    'active'                 => $active
2894
-                );
2895
-                // message type meta boxes
2896
-                // (which is really just the inactive container for each messenger
2897
-                // showing inactive message types for that messenger)
2898
-                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2899
-                $mt_template_args[$messenger . '_i_box'] = array(
2900
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2901
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2902
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2903
-                        : '',
2904
-                    'hidden'                 => $active ? '' : ' hidden',
2905
-                    'hide_on_message'        => $hide_on_message,
2906
-                    'hide_off_message'       => $hide_off_message,
2907
-                    'messenger'              => $messenger,
2908
-                    'active'                 => $active
2909
-                );
2910
-            }
2911
-        }
2912
-        
2913
-        
2914
-        //register messenger metaboxes
2915
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2916
-        foreach ($m_boxes as $box => $label) {
2917
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2918
-            $msgr          = str_replace('_a_box', '', $box);
2919
-            add_meta_box(
2920
-                'espresso_' . $msgr . '_settings',
2921
-                $label,
2922
-                function ($post, $metabox) {
2923
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2924
-                        $metabox["args"]["template_args"], true);
2925
-                },
2926
-                $this->_current_screen->id,
2927
-                'normal',
2928
-                'high',
2929
-                $callback_args
2930
-            );
2931
-        }
2932
-        
2933
-        //register message type metaboxes
2934
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2935
-        foreach ($mt_boxes as $box => $label) {
2936
-            $callback_args = array(
2937
-                'template_path' => $mt_template_path,
2938
-                'template_args' => $mt_template_args[$box]
2939
-            );
2940
-            $mt            = str_replace('_i_box', '', $box);
2941
-            add_meta_box(
2942
-                'espresso_' . $mt . '_inactive_mts',
2943
-                $label,
2944
-                function ($post, $metabox) {
2945
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2946
-                        $metabox["args"]["template_args"], true);
2947
-                },
2948
-                $this->_current_screen->id,
2949
-                'side',
2950
-                'high',
2951
-                $callback_args
2952
-            );
2953
-        }
2954
-        
2955
-        //register metabox for global messages settings but only when on the main site.  On single site installs this will
2956
-        //always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2957
-        if (is_main_site()) {
2958
-            add_meta_box(
2959
-                'espresso_global_message_settings',
2960
-                __('Global Message Settings', 'event_espresso'),
2961
-                array($this, 'global_messages_settings_metabox_content'),
2962
-                $this->_current_screen->id,
2963
-                'normal',
2964
-                'low',
2965
-                array()
2966
-            );
2967
-        }
2968
-        
2969
-    }
2970
-    
2971
-    
2972
-    /**
2973
-     *  This generates the content for the global messages settings metabox.
2974
-     * @return string
2975
-     */
2976
-    public function global_messages_settings_metabox_content()
2977
-    {
2978
-        $form = $this->_generate_global_settings_form();
2979
-        echo $form->form_open(
2980
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2981
-                'POST'
2982
-            )
2983
-             . $form->get_html()
2984
-             . $form->form_close();
2985
-    }
2986
-    
2987
-    
2988
-    /**
2989
-     * This generates and returns the form object for the global messages settings.
2990
-     * @return EE_Form_Section_Proper
2991
-     */
2992
-    protected function _generate_global_settings_form()
2993
-    {
2994
-        EE_Registry::instance()->load_helper('HTML');
2995
-        /** @var EE_Network_Core_Config $network_config */
2996
-        $network_config = EE_Registry::instance()->NET_CFG->core;
2997
-        
2998
-        return new EE_Form_Section_Proper(
2999
-            array(
3000
-                'name'            => 'global_messages_settings',
3001
-                'html_id'         => 'global_messages_settings',
3002
-                'html_class'      => 'form-table',
3003
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3004
-                'subsections'     => apply_filters(
3005
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3006
-                    array(
3007
-                        'do_messages_on_same_request' => new EE_Select_Input(
3008
-                            array(
3009
-                                true  => esc_html__("On the same request", "event_espresso"),
3010
-                                false => esc_html__("On a separate request", "event_espresso")
3011
-                            ),
3012
-                            array(
3013
-                                'default'         => $network_config->do_messages_on_same_request,
3014
-                                'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'),
3015
-                                'html_help_text'  => esc_html__('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3016
-                                    'event_espresso'),
3017
-                            )
3018
-                        ),
3019
-                        'delete_threshold' => new EE_Select_Input(
3020
-                            array(
3021
-                                0 => esc_html__('Forever', 'event_espresso'),
3022
-                                3 => esc_html__('3 Months', 'event_espresso'),
3023
-                                6 => esc_html__('6 Months', 'event_espresso'),
3024
-                                9 => esc_html__('9 Months', 'event_espresso'),
3025
-                                12 => esc_html__('12 Months', 'event_espresso'),
3026
-                                24 => esc_html__('24 Months', 'event_espresso'),
3027
-                                36 => esc_html__('36 Months', 'event_espresso')
3028
-                            ),
3029
-                            array(
3030
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3031
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3032
-                                'html_help_text' => esc_html__('You can control how long a record of processed messages is kept 
2824
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2825
+				'string', 'ee_mt_activate_form') : '';
2826
+		}
2827
+        
2828
+		$settings_template_args['description'] = $message_type->description;
2829
+		//we also need some hidden fields
2830
+		$settings_template_args['hidden_fields'] = array(
2831
+			'message_type_settings[messenger]'    => array(
2832
+				'type'  => 'hidden',
2833
+				'value' => $messenger->name
2834
+			),
2835
+			'message_type_settings[message_type]' => array(
2836
+				'type'  => 'hidden',
2837
+				'value' => $message_type->name
2838
+			),
2839
+			'type'                                => array(
2840
+				'type'  => 'hidden',
2841
+				'value' => 'message_type'
2842
+			)
2843
+		);
2844
+        
2845
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2846
+			'array');
2847
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2848
+        
2849
+        
2850
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2851
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
2852
+        
2853
+		return $content;
2854
+	}
2855
+    
2856
+    
2857
+	/**
2858
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
2859
+	 *
2860
+	 * @access protected
2861
+	 * @return void
2862
+	 */
2863
+	protected function _messages_settings_metaboxes()
2864
+	{
2865
+		$this->_set_m_mt_settings();
2866
+		$m_boxes         = $mt_boxes = array();
2867
+		$m_template_args = $mt_template_args = array();
2868
+        
2869
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2870
+        
2871
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
2872
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2873
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2874
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2875
+				//messenger meta boxes
2876
+				$active                                 = $selected_messenger == $messenger ? true : false;
2877
+				$active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2878
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2879
+					: '';
2880
+				$m_boxes[$messenger . '_a_box']         = sprintf(
2881
+					__('%s Settings', 'event_espresso'),
2882
+					$tab_array['label']
2883
+				);
2884
+				$m_template_args[$messenger . '_a_box'] = array(
2885
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2886
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2887
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2888
+						: '',
2889
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2890
+					'hidden'                 => $active ? '' : ' hidden',
2891
+					'hide_on_message'        => $hide_on_message,
2892
+					'messenger'              => $messenger,
2893
+					'active'                 => $active
2894
+				);
2895
+				// message type meta boxes
2896
+				// (which is really just the inactive container for each messenger
2897
+				// showing inactive message types for that messenger)
2898
+				$mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2899
+				$mt_template_args[$messenger . '_i_box'] = array(
2900
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2901
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2902
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2903
+						: '',
2904
+					'hidden'                 => $active ? '' : ' hidden',
2905
+					'hide_on_message'        => $hide_on_message,
2906
+					'hide_off_message'       => $hide_off_message,
2907
+					'messenger'              => $messenger,
2908
+					'active'                 => $active
2909
+				);
2910
+			}
2911
+		}
2912
+        
2913
+        
2914
+		//register messenger metaboxes
2915
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2916
+		foreach ($m_boxes as $box => $label) {
2917
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2918
+			$msgr          = str_replace('_a_box', '', $box);
2919
+			add_meta_box(
2920
+				'espresso_' . $msgr . '_settings',
2921
+				$label,
2922
+				function ($post, $metabox) {
2923
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2924
+						$metabox["args"]["template_args"], true);
2925
+				},
2926
+				$this->_current_screen->id,
2927
+				'normal',
2928
+				'high',
2929
+				$callback_args
2930
+			);
2931
+		}
2932
+        
2933
+		//register message type metaboxes
2934
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2935
+		foreach ($mt_boxes as $box => $label) {
2936
+			$callback_args = array(
2937
+				'template_path' => $mt_template_path,
2938
+				'template_args' => $mt_template_args[$box]
2939
+			);
2940
+			$mt            = str_replace('_i_box', '', $box);
2941
+			add_meta_box(
2942
+				'espresso_' . $mt . '_inactive_mts',
2943
+				$label,
2944
+				function ($post, $metabox) {
2945
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2946
+						$metabox["args"]["template_args"], true);
2947
+				},
2948
+				$this->_current_screen->id,
2949
+				'side',
2950
+				'high',
2951
+				$callback_args
2952
+			);
2953
+		}
2954
+        
2955
+		//register metabox for global messages settings but only when on the main site.  On single site installs this will
2956
+		//always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2957
+		if (is_main_site()) {
2958
+			add_meta_box(
2959
+				'espresso_global_message_settings',
2960
+				__('Global Message Settings', 'event_espresso'),
2961
+				array($this, 'global_messages_settings_metabox_content'),
2962
+				$this->_current_screen->id,
2963
+				'normal',
2964
+				'low',
2965
+				array()
2966
+			);
2967
+		}
2968
+        
2969
+	}
2970
+    
2971
+    
2972
+	/**
2973
+	 *  This generates the content for the global messages settings metabox.
2974
+	 * @return string
2975
+	 */
2976
+	public function global_messages_settings_metabox_content()
2977
+	{
2978
+		$form = $this->_generate_global_settings_form();
2979
+		echo $form->form_open(
2980
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2981
+				'POST'
2982
+			)
2983
+			 . $form->get_html()
2984
+			 . $form->form_close();
2985
+	}
2986
+    
2987
+    
2988
+	/**
2989
+	 * This generates and returns the form object for the global messages settings.
2990
+	 * @return EE_Form_Section_Proper
2991
+	 */
2992
+	protected function _generate_global_settings_form()
2993
+	{
2994
+		EE_Registry::instance()->load_helper('HTML');
2995
+		/** @var EE_Network_Core_Config $network_config */
2996
+		$network_config = EE_Registry::instance()->NET_CFG->core;
2997
+        
2998
+		return new EE_Form_Section_Proper(
2999
+			array(
3000
+				'name'            => 'global_messages_settings',
3001
+				'html_id'         => 'global_messages_settings',
3002
+				'html_class'      => 'form-table',
3003
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3004
+				'subsections'     => apply_filters(
3005
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3006
+					array(
3007
+						'do_messages_on_same_request' => new EE_Select_Input(
3008
+							array(
3009
+								true  => esc_html__("On the same request", "event_espresso"),
3010
+								false => esc_html__("On a separate request", "event_espresso")
3011
+							),
3012
+							array(
3013
+								'default'         => $network_config->do_messages_on_same_request,
3014
+								'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'),
3015
+								'html_help_text'  => esc_html__('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3016
+									'event_espresso'),
3017
+							)
3018
+						),
3019
+						'delete_threshold' => new EE_Select_Input(
3020
+							array(
3021
+								0 => esc_html__('Forever', 'event_espresso'),
3022
+								3 => esc_html__('3 Months', 'event_espresso'),
3023
+								6 => esc_html__('6 Months', 'event_espresso'),
3024
+								9 => esc_html__('9 Months', 'event_espresso'),
3025
+								12 => esc_html__('12 Months', 'event_espresso'),
3026
+								24 => esc_html__('24 Months', 'event_espresso'),
3027
+								36 => esc_html__('36 Months', 'event_espresso')
3028
+							),
3029
+							array(
3030
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3031
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3032
+								'html_help_text' => esc_html__('You can control how long a record of processed messages is kept 
3033 3033
                                                     via this option.', 'event_espresso'),
3034
-                            )
3035
-                        ),
3036
-                        'update_settings'             => new EE_Submit_Input(
3037
-                            array(
3038
-                                'default'         => esc_html__('Update', 'event_espresso'),
3039
-                                'html_label_text' => '&nbsp'
3040
-                            )
3041
-                        )
3042
-                    )
3043
-                )
3044
-            )
3045
-        );
3046
-    }
3047
-    
3048
-    
3049
-    /**
3050
-     * This handles updating the global settings set on the admin page.
3051
-     * @throws \EE_Error
3052
-     */
3053
-    protected function _update_global_settings()
3054
-    {
3055
-        /** @var EE_Network_Core_Config $network_config */
3056
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3057
-        $messages_config = EE_Registry::instance()->CFG->messages;
3058
-        $form           = $this->_generate_global_settings_form();
3059
-        if ($form->was_submitted()) {
3060
-            $form->receive_form_submission();
3061
-            if ($form->is_valid()) {
3062
-                $valid_data = $form->valid_data();
3063
-                foreach ($valid_data as $property => $value) {
3064
-                    $setter = 'set_' . $property;
3065
-                    if (method_exists($network_config, $setter)) {
3066
-                        $network_config->{$setter}($value);
3067
-                    } else if (
3068
-                        property_exists($network_config, $property)
3069
-                        && $network_config->{$property} !== $value
3070
-                    ) {
3071
-                        $network_config->{$property} = $value;
3072
-                    } else if (
3073
-                        property_exists($messages_config, $property)
3074
-                        && $messages_config->{$property} !== $value
3075
-                    ) {
3076
-                        $messages_config->{$property} = $value;
3077
-                    }
3078
-                }
3079
-                //only update if the form submission was valid!
3080
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3081
-                EE_Registry::instance()->CFG->update_espresso_config();
3082
-                EE_Error::overwrite_success();
3083
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3084
-            }
3085
-        }
3086
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3087
-    }
3088
-    
3089
-    
3090
-    /**
3091
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3092
-     *
3093
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3094
-     *
3095
-     * @return string            html formatted tabs
3096
-     */
3097
-    protected function _get_mt_tabs($tab_array)
3098
-    {
3099
-        $tab_array = (array)$tab_array;
3100
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3101
-        $tabs      = '';
3102
-        
3103
-        foreach ($tab_array as $tab) {
3104
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3105
-        }
3106
-        
3107
-        return $tabs;
3108
-    }
3109
-    
3110
-    
3111
-    /**
3112
-     * This prepares the content of the messenger meta box admin settings
3113
-     *
3114
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3115
-     *
3116
-     * @return string            html formatted content
3117
-     */
3118
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3119
-    {
3120
-        
3121
-        $fields                                         = $messenger->get_admin_settings_fields();
3122
-        $settings_template_args['template_form_fields'] = '';
3123
-        
3124
-        //is $messenger active?
3125
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3126
-        
3127
-        
3128
-        if ( ! empty($fields)) {
3034
+							)
3035
+						),
3036
+						'update_settings'             => new EE_Submit_Input(
3037
+							array(
3038
+								'default'         => esc_html__('Update', 'event_espresso'),
3039
+								'html_label_text' => '&nbsp'
3040
+							)
3041
+						)
3042
+					)
3043
+				)
3044
+			)
3045
+		);
3046
+	}
3047
+    
3048
+    
3049
+	/**
3050
+	 * This handles updating the global settings set on the admin page.
3051
+	 * @throws \EE_Error
3052
+	 */
3053
+	protected function _update_global_settings()
3054
+	{
3055
+		/** @var EE_Network_Core_Config $network_config */
3056
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3057
+		$messages_config = EE_Registry::instance()->CFG->messages;
3058
+		$form           = $this->_generate_global_settings_form();
3059
+		if ($form->was_submitted()) {
3060
+			$form->receive_form_submission();
3061
+			if ($form->is_valid()) {
3062
+				$valid_data = $form->valid_data();
3063
+				foreach ($valid_data as $property => $value) {
3064
+					$setter = 'set_' . $property;
3065
+					if (method_exists($network_config, $setter)) {
3066
+						$network_config->{$setter}($value);
3067
+					} else if (
3068
+						property_exists($network_config, $property)
3069
+						&& $network_config->{$property} !== $value
3070
+					) {
3071
+						$network_config->{$property} = $value;
3072
+					} else if (
3073
+						property_exists($messages_config, $property)
3074
+						&& $messages_config->{$property} !== $value
3075
+					) {
3076
+						$messages_config->{$property} = $value;
3077
+					}
3078
+				}
3079
+				//only update if the form submission was valid!
3080
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3081
+				EE_Registry::instance()->CFG->update_espresso_config();
3082
+				EE_Error::overwrite_success();
3083
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3084
+			}
3085
+		}
3086
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3087
+	}
3088
+    
3089
+    
3090
+	/**
3091
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3092
+	 *
3093
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3094
+	 *
3095
+	 * @return string            html formatted tabs
3096
+	 */
3097
+	protected function _get_mt_tabs($tab_array)
3098
+	{
3099
+		$tab_array = (array)$tab_array;
3100
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3101
+		$tabs      = '';
3102
+        
3103
+		foreach ($tab_array as $tab) {
3104
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3105
+		}
3106
+        
3107
+		return $tabs;
3108
+	}
3109
+    
3110
+    
3111
+	/**
3112
+	 * This prepares the content of the messenger meta box admin settings
3113
+	 *
3114
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3115
+	 *
3116
+	 * @return string            html formatted content
3117
+	 */
3118
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3119
+	{
3120
+        
3121
+		$fields                                         = $messenger->get_admin_settings_fields();
3122
+		$settings_template_args['template_form_fields'] = '';
3123
+        
3124
+		//is $messenger active?
3125
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3126
+        
3127
+        
3128
+		if ( ! empty($fields)) {
3129 3129
             
3130
-            $existing_settings = $messenger->get_existing_admin_settings();
3130
+			$existing_settings = $messenger->get_existing_admin_settings();
3131 3131
             
3132
-            foreach ($fields as $fldname => $fldprops) {
3133
-                $field_id                       = $messenger->name . '-' . $fldname;
3134
-                $template_form_field[$field_id] = array(
3135
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3136
-                    'label'      => $fldprops['label'],
3137
-                    'input'      => $fldprops['field_type'],
3138
-                    'type'       => $fldprops['value_type'],
3139
-                    'required'   => $fldprops['required'],
3140
-                    'validation' => $fldprops['validation'],
3141
-                    'value'      => isset($existing_settings[$field_id])
3142
-                        ? $existing_settings[$field_id]
3143
-                        : $fldprops['default'],
3144
-                    'css_class'  => '',
3145
-                    'format'     => $fldprops['format']
3146
-                );
3147
-            }
3132
+			foreach ($fields as $fldname => $fldprops) {
3133
+				$field_id                       = $messenger->name . '-' . $fldname;
3134
+				$template_form_field[$field_id] = array(
3135
+					'name'       => 'messenger_settings[' . $field_id . ']',
3136
+					'label'      => $fldprops['label'],
3137
+					'input'      => $fldprops['field_type'],
3138
+					'type'       => $fldprops['value_type'],
3139
+					'required'   => $fldprops['required'],
3140
+					'validation' => $fldprops['validation'],
3141
+					'value'      => isset($existing_settings[$field_id])
3142
+						? $existing_settings[$field_id]
3143
+						: $fldprops['default'],
3144
+					'css_class'  => '',
3145
+					'format'     => $fldprops['format']
3146
+				);
3147
+			}
3148 3148
             
3149 3149
             
3150
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3151
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3152
-                : '';
3153
-        }
3154
-        
3155
-        //we also need some hidden fields
3156
-        $settings_template_args['hidden_fields'] = array(
3157
-            'messenger_settings[messenger]' => array(
3158
-                'type'  => 'hidden',
3159
-                'value' => $messenger->name
3160
-            ),
3161
-            'type'                          => array(
3162
-                'type'  => 'hidden',
3163
-                'value' => 'messenger'
3164
-            )
3165
-        );
3166
-        
3167
-        //make sure any active message types that are existing are included in the hidden fields
3168
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3169
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3170
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3171
-                    'type'  => 'hidden',
3172
-                    'value' => $mt
3173
-                );
3174
-            }
3175
-        }
3176
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3177
-            $settings_template_args['hidden_fields'],
3178
-            'array'
3179
-        );
3180
-        $active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3181
-        
3182
-        $settings_template_args['messenger']           = $messenger->name;
3183
-        $settings_template_args['description']         = $messenger->description;
3184
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3185
-        
3186
-        
3187
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3188
-            ? $settings_template_args['show_hide_edit_form']
3189
-            : ' hidden';
3190
-        
3191
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3192
-            ? ' hidden'
3193
-            : $settings_template_args['show_hide_edit_form'];
3194
-        
3195
-        
3196
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3197
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3198
-        $settings_template_args['on_off_status'] = $active ? true : false;
3199
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3200
-        $content                                 = EEH_Template::display_template($template, $settings_template_args,
3201
-            true);
3202
-        
3203
-        return $content;
3204
-    }
3205
-    
3206
-    
3207
-    /**
3208
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3209
-     */
3210
-    public function activate_messenger_toggle()
3211
-    {
3212
-        $success = true;
3213
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3214
-        //let's check that we have required data
3215
-        if ( ! isset($this->_req_data['messenger'])) {
3216
-            EE_Error::add_error(
3217
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3218
-                __FILE__,
3219
-                __FUNCTION__,
3220
-                __LINE__
3221
-            );
3222
-            $success = false;
3223
-        }
3224
-        
3225
-        //do a nonce check here since we're not arriving via a normal route
3226
-        $nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3227
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3228
-        
3229
-        $this->_verify_nonce($nonce, $nonce_ref);
3230
-        
3231
-        
3232
-        if ( ! isset($this->_req_data['status'])) {
3233
-            EE_Error::add_error(
3234
-                __(
3235
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3236
-                    'event_espresso'
3237
-                ),
3238
-                __FILE__,
3239
-                __FUNCTION__,
3240
-                __LINE__
3241
-            );
3242
-            $success = false;
3243
-        }
3244
-        
3245
-        //do check to verify we have a valid status.
3246
-        $status = $this->_req_data['status'];
3247
-        
3248
-        if ($status != 'off' && $status != 'on') {
3249
-            EE_Error::add_error(
3250
-                sprintf(
3251
-                    __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3252
-                    $this->_req_data['status']
3253
-                ),
3254
-                __FILE__,
3255
-                __FUNCTION__,
3256
-                __LINE__
3257
-            );
3258
-            $success = false;
3259
-        }
3260
-        
3261
-        if ($success) {
3262
-            //made it here?  Stop dawdling then!!
3263
-            $success = $status == 'off'
3264
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3265
-                : $this->_activate_messenger($this->_req_data['messenger']);
3266
-        }
3267
-        
3268
-        $this->_template_args['success'] = $success;
3269
-        
3270
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3271
-        $this->_return_json();
3272
-        
3273
-    }
3274
-    
3275
-    
3276
-    /**
3277
-     * used by ajax from the messages settings page to activate|deactivate a message type
3278
-     *
3279
-     */
3280
-    public function activate_mt_toggle()
3281
-    {
3282
-        $success = true;
3283
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3284
-        
3285
-        //let's make sure we have the necessary data
3286
-        if ( ! isset($this->_req_data['message_type'])) {
3287
-            EE_Error::add_error(
3288
-                __('Message Type name needed to toggle activation. None given', 'event_espresso'),
3289
-                __FILE__, __FUNCTION__, __LINE__
3290
-            );
3291
-            $success = false;
3292
-        }
3293
-        
3294
-        if ( ! isset($this->_req_data['messenger'])) {
3295
-            EE_Error::add_error(
3296
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3297
-                __FILE__, __FUNCTION__, __LINE__
3298
-            );
3299
-            $success = false;
3300
-        }
3301
-        
3302
-        if ( ! isset($this->_req_data['status'])) {
3303
-            EE_Error::add_error(
3304
-                __('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3305
-                    'event_espresso'),
3306
-                __FILE__, __FUNCTION__, __LINE__
3307
-            );
3308
-            $success = false;
3309
-        }
3310
-        
3311
-        
3312
-        //do check to verify we have a valid status.
3313
-        $status = $this->_req_data['status'];
3314
-        
3315
-        if ($status != 'activate' && $status != 'deactivate') {
3316
-            EE_Error::add_error(
3317
-                sprintf(
3318
-                    __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3319
-                    $this->_req_data['status']
3320
-                ),
3321
-                __FILE__, __FUNCTION__, __LINE__
3322
-            );
3323
-            $success = false;
3324
-        }
3325
-        
3326
-        
3327
-        //do a nonce check here since we're not arriving via a normal route
3328
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3329
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3330
-        
3331
-        $this->_verify_nonce($nonce, $nonce_ref);
3332
-        
3333
-        if ($success) {
3334
-            //made it here? um, what are you waiting for then?
3335
-            $success = $status == 'deactivate'
3336
-                ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3337
-                    $this->_req_data['message_type'])
3338
-                : $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3339
-                    $this->_req_data['message_type']);
3340
-        }
3341
-        
3342
-        $this->_template_args['success'] = $success;
3343
-        $this->_return_json();
3344
-    }
3345
-    
3346
-    
3347
-    /**
3348
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3349
-     *
3350
-     * @param string $messenger_name The name of the messenger being activated
3351
-     *
3352
-     * @return bool
3353
-     */
3354
-    protected function _activate_messenger($messenger_name)
3355
-    {
3356
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3357
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3358
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3359
-        
3360
-        //ensure is active
3361
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3362
-        
3363
-        //set response_data for reload
3364
-        foreach ($message_types_to_activate as $message_type_name) {
3365
-            /** @var EE_message_type $message_type */
3366
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3367
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3368
-                    $message_type_name)
3369
-                && $message_type instanceof EE_message_type
3370
-            ) {
3371
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3372
-                if ($message_type->get_admin_settings_fields()) {
3373
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3374
-                }
3375
-            }
3376
-        }
3377
-        
3378
-        //add success message for activating messenger
3379
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3380
-        
3381
-    }
3382
-    
3383
-    
3384
-    /**
3385
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3386
-     *
3387
-     * @param string $messenger_name The name of the messenger being activated
3388
-     *
3389
-     * @return bool
3390
-     */
3391
-    protected function _deactivate_messenger($messenger_name)
3392
-    {
3393
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3394
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3395
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3396
-        
3397
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3398
-    }
3399
-    
3400
-    
3401
-    /**
3402
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3403
-     *
3404
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3405
-     * @param string $message_type_name The name of the message type being activated for the messenger
3406
-     *
3407
-     * @return bool
3408
-     */
3409
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3410
-    {
3411
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3412
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3413
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3414
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3415
-        
3416
-        //ensure is active
3417
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3418
-        
3419
-        //set response for load
3420
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3421
-            $message_type_name)
3422
-        ) {
3423
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3424
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3425
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3426
-            }
3427
-        }
3428
-        
3429
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3430
-            $message_type_to_activate);
3431
-    }
3432
-    
3433
-    
3434
-    /**
3435
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3436
-     *
3437
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3438
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3439
-     *
3440
-     * @return bool
3441
-     */
3442
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3443
-    {
3444
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3445
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3446
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3447
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3448
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3449
-        
3450
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3451
-            $message_type_to_deactivate);
3452
-    }
3453
-    
3454
-    
3455
-    /**
3456
-     * This just initializes the defaults for activating messenger and message type responses.
3457
-     */
3458
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
3459
-    {
3460
-        $this->_template_args['data']['active_mts'] = array();
3461
-        $this->_template_args['data']['mt_reload']  = array();
3462
-    }
3463
-    
3464
-    
3465
-    /**
3466
-     * Setup appropriate response for activating a messenger and/or message types
3467
-     *
3468
-     * @param EE_messenger         $messenger
3469
-     * @param EE_message_type|null $message_type
3470
-     *
3471
-     * @return bool
3472
-     * @throws EE_Error
3473
-     */
3474
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
3475
-        $messenger,
3476
-        EE_Message_Type $message_type = null
3477
-    ) {
3478
-        //if $messenger isn't a valid messenger object then get out.
3479
-        if ( ! $messenger instanceof EE_Messenger) {
3480
-            EE_Error::add_error(
3481
-                __('The messenger being activated is not a valid messenger', 'event_espresso'),
3482
-                __FILE__,
3483
-                __FUNCTION__,
3484
-                __LINE__
3485
-            );
3150
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3151
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3152
+				: '';
3153
+		}
3154
+        
3155
+		//we also need some hidden fields
3156
+		$settings_template_args['hidden_fields'] = array(
3157
+			'messenger_settings[messenger]' => array(
3158
+				'type'  => 'hidden',
3159
+				'value' => $messenger->name
3160
+			),
3161
+			'type'                          => array(
3162
+				'type'  => 'hidden',
3163
+				'value' => 'messenger'
3164
+			)
3165
+		);
3166
+        
3167
+		//make sure any active message types that are existing are included in the hidden fields
3168
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3169
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3170
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3171
+					'type'  => 'hidden',
3172
+					'value' => $mt
3173
+				);
3174
+			}
3175
+		}
3176
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3177
+			$settings_template_args['hidden_fields'],
3178
+			'array'
3179
+		);
3180
+		$active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3181
+        
3182
+		$settings_template_args['messenger']           = $messenger->name;
3183
+		$settings_template_args['description']         = $messenger->description;
3184
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3185
+        
3186
+        
3187
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3188
+			? $settings_template_args['show_hide_edit_form']
3189
+			: ' hidden';
3190
+        
3191
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3192
+			? ' hidden'
3193
+			: $settings_template_args['show_hide_edit_form'];
3194
+        
3195
+        
3196
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3197
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3198
+		$settings_template_args['on_off_status'] = $active ? true : false;
3199
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3200
+		$content                                 = EEH_Template::display_template($template, $settings_template_args,
3201
+			true);
3202
+        
3203
+		return $content;
3204
+	}
3205
+    
3206
+    
3207
+	/**
3208
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3209
+	 */
3210
+	public function activate_messenger_toggle()
3211
+	{
3212
+		$success = true;
3213
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3214
+		//let's check that we have required data
3215
+		if ( ! isset($this->_req_data['messenger'])) {
3216
+			EE_Error::add_error(
3217
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3218
+				__FILE__,
3219
+				__FUNCTION__,
3220
+				__LINE__
3221
+			);
3222
+			$success = false;
3223
+		}
3224
+        
3225
+		//do a nonce check here since we're not arriving via a normal route
3226
+		$nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3227
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3228
+        
3229
+		$this->_verify_nonce($nonce, $nonce_ref);
3230
+        
3231
+        
3232
+		if ( ! isset($this->_req_data['status'])) {
3233
+			EE_Error::add_error(
3234
+				__(
3235
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3236
+					'event_espresso'
3237
+				),
3238
+				__FILE__,
3239
+				__FUNCTION__,
3240
+				__LINE__
3241
+			);
3242
+			$success = false;
3243
+		}
3244
+        
3245
+		//do check to verify we have a valid status.
3246
+		$status = $this->_req_data['status'];
3247
+        
3248
+		if ($status != 'off' && $status != 'on') {
3249
+			EE_Error::add_error(
3250
+				sprintf(
3251
+					__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3252
+					$this->_req_data['status']
3253
+				),
3254
+				__FILE__,
3255
+				__FUNCTION__,
3256
+				__LINE__
3257
+			);
3258
+			$success = false;
3259
+		}
3260
+        
3261
+		if ($success) {
3262
+			//made it here?  Stop dawdling then!!
3263
+			$success = $status == 'off'
3264
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3265
+				: $this->_activate_messenger($this->_req_data['messenger']);
3266
+		}
3267
+        
3268
+		$this->_template_args['success'] = $success;
3269
+        
3270
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3271
+		$this->_return_json();
3272
+        
3273
+	}
3274
+    
3275
+    
3276
+	/**
3277
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3278
+	 *
3279
+	 */
3280
+	public function activate_mt_toggle()
3281
+	{
3282
+		$success = true;
3283
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3284
+        
3285
+		//let's make sure we have the necessary data
3286
+		if ( ! isset($this->_req_data['message_type'])) {
3287
+			EE_Error::add_error(
3288
+				__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3289
+				__FILE__, __FUNCTION__, __LINE__
3290
+			);
3291
+			$success = false;
3292
+		}
3293
+        
3294
+		if ( ! isset($this->_req_data['messenger'])) {
3295
+			EE_Error::add_error(
3296
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3297
+				__FILE__, __FUNCTION__, __LINE__
3298
+			);
3299
+			$success = false;
3300
+		}
3301
+        
3302
+		if ( ! isset($this->_req_data['status'])) {
3303
+			EE_Error::add_error(
3304
+				__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3305
+					'event_espresso'),
3306
+				__FILE__, __FUNCTION__, __LINE__
3307
+			);
3308
+			$success = false;
3309
+		}
3310
+        
3311
+        
3312
+		//do check to verify we have a valid status.
3313
+		$status = $this->_req_data['status'];
3314
+        
3315
+		if ($status != 'activate' && $status != 'deactivate') {
3316
+			EE_Error::add_error(
3317
+				sprintf(
3318
+					__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3319
+					$this->_req_data['status']
3320
+				),
3321
+				__FILE__, __FUNCTION__, __LINE__
3322
+			);
3323
+			$success = false;
3324
+		}
3325
+        
3326
+        
3327
+		//do a nonce check here since we're not arriving via a normal route
3328
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3329
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3330
+        
3331
+		$this->_verify_nonce($nonce, $nonce_ref);
3332
+        
3333
+		if ($success) {
3334
+			//made it here? um, what are you waiting for then?
3335
+			$success = $status == 'deactivate'
3336
+				? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3337
+					$this->_req_data['message_type'])
3338
+				: $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3339
+					$this->_req_data['message_type']);
3340
+		}
3341
+        
3342
+		$this->_template_args['success'] = $success;
3343
+		$this->_return_json();
3344
+	}
3345
+    
3346
+    
3347
+	/**
3348
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3349
+	 *
3350
+	 * @param string $messenger_name The name of the messenger being activated
3351
+	 *
3352
+	 * @return bool
3353
+	 */
3354
+	protected function _activate_messenger($messenger_name)
3355
+	{
3356
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3357
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3358
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3359
+        
3360
+		//ensure is active
3361
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3362
+        
3363
+		//set response_data for reload
3364
+		foreach ($message_types_to_activate as $message_type_name) {
3365
+			/** @var EE_message_type $message_type */
3366
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3367
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3368
+					$message_type_name)
3369
+				&& $message_type instanceof EE_message_type
3370
+			) {
3371
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3372
+				if ($message_type->get_admin_settings_fields()) {
3373
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3374
+				}
3375
+			}
3376
+		}
3377
+        
3378
+		//add success message for activating messenger
3379
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3380
+        
3381
+	}
3382
+    
3383
+    
3384
+	/**
3385
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3386
+	 *
3387
+	 * @param string $messenger_name The name of the messenger being activated
3388
+	 *
3389
+	 * @return bool
3390
+	 */
3391
+	protected function _deactivate_messenger($messenger_name)
3392
+	{
3393
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3394
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3395
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3396
+        
3397
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3398
+	}
3399
+    
3400
+    
3401
+	/**
3402
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3403
+	 *
3404
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3405
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3406
+	 *
3407
+	 * @return bool
3408
+	 */
3409
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3410
+	{
3411
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3412
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3413
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3414
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3415
+        
3416
+		//ensure is active
3417
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3418
+        
3419
+		//set response for load
3420
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3421
+			$message_type_name)
3422
+		) {
3423
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3424
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3425
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3426
+			}
3427
+		}
3428
+        
3429
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3430
+			$message_type_to_activate);
3431
+	}
3432
+    
3433
+    
3434
+	/**
3435
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3436
+	 *
3437
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3438
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3439
+	 *
3440
+	 * @return bool
3441
+	 */
3442
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3443
+	{
3444
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3445
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3446
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3447
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3448
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3449
+        
3450
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3451
+			$message_type_to_deactivate);
3452
+	}
3453
+    
3454
+    
3455
+	/**
3456
+	 * This just initializes the defaults for activating messenger and message type responses.
3457
+	 */
3458
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
3459
+	{
3460
+		$this->_template_args['data']['active_mts'] = array();
3461
+		$this->_template_args['data']['mt_reload']  = array();
3462
+	}
3463
+    
3464
+    
3465
+	/**
3466
+	 * Setup appropriate response for activating a messenger and/or message types
3467
+	 *
3468
+	 * @param EE_messenger         $messenger
3469
+	 * @param EE_message_type|null $message_type
3470
+	 *
3471
+	 * @return bool
3472
+	 * @throws EE_Error
3473
+	 */
3474
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
3475
+		$messenger,
3476
+		EE_Message_Type $message_type = null
3477
+	) {
3478
+		//if $messenger isn't a valid messenger object then get out.
3479
+		if ( ! $messenger instanceof EE_Messenger) {
3480
+			EE_Error::add_error(
3481
+				__('The messenger being activated is not a valid messenger', 'event_espresso'),
3482
+				__FILE__,
3483
+				__FUNCTION__,
3484
+				__LINE__
3485
+			);
3486 3486
             
3487
-            return false;
3488
-        }
3489
-        //activated
3490
-        if ($this->_template_args['data']['active_mts']) {
3491
-            EE_Error::overwrite_success();
3492
-            //activated a message type with the messenger
3493
-            if ($message_type instanceof EE_message_type) {
3494
-                EE_Error::add_success(
3495
-                    sprintf(
3496
-                        __('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3497
-                        ucwords($message_type->label['singular']),
3498
-                        ucwords($messenger->label['singular'])
3499
-                    )
3500
-                );
3487
+			return false;
3488
+		}
3489
+		//activated
3490
+		if ($this->_template_args['data']['active_mts']) {
3491
+			EE_Error::overwrite_success();
3492
+			//activated a message type with the messenger
3493
+			if ($message_type instanceof EE_message_type) {
3494
+				EE_Error::add_success(
3495
+					sprintf(
3496
+						__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3497
+						ucwords($message_type->label['singular']),
3498
+						ucwords($messenger->label['singular'])
3499
+					)
3500
+				);
3501 3501
                 
3502
-                //if message type was invoice then let's make sure we activate the invoice payment method.
3503
-                if ($message_type->name == 'invoice') {
3504
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
3505
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3506
-                    if ($pm instanceof EE_Payment_Method) {
3507
-                        EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
3508
-                            'event_espresso'));
3509
-                    }
3510
-                }
3511
-                //just toggles the entire messenger
3512
-            } else {
3513
-                EE_Error::add_success(
3514
-                    sprintf(
3515
-                        __('%s messenger has been successfully activated', 'event_espresso'),
3516
-                        ucwords($messenger->label['singular'])
3517
-                    )
3518
-                );
3519
-            }
3502
+				//if message type was invoice then let's make sure we activate the invoice payment method.
3503
+				if ($message_type->name == 'invoice') {
3504
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
3505
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3506
+					if ($pm instanceof EE_Payment_Method) {
3507
+						EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
3508
+							'event_espresso'));
3509
+					}
3510
+				}
3511
+				//just toggles the entire messenger
3512
+			} else {
3513
+				EE_Error::add_success(
3514
+					sprintf(
3515
+						__('%s messenger has been successfully activated', 'event_espresso'),
3516
+						ucwords($messenger->label['singular'])
3517
+					)
3518
+				);
3519
+			}
3520 3520
             
3521
-            return true;
3521
+			return true;
3522 3522
             
3523
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3524
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3525
-            //in which case we just give a success message for the messenger being successfully activated.
3526
-        } else {
3527
-            if ( ! $messenger->get_default_message_types()) {
3528
-                //messenger doesn't have any default message types so still a success.
3529
-                EE_Error::add_success(
3530
-                    sprintf(
3531
-                        __('%s messenger was successfully activated.', 'event_espresso'),
3532
-                        ucwords($messenger->label['singular'])
3533
-                    )
3534
-                );
3523
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3524
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3525
+			//in which case we just give a success message for the messenger being successfully activated.
3526
+		} else {
3527
+			if ( ! $messenger->get_default_message_types()) {
3528
+				//messenger doesn't have any default message types so still a success.
3529
+				EE_Error::add_success(
3530
+					sprintf(
3531
+						__('%s messenger was successfully activated.', 'event_espresso'),
3532
+						ucwords($messenger->label['singular'])
3533
+					)
3534
+				);
3535 3535
                 
3536
-                return true;
3537
-            } else {
3538
-                EE_Error::add_error(
3539
-                    $message_type instanceof EE_message_type
3540
-                        ? sprintf(
3541
-                        __('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3542
-                        ucwords($message_type->label['singular']),
3543
-                        ucwords($messenger->label['singular'])
3544
-                    )
3545
-                        : sprintf(
3546
-                        __('%s messenger was not successfully activated', 'event_espresso'),
3547
-                        ucwords($messenger->label['singular'])
3548
-                    ),
3549
-                    __FILE__,
3550
-                    __FUNCTION__,
3551
-                    __LINE__
3552
-                );
3536
+				return true;
3537
+			} else {
3538
+				EE_Error::add_error(
3539
+					$message_type instanceof EE_message_type
3540
+						? sprintf(
3541
+						__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3542
+						ucwords($message_type->label['singular']),
3543
+						ucwords($messenger->label['singular'])
3544
+					)
3545
+						: sprintf(
3546
+						__('%s messenger was not successfully activated', 'event_espresso'),
3547
+						ucwords($messenger->label['singular'])
3548
+					),
3549
+					__FILE__,
3550
+					__FUNCTION__,
3551
+					__LINE__
3552
+				);
3553 3553
                 
3554
-                return false;
3555
-            }
3556
-        }
3557
-    }
3558
-    
3559
-    
3560
-    /**
3561
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
3562
-     *
3563
-     * @param EE_messenger         $messenger
3564
-     * @param EE_message_type|null $message_type
3565
-     *
3566
-     * @return bool
3567
-     */
3568
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3569
-        $messenger,
3570
-        EE_message_type $message_type = null
3571
-    ) {
3572
-        EE_Error::overwrite_success();
3573
-        
3574
-        //if $messenger isn't a valid messenger object then get out.
3575
-        if ( ! $messenger instanceof EE_Messenger) {
3576
-            EE_Error::add_error(
3577
-                __('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3578
-                __FILE__,
3579
-                __FUNCTION__,
3580
-                __LINE__
3581
-            );
3554
+				return false;
3555
+			}
3556
+		}
3557
+	}
3558
+    
3559
+    
3560
+	/**
3561
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
3562
+	 *
3563
+	 * @param EE_messenger         $messenger
3564
+	 * @param EE_message_type|null $message_type
3565
+	 *
3566
+	 * @return bool
3567
+	 */
3568
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3569
+		$messenger,
3570
+		EE_message_type $message_type = null
3571
+	) {
3572
+		EE_Error::overwrite_success();
3573
+        
3574
+		//if $messenger isn't a valid messenger object then get out.
3575
+		if ( ! $messenger instanceof EE_Messenger) {
3576
+			EE_Error::add_error(
3577
+				__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3578
+				__FILE__,
3579
+				__FUNCTION__,
3580
+				__LINE__
3581
+			);
3582 3582
             
3583
-            return false;
3584
-        }
3585
-        
3586
-        if ($message_type instanceof EE_message_type) {
3587
-            $message_type_name = $message_type->name;
3588
-            EE_Error::add_success(
3589
-                sprintf(
3590
-                    __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3591
-                    ucwords($message_type->label['singular']),
3592
-                    ucwords($messenger->label['singular'])
3593
-                )
3594
-            );
3595
-        } else {
3596
-            $message_type_name = '';
3597
-            EE_Error::add_success(
3598
-                sprintf(
3599
-                    __('%s messenger has been successfully deactivated.', 'event_espresso'),
3600
-                    ucwords($messenger->label['singular'])
3601
-                )
3602
-            );
3603
-        }
3604
-        
3605
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3606
-        if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3607
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
3608
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3609
-            if ($count_updated > 0) {
3610
-                $msg = $message_type_name == 'invoice'
3611
-                    ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
3612
-                        'event_espresso')
3613
-                    : __('Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
3614
-                        'event_espresso');
3615
-                EE_Error::add_attention($msg);
3616
-            }
3617
-        }
3618
-        
3619
-        return true;
3620
-    }
3621
-    
3622
-    
3623
-    /**
3624
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3625
-     */
3626
-    public function update_mt_form()
3627
-    {
3628
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3629
-            EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3630
-                __LINE__);
3631
-            $this->_return_json();
3632
-        }
3633
-        
3634
-        $message_types = $this->get_installed_message_types();
3635
-        
3636
-        $message_type = $message_types[$this->_req_data['message_type']];
3637
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3638
-        
3639
-        $content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3640
-        $this->_template_args['success'] = true;
3641
-        $this->_template_args['content'] = $content;
3642
-        $this->_return_json();
3643
-    }
3644
-    
3645
-    
3646
-    /**
3647
-     * this handles saving the settings for a messenger or message type
3648
-     *
3649
-     */
3650
-    public function save_settings()
3651
-    {
3652
-        if ( ! isset($this->_req_data['type'])) {
3653
-            EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3654
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3655
-            $this->_template_args['error'] = true;
3656
-            $this->_return_json();
3657
-        }
3658
-        
3659
-        
3660
-        if ($this->_req_data['type'] == 'messenger') {
3661
-            $settings  = $this->_req_data['messenger_settings']; //this should be an array.
3662
-            $messenger = $settings['messenger'];
3663
-            //let's setup the settings data
3664
-            foreach ($settings as $key => $value) {
3665
-                switch ($key) {
3666
-                    case 'messenger' :
3667
-                        unset($settings['messenger']);
3668
-                        break;
3669
-                    case 'message_types' :
3670
-                        unset($settings['message_types']);
3671
-                        break;
3672
-                    default :
3673
-                        $settings[$key] = $value;
3674
-                        break;
3675
-                }
3676
-            }
3677
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3678
-        } else if ($this->_req_data['type'] == 'message_type') {
3679
-            $settings     = $this->_req_data['message_type_settings'];
3680
-            $messenger    = $settings['messenger'];
3681
-            $message_type = $settings['message_type'];
3583
+			return false;
3584
+		}
3585
+        
3586
+		if ($message_type instanceof EE_message_type) {
3587
+			$message_type_name = $message_type->name;
3588
+			EE_Error::add_success(
3589
+				sprintf(
3590
+					__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3591
+					ucwords($message_type->label['singular']),
3592
+					ucwords($messenger->label['singular'])
3593
+				)
3594
+			);
3595
+		} else {
3596
+			$message_type_name = '';
3597
+			EE_Error::add_success(
3598
+				sprintf(
3599
+					__('%s messenger has been successfully deactivated.', 'event_espresso'),
3600
+					ucwords($messenger->label['singular'])
3601
+				)
3602
+			);
3603
+		}
3604
+        
3605
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3606
+		if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3607
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
3608
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3609
+			if ($count_updated > 0) {
3610
+				$msg = $message_type_name == 'invoice'
3611
+					? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
3612
+						'event_espresso')
3613
+					: __('Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
3614
+						'event_espresso');
3615
+				EE_Error::add_attention($msg);
3616
+			}
3617
+		}
3618
+        
3619
+		return true;
3620
+	}
3621
+    
3622
+    
3623
+	/**
3624
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3625
+	 */
3626
+	public function update_mt_form()
3627
+	{
3628
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3629
+			EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3630
+				__LINE__);
3631
+			$this->_return_json();
3632
+		}
3633
+        
3634
+		$message_types = $this->get_installed_message_types();
3635
+        
3636
+		$message_type = $message_types[$this->_req_data['message_type']];
3637
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3638
+        
3639
+		$content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3640
+		$this->_template_args['success'] = true;
3641
+		$this->_template_args['content'] = $content;
3642
+		$this->_return_json();
3643
+	}
3644
+    
3645
+    
3646
+	/**
3647
+	 * this handles saving the settings for a messenger or message type
3648
+	 *
3649
+	 */
3650
+	public function save_settings()
3651
+	{
3652
+		if ( ! isset($this->_req_data['type'])) {
3653
+			EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3654
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3655
+			$this->_template_args['error'] = true;
3656
+			$this->_return_json();
3657
+		}
3658
+        
3659
+        
3660
+		if ($this->_req_data['type'] == 'messenger') {
3661
+			$settings  = $this->_req_data['messenger_settings']; //this should be an array.
3662
+			$messenger = $settings['messenger'];
3663
+			//let's setup the settings data
3664
+			foreach ($settings as $key => $value) {
3665
+				switch ($key) {
3666
+					case 'messenger' :
3667
+						unset($settings['messenger']);
3668
+						break;
3669
+					case 'message_types' :
3670
+						unset($settings['message_types']);
3671
+						break;
3672
+					default :
3673
+						$settings[$key] = $value;
3674
+						break;
3675
+				}
3676
+			}
3677
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3678
+		} else if ($this->_req_data['type'] == 'message_type') {
3679
+			$settings     = $this->_req_data['message_type_settings'];
3680
+			$messenger    = $settings['messenger'];
3681
+			$message_type = $settings['message_type'];
3682 3682
             
3683
-            foreach ($settings as $key => $value) {
3684
-                switch ($key) {
3685
-                    case 'messenger' :
3686
-                        unset($settings['messenger']);
3687
-                        break;
3688
-                    case 'message_type' :
3689
-                        unset($settings['message_type']);
3690
-                        break;
3691
-                    default :
3692
-                        $settings[$key] = $value;
3693
-                        break;
3694
-                }
3695
-            }
3683
+			foreach ($settings as $key => $value) {
3684
+				switch ($key) {
3685
+					case 'messenger' :
3686
+						unset($settings['messenger']);
3687
+						break;
3688
+					case 'message_type' :
3689
+						unset($settings['message_type']);
3690
+						break;
3691
+					default :
3692
+						$settings[$key] = $value;
3693
+						break;
3694
+				}
3695
+			}
3696 3696
             
3697
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3698
-        }
3699
-        
3700
-        //okay we should have the data all setup.  Now we just update!
3701
-        $success = $this->_message_resource_manager->update_active_messengers_option();
3702
-        
3703
-        if ($success) {
3704
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
3705
-        } else {
3706
-            EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3707
-        }
3708
-        
3709
-        $this->_template_args['success'] = $success;
3710
-        $this->_return_json();
3711
-    }
3712
-    
3713
-    
3714
-    
3715
-    
3716
-    /**  EE MESSAGE PROCESSING ACTIONS **/
3717
-    
3718
-    
3719
-    /**
3720
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3721
-     * However, this does not send immediately, it just queues for sending.
3722
-     *
3723
-     * @since 4.9.0
3724
-     */
3725
-    protected function _generate_now()
3726
-    {
3727
-        $msg_ids = $this->_get_msg_ids_from_request();
3728
-        EED_Messages::generate_now($msg_ids);
3729
-        $this->_redirect_after_action(false, '', '', array(), true);
3730
-    }
3731
-    
3732
-    
3733
-    /**
3734
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3735
-     * are EEM_Message::status_resend or EEM_Message::status_idle
3736
-     *
3737
-     * @since 4.9.0
3738
-     *
3739
-     */
3740
-    protected function _generate_and_send_now()
3741
-    {
3742
-        $this->_generate_now();
3743
-        $this->_send_now();
3744
-        $this->_redirect_after_action(false, '', '', array(), true);
3745
-    }
3746
-    
3747
-    
3748
-    /**
3749
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3750
-     *
3751
-     * @since 4.9.0
3752
-     */
3753
-    protected function _queue_for_resending()
3754
-    {
3755
-        $msg_ids = $this->_get_msg_ids_from_request();
3756
-        EED_Messages::queue_for_resending($msg_ids);
3757
-        $this->_redirect_after_action(false, '', '', array(), true);
3758
-    }
3759
-    
3760
-    
3761
-    /**
3762
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3763
-     *
3764
-     * @since 4.9.0
3765
-     */
3766
-    protected function _send_now()
3767
-    {
3768
-        $msg_ids = $this->_get_msg_ids_from_request();
3769
-        EED_Messages::send_now($msg_ids);
3770
-        $this->_redirect_after_action(false, '', '', array(), true);
3771
-    }
3772
-    
3773
-    
3774
-    /**
3775
-     * Deletes EE_messages for IDs in the request.
3776
-     *
3777
-     * @since 4.9.0
3778
-     */
3779
-    protected function _delete_ee_messages()
3780
-    {
3781
-        $msg_ids       = $this->_get_msg_ids_from_request();
3782
-        $deleted_count = 0;
3783
-        foreach ($msg_ids as $msg_id) {
3784
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3785
-                $deleted_count++;
3786
-            }
3787
-        }
3788
-        if ($deleted_count) {
3789
-            $this->_redirect_after_action(
3790
-                true,
3791
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
3792
-                __('deleted', 'event_espresso')
3793
-            );
3794
-        } else {
3795
-            EE_Error::add_error(
3796
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3797
-                __FILE__, __FUNCTION__, __LINE__
3798
-            );
3799
-            $this->_redirect_after_action(false, '', '', array(), true);
3800
-        }
3801
-    }
3802
-    
3803
-    
3804
-    /**
3805
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3806
-     * @since 4.9.0
3807
-     * @return array
3808
-     */
3809
-    protected function _get_msg_ids_from_request()
3810
-    {
3811
-        if ( ! isset($this->_req_data['MSG_ID'])) {
3812
-            return array();
3813
-        }
3814
-        
3815
-        return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3816
-    }
3697
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3698
+		}
3699
+        
3700
+		//okay we should have the data all setup.  Now we just update!
3701
+		$success = $this->_message_resource_manager->update_active_messengers_option();
3702
+        
3703
+		if ($success) {
3704
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
3705
+		} else {
3706
+			EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3707
+		}
3708
+        
3709
+		$this->_template_args['success'] = $success;
3710
+		$this->_return_json();
3711
+	}
3712
+    
3713
+    
3714
+    
3715
+    
3716
+	/**  EE MESSAGE PROCESSING ACTIONS **/
3717
+    
3718
+    
3719
+	/**
3720
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3721
+	 * However, this does not send immediately, it just queues for sending.
3722
+	 *
3723
+	 * @since 4.9.0
3724
+	 */
3725
+	protected function _generate_now()
3726
+	{
3727
+		$msg_ids = $this->_get_msg_ids_from_request();
3728
+		EED_Messages::generate_now($msg_ids);
3729
+		$this->_redirect_after_action(false, '', '', array(), true);
3730
+	}
3731
+    
3732
+    
3733
+	/**
3734
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3735
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
3736
+	 *
3737
+	 * @since 4.9.0
3738
+	 *
3739
+	 */
3740
+	protected function _generate_and_send_now()
3741
+	{
3742
+		$this->_generate_now();
3743
+		$this->_send_now();
3744
+		$this->_redirect_after_action(false, '', '', array(), true);
3745
+	}
3746
+    
3747
+    
3748
+	/**
3749
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3750
+	 *
3751
+	 * @since 4.9.0
3752
+	 */
3753
+	protected function _queue_for_resending()
3754
+	{
3755
+		$msg_ids = $this->_get_msg_ids_from_request();
3756
+		EED_Messages::queue_for_resending($msg_ids);
3757
+		$this->_redirect_after_action(false, '', '', array(), true);
3758
+	}
3759
+    
3760
+    
3761
+	/**
3762
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3763
+	 *
3764
+	 * @since 4.9.0
3765
+	 */
3766
+	protected function _send_now()
3767
+	{
3768
+		$msg_ids = $this->_get_msg_ids_from_request();
3769
+		EED_Messages::send_now($msg_ids);
3770
+		$this->_redirect_after_action(false, '', '', array(), true);
3771
+	}
3772
+    
3773
+    
3774
+	/**
3775
+	 * Deletes EE_messages for IDs in the request.
3776
+	 *
3777
+	 * @since 4.9.0
3778
+	 */
3779
+	protected function _delete_ee_messages()
3780
+	{
3781
+		$msg_ids       = $this->_get_msg_ids_from_request();
3782
+		$deleted_count = 0;
3783
+		foreach ($msg_ids as $msg_id) {
3784
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3785
+				$deleted_count++;
3786
+			}
3787
+		}
3788
+		if ($deleted_count) {
3789
+			$this->_redirect_after_action(
3790
+				true,
3791
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
3792
+				__('deleted', 'event_espresso')
3793
+			);
3794
+		} else {
3795
+			EE_Error::add_error(
3796
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3797
+				__FILE__, __FUNCTION__, __LINE__
3798
+			);
3799
+			$this->_redirect_after_action(false, '', '', array(), true);
3800
+		}
3801
+	}
3802
+    
3803
+    
3804
+	/**
3805
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3806
+	 * @since 4.9.0
3807
+	 * @return array
3808
+	 */
3809
+	protected function _get_msg_ids_from_request()
3810
+	{
3811
+		if ( ! isset($this->_req_data['MSG_ID'])) {
3812
+			return array();
3813
+		}
3814
+        
3815
+		return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3816
+	}
3817 3817
     
3818 3818
     
3819 3819
 }
Please login to merge, or discard this patch.
core/services/collections/CollectionLoader.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -221,37 +221,37 @@
 block discarded – undo
221 221
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
222 222
 	 */
223 223
 	protected function setIdentifier( $entity, $identifier ) {
224
-	    switch($this->collection_details->identifierType()) {
225
-	        // every unique object gets added to the collection, but not duplicates of the exact same object
226
-            case CollectionDetails::ID_OBJECT_HASH :
227
-                $identifier = spl_object_hash($entity);
228
-                break;
229
-            // only one entity per class can be added to collection, like a singleton
230
-            case CollectionDetails::ID_CLASS_NAME :
231
-                $identifier = get_class($entity);
232
-                break;
233
-            // objects added to the collection based on entity callback, so the entity itself decides
234
-            case CollectionDetails::ID_CALLBACK_METHOD :
235
-                $identifier_callback = $this->collection_details->identifierCallback();
236
-                if ( ! method_exists($entity, $identifier_callback)) {
237
-                    throw new InvalidEntityException(
238
-                        $entity,
239
-                        $this->collection_details->getCollectionInterface(),
240
-                        sprintf(
241
-                            __(
242
-                                'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
224
+		switch($this->collection_details->identifierType()) {
225
+			// every unique object gets added to the collection, but not duplicates of the exact same object
226
+			case CollectionDetails::ID_OBJECT_HASH :
227
+				$identifier = spl_object_hash($entity);
228
+				break;
229
+			// only one entity per class can be added to collection, like a singleton
230
+			case CollectionDetails::ID_CLASS_NAME :
231
+				$identifier = get_class($entity);
232
+				break;
233
+			// objects added to the collection based on entity callback, so the entity itself decides
234
+			case CollectionDetails::ID_CALLBACK_METHOD :
235
+				$identifier_callback = $this->collection_details->identifierCallback();
236
+				if ( ! method_exists($entity, $identifier_callback)) {
237
+					throw new InvalidEntityException(
238
+						$entity,
239
+						$this->collection_details->getCollectionInterface(),
240
+						sprintf(
241
+							__(
242
+								'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
243 243
                                 of "%2$s", but does not contain this method.',
244
-                                'event_espresso'
245
-                            ),
246
-                            $identifier_callback,
247
-                            get_class($entity)
248
-                        )
249
-                    );
250
-                }
251
-                $identifier = $entity->{$identifier_callback}();
252
-                break;
253
-
254
-        }
244
+								'event_espresso'
245
+							),
246
+							$identifier_callback,
247
+							get_class($entity)
248
+						)
249
+					);
250
+				}
251
+				$identifier = $entity->{$identifier_callback}();
252
+				break;
253
+
254
+		}
255 255
 		return apply_filters(
256 256
 			'FHEE__CollectionLoader__addEntityToCollection__identifier',
257 257
 			$identifier,
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\services\locators\LocatorInterface;
9 9
 use EventEspresso\core\services\locators\FileLocator;
10 10
 
11
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
12
-	exit( 'No direct script access allowed' );
11
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
12
+	exit('No direct script access allowed');
13 13
 }
14 14
 
15 15
 
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 		LocatorInterface $file_locator = null
82 82
 	) {
83 83
 		$this->collection_details = $collection_details;
84
-		if ( ! $collection instanceof CollectionInterface ) {
85
-			$collection = new Collection( $this->collection_details->getCollectionInterface() );
84
+		if ( ! $collection instanceof CollectionInterface) {
85
+			$collection = new Collection($this->collection_details->getCollectionInterface());
86 86
 		}
87 87
 		$this->collection = $collection;
88 88
 		$this->file_locator = $file_locator;
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
111 111
 	 */
112 112
 	protected function loadAllFromFilepaths() {
113
-		if ( ! $this->file_locator instanceof FileLocator ) {
113
+		if ( ! $this->file_locator instanceof FileLocator) {
114 114
 			$this->file_locator = new FileLocator();
115 115
 		}
116
-		$this->file_locator->setFileMask( $this->collection_details->getFileMask() );
116
+		$this->file_locator->setFileMask($this->collection_details->getFileMask());
117 117
 		// find all of the files that match the file mask in the specified folder
118
-		$this->file_locator->locate( $this->collection_details->getCollectionPaths() );
118
+		$this->file_locator->locate($this->collection_details->getCollectionPaths());
119 119
 		// filter the results
120 120
 		$filepaths = (array) apply_filters(
121 121
 			'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
 			$this->collection_details->collectionName(),
124 124
 			$this->collection_details
125 125
 		);
126
-		if ( empty( $filepaths ) ) {
126
+		if (empty($filepaths)) {
127 127
 			return;
128 128
 		}
129
-		foreach ( $filepaths as $filepath ) {
130
-			$this->loadClassFromFilepath( $filepath );
129
+		foreach ($filepaths as $filepath) {
130
+			$this->loadClassFromFilepath($filepath);
131 131
 		}
132 132
 	}
133 133
 
@@ -144,22 +144,22 @@  discard block
 block discarded – undo
144 144
 	 * @throws \EventEspresso\core\exceptions\InvalidFilePathException
145 145
 	 * @throws \EventEspresso\core\exceptions\InvalidClassException
146 146
 	 */
147
-	protected function loadClassFromFilepath( $filepath ) {
148
-		if ( ! is_string( $filepath ) ) {
149
-			throw new InvalidDataTypeException( '$filepath', $filepath, 'string' );
147
+	protected function loadClassFromFilepath($filepath) {
148
+		if ( ! is_string($filepath)) {
149
+			throw new InvalidDataTypeException('$filepath', $filepath, 'string');
150 150
 		}
151
-		if ( ! is_readable( $filepath ) ) {
152
-			throw new InvalidFilePathException( $filepath );
151
+		if ( ! is_readable($filepath)) {
152
+			throw new InvalidFilePathException($filepath);
153 153
 		}
154
-		require_once( $filepath );
154
+		require_once($filepath);
155 155
 		// extract filename from path
156
-		$file_name = basename( $filepath );
156
+		$file_name = basename($filepath);
157 157
 		// now remove any file extensions
158
-		$class_name = \EEH_File::get_classname_from_filepath_with_standard_filename( $file_name );
159
-		if ( ! class_exists( $class_name ) ) {
160
-			throw new InvalidClassException( $class_name );
158
+		$class_name = \EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
159
+		if ( ! class_exists($class_name)) {
160
+			throw new InvalidClassException($class_name);
161 161
 		}
162
-		return $this->addEntityToCollection( new $class_name(), $file_name );
162
+		return $this->addEntityToCollection(new $class_name(), $file_name);
163 163
 	}
164 164
 
165 165
 
@@ -173,15 +173,15 @@  discard block
 block discarded – undo
173 173
 	 * @return string
174 174
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
175 175
 	 */
176
-	protected function addEntityToCollection( $entity, $identifier ) {
176
+	protected function addEntityToCollection($entity, $identifier) {
177 177
 		do_action(
178 178
 			'FHEE__CollectionLoader__addEntityToCollection__entity',
179 179
 			$entity,
180 180
 			$this->collection_details->collectionName(),
181 181
 			$this->collection_details
182 182
 		);
183
-		$identifier = $this->setIdentifier( $entity, $identifier );
184
-		if ( $this->collection->has( $identifier ) ) {
183
+		$identifier = $this->setIdentifier($entity, $identifier);
184
+		if ($this->collection->has($identifier)) {
185 185
 			do_action(
186 186
 				'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
187 187
 				$this,
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 			);
191 191
 			return CollectionLoader::ENTITY_EXISTS;
192 192
 		}
193
-		if( $this->collection->add( $entity, $identifier ) ) {
193
+		if ($this->collection->add($entity, $identifier)) {
194 194
 			do_action(
195 195
 				'FHEE__CollectionLoader__addEntityToCollection__entity_added',
196 196
 				$this,
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
 	 * @return string
221 221
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
222 222
 	 */
223
-	protected function setIdentifier( $entity, $identifier ) {
224
-	    switch($this->collection_details->identifierType()) {
223
+	protected function setIdentifier($entity, $identifier) {
224
+	    switch ($this->collection_details->identifierType()) {
225 225
 	        // every unique object gets added to the collection, but not duplicates of the exact same object
226 226
             case CollectionDetails::ID_OBJECT_HASH :
227 227
                 $identifier = spl_object_hash($entity);
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
 			$this->collection_details->collectionName(),
279 279
 			$this->collection_details
280 280
 		);
281
-		foreach ( $FQCNs as $FQCN ) {
282
-			$this->loadClassFromFQCN( $FQCN );
281
+		foreach ($FQCNs as $FQCN) {
282
+			$this->loadClassFromFQCN($FQCN);
283 283
 		}
284 284
 	}
285 285
 
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
 	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
296 296
 	 * @throws \EventEspresso\core\exceptions\InvalidClassException
297 297
 	 */
298
-	protected function loadClassFromFQCN( $FQCN ) {
299
-		if ( ! is_string( $FQCN ) ) {
300
-			throw new InvalidDataTypeException( '$FQCN', $FQCN, 'string' );
298
+	protected function loadClassFromFQCN($FQCN) {
299
+		if ( ! is_string($FQCN)) {
300
+			throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
301 301
 		}
302
-		if ( ! class_exists( $FQCN ) ) {
303
-			throw new InvalidClassException( $FQCN );
302
+		if ( ! class_exists($FQCN)) {
303
+			throw new InvalidClassException($FQCN);
304 304
 		}
305 305
 		return $this->addEntityToCollection(
306
-			\EE_Registry::instance()->create( $FQCN ),
306
+			\EE_Registry::instance()->create($FQCN),
307 307
 			$FQCN
308 308
 		);
309 309
 	}
Please login to merge, or discard this patch.
core/helpers/EEH_Event_View.helper.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      * get_event
37 37
      * attempts to retrieve an EE_Event object any way it can
38 38
      *
39
-     * @param int|WP_Post $EVT_ID
39
+     * @param integer $EVT_ID
40 40
      * @return EE_Event|null
41 41
      * @throws \EE_Error
42 42
      */
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 *
114 114
 	 *  @access 	public
115 115
 	 * @param    int $EVT_ID
116
-	 *  @return 	string
116
+	 *  @return 	boolean
117 117
 	 */
118 118
 	public static function event_has_content_or_excerpt( $EVT_ID = 0 ) {
119 119
 		$event = EEH_Event_View::get_event( $EVT_ID );
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 *    event_active_status
134 134
 	 *
135 135
 	 * @access    public
136
-	 * @param null $num_words
136
+	 * @param integer $num_words
137 137
 	 * @param null $more
138 138
 	 * @return    string
139 139
 	 */
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 	 *
445 445
 	 * @access    public
446 446
 	 * @param int $EVT_ID
447
-	 * @param null $include_expired
447
+	 * @param false|null $include_expired
448 448
 	 * @param bool $include_deleted
449 449
 	 * @param null $limit
450 450
 	 * @return EE_Datetime[]
Please login to merge, or discard this patch.
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -32,47 +32,47 @@  discard block
 block discarded – undo
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * get_event
37
-     * attempts to retrieve an EE_Event object any way it can
38
-     *
39
-     * @param int|WP_Post $EVT_ID
40
-     * @return EE_Event|null
41
-     * @throws \EE_Error
42
-     */
35
+	/**
36
+	 * get_event
37
+	 * attempts to retrieve an EE_Event object any way it can
38
+	 *
39
+	 * @param int|WP_Post $EVT_ID
40
+	 * @return EE_Event|null
41
+	 * @throws \EE_Error
42
+	 */
43 43
 	public static function get_event( $EVT_ID = 0 ) {
44
-        // international newspaper?
45
-        global $post;
46
-        $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
47
-            ? $EVT_ID->ID
48
-            : absint($EVT_ID);
49
-        // do we already have the Event  you are looking for?
50
-        if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
51
-            return EEH_Event_View::$_event;
52
-        }
53
-        //reset property so that the new event is cached.
54
-        EEH_Event_View::$_event = null;
55
-
56
-        if ($EVT_ID || $post instanceof WP_Post) {
57
-            //if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
58
-            //then let's just use that cached event on the $post object.
59
-            if ($post->post_type === 'espresso_events'
60
-                && isset($post->EE_Event)
61
-                && ($EVT_ID === 0
62
-                    || $EVT_ID === $post->ID
63
-                    )
64
-            ) {
65
-                EEH_Event_View::$_event = $post->EE_Event;
66
-            }
67
-
68
-            //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
69
-            if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
70
-                EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
71
-            }
72
-        }
73
-
74
-        return EEH_Event_View::$_event;
75
-    }
44
+		// international newspaper?
45
+		global $post;
46
+		$EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
47
+			? $EVT_ID->ID
48
+			: absint($EVT_ID);
49
+		// do we already have the Event  you are looking for?
50
+		if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
51
+			return EEH_Event_View::$_event;
52
+		}
53
+		//reset property so that the new event is cached.
54
+		EEH_Event_View::$_event = null;
55
+
56
+		if ($EVT_ID || $post instanceof WP_Post) {
57
+			//if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
58
+			//then let's just use that cached event on the $post object.
59
+			if ($post->post_type === 'espresso_events'
60
+				&& isset($post->EE_Event)
61
+				&& ($EVT_ID === 0
62
+					|| $EVT_ID === $post->ID
63
+					)
64
+			) {
65
+				EEH_Event_View::$_event = $post->EE_Event;
66
+			}
67
+
68
+			//If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
69
+			if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
70
+				EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
71
+			}
72
+		}
73
+
74
+		return EEH_Event_View::$_event;
75
+	}
76 76
 
77 77
 
78 78
 
@@ -148,58 +148,58 @@  discard block
 block discarded – undo
148 148
 	 * @return    string
149 149
 	 */
150 150
 	public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) {
151
-        global $post;
151
+		global $post;
152 152
 		ob_start();
153 153
 		if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) {
154 154
 			// admin has chosen "full description"
155
-            // for the "Event Espresso - Events > Templates > Display Description" option
155
+			// for the "Event Espresso - Events > Templates > Display Description" option
156 156
 			the_content();
157 157
 		} else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) {
158
-            if ( has_excerpt( $post->ID )) {
159
-                // admin has chosen "excerpt (short desc)"
160
-                // for the "Event Espresso - Events > Templates > Display Description" option
161
-                // AND an excerpt actually exists
162
-                the_excerpt();
163
-            } else {
164
-                // admin has chosen "excerpt (short desc)"
165
-                // for the "Event Espresso - Events > Templates > Display Description" option
166
-                // but NO excerpt actually exists, so we need to create one
167
-                if ( ! empty( $num_words )) {
168
-                    if ( empty( $more )) {
169
-                        $more_link_text = __( '(more&hellip;)' );
170
-                        $more = ' <a href="' . get_permalink() . '"';
171
-                        $more .= ' class="more-link"';
172
-                        $more .= \EED_Events_Archive::link_target();
173
-                        $more .= '>' . $more_link_text . '</a>';
174
-                        $more = apply_filters( 'the_content_more_link', $more, $more_link_text );
175
-                    }
176
-                    $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' ));
177
-
178
-                    $content =  wp_trim_words( $content, $num_words, ' ' ) . $more;
179
-                } else {
180
-                    $content =  get_the_content();
181
-                }
182
-                global $allowedtags;
183
-                // make sure links are allowed
184
-                $allowedtags['a'] = isset($allowedtags['a'])
185
-                    ? $allowedtags['a']
186
-                    : array();
187
-                // as well as target attribute
188
-                $allowedtags['a']['target'] = isset($allowedtags['a']['target'])
189
-                    ? $allowedtags['a']['target']
190
-                    : false;
191
-                // but get previous value so we can reset it
192
-                $prev_value = $allowedtags['a']['target'];
193
-                $allowedtags['a']['target'] = true;
194
-                $content = wp_kses( $content, $allowedtags );
195
-                $content = strip_shortcodes( $content );
196
-                echo apply_filters( 'the_content', $content );
197
-                $allowedtags['a']['target'] = $prev_value;
198
-            }
199
-        } else {
200
-            // admin has chosen "none"
201
-            // for the "Event Espresso - Events > Templates > Display Description" option
202
-            echo apply_filters( 'the_content', '' );
158
+			if ( has_excerpt( $post->ID )) {
159
+				// admin has chosen "excerpt (short desc)"
160
+				// for the "Event Espresso - Events > Templates > Display Description" option
161
+				// AND an excerpt actually exists
162
+				the_excerpt();
163
+			} else {
164
+				// admin has chosen "excerpt (short desc)"
165
+				// for the "Event Espresso - Events > Templates > Display Description" option
166
+				// but NO excerpt actually exists, so we need to create one
167
+				if ( ! empty( $num_words )) {
168
+					if ( empty( $more )) {
169
+						$more_link_text = __( '(more&hellip;)' );
170
+						$more = ' <a href="' . get_permalink() . '"';
171
+						$more .= ' class="more-link"';
172
+						$more .= \EED_Events_Archive::link_target();
173
+						$more .= '>' . $more_link_text . '</a>';
174
+						$more = apply_filters( 'the_content_more_link', $more, $more_link_text );
175
+					}
176
+					$content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' ));
177
+
178
+					$content =  wp_trim_words( $content, $num_words, ' ' ) . $more;
179
+				} else {
180
+					$content =  get_the_content();
181
+				}
182
+				global $allowedtags;
183
+				// make sure links are allowed
184
+				$allowedtags['a'] = isset($allowedtags['a'])
185
+					? $allowedtags['a']
186
+					: array();
187
+				// as well as target attribute
188
+				$allowedtags['a']['target'] = isset($allowedtags['a']['target'])
189
+					? $allowedtags['a']['target']
190
+					: false;
191
+				// but get previous value so we can reset it
192
+				$prev_value = $allowedtags['a']['target'];
193
+				$allowedtags['a']['target'] = true;
194
+				$content = wp_kses( $content, $allowedtags );
195
+				$content = strip_shortcodes( $content );
196
+				echo apply_filters( 'the_content', $content );
197
+				$allowedtags['a']['target'] = $prev_value;
198
+			}
199
+		} else {
200
+			// admin has chosen "none"
201
+			// for the "Event Espresso - Events > Templates > Display Description" option
202
+			echo apply_filters( 'the_content', '' );
203 203
 		}
204 204
 		return ob_get_clean();
205 205
 	}
@@ -246,11 +246,11 @@  discard block
 block discarded – undo
246 246
 					$url = get_term_link( $term, 'espresso_venue_categories' );
247 247
 					if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) {
248 248
 						$category_links[] = '<a href="' . esc_url( $url )
249
-                                            . '" rel="tag"'
250
-                                            . \EED_Events_Archive::link_target()
251
-                                            .'>'
252
-                                            . $term->name
253
-                                            . '</a>';
249
+											. '" rel="tag"'
250
+											. \EED_Events_Archive::link_target()
251
+											.'>'
252
+											. $term->name
253
+											. '</a>';
254 254
 					}
255 255
 				}
256 256
 			}
Please login to merge, or discard this patch.
Spacing   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      * @return EE_Event|null
41 41
      * @throws \EE_Error
42 42
      */
43
-	public static function get_event( $EVT_ID = 0 ) {
43
+	public static function get_event($EVT_ID = 0) {
44 44
         // international newspaper?
45 45
         global $post;
46 46
         $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
             }
67 67
 
68 68
             //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
69
-            if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
69
+            if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
70 70
                 EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
71 71
             }
72 72
         }
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 	 * @param    int $EVT_ID
84 84
 	 * @return    boolean
85 85
 	 */
86
-	public static function display_ticket_selector( $EVT_ID = 0 ) {
87
-		$event = EEH_Event_View::get_event( $EVT_ID );
86
+	public static function display_ticket_selector($EVT_ID = 0) {
87
+		$event = EEH_Event_View::get_event($EVT_ID);
88 88
 		return $event instanceof EE_Event ? $event->display_ticket_selector() : FALSE;
89 89
 	}
90 90
 
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
 	 * @param    int $EVT_ID
98 98
 	 * @return    string
99 99
 	 */
100
-	public static function event_status( $EVT_ID = 0 ) {
101
-		$event = EEH_Event_View::get_event( $EVT_ID );
102
-		return $event instanceof EE_Event ? $event->pretty_active_status( FALSE ) : '';
100
+	public static function event_status($EVT_ID = 0) {
101
+		$event = EEH_Event_View::get_event($EVT_ID);
102
+		return $event instanceof EE_Event ? $event->pretty_active_status(FALSE) : '';
103 103
 	}
104 104
 
105 105
 
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
 	 * @param    int $EVT_ID
112 112
 	 *  @return 	string
113 113
 	 */
114
-	public static function event_active_status( $EVT_ID = 0 ) {
115
-		$event = EEH_Event_View::get_event( $EVT_ID );
114
+	public static function event_active_status($EVT_ID = 0) {
115
+		$event = EEH_Event_View::get_event($EVT_ID);
116 116
 		return $event instanceof EE_Event ? $event->pretty_active_status() : 'inactive';
117 117
 	}
118 118
 
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
 	 * @param    int $EVT_ID
126 126
 	 *  @return 	string
127 127
 	 */
128
-	public static function event_has_content_or_excerpt( $EVT_ID = 0 ) {
129
-		$event = EEH_Event_View::get_event( $EVT_ID );
128
+	public static function event_has_content_or_excerpt($EVT_ID = 0) {
129
+		$event = EEH_Event_View::get_event($EVT_ID);
130 130
 		$has_content_or_excerpt = FALSE;
131
-		if ( $event instanceof EE_Event ) {
132
-			$has_content_or_excerpt = $event->description() != '' || $event->short_description( NULL, NULL, TRUE ) != '' ? TRUE : FALSE;
131
+		if ($event instanceof EE_Event) {
132
+			$has_content_or_excerpt = $event->description() != '' || $event->short_description(NULL, NULL, TRUE) != '' ? TRUE : FALSE;
133 133
 		}
134
-		if ( is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) {
134
+		if (is_archive() && ! (espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list())) {
135 135
 			$has_content_or_excerpt = FALSE;
136 136
 		}
137 137
 		return $has_content_or_excerpt;
@@ -147,15 +147,15 @@  discard block
 block discarded – undo
147 147
 	 * @param null $more
148 148
 	 * @return    string
149 149
 	 */
150
-	public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) {
150
+	public static function event_content_or_excerpt($num_words = NULL, $more = NULL) {
151 151
         global $post;
152 152
 		ob_start();
153
-		if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) {
153
+		if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
154 154
 			// admin has chosen "full description"
155 155
             // for the "Event Espresso - Events > Templates > Display Description" option
156 156
 			the_content();
157
-		} else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) {
158
-            if ( has_excerpt( $post->ID )) {
157
+		} else if ((is_archive() && espresso_display_excerpt_in_event_list())) {
158
+            if (has_excerpt($post->ID)) {
159 159
                 // admin has chosen "excerpt (short desc)"
160 160
                 // for the "Event Espresso - Events > Templates > Display Description" option
161 161
                 // AND an excerpt actually exists
@@ -164,20 +164,20 @@  discard block
 block discarded – undo
164 164
                 // admin has chosen "excerpt (short desc)"
165 165
                 // for the "Event Espresso - Events > Templates > Display Description" option
166 166
                 // but NO excerpt actually exists, so we need to create one
167
-                if ( ! empty( $num_words )) {
168
-                    if ( empty( $more )) {
169
-                        $more_link_text = __( '(more&hellip;)' );
170
-                        $more = ' <a href="' . get_permalink() . '"';
167
+                if ( ! empty($num_words)) {
168
+                    if (empty($more)) {
169
+                        $more_link_text = __('(more&hellip;)');
170
+                        $more = ' <a href="'.get_permalink().'"';
171 171
                         $more .= ' class="more-link"';
172 172
                         $more .= \EED_Events_Archive::link_target();
173
-                        $more .= '>' . $more_link_text . '</a>';
174
-                        $more = apply_filters( 'the_content_more_link', $more, $more_link_text );
173
+                        $more .= '>'.$more_link_text.'</a>';
174
+                        $more = apply_filters('the_content_more_link', $more, $more_link_text);
175 175
                     }
176
-                    $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' ));
176
+                    $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
177 177
 
178
-                    $content =  wp_trim_words( $content, $num_words, ' ' ) . $more;
178
+                    $content = wp_trim_words($content, $num_words, ' ').$more;
179 179
                 } else {
180
-                    $content =  get_the_content();
180
+                    $content = get_the_content();
181 181
                 }
182 182
                 global $allowedtags;
183 183
                 // make sure links are allowed
@@ -191,15 +191,15 @@  discard block
 block discarded – undo
191 191
                 // but get previous value so we can reset it
192 192
                 $prev_value = $allowedtags['a']['target'];
193 193
                 $allowedtags['a']['target'] = true;
194
-                $content = wp_kses( $content, $allowedtags );
195
-                $content = strip_shortcodes( $content );
196
-                echo apply_filters( 'the_content', $content );
194
+                $content = wp_kses($content, $allowedtags);
195
+                $content = strip_shortcodes($content);
196
+                echo apply_filters('the_content', $content);
197 197
                 $allowedtags['a']['target'] = $prev_value;
198 198
             }
199 199
         } else {
200 200
             // admin has chosen "none"
201 201
             // for the "Event Espresso - Events > Templates > Display Description" option
202
-            echo apply_filters( 'the_content', '' );
202
+            echo apply_filters('the_content', '');
203 203
 		}
204 204
 		return ob_get_clean();
205 205
 	}
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
 	 * @param    int $EVT_ID
214 214
 	 *  @return 	EE_Ticket[]
215 215
 	 */
216
-	public static function event_tickets_available( $EVT_ID = 0 ) {
217
-		$event = EEH_Event_View::get_event( $EVT_ID );
216
+	public static function event_tickets_available($EVT_ID = 0) {
217
+		$event = EEH_Event_View::get_event($EVT_ID);
218 218
 		$tickets_available_for_purchase = array();
219
-		if( $event instanceof EE_Event ) {
220
-			$datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, FALSE );
221
-			foreach( $datetimes as $datetime ) {
222
-				$tickets_available_for_purchase = array_merge( $tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase() );
219
+		if ($event instanceof EE_Event) {
220
+			$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, FALSE);
221
+			foreach ($datetimes as $datetime) {
222
+				$tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
223 223
 			}
224 224
 		}
225 225
 		return $tickets_available_for_purchase;
@@ -235,17 +235,17 @@  discard block
 block discarded – undo
235 235
 	 * @param 	  bool   $hide_uncategorized
236 236
 	 * @return    string
237 237
 	 */
238
-	public static function event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE ) {
238
+	public static function event_categories($EVT_ID = 0, $hide_uncategorized = TRUE) {
239 239
 		$category_links = array();
240
-		$event = EEH_Event_View::get_event( $EVT_ID );
241
-		if ( $event instanceof EE_Event ) {
242
-			$event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' );
243
-			if ( $event_categories ) {
240
+		$event = EEH_Event_View::get_event($EVT_ID);
241
+		if ($event instanceof EE_Event) {
242
+			$event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
243
+			if ($event_categories) {
244 244
 				// loop thru terms and create links
245
-				foreach ( $event_categories as $term ) {
246
-					$url = get_term_link( $term, 'espresso_venue_categories' );
247
-					if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) {
248
-						$category_links[] = '<a href="' . esc_url( $url )
245
+				foreach ($event_categories as $term) {
246
+					$url = get_term_link($term, 'espresso_venue_categories');
247
+					if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) {
248
+						$category_links[] = '<a href="'.esc_url($url)
249 249
                                             . '" rel="tag"'
250 250
                                             . \EED_Events_Archive::link_target()
251 251
                                             .'>'
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 				}
256 256
 			}
257 257
 		}
258
-		return implode( ', ', $category_links );
258
+		return implode(', ', $category_links);
259 259
 	}
260 260
 
261 261
 
@@ -269,10 +269,10 @@  discard block
 block discarded – undo
269 269
 	 * @param int    $EVT_ID
270 270
 	 * @return    string
271 271
 	 */
272
-	public static function the_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) {
273
-		$datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID );
274
-		$format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
275
-		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) :  '';
272
+	public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) {
273
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
274
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
275
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
276 276
 	}
277 277
 
278 278
 
@@ -286,10 +286,10 @@  discard block
 block discarded – undo
286 286
 	 * @param int    $EVT_ID
287 287
 	 * @return    string
288 288
 	 */
289
-	public static function the_event_end_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) {
290
-		$datetime = EEH_Event_View::get_last_date_obj( $EVT_ID );
291
-		$format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
292
-		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : '';
289
+	public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) {
290
+		$datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
291
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
292
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
293 293
 	}
294 294
 
295 295
 
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
 	 * @param int    $EVT_ID
304 304
 	 * @return    string
305 305
 	 */
306
-	public static function the_earliest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) {
307
-		$datetime = EEH_Event_View::get_earliest_date_obj( $EVT_ID );
308
-		$format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
309
-		return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : '';
306
+	public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) {
307
+		$datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
308
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
309
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
310 310
 	}
311 311
 
312 312
 
@@ -320,10 +320,10 @@  discard block
 block discarded – undo
320 320
 	 * @param int    $EVT_ID
321 321
 	 * @return    string
322 322
 	 */
323
-	public static function the_latest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) {
324
-		$datetime = EEH_Event_View::get_latest_date_obj( $EVT_ID );
325
-		$format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
326
-		return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : '';
323
+	public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) {
324
+		$datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
325
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
326
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
327 327
 	}
328 328
 
329 329
 
@@ -335,13 +335,13 @@  discard block
 block discarded – undo
335 335
 	 * @param int $EVT_ID
336 336
 	 * @return    string
337 337
 	 */
338
-	public static function event_date_as_calendar_page( $EVT_ID = 0 ) {
339
-		$datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID );
340
-		if ( $datetime instanceof EE_Datetime ) {
338
+	public static function event_date_as_calendar_page($EVT_ID = 0) {
339
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
340
+		if ($datetime instanceof EE_Datetime) {
341 341
 	?>
342 342
 		<div class="event-date-calendar-page-dv">
343
-			<div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime( 'DTT_EVT_start', 'M' );?></div>
344
-			<div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date( 'd' );?></div>
343
+			<div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); ?></div>
344
+			<div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d'); ?></div>
345 345
 		</div>
346 346
 	<?php
347 347
 		}
@@ -356,17 +356,17 @@  discard block
 block discarded – undo
356 356
 	 * @param int $EVT_ID
357 357
 	 * @return    string
358 358
 	 */
359
-	public static function get_primary_date_obj( $EVT_ID = 0 ) {
360
-		$event = EEH_Event_View::get_event( $EVT_ID );
361
-		if ( $event instanceof EE_Event ) {
359
+	public static function get_primary_date_obj($EVT_ID = 0) {
360
+		$event = EEH_Event_View::get_event($EVT_ID);
361
+		if ($event instanceof EE_Event) {
362 362
 			$datetimes = $event->get_many_related(
363 363
 				'Datetime',
364 364
 				array(
365 365
 					'limit' => 1,
366
-					'order_by' => array( 'DTT_order' => 'ASC' )
366
+					'order_by' => array('DTT_order' => 'ASC')
367 367
 				)
368 368
 			);
369
-			return reset( $datetimes );
369
+			return reset($datetimes);
370 370
 		} else {
371 371
 			 return FALSE;
372 372
 		}
@@ -381,17 +381,17 @@  discard block
 block discarded – undo
381 381
 	 * @param int $EVT_ID
382 382
 	 * @return    string
383 383
 	 */
384
-	public static function get_last_date_obj( $EVT_ID = 0 ) {
385
-		$event = EEH_Event_View::get_event( $EVT_ID );
386
-		if ( $event instanceof EE_Event ) {
384
+	public static function get_last_date_obj($EVT_ID = 0) {
385
+		$event = EEH_Event_View::get_event($EVT_ID);
386
+		if ($event instanceof EE_Event) {
387 387
 			$datetimes = $event->get_many_related(
388 388
 				'Datetime',
389 389
 				array(
390 390
 					'limit' => 1,
391
-					'order_by' => array( 'DTT_order' => 'DESC' )
391
+					'order_by' => array('DTT_order' => 'DESC')
392 392
 				)
393 393
 			);
394
-			return end( $datetimes );
394
+			return end($datetimes);
395 395
 		} else {
396 396
 			return FALSE;
397 397
 		}
@@ -406,17 +406,17 @@  discard block
 block discarded – undo
406 406
 	 * @param int $EVT_ID
407 407
 	 * @return    string
408 408
 	 */
409
-	public static function get_earliest_date_obj( $EVT_ID = 0 ) {
410
-		$event = EEH_Event_View::get_event( $EVT_ID );
411
-		if ( $event instanceof EE_Event ) {
409
+	public static function get_earliest_date_obj($EVT_ID = 0) {
410
+		$event = EEH_Event_View::get_event($EVT_ID);
411
+		if ($event instanceof EE_Event) {
412 412
 			$datetimes = $event->get_many_related(
413 413
 				'Datetime',
414 414
 				array(
415 415
 					'limit' => 1,
416
-					'order_by' => array( 'DTT_EVT_start' => 'ASC' )
416
+					'order_by' => array('DTT_EVT_start' => 'ASC')
417 417
 				)
418 418
 			);
419
-			return reset( $datetimes );
419
+			return reset($datetimes);
420 420
 		} else {
421 421
 			 return FALSE;
422 422
 		}
@@ -431,17 +431,17 @@  discard block
 block discarded – undo
431 431
 	 * @param int $EVT_ID
432 432
 	 * @return    string
433 433
 	 */
434
-	public static function get_latest_date_obj( $EVT_ID = 0 ) {
435
-		$event = EEH_Event_View::get_event( $EVT_ID );
436
-		if ( $event instanceof EE_Event ) {
434
+	public static function get_latest_date_obj($EVT_ID = 0) {
435
+		$event = EEH_Event_View::get_event($EVT_ID);
436
+		if ($event instanceof EE_Event) {
437 437
 			$datetimes = $event->get_many_related(
438 438
 				'Datetime',
439 439
 				array(
440 440
 					'limit' => 1,
441
-					'order_by' => array( 'DTT_EVT_start' => 'DESC' )
441
+					'order_by' => array('DTT_EVT_start' => 'DESC')
442 442
 				)
443 443
 			);
444
-			return end( $datetimes );
444
+			return end($datetimes);
445 445
 		} else {
446 446
 			return FALSE;
447 447
 		}
@@ -459,17 +459,17 @@  discard block
 block discarded – undo
459 459
 	 * @param null $limit
460 460
 	 * @return EE_Datetime[]
461 461
 	 */
462
-	public static function get_all_date_obj( $EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL ) {
463
-		$event = EEH_Event_View::get_event( $EVT_ID );
464
-		if($include_expired === null){
465
-			if($event instanceof EE_Event && $event->is_expired()){
462
+	public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL) {
463
+		$event = EEH_Event_View::get_event($EVT_ID);
464
+		if ($include_expired === null) {
465
+			if ($event instanceof EE_Event && $event->is_expired()) {
466 466
 				$include_expired = true;
467
-			}else{
467
+			} else {
468 468
 				$include_expired = false;
469 469
 			}
470 470
 		}
471 471
 
472
-		if ( $event instanceof EE_Event ) {
472
+		if ($event instanceof EE_Event) {
473 473
 			return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
474 474
 		} else {
475 475
 			 return array();
@@ -485,11 +485,11 @@  discard block
 block discarded – undo
485 485
 	 * @param int $EVT_ID
486 486
 	 * @return    string
487 487
 	 */
488
-	public static function event_link_url( $EVT_ID = 0 ) {
489
-		$event = EEH_Event_View::get_event( $EVT_ID );
490
-		if ( $event instanceof EE_Event ) {
491
-			$url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink( $event->ID() );
492
-			return preg_match( "~^(?:f|ht)tps?://~i", $url ) ? $url : 'http://' . $url;
488
+	public static function event_link_url($EVT_ID = 0) {
489
+		$event = EEH_Event_View::get_event($EVT_ID);
490
+		if ($event instanceof EE_Event) {
491
+			$url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID());
492
+			return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://'.$url;
493 493
 		}
494 494
 		return NULL;
495 495
 	}
@@ -503,10 +503,10 @@  discard block
 block discarded – undo
503 503
 	 * @param int $EVT_ID
504 504
 	 * @return    string
505 505
 	 */
506
-	public static function event_phone( $EVT_ID = 0 ) {
507
-		$event = EEH_Event_View::get_event( $EVT_ID );
508
-		if ( $event instanceof EE_Event ) {
509
-			return EEH_Schema::telephone( $event->phone() );
506
+	public static function event_phone($EVT_ID = 0) {
507
+		$event = EEH_Event_View::get_event($EVT_ID);
508
+		if ($event instanceof EE_Event) {
509
+			return EEH_Schema::telephone($event->phone());
510 510
 		}
511 511
 		return NULL;
512 512
 	}
@@ -523,26 +523,26 @@  discard block
 block discarded – undo
523 523
 	 * @param string $after
524 524
 	 * @return    string
525 525
 	 */
526
-	public static function edit_event_link( $EVT_ID = 0, $link = '', $before = '', $after = '' ) {
527
-		$event = EEH_Event_View::get_event( $EVT_ID );
528
-		if ( $event instanceof EE_Event ) {
526
+	public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') {
527
+		$event = EEH_Event_View::get_event($EVT_ID);
528
+		if ($event instanceof EE_Event) {
529 529
 			// can the user edit this post ?
530
-			if ( current_user_can( 'edit_post', $event->ID() )) {
530
+			if (current_user_can('edit_post', $event->ID())) {
531 531
 				// set link text
532
-				$link_text = ! empty( $link ) ? $link : __('edit this event');
532
+				$link_text = ! empty($link) ? $link : __('edit this event');
533 533
 				// generate nonce
534
-				$nonce = wp_create_nonce( 'edit_nonce' );
534
+				$nonce = wp_create_nonce('edit_nonce');
535 535
 				// generate url to event editor for this event
536
-				$url = add_query_arg( array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url() );
536
+				$url = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce), admin_url());
537 537
 				// get edit CPT text
538
-				$post_type_obj = get_post_type_object( 'espresso_events' );
538
+				$post_type_obj = get_post_type_object('espresso_events');
539 539
 				// build final link html
540
-				$link = '<a class="post-edit-link" href="' . $url . '" ';
541
-				$link .= ' title="' . esc_attr( $post_type_obj->labels->edit_item ) . '"';
540
+				$link = '<a class="post-edit-link" href="'.$url.'" ';
541
+				$link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"';
542 542
 				$link .= \EED_Events_Archive::link_target();
543
-				$link .='>' . $link_text . '</a>';
543
+				$link .= '>'.$link_text.'</a>';
544 544
 				// put it all together
545
-				return $before . apply_filters( 'edit_post_link', $link, $event->ID() ) . $after;
545
+				return $before.apply_filters('edit_post_link', $link, $event->ID()).$after;
546 546
 			}
547 547
 		}
548 548
 		return '';
Please login to merge, or discard this patch.
core/services/shortcodes/LegacyShortcodesManager.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -117,44 +117,44 @@  discard block
 block discarded – undo
117 117
             // remove last segment
118 118
             array_pop($shortcode_path);
119 119
             // glue it back together
120
-            $shortcode_path = implode(DS, $shortcode_path) . DS;
120
+            $shortcode_path = implode(DS, $shortcode_path).DS;
121 121
         } else {
122 122
             // we need to generate the filename based off of the folder name
123 123
             // grab and sanitize shortcode directory name
124 124
             $shortcode = sanitize_key(basename($shortcode_path));
125
-            $shortcode_path = rtrim($shortcode_path, DS) . DS;
125
+            $shortcode_path = rtrim($shortcode_path, DS).DS;
126 126
         }
127 127
         // create classname from shortcode directory or file name
128 128
         $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
129 129
         // add class prefix
130
-        $shortcode_class = 'EES_' . $shortcode;
130
+        $shortcode_class = 'EES_'.$shortcode;
131 131
         // does the shortcode exist ?
132
-        if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
132
+        if ( ! is_readable($shortcode_path.DS.$shortcode_class.$shortcode_ext)) {
133 133
             $msg = sprintf(
134 134
                 esc_html__(
135 135
                     'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
136 136
                     'event_espresso'
137 137
                 ),
138 138
                 $shortcode_class,
139
-                $shortcode_path . DS . $shortcode_class . $shortcode_ext
139
+                $shortcode_path.DS.$shortcode_class.$shortcode_ext
140 140
             );
141
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
141
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
142 142
             return false;
143 143
         }
144 144
         // load the shortcode class file
145
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
145
+        require_once($shortcode_path.$shortcode_class.$shortcode_ext);
146 146
         // verify that class exists
147 147
         if ( ! class_exists($shortcode_class)) {
148 148
             $msg = sprintf(
149 149
                 esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
150 150
                 $shortcode_class
151 151
             );
152
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
152
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
153 153
             return false;
154 154
         }
155 155
         $shortcode = strtoupper($shortcode);
156 156
         // add to array of registered shortcodes
157
-        $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
157
+        $this->registry->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext;
158 158
         return true;
159 159
     }
160 160
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
         // cycle thru shortcode folders
173 173
         foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
174 174
             // add class prefix
175
-            $shortcode_class = 'EES_' . $shortcode;
175
+            $shortcode_class = 'EES_'.$shortcode;
176 176
             // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
177 177
             // which set hooks ?
178 178
             if (is_admin()) {
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
     {
291 291
         $has_shortcode = false;
292 292
         foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
293
-            if ($load_all || has_shortcode($content, $shortcode_class) ) {
293
+            if ($load_all || has_shortcode($content, $shortcode_class)) {
294 294
                 // load up the shortcode
295 295
                 $this->initializeShortcode($shortcode_class);
296 296
                 $has_shortcode = true;
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
      */
403 403
     public static function addShortcodeClassPrefix($class_name)
404 404
     {
405
-        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
405
+        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_'.$class_name;
406 406
     }
407 407
 
408 408
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
     {
415 415
         static $shortcode_tags = array();
416 416
         if (empty($shortcode_tags)) {
417
-            $shortcode_tags = array_keys((array)$this->registry->shortcodes);
417
+            $shortcode_tags = array_keys((array) $this->registry->shortcodes);
418 418
         }
419 419
         return $shortcode_tags;
420 420
     }
Please login to merge, or discard this patch.
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -25,429 +25,429 @@
 block discarded – undo
25 25
 class LegacyShortcodesManager
26 26
 {
27 27
 
28
-    /**
29
-     * @var EE_Registry $registry
30
-     */
31
-    private $registry;
32
-
33
-
34
-
35
-
36
-    /**
37
-     * LegacyShortcodesManager constructor.
38
-     *
39
-     * @param \EE_Registry $registry
40
-     */
41
-    public function __construct(EE_Registry $registry)
42
-    {
43
-        $this->registry = $registry;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * @return EE_Registry
50
-     */
51
-    public function registry()
52
-    {
53
-        return $this->registry;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * registerShortcodes
60
-     *
61
-     * @return void
62
-     */
63
-    public function registerShortcodes()
64
-    {
65
-        $this->registry->shortcodes = $this->getShortcodes();
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * getShortcodes
72
-     *
73
-     * @return array
74
-     */
75
-    public function getShortcodes()
76
-    {
77
-        // previously this method would glob the shortcodes directory
78
-        // then filter that list of shortcodes to register,
79
-        // but now we are going to just supply an empty array.
80
-        // this allows any shortcodes that have not yet been converted to the new system
81
-        // to still get loaded and processed, albeit using the same legacy logic as before
82
-        $shortcodes_to_register = apply_filters(
83
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
84
-            array()
85
-        );
86
-        if ( ! empty($shortcodes_to_register)) {
87
-            // cycle thru shortcode folders
88
-            foreach ($shortcodes_to_register as $shortcode_path) {
89
-                // add to list of installed shortcode modules
90
-                $this->registerShortcode($shortcode_path);
91
-            }
92
-        }
93
-        // filter list of installed modules
94
-        return apply_filters(
95
-            'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
96
-            ! empty($this->registry->shortcodes)
97
-                ? $this->registry->shortcodes
98
-                : array()
99
-        );
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     *    register_shortcode - makes core aware of this shortcode
106
-     *
107
-     * @access    public
108
-     * @param    string $shortcode_path - full path up to and including shortcode folder
109
-     * @return    bool
110
-     */
111
-    public function registerShortcode($shortcode_path = null)
112
-    {
113
-        do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
114
-        $shortcode_ext = '.shortcode.php';
115
-        // make all separators match
116
-        $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
117
-        // does the file path INCLUDE the actual file name as part of the path ?
118
-        if (strpos($shortcode_path, $shortcode_ext) !== false) {
119
-            // grab shortcode file name from directory name and break apart at dots
120
-            $shortcode_file = explode('.', basename($shortcode_path));
121
-            // take first segment from file name pieces and remove class prefix if it exists
122
-            $shortcode = strpos($shortcode_file[0], 'EES_') === 0
123
-                ? substr($shortcode_file[0], 4)
124
-                : $shortcode_file[0];
125
-            // sanitize shortcode directory name
126
-            $shortcode = sanitize_key($shortcode);
127
-            // now we need to rebuild the shortcode path
128
-            $shortcode_path = explode(DS, $shortcode_path);
129
-            // remove last segment
130
-            array_pop($shortcode_path);
131
-            // glue it back together
132
-            $shortcode_path = implode(DS, $shortcode_path) . DS;
133
-        } else {
134
-            // we need to generate the filename based off of the folder name
135
-            // grab and sanitize shortcode directory name
136
-            $shortcode = sanitize_key(basename($shortcode_path));
137
-            $shortcode_path = rtrim($shortcode_path, DS) . DS;
138
-        }
139
-        // create classname from shortcode directory or file name
140
-        $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
141
-        // add class prefix
142
-        $shortcode_class = 'EES_' . $shortcode;
143
-        // does the shortcode exist ?
144
-        if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
145
-            $msg = sprintf(
146
-                esc_html__(
147
-                    'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
148
-                    'event_espresso'
149
-                ),
150
-                $shortcode_class,
151
-                $shortcode_path . DS . $shortcode_class . $shortcode_ext
152
-            );
153
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
-            return false;
155
-        }
156
-        // load the shortcode class file
157
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
158
-        // verify that class exists
159
-        if ( ! class_exists($shortcode_class)) {
160
-            $msg = sprintf(
161
-                esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
162
-                $shortcode_class
163
-            );
164
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
-            return false;
166
-        }
167
-        $shortcode = strtoupper($shortcode);
168
-        // add to array of registered shortcodes
169
-        $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
170
-        return true;
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     *    _initialize_shortcodes
177
-     *    allow shortcodes to set hooks for the rest of the system
178
-     *
179
-     * @access private
180
-     * @return void
181
-     */
182
-    public function addShortcodes()
183
-    {
184
-        // cycle thru shortcode folders
185
-        foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
186
-            // add class prefix
187
-            $shortcode_class = 'EES_' . $shortcode;
188
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
189
-            // which set hooks ?
190
-            if (is_admin()) {
191
-                // fire immediately
192
-                call_user_func(array($shortcode_class, 'set_hooks_admin'));
193
-            } else {
194
-                // delay until other systems are online
195
-                add_action(
196
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
197
-                    array($shortcode_class, 'set_hooks')
198
-                );
199
-                // convert classname to UPPERCASE and create WP shortcode.
200
-                $shortcode_tag = strtoupper($shortcode);
201
-                // but first check if the shortcode has already
202
-                // been added before assigning 'fallback_shortcode_processor'
203
-                if ( ! shortcode_exists($shortcode_tag)) {
204
-                    // NOTE: this shortcode declaration will get overridden if the shortcode
205
-                    // is successfully detected in the post content in initializeShortcode()
206
-                    add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
207
-                }
208
-            }
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * callback for the WP "get_header" hook point
216
-     * checks posts for EE shortcodes, and initializes them,
217
-     * then toggles filter switch that loads core default assets
218
-     *
219
-     * @param \WP_Query $wp_query
220
-     * @return void
221
-     */
222
-    public function initializeShortcodes(WP_Query $wp_query)
223
-    {
224
-        if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) {
225
-            return;
226
-        }
227
-        global $wp;
228
-        /** @var EE_Front_controller $Front_Controller */
229
-        $Front_Controller = $this->registry->load_core('Front_Controller', array(), false);
230
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller);
231
-        $Front_Controller->Request_Handler()->set_request_vars();
232
-        // grab post_name from request
233
-        $current_post = apply_filters(
234
-            'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
235
-            $Front_Controller->Request_Handler()->get('post_name')
236
-        );
237
-        $show_on_front = get_option('show_on_front');
238
-        // if it's not set, then check if frontpage is blog
239
-        if (empty($current_post)) {
240
-            // yup.. this is the posts page, prepare to load all shortcode modules
241
-            $current_post = 'posts';
242
-            // unless..
243
-            if ($show_on_front === 'page') {
244
-                // some other page is set as the homepage
245
-                $page_on_front = get_option('page_on_front');
246
-                if ($page_on_front) {
247
-                    // k now we need to find the post_name for this page
248
-                    global $wpdb;
249
-                    $page_on_front = $wpdb->get_var(
250
-                        $wpdb->prepare(
251
-                            "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status='publish' AND ID=%d",
252
-                            $page_on_front
253
-                        )
254
-                    );
255
-                    // set the current post slug to what it actually is
256
-                    $current_post = $page_on_front ? $page_on_front : $current_post;
257
-                }
258
-            }
259
-        }
260
-        // in case $current_post is hierarchical like: /parent-page/current-page
261
-        $current_post = basename($current_post);
262
-        if (
263
-            // is current page/post the "blog" page ?
264
-            $current_post === EE_Config::get_page_for_posts()
265
-            // or are we on a category page?
266
-            || (
267
-                is_array(term_exists($current_post, 'category'))
268
-                || array_key_exists('category_name', $wp->query_vars)
269
-            )
270
-        ) {
271
-            // initialize all legacy shortcodes
272
-            $load_assets = $this->parseContentForShortcodes('', true);
273
-        } else {
274
-            global $wpdb;
275
-            $post_content = $wpdb->get_var(
276
-                $wpdb->prepare(
277
-                    "SELECT post_content from {$wpdb->posts} WHERE post_status='publish' AND post_name=%s",
278
-                    $current_post
279
-                )
280
-            );
281
-            $load_assets = $this->parseContentForShortcodes($post_content);
282
-        }
283
-        if ($load_assets) {
284
-            $this->registry->REQ->set_espresso_page(true);
285
-            add_filter('FHEE_load_css', '__return_true');
286
-            add_filter('FHEE_load_js', '__return_true');
287
-        }
288
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller);
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * checks supplied content against list of legacy shortcodes,
295
-     * then initializes any found shortcodes, and returns true.
296
-     * returns false if no shortcodes found.
297
-     *
298
-     * @param string $content
299
-     * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
300
-     * @return bool
301
-     */
302
-    public function parseContentForShortcodes($content = '', $load_all = false)
303
-    {
304
-        $has_shortcode = false;
305
-        foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
306
-            if ($load_all || has_shortcode($content, $shortcode_class) ) {
307
-                // load up the shortcode
308
-                $this->initializeShortcode($shortcode_class);
309
-                $has_shortcode = true;
310
-            }
311
-        }
312
-        return $has_shortcode;
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     * given a shortcode name, will instantiate the shortcode and call it's run() method
319
-     *
320
-     * @param string $shortcode_class
321
-     * @param WP     $wp
322
-     */
323
-    public function initializeShortcode($shortcode_class = '', WP $wp = null)
324
-    {
325
-        // don't do anything if shortcode is already initialized
326
-        if (
327
-            empty($this->registry->shortcodes->{$shortcode_class})
328
-            || ! is_string($this->registry->shortcodes->{$shortcode_class})
329
-        ) {
330
-            return;
331
-        }
332
-        // let's pause to reflect on this...
333
-        $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
334
-        // ensure that class is actually a shortcode
335
-        if (
336
-            defined('WP_DEBUG')
337
-            && WP_DEBUG === true
338
-            && ! $sc_reflector->isSubclassOf('EES_Shortcode')
339
-        ) {
340
-            EE_Error::add_error(
341
-                sprintf(
342
-                    esc_html__(
343
-                        'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
344
-                        'event_espresso'
345
-                    ),
346
-                    $shortcode_class
347
-                ),
348
-                __FILE__,
349
-                __FUNCTION__,
350
-                __LINE__
351
-            );
352
-            add_filter('FHEE_run_EE_the_content', '__return_true');
353
-            return;
354
-        }
355
-        global $wp;
356
-        // and pass the request object to the run method
357
-        $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
358
-        // fire the shortcode class's run method, so that it can activate resources
359
-        $this->registry->shortcodes->{$shortcode_class}->run($wp);
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * get classname, remove EES_prefix, and convert to UPPERCASE
366
-     *
367
-     * @param string $class_name
368
-     * @return string
369
-     */
370
-    public static function generateShortcodeTagFromClassName($class_name)
371
-    {
372
-        return strtoupper(str_replace('EES_', '', $class_name));
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * add EES_prefix and Capitalize words
379
-     *
380
-     * @param string $tag
381
-     * @return string
382
-     */
383
-    public static function generateShortcodeClassNameFromTag($tag)
384
-    {
385
-        // order of operation runs from inside to out
386
-        // 5) maybe add prefix
387
-        return LegacyShortcodesManager::addShortcodeClassPrefix(
388
-        // 4) find spaces, replace with underscores
389
-            str_replace(
390
-                ' ',
391
-                '_',
392
-                // 3) capitalize first letter of each word
393
-                ucwords(
394
-                // 2) also change to lowercase so ucwords() will work
395
-                    strtolower(
396
-                    // 1) find underscores, replace with spaces so ucwords() will work
397
-                        str_replace(
398
-                            '_',
399
-                            ' ',
400
-                            $tag
401
-                        )
402
-                    )
403
-                )
404
-            )
405
-        );
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * maybe add EES_prefix
412
-     *
413
-     * @param string $class_name
414
-     * @return string
415
-     */
416
-    public static function addShortcodeClassPrefix($class_name)
417
-    {
418
-        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * @return array
425
-     */
426
-    public function getEspressoShortcodeTags()
427
-    {
428
-        static $shortcode_tags = array();
429
-        if (empty($shortcode_tags)) {
430
-            $shortcode_tags = array_keys((array)$this->registry->shortcodes);
431
-        }
432
-        return $shortcode_tags;
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * @param string $content
439
-     * @return string
440
-     */
441
-    public function doShortcode($content)
442
-    {
443
-        foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
444
-            if (strpos($content, $shortcode_tag) !== false) {
445
-                $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
446
-                $this->initializeShortcode($shortcode_class);
447
-            }
448
-        }
449
-        return do_shortcode($content);
450
-    }
28
+	/**
29
+	 * @var EE_Registry $registry
30
+	 */
31
+	private $registry;
32
+
33
+
34
+
35
+
36
+	/**
37
+	 * LegacyShortcodesManager constructor.
38
+	 *
39
+	 * @param \EE_Registry $registry
40
+	 */
41
+	public function __construct(EE_Registry $registry)
42
+	{
43
+		$this->registry = $registry;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * @return EE_Registry
50
+	 */
51
+	public function registry()
52
+	{
53
+		return $this->registry;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * registerShortcodes
60
+	 *
61
+	 * @return void
62
+	 */
63
+	public function registerShortcodes()
64
+	{
65
+		$this->registry->shortcodes = $this->getShortcodes();
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * getShortcodes
72
+	 *
73
+	 * @return array
74
+	 */
75
+	public function getShortcodes()
76
+	{
77
+		// previously this method would glob the shortcodes directory
78
+		// then filter that list of shortcodes to register,
79
+		// but now we are going to just supply an empty array.
80
+		// this allows any shortcodes that have not yet been converted to the new system
81
+		// to still get loaded and processed, albeit using the same legacy logic as before
82
+		$shortcodes_to_register = apply_filters(
83
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
84
+			array()
85
+		);
86
+		if ( ! empty($shortcodes_to_register)) {
87
+			// cycle thru shortcode folders
88
+			foreach ($shortcodes_to_register as $shortcode_path) {
89
+				// add to list of installed shortcode modules
90
+				$this->registerShortcode($shortcode_path);
91
+			}
92
+		}
93
+		// filter list of installed modules
94
+		return apply_filters(
95
+			'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
96
+			! empty($this->registry->shortcodes)
97
+				? $this->registry->shortcodes
98
+				: array()
99
+		);
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 *    register_shortcode - makes core aware of this shortcode
106
+	 *
107
+	 * @access    public
108
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
109
+	 * @return    bool
110
+	 */
111
+	public function registerShortcode($shortcode_path = null)
112
+	{
113
+		do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
114
+		$shortcode_ext = '.shortcode.php';
115
+		// make all separators match
116
+		$shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
117
+		// does the file path INCLUDE the actual file name as part of the path ?
118
+		if (strpos($shortcode_path, $shortcode_ext) !== false) {
119
+			// grab shortcode file name from directory name and break apart at dots
120
+			$shortcode_file = explode('.', basename($shortcode_path));
121
+			// take first segment from file name pieces and remove class prefix if it exists
122
+			$shortcode = strpos($shortcode_file[0], 'EES_') === 0
123
+				? substr($shortcode_file[0], 4)
124
+				: $shortcode_file[0];
125
+			// sanitize shortcode directory name
126
+			$shortcode = sanitize_key($shortcode);
127
+			// now we need to rebuild the shortcode path
128
+			$shortcode_path = explode(DS, $shortcode_path);
129
+			// remove last segment
130
+			array_pop($shortcode_path);
131
+			// glue it back together
132
+			$shortcode_path = implode(DS, $shortcode_path) . DS;
133
+		} else {
134
+			// we need to generate the filename based off of the folder name
135
+			// grab and sanitize shortcode directory name
136
+			$shortcode = sanitize_key(basename($shortcode_path));
137
+			$shortcode_path = rtrim($shortcode_path, DS) . DS;
138
+		}
139
+		// create classname from shortcode directory or file name
140
+		$shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
141
+		// add class prefix
142
+		$shortcode_class = 'EES_' . $shortcode;
143
+		// does the shortcode exist ?
144
+		if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
145
+			$msg = sprintf(
146
+				esc_html__(
147
+					'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
148
+					'event_espresso'
149
+				),
150
+				$shortcode_class,
151
+				$shortcode_path . DS . $shortcode_class . $shortcode_ext
152
+			);
153
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
+			return false;
155
+		}
156
+		// load the shortcode class file
157
+		require_once($shortcode_path . $shortcode_class . $shortcode_ext);
158
+		// verify that class exists
159
+		if ( ! class_exists($shortcode_class)) {
160
+			$msg = sprintf(
161
+				esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
162
+				$shortcode_class
163
+			);
164
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
+			return false;
166
+		}
167
+		$shortcode = strtoupper($shortcode);
168
+		// add to array of registered shortcodes
169
+		$this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
170
+		return true;
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 *    _initialize_shortcodes
177
+	 *    allow shortcodes to set hooks for the rest of the system
178
+	 *
179
+	 * @access private
180
+	 * @return void
181
+	 */
182
+	public function addShortcodes()
183
+	{
184
+		// cycle thru shortcode folders
185
+		foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
186
+			// add class prefix
187
+			$shortcode_class = 'EES_' . $shortcode;
188
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
189
+			// which set hooks ?
190
+			if (is_admin()) {
191
+				// fire immediately
192
+				call_user_func(array($shortcode_class, 'set_hooks_admin'));
193
+			} else {
194
+				// delay until other systems are online
195
+				add_action(
196
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
197
+					array($shortcode_class, 'set_hooks')
198
+				);
199
+				// convert classname to UPPERCASE and create WP shortcode.
200
+				$shortcode_tag = strtoupper($shortcode);
201
+				// but first check if the shortcode has already
202
+				// been added before assigning 'fallback_shortcode_processor'
203
+				if ( ! shortcode_exists($shortcode_tag)) {
204
+					// NOTE: this shortcode declaration will get overridden if the shortcode
205
+					// is successfully detected in the post content in initializeShortcode()
206
+					add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
207
+				}
208
+			}
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * callback for the WP "get_header" hook point
216
+	 * checks posts for EE shortcodes, and initializes them,
217
+	 * then toggles filter switch that loads core default assets
218
+	 *
219
+	 * @param \WP_Query $wp_query
220
+	 * @return void
221
+	 */
222
+	public function initializeShortcodes(WP_Query $wp_query)
223
+	{
224
+		if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) {
225
+			return;
226
+		}
227
+		global $wp;
228
+		/** @var EE_Front_controller $Front_Controller */
229
+		$Front_Controller = $this->registry->load_core('Front_Controller', array(), false);
230
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller);
231
+		$Front_Controller->Request_Handler()->set_request_vars();
232
+		// grab post_name from request
233
+		$current_post = apply_filters(
234
+			'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
235
+			$Front_Controller->Request_Handler()->get('post_name')
236
+		);
237
+		$show_on_front = get_option('show_on_front');
238
+		// if it's not set, then check if frontpage is blog
239
+		if (empty($current_post)) {
240
+			// yup.. this is the posts page, prepare to load all shortcode modules
241
+			$current_post = 'posts';
242
+			// unless..
243
+			if ($show_on_front === 'page') {
244
+				// some other page is set as the homepage
245
+				$page_on_front = get_option('page_on_front');
246
+				if ($page_on_front) {
247
+					// k now we need to find the post_name for this page
248
+					global $wpdb;
249
+					$page_on_front = $wpdb->get_var(
250
+						$wpdb->prepare(
251
+							"SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status='publish' AND ID=%d",
252
+							$page_on_front
253
+						)
254
+					);
255
+					// set the current post slug to what it actually is
256
+					$current_post = $page_on_front ? $page_on_front : $current_post;
257
+				}
258
+			}
259
+		}
260
+		// in case $current_post is hierarchical like: /parent-page/current-page
261
+		$current_post = basename($current_post);
262
+		if (
263
+			// is current page/post the "blog" page ?
264
+			$current_post === EE_Config::get_page_for_posts()
265
+			// or are we on a category page?
266
+			|| (
267
+				is_array(term_exists($current_post, 'category'))
268
+				|| array_key_exists('category_name', $wp->query_vars)
269
+			)
270
+		) {
271
+			// initialize all legacy shortcodes
272
+			$load_assets = $this->parseContentForShortcodes('', true);
273
+		} else {
274
+			global $wpdb;
275
+			$post_content = $wpdb->get_var(
276
+				$wpdb->prepare(
277
+					"SELECT post_content from {$wpdb->posts} WHERE post_status='publish' AND post_name=%s",
278
+					$current_post
279
+				)
280
+			);
281
+			$load_assets = $this->parseContentForShortcodes($post_content);
282
+		}
283
+		if ($load_assets) {
284
+			$this->registry->REQ->set_espresso_page(true);
285
+			add_filter('FHEE_load_css', '__return_true');
286
+			add_filter('FHEE_load_js', '__return_true');
287
+		}
288
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller);
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * checks supplied content against list of legacy shortcodes,
295
+	 * then initializes any found shortcodes, and returns true.
296
+	 * returns false if no shortcodes found.
297
+	 *
298
+	 * @param string $content
299
+	 * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
300
+	 * @return bool
301
+	 */
302
+	public function parseContentForShortcodes($content = '', $load_all = false)
303
+	{
304
+		$has_shortcode = false;
305
+		foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
306
+			if ($load_all || has_shortcode($content, $shortcode_class) ) {
307
+				// load up the shortcode
308
+				$this->initializeShortcode($shortcode_class);
309
+				$has_shortcode = true;
310
+			}
311
+		}
312
+		return $has_shortcode;
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 * given a shortcode name, will instantiate the shortcode and call it's run() method
319
+	 *
320
+	 * @param string $shortcode_class
321
+	 * @param WP     $wp
322
+	 */
323
+	public function initializeShortcode($shortcode_class = '', WP $wp = null)
324
+	{
325
+		// don't do anything if shortcode is already initialized
326
+		if (
327
+			empty($this->registry->shortcodes->{$shortcode_class})
328
+			|| ! is_string($this->registry->shortcodes->{$shortcode_class})
329
+		) {
330
+			return;
331
+		}
332
+		// let's pause to reflect on this...
333
+		$sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
334
+		// ensure that class is actually a shortcode
335
+		if (
336
+			defined('WP_DEBUG')
337
+			&& WP_DEBUG === true
338
+			&& ! $sc_reflector->isSubclassOf('EES_Shortcode')
339
+		) {
340
+			EE_Error::add_error(
341
+				sprintf(
342
+					esc_html__(
343
+						'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
344
+						'event_espresso'
345
+					),
346
+					$shortcode_class
347
+				),
348
+				__FILE__,
349
+				__FUNCTION__,
350
+				__LINE__
351
+			);
352
+			add_filter('FHEE_run_EE_the_content', '__return_true');
353
+			return;
354
+		}
355
+		global $wp;
356
+		// and pass the request object to the run method
357
+		$this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
358
+		// fire the shortcode class's run method, so that it can activate resources
359
+		$this->registry->shortcodes->{$shortcode_class}->run($wp);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * get classname, remove EES_prefix, and convert to UPPERCASE
366
+	 *
367
+	 * @param string $class_name
368
+	 * @return string
369
+	 */
370
+	public static function generateShortcodeTagFromClassName($class_name)
371
+	{
372
+		return strtoupper(str_replace('EES_', '', $class_name));
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * add EES_prefix and Capitalize words
379
+	 *
380
+	 * @param string $tag
381
+	 * @return string
382
+	 */
383
+	public static function generateShortcodeClassNameFromTag($tag)
384
+	{
385
+		// order of operation runs from inside to out
386
+		// 5) maybe add prefix
387
+		return LegacyShortcodesManager::addShortcodeClassPrefix(
388
+		// 4) find spaces, replace with underscores
389
+			str_replace(
390
+				' ',
391
+				'_',
392
+				// 3) capitalize first letter of each word
393
+				ucwords(
394
+				// 2) also change to lowercase so ucwords() will work
395
+					strtolower(
396
+					// 1) find underscores, replace with spaces so ucwords() will work
397
+						str_replace(
398
+							'_',
399
+							' ',
400
+							$tag
401
+						)
402
+					)
403
+				)
404
+			)
405
+		);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * maybe add EES_prefix
412
+	 *
413
+	 * @param string $class_name
414
+	 * @return string
415
+	 */
416
+	public static function addShortcodeClassPrefix($class_name)
417
+	{
418
+		return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * @return array
425
+	 */
426
+	public function getEspressoShortcodeTags()
427
+	{
428
+		static $shortcode_tags = array();
429
+		if (empty($shortcode_tags)) {
430
+			$shortcode_tags = array_keys((array)$this->registry->shortcodes);
431
+		}
432
+		return $shortcode_tags;
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * @param string $content
439
+	 * @return string
440
+	 */
441
+	public function doShortcode($content)
442
+	{
443
+		foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
444
+			if (strpos($content, $shortcode_tag) !== false) {
445
+				$shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
446
+				$this->initializeShortcode($shortcode_class);
447
+			}
448
+		}
449
+		return do_shortcode($content);
450
+	}
451 451
 
452 452
 
453 453
 
Please login to merge, or discard this patch.
core/services/shortcodes/ShortcodeInterface.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -8,39 +8,39 @@
 block discarded – undo
8 8
 interface ShortcodeInterface
9 9
 {
10 10
 
11
-    /**
12
-     * the actual shortcode tag that gets registered with WordPress
13
-     *
14
-     * @return string
15
-     */
16
-    public function getTag();
17
-
18
-    /**
19
-     * the length of time in seconds to cache the results of the processShortcode() method
20
-     * 0 means the processShortcode() results will NOT be cached at all
21
-     *
22
-     * @return int
23
-     */
24
-    public function cacheExpiration();
25
-
26
-    /**
27
-     * a place for adding any initialization code that needs to run prior to wp_header().
28
-     * this may be required for shortcodes that utilize a corresponding module,
29
-     * and need to enqueue assets for that module
30
-     *
31
-     * @return void
32
-     */
33
-    public function initializeShortcode();
34
-
35
-    /**
36
-     * callback that runs when the shortcode is encountered in post content.
37
-     * IMPORTANT !!!
38
-     * remember that shortcode content should be RETURNED and NOT echoed out
39
-     *
40
-     * @param array $attributes
41
-     * @return string
42
-     */
43
-    public function processShortcode($attributes = array());
11
+	/**
12
+	 * the actual shortcode tag that gets registered with WordPress
13
+	 *
14
+	 * @return string
15
+	 */
16
+	public function getTag();
17
+
18
+	/**
19
+	 * the length of time in seconds to cache the results of the processShortcode() method
20
+	 * 0 means the processShortcode() results will NOT be cached at all
21
+	 *
22
+	 * @return int
23
+	 */
24
+	public function cacheExpiration();
25
+
26
+	/**
27
+	 * a place for adding any initialization code that needs to run prior to wp_header().
28
+	 * this may be required for shortcodes that utilize a corresponding module,
29
+	 * and need to enqueue assets for that module
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function initializeShortcode();
34
+
35
+	/**
36
+	 * callback that runs when the shortcode is encountered in post content.
37
+	 * IMPORTANT !!!
38
+	 * remember that shortcode content should be RETURNED and NOT echoed out
39
+	 *
40
+	 * @param array $attributes
41
+	 * @return string
42
+	 */
43
+	public function processShortcode($attributes = array());
44 44
 
45 45
 }
46 46
 // End of file ShortcodeInterface.php
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoTxnPage.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -27,91 +27,91 @@
 block discarded – undo
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * the actual shortcode tag that gets registered with WordPress
32
-     *
33
-     * @return string
34
-     */
35
-    public function getTag()
36
-    {
37
-        return 'ESPRESSO_TXN_PAGE';
38
-    }
39
-
40
-
41
-
42
-    /**
43
-     * the time in seconds to cache the results of the processShortcode() method
44
-     * 0 means the processShortcode() results will NOT be cached at all
45
-     *
46
-     * @return int
47
-     */
48
-    public function cacheExpiration()
49
-    {
50
-        return 0;
51
-    }
52
-
53
-
54
-    /**
55
-     * a place for adding any initialization code that needs to run prior to wp_header().
56
-     * this may be required for shortcodes that utilize a corresponding module,
57
-     * and need to enqueue assets for that module
58
-     *
59
-     * @return void
60
-     * @throws \Exception
61
-     * @throws \EE_Error
62
-     */
63
-    public function initializeShortcode()
64
-    {
65
-        $transaction = null;
66
-        if (EE_Registry::instance()->REQ->is_set('e_reg_url_link')) {
67
-            /** @var EEM_Transaction $EEM_Transaction */
68
-            $EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
69
-            $transaction = $EEM_Transaction->get_transaction_from_reg_url_link();
70
-        }
71
-        if ($transaction instanceof EE_Transaction) {
72
-            $payment_method = null;
73
-            $payment_method_slug = EE_Registry::instance()->REQ->get('ee_payment_method', null);
74
-            if ($payment_method_slug) {
75
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($payment_method_slug);
76
-            }
77
-            if ($payment_method instanceof EE_Payment_Method && $payment_method->is_off_site()) {
78
-                $gateway = $payment_method->type_obj()->get_gateway();
79
-                if (
80
-                    $gateway instanceof EE_Offsite_Gateway
81
-                    && $gateway->handle_IPN_in_this_request(
82
-                        \EE_Registry::instance()->REQ->params(),
83
-                        true
84
-                    )
85
-                ) {
86
-                    /** @type EE_Payment_Processor $payment_processor */
87
-                    $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
88
-                    $payment_processor->process_ipn($_REQUEST, $transaction, $payment_method);
89
-                }
90
-            }
91
-            //allow gateways to add a filter to stop rendering the page
92
-            if (apply_filters('FHEE__EES_Espresso_Txn_Page__run__exit', false)) {
93
-                exit;
94
-            }
95
-        }
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * callback that runs when the shortcode is encountered in post content.
102
-     * IMPORTANT !!!
103
-     * remember that shortcode content should be RETURNED and NOT echoed out
104
-     *
105
-     * @param array $attributes
106
-     * @return string
107
-     */
108
-    public function processShortcode($attributes = array())
109
-    {
110
-        return esc_html__(
111
-            'This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.',
112
-            'event_espresso'
113
-        );
114
-    }
30
+	/**
31
+	 * the actual shortcode tag that gets registered with WordPress
32
+	 *
33
+	 * @return string
34
+	 */
35
+	public function getTag()
36
+	{
37
+		return 'ESPRESSO_TXN_PAGE';
38
+	}
39
+
40
+
41
+
42
+	/**
43
+	 * the time in seconds to cache the results of the processShortcode() method
44
+	 * 0 means the processShortcode() results will NOT be cached at all
45
+	 *
46
+	 * @return int
47
+	 */
48
+	public function cacheExpiration()
49
+	{
50
+		return 0;
51
+	}
52
+
53
+
54
+	/**
55
+	 * a place for adding any initialization code that needs to run prior to wp_header().
56
+	 * this may be required for shortcodes that utilize a corresponding module,
57
+	 * and need to enqueue assets for that module
58
+	 *
59
+	 * @return void
60
+	 * @throws \Exception
61
+	 * @throws \EE_Error
62
+	 */
63
+	public function initializeShortcode()
64
+	{
65
+		$transaction = null;
66
+		if (EE_Registry::instance()->REQ->is_set('e_reg_url_link')) {
67
+			/** @var EEM_Transaction $EEM_Transaction */
68
+			$EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
69
+			$transaction = $EEM_Transaction->get_transaction_from_reg_url_link();
70
+		}
71
+		if ($transaction instanceof EE_Transaction) {
72
+			$payment_method = null;
73
+			$payment_method_slug = EE_Registry::instance()->REQ->get('ee_payment_method', null);
74
+			if ($payment_method_slug) {
75
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($payment_method_slug);
76
+			}
77
+			if ($payment_method instanceof EE_Payment_Method && $payment_method->is_off_site()) {
78
+				$gateway = $payment_method->type_obj()->get_gateway();
79
+				if (
80
+					$gateway instanceof EE_Offsite_Gateway
81
+					&& $gateway->handle_IPN_in_this_request(
82
+						\EE_Registry::instance()->REQ->params(),
83
+						true
84
+					)
85
+				) {
86
+					/** @type EE_Payment_Processor $payment_processor */
87
+					$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
88
+					$payment_processor->process_ipn($_REQUEST, $transaction, $payment_method);
89
+				}
90
+			}
91
+			//allow gateways to add a filter to stop rendering the page
92
+			if (apply_filters('FHEE__EES_Espresso_Txn_Page__run__exit', false)) {
93
+				exit;
94
+			}
95
+		}
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * callback that runs when the shortcode is encountered in post content.
102
+	 * IMPORTANT !!!
103
+	 * remember that shortcode content should be RETURNED and NOT echoed out
104
+	 *
105
+	 * @param array $attributes
106
+	 * @return string
107
+	 */
108
+	public function processShortcode($attributes = array())
109
+	{
110
+		return esc_html__(
111
+			'This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.',
112
+			'event_espresso'
113
+		);
114
+	}
115 115
 }
116 116
 // End of file EspressoTxnPage.php
117 117
 // Location: EventEspresso\core\domain\entities\shortcodes/EspressoTxnPage.php
118 118
\ No newline at end of file
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoCancelled.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -24,79 +24,79 @@
 block discarded – undo
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     * the actual shortcode tag that gets registered with WordPress
29
-     *
30
-     * @return string
31
-     */
32
-    public function getTag()
33
-    {
34
-        return 'ESPRESSO_CANCELLED';
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * the time in seconds to cache the results of the processShortcode() method
41
-     * 0 means the processShortcode() results will NOT be cached at all
42
-     *
43
-     * @return int
44
-     */
45
-    public function cacheExpiration()
46
-    {
47
-        return 0;
48
-    }
49
-
50
-
51
-    /**
52
-     * a place for adding any initialization code that needs to run prior to wp_header().
53
-     * this may be required for shortcodes that utilize a corresponding module,
54
-     * and need to enqueue assets for that module
55
-     *
56
-     * @return void
57
-     */
58
-    public function initializeShortcode()
59
-    {
60
-        // required by interface, but nothing to do atm
61
-    }
62
-
63
-
64
-    /**
65
-     * callback that runs when the shortcode is encountered in post content.
66
-     * IMPORTANT !!!
67
-     * remember that shortcode content should be RETURNED and NOT echoed out
68
-     *
69
-     * @param array $attributes
70
-     * @return string
71
-     * @throws \EE_Error
72
-     */
73
-    public function processShortcode($attributes = array())
74
-    {
75
-        $transaction = EE_Registry::instance()->SSN->get_session_data('transaction');
76
-        if ($transaction instanceof EE_Transaction) {
77
-            do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', $transaction);
78
-            $registrations = $transaction->registrations();
79
-            foreach ($registrations as $registration) {
80
-                if ($registration instanceof EE_Registration) {
81
-                    do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__registration', $registration);
82
-                }
83
-            }
84
-        }
85
-        do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__clear_session');
86
-        // remove all unwanted records from the db
87
-        if (EE_Registry::instance()->CART instanceof EE_Cart) {
88
-            EE_Registry::instance()->CART->delete_cart();
89
-        }
90
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
91
-        return sprintf(
92
-            __(
93
-                '%sAll unsaved registration information entered during this session has been deleted.%s',
94
-                'event_espresso'
95
-            ),
96
-            '<p class="ee-registrations-cancelled-pg ee-attention">',
97
-            '</p>'
98
-        );
99
-    }
27
+	/**
28
+	 * the actual shortcode tag that gets registered with WordPress
29
+	 *
30
+	 * @return string
31
+	 */
32
+	public function getTag()
33
+	{
34
+		return 'ESPRESSO_CANCELLED';
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * the time in seconds to cache the results of the processShortcode() method
41
+	 * 0 means the processShortcode() results will NOT be cached at all
42
+	 *
43
+	 * @return int
44
+	 */
45
+	public function cacheExpiration()
46
+	{
47
+		return 0;
48
+	}
49
+
50
+
51
+	/**
52
+	 * a place for adding any initialization code that needs to run prior to wp_header().
53
+	 * this may be required for shortcodes that utilize a corresponding module,
54
+	 * and need to enqueue assets for that module
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function initializeShortcode()
59
+	{
60
+		// required by interface, but nothing to do atm
61
+	}
62
+
63
+
64
+	/**
65
+	 * callback that runs when the shortcode is encountered in post content.
66
+	 * IMPORTANT !!!
67
+	 * remember that shortcode content should be RETURNED and NOT echoed out
68
+	 *
69
+	 * @param array $attributes
70
+	 * @return string
71
+	 * @throws \EE_Error
72
+	 */
73
+	public function processShortcode($attributes = array())
74
+	{
75
+		$transaction = EE_Registry::instance()->SSN->get_session_data('transaction');
76
+		if ($transaction instanceof EE_Transaction) {
77
+			do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', $transaction);
78
+			$registrations = $transaction->registrations();
79
+			foreach ($registrations as $registration) {
80
+				if ($registration instanceof EE_Registration) {
81
+					do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__registration', $registration);
82
+				}
83
+			}
84
+		}
85
+		do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__clear_session');
86
+		// remove all unwanted records from the db
87
+		if (EE_Registry::instance()->CART instanceof EE_Cart) {
88
+			EE_Registry::instance()->CART->delete_cart();
89
+		}
90
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
91
+		return sprintf(
92
+			__(
93
+				'%sAll unsaved registration information entered during this session has been deleted.%s',
94
+				'event_espresso'
95
+			),
96
+			'<p class="ee-registrations-cancelled-pg ee-attention">',
97
+			'</p>'
98
+		);
99
+	}
100 100
 
101 101
 }
102 102
 // End of file EspressoCancelled.php
Please login to merge, or discard this patch.