Completed
Branch master (d4ace2)
by
unknown
04:43
created
admin_pages/registrations/EE_Registrations_List_Table.class.php 2 patches
Indentation   +1137 added lines, -1137 removed lines patch added patch discarded remove patch
@@ -18,620 +18,620 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class EE_Registrations_List_Table extends EE_Admin_List_Table
20 20
 {
21
-    /**
22
-     * @var Registrations_Admin_Page
23
-     */
24
-    protected EE_Admin_Page $_admin_page;
25
-
26
-    protected RegistrationsListTableUserCapabilities $caps_handler;
27
-
28
-    private array $_status;
29
-
30
-    /**
31
-     * An array of transaction details for the related transaction to the registration being processed.
32
-     * This is set via the _set_related_details method.
33
-     *
34
-     * @var array
35
-     */
36
-    protected array $_transaction_details = [];
37
-
38
-    /**
39
-     * An array of event details for the related event to the registration being processed.
40
-     * This is set via the _set_related_details method.
41
-     *
42
-     * @var array
43
-     */
44
-    protected array $_event_details = [];
45
-
46
-    private array $filters = [];
47
-
48
-    private int $EVT_ID = 0;
49
-
50
-    private int $DTT_ID = 0;
51
-
52
-    private int $TKT_ID = 0;
53
-
54
-
55
-    /**
56
-     * @param Registrations_Admin_Page $admin_page
57
-     */
58
-    public function __construct(Registrations_Admin_Page $admin_page)
59
-    {
60
-        $this->caps_handler = new RegistrationsListTableUserCapabilities(EE_Registry::instance()->CAP);
61
-        $this->request      = $this->request ?? LoaderFactory::getShared(RequestInterface::class);
62
-        $this->setupFilters();
63
-        parent::__construct($admin_page);
64
-        $this->_status = $this->_admin_page->get_registration_status_array();
65
-    }
66
-
67
-
68
-    private function setupFilters()
69
-    {
70
-        // for event filtering
71
-        $this->EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INTEGER);
72
-        $this->EVT_ID = $this->request->getRequestParam('event_id', $this->EVT_ID, DataType::INTEGER);
73
-        // for datetime filtering
74
-        $this->DTT_ID = $this->request->getRequestParam('DTT_ID', 0, DataType::INTEGER);
75
-        $this->DTT_ID = $this->request->getRequestParam('datetime_id', $this->DTT_ID, DataType::INTEGER);
76
-        // for ticket filtering
77
-        $this->TKT_ID = $this->request->getRequestParam('TKT_ID', 0, DataType::INTEGER);
78
-        $this->TKT_ID = $this->request->getRequestParam('ticket_id', $this->TKT_ID, DataType::INTEGER);
79
-
80
-        $filters = [
81
-            'event_id'    => $this->EVT_ID,
82
-            'datetime_id' => $this->DTT_ID,
83
-            'ticket_id'   => $this->TKT_ID,
84
-        ];
85
-        foreach ($filters as $filter_key => $filter_value) {
86
-            if ($filter_value) {
87
-                $this->filters[ $filter_key ] = $filter_value;
88
-            }
89
-        }
90
-
91
-        add_filter(
92
-            'FHEE__EE_Admin_Page__get_list_table_view_RLs__extra_query_args',
93
-            [$this, 'filterExtraQueryArgs'],
94
-            10,
95
-            2
96
-        );
97
-    }
98
-
99
-
100
-    /**
101
-     * @param array         $extra_query_args
102
-     * @param EE_Admin_Page $admin_page
103
-     * @return void
104
-     * @since 5.0.13.p
105
-     */
106
-    public function filterExtraQueryArgs(array $extra_query_args, EE_Admin_Page $admin_page): array
107
-    {
108
-        if ($admin_page instanceof Registrations_Admin_Page) {
109
-            foreach ($admin_page->get_views() as $view_details) {
110
-                foreach ($this->filters as $filter_key => $filter_value) {
111
-                    $extra_query_args[ $view_details['slug'] ][ $filter_key ] = $filter_value;
112
-                }
113
-            }
114
-        }
115
-        return $extra_query_args;
116
-    }
117
-
118
-
119
-    /**
120
-     * @return void
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    protected function _setup_data()
125
-    {
126
-        $this->_data           = $this->_admin_page->get_registrations($this->_per_page);
127
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
128
-    }
129
-
130
-
131
-    /**
132
-     * @return void
133
-     */
134
-    protected function _set_properties()
135
-    {
136
-        $this->_wp_list_args = [
137
-            'singular' => esc_html__('registration', 'event_espresso'),
138
-            'plural'   => esc_html__('registrations', 'event_espresso'),
139
-            'ajax'     => true,
140
-            'screen'   => $this->_admin_page->get_current_screen()->id,
141
-        ];
142
-
143
-        if ($this->EVT_ID) {
144
-            $this->_columns = [
145
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
146
-                'id'               => esc_html__('ID', 'event_espresso'),
147
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
148
-                'ATT_email'        => esc_html__('Email', 'event_espresso'),
149
-                '_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
150
-                'REG_ticket'       => esc_html__('Ticket', 'event_espresso'),
151
-                '_REG_final_price' => esc_html__('Price', 'event_espresso'),
152
-                '_REG_paid'        => esc_html__('REG Paid', 'event_espresso'),
153
-                'TXN_total'        => esc_html__('TXN Paid/Total', 'event_espresso'),
154
-                'actions'          => $this->actionsColumnHeader(),
155
-            ];
156
-        } elseif ($this->TKT_ID) {
157
-            $this->_columns = [
158
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
159
-                'id'               => esc_html__('ID', 'event_espresso'),
160
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
161
-                'ATT_email'        => esc_html__('Email', 'event_espresso'),
162
-                '_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
163
-                '_REG_final_price' => esc_html__('Price', 'event_espresso'),
164
-                '_REG_paid'        => esc_html__('REG Paid', 'event_espresso'),
165
-                'TXN_total'        => esc_html__('TXN Paid/Total', 'event_espresso'),
166
-                'actions'          => $this->actionsColumnHeader(),
167
-            ];
168
-        } else {
169
-            $this->_columns = [
170
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
171
-                'id'               => esc_html__('ID', 'event_espresso'),
172
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
173
-                '_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
174
-                'event_name'       => esc_html__('Event', 'event_espresso'),
175
-                'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
176
-                'REG_ticket'       => esc_html__('Ticket', 'event_espresso'),
177
-                '_REG_final_price' => esc_html__('Price', 'event_espresso'),
178
-                '_REG_paid'        => esc_html__('REG Paid', 'event_espresso'),
179
-                'TXN_total'        => esc_html__('TXN Paid/Total', 'event_espresso'),
180
-                'actions'          => $this->actionsColumnHeader(),
181
-            ];
182
-        }
183
-
184
-        $this->_primary_column   = 'id';
185
-        $this->_sortable_columns = [
186
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
187
-            /**
188
-             * Allows users to change the default sort if they wish.
189
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
190
-             * name.
191
-             */
192
-            'ATT_fname'     => [
193
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
194
-                true,
195
-                $this,
196
-            ]
197
-                ? ['ATT_lname' => false]
198
-                : ['ATT_fname' => false],
199
-            'event_name'    => ['event_name' => false],
200
-            'DTT_EVT_start' => ['DTT_EVT_start' => false],
201
-            'id'            => ['REG_ID' => false],
202
-        ];
203
-        $this->_hidden_columns   = [];
204
-
205
-        $csv_report = RegistrationsCsvReportParams::getRequestParams(
206
-            $this->getReturnUrl(),
207
-            $this->_admin_page->get_request_data(),
208
-            $this->EVT_ID,
209
-            $this->DTT_ID
210
-        );
211
-        if (! empty($csv_report)) {
212
-            $this->_bottom_buttons['csv_reg_report'] = $csv_report;
213
-        }
214
-    }
215
-
216
-
217
-    /**
218
-     * This simply sets up the row class for the table rows.
219
-     * Allows for easier overriding of child methods for setting up sorting.
220
-     *
221
-     * @param EE_Registration $item the current item
222
-     * @return string
223
-     */
224
-    protected function _get_row_class($item): string
225
-    {
226
-        $class = parent::_get_row_class($item);
227
-        if ($this->_has_checkbox_column) {
228
-            $class .= ' has-checkbox-column';
229
-        }
230
-        return $class;
231
-    }
232
-
233
-
234
-    /**
235
-     * Set the $_transaction_details property if not set yet.
236
-     *
237
-     * @param EE_Registration $registration
238
-     * @throws EE_Error
239
-     * @throws InvalidArgumentException
240
-     * @throws ReflectionException
241
-     * @throws InvalidDataTypeException
242
-     * @throws InvalidInterfaceException
243
-     */
244
-    protected function _set_related_details(EE_Registration $registration)
245
-    {
246
-        $transaction                = $registration->transaction();
247
-        $status                     = $transaction->status_ID();
248
-        $this->_transaction_details = [
249
-            'transaction' => $transaction,
250
-            'status'      => $status,
251
-            'id'          => $transaction->ID(),
252
-            'title_attr'  => sprintf(
253
-                esc_html__('View Transaction Details (%s)', 'event_espresso'),
254
-                EEH_Template::pretty_status($status, false, 'sentence')
255
-            ),
256
-        ];
257
-        try {
258
-            $event = $registration->event();
259
-        } catch (EntityNotFoundException $e) {
260
-            $event = null;
261
-        }
262
-        $status               = $event instanceof EE_Event
263
-            ? $event->get_active_status()
264
-            : EE_Datetime::inactive;
265
-        $this->_event_details = [
266
-            'event'      => $event,
267
-            'status'     => $status,
268
-            'id'         => $event instanceof EE_Event
269
-                ? $event->ID()
270
-                : 0,
271
-            'title_attr' => sprintf(
272
-                esc_html__('Edit Event (%s)', 'event_espresso'),
273
-                EEH_Template::pretty_status($status, false, 'sentence')
274
-            ),
275
-        ];
276
-    }
277
-
278
-
279
-    /**
280
-     * @return array
281
-     * @throws EE_Error
282
-     * @throws ReflectionException
283
-     */
284
-    protected function _get_table_filters()
285
-    {
286
-        $filters = [];
287
-        // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
288
-        // methods.
289
-        $cur_date     = $this->request->getRequestParam('month_range', '');
290
-        $cur_category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INTEGER);
291
-        $reg_status   = $this->request->getRequestParam('_reg_status', '');
292
-        $filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
293
-        $filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
294
-        $status       = [];
295
-        $status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
296
-        foreach ($this->_status as $key => $value) {
297
-            $status[] = ['id' => $key, 'text' => $value];
298
-        }
299
-        if ($this->_view !== 'incomplete') {
300
-            $filters[] = EEH_Form_Fields::select_input(
301
-                '_reg_status',
302
-                $status,
303
-                $reg_status ? strtoupper($reg_status) : ''
304
-            );
305
-        }
306
-        foreach ($this->filters as $filter_key => $filter_value) {
307
-            $filters[] = EEH_Form_Fields::hidden_input($filter_key, $filter_value, 'reg_' . $filter_key);
308
-        }
309
-        return $filters;
310
-    }
311
-
312
-
313
-    /**
314
-     * @return void
315
-     * @throws EE_Error
316
-     * @throws InvalidArgumentException
317
-     * @throws InvalidDataTypeException
318
-     * @throws InvalidInterfaceException
319
-     * @throws ReflectionException
320
-     */
321
-    protected function _add_view_counts()
322
-    {
323
-        $this->_views['all']['count']       = $this->_total_registrations();
324
-        $this->_views['today']['count']     = $this->_total_registrations_today();
325
-        $this->_views['yesterday']['count'] = $this->totalRegistrationsYesterday();
326
-        $this->_views['month']['count']     = $this->_total_registrations_this_month();
327
-        if ($this->caps_handler->userCanTrashRegistrations()) {
328
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
329
-            $this->_views['trash']['count']      = $this->_total_registrations('trash');
330
-        }
331
-    }
332
-
333
-
334
-    private function addWhereParamsForFilters(array $where = []): array
335
-    {
336
-        if ($this->EVT_ID) {
337
-            $where['EVT_ID'] = $this->EVT_ID;
338
-        }
339
-        if ($this->DTT_ID) {
340
-            $where['Ticket.Datetime.DTT_ID'] = $this->DTT_ID;
341
-        }
342
-        if ($this->TKT_ID) {
343
-            $where['TKT_ID'] = $this->TKT_ID;
344
-        }
345
-        return $where;
346
-    }
347
-
348
-
349
-    /**
350
-     * @param string $view
351
-     * @return int
352
-     * @throws EE_Error
353
-     * @throws ReflectionException
354
-     */
355
-    protected function _total_registrations(string $view = ''): int
356
-    {
357
-        $where = $this->addWhereParamsForFilters();
358
-        switch ($view) {
359
-            case 'trash':
360
-                return EEM_Registration::instance()->count_deleted([$where]);
361
-            case 'incomplete':
362
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
363
-                break;
364
-            default:
365
-                $where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
366
-        }
367
-        return EEM_Registration::instance()->count([$where]);
368
-    }
369
-
370
-
371
-    /**
372
-     * @return int
373
-     * @throws EE_Error
374
-     * @throws ReflectionException
375
-     */
376
-    protected function _total_registrations_this_month(): int
377
-    {
378
-        $current_time   = current_time('timestamp');
379
-        $year_and_month = date('Y-m', $current_time);
380
-        $days_in_month  = date('t', $current_time);
381
-
382
-        $start_date = "$year_and_month-01";
383
-        $end_date   = "$year_and_month-$days_in_month";
384
-
385
-        return $this->totalRegistrationsForDateRange($start_date, $end_date);
386
-    }
387
-
388
-
389
-    /**
390
-     * @return int
391
-     * @throws EE_Error
392
-     * @throws ReflectionException
393
-     */
394
-    protected function _total_registrations_today(): int
395
-    {
396
-        $today = date('Y-m-d', current_time('timestamp'));
397
-        return $this->totalRegistrationsForDateRange($today, $today);
398
-    }
399
-
400
-
401
-    /**
402
-     * @return int
403
-     * @throws EE_Error
404
-     * @throws ReflectionException
405
-     */
406
-    protected function totalRegistrationsYesterday(): int
407
-    {
408
-        $yesterday = date('Y-m-d', current_time('timestamp') - DAY_IN_SECONDS);
409
-        return $this->totalRegistrationsForDateRange($yesterday, $yesterday);
410
-    }
411
-
412
-
413
-    /**
414
-     * @param string $start_date earlier date string in format 'Y-m-d'
415
-     * @param string $end_date   later date string in format 'Y-m-d'
416
-     * @return int
417
-     * @throws EE_Error
418
-     * @throws ReflectionException
419
-     */
420
-    private function totalRegistrationsForDateRange(string $start_date, string $end_date): int
421
-    {
422
-        $where = $this->addWhereParamsForFilters(
423
-            [
424
-                'REG_date' => [
425
-                    'BETWEEN',
426
-                    [
427
-                        EEM_Registration::instance()->convert_datetime_for_query(
428
-                            'REG_date',
429
-                            "$start_date 00:00:00",
430
-                            'Y-m-d H:i:s'
431
-                        ),
432
-                        EEM_Registration::instance()->convert_datetime_for_query(
433
-                            'REG_date',
434
-                            "$end_date  23:59:59",
435
-                            'Y-m-d H:i:s'
436
-                        ),
437
-                    ],
438
-                ],
439
-                'STS_ID'   => ['!=', EEM_Registration::status_id_incomplete],
440
-            ]
441
-        );
442
-        return EEM_Registration::instance()->count([$where]);
443
-    }
444
-
445
-
446
-    /**
447
-     * @param EE_Registration $item
448
-     * @return string
449
-     * @throws EE_Error
450
-     * @throws InvalidArgumentException
451
-     * @throws InvalidDataTypeException
452
-     * @throws InvalidInterfaceException
453
-     * @throws ReflectionException
454
-     */
455
-    public function column_cb($item): string
456
-    {
457
-        /** checkbox/lock **/
458
-        $REG_ID        = $item->ID();
459
-        $transaction   = $item->transaction();
460
-        $payment_count = $transaction->count_related('Payment');
461
-
462
-        $content = '<input type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />';
463
-        $content .= $payment_count > 0 || ! $this->caps_handler->userCanEditRegistration($item)
464
-            ? '<span class="ee-locked-entity dashicons dashicons-lock ee-aria-tooltip ee-aria-tooltip--big-box"
21
+	/**
22
+	 * @var Registrations_Admin_Page
23
+	 */
24
+	protected EE_Admin_Page $_admin_page;
25
+
26
+	protected RegistrationsListTableUserCapabilities $caps_handler;
27
+
28
+	private array $_status;
29
+
30
+	/**
31
+	 * An array of transaction details for the related transaction to the registration being processed.
32
+	 * This is set via the _set_related_details method.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected array $_transaction_details = [];
37
+
38
+	/**
39
+	 * An array of event details for the related event to the registration being processed.
40
+	 * This is set via the _set_related_details method.
41
+	 *
42
+	 * @var array
43
+	 */
44
+	protected array $_event_details = [];
45
+
46
+	private array $filters = [];
47
+
48
+	private int $EVT_ID = 0;
49
+
50
+	private int $DTT_ID = 0;
51
+
52
+	private int $TKT_ID = 0;
53
+
54
+
55
+	/**
56
+	 * @param Registrations_Admin_Page $admin_page
57
+	 */
58
+	public function __construct(Registrations_Admin_Page $admin_page)
59
+	{
60
+		$this->caps_handler = new RegistrationsListTableUserCapabilities(EE_Registry::instance()->CAP);
61
+		$this->request      = $this->request ?? LoaderFactory::getShared(RequestInterface::class);
62
+		$this->setupFilters();
63
+		parent::__construct($admin_page);
64
+		$this->_status = $this->_admin_page->get_registration_status_array();
65
+	}
66
+
67
+
68
+	private function setupFilters()
69
+	{
70
+		// for event filtering
71
+		$this->EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INTEGER);
72
+		$this->EVT_ID = $this->request->getRequestParam('event_id', $this->EVT_ID, DataType::INTEGER);
73
+		// for datetime filtering
74
+		$this->DTT_ID = $this->request->getRequestParam('DTT_ID', 0, DataType::INTEGER);
75
+		$this->DTT_ID = $this->request->getRequestParam('datetime_id', $this->DTT_ID, DataType::INTEGER);
76
+		// for ticket filtering
77
+		$this->TKT_ID = $this->request->getRequestParam('TKT_ID', 0, DataType::INTEGER);
78
+		$this->TKT_ID = $this->request->getRequestParam('ticket_id', $this->TKT_ID, DataType::INTEGER);
79
+
80
+		$filters = [
81
+			'event_id'    => $this->EVT_ID,
82
+			'datetime_id' => $this->DTT_ID,
83
+			'ticket_id'   => $this->TKT_ID,
84
+		];
85
+		foreach ($filters as $filter_key => $filter_value) {
86
+			if ($filter_value) {
87
+				$this->filters[ $filter_key ] = $filter_value;
88
+			}
89
+		}
90
+
91
+		add_filter(
92
+			'FHEE__EE_Admin_Page__get_list_table_view_RLs__extra_query_args',
93
+			[$this, 'filterExtraQueryArgs'],
94
+			10,
95
+			2
96
+		);
97
+	}
98
+
99
+
100
+	/**
101
+	 * @param array         $extra_query_args
102
+	 * @param EE_Admin_Page $admin_page
103
+	 * @return void
104
+	 * @since 5.0.13.p
105
+	 */
106
+	public function filterExtraQueryArgs(array $extra_query_args, EE_Admin_Page $admin_page): array
107
+	{
108
+		if ($admin_page instanceof Registrations_Admin_Page) {
109
+			foreach ($admin_page->get_views() as $view_details) {
110
+				foreach ($this->filters as $filter_key => $filter_value) {
111
+					$extra_query_args[ $view_details['slug'] ][ $filter_key ] = $filter_value;
112
+				}
113
+			}
114
+		}
115
+		return $extra_query_args;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return void
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	protected function _setup_data()
125
+	{
126
+		$this->_data           = $this->_admin_page->get_registrations($this->_per_page);
127
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
128
+	}
129
+
130
+
131
+	/**
132
+	 * @return void
133
+	 */
134
+	protected function _set_properties()
135
+	{
136
+		$this->_wp_list_args = [
137
+			'singular' => esc_html__('registration', 'event_espresso'),
138
+			'plural'   => esc_html__('registrations', 'event_espresso'),
139
+			'ajax'     => true,
140
+			'screen'   => $this->_admin_page->get_current_screen()->id,
141
+		];
142
+
143
+		if ($this->EVT_ID) {
144
+			$this->_columns = [
145
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
146
+				'id'               => esc_html__('ID', 'event_espresso'),
147
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
148
+				'ATT_email'        => esc_html__('Email', 'event_espresso'),
149
+				'_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
150
+				'REG_ticket'       => esc_html__('Ticket', 'event_espresso'),
151
+				'_REG_final_price' => esc_html__('Price', 'event_espresso'),
152
+				'_REG_paid'        => esc_html__('REG Paid', 'event_espresso'),
153
+				'TXN_total'        => esc_html__('TXN Paid/Total', 'event_espresso'),
154
+				'actions'          => $this->actionsColumnHeader(),
155
+			];
156
+		} elseif ($this->TKT_ID) {
157
+			$this->_columns = [
158
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
159
+				'id'               => esc_html__('ID', 'event_espresso'),
160
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
161
+				'ATT_email'        => esc_html__('Email', 'event_espresso'),
162
+				'_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
163
+				'_REG_final_price' => esc_html__('Price', 'event_espresso'),
164
+				'_REG_paid'        => esc_html__('REG Paid', 'event_espresso'),
165
+				'TXN_total'        => esc_html__('TXN Paid/Total', 'event_espresso'),
166
+				'actions'          => $this->actionsColumnHeader(),
167
+			];
168
+		} else {
169
+			$this->_columns = [
170
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
171
+				'id'               => esc_html__('ID', 'event_espresso'),
172
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
173
+				'_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
174
+				'event_name'       => esc_html__('Event', 'event_espresso'),
175
+				'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
176
+				'REG_ticket'       => esc_html__('Ticket', 'event_espresso'),
177
+				'_REG_final_price' => esc_html__('Price', 'event_espresso'),
178
+				'_REG_paid'        => esc_html__('REG Paid', 'event_espresso'),
179
+				'TXN_total'        => esc_html__('TXN Paid/Total', 'event_espresso'),
180
+				'actions'          => $this->actionsColumnHeader(),
181
+			];
182
+		}
183
+
184
+		$this->_primary_column   = 'id';
185
+		$this->_sortable_columns = [
186
+			'_REG_date'     => ['_REG_date' => true],   // true means its already sorted
187
+			/**
188
+			 * Allows users to change the default sort if they wish.
189
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
190
+			 * name.
191
+			 */
192
+			'ATT_fname'     => [
193
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
194
+				true,
195
+				$this,
196
+			]
197
+				? ['ATT_lname' => false]
198
+				: ['ATT_fname' => false],
199
+			'event_name'    => ['event_name' => false],
200
+			'DTT_EVT_start' => ['DTT_EVT_start' => false],
201
+			'id'            => ['REG_ID' => false],
202
+		];
203
+		$this->_hidden_columns   = [];
204
+
205
+		$csv_report = RegistrationsCsvReportParams::getRequestParams(
206
+			$this->getReturnUrl(),
207
+			$this->_admin_page->get_request_data(),
208
+			$this->EVT_ID,
209
+			$this->DTT_ID
210
+		);
211
+		if (! empty($csv_report)) {
212
+			$this->_bottom_buttons['csv_reg_report'] = $csv_report;
213
+		}
214
+	}
215
+
216
+
217
+	/**
218
+	 * This simply sets up the row class for the table rows.
219
+	 * Allows for easier overriding of child methods for setting up sorting.
220
+	 *
221
+	 * @param EE_Registration $item the current item
222
+	 * @return string
223
+	 */
224
+	protected function _get_row_class($item): string
225
+	{
226
+		$class = parent::_get_row_class($item);
227
+		if ($this->_has_checkbox_column) {
228
+			$class .= ' has-checkbox-column';
229
+		}
230
+		return $class;
231
+	}
232
+
233
+
234
+	/**
235
+	 * Set the $_transaction_details property if not set yet.
236
+	 *
237
+	 * @param EE_Registration $registration
238
+	 * @throws EE_Error
239
+	 * @throws InvalidArgumentException
240
+	 * @throws ReflectionException
241
+	 * @throws InvalidDataTypeException
242
+	 * @throws InvalidInterfaceException
243
+	 */
244
+	protected function _set_related_details(EE_Registration $registration)
245
+	{
246
+		$transaction                = $registration->transaction();
247
+		$status                     = $transaction->status_ID();
248
+		$this->_transaction_details = [
249
+			'transaction' => $transaction,
250
+			'status'      => $status,
251
+			'id'          => $transaction->ID(),
252
+			'title_attr'  => sprintf(
253
+				esc_html__('View Transaction Details (%s)', 'event_espresso'),
254
+				EEH_Template::pretty_status($status, false, 'sentence')
255
+			),
256
+		];
257
+		try {
258
+			$event = $registration->event();
259
+		} catch (EntityNotFoundException $e) {
260
+			$event = null;
261
+		}
262
+		$status               = $event instanceof EE_Event
263
+			? $event->get_active_status()
264
+			: EE_Datetime::inactive;
265
+		$this->_event_details = [
266
+			'event'      => $event,
267
+			'status'     => $status,
268
+			'id'         => $event instanceof EE_Event
269
+				? $event->ID()
270
+				: 0,
271
+			'title_attr' => sprintf(
272
+				esc_html__('Edit Event (%s)', 'event_espresso'),
273
+				EEH_Template::pretty_status($status, false, 'sentence')
274
+			),
275
+		];
276
+	}
277
+
278
+
279
+	/**
280
+	 * @return array
281
+	 * @throws EE_Error
282
+	 * @throws ReflectionException
283
+	 */
284
+	protected function _get_table_filters()
285
+	{
286
+		$filters = [];
287
+		// todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
288
+		// methods.
289
+		$cur_date     = $this->request->getRequestParam('month_range', '');
290
+		$cur_category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INTEGER);
291
+		$reg_status   = $this->request->getRequestParam('_reg_status', '');
292
+		$filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
293
+		$filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
294
+		$status       = [];
295
+		$status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
296
+		foreach ($this->_status as $key => $value) {
297
+			$status[] = ['id' => $key, 'text' => $value];
298
+		}
299
+		if ($this->_view !== 'incomplete') {
300
+			$filters[] = EEH_Form_Fields::select_input(
301
+				'_reg_status',
302
+				$status,
303
+				$reg_status ? strtoupper($reg_status) : ''
304
+			);
305
+		}
306
+		foreach ($this->filters as $filter_key => $filter_value) {
307
+			$filters[] = EEH_Form_Fields::hidden_input($filter_key, $filter_value, 'reg_' . $filter_key);
308
+		}
309
+		return $filters;
310
+	}
311
+
312
+
313
+	/**
314
+	 * @return void
315
+	 * @throws EE_Error
316
+	 * @throws InvalidArgumentException
317
+	 * @throws InvalidDataTypeException
318
+	 * @throws InvalidInterfaceException
319
+	 * @throws ReflectionException
320
+	 */
321
+	protected function _add_view_counts()
322
+	{
323
+		$this->_views['all']['count']       = $this->_total_registrations();
324
+		$this->_views['today']['count']     = $this->_total_registrations_today();
325
+		$this->_views['yesterday']['count'] = $this->totalRegistrationsYesterday();
326
+		$this->_views['month']['count']     = $this->_total_registrations_this_month();
327
+		if ($this->caps_handler->userCanTrashRegistrations()) {
328
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
329
+			$this->_views['trash']['count']      = $this->_total_registrations('trash');
330
+		}
331
+	}
332
+
333
+
334
+	private function addWhereParamsForFilters(array $where = []): array
335
+	{
336
+		if ($this->EVT_ID) {
337
+			$where['EVT_ID'] = $this->EVT_ID;
338
+		}
339
+		if ($this->DTT_ID) {
340
+			$where['Ticket.Datetime.DTT_ID'] = $this->DTT_ID;
341
+		}
342
+		if ($this->TKT_ID) {
343
+			$where['TKT_ID'] = $this->TKT_ID;
344
+		}
345
+		return $where;
346
+	}
347
+
348
+
349
+	/**
350
+	 * @param string $view
351
+	 * @return int
352
+	 * @throws EE_Error
353
+	 * @throws ReflectionException
354
+	 */
355
+	protected function _total_registrations(string $view = ''): int
356
+	{
357
+		$where = $this->addWhereParamsForFilters();
358
+		switch ($view) {
359
+			case 'trash':
360
+				return EEM_Registration::instance()->count_deleted([$where]);
361
+			case 'incomplete':
362
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
363
+				break;
364
+			default:
365
+				$where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
366
+		}
367
+		return EEM_Registration::instance()->count([$where]);
368
+	}
369
+
370
+
371
+	/**
372
+	 * @return int
373
+	 * @throws EE_Error
374
+	 * @throws ReflectionException
375
+	 */
376
+	protected function _total_registrations_this_month(): int
377
+	{
378
+		$current_time   = current_time('timestamp');
379
+		$year_and_month = date('Y-m', $current_time);
380
+		$days_in_month  = date('t', $current_time);
381
+
382
+		$start_date = "$year_and_month-01";
383
+		$end_date   = "$year_and_month-$days_in_month";
384
+
385
+		return $this->totalRegistrationsForDateRange($start_date, $end_date);
386
+	}
387
+
388
+
389
+	/**
390
+	 * @return int
391
+	 * @throws EE_Error
392
+	 * @throws ReflectionException
393
+	 */
394
+	protected function _total_registrations_today(): int
395
+	{
396
+		$today = date('Y-m-d', current_time('timestamp'));
397
+		return $this->totalRegistrationsForDateRange($today, $today);
398
+	}
399
+
400
+
401
+	/**
402
+	 * @return int
403
+	 * @throws EE_Error
404
+	 * @throws ReflectionException
405
+	 */
406
+	protected function totalRegistrationsYesterday(): int
407
+	{
408
+		$yesterday = date('Y-m-d', current_time('timestamp') - DAY_IN_SECONDS);
409
+		return $this->totalRegistrationsForDateRange($yesterday, $yesterday);
410
+	}
411
+
412
+
413
+	/**
414
+	 * @param string $start_date earlier date string in format 'Y-m-d'
415
+	 * @param string $end_date   later date string in format 'Y-m-d'
416
+	 * @return int
417
+	 * @throws EE_Error
418
+	 * @throws ReflectionException
419
+	 */
420
+	private function totalRegistrationsForDateRange(string $start_date, string $end_date): int
421
+	{
422
+		$where = $this->addWhereParamsForFilters(
423
+			[
424
+				'REG_date' => [
425
+					'BETWEEN',
426
+					[
427
+						EEM_Registration::instance()->convert_datetime_for_query(
428
+							'REG_date',
429
+							"$start_date 00:00:00",
430
+							'Y-m-d H:i:s'
431
+						),
432
+						EEM_Registration::instance()->convert_datetime_for_query(
433
+							'REG_date',
434
+							"$end_date  23:59:59",
435
+							'Y-m-d H:i:s'
436
+						),
437
+					],
438
+				],
439
+				'STS_ID'   => ['!=', EEM_Registration::status_id_incomplete],
440
+			]
441
+		);
442
+		return EEM_Registration::instance()->count([$where]);
443
+	}
444
+
445
+
446
+	/**
447
+	 * @param EE_Registration $item
448
+	 * @return string
449
+	 * @throws EE_Error
450
+	 * @throws InvalidArgumentException
451
+	 * @throws InvalidDataTypeException
452
+	 * @throws InvalidInterfaceException
453
+	 * @throws ReflectionException
454
+	 */
455
+	public function column_cb($item): string
456
+	{
457
+		/** checkbox/lock **/
458
+		$REG_ID        = $item->ID();
459
+		$transaction   = $item->transaction();
460
+		$payment_count = $transaction->count_related('Payment');
461
+
462
+		$content = '<input type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />';
463
+		$content .= $payment_count > 0 || ! $this->caps_handler->userCanEditRegistration($item)
464
+			? '<span class="ee-locked-entity dashicons dashicons-lock ee-aria-tooltip ee-aria-tooltip--big-box"
465 465
                     aria-label="' . $this->lockedRegMessage() . '"></span>'
466
-            : '';
467
-        return $this->columnContent('cb', $content, 'center');
468
-    }
469
-
470
-
471
-    private function lockedRegMessage(): string
472
-    {
473
-        return esc_html__(
474
-            'This lock-icon means that this registration cannot be trashed.  Registrations that belong to a transaction that has payments cannot be trashed.  If you wish to trash this registration then you must delete all payments attached to the related transaction first.',
475
-            'event_espresso'
476
-        );
477
-    }
478
-
479
-
480
-    /**
481
-     * @param EE_Registration $registration
482
-     * @return string
483
-     * @throws EE_Error
484
-     * @throws InvalidArgumentException
485
-     * @throws InvalidDataTypeException
486
-     * @throws InvalidInterfaceException
487
-     * @throws ReflectionException
488
-     */
489
-    public function column_id(EE_Registration $registration): string
490
-    {
491
-        $content = '<span class="ee-entity-id">' . $registration->ID() . '</span>';
492
-        $content .= '<span class="show-on-mobile-view-only">';
493
-        $content .= $this->column_ATT_fname($registration, false);
494
-        $content .= '</span>';
495
-
496
-        return $this->columnContent('id', $content, 'end');
497
-    }
498
-
499
-
500
-    /**
501
-     * @param EE_Registration $registration
502
-     * @param bool            $prep_content
503
-     * @return string
504
-     * @throws EE_Error
505
-     * @throws ReflectionException
506
-     */
507
-    public function column_ATT_fname(EE_Registration $registration, bool $prep_content = true): string
508
-    {
509
-        $status         = esc_attr($registration->status_ID());
510
-        $pretty_status  = EEH_Template::pretty_status($status, false, 'sentence');
511
-        $prime_reg_star = $registration->count() === 1
512
-            ? '<sup><span class="dashicons dashicons-star-filled gold-icon"></span></sup>'
513
-            : '';
514
-
515
-        $group_count = '
466
+			: '';
467
+		return $this->columnContent('cb', $content, 'center');
468
+	}
469
+
470
+
471
+	private function lockedRegMessage(): string
472
+	{
473
+		return esc_html__(
474
+			'This lock-icon means that this registration cannot be trashed.  Registrations that belong to a transaction that has payments cannot be trashed.  If you wish to trash this registration then you must delete all payments attached to the related transaction first.',
475
+			'event_espresso'
476
+		);
477
+	}
478
+
479
+
480
+	/**
481
+	 * @param EE_Registration $registration
482
+	 * @return string
483
+	 * @throws EE_Error
484
+	 * @throws InvalidArgumentException
485
+	 * @throws InvalidDataTypeException
486
+	 * @throws InvalidInterfaceException
487
+	 * @throws ReflectionException
488
+	 */
489
+	public function column_id(EE_Registration $registration): string
490
+	{
491
+		$content = '<span class="ee-entity-id">' . $registration->ID() . '</span>';
492
+		$content .= '<span class="show-on-mobile-view-only">';
493
+		$content .= $this->column_ATT_fname($registration, false);
494
+		$content .= '</span>';
495
+
496
+		return $this->columnContent('id', $content, 'end');
497
+	}
498
+
499
+
500
+	/**
501
+	 * @param EE_Registration $registration
502
+	 * @param bool            $prep_content
503
+	 * @return string
504
+	 * @throws EE_Error
505
+	 * @throws ReflectionException
506
+	 */
507
+	public function column_ATT_fname(EE_Registration $registration, bool $prep_content = true): string
508
+	{
509
+		$status         = esc_attr($registration->status_ID());
510
+		$pretty_status  = EEH_Template::pretty_status($status, false, 'sentence');
511
+		$prime_reg_star = $registration->count() === 1
512
+			? '<sup><span class="dashicons dashicons-star-filled gold-icon"></span></sup>'
513
+			: '';
514
+
515
+		$group_count = '
516 516
             <span class="reg-count-group-size" >
517 517
                 ' . sprintf(
518
-                esc_html__('(%1$s / %2$s)', 'event_espresso'),
519
-                $registration->count(),
520
-                $registration->group_size()
521
-            ) . '
518
+				esc_html__('(%1$s / %2$s)', 'event_espresso'),
519
+				$registration->count(),
520
+				$registration->group_size()
521
+			) . '
522 522
             </span >';
523 523
 
524
-        $content = '
524
+		$content = '
525 525
         <div class="ee-layout-row">
526 526
             <span aria-label="' . $pretty_status . '"
527 527
                   class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"
528 528
             ></span>
529 529
             ' . $this->viewRegistrationLink($registration, $status)
530
-            . $prime_reg_star
531
-            . $group_count . '
530
+			. $prime_reg_star
531
+			. $group_count . '
532 532
             <span class="spacer"></span>
533 533
             <span>
534 534
                 ' . sprintf(
535
-                esc_html__('Reg Code: %s', 'event_espresso'),
536
-                $registration->get('REG_code')
537
-            ) . '
535
+				esc_html__('Reg Code: %s', 'event_espresso'),
536
+				$registration->get('REG_code')
537
+			) . '
538 538
             </span>
539 539
         </div>';
540 540
 
541
-        $url_params = ['_REG_ID' => $registration->ID()];
542
-        if ($this->EVT_ID) {
543
-            $url_params['event_id'] = $this->EVT_ID;
544
-        }
545
-        // trash/restore/delete actions
546
-        $actions = $this->trashRegistrationLink($registration, $url_params);
547
-        $actions = $this->restoreRegistrationLink($registration, $url_params, $actions);
548
-        $actions = $this->deleteRegistrationLink($registration, $url_params, $actions);
549
-
550
-        $content .= $this->row_actions($actions);
551
-
552
-        return $prep_content ? $this->columnContent('ATT_fname', $content) : $content;
553
-    }
554
-
555
-
556
-    /**
557
-     * @param EE_Registration $registration
558
-     * @param bool            $prep_content
559
-     * @return string
560
-     * @throws EE_Error
561
-     * @throws ReflectionException
562
-     */
563
-    public function column__REG_date(EE_Registration $registration, bool $prep_content = true): string
564
-    {
565
-        $this->_set_related_details($registration);
566
-        // Build row actions
567
-        $content = $this->viewTransactionLink(
568
-            $registration->transaction(),
569
-            $registration->get_i18n_datetime('REG_date', 'M jS Y g:i a')
570
-        );
571
-        return $prep_content ? $this->columnContent('_REG_date', $content) : $content;
572
-    }
573
-
574
-
575
-    /**
576
-     * @param EE_Registration $registration
577
-     * @return string
578
-     * @throws EE_Error
579
-     * @throws InvalidArgumentException
580
-     * @throws InvalidDataTypeException
581
-     * @throws InvalidInterfaceException
582
-     * @throws ReflectionException
583
-     */
584
-    public function column_event_name(EE_Registration $registration): string
585
-    {
586
-        $this->_set_related_details($registration);
587
-        $edit_event              = $this->editEventLink($registration);
588
-        $actions['event_filter'] = $this->eventFilterLink($registration);
589
-        return $this->columnContent(
590
-            'event_name',
591
-            $edit_event . $this->row_actions($actions)
592
-        );
593
-    }
594
-
595
-
596
-    /**
597
-     * @param EE_Registration $registration
598
-     * @return string
599
-     * @throws EE_Error
600
-     * @throws InvalidArgumentException
601
-     * @throws InvalidDataTypeException
602
-     * @throws InvalidInterfaceException
603
-     * @throws ReflectionException
604
-     */
605
-    public function column_DTT_EVT_start(EE_Registration $registration): string
606
-    {
607
-        $datetime_strings = [];
608
-        $ticket           = $registration->ticket();
609
-        if ($ticket instanceof EE_Ticket) {
610
-            $remove_defaults = ['default_where_conditions' => 'none'];
611
-            $datetimes       = $ticket->datetimes($remove_defaults);
612
-            foreach ($datetimes as $datetime) {
613
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a');
614
-            }
615
-            $content = $this->generateDisplayForDatetimes($datetime_strings);
616
-        } else {
617
-            $content = esc_html__('There is no ticket on this registration', 'event_espresso');
618
-        }
619
-        return $this->columnContent('DTT_EVT_start', $content);
620
-    }
621
-
622
-
623
-    /**
624
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
625
-     *
626
-     * @param array $datetime_strings
627
-     * @return string
628
-     */
629
-    public function generateDisplayForDatetimes(array $datetime_strings): string
630
-    {
631
-        // get first item for initial visibility
632
-        $content = (string) array_shift($datetime_strings);
633
-        if (! empty($datetime_strings)) {
634
-            $content .= '
541
+		$url_params = ['_REG_ID' => $registration->ID()];
542
+		if ($this->EVT_ID) {
543
+			$url_params['event_id'] = $this->EVT_ID;
544
+		}
545
+		// trash/restore/delete actions
546
+		$actions = $this->trashRegistrationLink($registration, $url_params);
547
+		$actions = $this->restoreRegistrationLink($registration, $url_params, $actions);
548
+		$actions = $this->deleteRegistrationLink($registration, $url_params, $actions);
549
+
550
+		$content .= $this->row_actions($actions);
551
+
552
+		return $prep_content ? $this->columnContent('ATT_fname', $content) : $content;
553
+	}
554
+
555
+
556
+	/**
557
+	 * @param EE_Registration $registration
558
+	 * @param bool            $prep_content
559
+	 * @return string
560
+	 * @throws EE_Error
561
+	 * @throws ReflectionException
562
+	 */
563
+	public function column__REG_date(EE_Registration $registration, bool $prep_content = true): string
564
+	{
565
+		$this->_set_related_details($registration);
566
+		// Build row actions
567
+		$content = $this->viewTransactionLink(
568
+			$registration->transaction(),
569
+			$registration->get_i18n_datetime('REG_date', 'M jS Y g:i a')
570
+		);
571
+		return $prep_content ? $this->columnContent('_REG_date', $content) : $content;
572
+	}
573
+
574
+
575
+	/**
576
+	 * @param EE_Registration $registration
577
+	 * @return string
578
+	 * @throws EE_Error
579
+	 * @throws InvalidArgumentException
580
+	 * @throws InvalidDataTypeException
581
+	 * @throws InvalidInterfaceException
582
+	 * @throws ReflectionException
583
+	 */
584
+	public function column_event_name(EE_Registration $registration): string
585
+	{
586
+		$this->_set_related_details($registration);
587
+		$edit_event              = $this->editEventLink($registration);
588
+		$actions['event_filter'] = $this->eventFilterLink($registration);
589
+		return $this->columnContent(
590
+			'event_name',
591
+			$edit_event . $this->row_actions($actions)
592
+		);
593
+	}
594
+
595
+
596
+	/**
597
+	 * @param EE_Registration $registration
598
+	 * @return string
599
+	 * @throws EE_Error
600
+	 * @throws InvalidArgumentException
601
+	 * @throws InvalidDataTypeException
602
+	 * @throws InvalidInterfaceException
603
+	 * @throws ReflectionException
604
+	 */
605
+	public function column_DTT_EVT_start(EE_Registration $registration): string
606
+	{
607
+		$datetime_strings = [];
608
+		$ticket           = $registration->ticket();
609
+		if ($ticket instanceof EE_Ticket) {
610
+			$remove_defaults = ['default_where_conditions' => 'none'];
611
+			$datetimes       = $ticket->datetimes($remove_defaults);
612
+			foreach ($datetimes as $datetime) {
613
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a');
614
+			}
615
+			$content = $this->generateDisplayForDatetimes($datetime_strings);
616
+		} else {
617
+			$content = esc_html__('There is no ticket on this registration', 'event_espresso');
618
+		}
619
+		return $this->columnContent('DTT_EVT_start', $content);
620
+	}
621
+
622
+
623
+	/**
624
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
625
+	 *
626
+	 * @param array $datetime_strings
627
+	 * @return string
628
+	 */
629
+	public function generateDisplayForDatetimes(array $datetime_strings): string
630
+	{
631
+		// get first item for initial visibility
632
+		$content = (string) array_shift($datetime_strings);
633
+		if (! empty($datetime_strings)) {
634
+			$content .= '
635 635
                 <div class="ee-registration-event-datetimes-container-wrap">
636 636
                     <div class="ee-registration-event-datetimes-container__control">
637 637
                         <span class="tiny-text">' . esc_html__('Click to view additional dates', 'event_espresso') . '</span>
@@ -645,637 +645,637 @@  discard block
 block discarded – undo
645 645
                         ' . implode("", $datetime_strings) . '
646 646
                     </div>
647 647
                 </div>';
648
-        }
649
-        return $content;
650
-    }
651
-
652
-
653
-    /**
654
-     * @param EE_Registration $registration
655
-     * @return string
656
-     * @throws EE_Error
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidDataTypeException
659
-     * @throws InvalidInterfaceException
660
-     * @throws ReflectionException
661
-     */
662
-    public function column_ATT_email(EE_Registration $registration): string
663
-    {
664
-        $attendee = $registration->get_first_related('Attendee');
665
-        $content  = ! $attendee instanceof EE_Attendee
666
-            ? esc_html__('No attached contact record.', 'event_espresso')
667
-            : $attendee->email();
668
-        return $this->columnContent('ATT_email', $content);
669
-    }
670
-
671
-
672
-    /**
673
-     * @param EE_Registration $registration
674
-     * @return string
675
-     * @throws EE_Error
676
-     * @throws ReflectionException
677
-     */
678
-    public function column__REG_count(EE_Registration $registration): string
679
-    {
680
-        $content = sprintf(
681
-            esc_html__('%1$s / %2$s', 'event_espresso'),
682
-            $registration->count(),
683
-            $registration->group_size()
684
-        );
685
-        return $this->columnContent('_REG_count', $content);
686
-    }
687
-
688
-
689
-    /**
690
-     * @param EE_Registration $registration
691
-     * @return string
692
-     * @throws EE_Error
693
-     * @throws ReflectionException
694
-     */
695
-    public function column_REG_ticket(EE_Registration $registration): string
696
-    {
697
-        $ticket = $registration->ticket();
698
-        $ticket_name = $this->ticketName($ticket);
699
-        $actions['ticket_filter'] = $this->ticketFilterLink($ticket);
700
-        return $this->columnContent(
701
-            'REG_ticket',
702
-            $ticket_name . $this->row_actions($actions)
703
-        );
704
-    }
705
-
706
-
707
-    /**
708
-     * @param EE_Registration $registration
709
-     * @return string
710
-     * @throws EE_Error
711
-     * @throws ReflectionException
712
-     */
713
-    public function column__REG_final_price(EE_Registration $registration): string
714
-    {
715
-        // free ticket?
716
-        $content = $registration->final_price() > 0
717
-            ? '<span class="reg-overview-paid-event-spn">' . $registration->pretty_final_price() . '</span>'
718
-            : '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
719
-        return $this->columnContent( '_REG_final_price', $content, 'end' );
720
-    }
721
-
722
-
723
-    /**
724
-     * @param EE_Registration $registration
725
-     * @return string
726
-     * @throws EE_Error
727
-     * @throws ReflectionException
728
-     */
729
-    public function column__REG_paid(EE_Registration $registration): string
730
-    {
731
-        $payment_method      = $registration->payment_method();
732
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
733
-            ? $payment_method->admin_name()
734
-            : esc_html__('Unknown', 'event_espresso');
735
-
736
-        $payment_status = EEM_Registration::status_id_pending_payment;
737
-        $content = '<span>';
738
-        $icon = '';
739
-        $label = esc_attr__('pending payment', 'event_espresso');
740
-        if ($registration->paid() == $registration->final_price()) {
741
-            $icon = '<span class="dashicons dashicons-yes green-icon"></span> ';
742
-            $label = esc_attr__('paid in full', 'event_espresso');
743
-            $payment_status = EEM_Registration::status_id_approved;
744
-        }
745
-        if ($registration->paid() > $registration->final_price()) {
746
-            $icon = '<span class="dashicons dashicons-warning orange-icon"></span> ';
747
-            $label = esc_attr__('overpaid', 'event_espresso');
748
-            $payment_status = EEM_Transaction::overpaid_status_code;
749
-        }
750
-        $content .= '
648
+		}
649
+		return $content;
650
+	}
651
+
652
+
653
+	/**
654
+	 * @param EE_Registration $registration
655
+	 * @return string
656
+	 * @throws EE_Error
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidDataTypeException
659
+	 * @throws InvalidInterfaceException
660
+	 * @throws ReflectionException
661
+	 */
662
+	public function column_ATT_email(EE_Registration $registration): string
663
+	{
664
+		$attendee = $registration->get_first_related('Attendee');
665
+		$content  = ! $attendee instanceof EE_Attendee
666
+			? esc_html__('No attached contact record.', 'event_espresso')
667
+			: $attendee->email();
668
+		return $this->columnContent('ATT_email', $content);
669
+	}
670
+
671
+
672
+	/**
673
+	 * @param EE_Registration $registration
674
+	 * @return string
675
+	 * @throws EE_Error
676
+	 * @throws ReflectionException
677
+	 */
678
+	public function column__REG_count(EE_Registration $registration): string
679
+	{
680
+		$content = sprintf(
681
+			esc_html__('%1$s / %2$s', 'event_espresso'),
682
+			$registration->count(),
683
+			$registration->group_size()
684
+		);
685
+		return $this->columnContent('_REG_count', $content);
686
+	}
687
+
688
+
689
+	/**
690
+	 * @param EE_Registration $registration
691
+	 * @return string
692
+	 * @throws EE_Error
693
+	 * @throws ReflectionException
694
+	 */
695
+	public function column_REG_ticket(EE_Registration $registration): string
696
+	{
697
+		$ticket = $registration->ticket();
698
+		$ticket_name = $this->ticketName($ticket);
699
+		$actions['ticket_filter'] = $this->ticketFilterLink($ticket);
700
+		return $this->columnContent(
701
+			'REG_ticket',
702
+			$ticket_name . $this->row_actions($actions)
703
+		);
704
+	}
705
+
706
+
707
+	/**
708
+	 * @param EE_Registration $registration
709
+	 * @return string
710
+	 * @throws EE_Error
711
+	 * @throws ReflectionException
712
+	 */
713
+	public function column__REG_final_price(EE_Registration $registration): string
714
+	{
715
+		// free ticket?
716
+		$content = $registration->final_price() > 0
717
+			? '<span class="reg-overview-paid-event-spn">' . $registration->pretty_final_price() . '</span>'
718
+			: '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
719
+		return $this->columnContent( '_REG_final_price', $content, 'end' );
720
+	}
721
+
722
+
723
+	/**
724
+	 * @param EE_Registration $registration
725
+	 * @return string
726
+	 * @throws EE_Error
727
+	 * @throws ReflectionException
728
+	 */
729
+	public function column__REG_paid(EE_Registration $registration): string
730
+	{
731
+		$payment_method      = $registration->payment_method();
732
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
733
+			? $payment_method->admin_name()
734
+			: esc_html__('Unknown', 'event_espresso');
735
+
736
+		$payment_status = EEM_Registration::status_id_pending_payment;
737
+		$content = '<span>';
738
+		$icon = '';
739
+		$label = esc_attr__('pending payment', 'event_espresso');
740
+		if ($registration->paid() == $registration->final_price()) {
741
+			$icon = '<span class="dashicons dashicons-yes green-icon"></span> ';
742
+			$label = esc_attr__('paid in full', 'event_espresso');
743
+			$payment_status = EEM_Registration::status_id_approved;
744
+		}
745
+		if ($registration->paid() > $registration->final_price()) {
746
+			$icon = '<span class="dashicons dashicons-warning orange-icon"></span> ';
747
+			$label = esc_attr__('overpaid', 'event_espresso');
748
+			$payment_status = EEM_Transaction::overpaid_status_code;
749
+		}
750
+		$content .= '
751 751
             <span class="reg-overview-paid-event-spn ee-aria-tooltip ee-status-color--' . $payment_status . '"
752 752
                   aria-label="' . $label . '"
753 753
             >
754 754
                 ' . $icon . $registration->pretty_paid('no_currency_code') . '
755 755
             </span>
756 756
             </span>';
757
-        if ($registration->paid() > 0) {
758
-            $content .= '
757
+		if ($registration->paid() > 0) {
758
+			$content .= '
759 759
             <span class="ee-status-text-small">
760 760
                 ' . sprintf(
761
-                        esc_html__('...via %s', 'event_espresso'),
762
-                        $payment_method_name
763
-                    ) . '
761
+						esc_html__('...via %s', 'event_espresso'),
762
+						$payment_method_name
763
+					) . '
764 764
             </span>';
765
-        }
766
-        return $this->columnContent('_REG_paid', $content, 'end', 'stack');
767
-    }
768
-
769
-
770
-    /**
771
-     * @param EE_Registration $registration
772
-     * @return string
773
-     * @throws EE_Error
774
-     * @throws EntityNotFoundException
775
-     * @throws InvalidArgumentException
776
-     * @throws InvalidDataTypeException
777
-     * @throws InvalidInterfaceException
778
-     * @throws ReflectionException
779
-     */
780
-    public function column_TXN_total(EE_Registration $registration): string
781
-    {
782
-        $content      = '';
783
-        if ($registration->count() === 1) {
784
-            $transaction = $registration->transaction();
785
-            $content     = '
765
+		}
766
+		return $this->columnContent('_REG_paid', $content, 'end', 'stack');
767
+	}
768
+
769
+
770
+	/**
771
+	 * @param EE_Registration $registration
772
+	 * @return string
773
+	 * @throws EE_Error
774
+	 * @throws EntityNotFoundException
775
+	 * @throws InvalidArgumentException
776
+	 * @throws InvalidDataTypeException
777
+	 * @throws InvalidInterfaceException
778
+	 * @throws ReflectionException
779
+	 */
780
+	public function column_TXN_total(EE_Registration $registration): string
781
+	{
782
+		$content      = '';
783
+		if ($registration->count() === 1) {
784
+			$transaction = $registration->transaction();
785
+			$content     = '
786 786
             <span class="ee-status-color--' . $transaction->status_ID() . '">
787 787
                 ' . $transaction->pretty_paid('no_currency_code') . '
788 788
                 <span class="separator">/</span>
789 789
                 ' . $transaction->pretty_total('no_currency_code') . '
790 790
             </span>';
791 791
 
792
-            $content .= '<span class="row-actions">' . $this->viewTransactionLink($transaction) . '</span>';
793
-        }
794
-        return $this->columnContent('TXN_total', $content, 'end', 'stack');
795
-    }
796
-
797
-
798
-    /**
799
-     * @param EE_Registration $registration
800
-     * @return string
801
-     * @throws EE_Error
802
-     * @throws InvalidArgumentException
803
-     * @throws InvalidDataTypeException
804
-     * @throws InvalidInterfaceException
805
-     * @throws ReflectionException
806
-     */
807
-    public function column_actions(EE_Registration $registration): string
808
-    {
809
-        $attendee = $registration->attendee();
810
-        $this->_set_related_details($registration);
811
-
812
-        // Build and filter row actions
813
-        $actions = apply_filters(
814
-            'FHEE__EE_Registrations_List_Table__column_actions__actions',
815
-            [
816
-                'view_lnk'               => $this->viewRegistrationAction($registration),
817
-                'edit_lnk'               => $this->editContactAction($registration, $attendee),
818
-                'resend_reg_lnk'         => $this->resendRegistrationMessageAction($registration, $attendee),
819
-                'view_txn_lnk'           => $this->viewTransactionAction($registration->transaction()),
820
-                'dl_invoice_lnk'         => $this->viewTransactionInvoiceAction($registration, $attendee),
821
-                'filtered_messages_link' => $this->viewNotificationsAction($registration),
822
-            ],
823
-            $registration,
824
-            $this
825
-        );
826
-
827
-        $content = $this->_action_string(
828
-            implode('', $actions),
829
-            $registration,
830
-            'div',
831
-            'reg-overview-actions ee-list-table-actions'
832
-        );
833
-
834
-        return $this->columnContent('actions', $this->actionsModalMenu($content));
835
-    }
836
-
837
-
838
-    /**
839
-     * @throws EE_Error
840
-     * @throws ReflectionException
841
-     */
842
-    protected function viewRegistrationUrl(EE_Registration $registration): string
843
-    {
844
-        return EE_Admin_Page::add_query_args_and_nonce(
845
-            [
846
-                'action'  => 'view_registration',
847
-                '_REG_ID' => $registration->ID(),
848
-            ],
849
-            REG_ADMIN_URL
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * @throws EE_Error
856
-     * @throws ReflectionException
857
-     */
858
-    protected function viewRegistrationLink(
859
-        EE_Registration $registration,
860
-        string $status
861
-    ): string {
862
-        $attendee      = $registration->attendee();
863
-        $attendee_name = $attendee instanceof EE_Attendee
864
-            ? $attendee->full_name()
865
-            : '';
866
-        return $this->caps_handler->userCanReadRegistration($registration)
867
-            ? '
792
+			$content .= '<span class="row-actions">' . $this->viewTransactionLink($transaction) . '</span>';
793
+		}
794
+		return $this->columnContent('TXN_total', $content, 'end', 'stack');
795
+	}
796
+
797
+
798
+	/**
799
+	 * @param EE_Registration $registration
800
+	 * @return string
801
+	 * @throws EE_Error
802
+	 * @throws InvalidArgumentException
803
+	 * @throws InvalidDataTypeException
804
+	 * @throws InvalidInterfaceException
805
+	 * @throws ReflectionException
806
+	 */
807
+	public function column_actions(EE_Registration $registration): string
808
+	{
809
+		$attendee = $registration->attendee();
810
+		$this->_set_related_details($registration);
811
+
812
+		// Build and filter row actions
813
+		$actions = apply_filters(
814
+			'FHEE__EE_Registrations_List_Table__column_actions__actions',
815
+			[
816
+				'view_lnk'               => $this->viewRegistrationAction($registration),
817
+				'edit_lnk'               => $this->editContactAction($registration, $attendee),
818
+				'resend_reg_lnk'         => $this->resendRegistrationMessageAction($registration, $attendee),
819
+				'view_txn_lnk'           => $this->viewTransactionAction($registration->transaction()),
820
+				'dl_invoice_lnk'         => $this->viewTransactionInvoiceAction($registration, $attendee),
821
+				'filtered_messages_link' => $this->viewNotificationsAction($registration),
822
+			],
823
+			$registration,
824
+			$this
825
+		);
826
+
827
+		$content = $this->_action_string(
828
+			implode('', $actions),
829
+			$registration,
830
+			'div',
831
+			'reg-overview-actions ee-list-table-actions'
832
+		);
833
+
834
+		return $this->columnContent('actions', $this->actionsModalMenu($content));
835
+	}
836
+
837
+
838
+	/**
839
+	 * @throws EE_Error
840
+	 * @throws ReflectionException
841
+	 */
842
+	protected function viewRegistrationUrl(EE_Registration $registration): string
843
+	{
844
+		return EE_Admin_Page::add_query_args_and_nonce(
845
+			[
846
+				'action'  => 'view_registration',
847
+				'_REG_ID' => $registration->ID(),
848
+			],
849
+			REG_ADMIN_URL
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * @throws EE_Error
856
+	 * @throws ReflectionException
857
+	 */
858
+	protected function viewRegistrationLink(
859
+		EE_Registration $registration,
860
+		string $status
861
+	): string {
862
+		$attendee      = $registration->attendee();
863
+		$attendee_name = $attendee instanceof EE_Attendee
864
+			? $attendee->full_name()
865
+			: '';
866
+		return $this->caps_handler->userCanReadRegistration($registration)
867
+			? '
868 868
             <a  href="' . $this->viewRegistrationUrl($registration) . '"
869 869
                 class="row-title ee-status-color--' . $status . ' ee-aria-tooltip"
870 870
                 aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
871 871
             >
872 872
                 ' . $attendee_name . '
873 873
             </a>'
874
-            : $attendee_name;
875
-    }
876
-
877
-
878
-    /**
879
-     * @throws EE_Error
880
-     * @throws ReflectionException
881
-     */
882
-    protected function viewRegistrationAction(EE_Registration $registration): string
883
-    {
884
-        return $this->caps_handler->userCanReadRegistration($registration)
885
-            ? '
874
+			: $attendee_name;
875
+	}
876
+
877
+
878
+	/**
879
+	 * @throws EE_Error
880
+	 * @throws ReflectionException
881
+	 */
882
+	protected function viewRegistrationAction(EE_Registration $registration): string
883
+	{
884
+		return $this->caps_handler->userCanReadRegistration($registration)
885
+			? '
886 886
             <a  href="' . $this->viewRegistrationUrl($registration) . '"
887 887
                 class="ee-aria-tooltip button button--icon-only"
888 888
                 aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
889 889
             >
890 890
                 <span class="dashicons dashicons-clipboard"></span>
891 891
             </a>'
892
-            : '';
893
-    }
894
-
895
-
896
-    protected function editContactAction(EE_Registration $registration, ?EE_Attendee $attendee = null): string
897
-    {
898
-        if ($attendee instanceof EE_Attendee && $this->caps_handler->userCanEditContacts()) {
899
-            $edit_link_url = EE_Admin_Page::add_query_args_and_nonce(
900
-                [
901
-                    'action' => 'edit_attendee',
902
-                    'post'   => $registration->attendee_ID(),
903
-                ],
904
-                REG_ADMIN_URL
905
-            );
906
-            return '
892
+			: '';
893
+	}
894
+
895
+
896
+	protected function editContactAction(EE_Registration $registration, ?EE_Attendee $attendee = null): string
897
+	{
898
+		if ($attendee instanceof EE_Attendee && $this->caps_handler->userCanEditContacts()) {
899
+			$edit_link_url = EE_Admin_Page::add_query_args_and_nonce(
900
+				[
901
+					'action' => 'edit_attendee',
902
+					'post'   => $registration->attendee_ID(),
903
+				],
904
+				REG_ADMIN_URL
905
+			);
906
+			return '
907 907
                 <a href="' . $edit_link_url . '"
908 908
                    aria-label="' . esc_attr__('Edit Contact Details', 'event_espresso') . '"
909 909
                    class="ee-aria-tooltip button button--secondary button--icon-only"
910 910
                 >
911 911
                     <span class="dashicons dashicons-admin-users"></span>
912 912
                 </a>';
913
-        }
914
-        return '';
915
-    }
916
-
917
-
918
-    /**
919
-     * @throws EE_Error
920
-     * @throws ReflectionException
921
-     */
922
-    protected function resendRegistrationMessageAction(
923
-        EE_Registration $registration,
924
-        ?EE_Attendee $attendee = null
925
-    ): string {
926
-        if ($attendee instanceof EE_Attendee && $this->caps_handler->userCanResendMessage($registration)) {
927
-            $resend_reg_link_url = EE_Admin_Page::add_query_args_and_nonce(
928
-                [
929
-                    'action'  => 'resend_registration',
930
-                    '_REG_ID' => $registration->ID(),
931
-                ],
932
-                REG_ADMIN_URL,
933
-                true
934
-            );
935
-            return '
913
+		}
914
+		return '';
915
+	}
916
+
917
+
918
+	/**
919
+	 * @throws EE_Error
920
+	 * @throws ReflectionException
921
+	 */
922
+	protected function resendRegistrationMessageAction(
923
+		EE_Registration $registration,
924
+		?EE_Attendee $attendee = null
925
+	): string {
926
+		if ($attendee instanceof EE_Attendee && $this->caps_handler->userCanResendMessage($registration)) {
927
+			$resend_reg_link_url = EE_Admin_Page::add_query_args_and_nonce(
928
+				[
929
+					'action'  => 'resend_registration',
930
+					'_REG_ID' => $registration->ID(),
931
+				],
932
+				REG_ADMIN_URL,
933
+				true
934
+			);
935
+			return '
936 936
 			    <a href="' . $resend_reg_link_url . '" aria-label="'
937
-                . esc_attr__('Resend Registration Details', 'event_espresso')
938
-                . '" class="ee-aria-tooltip button button--icon-only">
937
+				. esc_attr__('Resend Registration Details', 'event_espresso')
938
+				. '" class="ee-aria-tooltip button button--icon-only">
939 939
 			        <span class="dashicons dashicons-email-alt"></span>
940 940
 			    </a>';
941
-        }
942
-        return '';
943
-    }
944
-
945
-
946
-    /**
947
-     * @param EE_Transaction $transaction
948
-     * @return string
949
-     * @throws EE_Error
950
-     * @throws ReflectionException
951
-     */
952
-    protected function viewTransactionUrl(EE_Transaction $transaction): string
953
-    {
954
-        return EE_Admin_Page::add_query_args_and_nonce(
955
-            [
956
-                'action' => 'view_transaction',
957
-                'TXN_ID' => $transaction->ID(),
958
-            ],
959
-            TXN_ADMIN_URL
960
-        );
961
-    }
962
-
963
-
964
-    /**
965
-     * @param EE_Transaction $transaction
966
-     * @param string         $link_text
967
-     * @return string
968
-     * @throws EE_Error
969
-     * @throws ReflectionException
970
-     * @since 5.0.18.p
971
-     */
972
-    protected function viewTransactionLink(EE_Transaction $transaction, string $link_text = ''): string
973
-    {
974
-        if ($this->caps_handler->userCanViewTransaction()) {
975
-            $link_text = $link_text ?: '<span class="dashicons dashicons-cart"></span> '
976
-                . esc_html__('View Transaction', 'event_espresso');
977
-            return '
941
+		}
942
+		return '';
943
+	}
944
+
945
+
946
+	/**
947
+	 * @param EE_Transaction $transaction
948
+	 * @return string
949
+	 * @throws EE_Error
950
+	 * @throws ReflectionException
951
+	 */
952
+	protected function viewTransactionUrl(EE_Transaction $transaction): string
953
+	{
954
+		return EE_Admin_Page::add_query_args_and_nonce(
955
+			[
956
+				'action' => 'view_transaction',
957
+				'TXN_ID' => $transaction->ID(),
958
+			],
959
+			TXN_ADMIN_URL
960
+		);
961
+	}
962
+
963
+
964
+	/**
965
+	 * @param EE_Transaction $transaction
966
+	 * @param string         $link_text
967
+	 * @return string
968
+	 * @throws EE_Error
969
+	 * @throws ReflectionException
970
+	 * @since 5.0.18.p
971
+	 */
972
+	protected function viewTransactionLink(EE_Transaction $transaction, string $link_text = ''): string
973
+	{
974
+		if ($this->caps_handler->userCanViewTransaction()) {
975
+			$link_text = $link_text ?: '<span class="dashicons dashicons-cart"></span> '
976
+				. esc_html__('View Transaction', 'event_espresso');
977
+			return '
978 978
             <a class="ee-reg-list-txn-link ee-aria-tooltip ee-status-color--' . $transaction->status_ID() . '"
979 979
                 href="' . $this->viewTransactionUrl($transaction) . '"
980 980
                 aria-label="' . esc_attr__('View Transaction', 'event_espresso') . '"
981 981
             >
982 982
                 ' . $link_text . '
983 983
             </a>';
984
-        }
985
-        return $link_text;
986
-    }
987
-
988
-
989
-    /**
990
-     * @param EE_Transaction $transaction
991
-     * @return string
992
-     * @throws EE_Error
993
-     * @throws ReflectionException
994
-     */
995
-    protected function viewTransactionAction(EE_Transaction $transaction): string
996
-    {
997
-        if ($this->caps_handler->userCanViewTransaction()) {
998
-            return '
984
+		}
985
+		return $link_text;
986
+	}
987
+
988
+
989
+	/**
990
+	 * @param EE_Transaction $transaction
991
+	 * @return string
992
+	 * @throws EE_Error
993
+	 * @throws ReflectionException
994
+	 */
995
+	protected function viewTransactionAction(EE_Transaction $transaction): string
996
+	{
997
+		if ($this->caps_handler->userCanViewTransaction()) {
998
+			return '
999 999
                 <a class="ee-aria-tooltip button button--icon-only"
1000 1000
                    href="' . $this->viewTransactionUrl($transaction) . '"
1001 1001
                    aria-label="' . sprintf(
1002
-                    esc_html__('View Transaction Details (%s)', 'event_espresso'),
1003
-                    EEH_Template::pretty_status($transaction->status_ID(), false, 'sentence')
1004
-                ) . '"
1002
+					esc_html__('View Transaction Details (%s)', 'event_espresso'),
1003
+					EEH_Template::pretty_status($transaction->status_ID(), false, 'sentence')
1004
+				) . '"
1005 1005
                 >
1006 1006
                     <span class="dashicons dashicons-cart"></span>
1007 1007
                 </a>';
1008
-        }
1009
-        return '';
1010
-    }
1011
-
1012
-
1013
-    /**
1014
-     * @throws EE_Error
1015
-     * @throws ReflectionException
1016
-     */
1017
-    protected function viewTransactionInvoiceAction(
1018
-        EE_Registration $registration,
1019
-        ?EE_Attendee $attendee = null
1020
-    ): string {
1021
-        // only show invoice link if message type is active.
1022
-        if (
1023
-            $attendee instanceof EE_Attendee
1024
-            && $registration->is_primary_registrant()
1025
-            && EEH_MSG_Template::is_mt_active('invoice')
1026
-        ) {
1027
-            return '
1008
+		}
1009
+		return '';
1010
+	}
1011
+
1012
+
1013
+	/**
1014
+	 * @throws EE_Error
1015
+	 * @throws ReflectionException
1016
+	 */
1017
+	protected function viewTransactionInvoiceAction(
1018
+		EE_Registration $registration,
1019
+		?EE_Attendee $attendee = null
1020
+	): string {
1021
+		// only show invoice link if message type is active.
1022
+		if (
1023
+			$attendee instanceof EE_Attendee
1024
+			&& $registration->is_primary_registrant()
1025
+			&& EEH_MSG_Template::is_mt_active('invoice')
1026
+		) {
1027
+			return '
1028 1028
                 <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso')
1029
-                . '" target="_blank" href="' . $registration->invoice_url() . '" class="ee-aria-tooltip button button--icon-only">
1029
+				. '" target="_blank" href="' . $registration->invoice_url() . '" class="ee-aria-tooltip button button--icon-only">
1030 1030
                     <span class="dashicons dashicons-media-spreadsheet"></span>
1031 1031
                 </a>';
1032
-        }
1033
-        return '';
1034
-    }
1035
-
1036
-
1037
-    /**
1038
-     * @throws ReflectionException
1039
-     * @throws EE_Error
1040
-     */
1041
-    protected function viewNotificationsAction(EE_Registration $registration): string
1042
-    {
1043
-        // message list table link (filtered by REG_ID
1044
-        return $this->caps_handler->userCanReadGlobalMessages()
1045
-            ? EEH_MSG_Template::get_message_action_link(
1046
-                'see_notifications_for',
1047
-                null,
1048
-                ['_REG_ID' => $registration->ID()]
1049
-            )
1050
-            : '';
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * @throws EE_Error
1056
-     * @throws ReflectionException
1057
-     */
1058
-    protected function trashRegistrationLink(
1059
-        EE_Registration $registration,
1060
-        array $url_params
1061
-    ): array {
1062
-        $actions = [];
1063
-        // can't trash what's already trashed
1064
-        if ($this->_view === 'trash') {
1065
-            return $actions;
1066
-        }
1067
-
1068
-        // check caps
1069
-        if (! $this->caps_handler->userCanTrashRegistration($registration)) {
1070
-            return $actions;
1071
-        }
1072
-
1073
-        // don't delete registrations that have payments applied
1074
-        $transaction   = $registration->transaction();
1075
-        $payment_count = $transaction instanceof EE_Transaction
1076
-            ? $transaction->count_related('Payment')
1077
-            : 0;
1078
-
1079
-        if ($payment_count > 0) {
1080
-            return $actions;
1081
-        }
1082
-
1083
-        $url_params['action'] = 'trash_registrations';
1084
-        $trash_link_url       = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1085
-        $actions['trash']     = '
1032
+		}
1033
+		return '';
1034
+	}
1035
+
1036
+
1037
+	/**
1038
+	 * @throws ReflectionException
1039
+	 * @throws EE_Error
1040
+	 */
1041
+	protected function viewNotificationsAction(EE_Registration $registration): string
1042
+	{
1043
+		// message list table link (filtered by REG_ID
1044
+		return $this->caps_handler->userCanReadGlobalMessages()
1045
+			? EEH_MSG_Template::get_message_action_link(
1046
+				'see_notifications_for',
1047
+				null,
1048
+				['_REG_ID' => $registration->ID()]
1049
+			)
1050
+			: '';
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * @throws EE_Error
1056
+	 * @throws ReflectionException
1057
+	 */
1058
+	protected function trashRegistrationLink(
1059
+		EE_Registration $registration,
1060
+		array $url_params
1061
+	): array {
1062
+		$actions = [];
1063
+		// can't trash what's already trashed
1064
+		if ($this->_view === 'trash') {
1065
+			return $actions;
1066
+		}
1067
+
1068
+		// check caps
1069
+		if (! $this->caps_handler->userCanTrashRegistration($registration)) {
1070
+			return $actions;
1071
+		}
1072
+
1073
+		// don't delete registrations that have payments applied
1074
+		$transaction   = $registration->transaction();
1075
+		$payment_count = $transaction instanceof EE_Transaction
1076
+			? $transaction->count_related('Payment')
1077
+			: 0;
1078
+
1079
+		if ($payment_count > 0) {
1080
+			return $actions;
1081
+		}
1082
+
1083
+		$url_params['action'] = 'trash_registrations';
1084
+		$trash_link_url       = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1085
+		$actions['trash']     = '
1086 1086
             <a class="ee-aria-tooltip"
1087 1087
                 href="' . $trash_link_url . '"
1088 1088
                 aria-label="' . esc_attr__('Trash Registration', 'event_espresso') . '"
1089 1089
             >
1090 1090
                 ' . esc_html__('Trash', 'event_espresso') . '
1091 1091
             </a>';
1092
-        return $actions;
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * @throws EE_Error
1098
-     * @throws ReflectionException
1099
-     */
1100
-    protected function restoreRegistrationLink(
1101
-        EE_Registration $registration,
1102
-        array $url_params,
1103
-        array $actions
1104
-    ): array {
1105
-        // can't restore what's not trashed
1106
-        if ($this->_view !== 'trash') {
1107
-            return $actions;
1108
-        }
1109
-
1110
-        // restore registration link
1111
-        if ($this->caps_handler->userCanRestoreRegistration($registration)) {
1112
-            $url_params['action'] = 'restore_registrations';
1113
-            $restore_link_url     = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1114
-            $actions['restore']   = '
1092
+		return $actions;
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * @throws EE_Error
1098
+	 * @throws ReflectionException
1099
+	 */
1100
+	protected function restoreRegistrationLink(
1101
+		EE_Registration $registration,
1102
+		array $url_params,
1103
+		array $actions
1104
+	): array {
1105
+		// can't restore what's not trashed
1106
+		if ($this->_view !== 'trash') {
1107
+			return $actions;
1108
+		}
1109
+
1110
+		// restore registration link
1111
+		if ($this->caps_handler->userCanRestoreRegistration($registration)) {
1112
+			$url_params['action'] = 'restore_registrations';
1113
+			$restore_link_url     = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1114
+			$actions['restore']   = '
1115 1115
                 <a class="ee-aria-tooltip"
1116 1116
                     href="' . $restore_link_url . '"
1117 1117
                     aria-label="' . esc_attr__('Restore Registration', 'event_espresso') . '"
1118 1118
                 >
1119 1119
                     ' . esc_html__('Restore', 'event_espresso') . '
1120 1120
                 </a>';
1121
-        }
1122
-
1123
-        return $actions;
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     * @throws EE_Error
1129
-     * @throws ReflectionException
1130
-     */
1131
-    protected function deleteRegistrationLink(
1132
-        EE_Registration $registration,
1133
-        array $url_params,
1134
-        array $actions
1135
-    ): array {
1136
-        if ($this->_view === 'trash' && $this->caps_handler->userCanDeleteRegistration($registration)) {
1137
-            $url_params['action'] = 'delete_registrations';
1138
-            $delete_link_url      = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1139
-            $actions['delete']    = '
1121
+		}
1122
+
1123
+		return $actions;
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 * @throws EE_Error
1129
+	 * @throws ReflectionException
1130
+	 */
1131
+	protected function deleteRegistrationLink(
1132
+		EE_Registration $registration,
1133
+		array $url_params,
1134
+		array $actions
1135
+	): array {
1136
+		if ($this->_view === 'trash' && $this->caps_handler->userCanDeleteRegistration($registration)) {
1137
+			$url_params['action'] = 'delete_registrations';
1138
+			$delete_link_url      = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1139
+			$actions['delete']    = '
1140 1140
                 <a class="ee-aria-tooltip"
1141 1141
                     href="' . $delete_link_url . '"
1142 1142
                     aria-label="' . esc_attr__('Delete Registration Permanently', 'event_espresso') . '"
1143 1143
                 >
1144 1144
                     ' . esc_html__('Delete', 'event_espresso') . '
1145 1145
                 </a>';
1146
-        }
1147
-        return $actions;
1148
-    }
1149
-
1150
-
1151
-    protected function editEventLink(EE_Registration $registration): string
1152
-    {
1153
-        $EVT_ID     = $registration->event_ID();
1154
-        $event_name = $this->eventName($registration);
1155
-        if (! $EVT_ID || ! $this->caps_handler->userCanEditEvent($EVT_ID)) {
1156
-            return $event_name;
1157
-        }
1158
-        $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
1159
-            ['action' => 'edit', 'post' => $EVT_ID],
1160
-            EVENTS_ADMIN_URL
1161
-        );
1162
-        return '
1146
+		}
1147
+		return $actions;
1148
+	}
1149
+
1150
+
1151
+	protected function editEventLink(EE_Registration $registration): string
1152
+	{
1153
+		$EVT_ID     = $registration->event_ID();
1154
+		$event_name = $this->eventName($registration);
1155
+		if (! $EVT_ID || ! $this->caps_handler->userCanEditEvent($EVT_ID)) {
1156
+			return $event_name;
1157
+		}
1158
+		$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
1159
+			['action' => 'edit', 'post' => $EVT_ID],
1160
+			EVENTS_ADMIN_URL
1161
+		);
1162
+		return '
1163 1163
             <a class="ee-aria-tooltip ee-status-color--' . $this->_event_details['status'] . '"
1164 1164
                 href="' . $edit_event_url . '"
1165 1165
                 aria-label="' . esc_attr($this->_event_details['title_attr']) . '"
1166 1166
             >
1167 1167
                 ' . $event_name . '
1168 1168
             </a>';
1169
-    }
1169
+	}
1170 1170
 
1171 1171
 
1172
-    protected function eventName(EE_Registration $registration): string
1173
-    {
1174
-        $event_name = $registration->event_name();
1175
-        $event_name = $event_name ?: esc_html__("No Associated Event", 'event_espresso');
1176
-        return wp_trim_words($event_name, 30, '...');
1177
-    }
1172
+	protected function eventName(EE_Registration $registration): string
1173
+	{
1174
+		$event_name = $registration->event_name();
1175
+		$event_name = $event_name ?: esc_html__("No Associated Event", 'event_espresso');
1176
+		return wp_trim_words($event_name, 30, '...');
1177
+	}
1178 1178
 
1179 1179
 
1180
-    protected function eventFilterLink(EE_Registration $registration): string
1181
-    {
1182
-        $event_filter_url = EE_Admin_Page::add_query_args_and_nonce(
1183
-            ['event_id' => $registration->event_ID()],
1184
-            REG_ADMIN_URL
1185
-        );
1186
-        return '
1180
+	protected function eventFilterLink(EE_Registration $registration): string
1181
+	{
1182
+		$event_filter_url = EE_Admin_Page::add_query_args_and_nonce(
1183
+			['event_id' => $registration->event_ID()],
1184
+			REG_ADMIN_URL
1185
+		);
1186
+		return '
1187 1187
             <a  class="ee-aria-tooltip ee-event-filter-link"
1188 1188
                 href="' . $event_filter_url . '"
1189 1189
                 aria-label="' . sprintf(
1190
-                    esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
1191
-                    $this->eventName($registration)
1192
-                ) . '"
1190
+					esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
1191
+					$this->eventName($registration)
1192
+				) . '"
1193 1193
             >
1194 1194
                 <span class="dashicons dashicons-groups dashicons--small"></span>'
1195
-                . esc_html__('View Registrations', 'event_espresso') . '
1195
+				. esc_html__('View Registrations', 'event_espresso') . '
1196 1196
             </a>';
1197
-    }
1198
-
1199
-
1200
-    /**
1201
-     * @param EE_Ticket $ticket
1202
-     * @return string
1203
-     * @throws EE_Error
1204
-     * @throws ReflectionException
1205
-     * @since 5.0.18.p
1206
-     */
1207
-    protected function ticketName(EE_Ticket $ticket): string
1208
-    {
1209
-        return '<span class="TKT_name ee-status-color--' . $ticket->ticket_status() . '">' . $ticket->name() . '</span>';
1210
-    }
1211
-
1212
-
1213
-    /**
1214
-     * @param EE_Ticket $ticket
1215
-     * @return string
1216
-     * @throws EE_Error
1217
-     * @throws ReflectionException
1218
-     * @since 5.0.18.p
1219
-     */
1220
-    protected function ticketFilterLink(EE_Ticket $ticket): string
1221
-    {
1222
-        $ticket_filter_url = EE_Admin_Page::add_query_args_and_nonce(['ticket_id' => $ticket->ID()], REG_ADMIN_URL);
1223
-        return '
1197
+	}
1198
+
1199
+
1200
+	/**
1201
+	 * @param EE_Ticket $ticket
1202
+	 * @return string
1203
+	 * @throws EE_Error
1204
+	 * @throws ReflectionException
1205
+	 * @since 5.0.18.p
1206
+	 */
1207
+	protected function ticketName(EE_Ticket $ticket): string
1208
+	{
1209
+		return '<span class="TKT_name ee-status-color--' . $ticket->ticket_status() . '">' . $ticket->name() . '</span>';
1210
+	}
1211
+
1212
+
1213
+	/**
1214
+	 * @param EE_Ticket $ticket
1215
+	 * @return string
1216
+	 * @throws EE_Error
1217
+	 * @throws ReflectionException
1218
+	 * @since 5.0.18.p
1219
+	 */
1220
+	protected function ticketFilterLink(EE_Ticket $ticket): string
1221
+	{
1222
+		$ticket_filter_url = EE_Admin_Page::add_query_args_and_nonce(['ticket_id' => $ticket->ID()], REG_ADMIN_URL);
1223
+		return '
1224 1224
             <a  class="ee-aria-tooltip ee-ticket-filter-link"
1225 1225
                 href="' . $ticket_filter_url . '"
1226 1226
                 aria-label="' . sprintf(
1227
-                esc_attr__('Filter this list to only show registrations for ticket %s', 'event_espresso'),
1228
-                $ticket->name()
1229
-            ) . '"
1227
+				esc_attr__('Filter this list to only show registrations for ticket %s', 'event_espresso'),
1228
+				$ticket->name()
1229
+			) . '"
1230 1230
             >
1231 1231
                 <span class="dashicons dashicons-groups dashicons--small"></span>'
1232
-                . esc_html__('View Registrations', 'event_espresso') . '
1232
+				. esc_html__('View Registrations', 'event_espresso') . '
1233 1233
             </a>';
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     * @param EE_Registration $registration
1239
-     * @return string
1240
-     * @throws EE_Error
1241
-     * @throws ReflectionException
1242
-     * @deprecated 5.0.18.p
1243
-     */
1244
-    public function column_TXN_paid(EE_Registration $registration): string
1245
-    {
1246
-        $transaction = $registration->transaction();
1247
-        $content = $transaction->pretty_paid();
1248
-        if ($transaction->paid() >= $transaction->total()) {
1249
-            $content .= '<span class="dashicons dashicons-yes green-icon"></span>';
1250
-        }
1251
-        $content .= $this->viewTransactionLink($transaction);
1252
-        return $this->columnContent('TXN_paid', $content, 'end');
1253
-    }
1254
-
1255
-
1256
-    /**
1257
-     * @param EE_Registration $registration
1258
-     * @return string
1259
-     * @throws EE_Error
1260
-     * @throws ReflectionException
1261
-     * @deprecated 5.0.18.p
1262
-     */
1263
-    public function column_PRC_amount(EE_Registration $registration): string
1264
-    {
1265
-        $ticket = $registration->ticket();
1266
-
1267
-        $content = $this->EVT_ID && $ticket instanceof EE_Ticket
1268
-            ? '<div class="TKT_name">' . $ticket->name() . '</div>'
1269
-            : '';
1270
-
1271
-        $payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
1272
-        $content        .= $registration->final_price() > 0
1273
-            ? '<span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 * @param EE_Registration $registration
1239
+	 * @return string
1240
+	 * @throws EE_Error
1241
+	 * @throws ReflectionException
1242
+	 * @deprecated 5.0.18.p
1243
+	 */
1244
+	public function column_TXN_paid(EE_Registration $registration): string
1245
+	{
1246
+		$transaction = $registration->transaction();
1247
+		$content = $transaction->pretty_paid();
1248
+		if ($transaction->paid() >= $transaction->total()) {
1249
+			$content .= '<span class="dashicons dashicons-yes green-icon"></span>';
1250
+		}
1251
+		$content .= $this->viewTransactionLink($transaction);
1252
+		return $this->columnContent('TXN_paid', $content, 'end');
1253
+	}
1254
+
1255
+
1256
+	/**
1257
+	 * @param EE_Registration $registration
1258
+	 * @return string
1259
+	 * @throws EE_Error
1260
+	 * @throws ReflectionException
1261
+	 * @deprecated 5.0.18.p
1262
+	 */
1263
+	public function column_PRC_amount(EE_Registration $registration): string
1264
+	{
1265
+		$ticket = $registration->ticket();
1266
+
1267
+		$content = $this->EVT_ID && $ticket instanceof EE_Ticket
1268
+			? '<div class="TKT_name">' . $ticket->name() . '</div>'
1269
+			: '';
1270
+
1271
+		$payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
1272
+		$content        .= $registration->final_price() > 0
1273
+			? '<span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
1274 1274
                 ' . $registration->pretty_final_price() . '
1275 1275
                </span>'
1276
-            // free event
1277
-            : '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
1276
+			// free event
1277
+			: '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
1278 1278
 
1279
-        return $this->columnContent('PRC_amount', $content, 'end');
1280
-    }
1279
+		return $this->columnContent('PRC_amount', $content, 'end');
1280
+	}
1281 1281
 }
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         ];
85 85
         foreach ($filters as $filter_key => $filter_value) {
86 86
             if ($filter_value) {
87
-                $this->filters[ $filter_key ] = $filter_value;
87
+                $this->filters[$filter_key] = $filter_value;
88 88
             }
89 89
         }
90 90
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         if ($admin_page instanceof Registrations_Admin_Page) {
109 109
             foreach ($admin_page->get_views() as $view_details) {
110 110
                 foreach ($this->filters as $filter_key => $filter_value) {
111
-                    $extra_query_args[ $view_details['slug'] ][ $filter_key ] = $filter_value;
111
+                    $extra_query_args[$view_details['slug']][$filter_key] = $filter_value;
112 112
                 }
113 113
             }
114 114
         }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
         $this->_primary_column   = 'id';
185 185
         $this->_sortable_columns = [
186
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
186
+            '_REG_date'     => ['_REG_date' => true], // true means its already sorted
187 187
             /**
188 188
              * Allows users to change the default sort if they wish.
189 189
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
             'DTT_EVT_start' => ['DTT_EVT_start' => false],
201 201
             'id'            => ['REG_ID' => false],
202 202
         ];
203
-        $this->_hidden_columns   = [];
203
+        $this->_hidden_columns = [];
204 204
 
205 205
         $csv_report = RegistrationsCsvReportParams::getRequestParams(
206 206
             $this->getReturnUrl(),
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             $this->EVT_ID,
209 209
             $this->DTT_ID
210 210
         );
211
-        if (! empty($csv_report)) {
211
+        if ( ! empty($csv_report)) {
212 212
             $this->_bottom_buttons['csv_reg_report'] = $csv_report;
213 213
         }
214 214
     }
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
             );
305 305
         }
306 306
         foreach ($this->filters as $filter_key => $filter_value) {
307
-            $filters[] = EEH_Form_Fields::hidden_input($filter_key, $filter_value, 'reg_' . $filter_key);
307
+            $filters[] = EEH_Form_Fields::hidden_input($filter_key, $filter_value, 'reg_'.$filter_key);
308 308
         }
309 309
         return $filters;
310 310
     }
@@ -459,10 +459,10 @@  discard block
 block discarded – undo
459 459
         $transaction   = $item->transaction();
460 460
         $payment_count = $transaction->count_related('Payment');
461 461
 
462
-        $content = '<input type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />';
462
+        $content = '<input type="checkbox" name="_REG_ID[]" value="'.$REG_ID.'" />';
463 463
         $content .= $payment_count > 0 || ! $this->caps_handler->userCanEditRegistration($item)
464 464
             ? '<span class="ee-locked-entity dashicons dashicons-lock ee-aria-tooltip ee-aria-tooltip--big-box"
465
-                    aria-label="' . $this->lockedRegMessage() . '"></span>'
465
+                    aria-label="' . $this->lockedRegMessage().'"></span>'
466 466
             : '';
467 467
         return $this->columnContent('cb', $content, 'center');
468 468
     }
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
      */
489 489
     public function column_id(EE_Registration $registration): string
490 490
     {
491
-        $content = '<span class="ee-entity-id">' . $registration->ID() . '</span>';
491
+        $content = '<span class="ee-entity-id">'.$registration->ID().'</span>';
492 492
         $content .= '<span class="show-on-mobile-view-only">';
493 493
         $content .= $this->column_ATT_fname($registration, false);
494 494
         $content .= '</span>';
@@ -518,23 +518,23 @@  discard block
 block discarded – undo
518 518
                 esc_html__('(%1$s / %2$s)', 'event_espresso'),
519 519
                 $registration->count(),
520 520
                 $registration->group_size()
521
-            ) . '
521
+            ).'
522 522
             </span >';
523 523
 
524 524
         $content = '
525 525
         <div class="ee-layout-row">
526
-            <span aria-label="' . $pretty_status . '"
527
-                  class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"
526
+            <span aria-label="' . $pretty_status.'"
527
+                  class="ee-status-dot ee-status-bg--' . $status.' ee-aria-tooltip"
528 528
             ></span>
529 529
             ' . $this->viewRegistrationLink($registration, $status)
530 530
             . $prime_reg_star
531
-            . $group_count . '
531
+            . $group_count.'
532 532
             <span class="spacer"></span>
533 533
             <span>
534 534
                 ' . sprintf(
535 535
                 esc_html__('Reg Code: %s', 'event_espresso'),
536 536
                 $registration->get('REG_code')
537
-            ) . '
537
+            ).'
538 538
             </span>
539 539
         </div>';
540 540
 
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
         $actions['event_filter'] = $this->eventFilterLink($registration);
589 589
         return $this->columnContent(
590 590
             'event_name',
591
-            $edit_event . $this->row_actions($actions)
591
+            $edit_event.$this->row_actions($actions)
592 592
         );
593 593
     }
594 594
 
@@ -630,19 +630,19 @@  discard block
 block discarded – undo
630 630
     {
631 631
         // get first item for initial visibility
632 632
         $content = (string) array_shift($datetime_strings);
633
-        if (! empty($datetime_strings)) {
633
+        if ( ! empty($datetime_strings)) {
634 634
             $content .= '
635 635
                 <div class="ee-registration-event-datetimes-container-wrap">
636 636
                     <div class="ee-registration-event-datetimes-container__control">
637
-                        <span class="tiny-text">' . esc_html__('Click to view additional dates', 'event_espresso') . '</span>
638
-                        <button aria-label="' . esc_attr__('Click to view additional dates', 'event_espresso') . '"
637
+                        <span class="tiny-text">' . esc_html__('Click to view additional dates', 'event_espresso').'</span>
638
+                        <button aria-label="' . esc_attr__('Click to view additional dates', 'event_espresso').'"
639 639
                               class="ee-aria-tooltip button button--secondary button--tiny button--icon-only ee-js ee-more-datetimes-toggle"
640 640
                         >
641 641
                            <span class="dashicons dashicons-admin-collapse"></span>
642 642
                         </button>
643 643
                     </div>
644 644
                     <div class="ee-registration-event-datetimes-container more-items hidden">
645
-                        ' . implode("", $datetime_strings) . '
645
+                        ' . implode("", $datetime_strings).'
646 646
                     </div>
647 647
                 </div>';
648 648
         }
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
         $actions['ticket_filter'] = $this->ticketFilterLink($ticket);
700 700
         return $this->columnContent(
701 701
             'REG_ticket',
702
-            $ticket_name . $this->row_actions($actions)
702
+            $ticket_name.$this->row_actions($actions)
703 703
         );
704 704
     }
705 705
 
@@ -714,9 +714,9 @@  discard block
 block discarded – undo
714 714
     {
715 715
         // free ticket?
716 716
         $content = $registration->final_price() > 0
717
-            ? '<span class="reg-overview-paid-event-spn">' . $registration->pretty_final_price() . '</span>'
718
-            : '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
719
-        return $this->columnContent( '_REG_final_price', $content, 'end' );
717
+            ? '<span class="reg-overview-paid-event-spn">'.$registration->pretty_final_price().'</span>'
718
+            : '<span class="reg-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>';
719
+        return $this->columnContent('_REG_final_price', $content, 'end');
720 720
     }
721 721
 
722 722
 
@@ -748,10 +748,10 @@  discard block
 block discarded – undo
748 748
             $payment_status = EEM_Transaction::overpaid_status_code;
749 749
         }
750 750
         $content .= '
751
-            <span class="reg-overview-paid-event-spn ee-aria-tooltip ee-status-color--' . $payment_status . '"
752
-                  aria-label="' . $label . '"
751
+            <span class="reg-overview-paid-event-spn ee-aria-tooltip ee-status-color--' . $payment_status.'"
752
+                  aria-label="' . $label.'"
753 753
             >
754
-                ' . $icon . $registration->pretty_paid('no_currency_code') . '
754
+                ' . $icon.$registration->pretty_paid('no_currency_code').'
755 755
             </span>
756 756
             </span>';
757 757
         if ($registration->paid() > 0) {
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
                 ' . sprintf(
761 761
                         esc_html__('...via %s', 'event_espresso'),
762 762
                         $payment_method_name
763
-                    ) . '
763
+                    ).'
764 764
             </span>';
765 765
         }
766 766
         return $this->columnContent('_REG_paid', $content, 'end', 'stack');
@@ -779,17 +779,17 @@  discard block
 block discarded – undo
779 779
      */
780 780
     public function column_TXN_total(EE_Registration $registration): string
781 781
     {
782
-        $content      = '';
782
+        $content = '';
783 783
         if ($registration->count() === 1) {
784 784
             $transaction = $registration->transaction();
785 785
             $content     = '
786
-            <span class="ee-status-color--' . $transaction->status_ID() . '">
787
-                ' . $transaction->pretty_paid('no_currency_code') . '
786
+            <span class="ee-status-color--' . $transaction->status_ID().'">
787
+                ' . $transaction->pretty_paid('no_currency_code').'
788 788
                 <span class="separator">/</span>
789
-                ' . $transaction->pretty_total('no_currency_code') . '
789
+                ' . $transaction->pretty_total('no_currency_code').'
790 790
             </span>';
791 791
 
792
-            $content .= '<span class="row-actions">' . $this->viewTransactionLink($transaction) . '</span>';
792
+            $content .= '<span class="row-actions">'.$this->viewTransactionLink($transaction).'</span>';
793 793
         }
794 794
         return $this->columnContent('TXN_total', $content, 'end', 'stack');
795 795
     }
@@ -865,11 +865,11 @@  discard block
 block discarded – undo
865 865
             : '';
866 866
         return $this->caps_handler->userCanReadRegistration($registration)
867 867
             ? '
868
-            <a  href="' . $this->viewRegistrationUrl($registration) . '"
869
-                class="row-title ee-status-color--' . $status . ' ee-aria-tooltip"
870
-                aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
868
+            <a  href="' . $this->viewRegistrationUrl($registration).'"
869
+                class="row-title ee-status-color--' . $status.' ee-aria-tooltip"
870
+                aria-label="' . esc_attr__('View Registration Details', 'event_espresso').'"
871 871
             >
872
-                ' . $attendee_name . '
872
+                ' . $attendee_name.'
873 873
             </a>'
874 874
             : $attendee_name;
875 875
     }
@@ -883,9 +883,9 @@  discard block
 block discarded – undo
883 883
     {
884 884
         return $this->caps_handler->userCanReadRegistration($registration)
885 885
             ? '
886
-            <a  href="' . $this->viewRegistrationUrl($registration) . '"
886
+            <a  href="' . $this->viewRegistrationUrl($registration).'"
887 887
                 class="ee-aria-tooltip button button--icon-only"
888
-                aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
888
+                aria-label="' . esc_attr__('View Registration Details', 'event_espresso').'"
889 889
             >
890 890
                 <span class="dashicons dashicons-clipboard"></span>
891 891
             </a>'
@@ -904,8 +904,8 @@  discard block
 block discarded – undo
904 904
                 REG_ADMIN_URL
905 905
             );
906 906
             return '
907
-                <a href="' . $edit_link_url . '"
908
-                   aria-label="' . esc_attr__('Edit Contact Details', 'event_espresso') . '"
907
+                <a href="' . $edit_link_url.'"
908
+                   aria-label="' . esc_attr__('Edit Contact Details', 'event_espresso').'"
909 909
                    class="ee-aria-tooltip button button--secondary button--icon-only"
910 910
                 >
911 911
                     <span class="dashicons dashicons-admin-users"></span>
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
                 true
934 934
             );
935 935
             return '
936
-			    <a href="' . $resend_reg_link_url . '" aria-label="'
936
+			    <a href="' . $resend_reg_link_url.'" aria-label="'
937 937
                 . esc_attr__('Resend Registration Details', 'event_espresso')
938 938
                 . '" class="ee-aria-tooltip button button--icon-only">
939 939
 			        <span class="dashicons dashicons-email-alt"></span>
@@ -975,11 +975,11 @@  discard block
 block discarded – undo
975 975
             $link_text = $link_text ?: '<span class="dashicons dashicons-cart"></span> '
976 976
                 . esc_html__('View Transaction', 'event_espresso');
977 977
             return '
978
-            <a class="ee-reg-list-txn-link ee-aria-tooltip ee-status-color--' . $transaction->status_ID() . '"
979
-                href="' . $this->viewTransactionUrl($transaction) . '"
980
-                aria-label="' . esc_attr__('View Transaction', 'event_espresso') . '"
978
+            <a class="ee-reg-list-txn-link ee-aria-tooltip ee-status-color--' . $transaction->status_ID().'"
979
+                href="' . $this->viewTransactionUrl($transaction).'"
980
+                aria-label="' . esc_attr__('View Transaction', 'event_espresso').'"
981 981
             >
982
-                ' . $link_text . '
982
+                ' . $link_text.'
983 983
             </a>';
984 984
         }
985 985
         return $link_text;
@@ -997,11 +997,11 @@  discard block
 block discarded – undo
997 997
         if ($this->caps_handler->userCanViewTransaction()) {
998 998
             return '
999 999
                 <a class="ee-aria-tooltip button button--icon-only"
1000
-                   href="' . $this->viewTransactionUrl($transaction) . '"
1000
+                   href="' . $this->viewTransactionUrl($transaction).'"
1001 1001
                    aria-label="' . sprintf(
1002 1002
                     esc_html__('View Transaction Details (%s)', 'event_espresso'),
1003 1003
                     EEH_Template::pretty_status($transaction->status_ID(), false, 'sentence')
1004
-                ) . '"
1004
+                ).'"
1005 1005
                 >
1006 1006
                     <span class="dashicons dashicons-cart"></span>
1007 1007
                 </a>';
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
         ) {
1027 1027
             return '
1028 1028
                 <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso')
1029
-                . '" target="_blank" href="' . $registration->invoice_url() . '" class="ee-aria-tooltip button button--icon-only">
1029
+                . '" target="_blank" href="'.$registration->invoice_url().'" class="ee-aria-tooltip button button--icon-only">
1030 1030
                     <span class="dashicons dashicons-media-spreadsheet"></span>
1031 1031
                 </a>';
1032 1032
         }
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
         }
1067 1067
 
1068 1068
         // check caps
1069
-        if (! $this->caps_handler->userCanTrashRegistration($registration)) {
1069
+        if ( ! $this->caps_handler->userCanTrashRegistration($registration)) {
1070 1070
             return $actions;
1071 1071
         }
1072 1072
 
@@ -1084,10 +1084,10 @@  discard block
 block discarded – undo
1084 1084
         $trash_link_url       = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1085 1085
         $actions['trash']     = '
1086 1086
             <a class="ee-aria-tooltip"
1087
-                href="' . $trash_link_url . '"
1088
-                aria-label="' . esc_attr__('Trash Registration', 'event_espresso') . '"
1087
+                href="' . $trash_link_url.'"
1088
+                aria-label="' . esc_attr__('Trash Registration', 'event_espresso').'"
1089 1089
             >
1090
-                ' . esc_html__('Trash', 'event_espresso') . '
1090
+                ' . esc_html__('Trash', 'event_espresso').'
1091 1091
             </a>';
1092 1092
         return $actions;
1093 1093
     }
@@ -1113,10 +1113,10 @@  discard block
 block discarded – undo
1113 1113
             $restore_link_url     = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1114 1114
             $actions['restore']   = '
1115 1115
                 <a class="ee-aria-tooltip"
1116
-                    href="' . $restore_link_url . '"
1117
-                    aria-label="' . esc_attr__('Restore Registration', 'event_espresso') . '"
1116
+                    href="' . $restore_link_url.'"
1117
+                    aria-label="' . esc_attr__('Restore Registration', 'event_espresso').'"
1118 1118
                 >
1119
-                    ' . esc_html__('Restore', 'event_espresso') . '
1119
+                    ' . esc_html__('Restore', 'event_espresso').'
1120 1120
                 </a>';
1121 1121
         }
1122 1122
 
@@ -1138,10 +1138,10 @@  discard block
 block discarded – undo
1138 1138
             $delete_link_url      = EE_Admin_Page::add_query_args_and_nonce($url_params, REG_ADMIN_URL);
1139 1139
             $actions['delete']    = '
1140 1140
                 <a class="ee-aria-tooltip"
1141
-                    href="' . $delete_link_url . '"
1142
-                    aria-label="' . esc_attr__('Delete Registration Permanently', 'event_espresso') . '"
1141
+                    href="' . $delete_link_url.'"
1142
+                    aria-label="' . esc_attr__('Delete Registration Permanently', 'event_espresso').'"
1143 1143
                 >
1144
-                    ' . esc_html__('Delete', 'event_espresso') . '
1144
+                    ' . esc_html__('Delete', 'event_espresso').'
1145 1145
                 </a>';
1146 1146
         }
1147 1147
         return $actions;
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
     {
1153 1153
         $EVT_ID     = $registration->event_ID();
1154 1154
         $event_name = $this->eventName($registration);
1155
-        if (! $EVT_ID || ! $this->caps_handler->userCanEditEvent($EVT_ID)) {
1155
+        if ( ! $EVT_ID || ! $this->caps_handler->userCanEditEvent($EVT_ID)) {
1156 1156
             return $event_name;
1157 1157
         }
1158 1158
         $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
@@ -1160,11 +1160,11 @@  discard block
 block discarded – undo
1160 1160
             EVENTS_ADMIN_URL
1161 1161
         );
1162 1162
         return '
1163
-            <a class="ee-aria-tooltip ee-status-color--' . $this->_event_details['status'] . '"
1164
-                href="' . $edit_event_url . '"
1165
-                aria-label="' . esc_attr($this->_event_details['title_attr']) . '"
1163
+            <a class="ee-aria-tooltip ee-status-color--' . $this->_event_details['status'].'"
1164
+                href="' . $edit_event_url.'"
1165
+                aria-label="' . esc_attr($this->_event_details['title_attr']).'"
1166 1166
             >
1167
-                ' . $event_name . '
1167
+                ' . $event_name.'
1168 1168
             </a>';
1169 1169
     }
1170 1170
 
@@ -1185,14 +1185,14 @@  discard block
 block discarded – undo
1185 1185
         );
1186 1186
         return '
1187 1187
             <a  class="ee-aria-tooltip ee-event-filter-link"
1188
-                href="' . $event_filter_url . '"
1188
+                href="' . $event_filter_url.'"
1189 1189
                 aria-label="' . sprintf(
1190 1190
                     esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
1191 1191
                     $this->eventName($registration)
1192
-                ) . '"
1192
+                ).'"
1193 1193
             >
1194 1194
                 <span class="dashicons dashicons-groups dashicons--small"></span>'
1195
-                . esc_html__('View Registrations', 'event_espresso') . '
1195
+                . esc_html__('View Registrations', 'event_espresso').'
1196 1196
             </a>';
1197 1197
     }
1198 1198
 
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
      */
1207 1207
     protected function ticketName(EE_Ticket $ticket): string
1208 1208
     {
1209
-        return '<span class="TKT_name ee-status-color--' . $ticket->ticket_status() . '">' . $ticket->name() . '</span>';
1209
+        return '<span class="TKT_name ee-status-color--'.$ticket->ticket_status().'">'.$ticket->name().'</span>';
1210 1210
     }
1211 1211
 
1212 1212
 
@@ -1222,14 +1222,14 @@  discard block
 block discarded – undo
1222 1222
         $ticket_filter_url = EE_Admin_Page::add_query_args_and_nonce(['ticket_id' => $ticket->ID()], REG_ADMIN_URL);
1223 1223
         return '
1224 1224
             <a  class="ee-aria-tooltip ee-ticket-filter-link"
1225
-                href="' . $ticket_filter_url . '"
1225
+                href="' . $ticket_filter_url.'"
1226 1226
                 aria-label="' . sprintf(
1227 1227
                 esc_attr__('Filter this list to only show registrations for ticket %s', 'event_espresso'),
1228 1228
                 $ticket->name()
1229
-            ) . '"
1229
+            ).'"
1230 1230
             >
1231 1231
                 <span class="dashicons dashicons-groups dashicons--small"></span>'
1232
-                . esc_html__('View Registrations', 'event_espresso') . '
1232
+                . esc_html__('View Registrations', 'event_espresso').'
1233 1233
             </a>';
1234 1234
     }
1235 1235
 
@@ -1265,16 +1265,16 @@  discard block
 block discarded – undo
1265 1265
         $ticket = $registration->ticket();
1266 1266
 
1267 1267
         $content = $this->EVT_ID && $ticket instanceof EE_Ticket
1268
-            ? '<div class="TKT_name">' . $ticket->name() . '</div>'
1268
+            ? '<div class="TKT_name">'.$ticket->name().'</div>'
1269 1269
             : '';
1270 1270
 
1271 1271
         $payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
1272
-        $content        .= $registration->final_price() > 0
1273
-            ? '<span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
1274
-                ' . $registration->pretty_final_price() . '
1272
+        $content .= $registration->final_price() > 0
1273
+            ? '<span class="reg-overview-paid-event-spn ee-status-color--'.$payment_status.'">
1274
+                ' . $registration->pretty_final_price().'
1275 1275
                </span>'
1276 1276
             // free event
1277
-            : '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
1277
+            : '<span class="reg-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>';
1278 1278
 
1279 1279
         return $this->columnContent('PRC_amount', $content, 'end');
1280 1280
     }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2943 added lines, -2943 removed lines patch added patch discarded remove patch
@@ -19,2950 +19,2950 @@
 block discarded – undo
19 19
  */
20 20
 class Events_Admin_Page extends EE_Admin_Page_CPT
21 21
 {
22
-    /**
23
-     * primary key for the event model
24
-     */
25
-    private int $EVT_ID = 0;
26
-
27
-    /**
28
-     * This will hold the event object for event_details screen.
29
-     *
30
-     * @var EE_Event|null $_event
31
-     */
32
-    protected ?EE_Event $_event = null;
33
-
34
-    /**
35
-     * This will hold the category object for category_details screen.
36
-     */
37
-    protected ?stdClass $_category = null;
38
-
39
-    protected ?EEM_Event $_event_model = null;
40
-
41
-    /**
42
-     * @var EE_Event|EE_CPT_Base|null $_cpt_model_obj
43
-     */
44
-    protected $_cpt_model_obj;
45
-
46
-    protected ?NodeGroupDao $model_obj_node_group_persister = null;
47
-
48
-    protected ?AdvancedEditorAdminFormSection $advanced_editor_admin_form = null;
49
-
50
-
51
-    /**
52
-     * Initialize page props for this admin page group.
53
-     */
54
-    protected function _init_page_props()
55
-    {
56
-        // is there a evt_id in the request?
57
-        $this->EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT);
58
-        $this->EVT_ID = $this->request->getRequestParam('post', $this->EVT_ID, DataType::INT);
59
-        $this->EVT_ID = $this->request->getRequestParam('post_ID', $this->EVT_ID, DataType::INT);
60
-
61
-        $this->page_slug        = EVENTS_PG_SLUG;
62
-        $this->page_label       = EVENTS_LABEL;
63
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
64
-        $this->_admin_base_path = EVENTS_ADMIN;
65
-        $this->_cpt_model_names = [
66
-            'create_new' => 'EEM_Event',
67
-            'edit'       => 'EEM_Event',
68
-        ];
69
-        $this->_cpt_edit_routes = [
70
-            'espresso_events' => 'edit',
71
-        ];
72
-        add_action(
73
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
74
-            [$this, 'verify_event_edit'],
75
-            10,
76
-            2
77
-        );
78
-    }
79
-
80
-
81
-    /**
82
-     * Sets the ajax hooks used for this admin page group.
83
-     */
84
-    protected function _ajax_hooks()
85
-    {
86
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
87
-    }
88
-
89
-
90
-    /**
91
-     * Sets the page properties for this admin page group.
92
-     */
93
-    protected function _define_page_props()
94
-    {
95
-        $this->_admin_page_title = EVENTS_LABEL;
96
-        $this->_labels           = [
97
-            'buttons'      => [
98
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
99
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
100
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
101
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
102
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
103
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
104
-            ],
105
-            'editor_title' => [
106
-                'espresso_events' => esc_html__('Edit Event', 'event_espresso'),
107
-            ],
108
-            'publishbox'   => [
109
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
110
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
111
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
112
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
113
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
114
-            ],
115
-        ];
116
-    }
117
-
118
-
119
-    /**
120
-     * Sets the page routes property for this admin page group.
121
-     */
122
-    protected function _set_page_routes()
123
-    {
124
-        $this->_page_routes = [
125
-            'default'                       => [
126
-                'func'       => [$this, '_events_overview_list_table'],
127
-                'capability' => 'ee_read_events',
128
-            ],
129
-            'create_new'                    => [
130
-                'func'       => [$this, '_create_new_cpt_item'],
131
-                'capability' => 'ee_edit_events',
132
-            ],
133
-            'edit'                          => [
134
-                'func'       => [$this, '_edit_cpt_item'],
135
-                'capability' => 'ee_edit_event',
136
-                'obj_id'     => $this->EVT_ID,
137
-            ],
138
-            'copy_event'                    => [
139
-                'func'       => [$this, '_copy_events'],
140
-                'capability' => 'ee_edit_event',
141
-                'obj_id'     => $this->EVT_ID,
142
-                'noheader'   => true,
143
-            ],
144
-            'trash_event'                   => [
145
-                'func'       => [$this, '_trash_or_restore_event'],
146
-                'args'       => ['event_status' => 'trash'],
147
-                'capability' => 'ee_delete_event',
148
-                'obj_id'     => $this->EVT_ID,
149
-                'noheader'   => true,
150
-            ],
151
-            'trash_events'                  => [
152
-                'func'       => [$this, '_trash_or_restore_events'],
153
-                'args'       => ['event_status' => 'trash'],
154
-                'capability' => 'ee_delete_events',
155
-                'noheader'   => true,
156
-            ],
157
-            'restore_event'                 => [
158
-                'func'       => [$this, '_trash_or_restore_event'],
159
-                'args'       => ['event_status' => 'draft'],
160
-                'capability' => 'ee_delete_event',
161
-                'obj_id'     => $this->EVT_ID,
162
-                'noheader'   => true,
163
-            ],
164
-            'restore_events'                => [
165
-                'func'       => [$this, '_trash_or_restore_events'],
166
-                'args'       => ['event_status' => 'draft'],
167
-                'capability' => 'ee_delete_events',
168
-                'noheader'   => true,
169
-            ],
170
-            'delete_event'                  => [
171
-                'func'       => [$this, '_delete_event'],
172
-                'capability' => 'ee_delete_event',
173
-                'obj_id'     => $this->EVT_ID,
174
-                'noheader'   => true,
175
-            ],
176
-            'delete_events'                 => [
177
-                'func'       => [$this, '_delete_events'],
178
-                'capability' => 'ee_delete_events',
179
-                'noheader'   => true,
180
-            ],
181
-            'view_report'                   => [
182
-                'func'       => [$this, '_view_report'],
183
-                'capability' => 'ee_edit_events',
184
-            ],
185
-            'default_event_settings'        => [
186
-                'func'       => [$this, '_default_event_settings'],
187
-                'capability' => 'manage_options',
188
-            ],
189
-            'update_default_event_settings' => [
190
-                'func'       => [$this, '_update_default_event_settings'],
191
-                'capability' => 'manage_options',
192
-                'noheader'   => true,
193
-            ],
194
-            'template_settings'             => [
195
-                'func'       => [$this, '_template_settings'],
196
-                'capability' => 'manage_options',
197
-            ],
198
-            // event category tab related
199
-            'add_category'                  => [
200
-                'func'       => [$this, '_category_details'],
201
-                'capability' => 'ee_edit_event_category',
202
-                'args'       => ['view' => 'add'],
203
-            ],
204
-            'edit_category'                 => [
205
-                'func'       => [$this, '_category_details'],
206
-                'capability' => 'ee_edit_event_category',
207
-                'args'       => ['view' => 'edit'],
208
-            ],
209
-            'delete_categories'             => [
210
-                'func'       => [$this, '_delete_categories'],
211
-                'capability' => 'ee_delete_event_category',
212
-                'noheader'   => true,
213
-            ],
214
-            'delete_category'               => [
215
-                'func'       => [$this, '_delete_categories'],
216
-                'capability' => 'ee_delete_event_category',
217
-                'noheader'   => true,
218
-            ],
219
-            'insert_category'               => [
220
-                'func'       => [$this, '_insert_or_update_category'],
221
-                'args'       => ['new_category' => true],
222
-                'capability' => 'ee_edit_event_category',
223
-                'noheader'   => true,
224
-            ],
225
-            'update_category'               => [
226
-                'func'       => [$this, '_insert_or_update_category'],
227
-                'args'       => ['new_category' => false],
228
-                'capability' => 'ee_edit_event_category',
229
-                'noheader'   => true,
230
-            ],
231
-            'category_list'                 => [
232
-                'func'       => [$this, '_category_list_table'],
233
-                'capability' => 'ee_manage_event_categories',
234
-            ],
235
-            'preview_deletion'              => [
236
-                'func'       => [$this, 'previewDeletion'],
237
-                'capability' => 'ee_delete_events',
238
-            ],
239
-            'confirm_deletion'              => [
240
-                'func'       => [$this, 'confirmDeletion'],
241
-                'capability' => 'ee_delete_events',
242
-                'noheader'   => true,
243
-            ],
244
-        ];
245
-    }
246
-
247
-
248
-    /**
249
-     * Set the _page_config property for this admin page group.
250
-     */
251
-    protected function _set_page_config()
252
-    {
253
-        $post_id            = $this->request->getRequestParam('post', 0, DataType::INT);
254
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
255
-        $this->_page_config = [
256
-            'default'                => [
257
-                'nav'           => [
258
-                    'label' => esc_html__('Overview', 'event_espresso'),
259
-                    'icon'  => 'dashicons-list-view',
260
-                    'order' => 10,
261
-                ],
262
-                'list_table'    => 'Events_Admin_List_Table',
263
-                'help_tabs'     => [
264
-                    'events_overview_help_tab'                       => [
265
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
266
-                        'filename' => 'events_overview',
267
-                    ],
268
-                    'events_overview_table_column_headings_help_tab' => [
269
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
270
-                        'filename' => 'events_overview_table_column_headings',
271
-                    ],
272
-                    'events_overview_filters_help_tab'               => [
273
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
274
-                        'filename' => 'events_overview_filters',
275
-                    ],
276
-                    'events_overview_view_help_tab'                  => [
277
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
278
-                        'filename' => 'events_overview_views',
279
-                    ],
280
-                    'events_overview_other_help_tab'                 => [
281
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
282
-                        'filename' => 'events_overview_other',
283
-                    ],
284
-                ],
285
-                'require_nonce' => false,
286
-            ],
287
-            'create_new'             => [
288
-                'nav'           => [
289
-                    'label'      => esc_html__('Add New Event', 'event_espresso'),
290
-                    'icon'       => 'dashicons-plus-alt',
291
-                    'order'      => 15,
292
-                    'persistent' => false,
293
-                ],
294
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
295
-                'help_tabs'     => [
296
-                    'event_editor_help_tab'                            => [
297
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
298
-                        'filename' => 'event_editor',
299
-                    ],
300
-                    'event_editor_title_richtexteditor_help_tab'       => [
301
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
302
-                        'filename' => 'event_editor_title_richtexteditor',
303
-                    ],
304
-                    'event_editor_venue_details_help_tab'              => [
305
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
306
-                        'filename' => 'event_editor_venue_details',
307
-                    ],
308
-                    'event_editor_event_datetimes_help_tab'            => [
309
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
310
-                        'filename' => 'event_editor_event_datetimes',
311
-                    ],
312
-                    'event_editor_event_tickets_help_tab'              => [
313
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
314
-                        'filename' => 'event_editor_event_tickets',
315
-                    ],
316
-                    'event_editor_event_registration_options_help_tab' => [
317
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
318
-                        'filename' => 'event_editor_event_registration_options',
319
-                    ],
320
-                    'event_editor_tags_categories_help_tab'            => [
321
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
322
-                        'filename' => 'event_editor_tags_categories',
323
-                    ],
324
-                    'event_editor_questions_registrants_help_tab'      => [
325
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
326
-                        'filename' => 'event_editor_questions_registrants',
327
-                    ],
328
-                    'event_editor_save_new_event_help_tab'             => [
329
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
330
-                        'filename' => 'event_editor_save_new_event',
331
-                    ],
332
-                    'event_editor_other_help_tab'                      => [
333
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
334
-                        'filename' => 'event_editor_other',
335
-                    ],
336
-                ],
337
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
338
-                'require_nonce' => false,
339
-            ],
340
-            'edit'                   => [
341
-                'nav'           => [
342
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
343
-                    'icon'       => 'dashicons-edit',
344
-                    'order'      => 15,
345
-                    'persistent' => false,
346
-                    'url'        => $post_id
347
-                        ? EE_Admin_Page::add_query_args_and_nonce(
348
-                            ['post' => $post_id, 'action' => 'edit'],
349
-                            $this->_current_page_view_url
350
-                        )
351
-                        : $this->_admin_base_url,
352
-                ],
353
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
354
-                'help_tabs'     => [
355
-                    'event_editor_help_tab'                            => [
356
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
357
-                        'filename' => 'event_editor',
358
-                    ],
359
-                    'event_editor_title_richtexteditor_help_tab'       => [
360
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
361
-                        'filename' => 'event_editor_title_richtexteditor',
362
-                    ],
363
-                    'event_editor_venue_details_help_tab'              => [
364
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
365
-                        'filename' => 'event_editor_venue_details',
366
-                    ],
367
-                    'event_editor_event_datetimes_help_tab'            => [
368
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
369
-                        'filename' => 'event_editor_event_datetimes',
370
-                    ],
371
-                    'event_editor_event_tickets_help_tab'              => [
372
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
373
-                        'filename' => 'event_editor_event_tickets',
374
-                    ],
375
-                    'event_editor_event_registration_options_help_tab' => [
376
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
377
-                        'filename' => 'event_editor_event_registration_options',
378
-                    ],
379
-                    'event_editor_tags_categories_help_tab'            => [
380
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
381
-                        'filename' => 'event_editor_tags_categories',
382
-                    ],
383
-                    'event_editor_questions_registrants_help_tab'      => [
384
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
385
-                        'filename' => 'event_editor_questions_registrants',
386
-                    ],
387
-                    'event_editor_save_new_event_help_tab'             => [
388
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
389
-                        'filename' => 'event_editor_save_new_event',
390
-                    ],
391
-                    'event_editor_other_help_tab'                      => [
392
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
393
-                        'filename' => 'event_editor_other',
394
-                    ],
395
-                ],
396
-                'require_nonce' => false,
397
-            ],
398
-            'default_event_settings' => [
399
-                'nav'           => [
400
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
401
-                    'icon'  => 'dashicons-admin-generic',
402
-                    'order' => 40,
403
-                ],
404
-                'metaboxes'     => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes),
405
-                'labels'        => [
406
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
407
-                ],
408
-                'help_tabs'     => [
409
-                    'default_settings_help_tab'        => [
410
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
411
-                        'filename' => 'events_default_settings',
412
-                    ],
413
-                    'default_settings_status_help_tab' => [
414
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
415
-                        'filename' => 'events_default_settings_status',
416
-                    ],
417
-                    'default_maximum_tickets_help_tab' => [
418
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
419
-                        'filename' => 'events_default_settings_max_tickets',
420
-                    ],
421
-                ],
422
-                'require_nonce' => false,
423
-            ],
424
-            // template settings
425
-            'template_settings'      => [
426
-                'nav'           => [
427
-                    'label' => esc_html__('Templates', 'event_espresso'),
428
-                    'icon'  => 'dashicons-layout',
429
-                    'order' => 30,
430
-                ],
431
-                'metaboxes'     => $this->_default_espresso_metaboxes,
432
-                'help_tabs'     => [
433
-                    'general_settings_templates_help_tab' => [
434
-                        'title'    => esc_html__('Templates', 'event_espresso'),
435
-                        'filename' => 'general_settings_templates',
436
-                    ],
437
-                ],
438
-                'require_nonce' => false,
439
-            ],
440
-            // event category stuff
441
-            'add_category'           => [
442
-                'nav'           => [
443
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
444
-                    'icon'       => 'dashicons-plus-alt',
445
-                    'order'      => 25,
446
-                    'persistent' => false,
447
-                ],
448
-                'help_tabs'     => [
449
-                    'add_category_help_tab' => [
450
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
451
-                        'filename' => 'events_add_category',
452
-                    ],
453
-                ],
454
-                'metaboxes'     => ['_publish_post_box'],
455
-                'require_nonce' => false,
456
-            ],
457
-            'edit_category'          => [
458
-                'nav'           => [
459
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
460
-                    'icon'       => 'dashicons-edit',
461
-                    'order'      => 25,
462
-                    'persistent' => false,
463
-                    'url'        => $EVT_CAT_ID
464
-                        ? add_query_arg(
465
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
466
-                            $this->_current_page_view_url
467
-                        )
468
-                        : $this->_admin_base_url,
469
-                ],
470
-                'help_tabs'     => [
471
-                    'edit_category_help_tab' => [
472
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
473
-                        'filename' => 'events_edit_category',
474
-                    ],
475
-                ],
476
-                'metaboxes'     => ['_publish_post_box'],
477
-                'require_nonce' => false,
478
-            ],
479
-            'category_list'          => [
480
-                'nav'           => [
481
-                    'label' => esc_html__('Categories', 'event_espresso'),
482
-                    'icon'  => 'dashicons-networking',
483
-                    'order' => 20,
484
-                ],
485
-                'list_table'    => 'Event_Categories_Admin_List_Table',
486
-                'help_tabs'     => [
487
-                    'events_categories_help_tab'                       => [
488
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
489
-                        'filename' => 'events_categories',
490
-                    ],
491
-                    'events_categories_table_column_headings_help_tab' => [
492
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
493
-                        'filename' => 'events_categories_table_column_headings',
494
-                    ],
495
-                    'events_categories_view_help_tab'                  => [
496
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
497
-                        'filename' => 'events_categories_views',
498
-                    ],
499
-                    'events_categories_other_help_tab'                 => [
500
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
501
-                        'filename' => 'events_categories_other',
502
-                    ],
503
-                ],
504
-                'metaboxes'     => $this->_default_espresso_metaboxes,
505
-                'require_nonce' => false,
506
-            ],
507
-            'preview_deletion'       => [
508
-                'nav'           => [
509
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
510
-                    'icon'       => 'dashicons-remove',
511
-                    'order'      => 15,
512
-                    'persistent' => false,
513
-                    'url'        => '',
514
-                ],
515
-                'require_nonce' => false,
516
-            ],
517
-        ];
518
-    }
519
-
520
-
521
-    /**
522
-     * Used to register any global screen options if necessary for every route in this admin page group.
523
-     */
524
-    protected function _add_screen_options()
525
-    {
526
-    }
527
-
528
-
529
-    /**
530
-     * Implementing the screen options for the 'default' route.
531
-     *
532
-     * @throws InvalidArgumentException
533
-     * @throws InvalidDataTypeException
534
-     * @throws InvalidInterfaceException
535
-     */
536
-    protected function _add_screen_options_default()
537
-    {
538
-        $this->_per_page_screen_option();
539
-    }
540
-
541
-
542
-    /**
543
-     * Implementing screen options for the category list route.
544
-     *
545
-     * @throws InvalidArgumentException
546
-     * @throws InvalidDataTypeException
547
-     * @throws InvalidInterfaceException
548
-     */
549
-    protected function _add_screen_options_category_list()
550
-    {
551
-        $page_title              = $this->_admin_page_title;
552
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
553
-        $this->_per_page_screen_option();
554
-        $this->_admin_page_title = $page_title;
555
-    }
556
-
557
-
558
-    /**
559
-     * Used to register any global feature pointers for the admin page group.
560
-     */
561
-    protected function _add_feature_pointers()
562
-    {
563
-    }
564
-
565
-
566
-    /**
567
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
568
-     */
569
-    public function load_scripts_styles()
570
-    {
571
-        wp_register_style(
572
-            'events-admin-css',
573
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
574
-            [],
575
-            EVENT_ESPRESSO_VERSION
576
-        );
577
-        wp_register_style(
578
-            'ee-cat-admin',
579
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
580
-            [],
581
-            EVENT_ESPRESSO_VERSION
582
-        );
583
-        wp_enqueue_style('events-admin-css');
584
-        wp_enqueue_style('ee-cat-admin');
585
-        // scripts
586
-        wp_register_script(
587
-            'event_editor_js',
588
-            EVENTS_ASSETS_URL . 'event_editor.js',
589
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
590
-            EVENT_ESPRESSO_VERSION,
591
-            true
592
-        );
593
-    }
594
-
595
-
596
-    /**
597
-     * Enqueuing scripts and styles specific to this view
598
-     */
599
-    public function load_scripts_styles_create_new()
600
-    {
601
-        $this->load_scripts_styles_edit();
602
-    }
603
-
604
-
605
-    /**
606
-     * Enqueuing scripts and styles specific to this view
607
-     */
608
-    public function load_scripts_styles_edit()
609
-    {
610
-        // styles
611
-        wp_enqueue_style('espresso-ui-theme');
612
-        wp_register_style(
613
-            'event-editor-css',
614
-            EVENTS_ASSETS_URL . 'event-editor.css',
615
-            ['ee-admin-css'],
616
-            EVENT_ESPRESSO_VERSION
617
-        );
618
-        wp_enqueue_style('event-editor-css');
619
-        // scripts
620
-        if (! $this->admin_config->useAdvancedEditor()) {
621
-            wp_register_script(
622
-                'event-datetime-metabox',
623
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
624
-                ['event_editor_js', 'ee-datepicker'],
625
-                EVENT_ESPRESSO_VERSION
626
-            );
627
-            wp_enqueue_script('event-datetime-metabox');
628
-        }
629
-    }
630
-
631
-
632
-    /**
633
-     * Populating the _views property for the category list table view.
634
-     */
635
-    protected function _set_list_table_views_category_list()
636
-    {
637
-        $this->_views = [
638
-            'all' => [
639
-                'slug'        => 'all',
640
-                'label'       => esc_html__('All', 'event_espresso'),
641
-                'count'       => 0,
642
-                'bulk_action' => [
643
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
644
-                ],
645
-            ],
646
-        ];
647
-    }
648
-
649
-
650
-    /**
651
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
652
-     */
653
-    public function admin_init()
654
-    {
655
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
656
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
657
-            'event_espresso'
658
-        );
659
-    }
660
-
661
-
662
-    /**
663
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
664
-     * group.
665
-     */
666
-    public function admin_notices()
667
-    {
668
-    }
669
-
670
-
671
-    /**
672
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
673
-     * this admin page group.
674
-     */
675
-    public function admin_footer_scripts()
676
-    {
677
-    }
678
-
679
-
680
-    /**
681
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
682
-     * warning (via EE_Error::add_error());
683
-     *
684
-     * @param EE_Event|null $event Event object
685
-     * @param string        $req_type
686
-     * @return void
687
-     * @throws EE_Error
688
-     * @throws ReflectionException
689
-     */
690
-    public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '')
691
-    {
692
-        // don't need to do this when processing
693
-        if (! empty($req_type)) {
694
-            return;
695
-        }
696
-        // no event?
697
-        if (! $event instanceof EE_Event) {
698
-            $event = $this->_cpt_model_obj;
699
-        }
700
-        // STILL no event?
701
-        if (! $event instanceof EE_Event) {
702
-            return;
703
-        }
704
-        // don't need to keep calling this
705
-        remove_action(
706
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
707
-            [$this, 'verify_event_edit']
708
-        );
709
-        $orig_status = $event->status();
710
-        // first check if event is active.
711
-        if (
712
-            $orig_status === EEM_Event::cancelled
713
-            || $orig_status === EEM_Event::postponed
714
-            || $event->is_expired()
715
-            || $event->is_inactive()
716
-        ) {
717
-            return;
718
-        }
719
-        // made it here so it IS active... next check that any of the tickets are sold.
720
-        if ($event->is_sold_out(true)) {
721
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
722
-                EE_Error::add_attention(
723
-                    sprintf(
724
-                        esc_html__(
725
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
726
-                            'event_espresso'
727
-                        ),
728
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
729
-                    )
730
-                );
731
-            }
732
-            return;
733
-        }
734
-        if ($orig_status === EEM_Event::sold_out) {
735
-            EE_Error::add_attention(
736
-                sprintf(
737
-                    esc_html__(
738
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
739
-                        'event_espresso'
740
-                    ),
741
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
742
-                )
743
-            );
744
-        }
745
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
746
-        if (! $event->tickets_on_sale()) {
747
-            return;
748
-        }
749
-        // made it here so show warning
750
-        $this->_edit_event_warning();
751
-    }
752
-
753
-
754
-    /**
755
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
756
-     * When needed, hook this into a EE_Error::add_error() notice.
757
-     *
758
-     * @access protected
759
-     * @return void
760
-     */
761
-    protected function _edit_event_warning()
762
-    {
763
-        // we don't want to add warnings during these requests
764
-        if ($this->request->getRequestParam('action') === 'editpost') {
765
-            return;
766
-        }
767
-        EE_Error::add_attention(
768
-            sprintf(
769
-                esc_html__(
770
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
771
-                    'event_espresso'
772
-                ),
773
-                '<a class="espresso-help-tab-lnk ee-help-tab-link">',
774
-                '</a>'
775
-            )
776
-        );
777
-    }
778
-
779
-
780
-    /**
781
-     * When a user is creating a new event, notify them if they haven't set their timezone.
782
-     * Otherwise, do the normal logic
783
-     *
784
-     * @return void
785
-     * @throws EE_Error
786
-     * @throws InvalidArgumentException
787
-     * @throws InvalidDataTypeException
788
-     * @throws InvalidInterfaceException
789
-     * @throws ReflectionException
790
-     */
791
-    protected function _create_new_cpt_item()
792
-    {
793
-        $has_timezone_string = get_option('timezone_string');
794
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
795
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
796
-            EE_Error::add_attention(
797
-                sprintf(
798
-                    esc_html__(
799
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
800
-                        'event_espresso'
801
-                    ),
802
-                    '<br>',
803
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
804
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
805
-                    . '</select>',
806
-                    '<button class="button button--secondary timezone-submit">',
807
-                    '</button><span class="spinner"></span>'
808
-                ),
809
-                __FILE__,
810
-                __FUNCTION__,
811
-                __LINE__
812
-            );
813
-        }
814
-        parent::_create_new_cpt_item();
815
-    }
816
-
817
-
818
-    /**
819
-     * Sets the _views property for the default route in this admin page group.
820
-     */
821
-    protected function _set_list_table_views_default()
822
-    {
823
-        $this->_views = [
824
-            'all'   => [
825
-                'slug'        => 'all',
826
-                'label'       => esc_html__('View All Events', 'event_espresso'),
827
-                'count'       => 0,
828
-                'bulk_action' => [
829
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
830
-                ],
831
-            ],
832
-            'draft' => [
833
-                'slug'        => 'draft',
834
-                'label'       => esc_html__('Draft', 'event_espresso'),
835
-                'count'       => 0,
836
-                'bulk_action' => [
837
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
838
-                ],
839
-            ],
840
-        ];
841
-        if ($this->capabilities->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
842
-            $this->_views['trash'] = [
843
-                'slug'        => 'trash',
844
-                'label'       => esc_html__('Trash', 'event_espresso'),
845
-                'count'       => 0,
846
-                'bulk_action' => [
847
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
848
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
849
-                ],
850
-            ];
851
-        }
852
-    }
853
-
854
-
855
-    /**
856
-     * Provides the legend item array for the default list table view.
857
-     *
858
-     * @return array
859
-     * @throws EE_Error
860
-     * @throws EE_Error
861
-     */
862
-    protected function _event_legend_items(): array
863
-    {
864
-        $items    = [
865
-            'view_details'   => [
866
-                'class' => 'dashicons dashicons-visibility',
867
-                'desc'  => esc_html__('View Event', 'event_espresso'),
868
-            ],
869
-            'edit_event'     => [
870
-                'class' => 'dashicons dashicons-calendar-alt',
871
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
872
-            ],
873
-            'view_attendees' => [
874
-                'class' => 'dashicons dashicons-groups',
875
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
876
-            ],
877
-        ];
878
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
879
-        $statuses = [
880
-            'sold_out_status'  => [
881
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
882
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
883
-            ],
884
-            'active_status'    => [
885
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
886
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
887
-            ],
888
-            'upcoming_status'  => [
889
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
890
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
891
-            ],
892
-            'postponed_status' => [
893
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
894
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
895
-            ],
896
-            'cancelled_status' => [
897
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
898
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
899
-            ],
900
-            'expired_status'   => [
901
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
902
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
903
-            ],
904
-            'inactive_status'  => [
905
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
906
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
907
-            ],
908
-        ];
909
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
910
-        return array_merge($items, $statuses);
911
-    }
912
-
913
-
914
-    /**
915
-     * @return EEM_Event
916
-     * @throws EE_Error
917
-     * @throws InvalidArgumentException
918
-     * @throws InvalidDataTypeException
919
-     * @throws InvalidInterfaceException
920
-     * @throws ReflectionException
921
-     */
922
-    private function _event_model(): EEM_Event
923
-    {
924
-        if (! $this->_event_model instanceof EEM_Event) {
925
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
926
-        }
927
-        return $this->_event_model;
928
-    }
929
-
930
-
931
-    /**
932
-     * Adds extra buttons to the WP CPT permalink field row.
933
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
934
-     *
935
-     * @param string      $return    the current html
936
-     * @param int         $id        the post id for the page
937
-     * @param string|null $new_title What the title is
938
-     * @param string|null $new_slug  what the slug is
939
-     * @return string            The new html string for the permalink area
940
-     * @deprecated 5.0.0.p
941
-     * @see        TicketSelectorShortcodeButton::addButton
942
-     */
943
-    public function extra_permalink_field_buttons(
944
-        string $return,
945
-        int $id,
946
-        ?string $new_title,
947
-        ?string $new_slug
948
-    ): string {
949
-        return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug);
950
-    }
951
-
952
-
953
-    /**
954
-     * _events_overview_list_table
955
-     * This contains the logic for showing the events_overview list
956
-     *
957
-     * @access protected
958
-     * @return void
959
-     * @throws DomainException
960
-     * @throws EE_Error
961
-     * @throws InvalidArgumentException
962
-     * @throws InvalidDataTypeException
963
-     * @throws InvalidInterfaceException
964
-     */
965
-    protected function _events_overview_list_table()
966
-    {
967
-        $after_list_table = [];
968
-        $links_html       = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
969
-        $links_html       .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
970
-        $links_html       .= EEH_HTML::div(
971
-            EEH_Template::get_button_or_link(
972
-                get_post_type_archive_link(EspressoPostType::EVENTS),
973
-                esc_html__('View Event Archive Page', 'event_espresso'),
974
-                'button button--small button--secondary'
975
-            ),
976
-            '',
977
-            'ee-admin-button-row ee-admin-button-row--align-start'
978
-        );
979
-        $links_html       .= EEH_HTML::divx();
980
-
981
-        $after_list_table['view_event_list_button'] = $links_html;
982
-
983
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
984
-        $this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
985
-                'create_new',
986
-                'add',
987
-                [],
988
-                'add-new-h2'
989
-            );
990
-
991
-        $this->_template_args['after_list_table'] = array_merge(
992
-            (array) $this->_template_args['after_list_table'],
993
-            $after_list_table
994
-        );
995
-        $this->display_admin_list_table_page_with_no_sidebar();
996
-    }
997
-
998
-
999
-    /**
1000
-     * this allows for extra misc actions in the default WP publish box
1001
-     *
1002
-     * @return void
1003
-     * @throws DomainException
1004
-     * @throws EE_Error
1005
-     * @throws InvalidArgumentException
1006
-     * @throws InvalidDataTypeException
1007
-     * @throws InvalidInterfaceException
1008
-     * @throws ReflectionException
1009
-     */
1010
-    public function extra_misc_actions_publish_box()
1011
-    {
1012
-        $this->_generate_publish_box_extra_content();
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1018
-     * saved.
1019
-     * Typically you would use this to save any additional data.
1020
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1021
-     * ALSO very important.  When a post transitions from scheduled to published,
1022
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1023
-     * other meta saves. So MAKE sure that you handle this accordingly.
1024
-     *
1025
-     * @access protected
1026
-     * @abstract
1027
-     * @param string  $post_id The ID of the cpt that was saved (so you can link relationally)
1028
-     * @param WP_Post $post    The post object of the cpt that was saved.
1029
-     * @return void
1030
-     * @throws EE_Error
1031
-     * @throws InvalidArgumentException
1032
-     * @throws InvalidDataTypeException
1033
-     * @throws InvalidInterfaceException
1034
-     * @throws ReflectionException
1035
-     */
1036
-    protected function _insert_update_cpt_item($post_id, $post)
1037
-    {
1038
-        if ($post instanceof WP_Post && $post->post_type !== EspressoPostType::EVENTS) {
1039
-            // get out we're not processing an event save.
1040
-            return;
1041
-        }
1042
-        $event_values = [
1043
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, DataType::BOOL),
1044
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, DataType::BOOL),
1045
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1046
-        ];
1047
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1048
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1049
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1050
-                'display_ticket_selector',
1051
-                false,
1052
-                'bool'
1053
-            );
1054
-            $event_values['EVT_additional_limit']            = min(
1055
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1056
-                $this->request->getRequestParam(
1057
-                    'additional_limit',
1058
-                    EEM_Event::get_default_additional_limit(),
1059
-                    'int'
1060
-                )
1061
-            );
1062
-            $event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1063
-                'EVT_default_registration_status',
1064
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1065
-            );
1066
-
1067
-            $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1068
-            $event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1069
-            $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, DataType::BOOL);
1070
-        } elseif ($post instanceof WP_Post) {
1071
-            $event_values['EVT_name'] = $post->post_title;
1072
-            $event_values['EVT_desc'] = $post->post_content;
1073
-        }
1074
-        // update event
1075
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1076
-        // get event_object for other metaboxes...
1077
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1078
-        // i have to setup where conditions to override the filters in the model
1079
-        // that filter out auto-draft and inherit statuses so we GET the inherit id!
1080
-        /** @var EE_Event $event */
1081
-        $event = $this->_event_model()->get_one(
1082
-            [
1083
-                [
1084
-                    $this->_event_model()->primary_key_name() => $post_id,
1085
-                    'OR'                                      => [
1086
-                        'status'   => $post->post_status,
1087
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1088
-                        // but the returned object here has a status of "publish", so use the original post status as well
1089
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1090
-                    ],
1091
-                    'status' => ['NOT IN', ['auto-draft']],
1092
-                ],
1093
-            ]
1094
-        );
1095
-
1096
-        // the following are default callbacks for event attachment updates
1097
-        // that can be overridden by caffeinated functionality and/or addons.
1098
-        $event_update_callbacks = [];
1099
-        if (! $this->admin_config->useAdvancedEditor()) {
1100
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1101
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1102
-        }
1103
-        $event_update_callbacks = apply_filters(
1104
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1105
-            $event_update_callbacks
1106
-        );
1107
-
1108
-        $att_success = true;
1109
-        foreach ($event_update_callbacks as $e_callback) {
1110
-            $_success = is_callable($e_callback)
1111
-                ? $e_callback($event, $this->request->requestParams())
1112
-                : false;
1113
-            // if ANY of these updates fail then we want the appropriate global error message
1114
-            $att_success = $_success !== false ? $att_success : false;
1115
-        }
1116
-        // any errors?
1117
-        if ($success && $att_success === false) {
1118
-            EE_Error::add_error(
1119
-                esc_html__(
1120
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1121
-                    'event_espresso'
1122
-                ),
1123
-                __FILE__,
1124
-                __FUNCTION__,
1125
-                __LINE__
1126
-            );
1127
-        } elseif ($success === false) {
1128
-            EE_Error::add_error(
1129
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1130
-                __FILE__,
1131
-                __FUNCTION__,
1132
-                __LINE__
1133
-            );
1134
-        }
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     * @param int $post_id
1140
-     * @param int $revision_id
1141
-     * @throws EE_Error
1142
-     * @throws EE_Error
1143
-     * @throws ReflectionException
1144
-     * @see parent::restore_item()
1145
-     */
1146
-    protected function _restore_cpt_item(int $post_id, int $revision_id)
1147
-    {
1148
-        // copy existing event meta to new post
1149
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1150
-        if ($post_evt instanceof EE_Event) {
1151
-            // meta revision restore
1152
-            $post_evt->restore_revision($revision_id);
1153
-            // related objs restore
1154
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1155
-        }
1156
-    }
1157
-
1158
-
1159
-    /**
1160
-     * Attach the venue to the Event
1161
-     *
1162
-     * @param EE_Event $event Event Object to add the venue to
1163
-     * @param array    $data  The request data from the form
1164
-     * @return bool           Success or fail.
1165
-     * @throws EE_Error
1166
-     * @throws ReflectionException
1167
-     */
1168
-    protected function _default_venue_update(EE_Event $event, array $data): bool
1169
-    {
1170
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1171
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1172
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1173
-        // very important.  If we don't have a venue name...
1174
-        // then we'll get out because not necessary to create empty venue
1175
-        if (empty($data['venue_title'])) {
1176
-            return false;
1177
-        }
1178
-        $venue_array = [
1179
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1180
-            'VNU_name'            => $data['venue_title'],
1181
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1182
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1183
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1184
-                ? $data['venue_short_description']
1185
-                : null,
1186
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1187
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1188
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1189
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1190
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1191
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1192
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1193
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1194
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1195
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1196
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1197
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1198
-            'status'              => 'publish',
1199
-        ];
1200
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1201
-        if (! empty($venue_id)) {
1202
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1203
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1204
-            // we've gotta make sure that the venue is always attached to a revision..
1205
-            // add_relation_to should take care of making sure that the relation is already present.
1206
-            $event->_add_relation_to($venue_id, 'Venue');
1207
-            return $rows_affected > 0;
1208
-        }
1209
-        // we insert the venue
1210
-        $venue_id = $venue_model->insert($venue_array);
1211
-        $event->_add_relation_to($venue_id, 'Venue');
1212
-        return ! empty($venue_id);
1213
-        // when we have the ancestor come in it's already been handled by the revision save.
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1219
-     *
1220
-     * @param EE_Event $event The Event object we're attaching data to
1221
-     * @param array    $data  The request data from the form
1222
-     * @return array
1223
-     * @throws EE_Error
1224
-     * @throws ReflectionException
1225
-     * @throws Exception
1226
-     */
1227
-    protected function _default_tickets_update(EE_Event $event, array $data): array
1228
-    {
1229
-        if ($this->admin_config->useAdvancedEditor()) {
1230
-            return [];
1231
-        }
1232
-        $datetime       = null;
1233
-        $saved_tickets  = [];
1234
-        $event_timezone = $event->get_timezone();
1235
-        $date_formats   = ['Y-m-d', 'h:i a'];
1236
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1237
-            // trim all values to ensure any excess whitespace is removed.
1238
-            $datetime_data                = array_map('trim', $datetime_data);
1239
-            $datetime_data['DTT_EVT_end'] = ! empty($datetime_data['DTT_EVT_end'])
1240
-                    ? $datetime_data['DTT_EVT_end']
1241
-                    : $datetime_data['DTT_EVT_start'];
1242
-            $datetime_values              = [
1243
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1244
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1245
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1246
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1247
-                'DTT_order'     => $row,
1248
-            ];
1249
-            // if we have an id then let's get existing object first and then set the new values.
1250
-            //  Otherwise we instantiate a new object for save.
1251
-            if (! empty($datetime_data['DTT_ID'])) {
1252
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1253
-                if (! $datetime instanceof EE_Datetime) {
1254
-                    throw new RuntimeException(
1255
-                        sprintf(
1256
-                            esc_html__(
1257
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1258
-                                'event_espresso'
1259
-                            ),
1260
-                            $datetime_data['DTT_ID']
1261
-                        )
1262
-                    );
1263
-                }
1264
-                $datetime->set_date_format($date_formats[0]);
1265
-                $datetime->set_time_format($date_formats[1]);
1266
-                foreach ($datetime_values as $field => $value) {
1267
-                    $datetime->set($field, $value);
1268
-                }
1269
-            } else {
1270
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1271
-            }
1272
-            if (! $datetime instanceof EE_Datetime) {
1273
-                throw new RuntimeException(
1274
-                    sprintf(
1275
-                        esc_html__(
1276
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1277
-                            'event_espresso'
1278
-                        ),
1279
-                        print_r($datetime_values, true)
1280
-                    )
1281
-                );
1282
-            }
1283
-            // before going any further make sure our dates are setup correctly
1284
-            // so that the end date is always equal or greater than the start date.
1285
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1286
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1287
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1288
-            }
1289
-            $datetime->save();
1290
-            $event->_add_relation_to($datetime, 'Datetime');
1291
-        }
1292
-        // no datetimes get deleted so we don't do any of that logic here.
1293
-        // update tickets next
1294
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1295
-
1296
-        // set up some default start and end dates in case those are not present in the incoming data
1297
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1298
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1299
-        // use the start date of the first datetime for the end date
1300
-        $first_datetime   = $event->first_datetime();
1301
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1302
-
1303
-        // now process the incoming data
1304
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1305
-            $update_prices = false;
1306
-            $ticket_price  = $data['edit_prices'][ $row ][1]['PRC_amount'] ?? 0;
1307
-            // trim inputs to ensure any excess whitespace is removed.
1308
-            $ticket_data   = array_map('trim', $ticket_data);
1309
-            $ticket_values = [
1310
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1311
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1312
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1313
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1314
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1315
-                    ? $ticket_data['TKT_start_date']
1316
-                    : $default_start_date,
1317
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1318
-                    ? $ticket_data['TKT_end_date']
1319
-                    : $default_end_date,
1320
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1321
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1322
-                    ? $ticket_data['TKT_qty']
1323
-                    : EE_INF,
1324
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1325
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1326
-                    ? $ticket_data['TKT_uses']
1327
-                    : EE_INF,
1328
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1329
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1330
-                'TKT_order'       => $ticket_data['TKT_order'] ?? $row,
1331
-                'TKT_price'       => $ticket_price,
1332
-                'TKT_row'         => $row,
1333
-            ];
1334
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1335
-            // which means in turn that the prices will become new prices as well.
1336
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1337
-                $ticket_values['TKT_ID']         = 0;
1338
-                $ticket_values['TKT_is_default'] = 0;
1339
-                $update_prices                   = true;
1340
-            }
1341
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1342
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1343
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1344
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1345
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1346
-            if (! empty($ticket_data['TKT_ID'])) {
1347
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1348
-                if (! $existing_ticket instanceof EE_Ticket) {
1349
-                    throw new RuntimeException(
1350
-                        sprintf(
1351
-                            esc_html__(
1352
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1353
-                                'event_espresso'
1354
-                            ),
1355
-                            $ticket_data['TKT_ID']
1356
-                        )
1357
-                    );
1358
-                }
1359
-                $ticket_sold = $existing_ticket->count_related(
1360
-                        'Registration',
1361
-                        [
1362
-                            [
1363
-                                'STS_ID' => [
1364
-                                    'NOT IN',
1365
-                                    [EEM_Registration::status_id_incomplete],
1366
-                                ],
1367
-                            ],
1368
-                        ]
1369
-                    ) > 0;
1370
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1371
-                // if they are different then we create a new ticket (if $ticket_sold)
1372
-                // if they aren't different then we go ahead and modify existing ticket.
1373
-                $create_new_ticket = $ticket_sold
1374
-                                     && $ticket_price !== $existing_ticket->price()
1375
-                                     && ! $existing_ticket->deleted();
1376
-                $existing_ticket->set_date_format($date_formats[0]);
1377
-                $existing_ticket->set_time_format($date_formats[1]);
1378
-                // set new values
1379
-                foreach ($ticket_values as $field => $value) {
1380
-                    if ($field == 'TKT_qty') {
1381
-                        $existing_ticket->set_qty($value);
1382
-                    } elseif ($field == 'TKT_price') {
1383
-                        $existing_ticket->set('TKT_price', $ticket_price);
1384
-                    } else {
1385
-                        $existing_ticket->set($field, $value);
1386
-                    }
1387
-                }
1388
-                $ticket = $existing_ticket;
1389
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1390
-                //  Otherwise we have to create a new ticket.
1391
-                if ($create_new_ticket) {
1392
-                    // archive the old ticket first
1393
-                    $existing_ticket->set('TKT_deleted', 1);
1394
-                    $existing_ticket->save();
1395
-                    // make sure this ticket is still recorded in our $saved_tickets
1396
-                    // so we don't run it through the regular trash routine.
1397
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1398
-                    // create new ticket that's a copy of the existing except,
1399
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1400
-                    $new_ticket = clone $existing_ticket;
1401
-                    $new_ticket->set('TKT_ID', 0);
1402
-                    $new_ticket->set('TKT_deleted', 0);
1403
-                    $new_ticket->set('TKT_sold', 0);
1404
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1405
-                    $update_prices = true;
1406
-                    $ticket        = $new_ticket;
1407
-                }
1408
-            } else {
1409
-                // no TKT_id so a new ticket
1410
-                $ticket_values['TKT_price'] = $ticket_price;
1411
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1412
-                $update_prices              = true;
1413
-            }
1414
-            if (! $ticket instanceof EE_Ticket) {
1415
-                throw new RuntimeException(
1416
-                    sprintf(
1417
-                        esc_html__(
1418
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1419
-                            'event_espresso'
1420
-                        ),
1421
-                        print_r($ticket_values, true)
1422
-                    )
1423
-                );
1424
-            }
1425
-            // cap ticket qty by datetime reg limits
1426
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1427
-            // update ticket.
1428
-            $ticket->save();
1429
-            // before going any further make sure our dates are setup correctly
1430
-            // so that the end date is always equal or greater than the start date.
1431
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1432
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1433
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1434
-                $ticket->save();
1435
-            }
1436
-            // initially let's add the ticket to the datetime
1437
-            $datetime->_add_relation_to($ticket, 'Ticket');
1438
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1439
-            // add prices to ticket
1440
-            $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1441
-                ? $data['edit_prices'][ $row ]
1442
-                : [];
1443
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1444
-        }
1445
-        // however now we need to handle permanently deleting tickets via the ui.
1446
-        // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1447
-        // However, it does allow for deleting tickets that have no tickets sold,
1448
-        // in which case we want to get rid of permanently because there is no need to save in db.
1449
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1450
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1451
-        foreach ($tickets_removed as $id) {
1452
-            $id = absint($id);
1453
-            // get the ticket for this id
1454
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1455
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1456
-                continue;
1457
-            }
1458
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1459
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1460
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1461
-            foreach ($related_datetimes as $related_datetime) {
1462
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1463
-            }
1464
-            // need to do the same for prices (except these prices can also be deleted because again,
1465
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1466
-            $ticket_to_remove->delete_related_permanently('Price');
1467
-            // finally let's delete this ticket
1468
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1469
-            $ticket_to_remove->delete_permanently();
1470
-        }
1471
-        return [$datetime, $saved_tickets];
1472
-    }
1473
-
1474
-
1475
-    /**
1476
-     * This attaches a list of given prices to a ticket.
1477
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1478
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1479
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1480
-     *
1481
-     * @access  private
1482
-     * @param array     $prices_data Array of prices from the form.
1483
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1484
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1485
-     * @return  void
1486
-     * @throws EE_Error
1487
-     * @throws ReflectionException
1488
-     */
1489
-    private function _add_prices_to_ticket(array $prices_data, EE_Ticket $ticket, bool $new_prices = false)
1490
-    {
1491
-        $timezone = $ticket->get_timezone();
1492
-        foreach ($prices_data as $row => $price_data) {
1493
-            $price_values = [
1494
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1495
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1496
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1497
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1498
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1499
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1500
-                'PRC_order'      => $row,
1501
-            ];
1502
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1503
-                $price_values['PRC_ID'] = 0;
1504
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1505
-            } else {
1506
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1507
-                // update this price with new values
1508
-                foreach ($price_values as $field => $new_price) {
1509
-                    $price->set($field, $new_price);
1510
-                }
1511
-            }
1512
-            if (! $price instanceof EE_Price) {
1513
-                throw new RuntimeException(
1514
-                    sprintf(
1515
-                        esc_html__(
1516
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1517
-                            'event_espresso'
1518
-                        ),
1519
-                        print_r($price_values, true)
1520
-                    )
1521
-                );
1522
-            }
1523
-            $price->save();
1524
-            $ticket->_add_relation_to($price, 'Price');
1525
-        }
1526
-    }
1527
-
1528
-
1529
-    /**
1530
-     * Add in our autosave ajax handlers
1531
-     */
1532
-    protected function _ee_autosave_create_new()
1533
-    {
1534
-    }
1535
-
1536
-
1537
-    /**
1538
-     * More autosave handlers.
1539
-     */
1540
-    protected function _ee_autosave_edit()
1541
-    {
1542
-    }
1543
-
1544
-
1545
-    /**
1546
-     * @throws EE_Error
1547
-     * @throws ReflectionException
1548
-     */
1549
-    private function _generate_publish_box_extra_content()
1550
-    {
1551
-        // load formatter helper
1552
-        // args for getting related registrations
1553
-        $approved_query_args        = [
1554
-            [
1555
-                'REG_deleted' => 0,
1556
-                'STS_ID'      => EEM_Registration::status_id_approved,
1557
-            ],
1558
-        ];
1559
-        $not_approved_query_args    = [
1560
-            [
1561
-                'REG_deleted' => 0,
1562
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1563
-            ],
1564
-        ];
1565
-        $pending_payment_query_args = [
1566
-            [
1567
-                'REG_deleted' => 0,
1568
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1569
-            ],
1570
-        ];
1571
-        // publish box
1572
-        $publish_box_extra_args = [
1573
-            'view_approved_reg_url'        => add_query_arg(
1574
-                [
1575
-                    'action'      => 'default',
1576
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1577
-                    '_reg_status' => EEM_Registration::status_id_approved,
1578
-                    'use_filters' => true,
1579
-                ],
1580
-                REG_ADMIN_URL
1581
-            ),
1582
-            'view_not_approved_reg_url'    => add_query_arg(
1583
-                [
1584
-                    'action'      => 'default',
1585
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1586
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1587
-                    'use_filters' => true,
1588
-                ],
1589
-                REG_ADMIN_URL
1590
-            ),
1591
-            'view_pending_payment_reg_url' => add_query_arg(
1592
-                [
1593
-                    'action'      => 'default',
1594
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1595
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1596
-                    'use_filters' => true,
1597
-                ],
1598
-                REG_ADMIN_URL
1599
-            ),
1600
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1601
-                'Registration',
1602
-                $approved_query_args
1603
-            ),
1604
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1605
-                'Registration',
1606
-                $not_approved_query_args
1607
-            ),
1608
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1609
-                'Registration',
1610
-                $pending_payment_query_args
1611
-            ),
1612
-            'misc_pub_section_class'       => apply_filters(
1613
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1614
-                'misc-pub-section'
1615
-            ),
1616
-        ];
1617
-        ob_start();
1618
-        do_action(
1619
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1620
-            $this->_cpt_model_obj
1621
-        );
1622
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1623
-        // load template
1624
-        EEH_Template::display_template(
1625
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1626
-            $publish_box_extra_args
1627
-        );
1628
-    }
1629
-
1630
-
1631
-    /**
1632
-     * @return EE_Event
1633
-     */
1634
-    public function get_event_object()
1635
-    {
1636
-        return $this->_cpt_model_obj;
1637
-    }
1638
-
1639
-
1640
-
1641
-
1642
-    /** METABOXES * */
1643
-    /**
1644
-     * _register_event_editor_meta_boxes
1645
-     * add all metaboxes related to the event_editor
1646
-     *
1647
-     * @return void
1648
-     * @throws EE_Error
1649
-     * @throws ReflectionException
1650
-     */
1651
-    protected function _register_event_editor_meta_boxes()
1652
-    {
1653
-        $this->verify_cpt_object();
1654
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1655
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1656
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1657
-            $this->addMetaBox(
1658
-                'espresso_event_editor_event_options',
1659
-                esc_html__('Event Registration Options', 'event_espresso'),
1660
-                [$this, 'registration_options_meta_box'],
1661
-                $this->page_slug,
1662
-                'side'
1663
-            );
1664
-        }
1665
-        if (! $use_advanced_editor) {
1666
-            $this->addMetaBox(
1667
-                'espresso_event_editor_tickets',
1668
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1669
-                [$this, 'ticket_metabox'],
1670
-                $this->page_slug,
1671
-                'normal',
1672
-                'high'
1673
-            );
1674
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1675
-            add_action(
1676
-                'add_meta_boxes_espresso_events',
1677
-                function () {
1678
-                    global $current_screen;
1679
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1680
-                },
1681
-                99
1682
-            );
1683
-        }
1684
-        // NOTE: if you're looking for other metaboxes in here,
1685
-        // where a metabox has a related management page in the admin
1686
-        // you will find it setup in the related management page's "_Hooks" file.
1687
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1688
-    }
1689
-
1690
-
1691
-    /**
1692
-     * @throws DomainException
1693
-     * @throws EE_Error
1694
-     * @throws ReflectionException
1695
-     */
1696
-    public function ticket_metabox()
1697
-    {
1698
-        $existing_datetime_ids = $existing_ticket_ids = [];
1699
-        // defaults for template args
1700
-        $template_args = [
1701
-            'ticket_rows'       => '',
1702
-            'total_ticket_rows' => 1,
1703
-            'trash_icon'        => 'dashicons dashicons-lock',
1704
-            'disabled'          => '',
1705
-        ];
1706
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1707
-        /**
1708
-         * 1. Start with retrieving Datetimes
1709
-         * 2. Fore each datetime get related tickets
1710
-         * 3. For each ticket get related prices
1711
-         */
1712
-        /** @var EEM_Datetime $datetime_model */
1713
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1714
-        /** @var EEM_Ticket $datetime_model */
1715
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1716
-        $times        = $datetime_model->get_all_event_dates($event_id);
1717
-        /** @type EE_Datetime $first_datetime */
1718
-        $first_datetime = reset($times);
1719
-        // do we get related tickets?
1720
-        if (
1721
-            $first_datetime instanceof EE_Datetime
1722
-            && $first_datetime->ID() !== 0
1723
-        ) {
1724
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1725
-            $template_args['time']   = $first_datetime;
1726
-            $related_tickets         = $first_datetime->tickets(
1727
-                [
1728
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1729
-                    'default_where_conditions' => 'none',
1730
-                ]
1731
-            );
1732
-            if (! empty($related_tickets)) {
1733
-                $template_args['total_ticket_rows'] = count($related_tickets);
1734
-                $row                                = 0;
1735
-                foreach ($related_tickets as $ticket) {
1736
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1737
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1738
-                    $row++;
1739
-                }
1740
-            } else {
1741
-                $template_args['total_ticket_rows'] = 1;
1742
-                /** @type EE_Ticket $ticket */
1743
-                $ticket                       = $ticket_model->create_default_object();
1744
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1745
-            }
1746
-        } else {
1747
-            $template_args['time'] = $times[0];
1748
-            /** @type EE_Ticket[] $tickets */
1749
-            $tickets                      = $ticket_model->get_all_default_tickets();
1750
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1751
-            // NOTE: we're just sending the first default row
1752
-            // (decaf can't manage default tickets so this should be sufficient);
1753
-        }
1754
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1755
-            'event_editor_event_datetimes_help_tab'
1756
-        );
1757
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1758
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1759
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1760
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1761
-            $ticket_model->create_default_object(),
1762
-            true
1763
-        );
1764
-        $template                                  = apply_filters(
1765
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1766
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1767
-        );
1768
-        EEH_Template::display_template($template, $template_args);
1769
-    }
1770
-
1771
-
1772
-    /**
1773
-     * Setup an individual ticket form for the decaf event editor page
22
+	/**
23
+	 * primary key for the event model
24
+	 */
25
+	private int $EVT_ID = 0;
26
+
27
+	/**
28
+	 * This will hold the event object for event_details screen.
29
+	 *
30
+	 * @var EE_Event|null $_event
31
+	 */
32
+	protected ?EE_Event $_event = null;
33
+
34
+	/**
35
+	 * This will hold the category object for category_details screen.
36
+	 */
37
+	protected ?stdClass $_category = null;
38
+
39
+	protected ?EEM_Event $_event_model = null;
40
+
41
+	/**
42
+	 * @var EE_Event|EE_CPT_Base|null $_cpt_model_obj
43
+	 */
44
+	protected $_cpt_model_obj;
45
+
46
+	protected ?NodeGroupDao $model_obj_node_group_persister = null;
47
+
48
+	protected ?AdvancedEditorAdminFormSection $advanced_editor_admin_form = null;
49
+
50
+
51
+	/**
52
+	 * Initialize page props for this admin page group.
53
+	 */
54
+	protected function _init_page_props()
55
+	{
56
+		// is there a evt_id in the request?
57
+		$this->EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT);
58
+		$this->EVT_ID = $this->request->getRequestParam('post', $this->EVT_ID, DataType::INT);
59
+		$this->EVT_ID = $this->request->getRequestParam('post_ID', $this->EVT_ID, DataType::INT);
60
+
61
+		$this->page_slug        = EVENTS_PG_SLUG;
62
+		$this->page_label       = EVENTS_LABEL;
63
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
64
+		$this->_admin_base_path = EVENTS_ADMIN;
65
+		$this->_cpt_model_names = [
66
+			'create_new' => 'EEM_Event',
67
+			'edit'       => 'EEM_Event',
68
+		];
69
+		$this->_cpt_edit_routes = [
70
+			'espresso_events' => 'edit',
71
+		];
72
+		add_action(
73
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
74
+			[$this, 'verify_event_edit'],
75
+			10,
76
+			2
77
+		);
78
+	}
79
+
80
+
81
+	/**
82
+	 * Sets the ajax hooks used for this admin page group.
83
+	 */
84
+	protected function _ajax_hooks()
85
+	{
86
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
87
+	}
88
+
89
+
90
+	/**
91
+	 * Sets the page properties for this admin page group.
92
+	 */
93
+	protected function _define_page_props()
94
+	{
95
+		$this->_admin_page_title = EVENTS_LABEL;
96
+		$this->_labels           = [
97
+			'buttons'      => [
98
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
99
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
100
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
101
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
102
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
103
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
104
+			],
105
+			'editor_title' => [
106
+				'espresso_events' => esc_html__('Edit Event', 'event_espresso'),
107
+			],
108
+			'publishbox'   => [
109
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
110
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
111
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
112
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
113
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
114
+			],
115
+		];
116
+	}
117
+
118
+
119
+	/**
120
+	 * Sets the page routes property for this admin page group.
121
+	 */
122
+	protected function _set_page_routes()
123
+	{
124
+		$this->_page_routes = [
125
+			'default'                       => [
126
+				'func'       => [$this, '_events_overview_list_table'],
127
+				'capability' => 'ee_read_events',
128
+			],
129
+			'create_new'                    => [
130
+				'func'       => [$this, '_create_new_cpt_item'],
131
+				'capability' => 'ee_edit_events',
132
+			],
133
+			'edit'                          => [
134
+				'func'       => [$this, '_edit_cpt_item'],
135
+				'capability' => 'ee_edit_event',
136
+				'obj_id'     => $this->EVT_ID,
137
+			],
138
+			'copy_event'                    => [
139
+				'func'       => [$this, '_copy_events'],
140
+				'capability' => 'ee_edit_event',
141
+				'obj_id'     => $this->EVT_ID,
142
+				'noheader'   => true,
143
+			],
144
+			'trash_event'                   => [
145
+				'func'       => [$this, '_trash_or_restore_event'],
146
+				'args'       => ['event_status' => 'trash'],
147
+				'capability' => 'ee_delete_event',
148
+				'obj_id'     => $this->EVT_ID,
149
+				'noheader'   => true,
150
+			],
151
+			'trash_events'                  => [
152
+				'func'       => [$this, '_trash_or_restore_events'],
153
+				'args'       => ['event_status' => 'trash'],
154
+				'capability' => 'ee_delete_events',
155
+				'noheader'   => true,
156
+			],
157
+			'restore_event'                 => [
158
+				'func'       => [$this, '_trash_or_restore_event'],
159
+				'args'       => ['event_status' => 'draft'],
160
+				'capability' => 'ee_delete_event',
161
+				'obj_id'     => $this->EVT_ID,
162
+				'noheader'   => true,
163
+			],
164
+			'restore_events'                => [
165
+				'func'       => [$this, '_trash_or_restore_events'],
166
+				'args'       => ['event_status' => 'draft'],
167
+				'capability' => 'ee_delete_events',
168
+				'noheader'   => true,
169
+			],
170
+			'delete_event'                  => [
171
+				'func'       => [$this, '_delete_event'],
172
+				'capability' => 'ee_delete_event',
173
+				'obj_id'     => $this->EVT_ID,
174
+				'noheader'   => true,
175
+			],
176
+			'delete_events'                 => [
177
+				'func'       => [$this, '_delete_events'],
178
+				'capability' => 'ee_delete_events',
179
+				'noheader'   => true,
180
+			],
181
+			'view_report'                   => [
182
+				'func'       => [$this, '_view_report'],
183
+				'capability' => 'ee_edit_events',
184
+			],
185
+			'default_event_settings'        => [
186
+				'func'       => [$this, '_default_event_settings'],
187
+				'capability' => 'manage_options',
188
+			],
189
+			'update_default_event_settings' => [
190
+				'func'       => [$this, '_update_default_event_settings'],
191
+				'capability' => 'manage_options',
192
+				'noheader'   => true,
193
+			],
194
+			'template_settings'             => [
195
+				'func'       => [$this, '_template_settings'],
196
+				'capability' => 'manage_options',
197
+			],
198
+			// event category tab related
199
+			'add_category'                  => [
200
+				'func'       => [$this, '_category_details'],
201
+				'capability' => 'ee_edit_event_category',
202
+				'args'       => ['view' => 'add'],
203
+			],
204
+			'edit_category'                 => [
205
+				'func'       => [$this, '_category_details'],
206
+				'capability' => 'ee_edit_event_category',
207
+				'args'       => ['view' => 'edit'],
208
+			],
209
+			'delete_categories'             => [
210
+				'func'       => [$this, '_delete_categories'],
211
+				'capability' => 'ee_delete_event_category',
212
+				'noheader'   => true,
213
+			],
214
+			'delete_category'               => [
215
+				'func'       => [$this, '_delete_categories'],
216
+				'capability' => 'ee_delete_event_category',
217
+				'noheader'   => true,
218
+			],
219
+			'insert_category'               => [
220
+				'func'       => [$this, '_insert_or_update_category'],
221
+				'args'       => ['new_category' => true],
222
+				'capability' => 'ee_edit_event_category',
223
+				'noheader'   => true,
224
+			],
225
+			'update_category'               => [
226
+				'func'       => [$this, '_insert_or_update_category'],
227
+				'args'       => ['new_category' => false],
228
+				'capability' => 'ee_edit_event_category',
229
+				'noheader'   => true,
230
+			],
231
+			'category_list'                 => [
232
+				'func'       => [$this, '_category_list_table'],
233
+				'capability' => 'ee_manage_event_categories',
234
+			],
235
+			'preview_deletion'              => [
236
+				'func'       => [$this, 'previewDeletion'],
237
+				'capability' => 'ee_delete_events',
238
+			],
239
+			'confirm_deletion'              => [
240
+				'func'       => [$this, 'confirmDeletion'],
241
+				'capability' => 'ee_delete_events',
242
+				'noheader'   => true,
243
+			],
244
+		];
245
+	}
246
+
247
+
248
+	/**
249
+	 * Set the _page_config property for this admin page group.
250
+	 */
251
+	protected function _set_page_config()
252
+	{
253
+		$post_id            = $this->request->getRequestParam('post', 0, DataType::INT);
254
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
255
+		$this->_page_config = [
256
+			'default'                => [
257
+				'nav'           => [
258
+					'label' => esc_html__('Overview', 'event_espresso'),
259
+					'icon'  => 'dashicons-list-view',
260
+					'order' => 10,
261
+				],
262
+				'list_table'    => 'Events_Admin_List_Table',
263
+				'help_tabs'     => [
264
+					'events_overview_help_tab'                       => [
265
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
266
+						'filename' => 'events_overview',
267
+					],
268
+					'events_overview_table_column_headings_help_tab' => [
269
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
270
+						'filename' => 'events_overview_table_column_headings',
271
+					],
272
+					'events_overview_filters_help_tab'               => [
273
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
274
+						'filename' => 'events_overview_filters',
275
+					],
276
+					'events_overview_view_help_tab'                  => [
277
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
278
+						'filename' => 'events_overview_views',
279
+					],
280
+					'events_overview_other_help_tab'                 => [
281
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
282
+						'filename' => 'events_overview_other',
283
+					],
284
+				],
285
+				'require_nonce' => false,
286
+			],
287
+			'create_new'             => [
288
+				'nav'           => [
289
+					'label'      => esc_html__('Add New Event', 'event_espresso'),
290
+					'icon'       => 'dashicons-plus-alt',
291
+					'order'      => 15,
292
+					'persistent' => false,
293
+				],
294
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
295
+				'help_tabs'     => [
296
+					'event_editor_help_tab'                            => [
297
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
298
+						'filename' => 'event_editor',
299
+					],
300
+					'event_editor_title_richtexteditor_help_tab'       => [
301
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
302
+						'filename' => 'event_editor_title_richtexteditor',
303
+					],
304
+					'event_editor_venue_details_help_tab'              => [
305
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
306
+						'filename' => 'event_editor_venue_details',
307
+					],
308
+					'event_editor_event_datetimes_help_tab'            => [
309
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
310
+						'filename' => 'event_editor_event_datetimes',
311
+					],
312
+					'event_editor_event_tickets_help_tab'              => [
313
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
314
+						'filename' => 'event_editor_event_tickets',
315
+					],
316
+					'event_editor_event_registration_options_help_tab' => [
317
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
318
+						'filename' => 'event_editor_event_registration_options',
319
+					],
320
+					'event_editor_tags_categories_help_tab'            => [
321
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
322
+						'filename' => 'event_editor_tags_categories',
323
+					],
324
+					'event_editor_questions_registrants_help_tab'      => [
325
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
326
+						'filename' => 'event_editor_questions_registrants',
327
+					],
328
+					'event_editor_save_new_event_help_tab'             => [
329
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
330
+						'filename' => 'event_editor_save_new_event',
331
+					],
332
+					'event_editor_other_help_tab'                      => [
333
+						'title'    => esc_html__('Event Other', 'event_espresso'),
334
+						'filename' => 'event_editor_other',
335
+					],
336
+				],
337
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
338
+				'require_nonce' => false,
339
+			],
340
+			'edit'                   => [
341
+				'nav'           => [
342
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
343
+					'icon'       => 'dashicons-edit',
344
+					'order'      => 15,
345
+					'persistent' => false,
346
+					'url'        => $post_id
347
+						? EE_Admin_Page::add_query_args_and_nonce(
348
+							['post' => $post_id, 'action' => 'edit'],
349
+							$this->_current_page_view_url
350
+						)
351
+						: $this->_admin_base_url,
352
+				],
353
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
354
+				'help_tabs'     => [
355
+					'event_editor_help_tab'                            => [
356
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
357
+						'filename' => 'event_editor',
358
+					],
359
+					'event_editor_title_richtexteditor_help_tab'       => [
360
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
361
+						'filename' => 'event_editor_title_richtexteditor',
362
+					],
363
+					'event_editor_venue_details_help_tab'              => [
364
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
365
+						'filename' => 'event_editor_venue_details',
366
+					],
367
+					'event_editor_event_datetimes_help_tab'            => [
368
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
369
+						'filename' => 'event_editor_event_datetimes',
370
+					],
371
+					'event_editor_event_tickets_help_tab'              => [
372
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
373
+						'filename' => 'event_editor_event_tickets',
374
+					],
375
+					'event_editor_event_registration_options_help_tab' => [
376
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
377
+						'filename' => 'event_editor_event_registration_options',
378
+					],
379
+					'event_editor_tags_categories_help_tab'            => [
380
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
381
+						'filename' => 'event_editor_tags_categories',
382
+					],
383
+					'event_editor_questions_registrants_help_tab'      => [
384
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
385
+						'filename' => 'event_editor_questions_registrants',
386
+					],
387
+					'event_editor_save_new_event_help_tab'             => [
388
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
389
+						'filename' => 'event_editor_save_new_event',
390
+					],
391
+					'event_editor_other_help_tab'                      => [
392
+						'title'    => esc_html__('Event Other', 'event_espresso'),
393
+						'filename' => 'event_editor_other',
394
+					],
395
+				],
396
+				'require_nonce' => false,
397
+			],
398
+			'default_event_settings' => [
399
+				'nav'           => [
400
+					'label' => esc_html__('Default Settings', 'event_espresso'),
401
+					'icon'  => 'dashicons-admin-generic',
402
+					'order' => 40,
403
+				],
404
+				'metaboxes'     => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes),
405
+				'labels'        => [
406
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
407
+				],
408
+				'help_tabs'     => [
409
+					'default_settings_help_tab'        => [
410
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
411
+						'filename' => 'events_default_settings',
412
+					],
413
+					'default_settings_status_help_tab' => [
414
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
415
+						'filename' => 'events_default_settings_status',
416
+					],
417
+					'default_maximum_tickets_help_tab' => [
418
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
419
+						'filename' => 'events_default_settings_max_tickets',
420
+					],
421
+				],
422
+				'require_nonce' => false,
423
+			],
424
+			// template settings
425
+			'template_settings'      => [
426
+				'nav'           => [
427
+					'label' => esc_html__('Templates', 'event_espresso'),
428
+					'icon'  => 'dashicons-layout',
429
+					'order' => 30,
430
+				],
431
+				'metaboxes'     => $this->_default_espresso_metaboxes,
432
+				'help_tabs'     => [
433
+					'general_settings_templates_help_tab' => [
434
+						'title'    => esc_html__('Templates', 'event_espresso'),
435
+						'filename' => 'general_settings_templates',
436
+					],
437
+				],
438
+				'require_nonce' => false,
439
+			],
440
+			// event category stuff
441
+			'add_category'           => [
442
+				'nav'           => [
443
+					'label'      => esc_html__('Add Category', 'event_espresso'),
444
+					'icon'       => 'dashicons-plus-alt',
445
+					'order'      => 25,
446
+					'persistent' => false,
447
+				],
448
+				'help_tabs'     => [
449
+					'add_category_help_tab' => [
450
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
451
+						'filename' => 'events_add_category',
452
+					],
453
+				],
454
+				'metaboxes'     => ['_publish_post_box'],
455
+				'require_nonce' => false,
456
+			],
457
+			'edit_category'          => [
458
+				'nav'           => [
459
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
460
+					'icon'       => 'dashicons-edit',
461
+					'order'      => 25,
462
+					'persistent' => false,
463
+					'url'        => $EVT_CAT_ID
464
+						? add_query_arg(
465
+							['EVT_CAT_ID' => $EVT_CAT_ID],
466
+							$this->_current_page_view_url
467
+						)
468
+						: $this->_admin_base_url,
469
+				],
470
+				'help_tabs'     => [
471
+					'edit_category_help_tab' => [
472
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
473
+						'filename' => 'events_edit_category',
474
+					],
475
+				],
476
+				'metaboxes'     => ['_publish_post_box'],
477
+				'require_nonce' => false,
478
+			],
479
+			'category_list'          => [
480
+				'nav'           => [
481
+					'label' => esc_html__('Categories', 'event_espresso'),
482
+					'icon'  => 'dashicons-networking',
483
+					'order' => 20,
484
+				],
485
+				'list_table'    => 'Event_Categories_Admin_List_Table',
486
+				'help_tabs'     => [
487
+					'events_categories_help_tab'                       => [
488
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
489
+						'filename' => 'events_categories',
490
+					],
491
+					'events_categories_table_column_headings_help_tab' => [
492
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
493
+						'filename' => 'events_categories_table_column_headings',
494
+					],
495
+					'events_categories_view_help_tab'                  => [
496
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
497
+						'filename' => 'events_categories_views',
498
+					],
499
+					'events_categories_other_help_tab'                 => [
500
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
501
+						'filename' => 'events_categories_other',
502
+					],
503
+				],
504
+				'metaboxes'     => $this->_default_espresso_metaboxes,
505
+				'require_nonce' => false,
506
+			],
507
+			'preview_deletion'       => [
508
+				'nav'           => [
509
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
510
+					'icon'       => 'dashicons-remove',
511
+					'order'      => 15,
512
+					'persistent' => false,
513
+					'url'        => '',
514
+				],
515
+				'require_nonce' => false,
516
+			],
517
+		];
518
+	}
519
+
520
+
521
+	/**
522
+	 * Used to register any global screen options if necessary for every route in this admin page group.
523
+	 */
524
+	protected function _add_screen_options()
525
+	{
526
+	}
527
+
528
+
529
+	/**
530
+	 * Implementing the screen options for the 'default' route.
531
+	 *
532
+	 * @throws InvalidArgumentException
533
+	 * @throws InvalidDataTypeException
534
+	 * @throws InvalidInterfaceException
535
+	 */
536
+	protected function _add_screen_options_default()
537
+	{
538
+		$this->_per_page_screen_option();
539
+	}
540
+
541
+
542
+	/**
543
+	 * Implementing screen options for the category list route.
544
+	 *
545
+	 * @throws InvalidArgumentException
546
+	 * @throws InvalidDataTypeException
547
+	 * @throws InvalidInterfaceException
548
+	 */
549
+	protected function _add_screen_options_category_list()
550
+	{
551
+		$page_title              = $this->_admin_page_title;
552
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
553
+		$this->_per_page_screen_option();
554
+		$this->_admin_page_title = $page_title;
555
+	}
556
+
557
+
558
+	/**
559
+	 * Used to register any global feature pointers for the admin page group.
560
+	 */
561
+	protected function _add_feature_pointers()
562
+	{
563
+	}
564
+
565
+
566
+	/**
567
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
568
+	 */
569
+	public function load_scripts_styles()
570
+	{
571
+		wp_register_style(
572
+			'events-admin-css',
573
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
574
+			[],
575
+			EVENT_ESPRESSO_VERSION
576
+		);
577
+		wp_register_style(
578
+			'ee-cat-admin',
579
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
580
+			[],
581
+			EVENT_ESPRESSO_VERSION
582
+		);
583
+		wp_enqueue_style('events-admin-css');
584
+		wp_enqueue_style('ee-cat-admin');
585
+		// scripts
586
+		wp_register_script(
587
+			'event_editor_js',
588
+			EVENTS_ASSETS_URL . 'event_editor.js',
589
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
590
+			EVENT_ESPRESSO_VERSION,
591
+			true
592
+		);
593
+	}
594
+
595
+
596
+	/**
597
+	 * Enqueuing scripts and styles specific to this view
598
+	 */
599
+	public function load_scripts_styles_create_new()
600
+	{
601
+		$this->load_scripts_styles_edit();
602
+	}
603
+
604
+
605
+	/**
606
+	 * Enqueuing scripts and styles specific to this view
607
+	 */
608
+	public function load_scripts_styles_edit()
609
+	{
610
+		// styles
611
+		wp_enqueue_style('espresso-ui-theme');
612
+		wp_register_style(
613
+			'event-editor-css',
614
+			EVENTS_ASSETS_URL . 'event-editor.css',
615
+			['ee-admin-css'],
616
+			EVENT_ESPRESSO_VERSION
617
+		);
618
+		wp_enqueue_style('event-editor-css');
619
+		// scripts
620
+		if (! $this->admin_config->useAdvancedEditor()) {
621
+			wp_register_script(
622
+				'event-datetime-metabox',
623
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
624
+				['event_editor_js', 'ee-datepicker'],
625
+				EVENT_ESPRESSO_VERSION
626
+			);
627
+			wp_enqueue_script('event-datetime-metabox');
628
+		}
629
+	}
630
+
631
+
632
+	/**
633
+	 * Populating the _views property for the category list table view.
634
+	 */
635
+	protected function _set_list_table_views_category_list()
636
+	{
637
+		$this->_views = [
638
+			'all' => [
639
+				'slug'        => 'all',
640
+				'label'       => esc_html__('All', 'event_espresso'),
641
+				'count'       => 0,
642
+				'bulk_action' => [
643
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
644
+				],
645
+			],
646
+		];
647
+	}
648
+
649
+
650
+	/**
651
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
652
+	 */
653
+	public function admin_init()
654
+	{
655
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
656
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
657
+			'event_espresso'
658
+		);
659
+	}
660
+
661
+
662
+	/**
663
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
664
+	 * group.
665
+	 */
666
+	public function admin_notices()
667
+	{
668
+	}
669
+
670
+
671
+	/**
672
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
673
+	 * this admin page group.
674
+	 */
675
+	public function admin_footer_scripts()
676
+	{
677
+	}
678
+
679
+
680
+	/**
681
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
682
+	 * warning (via EE_Error::add_error());
683
+	 *
684
+	 * @param EE_Event|null $event Event object
685
+	 * @param string        $req_type
686
+	 * @return void
687
+	 * @throws EE_Error
688
+	 * @throws ReflectionException
689
+	 */
690
+	public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '')
691
+	{
692
+		// don't need to do this when processing
693
+		if (! empty($req_type)) {
694
+			return;
695
+		}
696
+		// no event?
697
+		if (! $event instanceof EE_Event) {
698
+			$event = $this->_cpt_model_obj;
699
+		}
700
+		// STILL no event?
701
+		if (! $event instanceof EE_Event) {
702
+			return;
703
+		}
704
+		// don't need to keep calling this
705
+		remove_action(
706
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
707
+			[$this, 'verify_event_edit']
708
+		);
709
+		$orig_status = $event->status();
710
+		// first check if event is active.
711
+		if (
712
+			$orig_status === EEM_Event::cancelled
713
+			|| $orig_status === EEM_Event::postponed
714
+			|| $event->is_expired()
715
+			|| $event->is_inactive()
716
+		) {
717
+			return;
718
+		}
719
+		// made it here so it IS active... next check that any of the tickets are sold.
720
+		if ($event->is_sold_out(true)) {
721
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
722
+				EE_Error::add_attention(
723
+					sprintf(
724
+						esc_html__(
725
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
726
+							'event_espresso'
727
+						),
728
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
729
+					)
730
+				);
731
+			}
732
+			return;
733
+		}
734
+		if ($orig_status === EEM_Event::sold_out) {
735
+			EE_Error::add_attention(
736
+				sprintf(
737
+					esc_html__(
738
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
739
+						'event_espresso'
740
+					),
741
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
742
+				)
743
+			);
744
+		}
745
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
746
+		if (! $event->tickets_on_sale()) {
747
+			return;
748
+		}
749
+		// made it here so show warning
750
+		$this->_edit_event_warning();
751
+	}
752
+
753
+
754
+	/**
755
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
756
+	 * When needed, hook this into a EE_Error::add_error() notice.
757
+	 *
758
+	 * @access protected
759
+	 * @return void
760
+	 */
761
+	protected function _edit_event_warning()
762
+	{
763
+		// we don't want to add warnings during these requests
764
+		if ($this->request->getRequestParam('action') === 'editpost') {
765
+			return;
766
+		}
767
+		EE_Error::add_attention(
768
+			sprintf(
769
+				esc_html__(
770
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
771
+					'event_espresso'
772
+				),
773
+				'<a class="espresso-help-tab-lnk ee-help-tab-link">',
774
+				'</a>'
775
+			)
776
+		);
777
+	}
778
+
779
+
780
+	/**
781
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
782
+	 * Otherwise, do the normal logic
783
+	 *
784
+	 * @return void
785
+	 * @throws EE_Error
786
+	 * @throws InvalidArgumentException
787
+	 * @throws InvalidDataTypeException
788
+	 * @throws InvalidInterfaceException
789
+	 * @throws ReflectionException
790
+	 */
791
+	protected function _create_new_cpt_item()
792
+	{
793
+		$has_timezone_string = get_option('timezone_string');
794
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
795
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
796
+			EE_Error::add_attention(
797
+				sprintf(
798
+					esc_html__(
799
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
800
+						'event_espresso'
801
+					),
802
+					'<br>',
803
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
804
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
805
+					. '</select>',
806
+					'<button class="button button--secondary timezone-submit">',
807
+					'</button><span class="spinner"></span>'
808
+				),
809
+				__FILE__,
810
+				__FUNCTION__,
811
+				__LINE__
812
+			);
813
+		}
814
+		parent::_create_new_cpt_item();
815
+	}
816
+
817
+
818
+	/**
819
+	 * Sets the _views property for the default route in this admin page group.
820
+	 */
821
+	protected function _set_list_table_views_default()
822
+	{
823
+		$this->_views = [
824
+			'all'   => [
825
+				'slug'        => 'all',
826
+				'label'       => esc_html__('View All Events', 'event_espresso'),
827
+				'count'       => 0,
828
+				'bulk_action' => [
829
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
830
+				],
831
+			],
832
+			'draft' => [
833
+				'slug'        => 'draft',
834
+				'label'       => esc_html__('Draft', 'event_espresso'),
835
+				'count'       => 0,
836
+				'bulk_action' => [
837
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
838
+				],
839
+			],
840
+		];
841
+		if ($this->capabilities->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
842
+			$this->_views['trash'] = [
843
+				'slug'        => 'trash',
844
+				'label'       => esc_html__('Trash', 'event_espresso'),
845
+				'count'       => 0,
846
+				'bulk_action' => [
847
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
848
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
849
+				],
850
+			];
851
+		}
852
+	}
853
+
854
+
855
+	/**
856
+	 * Provides the legend item array for the default list table view.
857
+	 *
858
+	 * @return array
859
+	 * @throws EE_Error
860
+	 * @throws EE_Error
861
+	 */
862
+	protected function _event_legend_items(): array
863
+	{
864
+		$items    = [
865
+			'view_details'   => [
866
+				'class' => 'dashicons dashicons-visibility',
867
+				'desc'  => esc_html__('View Event', 'event_espresso'),
868
+			],
869
+			'edit_event'     => [
870
+				'class' => 'dashicons dashicons-calendar-alt',
871
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
872
+			],
873
+			'view_attendees' => [
874
+				'class' => 'dashicons dashicons-groups',
875
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
876
+			],
877
+		];
878
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
879
+		$statuses = [
880
+			'sold_out_status'  => [
881
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
882
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
883
+			],
884
+			'active_status'    => [
885
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
886
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
887
+			],
888
+			'upcoming_status'  => [
889
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
890
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
891
+			],
892
+			'postponed_status' => [
893
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
894
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
895
+			],
896
+			'cancelled_status' => [
897
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
898
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
899
+			],
900
+			'expired_status'   => [
901
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
902
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
903
+			],
904
+			'inactive_status'  => [
905
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
906
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
907
+			],
908
+		];
909
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
910
+		return array_merge($items, $statuses);
911
+	}
912
+
913
+
914
+	/**
915
+	 * @return EEM_Event
916
+	 * @throws EE_Error
917
+	 * @throws InvalidArgumentException
918
+	 * @throws InvalidDataTypeException
919
+	 * @throws InvalidInterfaceException
920
+	 * @throws ReflectionException
921
+	 */
922
+	private function _event_model(): EEM_Event
923
+	{
924
+		if (! $this->_event_model instanceof EEM_Event) {
925
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
926
+		}
927
+		return $this->_event_model;
928
+	}
929
+
930
+
931
+	/**
932
+	 * Adds extra buttons to the WP CPT permalink field row.
933
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
934
+	 *
935
+	 * @param string      $return    the current html
936
+	 * @param int         $id        the post id for the page
937
+	 * @param string|null $new_title What the title is
938
+	 * @param string|null $new_slug  what the slug is
939
+	 * @return string            The new html string for the permalink area
940
+	 * @deprecated 5.0.0.p
941
+	 * @see        TicketSelectorShortcodeButton::addButton
942
+	 */
943
+	public function extra_permalink_field_buttons(
944
+		string $return,
945
+		int $id,
946
+		?string $new_title,
947
+		?string $new_slug
948
+	): string {
949
+		return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug);
950
+	}
951
+
952
+
953
+	/**
954
+	 * _events_overview_list_table
955
+	 * This contains the logic for showing the events_overview list
956
+	 *
957
+	 * @access protected
958
+	 * @return void
959
+	 * @throws DomainException
960
+	 * @throws EE_Error
961
+	 * @throws InvalidArgumentException
962
+	 * @throws InvalidDataTypeException
963
+	 * @throws InvalidInterfaceException
964
+	 */
965
+	protected function _events_overview_list_table()
966
+	{
967
+		$after_list_table = [];
968
+		$links_html       = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
969
+		$links_html       .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
970
+		$links_html       .= EEH_HTML::div(
971
+			EEH_Template::get_button_or_link(
972
+				get_post_type_archive_link(EspressoPostType::EVENTS),
973
+				esc_html__('View Event Archive Page', 'event_espresso'),
974
+				'button button--small button--secondary'
975
+			),
976
+			'',
977
+			'ee-admin-button-row ee-admin-button-row--align-start'
978
+		);
979
+		$links_html       .= EEH_HTML::divx();
980
+
981
+		$after_list_table['view_event_list_button'] = $links_html;
982
+
983
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
984
+		$this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
985
+				'create_new',
986
+				'add',
987
+				[],
988
+				'add-new-h2'
989
+			);
990
+
991
+		$this->_template_args['after_list_table'] = array_merge(
992
+			(array) $this->_template_args['after_list_table'],
993
+			$after_list_table
994
+		);
995
+		$this->display_admin_list_table_page_with_no_sidebar();
996
+	}
997
+
998
+
999
+	/**
1000
+	 * this allows for extra misc actions in the default WP publish box
1001
+	 *
1002
+	 * @return void
1003
+	 * @throws DomainException
1004
+	 * @throws EE_Error
1005
+	 * @throws InvalidArgumentException
1006
+	 * @throws InvalidDataTypeException
1007
+	 * @throws InvalidInterfaceException
1008
+	 * @throws ReflectionException
1009
+	 */
1010
+	public function extra_misc_actions_publish_box()
1011
+	{
1012
+		$this->_generate_publish_box_extra_content();
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1018
+	 * saved.
1019
+	 * Typically you would use this to save any additional data.
1020
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1021
+	 * ALSO very important.  When a post transitions from scheduled to published,
1022
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1023
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1024
+	 *
1025
+	 * @access protected
1026
+	 * @abstract
1027
+	 * @param string  $post_id The ID of the cpt that was saved (so you can link relationally)
1028
+	 * @param WP_Post $post    The post object of the cpt that was saved.
1029
+	 * @return void
1030
+	 * @throws EE_Error
1031
+	 * @throws InvalidArgumentException
1032
+	 * @throws InvalidDataTypeException
1033
+	 * @throws InvalidInterfaceException
1034
+	 * @throws ReflectionException
1035
+	 */
1036
+	protected function _insert_update_cpt_item($post_id, $post)
1037
+	{
1038
+		if ($post instanceof WP_Post && $post->post_type !== EspressoPostType::EVENTS) {
1039
+			// get out we're not processing an event save.
1040
+			return;
1041
+		}
1042
+		$event_values = [
1043
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, DataType::BOOL),
1044
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, DataType::BOOL),
1045
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1046
+		];
1047
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1048
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1049
+			$event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1050
+				'display_ticket_selector',
1051
+				false,
1052
+				'bool'
1053
+			);
1054
+			$event_values['EVT_additional_limit']            = min(
1055
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1056
+				$this->request->getRequestParam(
1057
+					'additional_limit',
1058
+					EEM_Event::get_default_additional_limit(),
1059
+					'int'
1060
+				)
1061
+			);
1062
+			$event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1063
+				'EVT_default_registration_status',
1064
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1065
+			);
1066
+
1067
+			$event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1068
+			$event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1069
+			$event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, DataType::BOOL);
1070
+		} elseif ($post instanceof WP_Post) {
1071
+			$event_values['EVT_name'] = $post->post_title;
1072
+			$event_values['EVT_desc'] = $post->post_content;
1073
+		}
1074
+		// update event
1075
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1076
+		// get event_object for other metaboxes...
1077
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1078
+		// i have to setup where conditions to override the filters in the model
1079
+		// that filter out auto-draft and inherit statuses so we GET the inherit id!
1080
+		/** @var EE_Event $event */
1081
+		$event = $this->_event_model()->get_one(
1082
+			[
1083
+				[
1084
+					$this->_event_model()->primary_key_name() => $post_id,
1085
+					'OR'                                      => [
1086
+						'status'   => $post->post_status,
1087
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1088
+						// but the returned object here has a status of "publish", so use the original post status as well
1089
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1090
+					],
1091
+					'status' => ['NOT IN', ['auto-draft']],
1092
+				],
1093
+			]
1094
+		);
1095
+
1096
+		// the following are default callbacks for event attachment updates
1097
+		// that can be overridden by caffeinated functionality and/or addons.
1098
+		$event_update_callbacks = [];
1099
+		if (! $this->admin_config->useAdvancedEditor()) {
1100
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1101
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1102
+		}
1103
+		$event_update_callbacks = apply_filters(
1104
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1105
+			$event_update_callbacks
1106
+		);
1107
+
1108
+		$att_success = true;
1109
+		foreach ($event_update_callbacks as $e_callback) {
1110
+			$_success = is_callable($e_callback)
1111
+				? $e_callback($event, $this->request->requestParams())
1112
+				: false;
1113
+			// if ANY of these updates fail then we want the appropriate global error message
1114
+			$att_success = $_success !== false ? $att_success : false;
1115
+		}
1116
+		// any errors?
1117
+		if ($success && $att_success === false) {
1118
+			EE_Error::add_error(
1119
+				esc_html__(
1120
+					'Event Details saved successfully but something went wrong with saving attachments.',
1121
+					'event_espresso'
1122
+				),
1123
+				__FILE__,
1124
+				__FUNCTION__,
1125
+				__LINE__
1126
+			);
1127
+		} elseif ($success === false) {
1128
+			EE_Error::add_error(
1129
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1130
+				__FILE__,
1131
+				__FUNCTION__,
1132
+				__LINE__
1133
+			);
1134
+		}
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 * @param int $post_id
1140
+	 * @param int $revision_id
1141
+	 * @throws EE_Error
1142
+	 * @throws EE_Error
1143
+	 * @throws ReflectionException
1144
+	 * @see parent::restore_item()
1145
+	 */
1146
+	protected function _restore_cpt_item(int $post_id, int $revision_id)
1147
+	{
1148
+		// copy existing event meta to new post
1149
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1150
+		if ($post_evt instanceof EE_Event) {
1151
+			// meta revision restore
1152
+			$post_evt->restore_revision($revision_id);
1153
+			// related objs restore
1154
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1155
+		}
1156
+	}
1157
+
1158
+
1159
+	/**
1160
+	 * Attach the venue to the Event
1161
+	 *
1162
+	 * @param EE_Event $event Event Object to add the venue to
1163
+	 * @param array    $data  The request data from the form
1164
+	 * @return bool           Success or fail.
1165
+	 * @throws EE_Error
1166
+	 * @throws ReflectionException
1167
+	 */
1168
+	protected function _default_venue_update(EE_Event $event, array $data): bool
1169
+	{
1170
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1171
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1172
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1173
+		// very important.  If we don't have a venue name...
1174
+		// then we'll get out because not necessary to create empty venue
1175
+		if (empty($data['venue_title'])) {
1176
+			return false;
1177
+		}
1178
+		$venue_array = [
1179
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1180
+			'VNU_name'            => $data['venue_title'],
1181
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1182
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1183
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1184
+				? $data['venue_short_description']
1185
+				: null,
1186
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1187
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1188
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1189
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1190
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1191
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1192
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1193
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1194
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1195
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1196
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1197
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1198
+			'status'              => 'publish',
1199
+		];
1200
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1201
+		if (! empty($venue_id)) {
1202
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1203
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1204
+			// we've gotta make sure that the venue is always attached to a revision..
1205
+			// add_relation_to should take care of making sure that the relation is already present.
1206
+			$event->_add_relation_to($venue_id, 'Venue');
1207
+			return $rows_affected > 0;
1208
+		}
1209
+		// we insert the venue
1210
+		$venue_id = $venue_model->insert($venue_array);
1211
+		$event->_add_relation_to($venue_id, 'Venue');
1212
+		return ! empty($venue_id);
1213
+		// when we have the ancestor come in it's already been handled by the revision save.
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1219
+	 *
1220
+	 * @param EE_Event $event The Event object we're attaching data to
1221
+	 * @param array    $data  The request data from the form
1222
+	 * @return array
1223
+	 * @throws EE_Error
1224
+	 * @throws ReflectionException
1225
+	 * @throws Exception
1226
+	 */
1227
+	protected function _default_tickets_update(EE_Event $event, array $data): array
1228
+	{
1229
+		if ($this->admin_config->useAdvancedEditor()) {
1230
+			return [];
1231
+		}
1232
+		$datetime       = null;
1233
+		$saved_tickets  = [];
1234
+		$event_timezone = $event->get_timezone();
1235
+		$date_formats   = ['Y-m-d', 'h:i a'];
1236
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1237
+			// trim all values to ensure any excess whitespace is removed.
1238
+			$datetime_data                = array_map('trim', $datetime_data);
1239
+			$datetime_data['DTT_EVT_end'] = ! empty($datetime_data['DTT_EVT_end'])
1240
+					? $datetime_data['DTT_EVT_end']
1241
+					: $datetime_data['DTT_EVT_start'];
1242
+			$datetime_values              = [
1243
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1244
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1245
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1246
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1247
+				'DTT_order'     => $row,
1248
+			];
1249
+			// if we have an id then let's get existing object first and then set the new values.
1250
+			//  Otherwise we instantiate a new object for save.
1251
+			if (! empty($datetime_data['DTT_ID'])) {
1252
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1253
+				if (! $datetime instanceof EE_Datetime) {
1254
+					throw new RuntimeException(
1255
+						sprintf(
1256
+							esc_html__(
1257
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1258
+								'event_espresso'
1259
+							),
1260
+							$datetime_data['DTT_ID']
1261
+						)
1262
+					);
1263
+				}
1264
+				$datetime->set_date_format($date_formats[0]);
1265
+				$datetime->set_time_format($date_formats[1]);
1266
+				foreach ($datetime_values as $field => $value) {
1267
+					$datetime->set($field, $value);
1268
+				}
1269
+			} else {
1270
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1271
+			}
1272
+			if (! $datetime instanceof EE_Datetime) {
1273
+				throw new RuntimeException(
1274
+					sprintf(
1275
+						esc_html__(
1276
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1277
+							'event_espresso'
1278
+						),
1279
+						print_r($datetime_values, true)
1280
+					)
1281
+				);
1282
+			}
1283
+			// before going any further make sure our dates are setup correctly
1284
+			// so that the end date is always equal or greater than the start date.
1285
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1286
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1287
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1288
+			}
1289
+			$datetime->save();
1290
+			$event->_add_relation_to($datetime, 'Datetime');
1291
+		}
1292
+		// no datetimes get deleted so we don't do any of that logic here.
1293
+		// update tickets next
1294
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1295
+
1296
+		// set up some default start and end dates in case those are not present in the incoming data
1297
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1298
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1299
+		// use the start date of the first datetime for the end date
1300
+		$first_datetime   = $event->first_datetime();
1301
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1302
+
1303
+		// now process the incoming data
1304
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1305
+			$update_prices = false;
1306
+			$ticket_price  = $data['edit_prices'][ $row ][1]['PRC_amount'] ?? 0;
1307
+			// trim inputs to ensure any excess whitespace is removed.
1308
+			$ticket_data   = array_map('trim', $ticket_data);
1309
+			$ticket_values = [
1310
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1311
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1312
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1313
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1314
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1315
+					? $ticket_data['TKT_start_date']
1316
+					: $default_start_date,
1317
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1318
+					? $ticket_data['TKT_end_date']
1319
+					: $default_end_date,
1320
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1321
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1322
+					? $ticket_data['TKT_qty']
1323
+					: EE_INF,
1324
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1325
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1326
+					? $ticket_data['TKT_uses']
1327
+					: EE_INF,
1328
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1329
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1330
+				'TKT_order'       => $ticket_data['TKT_order'] ?? $row,
1331
+				'TKT_price'       => $ticket_price,
1332
+				'TKT_row'         => $row,
1333
+			];
1334
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1335
+			// which means in turn that the prices will become new prices as well.
1336
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1337
+				$ticket_values['TKT_ID']         = 0;
1338
+				$ticket_values['TKT_is_default'] = 0;
1339
+				$update_prices                   = true;
1340
+			}
1341
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1342
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1343
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1344
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1345
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1346
+			if (! empty($ticket_data['TKT_ID'])) {
1347
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1348
+				if (! $existing_ticket instanceof EE_Ticket) {
1349
+					throw new RuntimeException(
1350
+						sprintf(
1351
+							esc_html__(
1352
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1353
+								'event_espresso'
1354
+							),
1355
+							$ticket_data['TKT_ID']
1356
+						)
1357
+					);
1358
+				}
1359
+				$ticket_sold = $existing_ticket->count_related(
1360
+						'Registration',
1361
+						[
1362
+							[
1363
+								'STS_ID' => [
1364
+									'NOT IN',
1365
+									[EEM_Registration::status_id_incomplete],
1366
+								],
1367
+							],
1368
+						]
1369
+					) > 0;
1370
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1371
+				// if they are different then we create a new ticket (if $ticket_sold)
1372
+				// if they aren't different then we go ahead and modify existing ticket.
1373
+				$create_new_ticket = $ticket_sold
1374
+									 && $ticket_price !== $existing_ticket->price()
1375
+									 && ! $existing_ticket->deleted();
1376
+				$existing_ticket->set_date_format($date_formats[0]);
1377
+				$existing_ticket->set_time_format($date_formats[1]);
1378
+				// set new values
1379
+				foreach ($ticket_values as $field => $value) {
1380
+					if ($field == 'TKT_qty') {
1381
+						$existing_ticket->set_qty($value);
1382
+					} elseif ($field == 'TKT_price') {
1383
+						$existing_ticket->set('TKT_price', $ticket_price);
1384
+					} else {
1385
+						$existing_ticket->set($field, $value);
1386
+					}
1387
+				}
1388
+				$ticket = $existing_ticket;
1389
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1390
+				//  Otherwise we have to create a new ticket.
1391
+				if ($create_new_ticket) {
1392
+					// archive the old ticket first
1393
+					$existing_ticket->set('TKT_deleted', 1);
1394
+					$existing_ticket->save();
1395
+					// make sure this ticket is still recorded in our $saved_tickets
1396
+					// so we don't run it through the regular trash routine.
1397
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1398
+					// create new ticket that's a copy of the existing except,
1399
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1400
+					$new_ticket = clone $existing_ticket;
1401
+					$new_ticket->set('TKT_ID', 0);
1402
+					$new_ticket->set('TKT_deleted', 0);
1403
+					$new_ticket->set('TKT_sold', 0);
1404
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1405
+					$update_prices = true;
1406
+					$ticket        = $new_ticket;
1407
+				}
1408
+			} else {
1409
+				// no TKT_id so a new ticket
1410
+				$ticket_values['TKT_price'] = $ticket_price;
1411
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1412
+				$update_prices              = true;
1413
+			}
1414
+			if (! $ticket instanceof EE_Ticket) {
1415
+				throw new RuntimeException(
1416
+					sprintf(
1417
+						esc_html__(
1418
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1419
+							'event_espresso'
1420
+						),
1421
+						print_r($ticket_values, true)
1422
+					)
1423
+				);
1424
+			}
1425
+			// cap ticket qty by datetime reg limits
1426
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1427
+			// update ticket.
1428
+			$ticket->save();
1429
+			// before going any further make sure our dates are setup correctly
1430
+			// so that the end date is always equal or greater than the start date.
1431
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1432
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1433
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1434
+				$ticket->save();
1435
+			}
1436
+			// initially let's add the ticket to the datetime
1437
+			$datetime->_add_relation_to($ticket, 'Ticket');
1438
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1439
+			// add prices to ticket
1440
+			$prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1441
+				? $data['edit_prices'][ $row ]
1442
+				: [];
1443
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1444
+		}
1445
+		// however now we need to handle permanently deleting tickets via the ui.
1446
+		// Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1447
+		// However, it does allow for deleting tickets that have no tickets sold,
1448
+		// in which case we want to get rid of permanently because there is no need to save in db.
1449
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1450
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1451
+		foreach ($tickets_removed as $id) {
1452
+			$id = absint($id);
1453
+			// get the ticket for this id
1454
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1455
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1456
+				continue;
1457
+			}
1458
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1459
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1460
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1461
+			foreach ($related_datetimes as $related_datetime) {
1462
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1463
+			}
1464
+			// need to do the same for prices (except these prices can also be deleted because again,
1465
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1466
+			$ticket_to_remove->delete_related_permanently('Price');
1467
+			// finally let's delete this ticket
1468
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1469
+			$ticket_to_remove->delete_permanently();
1470
+		}
1471
+		return [$datetime, $saved_tickets];
1472
+	}
1473
+
1474
+
1475
+	/**
1476
+	 * This attaches a list of given prices to a ticket.
1477
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1478
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1479
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1480
+	 *
1481
+	 * @access  private
1482
+	 * @param array     $prices_data Array of prices from the form.
1483
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1484
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1485
+	 * @return  void
1486
+	 * @throws EE_Error
1487
+	 * @throws ReflectionException
1488
+	 */
1489
+	private function _add_prices_to_ticket(array $prices_data, EE_Ticket $ticket, bool $new_prices = false)
1490
+	{
1491
+		$timezone = $ticket->get_timezone();
1492
+		foreach ($prices_data as $row => $price_data) {
1493
+			$price_values = [
1494
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1495
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1496
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1497
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1498
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1499
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1500
+				'PRC_order'      => $row,
1501
+			];
1502
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1503
+				$price_values['PRC_ID'] = 0;
1504
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1505
+			} else {
1506
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1507
+				// update this price with new values
1508
+				foreach ($price_values as $field => $new_price) {
1509
+					$price->set($field, $new_price);
1510
+				}
1511
+			}
1512
+			if (! $price instanceof EE_Price) {
1513
+				throw new RuntimeException(
1514
+					sprintf(
1515
+						esc_html__(
1516
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1517
+							'event_espresso'
1518
+						),
1519
+						print_r($price_values, true)
1520
+					)
1521
+				);
1522
+			}
1523
+			$price->save();
1524
+			$ticket->_add_relation_to($price, 'Price');
1525
+		}
1526
+	}
1527
+
1528
+
1529
+	/**
1530
+	 * Add in our autosave ajax handlers
1531
+	 */
1532
+	protected function _ee_autosave_create_new()
1533
+	{
1534
+	}
1535
+
1536
+
1537
+	/**
1538
+	 * More autosave handlers.
1539
+	 */
1540
+	protected function _ee_autosave_edit()
1541
+	{
1542
+	}
1543
+
1544
+
1545
+	/**
1546
+	 * @throws EE_Error
1547
+	 * @throws ReflectionException
1548
+	 */
1549
+	private function _generate_publish_box_extra_content()
1550
+	{
1551
+		// load formatter helper
1552
+		// args for getting related registrations
1553
+		$approved_query_args        = [
1554
+			[
1555
+				'REG_deleted' => 0,
1556
+				'STS_ID'      => EEM_Registration::status_id_approved,
1557
+			],
1558
+		];
1559
+		$not_approved_query_args    = [
1560
+			[
1561
+				'REG_deleted' => 0,
1562
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1563
+			],
1564
+		];
1565
+		$pending_payment_query_args = [
1566
+			[
1567
+				'REG_deleted' => 0,
1568
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1569
+			],
1570
+		];
1571
+		// publish box
1572
+		$publish_box_extra_args = [
1573
+			'view_approved_reg_url'        => add_query_arg(
1574
+				[
1575
+					'action'      => 'default',
1576
+					'event_id'    => $this->_cpt_model_obj->ID(),
1577
+					'_reg_status' => EEM_Registration::status_id_approved,
1578
+					'use_filters' => true,
1579
+				],
1580
+				REG_ADMIN_URL
1581
+			),
1582
+			'view_not_approved_reg_url'    => add_query_arg(
1583
+				[
1584
+					'action'      => 'default',
1585
+					'event_id'    => $this->_cpt_model_obj->ID(),
1586
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1587
+					'use_filters' => true,
1588
+				],
1589
+				REG_ADMIN_URL
1590
+			),
1591
+			'view_pending_payment_reg_url' => add_query_arg(
1592
+				[
1593
+					'action'      => 'default',
1594
+					'event_id'    => $this->_cpt_model_obj->ID(),
1595
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1596
+					'use_filters' => true,
1597
+				],
1598
+				REG_ADMIN_URL
1599
+			),
1600
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1601
+				'Registration',
1602
+				$approved_query_args
1603
+			),
1604
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1605
+				'Registration',
1606
+				$not_approved_query_args
1607
+			),
1608
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1609
+				'Registration',
1610
+				$pending_payment_query_args
1611
+			),
1612
+			'misc_pub_section_class'       => apply_filters(
1613
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1614
+				'misc-pub-section'
1615
+			),
1616
+		];
1617
+		ob_start();
1618
+		do_action(
1619
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1620
+			$this->_cpt_model_obj
1621
+		);
1622
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1623
+		// load template
1624
+		EEH_Template::display_template(
1625
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1626
+			$publish_box_extra_args
1627
+		);
1628
+	}
1629
+
1630
+
1631
+	/**
1632
+	 * @return EE_Event
1633
+	 */
1634
+	public function get_event_object()
1635
+	{
1636
+		return $this->_cpt_model_obj;
1637
+	}
1638
+
1639
+
1640
+
1641
+
1642
+	/** METABOXES * */
1643
+	/**
1644
+	 * _register_event_editor_meta_boxes
1645
+	 * add all metaboxes related to the event_editor
1646
+	 *
1647
+	 * @return void
1648
+	 * @throws EE_Error
1649
+	 * @throws ReflectionException
1650
+	 */
1651
+	protected function _register_event_editor_meta_boxes()
1652
+	{
1653
+		$this->verify_cpt_object();
1654
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1655
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1656
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1657
+			$this->addMetaBox(
1658
+				'espresso_event_editor_event_options',
1659
+				esc_html__('Event Registration Options', 'event_espresso'),
1660
+				[$this, 'registration_options_meta_box'],
1661
+				$this->page_slug,
1662
+				'side'
1663
+			);
1664
+		}
1665
+		if (! $use_advanced_editor) {
1666
+			$this->addMetaBox(
1667
+				'espresso_event_editor_tickets',
1668
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1669
+				[$this, 'ticket_metabox'],
1670
+				$this->page_slug,
1671
+				'normal',
1672
+				'high'
1673
+			);
1674
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1675
+			add_action(
1676
+				'add_meta_boxes_espresso_events',
1677
+				function () {
1678
+					global $current_screen;
1679
+					remove_meta_box('authordiv', $current_screen, 'normal');
1680
+				},
1681
+				99
1682
+			);
1683
+		}
1684
+		// NOTE: if you're looking for other metaboxes in here,
1685
+		// where a metabox has a related management page in the admin
1686
+		// you will find it setup in the related management page's "_Hooks" file.
1687
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1688
+	}
1689
+
1690
+
1691
+	/**
1692
+	 * @throws DomainException
1693
+	 * @throws EE_Error
1694
+	 * @throws ReflectionException
1695
+	 */
1696
+	public function ticket_metabox()
1697
+	{
1698
+		$existing_datetime_ids = $existing_ticket_ids = [];
1699
+		// defaults for template args
1700
+		$template_args = [
1701
+			'ticket_rows'       => '',
1702
+			'total_ticket_rows' => 1,
1703
+			'trash_icon'        => 'dashicons dashicons-lock',
1704
+			'disabled'          => '',
1705
+		];
1706
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1707
+		/**
1708
+		 * 1. Start with retrieving Datetimes
1709
+		 * 2. Fore each datetime get related tickets
1710
+		 * 3. For each ticket get related prices
1711
+		 */
1712
+		/** @var EEM_Datetime $datetime_model */
1713
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1714
+		/** @var EEM_Ticket $datetime_model */
1715
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1716
+		$times        = $datetime_model->get_all_event_dates($event_id);
1717
+		/** @type EE_Datetime $first_datetime */
1718
+		$first_datetime = reset($times);
1719
+		// do we get related tickets?
1720
+		if (
1721
+			$first_datetime instanceof EE_Datetime
1722
+			&& $first_datetime->ID() !== 0
1723
+		) {
1724
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1725
+			$template_args['time']   = $first_datetime;
1726
+			$related_tickets         = $first_datetime->tickets(
1727
+				[
1728
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1729
+					'default_where_conditions' => 'none',
1730
+				]
1731
+			);
1732
+			if (! empty($related_tickets)) {
1733
+				$template_args['total_ticket_rows'] = count($related_tickets);
1734
+				$row                                = 0;
1735
+				foreach ($related_tickets as $ticket) {
1736
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1737
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1738
+					$row++;
1739
+				}
1740
+			} else {
1741
+				$template_args['total_ticket_rows'] = 1;
1742
+				/** @type EE_Ticket $ticket */
1743
+				$ticket                       = $ticket_model->create_default_object();
1744
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1745
+			}
1746
+		} else {
1747
+			$template_args['time'] = $times[0];
1748
+			/** @type EE_Ticket[] $tickets */
1749
+			$tickets                      = $ticket_model->get_all_default_tickets();
1750
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1751
+			// NOTE: we're just sending the first default row
1752
+			// (decaf can't manage default tickets so this should be sufficient);
1753
+		}
1754
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1755
+			'event_editor_event_datetimes_help_tab'
1756
+		);
1757
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1758
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1759
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1760
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1761
+			$ticket_model->create_default_object(),
1762
+			true
1763
+		);
1764
+		$template                                  = apply_filters(
1765
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1766
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1767
+		);
1768
+		EEH_Template::display_template($template, $template_args);
1769
+	}
1770
+
1771
+
1772
+	/**
1773
+	 * Setup an individual ticket form for the decaf event editor page
1774
+	 *
1775
+	 * @access private
1776
+	 * @param EE_Ticket $ticket   the ticket object
1777
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1778
+	 * @param int       $row
1779
+	 * @return string generated html for the ticket row.
1780
+	 * @throws EE_Error
1781
+	 * @throws ReflectionException
1782
+	 */
1783
+	private function _get_ticket_row(EE_Ticket $ticket, bool $skeleton = false, int $row = 0): string
1784
+	{
1785
+		$template_args = [
1786
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1787
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1788
+				: '',
1789
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1790
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1791
+			'TKT_name'            => $ticket->get('TKT_name'),
1792
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1793
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1794
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1795
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1796
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1797
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1798
+			'trash_icon'          => ($skeleton || (! $ticket->get('TKT_deleted')))
1799
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1800
+				? 'dashicons dashicons-post-trash clickable'
1801
+				: 'dashicons dashicons-lock',
1802
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1803
+				: ' disabled=disabled',
1804
+		];
1805
+		$price         = $ticket->ID() !== 0
1806
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1807
+			: null;
1808
+		$price         = $price instanceof EE_Price
1809
+			? $price
1810
+			: EEM_Price::instance()->create_default_object();
1811
+		$price_args    = [
1812
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1813
+			'PRC_amount'            => $price->get('PRC_amount'),
1814
+			'PRT_ID'                => $price->get('PRT_ID'),
1815
+			'PRC_ID'                => $price->get('PRC_ID'),
1816
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1817
+		];
1818
+		// make sure we have default start and end dates if skeleton
1819
+		// handle rows that should NOT be empty
1820
+		if (empty($template_args['TKT_start_date'])) {
1821
+			// if empty then the start date will be now.
1822
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1823
+		}
1824
+		if (empty($template_args['TKT_end_date'])) {
1825
+			// get the earliest datetime (if present);
1826
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1827
+				? $this->_cpt_model_obj->get_first_related(
1828
+					'Datetime',
1829
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1830
+				)
1831
+				: null;
1832
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1833
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1834
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1835
+		}
1836
+		$template_args = array_merge($template_args, $price_args);
1837
+		$template      = apply_filters(
1838
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1839
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1840
+			$ticket
1841
+		);
1842
+		return EEH_Template::display_template($template, $template_args, true);
1843
+	}
1844
+
1845
+
1846
+	/**
1847
+	 * @throws EE_Error
1848
+	 * @throws ReflectionException
1849
+	 */
1850
+	public function registration_options_meta_box()
1851
+	{
1852
+		$yes_no_values             = [
1853
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1854
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1855
+		];
1856
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1857
+			[
1858
+				EEM_Registration::status_id_cancelled,
1859
+				EEM_Registration::status_id_declined,
1860
+				EEM_Registration::status_id_incomplete,
1861
+			],
1862
+			true
1863
+		);
1864
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1865
+		$template_args['_event']                          = $this->_cpt_model_obj;
1866
+		$template_args['event']                           = $this->_cpt_model_obj;
1867
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1868
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1869
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1870
+			'default_reg_status',
1871
+			$default_reg_status_values,
1872
+			$this->_cpt_model_obj->default_registration_status(),
1873
+			'',
1874
+			'ee-input-width--reg',
1875
+			false
1876
+		);
1877
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1878
+			'display_desc',
1879
+			$yes_no_values,
1880
+			$this->_cpt_model_obj->display_description()
1881
+		);
1882
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1883
+			'display_ticket_selector',
1884
+			$yes_no_values,
1885
+			$this->_cpt_model_obj->display_ticket_selector(),
1886
+			'',
1887
+			'ee-input-width--small',
1888
+			false
1889
+		);
1890
+		$template_args['additional_registration_options'] = apply_filters(
1891
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1892
+			'',
1893
+			$template_args,
1894
+			$yes_no_values,
1895
+			$default_reg_status_values
1896
+		);
1897
+		EEH_Template::display_template(
1898
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1899
+			$template_args
1900
+		);
1901
+	}
1902
+
1903
+
1904
+	/**
1905
+	 * _get_events()
1906
+	 * This method simply returns all the events (for the given _view and paging)
1907
+	 *
1908
+	 * @access public
1909
+	 * @param int  $per_page     count of items per page (20 default);
1910
+	 * @param int  $current_page what is the current page being viewed.
1911
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1912
+	 *                           If FALSE then we return an array of event objects
1913
+	 *                           that match the given _view and paging parameters.
1914
+	 * @return array|int         an array of event objects or a count of them.
1915
+	 * @throws Exception
1916
+	 */
1917
+	public function get_events(int $per_page = 10, int $current_page = 1, bool $count = false)
1918
+	{
1919
+		$EEM_Event   = $this->_event_model();
1920
+		$offset      = ($current_page - 1) * $per_page;
1921
+		$limit       = $count ? null : $offset . ',' . $per_page;
1922
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1923
+		$order       = $this->request->getRequestParam('order', 'DESC');
1924
+		$month_range = $this->request->getRequestParam('month_range');
1925
+		if ($month_range) {
1926
+			$pieces = explode(' ', $month_range, 3);
1927
+			// simulate the FIRST day of the month, that fixes issues for months like February
1928
+			// where PHP doesn't know what to assume for date.
1929
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1930
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1931
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1932
+		}
1933
+		$where  = [];
1934
+		$status = $this->request->getRequestParam('status');
1935
+		// determine what post_status our condition will have for the query.
1936
+		switch ($status) {
1937
+			case 'month':
1938
+			case 'today':
1939
+			case null:
1940
+			case 'all':
1941
+				break;
1942
+			case 'draft':
1943
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1944
+				break;
1945
+			default:
1946
+				$where['status'] = $status;
1947
+		}
1948
+		// categories? The default for all categories is -1
1949
+		$category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INT);
1950
+		if ($category !== -1) {
1951
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1952
+			$where['Term_Taxonomy.term_id']  = $category;
1953
+		}
1954
+		// date where conditions
1955
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1956
+		if ($month_range) {
1957
+			$DateTime = new DateTime(
1958
+				$year_r . '-' . $month_r . '-01 00:00:00',
1959
+				new DateTimeZone('UTC')
1960
+			);
1961
+			$start    = $DateTime->getTimestamp();
1962
+			// set the datetime to be the end of the month
1963
+			$DateTime->setDate(
1964
+				$year_r,
1965
+				$month_r,
1966
+				$DateTime->format('t')
1967
+			)->setTime(23, 59, 59);
1968
+			$end                             = $DateTime->getTimestamp();
1969
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1970
+		} elseif ($status === 'today') {
1971
+			$DateTime                        = new DateTime(
1972
+				'now',
1973
+				new DateTimeZone(EEM_Event::instance()->get_timezone())
1974
+			);
1975
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1976
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1977
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1978
+		} elseif ($status === 'month') {
1979
+			$now                             = date('Y-m-01');
1980
+			$DateTime                        = new DateTime(
1981
+				$now,
1982
+				new DateTimeZone(EEM_Event::instance()->get_timezone())
1983
+			);
1984
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1985
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1986
+														->setTime(23, 59, 59)
1987
+														->format(implode(' ', $start_formats));
1988
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1989
+		}
1990
+		if (! $this->capabilities->current_user_can('ee_read_others_events', 'get_events')) {
1991
+			$where['EVT_wp_user'] = get_current_user_id();
1992
+		} else {
1993
+			if (! isset($where['status'])) {
1994
+				if (! $this->capabilities->current_user_can('ee_read_private_events', 'get_events')) {
1995
+					$where['OR'] = [
1996
+						'status*restrict_private' => ['!=', 'private'],
1997
+						'AND'                     => [
1998
+							'status*inclusive' => ['=', 'private'],
1999
+							'EVT_wp_user'      => get_current_user_id(),
2000
+						],
2001
+					];
2002
+				}
2003
+			}
2004
+		}
2005
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, DataType::INT);
2006
+		if (
2007
+			$wp_user
2008
+			&& $wp_user !== get_current_user_id()
2009
+			&& $this->capabilities->current_user_can('ee_read_others_events', 'get_events')
2010
+		) {
2011
+			$where['EVT_wp_user'] = $wp_user;
2012
+		}
2013
+		// search query handling
2014
+		$search_term = $this->request->getRequestParam('s');
2015
+		if ($search_term) {
2016
+			$search_term = '%' . $search_term . '%';
2017
+			$where['OR'] = [
2018
+				'EVT_name'       => ['LIKE', $search_term],
2019
+				'EVT_desc'       => ['LIKE', $search_term],
2020
+				'EVT_short_desc' => ['LIKE', $search_term],
2021
+			];
2022
+		}
2023
+		// filter events by venue.
2024
+		$venue = $this->request->getRequestParam('venue', 0, DataType::INT);
2025
+		if ($venue) {
2026
+			$where['Venue.VNU_ID'] = $venue;
2027
+		}
2028
+		$request_params = $this->request->requestParams();
2029
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2030
+		$query_params   = apply_filters(
2031
+			'FHEE__Events_Admin_Page__get_events__query_params',
2032
+			[
2033
+				$where,
2034
+				'limit'    => $limit,
2035
+				'order_by' => $orderby,
2036
+				'order'    => $order,
2037
+				'group_by' => 'EVT_ID',
2038
+			],
2039
+			$request_params
2040
+		);
2041
+
2042
+		// let's first check if we have special requests coming in.
2043
+		$active_status = $this->request->getRequestParam('active_status');
2044
+		if ($active_status) {
2045
+			switch ($active_status) {
2046
+				case 'upcoming':
2047
+					return $EEM_Event->get_upcoming_events($query_params, $count);
2048
+				case 'expired':
2049
+					return $EEM_Event->get_expired_events($query_params, $count);
2050
+				case 'active':
2051
+					return $EEM_Event->get_active_events($query_params, $count);
2052
+				case 'inactive':
2053
+					return $EEM_Event->get_inactive_events($query_params, $count);
2054
+			}
2055
+		}
2056
+
2057
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2058
+	}
2059
+
2060
+
2061
+	/**
2062
+	 * handling for WordPress CPT actions (trash, restore, delete)
2063
+	 *
2064
+	 * @param string $post_id
2065
+	 * @throws EE_Error
2066
+	 * @throws ReflectionException
2067
+	 */
2068
+	public function trash_cpt_item($post_id)
2069
+	{
2070
+		$this->request->setRequestParam('EVT_ID', $post_id);
2071
+		$this->_trash_or_restore_event('trash', false);
2072
+	}
2073
+
2074
+
2075
+	/**
2076
+	 * @param string $post_id
2077
+	 * @throws EE_Error
2078
+	 * @throws ReflectionException
2079
+	 */
2080
+	public function restore_cpt_item($post_id)
2081
+	{
2082
+		$this->request->setRequestParam('EVT_ID', $post_id);
2083
+		$this->_trash_or_restore_event('draft', false);
2084
+	}
2085
+
2086
+
2087
+	/**
2088
+	 * @param string $post_id
2089
+	 * @throws EE_Error
2090
+	 * @throws EE_Error
2091
+	 */
2092
+	public function delete_cpt_item($post_id)
2093
+	{
2094
+		throw new EE_Error(
2095
+			esc_html__(
2096
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2097
+				'event_espresso'
2098
+			)
2099
+		);
2100
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2101
+		// $this->_delete_event();
2102
+	}
2103
+
2104
+
2105
+	/**
2106
+	 * _trash_or_restore_event
2107
+	 *
2108
+	 * @access protected
2109
+	 * @param string $event_status
2110
+	 * @param bool   $redirect_after
2111
+	 * @throws EE_Error
2112
+	 * @throws EE_Error
2113
+	 * @throws ReflectionException
2114
+	 */
2115
+	protected function _trash_or_restore_event(string $event_status = 'trash', bool $redirect_after = true)
2116
+	{
2117
+		// loop thru events
2118
+		if ($this->EVT_ID) {
2119
+			// clean status
2120
+			$event_status = sanitize_key($event_status);
2121
+			// grab status
2122
+			if (! empty($event_status)) {
2123
+				$success = $this->_change_event_status($this->EVT_ID, $event_status);
2124
+			} else {
2125
+				$success = false;
2126
+				$msg     = esc_html__(
2127
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2128
+					'event_espresso'
2129
+				);
2130
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2131
+			}
2132
+		} else {
2133
+			$success = false;
2134
+			$msg     = esc_html__(
2135
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2136
+				'event_espresso'
2137
+			);
2138
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2139
+		}
2140
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2141
+		if ($redirect_after) {
2142
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2143
+		}
2144
+	}
2145
+
2146
+
2147
+	/**
2148
+	 * _trash_or_restore_events
2149
+	 *
2150
+	 * @access protected
2151
+	 * @param string $event_status
2152
+	 * @return void
2153
+	 * @throws EE_Error
2154
+	 * @throws EE_Error
2155
+	 * @throws ReflectionException
2156
+	 */
2157
+	protected function _trash_or_restore_events(string $event_status = 'trash')
2158
+	{
2159
+		// clean status
2160
+		$event_status = sanitize_key($event_status);
2161
+		// grab status
2162
+		if (! empty($event_status)) {
2163
+			$success = true;
2164
+			// determine the event id and set to array.
2165
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2166
+			// loop thru events
2167
+			foreach ($EVT_IDs as $EVT_ID) {
2168
+				if ($EVT_ID = absint($EVT_ID)) {
2169
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2170
+					$success = $results !== false ? $success : false;
2171
+				} else {
2172
+					$msg = sprintf(
2173
+						esc_html__(
2174
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2175
+							'event_espresso'
2176
+						),
2177
+						$EVT_ID
2178
+					);
2179
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2180
+					$success = false;
2181
+				}
2182
+			}
2183
+		} else {
2184
+			$success = false;
2185
+			$msg     = esc_html__(
2186
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2187
+				'event_espresso'
2188
+			);
2189
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2190
+		}
2191
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2192
+		$success = $success ? 2 : false;
2193
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2194
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2195
+	}
2196
+
2197
+
2198
+	/**
2199
+	 * @param int    $EVT_ID
2200
+	 * @param string $event_status
2201
+	 * @return bool
2202
+	 * @throws EE_Error
2203
+	 * @throws ReflectionException
2204
+	 */
2205
+	private function _change_event_status(int $EVT_ID = 0, string $event_status = ''): bool
2206
+	{
2207
+		// grab event id
2208
+		if (! $EVT_ID) {
2209
+			$msg = esc_html__(
2210
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2211
+				'event_espresso'
2212
+			);
2213
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2214
+			return false;
2215
+		}
2216
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2217
+		// clean status
2218
+		$event_status = sanitize_key($event_status);
2219
+		// grab status
2220
+		if (empty($event_status)) {
2221
+			$msg = esc_html__(
2222
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2223
+				'event_espresso'
2224
+			);
2225
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2226
+			return false;
2227
+		}
2228
+		// was event trashed or restored ?
2229
+		switch ($event_status) {
2230
+			case 'draft':
2231
+				$action = 'restored from the trash';
2232
+				$hook   = 'AHEE_event_restored_from_trash';
2233
+				break;
2234
+			case 'trash':
2235
+				$action = 'moved to the trash';
2236
+				$hook   = 'AHEE_event_moved_to_trash';
2237
+				break;
2238
+			default:
2239
+				$action = 'updated';
2240
+				$hook   = false;
2241
+		}
2242
+		// use class to change status
2243
+		$this->_cpt_model_obj->set_status($event_status);
2244
+		$success = $this->_cpt_model_obj->save();
2245
+		if (! $success) {
2246
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2247
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2248
+			return false;
2249
+		}
2250
+		if ($hook) {
2251
+			do_action($hook);
2252
+			// fake the action hook in EE_Soft_Delete_Base_Class::delete_or_restore()
2253
+			// because events side step that and it otherwise won't get called
2254
+			do_action(
2255
+				'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after',
2256
+				$this->_cpt_model_obj,
2257
+				$hook === 'AHEE_event_moved_to_trash',
2258
+				$success
2259
+			);
2260
+		}
2261
+		return true;
2262
+	}
2263
+
2264
+
2265
+	/**
2266
+	 * @param array $event_ids
2267
+	 * @return array
2268
+	 * @since   4.10.23.p
2269
+	 */
2270
+	private function cleanEventIds(array $event_ids): array
2271
+	{
2272
+		return array_map('absint', $event_ids);
2273
+	}
2274
+
2275
+
2276
+	/**
2277
+	 * @return array
2278
+	 * @since   4.10.23.p
2279
+	 */
2280
+	private function getEventIdsFromRequest(): array
2281
+	{
2282
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2283
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2284
+		} else {
2285
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2286
+		}
2287
+	}
2288
+
2289
+
2290
+	/**
2291
+	 * @param bool $preview_delete
2292
+	 * @throws EE_Error
2293
+	 * @throws ReflectionException
2294
+	 */
2295
+	protected function _delete_event(bool $preview_delete = true)
2296
+	{
2297
+		$this->_delete_events($preview_delete);
2298
+	}
2299
+
2300
+
2301
+	/**
2302
+	 * Gets the tree traversal batch persister.
2303
+	 *
2304
+	 * @return NodeGroupDao
2305
+	 * @throws InvalidArgumentException
2306
+	 * @throws InvalidDataTypeException
2307
+	 * @throws InvalidInterfaceException
2308
+	 * @since 4.10.12.p
2309
+	 */
2310
+	protected function getModelObjNodeGroupPersister(): NodeGroupDao
2311
+	{
2312
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2313
+			$this->model_obj_node_group_persister =
2314
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2315
+		}
2316
+		return $this->model_obj_node_group_persister;
2317
+	}
2318
+
2319
+
2320
+	/**
2321
+	 * @param bool $preview_delete
2322
+	 * @return void
2323
+	 * @throws EE_Error
2324
+	 * @throws ReflectionException
2325
+	 */
2326
+	protected function _delete_events(bool $preview_delete = true)
2327
+	{
2328
+		$event_ids = $this->getEventIdsFromRequest();
2329
+		if ($preview_delete) {
2330
+			$this->generateDeletionPreview($event_ids);
2331
+		} else {
2332
+			foreach ($event_ids as $event_id) {
2333
+				$event = EEM_Event::instance()->get_one_by_ID($event_id);
2334
+				if ($event instanceof EE_Event) {
2335
+					$event->delete_permanently();
2336
+				}
2337
+			}
2338
+		}
2339
+	}
2340
+
2341
+
2342
+	/**
2343
+	 * @param array $event_ids
2344
+	 */
2345
+	protected function generateDeletionPreview(array $event_ids)
2346
+	{
2347
+		$event_ids = $this->cleanEventIds($event_ids);
2348
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2349
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2350
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2351
+			[
2352
+				'action'            => 'preview_deletion',
2353
+				'deletion_job_code' => $deletion_job_code,
2354
+			],
2355
+			$this->_admin_base_url
2356
+		);
2357
+		EEH_URL::safeRedirectAndExit(
2358
+			EE_Admin_Page::add_query_args_and_nonce(
2359
+				[
2360
+					'page'              => EED_Batch::PAGE_SLUG,
2361
+					'batch'             => EED_Batch::batch_job,
2362
+					'EVT_IDs'           => $event_ids,
2363
+					'deletion_job_code' => $deletion_job_code,
2364
+					'job_handler'       => urlencode('EventEspresso\core\libraries\batch\JobHandlers\PreviewEventDeletion'),
2365
+					'return_url'        => urlencode($return_url),
2366
+				],
2367
+				admin_url()
2368
+			)
2369
+		);
2370
+	}
2371
+
2372
+
2373
+	/**
2374
+	 * Checks for a POST submission
2375
+	 *
2376
+	 * @since 4.10.12.p
2377
+	 */
2378
+	protected function confirmDeletion()
2379
+	{
2380
+		$deletion_redirect_logic = $this->getLoader()->getShared(
2381
+			'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'
2382
+		);
2383
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2384
+	}
2385
+
2386
+
2387
+	/**
2388
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2389
+	 *
2390
+	 * @throws EE_Error
2391
+	 * @since 4.10.12.p
2392
+	 */
2393
+	protected function previewDeletion()
2394
+	{
2395
+		$preview_deletion_logic = $this->getLoader()->getShared(
2396
+			'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'
2397
+		);
2398
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2399
+		$this->display_admin_page_with_no_sidebar();
2400
+	}
2401
+
2402
+
2403
+	/**
2404
+	 * get total number of events
2405
+	 *
2406
+	 * @access public
2407
+	 * @return int
2408
+	 * @throws EE_Error
2409
+	 * @throws EE_Error
2410
+	 * @throws ReflectionException
2411
+	 */
2412
+	public function total_events(): int
2413
+	{
2414
+		return EEM_Event::instance()->count(
2415
+			['caps' => 'read_admin'],
2416
+			'EVT_ID',
2417
+			true
2418
+		);
2419
+	}
2420
+
2421
+
2422
+	/**
2423
+	 * get total number of draft events
2424
+	 *
2425
+	 * @access public
2426
+	 * @return int
2427
+	 * @throws EE_Error
2428
+	 * @throws EE_Error
2429
+	 * @throws ReflectionException
2430
+	 */
2431
+	public function total_events_draft(): int
2432
+	{
2433
+		return EEM_Event::instance()->count(
2434
+			[
2435
+				['status' => ['IN', ['draft', 'auto-draft']]],
2436
+				'caps' => 'read_admin',
2437
+			],
2438
+			'EVT_ID',
2439
+			true
2440
+		);
2441
+	}
2442
+
2443
+
2444
+	/**
2445
+	 * get total number of trashed events
2446
+	 *
2447
+	 * @access public
2448
+	 * @return int
2449
+	 * @throws EE_Error
2450
+	 * @throws EE_Error
2451
+	 * @throws ReflectionException
2452
+	 */
2453
+	public function total_trashed_events(): int
2454
+	{
2455
+		return EEM_Event::instance()->count(
2456
+			[
2457
+				['status' => 'trash'],
2458
+				'caps' => 'read_admin',
2459
+			],
2460
+			'EVT_ID',
2461
+			true
2462
+		);
2463
+	}
2464
+
2465
+
2466
+	/**
2467
+	 *    _default_event_settings
2468
+	 *    This generates the Default Settings Tab
2469
+	 *
2470
+	 * @return void
2471
+	 * @throws DomainException
2472
+	 * @throws EE_Error
2473
+	 * @throws InvalidArgumentException
2474
+	 * @throws InvalidDataTypeException
2475
+	 * @throws InvalidInterfaceException
2476
+	 * @throws ReflectionException
2477
+	 */
2478
+	protected function _default_event_settings()
2479
+	{
2480
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2481
+		$this->_set_publish_post_box_vars();
2482
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
2483
+			$this->_default_event_settings_form()->get_html(),
2484
+			'',
2485
+			'padding'
2486
+		);
2487
+		$this->display_admin_page_with_sidebar();
2488
+	}
2489
+
2490
+
2491
+	/**
2492
+	 * Return the form for event settings.
2493
+	 *
2494
+	 * @return EE_Form_Section_Proper
2495
+	 * @throws EE_Error
2496
+	 * @throws ReflectionException
2497
+	 */
2498
+	protected function _default_event_settings_form(): EE_Form_Section_Proper
2499
+	{
2500
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2501
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2502
+		// exclude
2503
+			[
2504
+				EEM_Registration::status_id_cancelled,
2505
+				EEM_Registration::status_id_declined,
2506
+				EEM_Registration::status_id_incomplete,
2507
+				EEM_Registration::status_id_wait_list,
2508
+			],
2509
+			true
2510
+		);
2511
+		// setup Advanced Editor ???
2512
+		if (
2513
+			$this->raw_req_action === 'default_event_settings'
2514
+			|| $this->raw_req_action === 'update_default_event_settings'
2515
+		) {
2516
+			$this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2517
+		}
2518
+		return new EE_Form_Section_Proper(
2519
+			[
2520
+				'name'            => 'update_default_event_settings',
2521
+				'html_id'         => 'update_default_event_settings',
2522
+				'html_class'      => 'form-table',
2523
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2524
+				'subsections'     => apply_filters(
2525
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2526
+					[
2527
+						'defaults_section_header' => new EE_Form_Section_HTML(
2528
+							EEH_HTML::h2(
2529
+								esc_html__('Default Settings', 'event_espresso'),
2530
+								'',
2531
+								'ee-admin-settings-hdr'
2532
+							)
2533
+						),
2534
+						'default_reg_status'      => new EE_Select_Input(
2535
+							$registration_stati_for_selection,
2536
+							[
2537
+								'default'         => isset($registration_config->default_STS_ID)
2538
+													 && array_key_exists(
2539
+														 $registration_config->default_STS_ID,
2540
+														 $registration_stati_for_selection
2541
+													 )
2542
+									? sanitize_text_field($registration_config->default_STS_ID)
2543
+									: EEM_Registration::status_id_pending_payment,
2544
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2545
+													 . EEH_Template::get_help_tab_link(
2546
+										'default_settings_status_help_tab'
2547
+									),
2548
+								'html_help_text'  => esc_html__(
2549
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2550
+									'event_espresso'
2551
+								),
2552
+							]
2553
+						),
2554
+						'default_max_tickets'     => new EE_Integer_Input(
2555
+							[
2556
+								'default'         => $registration_config->default_maximum_number_of_tickets
2557
+													 ?? EEM_Event::get_default_additional_limit(),
2558
+								'html_label_text' => esc_html__(
2559
+														 'Default Maximum Tickets Allowed Per Order:',
2560
+														 'event_espresso'
2561
+													 )
2562
+													 . EEH_Template::get_help_tab_link(
2563
+										'default_maximum_tickets_help_tab"'
2564
+									),
2565
+								'html_help_text'  => esc_html__(
2566
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2567
+									'event_espresso'
2568
+								),
2569
+							]
2570
+						),
2571
+					]
2572
+				),
2573
+			]
2574
+		);
2575
+	}
2576
+
2577
+
2578
+	/**
2579
+	 * @return void
2580
+	 * @throws EE_Error
2581
+	 * @throws InvalidArgumentException
2582
+	 * @throws InvalidDataTypeException
2583
+	 * @throws InvalidInterfaceException
2584
+	 * @throws ReflectionException
2585
+	 */
2586
+	protected function _update_default_event_settings()
2587
+	{
2588
+		$form = $this->_default_event_settings_form();
2589
+		if ($form->was_submitted()) {
2590
+			$form->receive_form_submission();
2591
+			if ($form->is_valid()) {
2592
+				$registration_config = EE_Registry::instance()->CFG->registration;
2593
+				$valid_data          = $form->valid_data();
2594
+				if (isset($valid_data['default_reg_status'])) {
2595
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2596
+				}
2597
+				if (isset($valid_data['default_max_tickets'])) {
2598
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2599
+				}
2600
+				do_action(
2601
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2602
+					$valid_data,
2603
+					EE_Registry::instance()->CFG,
2604
+					$this
2605
+				);
2606
+				// update because data was valid!
2607
+				EE_Registry::instance()->CFG->update_espresso_config();
2608
+				EE_Error::overwrite_success();
2609
+				EE_Error::add_success(
2610
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2611
+				);
2612
+			}
2613
+		}
2614
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2615
+	}
2616
+
2617
+
2618
+	/*************        Templates        *************
1774 2619
      *
1775
-     * @access private
1776
-     * @param EE_Ticket $ticket   the ticket object
1777
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1778
-     * @param int       $row
1779
-     * @return string generated html for the ticket row.
1780
-     * @throws EE_Error
1781
-     * @throws ReflectionException
1782
-     */
1783
-    private function _get_ticket_row(EE_Ticket $ticket, bool $skeleton = false, int $row = 0): string
1784
-    {
1785
-        $template_args = [
1786
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1787
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1788
-                : '',
1789
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1790
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1791
-            'TKT_name'            => $ticket->get('TKT_name'),
1792
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1793
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1794
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1795
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1796
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1797
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1798
-            'trash_icon'          => ($skeleton || (! $ticket->get('TKT_deleted')))
1799
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1800
-                ? 'dashicons dashicons-post-trash clickable'
1801
-                : 'dashicons dashicons-lock',
1802
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1803
-                : ' disabled=disabled',
1804
-        ];
1805
-        $price         = $ticket->ID() !== 0
1806
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1807
-            : null;
1808
-        $price         = $price instanceof EE_Price
1809
-            ? $price
1810
-            : EEM_Price::instance()->create_default_object();
1811
-        $price_args    = [
1812
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1813
-            'PRC_amount'            => $price->get('PRC_amount'),
1814
-            'PRT_ID'                => $price->get('PRT_ID'),
1815
-            'PRC_ID'                => $price->get('PRC_ID'),
1816
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1817
-        ];
1818
-        // make sure we have default start and end dates if skeleton
1819
-        // handle rows that should NOT be empty
1820
-        if (empty($template_args['TKT_start_date'])) {
1821
-            // if empty then the start date will be now.
1822
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1823
-        }
1824
-        if (empty($template_args['TKT_end_date'])) {
1825
-            // get the earliest datetime (if present);
1826
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1827
-                ? $this->_cpt_model_obj->get_first_related(
1828
-                    'Datetime',
1829
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1830
-                )
1831
-                : null;
1832
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1833
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1834
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1835
-        }
1836
-        $template_args = array_merge($template_args, $price_args);
1837
-        $template      = apply_filters(
1838
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1839
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1840
-            $ticket
1841
-        );
1842
-        return EEH_Template::display_template($template, $template_args, true);
1843
-    }
1844
-
1845
-
1846
-    /**
1847
-     * @throws EE_Error
1848
-     * @throws ReflectionException
1849
-     */
1850
-    public function registration_options_meta_box()
1851
-    {
1852
-        $yes_no_values             = [
1853
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1854
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1855
-        ];
1856
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1857
-            [
1858
-                EEM_Registration::status_id_cancelled,
1859
-                EEM_Registration::status_id_declined,
1860
-                EEM_Registration::status_id_incomplete,
1861
-            ],
1862
-            true
1863
-        );
1864
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1865
-        $template_args['_event']                          = $this->_cpt_model_obj;
1866
-        $template_args['event']                           = $this->_cpt_model_obj;
1867
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1868
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1869
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1870
-            'default_reg_status',
1871
-            $default_reg_status_values,
1872
-            $this->_cpt_model_obj->default_registration_status(),
1873
-            '',
1874
-            'ee-input-width--reg',
1875
-            false
1876
-        );
1877
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1878
-            'display_desc',
1879
-            $yes_no_values,
1880
-            $this->_cpt_model_obj->display_description()
1881
-        );
1882
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1883
-            'display_ticket_selector',
1884
-            $yes_no_values,
1885
-            $this->_cpt_model_obj->display_ticket_selector(),
1886
-            '',
1887
-            'ee-input-width--small',
1888
-            false
1889
-        );
1890
-        $template_args['additional_registration_options'] = apply_filters(
1891
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1892
-            '',
1893
-            $template_args,
1894
-            $yes_no_values,
1895
-            $default_reg_status_values
1896
-        );
1897
-        EEH_Template::display_template(
1898
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1899
-            $template_args
1900
-        );
1901
-    }
1902
-
1903
-
1904
-    /**
1905
-     * _get_events()
1906
-     * This method simply returns all the events (for the given _view and paging)
1907
-     *
1908
-     * @access public
1909
-     * @param int  $per_page     count of items per page (20 default);
1910
-     * @param int  $current_page what is the current page being viewed.
1911
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1912
-     *                           If FALSE then we return an array of event objects
1913
-     *                           that match the given _view and paging parameters.
1914
-     * @return array|int         an array of event objects or a count of them.
1915
-     * @throws Exception
1916
-     */
1917
-    public function get_events(int $per_page = 10, int $current_page = 1, bool $count = false)
1918
-    {
1919
-        $EEM_Event   = $this->_event_model();
1920
-        $offset      = ($current_page - 1) * $per_page;
1921
-        $limit       = $count ? null : $offset . ',' . $per_page;
1922
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1923
-        $order       = $this->request->getRequestParam('order', 'DESC');
1924
-        $month_range = $this->request->getRequestParam('month_range');
1925
-        if ($month_range) {
1926
-            $pieces = explode(' ', $month_range, 3);
1927
-            // simulate the FIRST day of the month, that fixes issues for months like February
1928
-            // where PHP doesn't know what to assume for date.
1929
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1930
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1931
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1932
-        }
1933
-        $where  = [];
1934
-        $status = $this->request->getRequestParam('status');
1935
-        // determine what post_status our condition will have for the query.
1936
-        switch ($status) {
1937
-            case 'month':
1938
-            case 'today':
1939
-            case null:
1940
-            case 'all':
1941
-                break;
1942
-            case 'draft':
1943
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1944
-                break;
1945
-            default:
1946
-                $where['status'] = $status;
1947
-        }
1948
-        // categories? The default for all categories is -1
1949
-        $category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INT);
1950
-        if ($category !== -1) {
1951
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1952
-            $where['Term_Taxonomy.term_id']  = $category;
1953
-        }
1954
-        // date where conditions
1955
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1956
-        if ($month_range) {
1957
-            $DateTime = new DateTime(
1958
-                $year_r . '-' . $month_r . '-01 00:00:00',
1959
-                new DateTimeZone('UTC')
1960
-            );
1961
-            $start    = $DateTime->getTimestamp();
1962
-            // set the datetime to be the end of the month
1963
-            $DateTime->setDate(
1964
-                $year_r,
1965
-                $month_r,
1966
-                $DateTime->format('t')
1967
-            )->setTime(23, 59, 59);
1968
-            $end                             = $DateTime->getTimestamp();
1969
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1970
-        } elseif ($status === 'today') {
1971
-            $DateTime                        = new DateTime(
1972
-                'now',
1973
-                new DateTimeZone(EEM_Event::instance()->get_timezone())
1974
-            );
1975
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1976
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1977
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1978
-        } elseif ($status === 'month') {
1979
-            $now                             = date('Y-m-01');
1980
-            $DateTime                        = new DateTime(
1981
-                $now,
1982
-                new DateTimeZone(EEM_Event::instance()->get_timezone())
1983
-            );
1984
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1985
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1986
-                                                        ->setTime(23, 59, 59)
1987
-                                                        ->format(implode(' ', $start_formats));
1988
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1989
-        }
1990
-        if (! $this->capabilities->current_user_can('ee_read_others_events', 'get_events')) {
1991
-            $where['EVT_wp_user'] = get_current_user_id();
1992
-        } else {
1993
-            if (! isset($where['status'])) {
1994
-                if (! $this->capabilities->current_user_can('ee_read_private_events', 'get_events')) {
1995
-                    $where['OR'] = [
1996
-                        'status*restrict_private' => ['!=', 'private'],
1997
-                        'AND'                     => [
1998
-                            'status*inclusive' => ['=', 'private'],
1999
-                            'EVT_wp_user'      => get_current_user_id(),
2000
-                        ],
2001
-                    ];
2002
-                }
2003
-            }
2004
-        }
2005
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, DataType::INT);
2006
-        if (
2007
-            $wp_user
2008
-            && $wp_user !== get_current_user_id()
2009
-            && $this->capabilities->current_user_can('ee_read_others_events', 'get_events')
2010
-        ) {
2011
-            $where['EVT_wp_user'] = $wp_user;
2012
-        }
2013
-        // search query handling
2014
-        $search_term = $this->request->getRequestParam('s');
2015
-        if ($search_term) {
2016
-            $search_term = '%' . $search_term . '%';
2017
-            $where['OR'] = [
2018
-                'EVT_name'       => ['LIKE', $search_term],
2019
-                'EVT_desc'       => ['LIKE', $search_term],
2020
-                'EVT_short_desc' => ['LIKE', $search_term],
2021
-            ];
2022
-        }
2023
-        // filter events by venue.
2024
-        $venue = $this->request->getRequestParam('venue', 0, DataType::INT);
2025
-        if ($venue) {
2026
-            $where['Venue.VNU_ID'] = $venue;
2027
-        }
2028
-        $request_params = $this->request->requestParams();
2029
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2030
-        $query_params   = apply_filters(
2031
-            'FHEE__Events_Admin_Page__get_events__query_params',
2032
-            [
2033
-                $where,
2034
-                'limit'    => $limit,
2035
-                'order_by' => $orderby,
2036
-                'order'    => $order,
2037
-                'group_by' => 'EVT_ID',
2038
-            ],
2039
-            $request_params
2040
-        );
2041
-
2042
-        // let's first check if we have special requests coming in.
2043
-        $active_status = $this->request->getRequestParam('active_status');
2044
-        if ($active_status) {
2045
-            switch ($active_status) {
2046
-                case 'upcoming':
2047
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
2048
-                case 'expired':
2049
-                    return $EEM_Event->get_expired_events($query_params, $count);
2050
-                case 'active':
2051
-                    return $EEM_Event->get_active_events($query_params, $count);
2052
-                case 'inactive':
2053
-                    return $EEM_Event->get_inactive_events($query_params, $count);
2054
-            }
2055
-        }
2056
-
2057
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2058
-    }
2059
-
2060
-
2061
-    /**
2062
-     * handling for WordPress CPT actions (trash, restore, delete)
2063
-     *
2064
-     * @param string $post_id
2065
-     * @throws EE_Error
2066
-     * @throws ReflectionException
2067
-     */
2068
-    public function trash_cpt_item($post_id)
2069
-    {
2070
-        $this->request->setRequestParam('EVT_ID', $post_id);
2071
-        $this->_trash_or_restore_event('trash', false);
2072
-    }
2073
-
2074
-
2075
-    /**
2076
-     * @param string $post_id
2077
-     * @throws EE_Error
2078
-     * @throws ReflectionException
2079
-     */
2080
-    public function restore_cpt_item($post_id)
2081
-    {
2082
-        $this->request->setRequestParam('EVT_ID', $post_id);
2083
-        $this->_trash_or_restore_event('draft', false);
2084
-    }
2085
-
2086
-
2087
-    /**
2088
-     * @param string $post_id
2089
-     * @throws EE_Error
2090
-     * @throws EE_Error
2091
-     */
2092
-    public function delete_cpt_item($post_id)
2093
-    {
2094
-        throw new EE_Error(
2095
-            esc_html__(
2096
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2097
-                'event_espresso'
2098
-            )
2099
-        );
2100
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2101
-        // $this->_delete_event();
2102
-    }
2103
-
2104
-
2105
-    /**
2106
-     * _trash_or_restore_event
2107
-     *
2108
-     * @access protected
2109
-     * @param string $event_status
2110
-     * @param bool   $redirect_after
2111
-     * @throws EE_Error
2112
-     * @throws EE_Error
2113
-     * @throws ReflectionException
2114
-     */
2115
-    protected function _trash_or_restore_event(string $event_status = 'trash', bool $redirect_after = true)
2116
-    {
2117
-        // loop thru events
2118
-        if ($this->EVT_ID) {
2119
-            // clean status
2120
-            $event_status = sanitize_key($event_status);
2121
-            // grab status
2122
-            if (! empty($event_status)) {
2123
-                $success = $this->_change_event_status($this->EVT_ID, $event_status);
2124
-            } else {
2125
-                $success = false;
2126
-                $msg     = esc_html__(
2127
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2128
-                    'event_espresso'
2129
-                );
2130
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2131
-            }
2132
-        } else {
2133
-            $success = false;
2134
-            $msg     = esc_html__(
2135
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2136
-                'event_espresso'
2137
-            );
2138
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2139
-        }
2140
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2141
-        if ($redirect_after) {
2142
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2143
-        }
2144
-    }
2145
-
2146
-
2147
-    /**
2148
-     * _trash_or_restore_events
2149
-     *
2150
-     * @access protected
2151
-     * @param string $event_status
2152
-     * @return void
2153
-     * @throws EE_Error
2154
-     * @throws EE_Error
2155
-     * @throws ReflectionException
2156
-     */
2157
-    protected function _trash_or_restore_events(string $event_status = 'trash')
2158
-    {
2159
-        // clean status
2160
-        $event_status = sanitize_key($event_status);
2161
-        // grab status
2162
-        if (! empty($event_status)) {
2163
-            $success = true;
2164
-            // determine the event id and set to array.
2165
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2166
-            // loop thru events
2167
-            foreach ($EVT_IDs as $EVT_ID) {
2168
-                if ($EVT_ID = absint($EVT_ID)) {
2169
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2170
-                    $success = $results !== false ? $success : false;
2171
-                } else {
2172
-                    $msg = sprintf(
2173
-                        esc_html__(
2174
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2175
-                            'event_espresso'
2176
-                        ),
2177
-                        $EVT_ID
2178
-                    );
2179
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2180
-                    $success = false;
2181
-                }
2182
-            }
2183
-        } else {
2184
-            $success = false;
2185
-            $msg     = esc_html__(
2186
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2187
-                'event_espresso'
2188
-            );
2189
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2190
-        }
2191
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2192
-        $success = $success ? 2 : false;
2193
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2194
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2195
-    }
2196
-
2197
-
2198
-    /**
2199
-     * @param int    $EVT_ID
2200
-     * @param string $event_status
2201
-     * @return bool
2202
-     * @throws EE_Error
2203
-     * @throws ReflectionException
2204
-     */
2205
-    private function _change_event_status(int $EVT_ID = 0, string $event_status = ''): bool
2206
-    {
2207
-        // grab event id
2208
-        if (! $EVT_ID) {
2209
-            $msg = esc_html__(
2210
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2211
-                'event_espresso'
2212
-            );
2213
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2214
-            return false;
2215
-        }
2216
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2217
-        // clean status
2218
-        $event_status = sanitize_key($event_status);
2219
-        // grab status
2220
-        if (empty($event_status)) {
2221
-            $msg = esc_html__(
2222
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2223
-                'event_espresso'
2224
-            );
2225
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2226
-            return false;
2227
-        }
2228
-        // was event trashed or restored ?
2229
-        switch ($event_status) {
2230
-            case 'draft':
2231
-                $action = 'restored from the trash';
2232
-                $hook   = 'AHEE_event_restored_from_trash';
2233
-                break;
2234
-            case 'trash':
2235
-                $action = 'moved to the trash';
2236
-                $hook   = 'AHEE_event_moved_to_trash';
2237
-                break;
2238
-            default:
2239
-                $action = 'updated';
2240
-                $hook   = false;
2241
-        }
2242
-        // use class to change status
2243
-        $this->_cpt_model_obj->set_status($event_status);
2244
-        $success = $this->_cpt_model_obj->save();
2245
-        if (! $success) {
2246
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2247
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2248
-            return false;
2249
-        }
2250
-        if ($hook) {
2251
-            do_action($hook);
2252
-            // fake the action hook in EE_Soft_Delete_Base_Class::delete_or_restore()
2253
-            // because events side step that and it otherwise won't get called
2254
-            do_action(
2255
-                'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after',
2256
-                $this->_cpt_model_obj,
2257
-                $hook === 'AHEE_event_moved_to_trash',
2258
-                $success
2259
-            );
2260
-        }
2261
-        return true;
2262
-    }
2263
-
2264
-
2265
-    /**
2266
-     * @param array $event_ids
2267
-     * @return array
2268
-     * @since   4.10.23.p
2269
-     */
2270
-    private function cleanEventIds(array $event_ids): array
2271
-    {
2272
-        return array_map('absint', $event_ids);
2273
-    }
2274
-
2275
-
2276
-    /**
2277
-     * @return array
2278
-     * @since   4.10.23.p
2279
-     */
2280
-    private function getEventIdsFromRequest(): array
2281
-    {
2282
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2283
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2284
-        } else {
2285
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2286
-        }
2287
-    }
2288
-
2289
-
2290
-    /**
2291
-     * @param bool $preview_delete
2292
-     * @throws EE_Error
2293
-     * @throws ReflectionException
2294
-     */
2295
-    protected function _delete_event(bool $preview_delete = true)
2296
-    {
2297
-        $this->_delete_events($preview_delete);
2298
-    }
2299
-
2300
-
2301
-    /**
2302
-     * Gets the tree traversal batch persister.
2303
-     *
2304
-     * @return NodeGroupDao
2305
-     * @throws InvalidArgumentException
2306
-     * @throws InvalidDataTypeException
2307
-     * @throws InvalidInterfaceException
2308
-     * @since 4.10.12.p
2309
-     */
2310
-    protected function getModelObjNodeGroupPersister(): NodeGroupDao
2311
-    {
2312
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2313
-            $this->model_obj_node_group_persister =
2314
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2315
-        }
2316
-        return $this->model_obj_node_group_persister;
2317
-    }
2318
-
2319
-
2320
-    /**
2321
-     * @param bool $preview_delete
2322
-     * @return void
2323
-     * @throws EE_Error
2324
-     * @throws ReflectionException
2325
-     */
2326
-    protected function _delete_events(bool $preview_delete = true)
2327
-    {
2328
-        $event_ids = $this->getEventIdsFromRequest();
2329
-        if ($preview_delete) {
2330
-            $this->generateDeletionPreview($event_ids);
2331
-        } else {
2332
-            foreach ($event_ids as $event_id) {
2333
-                $event = EEM_Event::instance()->get_one_by_ID($event_id);
2334
-                if ($event instanceof EE_Event) {
2335
-                    $event->delete_permanently();
2336
-                }
2337
-            }
2338
-        }
2339
-    }
2340
-
2341
-
2342
-    /**
2343
-     * @param array $event_ids
2344
-     */
2345
-    protected function generateDeletionPreview(array $event_ids)
2346
-    {
2347
-        $event_ids = $this->cleanEventIds($event_ids);
2348
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2349
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2350
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2351
-            [
2352
-                'action'            => 'preview_deletion',
2353
-                'deletion_job_code' => $deletion_job_code,
2354
-            ],
2355
-            $this->_admin_base_url
2356
-        );
2357
-        EEH_URL::safeRedirectAndExit(
2358
-            EE_Admin_Page::add_query_args_and_nonce(
2359
-                [
2360
-                    'page'              => EED_Batch::PAGE_SLUG,
2361
-                    'batch'             => EED_Batch::batch_job,
2362
-                    'EVT_IDs'           => $event_ids,
2363
-                    'deletion_job_code' => $deletion_job_code,
2364
-                    'job_handler'       => urlencode('EventEspresso\core\libraries\batch\JobHandlers\PreviewEventDeletion'),
2365
-                    'return_url'        => urlencode($return_url),
2366
-                ],
2367
-                admin_url()
2368
-            )
2369
-        );
2370
-    }
2371
-
2372
-
2373
-    /**
2374
-     * Checks for a POST submission
2375
-     *
2376
-     * @since 4.10.12.p
2377
-     */
2378
-    protected function confirmDeletion()
2379
-    {
2380
-        $deletion_redirect_logic = $this->getLoader()->getShared(
2381
-            'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'
2382
-        );
2383
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2384
-    }
2385
-
2386
-
2387
-    /**
2388
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2389
-     *
2390
-     * @throws EE_Error
2391
-     * @since 4.10.12.p
2392
-     */
2393
-    protected function previewDeletion()
2394
-    {
2395
-        $preview_deletion_logic = $this->getLoader()->getShared(
2396
-            'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'
2397
-        );
2398
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2399
-        $this->display_admin_page_with_no_sidebar();
2400
-    }
2401
-
2402
-
2403
-    /**
2404
-     * get total number of events
2405
-     *
2406
-     * @access public
2407
-     * @return int
2408
-     * @throws EE_Error
2409
-     * @throws EE_Error
2410
-     * @throws ReflectionException
2411
-     */
2412
-    public function total_events(): int
2413
-    {
2414
-        return EEM_Event::instance()->count(
2415
-            ['caps' => 'read_admin'],
2416
-            'EVT_ID',
2417
-            true
2418
-        );
2419
-    }
2420
-
2421
-
2422
-    /**
2423
-     * get total number of draft events
2424
-     *
2425
-     * @access public
2426
-     * @return int
2427
-     * @throws EE_Error
2428
-     * @throws EE_Error
2429
-     * @throws ReflectionException
2430
-     */
2431
-    public function total_events_draft(): int
2432
-    {
2433
-        return EEM_Event::instance()->count(
2434
-            [
2435
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2436
-                'caps' => 'read_admin',
2437
-            ],
2438
-            'EVT_ID',
2439
-            true
2440
-        );
2441
-    }
2442
-
2443
-
2444
-    /**
2445
-     * get total number of trashed events
2446
-     *
2447
-     * @access public
2448
-     * @return int
2449
-     * @throws EE_Error
2450
-     * @throws EE_Error
2451
-     * @throws ReflectionException
2452
-     */
2453
-    public function total_trashed_events(): int
2454
-    {
2455
-        return EEM_Event::instance()->count(
2456
-            [
2457
-                ['status' => 'trash'],
2458
-                'caps' => 'read_admin',
2459
-            ],
2460
-            'EVT_ID',
2461
-            true
2462
-        );
2463
-    }
2464
-
2465
-
2466
-    /**
2467
-     *    _default_event_settings
2468
-     *    This generates the Default Settings Tab
2469
-     *
2470
-     * @return void
2471
-     * @throws DomainException
2472
-     * @throws EE_Error
2473
-     * @throws InvalidArgumentException
2474
-     * @throws InvalidDataTypeException
2475
-     * @throws InvalidInterfaceException
2476
-     * @throws ReflectionException
2477
-     */
2478
-    protected function _default_event_settings()
2479
-    {
2480
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2481
-        $this->_set_publish_post_box_vars();
2482
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
2483
-            $this->_default_event_settings_form()->get_html(),
2484
-            '',
2485
-            'padding'
2486
-        );
2487
-        $this->display_admin_page_with_sidebar();
2488
-    }
2489
-
2490
-
2491
-    /**
2492
-     * Return the form for event settings.
2493
-     *
2494
-     * @return EE_Form_Section_Proper
2495
-     * @throws EE_Error
2496
-     * @throws ReflectionException
2497
-     */
2498
-    protected function _default_event_settings_form(): EE_Form_Section_Proper
2499
-    {
2500
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2501
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2502
-        // exclude
2503
-            [
2504
-                EEM_Registration::status_id_cancelled,
2505
-                EEM_Registration::status_id_declined,
2506
-                EEM_Registration::status_id_incomplete,
2507
-                EEM_Registration::status_id_wait_list,
2508
-            ],
2509
-            true
2510
-        );
2511
-        // setup Advanced Editor ???
2512
-        if (
2513
-            $this->raw_req_action === 'default_event_settings'
2514
-            || $this->raw_req_action === 'update_default_event_settings'
2515
-        ) {
2516
-            $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2517
-        }
2518
-        return new EE_Form_Section_Proper(
2519
-            [
2520
-                'name'            => 'update_default_event_settings',
2521
-                'html_id'         => 'update_default_event_settings',
2522
-                'html_class'      => 'form-table',
2523
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2524
-                'subsections'     => apply_filters(
2525
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2526
-                    [
2527
-                        'defaults_section_header' => new EE_Form_Section_HTML(
2528
-                            EEH_HTML::h2(
2529
-                                esc_html__('Default Settings', 'event_espresso'),
2530
-                                '',
2531
-                                'ee-admin-settings-hdr'
2532
-                            )
2533
-                        ),
2534
-                        'default_reg_status'      => new EE_Select_Input(
2535
-                            $registration_stati_for_selection,
2536
-                            [
2537
-                                'default'         => isset($registration_config->default_STS_ID)
2538
-                                                     && array_key_exists(
2539
-                                                         $registration_config->default_STS_ID,
2540
-                                                         $registration_stati_for_selection
2541
-                                                     )
2542
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2543
-                                    : EEM_Registration::status_id_pending_payment,
2544
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2545
-                                                     . EEH_Template::get_help_tab_link(
2546
-                                        'default_settings_status_help_tab'
2547
-                                    ),
2548
-                                'html_help_text'  => esc_html__(
2549
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2550
-                                    'event_espresso'
2551
-                                ),
2552
-                            ]
2553
-                        ),
2554
-                        'default_max_tickets'     => new EE_Integer_Input(
2555
-                            [
2556
-                                'default'         => $registration_config->default_maximum_number_of_tickets
2557
-                                                     ?? EEM_Event::get_default_additional_limit(),
2558
-                                'html_label_text' => esc_html__(
2559
-                                                         'Default Maximum Tickets Allowed Per Order:',
2560
-                                                         'event_espresso'
2561
-                                                     )
2562
-                                                     . EEH_Template::get_help_tab_link(
2563
-                                        'default_maximum_tickets_help_tab"'
2564
-                                    ),
2565
-                                'html_help_text'  => esc_html__(
2566
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2567
-                                    'event_espresso'
2568
-                                ),
2569
-                            ]
2570
-                        ),
2571
-                    ]
2572
-                ),
2573
-            ]
2574
-        );
2575
-    }
2576
-
2577
-
2578
-    /**
2579
-     * @return void
2580
-     * @throws EE_Error
2581
-     * @throws InvalidArgumentException
2582
-     * @throws InvalidDataTypeException
2583
-     * @throws InvalidInterfaceException
2584
-     * @throws ReflectionException
2585
-     */
2586
-    protected function _update_default_event_settings()
2587
-    {
2588
-        $form = $this->_default_event_settings_form();
2589
-        if ($form->was_submitted()) {
2590
-            $form->receive_form_submission();
2591
-            if ($form->is_valid()) {
2592
-                $registration_config = EE_Registry::instance()->CFG->registration;
2593
-                $valid_data          = $form->valid_data();
2594
-                if (isset($valid_data['default_reg_status'])) {
2595
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2596
-                }
2597
-                if (isset($valid_data['default_max_tickets'])) {
2598
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2599
-                }
2600
-                do_action(
2601
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2602
-                    $valid_data,
2603
-                    EE_Registry::instance()->CFG,
2604
-                    $this
2605
-                );
2606
-                // update because data was valid!
2607
-                EE_Registry::instance()->CFG->update_espresso_config();
2608
-                EE_Error::overwrite_success();
2609
-                EE_Error::add_success(
2610
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2611
-                );
2612
-            }
2613
-        }
2614
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2615
-    }
2616
-
2617
-
2618
-    /*************        Templates        *************
2619
-     *
2620
-     * @throws EE_Error
2621
-     */
2622
-    protected function _template_settings()
2623
-    {
2624
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2625
-        $this->_template_args['preview_img']  = '<img src="'
2626
-                                                . EVENTS_ASSETS_URL
2627
-                                                . '/images/'
2628
-                                                . 'caffeinated_template_features.jpg" alt="'
2629
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2630
-                                                . '" />';
2631
-        $this->_template_args['preview_text'] = '<strong>'
2632
-                                                . esc_html__(
2633
-                                                    'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2634
-                                                    'event_espresso'
2635
-                                                ) . '</strong>';
2636
-        $this->display_admin_caf_preview_page('template_settings_tab');
2637
-    }
2638
-
2639
-
2640
-    /** Event Category Stuff **/
2641
-    /**
2642
-     * set the _category property with the category object for the loaded page.
2643
-     *
2644
-     * @access private
2645
-     * @return void
2646
-     */
2647
-    private function _set_category_object()
2648
-    {
2649
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2650
-            return;
2651
-        } //already have the category object so get out.
2652
-        // set default category object
2653
-        $this->_set_empty_category_object();
2654
-        // only set if we've got an id
2655
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
2656
-        if (! $category_ID) {
2657
-            return;
2658
-        }
2659
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2660
-        if (! empty($term)) {
2661
-            $this->_category->category_name       = $term->name;
2662
-            $this->_category->category_identifier = $term->slug;
2663
-            $this->_category->category_desc       = $term->description;
2664
-            $this->_category->id                  = $term->term_id;
2665
-            $this->_category->parent              = $term->parent;
2666
-        }
2667
-    }
2668
-
2669
-
2670
-    /**
2671
-     * Clears out category properties.
2672
-     */
2673
-    private function _set_empty_category_object()
2674
-    {
2675
-        $this->_category                = new stdClass();
2676
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2677
-        $this->_category->id            = $this->_category->parent = 0;
2678
-    }
2679
-
2680
-
2681
-    /**
2682
-     * @throws DomainException
2683
-     * @throws EE_Error
2684
-     * @throws InvalidArgumentException
2685
-     * @throws InvalidDataTypeException
2686
-     * @throws InvalidInterfaceException
2687
-     */
2688
-    protected function _category_list_table()
2689
-    {
2690
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2691
-        $this->_admin_page_title .= ' ';
2692
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2693
-            'add_category',
2694
-            'add_category',
2695
-            [],
2696
-            'add-new-h2'
2697
-        );
2698
-        $this->display_admin_list_table_page_with_sidebar();
2699
-    }
2700
-
2701
-
2702
-    /**
2703
-     * Output category details view.
2704
-     *
2705
-     * @throws EE_Error
2706
-     * @throws EE_Error
2707
-     */
2708
-    protected function _category_details($view)
2709
-    {
2710
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2711
-        $this->_set_add_edit_form_tags($route);
2712
-        $this->_set_category_object();
2713
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2714
-        $delete_action = 'delete_category';
2715
-        // custom redirect
2716
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2717
-            ['action' => 'category_list'],
2718
-            $this->_admin_base_url
2719
-        );
2720
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2721
-        // take care of contents
2722
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2723
-        $this->display_admin_page_with_sidebar();
2724
-    }
2725
-
2726
-
2727
-    /**
2728
-     * Output category details content.
2729
-     *
2730
-     * @throws DomainException
2731
-     */
2732
-    protected function _category_details_content(): string
2733
-    {
2734
-        $editor_args['category_desc'] = [
2735
-            'type'          => 'wp_editor',
2736
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2737
-            'class'         => 'my_editor_custom',
2738
-            'wpeditor_args' => ['media_buttons' => false],
2739
-        ];
2740
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2741
-        $all_terms                    = get_terms(
2742
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2743
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2744
-        );
2745
-        // setup category select for term parents.
2746
-        $category_select_values[] = [
2747
-            'text' => esc_html__('No Parent', 'event_espresso'),
2748
-            'id'   => 0,
2749
-        ];
2750
-        foreach ($all_terms as $term) {
2751
-            $category_select_values[] = [
2752
-                'text' => $term->name,
2753
-                'id'   => $term->term_id,
2754
-            ];
2755
-        }
2756
-        $category_select = EEH_Form_Fields::select_input(
2757
-            'category_parent',
2758
-            $category_select_values,
2759
-            $this->_category->parent
2760
-        );
2761
-        $template_args   = [
2762
-            'category'                 => $this->_category,
2763
-            'category_select'          => $category_select,
2764
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2765
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2766
-            'disable'                  => '',
2767
-            'disabled_message'         => false,
2768
-        ];
2769
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2770
-        return EEH_Template::display_template($template, $template_args, true);
2771
-    }
2772
-
2773
-
2774
-    /**
2775
-     * Handles deleting categories.
2776
-     *
2777
-     * @throws EE_Error
2778
-     */
2779
-    protected function _delete_categories()
2780
-    {
2781
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2782
-        foreach ($category_IDs as $category_ID) {
2783
-            $this->_delete_category($category_ID);
2784
-        }
2785
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2786
-        $query_args = [
2787
-            'action' => 'category_list',
2788
-        ];
2789
-        $this->_redirect_after_action(0, '', '', $query_args);
2790
-    }
2791
-
2792
-
2793
-    /**
2794
-     * Handles deleting specific category.
2795
-     *
2796
-     * @param int $cat_id
2797
-     */
2798
-    protected function _delete_category(int $cat_id)
2799
-    {
2800
-        $cat_id = absint($cat_id);
2801
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * Handles triggering the update or insertion of a new category.
2807
-     *
2808
-     * @param bool $new_category true means we're triggering the insert of a new category.
2809
-     * @throws EE_Error
2810
-     * @throws EE_Error
2811
-     */
2812
-    protected function _insert_or_update_category(bool $new_category)
2813
-    {
2814
-        $cat_id  = $this->_insert_category($new_category);
2815
-        $success = 0; // we already have a success message so lets not send another.
2816
-        if ($cat_id) {
2817
-            $query_args = [
2818
-                'action'     => 'edit_category',
2819
-                'EVT_CAT_ID' => $cat_id,
2820
-            ];
2821
-        } else {
2822
-            $query_args = ['action' => 'add_category'];
2823
-        }
2824
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2825
-    }
2826
-
2827
-
2828
-    /**
2829
-     * Inserts or updates category
2830
-     *
2831
-     * @param bool $new_category (true indicates we're updating a category).
2832
-     * @return bool|mixed|string
2833
-     */
2834
-    private function _insert_category(bool $new_category)
2835
-    {
2836
-        $category_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
2837
-        $category_name       = $this->request->getRequestParam('category_name', '');
2838
-        $category_desc       = $this->request->getRequestParam('category_desc', '', DataType::HTML);
2839
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, DataType::INT);
2840
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2841
-
2842
-        if (empty($category_name)) {
2843
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2844
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2845
-            return 0;
2846
-        }
2847
-        $term_args = [
2848
-            'name'        => $category_name,
2849
-            'description' => $category_desc,
2850
-            'parent'      => $category_parent,
2851
-        ];
2852
-        // was the category_identifier input disabled?
2853
-        if ($category_identifier) {
2854
-            $term_args['slug'] = $category_identifier;
2855
-        }
2856
-        $insert_ids = $new_category
2857
-            ? wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2858
-            : wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2859
-
2860
-        if ($insert_ids instanceof WP_Error) {
2861
-            EE_Error::add_error($insert_ids->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
2862
-            return 0;
2863
-        }
2864
-        $category_ID = $insert_ids['term_id'] ?? 0;
2865
-        if (! $category_ID) {
2866
-            EE_Error::add_error(
2867
-                esc_html__(
2868
-                    'An error occurred and the category has not been saved to the database.',
2869
-                    'event_espresso'
2870
-                ),
2871
-                __FILE__,
2872
-                __FUNCTION__,
2873
-                __LINE__
2874
-            );
2875
-            return 0;
2876
-        }
2877
-        EE_Error::add_success(
2878
-            sprintf(
2879
-                esc_html__('The category %s was successfully saved', 'event_espresso'),
2880
-                $category_name
2881
-            )
2882
-        );
2883
-        return $category_ID;
2884
-    }
2885
-
2886
-
2887
-    /**
2888
-     * Gets categories or count of categories matching the arguments in the request.
2889
-     *
2890
-     * @param int  $per_page
2891
-     * @param int  $current_page
2892
-     * @param bool $count
2893
-     * @return EE_Term_Taxonomy[]|int
2894
-     * @throws EE_Error
2895
-     * @throws ReflectionException
2896
-     */
2897
-    public function get_categories(int $per_page = 10, int $current_page = 1, bool $count = false)
2898
-    {
2899
-        // testing term stuff
2900
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2901
-        $order       = $this->request->getRequestParam('order', 'DESC');
2902
-        $limit       = ($current_page - 1) * $per_page;
2903
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2904
-        $search_term = $this->request->getRequestParam('s');
2905
-        if ($search_term) {
2906
-            $search_term = '%' . $search_term . '%';
2907
-            $where['OR'] = [
2908
-                'Term.name'   => ['LIKE', $search_term],
2909
-                'description' => ['LIKE', $search_term],
2910
-            ];
2911
-        }
2912
-        $query_params = [
2913
-            $where,
2914
-            'order_by'   => [$orderby => $order],
2915
-            'limit'      => $limit . ',' . $per_page,
2916
-            'force_join' => ['Term'],
2917
-        ];
2918
-        return $count
2919
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2920
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2921
-    }
2922
-
2923
-    /* end category stuff */
2924
-
2925
-
2926
-    /**************/
2927
-
2928
-
2929
-    /**
2930
-     * Callback for the `ee_save_timezone_setting` ajax action.
2931
-     *
2932
-     * @throws EE_Error
2933
-     * @throws InvalidArgumentException
2934
-     * @throws InvalidDataTypeException
2935
-     * @throws InvalidInterfaceException
2936
-     */
2937
-    public function saveTimezoneString()
2938
-    {
2939
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2940
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2941
-            EE_Error::add_error(
2942
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2943
-                __FILE__,
2944
-                __FUNCTION__,
2945
-                __LINE__
2946
-            );
2947
-            $this->_template_args['error'] = true;
2948
-            $this->_return_json();
2949
-        }
2950
-
2951
-        update_option('timezone_string', $timezone_string);
2952
-        EE_Error::add_success(
2953
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2954
-        );
2955
-        $this->_template_args['success'] = true;
2956
-        $this->_return_json(true, ['action' => 'create_new']);
2957
-    }
2958
-
2959
-
2960
-    /**
2961 2620
      * @throws EE_Error
2962
-     * @deprecated 4.10.25.p
2963 2621
      */
2964
-    public function save_timezonestring_setting()
2965
-    {
2966
-        $this->saveTimezoneString();
2967
-    }
2622
+	protected function _template_settings()
2623
+	{
2624
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2625
+		$this->_template_args['preview_img']  = '<img src="'
2626
+												. EVENTS_ASSETS_URL
2627
+												. '/images/'
2628
+												. 'caffeinated_template_features.jpg" alt="'
2629
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2630
+												. '" />';
2631
+		$this->_template_args['preview_text'] = '<strong>'
2632
+												. esc_html__(
2633
+													'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2634
+													'event_espresso'
2635
+												) . '</strong>';
2636
+		$this->display_admin_caf_preview_page('template_settings_tab');
2637
+	}
2638
+
2639
+
2640
+	/** Event Category Stuff **/
2641
+	/**
2642
+	 * set the _category property with the category object for the loaded page.
2643
+	 *
2644
+	 * @access private
2645
+	 * @return void
2646
+	 */
2647
+	private function _set_category_object()
2648
+	{
2649
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2650
+			return;
2651
+		} //already have the category object so get out.
2652
+		// set default category object
2653
+		$this->_set_empty_category_object();
2654
+		// only set if we've got an id
2655
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
2656
+		if (! $category_ID) {
2657
+			return;
2658
+		}
2659
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2660
+		if (! empty($term)) {
2661
+			$this->_category->category_name       = $term->name;
2662
+			$this->_category->category_identifier = $term->slug;
2663
+			$this->_category->category_desc       = $term->description;
2664
+			$this->_category->id                  = $term->term_id;
2665
+			$this->_category->parent              = $term->parent;
2666
+		}
2667
+	}
2668
+
2669
+
2670
+	/**
2671
+	 * Clears out category properties.
2672
+	 */
2673
+	private function _set_empty_category_object()
2674
+	{
2675
+		$this->_category                = new stdClass();
2676
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2677
+		$this->_category->id            = $this->_category->parent = 0;
2678
+	}
2679
+
2680
+
2681
+	/**
2682
+	 * @throws DomainException
2683
+	 * @throws EE_Error
2684
+	 * @throws InvalidArgumentException
2685
+	 * @throws InvalidDataTypeException
2686
+	 * @throws InvalidInterfaceException
2687
+	 */
2688
+	protected function _category_list_table()
2689
+	{
2690
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2691
+		$this->_admin_page_title .= ' ';
2692
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2693
+			'add_category',
2694
+			'add_category',
2695
+			[],
2696
+			'add-new-h2'
2697
+		);
2698
+		$this->display_admin_list_table_page_with_sidebar();
2699
+	}
2700
+
2701
+
2702
+	/**
2703
+	 * Output category details view.
2704
+	 *
2705
+	 * @throws EE_Error
2706
+	 * @throws EE_Error
2707
+	 */
2708
+	protected function _category_details($view)
2709
+	{
2710
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2711
+		$this->_set_add_edit_form_tags($route);
2712
+		$this->_set_category_object();
2713
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2714
+		$delete_action = 'delete_category';
2715
+		// custom redirect
2716
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2717
+			['action' => 'category_list'],
2718
+			$this->_admin_base_url
2719
+		);
2720
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2721
+		// take care of contents
2722
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2723
+		$this->display_admin_page_with_sidebar();
2724
+	}
2725
+
2726
+
2727
+	/**
2728
+	 * Output category details content.
2729
+	 *
2730
+	 * @throws DomainException
2731
+	 */
2732
+	protected function _category_details_content(): string
2733
+	{
2734
+		$editor_args['category_desc'] = [
2735
+			'type'          => 'wp_editor',
2736
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2737
+			'class'         => 'my_editor_custom',
2738
+			'wpeditor_args' => ['media_buttons' => false],
2739
+		];
2740
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2741
+		$all_terms                    = get_terms(
2742
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2743
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2744
+		);
2745
+		// setup category select for term parents.
2746
+		$category_select_values[] = [
2747
+			'text' => esc_html__('No Parent', 'event_espresso'),
2748
+			'id'   => 0,
2749
+		];
2750
+		foreach ($all_terms as $term) {
2751
+			$category_select_values[] = [
2752
+				'text' => $term->name,
2753
+				'id'   => $term->term_id,
2754
+			];
2755
+		}
2756
+		$category_select = EEH_Form_Fields::select_input(
2757
+			'category_parent',
2758
+			$category_select_values,
2759
+			$this->_category->parent
2760
+		);
2761
+		$template_args   = [
2762
+			'category'                 => $this->_category,
2763
+			'category_select'          => $category_select,
2764
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2765
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2766
+			'disable'                  => '',
2767
+			'disabled_message'         => false,
2768
+		];
2769
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2770
+		return EEH_Template::display_template($template, $template_args, true);
2771
+	}
2772
+
2773
+
2774
+	/**
2775
+	 * Handles deleting categories.
2776
+	 *
2777
+	 * @throws EE_Error
2778
+	 */
2779
+	protected function _delete_categories()
2780
+	{
2781
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2782
+		foreach ($category_IDs as $category_ID) {
2783
+			$this->_delete_category($category_ID);
2784
+		}
2785
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2786
+		$query_args = [
2787
+			'action' => 'category_list',
2788
+		];
2789
+		$this->_redirect_after_action(0, '', '', $query_args);
2790
+	}
2791
+
2792
+
2793
+	/**
2794
+	 * Handles deleting specific category.
2795
+	 *
2796
+	 * @param int $cat_id
2797
+	 */
2798
+	protected function _delete_category(int $cat_id)
2799
+	{
2800
+		$cat_id = absint($cat_id);
2801
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * Handles triggering the update or insertion of a new category.
2807
+	 *
2808
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2809
+	 * @throws EE_Error
2810
+	 * @throws EE_Error
2811
+	 */
2812
+	protected function _insert_or_update_category(bool $new_category)
2813
+	{
2814
+		$cat_id  = $this->_insert_category($new_category);
2815
+		$success = 0; // we already have a success message so lets not send another.
2816
+		if ($cat_id) {
2817
+			$query_args = [
2818
+				'action'     => 'edit_category',
2819
+				'EVT_CAT_ID' => $cat_id,
2820
+			];
2821
+		} else {
2822
+			$query_args = ['action' => 'add_category'];
2823
+		}
2824
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2825
+	}
2826
+
2827
+
2828
+	/**
2829
+	 * Inserts or updates category
2830
+	 *
2831
+	 * @param bool $new_category (true indicates we're updating a category).
2832
+	 * @return bool|mixed|string
2833
+	 */
2834
+	private function _insert_category(bool $new_category)
2835
+	{
2836
+		$category_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
2837
+		$category_name       = $this->request->getRequestParam('category_name', '');
2838
+		$category_desc       = $this->request->getRequestParam('category_desc', '', DataType::HTML);
2839
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, DataType::INT);
2840
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2841
+
2842
+		if (empty($category_name)) {
2843
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2844
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2845
+			return 0;
2846
+		}
2847
+		$term_args = [
2848
+			'name'        => $category_name,
2849
+			'description' => $category_desc,
2850
+			'parent'      => $category_parent,
2851
+		];
2852
+		// was the category_identifier input disabled?
2853
+		if ($category_identifier) {
2854
+			$term_args['slug'] = $category_identifier;
2855
+		}
2856
+		$insert_ids = $new_category
2857
+			? wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2858
+			: wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2859
+
2860
+		if ($insert_ids instanceof WP_Error) {
2861
+			EE_Error::add_error($insert_ids->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
2862
+			return 0;
2863
+		}
2864
+		$category_ID = $insert_ids['term_id'] ?? 0;
2865
+		if (! $category_ID) {
2866
+			EE_Error::add_error(
2867
+				esc_html__(
2868
+					'An error occurred and the category has not been saved to the database.',
2869
+					'event_espresso'
2870
+				),
2871
+				__FILE__,
2872
+				__FUNCTION__,
2873
+				__LINE__
2874
+			);
2875
+			return 0;
2876
+		}
2877
+		EE_Error::add_success(
2878
+			sprintf(
2879
+				esc_html__('The category %s was successfully saved', 'event_espresso'),
2880
+				$category_name
2881
+			)
2882
+		);
2883
+		return $category_ID;
2884
+	}
2885
+
2886
+
2887
+	/**
2888
+	 * Gets categories or count of categories matching the arguments in the request.
2889
+	 *
2890
+	 * @param int  $per_page
2891
+	 * @param int  $current_page
2892
+	 * @param bool $count
2893
+	 * @return EE_Term_Taxonomy[]|int
2894
+	 * @throws EE_Error
2895
+	 * @throws ReflectionException
2896
+	 */
2897
+	public function get_categories(int $per_page = 10, int $current_page = 1, bool $count = false)
2898
+	{
2899
+		// testing term stuff
2900
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2901
+		$order       = $this->request->getRequestParam('order', 'DESC');
2902
+		$limit       = ($current_page - 1) * $per_page;
2903
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2904
+		$search_term = $this->request->getRequestParam('s');
2905
+		if ($search_term) {
2906
+			$search_term = '%' . $search_term . '%';
2907
+			$where['OR'] = [
2908
+				'Term.name'   => ['LIKE', $search_term],
2909
+				'description' => ['LIKE', $search_term],
2910
+			];
2911
+		}
2912
+		$query_params = [
2913
+			$where,
2914
+			'order_by'   => [$orderby => $order],
2915
+			'limit'      => $limit . ',' . $per_page,
2916
+			'force_join' => ['Term'],
2917
+		];
2918
+		return $count
2919
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2920
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2921
+	}
2922
+
2923
+	/* end category stuff */
2924
+
2925
+
2926
+	/**************/
2927
+
2928
+
2929
+	/**
2930
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2931
+	 *
2932
+	 * @throws EE_Error
2933
+	 * @throws InvalidArgumentException
2934
+	 * @throws InvalidDataTypeException
2935
+	 * @throws InvalidInterfaceException
2936
+	 */
2937
+	public function saveTimezoneString()
2938
+	{
2939
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2940
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2941
+			EE_Error::add_error(
2942
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2943
+				__FILE__,
2944
+				__FUNCTION__,
2945
+				__LINE__
2946
+			);
2947
+			$this->_template_args['error'] = true;
2948
+			$this->_return_json();
2949
+		}
2950
+
2951
+		update_option('timezone_string', $timezone_string);
2952
+		EE_Error::add_success(
2953
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2954
+		);
2955
+		$this->_template_args['success'] = true;
2956
+		$this->_return_json(true, ['action' => 'create_new']);
2957
+	}
2958
+
2959
+
2960
+	/**
2961
+	 * @throws EE_Error
2962
+	 * @deprecated 4.10.25.p
2963
+	 */
2964
+	public function save_timezonestring_setting()
2965
+	{
2966
+		$this->saveTimezoneString();
2967
+	}
2968 2968
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4084 added lines, -4084 removed lines patch added patch discarded remove patch
@@ -19,2512 +19,2512 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class Messages_Admin_Page extends EE_Admin_Page
21 21
 {
22
-    private ?EEM_Message                   $MSG_MODEL                 = null;
22
+	private ?EEM_Message                   $MSG_MODEL                 = null;
23 23
 
24
-    private ?EEM_Message_Template          $MTP_MODEL                 = null;
24
+	private ?EEM_Message_Template          $MTP_MODEL                 = null;
25 25
 
26
-    private ?EEM_Message_Template_Group    $MTG_MODEL                 = null;
26
+	private ?EEM_Message_Template_Group    $MTG_MODEL                 = null;
27 27
 
28
-    protected ?EE_Message_Resource_Manager $_message_resource_manager = null;
28
+	protected ?EE_Message_Resource_Manager $_message_resource_manager = null;
29 29
 
30
-    protected ?EE_Message_Template_Group   $_message_template_group   = null;
30
+	protected ?EE_Message_Template_Group   $_message_template_group   = null;
31 31
 
32
-    protected ?EE_messenger                $_active_messenger         = null;
32
+	protected ?EE_messenger                $_active_messenger         = null;
33 33
 
34
-    protected ?MessageTemplateManager      $message_template_manager  = null;
34
+	protected ?MessageTemplateManager      $message_template_manager  = null;
35 35
 
36 36
 
37
-    /**
38
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
39
-     * IF there is no group then it gets automatically set to the Default template pack.
40
-     *
41
-     * @since 4.5.0
42
-     */
43
-    protected ?EE_Messages_Template_Pack $_template_pack            = null;
37
+	/**
38
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
39
+	 * IF there is no group then it gets automatically set to the Default template pack.
40
+	 *
41
+	 * @since 4.5.0
42
+	 */
43
+	protected ?EE_Messages_Template_Pack $_template_pack            = null;
44 44
 
45
-    protected array                      $_active_messengers        = [];
46
-
47
-    protected array                      $_active_message_types     = [];
45
+	protected array                      $_active_messengers        = [];
46
+
47
+	protected array                      $_active_message_types     = [];
48 48
 
49
-    protected array                      $_shortcodes               = [];
50
-
51
-    protected array                      $_m_mt_settings            = [];
49
+	protected array                      $_shortcodes               = [];
50
+
51
+	protected array                      $_m_mt_settings            = [];
52 52
 
53
-    protected string                     $_active_message_type_name = '';
53
+	protected string                     $_active_message_type_name = '';
54 54
 
55
-    protected string                     $_active_messenger_name    = '';
56
-
57
-    protected string                     $_context_switcher         = '';
55
+	protected string                     $_active_messenger_name    = '';
56
+
57
+	protected string                     $_context_switcher         = '';
58 58
 
59 59
 
60
-    /**
61
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
62
-     * group is.  If there is no group then it automatically gets set to default.
63
-     *
64
-     * @since 4.5.0
65
-     */
66
-    protected string $_variation = '';
67
-
68
-
69
-    /**
70
-     * @param bool $routing
71
-     * @throws EE_Error
72
-     * @throws ReflectionException
73
-     */
74
-    public function __construct($routing = true)
75
-    {
76
-        // make sure messages autoloader is running
77
-        EED_Messages::set_autoloaders();
78
-        parent::__construct($routing);
79
-    }
80
-
81
-
82
-    /**
83
-     * @return EEM_Message
84
-     * @throws EE_Error
85
-     * @throws ReflectionException
86
-     */
87
-    public function getMsgModel(): EEM_Message
88
-    {
89
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
90
-            $this->MSG_MODEL = EEM_Message::instance();
91
-        }
92
-        return $this->MSG_MODEL;
93
-    }
94
-
95
-
96
-    /**
97
-     * @return EEM_Message_Template
98
-     * @throws EE_Error
99
-     * @throws ReflectionException
100
-     */
101
-    public function getMtpModel(): EEM_Message_Template
102
-    {
103
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
104
-            $this->MTP_MODEL = EEM_Message_Template::instance();
105
-        }
106
-        return $this->MTP_MODEL;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return EEM_Message_Template_Group
112
-     * @throws EE_Error
113
-     * @throws ReflectionException
114
-     */
115
-    public function getMtgModel(): EEM_Message_Template_Group
116
-    {
117
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
118
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
119
-        }
120
-        return $this->MTG_MODEL;
121
-    }
122
-
123
-
124
-    public function getMessageTemplateManager(): MessageTemplateManager
125
-    {
126
-        if (! $this->message_template_manager instanceof MessageTemplateManager) {
127
-            $this->message_template_manager = $this->loader->getShared(MessageTemplateManager::class);
128
-        }
129
-        return $this->message_template_manager;
130
-    }
131
-
132
-
133
-    /**
134
-     * @throws EE_Error
135
-     * @throws ReflectionException
136
-     */
137
-    protected function _init_page_props()
138
-    {
139
-        $this->page_slug        = EE_MSG_PG_SLUG;
140
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
141
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
142
-        $this->_admin_base_path = EE_MSG_ADMIN;
143
-
144
-        $messenger                       = $this->request->getRequestParam('messenger', '');
145
-        $message_type                    = $this->request->getRequestParam('message_type', '');
146
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
147
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
148
-
149
-        $this->_load_message_resource_manager();
150
-    }
151
-
152
-
153
-    protected function _load_message_resource_manager()
154
-    {
155
-        if (! $this->_message_resource_manager instanceof EE_Message_Resource_Manager) {
156
-            $this->_message_resource_manager = $this->loader->getShared(EE_Message_Resource_Manager::class);
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Generate select input with provided messenger options array.
163
-     *
164
-     * @param array $messenger_options Array of messengers indexed by slug and values are the messenger labels.
165
-     * @return string
166
-     * @throws EE_Error
167
-     */
168
-    public function get_messengers_select_input($messenger_options)
169
-    {
170
-        // if empty or just one value then just return an empty string
171
-        if (
172
-            empty($messenger_options)
173
-            || ! is_array($messenger_options)
174
-            || count($messenger_options) === 1
175
-        ) {
176
-            return '';
177
-        }
178
-        // merge in default
179
-        $messenger_options = array_merge(
180
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
181
-            $messenger_options
182
-        );
183
-        $input             = new EE_Select_Input(
184
-            $messenger_options,
185
-            [
186
-                'html_name'  => 'ee_messenger_filter_by',
187
-                'html_id'    => 'ee_messenger_filter_by',
188
-                'html_class' => 'wide',
189
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
190
-            ]
191
-        );
192
-
193
-        return $input->get_html_for_input();
194
-    }
195
-
196
-
197
-    /**
198
-     * Generate select input with provided message type options array.
199
-     *
200
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
201
-     *                                    message type labels
202
-     * @return string
203
-     * @throws EE_Error
204
-     */
205
-    public function get_message_types_select_input($message_type_options)
206
-    {
207
-        // if empty or count of options is 1 then just return an empty string
208
-        if (
209
-            empty($message_type_options)
210
-            || ! is_array($message_type_options)
211
-            || count($message_type_options) === 1
212
-        ) {
213
-            return '';
214
-        }
215
-        // merge in default
216
-        $message_type_options = array_merge(
217
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
218
-            $message_type_options
219
-        );
220
-        $input                = new EE_Select_Input(
221
-            $message_type_options,
222
-            [
223
-                'html_name'  => 'ee_message_type_filter_by',
224
-                'html_id'    => 'ee_message_type_filter_by',
225
-                'html_class' => 'wide',
226
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
227
-            ]
228
-        );
229
-
230
-        return $input->get_html_for_input();
231
-    }
232
-
233
-
234
-    /**
235
-     * Generate select input with provide message type contexts array.
236
-     *
237
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
238
-     *                               context label.
239
-     * @return string
240
-     * @throws EE_Error
241
-     */
242
-    public function get_contexts_for_message_types_select_input($context_options)
243
-    {
244
-        // if empty or count of options is one then just return empty string
245
-        if (
246
-            empty($context_options)
247
-            || ! is_array($context_options)
248
-            || count($context_options) === 1
249
-        ) {
250
-            return '';
251
-        }
252
-        // merge in default
253
-        $context_options = array_merge(
254
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
255
-            $context_options
256
-        );
257
-        $input           = new EE_Select_Input(
258
-            $context_options,
259
-            [
260
-                'html_name'  => 'ee_context_filter_by',
261
-                'html_id'    => 'ee_context_filter_by',
262
-                'html_class' => 'wide',
263
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
264
-            ]
265
-        );
266
-
267
-        return $input->get_html_for_input();
268
-    }
269
-
270
-
271
-    protected function _ajax_hooks()
272
-    {
273
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
274
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
275
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
276
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
277
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
278
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
279
-    }
280
-
281
-
282
-    protected function _define_page_props()
283
-    {
284
-        $this->_admin_page_title = $this->page_label;
285
-        $this->_labels           = [
286
-            'buttons'    => [
287
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
288
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
289
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
290
-            ],
291
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
292
-        ];
293
-    }
294
-
295
-
296
-    /**
297
-     *        an array for storing key => value pairs of request actions and their corresponding methods
298
-     *
299
-     * @access protected
300
-     * @return void
301
-     */
302
-    protected function _set_page_routes()
303
-    {
304
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
305
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, DataType::INTEGER);
306
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, DataType::INTEGER);
307
-
308
-        $this->_page_routes = [
309
-            'default'                          => [
310
-                'func'       => [$this, '_message_queue_list_table'],
311
-                'capability' => 'ee_read_global_messages',
312
-            ],
313
-            'global_mtps'                      => [
314
-                'func'       => [$this, '_ee_default_messages_overview_list_table'],
315
-                'capability' => 'ee_read_global_messages',
316
-            ],
317
-            'custom_mtps'                      => [
318
-                'func'       => [$this, '_custom_mtps_preview'],
319
-                'capability' => 'ee_read_messages',
320
-            ],
321
-            'add_new_message_template'         => [
322
-                'func'       => [$this, 'insertMessageTemplate'],
323
-                'capability' => 'ee_edit_messages',
324
-                'noheader'   => true,
325
-            ],
326
-            'edit_message_template'            => [
327
-                'func'       => [$this, '_edit_message_template'],
328
-                'capability' => 'ee_edit_message',
329
-                'obj_id'     => $GRP_ID,
330
-            ],
331
-            'preview_message'                  => [
332
-                'func'               => [$this, '_preview_message'],
333
-                'capability'         => 'ee_read_message',
334
-                'obj_id'             => $GRP_ID,
335
-                'noheader'           => true,
336
-                'headers_sent_route' => 'display_preview_message',
337
-            ],
338
-            'display_preview_message'          => [
339
-                'func'       => [$this, '_display_preview_message'],
340
-                'capability' => 'ee_read_message',
341
-                'obj_id'     => $GRP_ID,
342
-            ],
343
-            'insert_message_template'          => [
344
-                'func'       => [$this, 'insertMessageTemplate'],
345
-                'capability' => 'ee_edit_messages',
346
-                'noheader'   => true,
347
-            ],
348
-            'update_message_template'          => [
349
-                'func'       => [$this, 'updateMessageTemplate'],
350
-                'capability' => 'ee_edit_message',
351
-                'obj_id'     => $GRP_ID,
352
-                'noheader'   => true,
353
-            ],
354
-            'trash_message_template'           => [
355
-                'func'       => [$this, '_trash_or_restore_message_template'],
356
-                'capability' => 'ee_delete_message',
357
-                'obj_id'     => $GRP_ID,
358
-                'args'       => ['trash' => true, 'all' => true],
359
-                'noheader'   => true,
360
-            ],
361
-            'trash_message_template_context'   => [
362
-                'func'       => [$this, '_trash_or_restore_message_template'],
363
-                'capability' => 'ee_delete_message',
364
-                'obj_id'     => $GRP_ID,
365
-                'args'       => ['trash' => true],
366
-                'noheader'   => true,
367
-            ],
368
-            'restore_message_template'         => [
369
-                'func'       => [$this, '_trash_or_restore_message_template'],
370
-                'capability' => 'ee_delete_message',
371
-                'obj_id'     => $GRP_ID,
372
-                'args'       => ['trash' => false, 'all' => true],
373
-                'noheader'   => true,
374
-            ],
375
-            'restore_message_template_context' => [
376
-                'func'       => [$this, '_trash_or_restore_message_template'],
377
-                'capability' => 'ee_delete_message',
378
-                'obj_id'     => $GRP_ID,
379
-                'args'       => ['trash' => false],
380
-                'noheader'   => true,
381
-            ],
382
-            'delete_message_template'          => [
383
-                'func'       => [$this, '_delete_message_template'],
384
-                'capability' => 'ee_delete_message',
385
-                'obj_id'     => $GRP_ID,
386
-                'noheader'   => true,
387
-            ],
388
-            'reset_to_default'                 => [
389
-                'func'       => [$this, '_reset_to_default_template'],
390
-                'capability' => 'ee_edit_message',
391
-                'obj_id'     => $GRP_ID,
392
-                'noheader'   => true,
393
-            ],
394
-            'settings'                         => [
395
-                'func'       => [$this, '_settings'],
396
-                'capability' => 'manage_options',
397
-            ],
398
-            'update_global_settings'           => [
399
-                'func'       => [$this, '_update_global_settings'],
400
-                'capability' => 'manage_options',
401
-                'noheader'   => true,
402
-            ],
403
-            'generate_now'                     => [
404
-                'func'       => [$this, '_generate_now'],
405
-                'capability' => 'ee_send_message',
406
-                'noheader'   => true,
407
-            ],
408
-            'generate_and_send_now'            => [
409
-                'func'       => [$this, '_generate_and_send_now'],
410
-                'capability' => 'ee_send_message',
411
-                'noheader'   => true,
412
-            ],
413
-            'queue_for_resending'              => [
414
-                'func'       => [$this, '_queue_for_resending'],
415
-                'capability' => 'ee_send_message',
416
-                'noheader'   => true,
417
-            ],
418
-            'send_now'                         => [
419
-                'func'       => [$this, '_send_now'],
420
-                'capability' => 'ee_send_message',
421
-                'noheader'   => true,
422
-            ],
423
-            'delete_ee_message'                => [
424
-                'func'       => [$this, '_delete_ee_messages'],
425
-                'capability' => 'ee_delete_messages',
426
-                'noheader'   => true,
427
-            ],
428
-            'delete_ee_messages'               => [
429
-                'func'       => [$this, '_delete_ee_messages'],
430
-                'capability' => 'ee_delete_messages',
431
-                'noheader'   => true,
432
-                'obj_id'     => $MSG_ID,
433
-            ],
434
-        ];
435
-    }
436
-
437
-
438
-    protected function _set_page_config()
439
-    {
440
-        $this->_page_config = [
441
-            'default'                  => [
442
-                'nav'           => [
443
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
444
-                    'icon'  => 'dashicons-email',
445
-                    'order' => 10,
446
-                ],
447
-                'list_table'    => 'EE_Message_List_Table',
448
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
449
-                'require_nonce' => false,
450
-            ],
451
-            'global_mtps'              => [
452
-                'nav'           => [
453
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
454
-                    'icon'  => 'dashicons-layout',
455
-                    'order' => 20,
456
-                ],
457
-                'list_table'    => 'Messages_Template_List_Table',
458
-                'help_tabs'     => [
459
-                    'messages_overview_help_tab'                                => [
460
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
461
-                        'filename' => 'messages_overview',
462
-                    ],
463
-                    'messages_overview_messages_table_column_headings_help_tab' => [
464
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
465
-                        'filename' => 'messages_overview_table_column_headings',
466
-                    ],
467
-                    'messages_overview_messages_filters_help_tab'               => [
468
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
469
-                        'filename' => 'messages_overview_filters',
470
-                    ],
471
-                    'messages_overview_messages_views_help_tab'                 => [
472
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
473
-                        'filename' => 'messages_overview_views',
474
-                    ],
475
-                    'message_overview_message_types_help_tab'                   => [
476
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
477
-                        'filename' => 'messages_overview_types',
478
-                    ],
479
-                    'messages_overview_messengers_help_tab'                     => [
480
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
481
-                        'filename' => 'messages_overview_messengers',
482
-                    ],
483
-                ],
484
-                'require_nonce' => false,
485
-            ],
486
-            'custom_mtps'              => [
487
-                'nav'           => [
488
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
489
-                    'icon'  => 'dashicons-admin-customizer',
490
-                    'order' => 30,
491
-                ],
492
-                'help_tabs'     => [],
493
-                'require_nonce' => false,
494
-            ],
495
-            'add_new_message_template' => [
496
-                'nav'           => [
497
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
498
-                    'icon'       => 'dashicons-plus-alt',
499
-                    'order'      => 5,
500
-                    'persistent' => false,
501
-                ],
502
-                'require_nonce' => false,
503
-            ],
504
-            'edit_message_template'    => [
505
-                'labels'        => [
506
-                    'buttons'    => [
507
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
508
-                    ],
509
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
510
-                ],
511
-                'nav'           => [
512
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
513
-                    'icon'       => 'dashicons-edit-large',
514
-                    'order'      => 5,
515
-                    'persistent' => false,
516
-                    'url'        => '',
517
-                ],
518
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
519
-                'has_metaboxes' => true,
520
-                'help_tabs'     => [
521
-                    'edit_message_template'            => [
522
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
523
-                        'callback' => 'edit_message_template_help_tab',
524
-                    ],
525
-                    'message_templates_help_tab'       => [
526
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
527
-                        'filename' => 'messages_templates',
528
-                    ],
529
-                    'message_template_shortcodes'      => [
530
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
531
-                        'callback' => 'message_template_shortcodes_help_tab',
532
-                    ],
533
-                    'message_preview_help_tab'         => [
534
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
535
-                        'filename' => 'messages_preview',
536
-                    ],
537
-                    'messages_overview_other_help_tab' => [
538
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
539
-                        'filename' => 'messages_overview_other',
540
-                    ],
541
-                ],
542
-                'require_nonce' => false,
543
-            ],
544
-            'display_preview_message'  => [
545
-                'nav'           => [
546
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
547
-                    'icon'       => 'dashicons-visibility-bar',
548
-                    'order'      => 5,
549
-                    'url'        => '',
550
-                    'persistent' => false,
551
-                ],
552
-                'help_tabs'     => [
553
-                    'preview_message' => [
554
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
555
-                        'callback' => 'preview_message_help_tab',
556
-                    ],
557
-                ],
558
-                'require_nonce' => false,
559
-            ],
560
-            'settings'                 => [
561
-                'nav'           => [
562
-                    'label' => esc_html__('Settings', 'event_espresso'),
563
-                    'icon'  => 'dashicons-admin-generic',
564
-                    'order' => 40,
565
-                ],
566
-                'metaboxes'     => ['_messages_settings_metaboxes'],
567
-                'help_tabs'     => [
568
-                    'messages_settings_help_tab'               => [
569
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
570
-                        'filename' => 'messages_settings',
571
-                    ],
572
-                    'messages_settings_message_types_help_tab' => [
573
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
574
-                        'filename' => 'messages_settings_message_types',
575
-                    ],
576
-                    'messages_settings_messengers_help_tab'    => [
577
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
578
-                        'filename' => 'messages_settings_messengers',
579
-                    ],
580
-                ],
581
-                'require_nonce' => false,
582
-            ],
583
-        ];
584
-    }
585
-
586
-
587
-    protected function _add_screen_options()
588
-    {
589
-        // todo
590
-    }
591
-
592
-
593
-    protected function _add_screen_options_global_mtps()
594
-    {
595
-        /**
596
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
597
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
598
-         */
599
-        $page_title              = $this->_admin_page_title;
600
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
601
-        $this->_per_page_screen_option();
602
-        $this->_admin_page_title = $page_title;
603
-    }
604
-
605
-
606
-    protected function _add_screen_options_default()
607
-    {
608
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
609
-        $this->_per_page_screen_option();
610
-    }
611
-
612
-
613
-    // none of the below group are currently used for Messages
614
-    protected function _add_feature_pointers()
615
-    {
616
-    }
617
-
618
-
619
-    public function admin_init()
620
-    {
621
-    }
622
-
623
-
624
-    public function admin_notices()
625
-    {
626
-    }
627
-
628
-
629
-    public function admin_footer_scripts()
630
-    {
631
-    }
632
-
633
-
634
-    public function messages_help_tab()
635
-    {
636
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
637
-    }
638
-
639
-
640
-    public function messengers_help_tab()
641
-    {
642
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
643
-    }
644
-
645
-
646
-    public function message_types_help_tab()
647
-    {
648
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
649
-    }
650
-
651
-
652
-    public function messages_overview_help_tab()
653
-    {
654
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
655
-    }
656
-
657
-
658
-    public function message_templates_help_tab()
659
-    {
660
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
661
-    }
662
-
663
-
664
-    public function edit_message_template_help_tab()
665
-    {
666
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
667
-                        . esc_attr__('Editor Title', 'event_espresso')
668
-                        . '" />';
669
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
670
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
671
-                        . '" />';
672
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
673
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
674
-                        . '" />';
675
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
676
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
677
-                        . '" />';
678
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
679
-                        . esc_attr__('Publish Metabox', 'event_espresso')
680
-                        . '" />';
681
-        EEH_Template::display_template(
682
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
683
-            $args
684
-        );
685
-    }
686
-
687
-
688
-    /**
689
-     * @throws ReflectionException
690
-     * @throws EE_Error
691
-     */
692
-    public function message_template_shortcodes_help_tab()
693
-    {
694
-        $this->_set_shortcodes();
695
-        $args['shortcodes'] = $this->_shortcodes;
696
-        EEH_Template::display_template(
697
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
698
-            $args
699
-        );
700
-    }
701
-
702
-
703
-    public function preview_message_help_tab()
704
-    {
705
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
706
-    }
707
-
708
-
709
-    public function settings_help_tab()
710
-    {
711
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
712
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
713
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
714
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
715
-        $args['img3'] = '<div class="ee-switch">'
716
-                        . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
717
-                        . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
718
-                        . '</div>';
719
-        $args['img4'] = '<div class="switch">'
720
-                        . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
721
-                        . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
722
-                        . '</div>';
723
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
724
-    }
725
-
726
-
727
-    public function load_scripts_styles()
728
-    {
729
-        wp_enqueue_style(
730
-            'espresso_ee_msg',
731
-            EE_MSG_ASSETS_URL . 'ee_message_admin.css',
732
-            [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
733
-            EVENT_ESPRESSO_VERSION
734
-        );
735
-        wp_enqueue_style(
736
-            'ee_message_shortcodes',
737
-            EE_MSG_ASSETS_URL . 'ee_message_shortcodes.css',
738
-            [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
739
-            EVENT_ESPRESSO_VERSION
740
-        );
741
-
742
-        wp_register_script(
743
-            'ee-messages-settings',
744
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
745
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
746
-            EVENT_ESPRESSO_VERSION,
747
-            true
748
-        );
749
-        wp_register_script(
750
-            'ee-msg-list-table-js',
751
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
752
-            ['ee-dialog'],
753
-            EVENT_ESPRESSO_VERSION
754
-        );
755
-    }
756
-
757
-
758
-    public function load_scripts_styles_default()
759
-    {
760
-        wp_enqueue_script('ee-msg-list-table-js');
761
-    }
762
-
763
-
764
-    public function wp_editor_css($mce_css)
765
-    {
766
-        // if we're on the edit_message_template route
767
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
768
-            $message_type_name = $this->_active_message_type_name;
769
-
770
-            // we're going to REPLACE the existing mce css
771
-            // we need to get the css file location from the active messenger
772
-            $mce_css = $this->_active_messenger->get_variation(
773
-                $this->_template_pack,
774
-                $message_type_name,
775
-                true,
776
-                'wpeditor',
777
-                $this->_variation
778
-            );
779
-        }
780
-
781
-        return $mce_css;
782
-    }
783
-
784
-
785
-    /**
786
-     * @throws EE_Error
787
-     * @throws ReflectionException
788
-     */
789
-    public function load_scripts_styles_edit_message_template()
790
-    {
791
-        $this->_set_shortcodes();
792
-
793
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
794
-            esc_html__(
795
-                '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.',
796
-                'event_espresso'
797
-            ),
798
-            $this->_message_template_group->messenger_obj()->label['singular'],
799
-            $this->_message_template_group->message_type_obj()->label['singular']
800
-        );
801
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
802
-            '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?',
803
-            'event_espresso'
804
-        );
805
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
806
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
807
-            'event_espresso'
808
-        );
809
-
810
-        wp_register_script(
811
-            'ee_msgs_edit_js',
812
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
813
-            ['jquery'],
814
-            EVENT_ESPRESSO_VERSION
815
-        );
816
-
817
-        wp_enqueue_script('ee_admin_js');
818
-        wp_enqueue_script('ee_msgs_edit_js');
819
-
820
-        // add in special css for tiny_mce
821
-        add_filter('mce_css', [$this, 'wp_editor_css']);
822
-    }
823
-
824
-
825
-    /**
826
-     * @throws EE_Error
827
-     * @throws ReflectionException
828
-     */
829
-    public function load_scripts_styles_display_preview_message()
830
-    {
831
-        $this->_set_message_template_group();
832
-        if ($this->_active_messenger_name) {
833
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
834
-                $this->_active_messenger_name
835
-            );
836
-        }
837
-
838
-        wp_enqueue_style(
839
-            'espresso_preview_css',
840
-            $this->_active_messenger->get_variation(
841
-                $this->_template_pack,
842
-                $this->_active_message_type_name,
843
-                true,
844
-                'preview',
845
-                $this->_variation
846
-            )
847
-        );
848
-    }
849
-
850
-
851
-    public function load_scripts_styles_settings()
852
-    {
853
-        wp_register_style(
854
-            'ee-message-settings',
855
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
856
-            [],
857
-            EVENT_ESPRESSO_VERSION
858
-        );
859
-        wp_enqueue_style('ee-text-links');
860
-        wp_enqueue_style('ee-message-settings');
861
-        wp_enqueue_script('ee-messages-settings');
862
-    }
863
-
864
-
865
-    /**
866
-     * set views array for List Table
867
-     */
868
-    public function _set_list_table_views_global_mtps()
869
-    {
870
-        $this->_views = [
871
-            'in_use' => [
872
-                'slug'  => 'in_use',
873
-                'label' => esc_html__('In Use', 'event_espresso'),
874
-                'count' => 0,
875
-            ],
876
-        ];
877
-    }
878
-
879
-
880
-    /**
881
-     * Set views array for the Custom Template List Table
882
-     */
883
-    public function _set_list_table_views_custom_mtps()
884
-    {
885
-        $this->_set_list_table_views_global_mtps();
886
-        $this->_views['in_use']['bulk_action'] = [
887
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
888
-        ];
889
-    }
890
-
891
-
892
-    /**
893
-     * set views array for message queue list table
894
-     *
895
-     * @throws InvalidDataTypeException
896
-     * @throws InvalidInterfaceException
897
-     * @throws InvalidArgumentException
898
-     * @throws EE_Error
899
-     * @throws ReflectionException
900
-     */
901
-    public function _set_list_table_views_default()
902
-    {
903
-        EE_Registry::instance()->load_helper('Template');
904
-
905
-        $common_bulk_actions = $this->capabilities->current_user_can(
906
-            'ee_send_message',
907
-            'message_list_table_bulk_actions'
908
-        )
909
-            ? [
910
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
911
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
912
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
913
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
914
-            ]
915
-            : [];
916
-
917
-        $delete_bulk_action = $this->capabilities->current_user_can(
918
-            'ee_delete_messages',
919
-            'message_list_table_bulk_actions'
920
-        )
921
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
922
-            : [];
923
-
924
-
925
-        $this->_views = [
926
-            'all' => [
927
-                'slug'        => 'all',
928
-                'label'       => esc_html__('All', 'event_espresso'),
929
-                'count'       => 0,
930
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
931
-            ],
932
-        ];
933
-
934
-
935
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
936
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
937
-                continue;
938
-            }
939
-            $status_bulk_actions = $common_bulk_actions;
940
-            // unset bulk actions not applying to status
941
-            if (! empty($status_bulk_actions)) {
942
-                switch ($status) {
943
-                    case EEM_Message::status_idle:
944
-                    case EEM_Message::status_resend:
945
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
946
-                        break;
947
-
948
-                    case EEM_Message::status_failed:
949
-                    case EEM_Message::status_debug_only:
950
-                    case EEM_Message::status_messenger_executing:
951
-                        $status_bulk_actions = [];
952
-                        break;
953
-
954
-                    case EEM_Message::status_incomplete:
955
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
956
-                        break;
957
-
958
-                    case EEM_Message::status_retry:
959
-                    case EEM_Message::status_sent:
960
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
961
-                        break;
962
-                }
963
-            }
964
-
965
-            // skip adding messenger executing status to views because it will be included with the Failed view.
966
-            if ($status === EEM_Message::status_messenger_executing) {
967
-                continue;
968
-            }
969
-
970
-            $this->_views[ strtolower($status) ] = [
971
-                'slug'        => strtolower($status),
972
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
973
-                'count'       => 0,
974
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
975
-            ];
976
-        }
977
-    }
978
-
979
-
980
-    /**
981
-     * @throws EE_Error
982
-     */
983
-    protected function _ee_default_messages_overview_list_table()
984
-    {
985
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
986
-        $this->display_admin_list_table_page_with_no_sidebar();
987
-    }
988
-
989
-
990
-    /**
991
-     * @throws EE_Error
992
-     * @throws ReflectionException
993
-     */
994
-    protected function _message_queue_list_table()
995
-    {
996
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
997
-        $this->_template_args['per_column']        = 6;
998
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
999
-        $message_results                           = trim(EEM_Message::instance()->get_pretty_label_for_results());
1000
-        $this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1001
-        $this->display_admin_list_table_page_with_no_sidebar();
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     * @throws EE_Error
1007
-     */
1008
-    protected function _message_legend_items()
1009
-    {
1010
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1011
-        $action_items       = [];
1012
-
1013
-        foreach ($action_css_classes as $action_item => $action_details) {
1014
-            if ($action_item === 'see_notifications_for') {
1015
-                continue;
1016
-            }
1017
-            $action_items[ $action_item ] = [
1018
-                'class' => $action_details['css_class'],
1019
-                'desc'  => $action_details['label'],
1020
-            ];
1021
-        }
1022
-
1023
-        /** @var array $status_items status legend setup */
1024
-        $status_items = [
1025
-            'sent_status'                => [
1026
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1027
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1028
-            ],
1029
-            'idle_status'                => [
1030
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1031
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1032
-            ],
1033
-            'failed_status'              => [
1034
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1035
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1036
-            ],
1037
-            'messenger_executing_status' => [
1038
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1039
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1040
-            ],
1041
-            'resend_status'              => [
1042
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1043
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1044
-            ],
1045
-            'incomplete_status'          => [
1046
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1047
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1048
-            ],
1049
-            'retry_status'               => [
1050
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1051
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1052
-            ],
1053
-        ];
1054
-        if (EEM_Message::debug()) {
1055
-            $status_items['debug_only_status'] = [
1056
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1057
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1058
-            ];
1059
-        }
1060
-
1061
-        return array_merge($action_items, $status_items);
1062
-    }
1063
-
1064
-
1065
-    /**
1066
-     * @throws EE_Error
1067
-     */
1068
-    protected function _custom_mtps_preview()
1069
-    {
1070
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1071
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1072
-                                                . ' alt="' . esc_attr__(
1073
-                                                    'Preview Custom Message Templates screenshot',
1074
-                                                    'event_espresso'
1075
-                                                ) . '" />';
1076
-        $this->_template_args['preview_text'] = '<strong>'
1077
-                                                . esc_html__(
1078
-                                                    '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.',
1079
-                                                    'event_espresso'
1080
-                                                )
1081
-                                                . '</strong>';
1082
-
1083
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1084
-    }
1085
-
1086
-
1087
-    /**
1088
-     * get_message_templates
1089
-     * This gets all the message templates for listing on the overview list.
1090
-     *
1091
-     * @param int    $per_page the amount of templates groups to show per page
1092
-     * @param string $type     the current _view we're getting templates for
1093
-     * @param bool   $count    return count?
1094
-     * @param bool   $all      disregard any paging info (get all data);
1095
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1096
-     * @return array|int
1097
-     * @throws EE_Error
1098
-     * @throws InvalidArgumentException
1099
-     * @throws InvalidDataTypeException
1100
-     * @throws InvalidInterfaceException
1101
-     * @throws ReflectionException
1102
-     */
1103
-    public function get_message_templates(
1104
-        int $per_page = 10,
1105
-        string $type = 'in_use',
1106
-        bool $count = false,
1107
-        bool $all = false,
1108
-        bool $global = true
1109
-    ) {
1110
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1111
-        // ensure that the orderby param is actually set within the request data
1112
-        $this->request->setRequestParam('orderby', $orderby);
1113
-        $order        = $this->request->getRequestParam('order', 'ASC');
1114
-        $current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
1115
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
1116
-
1117
-        $offset = ($current_page - 1) * $per_page;
1118
-        $limit  = $all ? null : [$offset, $per_page];
1119
-
1120
-        // options will match what is in the _views array property
1121
-        return $type === 'in_use'
1122
-            ? $this->getMtgModel()->get_all_active_message_templates(
1123
-                $orderby,
1124
-                $order,
1125
-                $limit,
1126
-                $count,
1127
-                $global,
1128
-                true
1129
-            )
1130
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1131
-                $orderby,
1132
-                $order,
1133
-                $limit,
1134
-                $count,
1135
-                $global
1136
-            );
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * filters etc might need a list of installed message_types
1142
-     *
1143
-     * @return array an array of message type objects
1144
-     */
1145
-    public function get_installed_message_types(): array
1146
-    {
1147
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1148
-        $installed               = [];
1149
-
1150
-        foreach ($installed_message_types as $message_type) {
1151
-            $installed[ $message_type->name ] = $message_type;
1152
-        }
1153
-
1154
-        return $installed;
1155
-    }
1156
-
1157
-
1158
-    /**
1159
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1160
-     *
1161
-     * @param string     $message_type
1162
-     * @param string     $messenger
1163
-     * @param int|string $GRP_ID
1164
-     * @throws EE_error
1165
-     * @throws ReflectionException
1166
-     * @deprecated 5.0.8.p
1167
-     */
1168
-    public function add_message_template(string $message_type = '', string $messenger = '', $GRP_ID = '')
1169
-    {
1170
-        $this->insertMessageTemplate();
1171
-    }
1172
-
1173
-
1174
-    /**
1175
-     * @param string $message_type     message type slug
1176
-     * @param string $messenger        messenger slug
1177
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1178
-     *                                 off of.
1179
-     * @throws EE_error
1180
-     * @throws ReflectionException
1181
-     * @deprecated 4.10.29.p
1182
-     */
1183
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1184
-    {
1185
-        $this->insertMessageTemplate($message_type, $messenger, $GRP_ID);
1186
-    }
1187
-
1188
-
1189
-    /**
1190
-     * _edit_message_template
1191
-     *
1192
-     * @access protected
1193
-     * @return void
1194
-     * @throws InvalidIdentifierException
1195
-     * @throws DomainException
1196
-     * @throws EE_Error
1197
-     * @throws InvalidArgumentException
1198
-     * @throws ReflectionException
1199
-     * @throws InvalidDataTypeException
1200
-     * @throws InvalidInterfaceException
1201
-     */
1202
-    protected function _edit_message_template()
1203
-    {
1204
-        $template_fields = '';
1205
-        $sidebar_fields  = '';
1206
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1207
-        // valid html in the templates.
1208
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1209
-
1210
-        $GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
1211
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', $GRP_ID, DataType::INTEGER);
1212
-
1213
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
1214
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, DataType::INTEGER);
1215
-
1216
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1217
-        $message_template_group = $this->_message_template_group;
1218
-        $c_label                = $message_template_group->context_label();
1219
-        $c_config               = $message_template_group->contexts_config();
1220
-
1221
-        reset($c_config);
1222
-        $context = $this->request->getRequestParam('context', key($c_config));
1223
-        $context = strtolower($context);
1224
-
1225
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1226
-
1227
-        $edit_message_template_form_url = add_query_arg(
1228
-            ['action' => $action, 'noheader' => true],
1229
-            EE_MSG_ADMIN_URL
1230
-        );
1231
-
1232
-        // set active messenger for this view
1233
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1234
-            $message_template_group->messenger()
1235
-        );
1236
-        $this->_active_message_type_name = $message_template_group->message_type();
1237
-
1238
-
1239
-        // Do we have any validation errors?
1240
-        $validators = $this->_get_transient();
1241
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1242
-
1243
-
1244
-        // we need to assemble the title from Various details
1245
-        $context_label = sprintf(
1246
-            esc_html__('(%s %s)', 'event_espresso'),
1247
-            $c_config[ $context ]['label'],
1248
-            ucwords($c_label['label'])
1249
-        );
1250
-
1251
-        $title = sprintf(
1252
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1253
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1254
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1255
-            $context_label
1256
-        );
1257
-
1258
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1259
-        $this->_template_args['message_template'] = $message_template_group;
1260
-        $this->_template_args['is_extra_fields']  = false;
1261
-
1262
-
1263
-        // let's get EEH_MSG_Template so we can get template form fields
1264
-        $template_field_structure = EEH_MSG_Template::get_fields(
1265
-            $message_template_group->messenger(),
1266
-            $message_template_group->message_type()
1267
-        );
1268
-
1269
-        if (! $template_field_structure) {
1270
-            $template_field_structure = false;
1271
-            $template_fields          = esc_html__(
1272
-                'There was an error in assembling the fields for this display (you should see an error message)',
1273
-                'event_espresso'
1274
-            );
1275
-        }
1276
-
1277
-        $message_templates = $message_template_group->context_templates();
1278
-
1279
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1280
-        // will get handled in the "extra" array.
1281
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1282
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1283
-                unset($template_field_structure[ $context ][ $reference_field ]);
1284
-            }
1285
-        }
1286
-
1287
-        // let's loop through the template_field_structure and actually assemble the input fields!
1288
-        if (! empty($template_field_structure)) {
1289
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1290
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1291
-                // the extra array and reset them.
1292
-                if ($template_field === 'extra') {
1293
-                    $this->_template_args['is_extra_fields'] = true;
1294
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1295
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1296
-                        $content          = $message_template instanceof EE_Message_Template
1297
-                            ? $message_template->get('MTP_content')
1298
-                            : '';
1299
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1300
-                            // let's verify if we need this extra field via the shortcodes parameter.
1301
-                            $continue = false;
1302
-                            if (isset($extra_array['shortcodes_required'])) {
1303
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1304
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1305
-                                        $continue = true;
1306
-                                    }
1307
-                                }
1308
-                                if ($continue) {
1309
-                                    continue;
1310
-                                }
1311
-                            }
1312
-
1313
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1314
-
1315
-                            $template_form_fields[ $field_id ]         = $extra_array;
1316
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1317
-                                                                         . $reference_field
1318
-                                                                         . '][content]['
1319
-                                                                         . $extra_field . ']';
1320
-                            $css_class                                 = $extra_array['css_class'] ?? '';
1321
-
1322
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1323
-                                                                              && in_array($extra_field, $v_fields, true)
1324
-                                                                              && (
1325
-                                                                                  is_array($validators[ $extra_field ])
1326
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1327
-                                                                              )
1328
-                                ? 'validate-error ' . $css_class
1329
-                                : $css_class;
1330
-
1331
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1332
-                                                                          && isset($content[ $extra_field ])
1333
-                                ? $content[ $extra_field ]
1334
-                                : '';
1335
-
1336
-                            // do we have a validation error?  if we do then let's use that value instead
1337
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1338
-                                ? $validators[ $extra_field ]['value']
1339
-                                : $template_form_fields[ $field_id ]['value'];
1340
-
1341
-
1342
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1343
-
1344
-                            // shortcode selector
1345
-                            $field_name_to_use                                   = $extra_field === 'main'
1346
-                                ? 'content'
1347
-                                : $extra_field;
1348
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1349
-                                $field_name_to_use,
1350
-                                $field_id
1351
-                            );
1352
-                        }
1353
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1354
-                        $template_field_template_name_id = $reference_field . '-name';
1355
-
1356
-                        $template_form_fields[ $template_field_MTP_id ] = [
1357
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1358
-                            'label'      => null,
1359
-                            'input'      => 'hidden',
1360
-                            'type'       => 'int',
1361
-                            'required'   => false,
1362
-                            'validation' => false,
1363
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1364
-                            'css_class'  => '',
1365
-                            'format'     => '%d',
1366
-                            'db-col'     => 'MTP_ID',
1367
-                        ];
1368
-
1369
-                        $template_form_fields[ $template_field_template_name_id ] = [
1370
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1371
-                            'label'      => null,
1372
-                            'input'      => 'hidden',
1373
-                            'type'       => 'string',
1374
-                            'required'   => false,
1375
-                            'validation' => true,
1376
-                            'value'      => $reference_field,
1377
-                            'css_class'  => '',
1378
-                            'format'     => '%s',
1379
-                            'db-col'     => 'MTP_template_field',
1380
-                        ];
1381
-                    }
1382
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1383
-                } else {
1384
-                    $field_id                                   = $template_field . '-content';
1385
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1386
-                    $template_form_fields[ $field_id ]['name']  =
1387
-                        'MTP_template_fields[' . $template_field . '][content]';
1388
-                    $message_template                           =
1389
-                        $message_templates[ $context ][ $template_field ] ?? null;
1390
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1391
-                                                                  && is_array($message_templates[ $context ])
1392
-                                                                  && $message_template instanceof EE_Message_Template
1393
-                        ? $message_template->get('MTP_content')
1394
-                        : '';
1395
-
1396
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1397
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1398
-                        ? $validators[ $template_field ]['value']
1399
-                        : $template_form_fields[ $field_id ]['value'];
1400
-
1401
-
1402
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1403
-                    $css_class                                      = $field_setup_array['css_class'] ?? '';
1404
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1405
-                                                                      && in_array($template_field, $v_fields, true)
1406
-                                                                      && isset($validators[ $template_field ]['msg'])
1407
-                        ? 'validate-error ' . $css_class
1408
-                        : $css_class;
1409
-
1410
-                    // shortcode selector
1411
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1412
-                        $template_field,
1413
-                        $field_id
1414
-                    );
1415
-                }
1416
-
1417
-                // k took care of content field(s) now let's take care of others.
1418
-
1419
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1420
-                $template_field_field_template_name_id = $template_field . '-name';
1421
-
1422
-                // foreach template field there are actually two form fields created
1423
-                $template_form_fields[ $template_field_MTP_id ] = [
1424
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1425
-                    'label'      => null,
1426
-                    'input'      => 'hidden',
1427
-                    'type'       => 'int',
1428
-                    'required'   => false,
1429
-                    'validation' => true,
1430
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1431
-                    'css_class'  => '',
1432
-                    'format'     => '%d',
1433
-                    'db-col'     => 'MTP_ID',
1434
-                ];
1435
-
1436
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1437
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1438
-                    'label'      => null,
1439
-                    'input'      => 'hidden',
1440
-                    'type'       => 'string',
1441
-                    'required'   => false,
1442
-                    'validation' => true,
1443
-                    'value'      => $template_field,
1444
-                    'css_class'  => '',
1445
-                    'format'     => '%s',
1446
-                    'db-col'     => 'MTP_template_field',
1447
-                ];
1448
-            }
1449
-
1450
-            // add other fields
1451
-            $template_form_fields['ee-msg-current-context'] = [
1452
-                'name'       => 'MTP_context',
1453
-                'label'      => null,
1454
-                'input'      => 'hidden',
1455
-                'type'       => 'string',
1456
-                'required'   => false,
1457
-                'validation' => true,
1458
-                'value'      => $context,
1459
-                'css_class'  => '',
1460
-                'format'     => '%s',
1461
-                'db-col'     => 'MTP_context',
1462
-            ];
1463
-
1464
-            $template_form_fields['ee-msg-grp-id'] = [
1465
-                'name'       => 'GRP_ID',
1466
-                'label'      => null,
1467
-                'input'      => 'hidden',
1468
-                'type'       => 'int',
1469
-                'required'   => false,
1470
-                'validation' => true,
1471
-                'value'      => $GRP_ID,
1472
-                'css_class'  => '',
1473
-                'format'     => '%d',
1474
-                'db-col'     => 'GRP_ID',
1475
-            ];
1476
-
1477
-            $template_form_fields['ee-msg-messenger'] = [
1478
-                'name'       => 'MTP_messenger',
1479
-                'label'      => null,
1480
-                'input'      => 'hidden',
1481
-                'type'       => 'string',
1482
-                'required'   => false,
1483
-                'validation' => true,
1484
-                'value'      => $message_template_group->messenger(),
1485
-                'css_class'  => '',
1486
-                'format'     => '%s',
1487
-                'db-col'     => 'MTP_messenger',
1488
-            ];
1489
-
1490
-            $template_form_fields['ee-msg-message-type'] = [
1491
-                'name'       => 'MTP_message_type',
1492
-                'label'      => null,
1493
-                'input'      => 'hidden',
1494
-                'type'       => 'string',
1495
-                'required'   => false,
1496
-                'validation' => true,
1497
-                'value'      => $message_template_group->message_type(),
1498
-                'css_class'  => '',
1499
-                'format'     => '%s',
1500
-                'db-col'     => 'MTP_message_type',
1501
-            ];
1502
-
1503
-            $sidebar_form_fields['ee-msg-is-global'] = [
1504
-                'name'       => 'MTP_is_global',
1505
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1506
-                'input'      => 'hidden',
1507
-                'type'       => 'int',
1508
-                'required'   => false,
1509
-                'validation' => true,
1510
-                'value'      => $message_template_group->get('MTP_is_global'),
1511
-                'css_class'  => '',
1512
-                'format'     => '%d',
1513
-                'db-col'     => 'MTP_is_global',
1514
-            ];
1515
-
1516
-            $sidebar_form_fields['ee-msg-is-override'] = [
1517
-                'name'       => 'MTP_is_override',
1518
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1519
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1520
-                'type'       => 'int',
1521
-                'required'   => false,
1522
-                'validation' => true,
1523
-                'value'      => $message_template_group->get('MTP_is_override'),
1524
-                'css_class'  => '',
1525
-                'format'     => '%d',
1526
-                'db-col'     => 'MTP_is_override',
1527
-            ];
1528
-
1529
-            $sidebar_form_fields['ee-msg-is-active'] = [
1530
-                'name'       => 'MTP_is_active',
1531
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1532
-                'input'      => 'hidden',
1533
-                'type'       => 'int',
1534
-                'required'   => false,
1535
-                'validation' => true,
1536
-                'value'      => $message_template_group->is_active(),
1537
-                'css_class'  => '',
1538
-                'format'     => '%d',
1539
-                'db-col'     => 'MTP_is_active',
1540
-            ];
1541
-
1542
-            $sidebar_form_fields['ee-msg-deleted'] = [
1543
-                'name'       => 'MTP_deleted',
1544
-                'label'      => null,
1545
-                'input'      => 'hidden',
1546
-                'type'       => 'int',
1547
-                'required'   => false,
1548
-                'validation' => true,
1549
-                'value'      => $message_template_group->get('MTP_deleted'),
1550
-                'css_class'  => '',
1551
-                'format'     => '%d',
1552
-                'db-col'     => 'MTP_deleted',
1553
-            ];
1554
-            $sidebar_form_fields['ee-msg-author']  = [
1555
-                'name'       => 'MTP_user_id',
1556
-                'label'      => esc_html__('Author', 'event_espresso'),
1557
-                'input'      => 'hidden',
1558
-                'type'       => 'int',
1559
-                'required'   => false,
1560
-                'validation' => false,
1561
-                'value'      => $message_template_group->user(),
1562
-                'format'     => '%d',
1563
-                'db-col'     => 'MTP_user_id',
1564
-            ];
1565
-
1566
-            $sidebar_form_fields['ee-msg-route'] = [
1567
-                'name'  => 'action',
1568
-                'input' => 'hidden',
1569
-                'type'  => 'string',
1570
-                'value' => $action,
1571
-            ];
1572
-
1573
-            $sidebar_form_fields['ee-msg-id']        = [
1574
-                'name'  => 'id',
1575
-                'input' => 'hidden',
1576
-                'type'  => 'int',
1577
-                'value' => $GRP_ID,
1578
-            ];
1579
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1580
-                'name'  => $action . '_nonce',
1581
-                'input' => 'hidden',
1582
-                'type'  => 'string',
1583
-                'value' => wp_create_nonce($action . '_nonce'),
1584
-            ];
1585
-
1586
-            $template_switch = $this->request->getRequestParam('template_switch');
1587
-            if ($template_switch) {
1588
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1589
-                    'name'  => 'template_switch',
1590
-                    'input' => 'hidden',
1591
-                    'type'  => 'int',
1592
-                    'value' => 1,
1593
-                ];
1594
-            }
1595
-
1596
-
1597
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1598
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1599
-        } //end if ( !empty($template_field_structure) )
1600
-
1601
-        // set extra content for publish box
1602
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1603
-        $this->_set_publish_post_box_vars(
1604
-            'id',
1605
-            $GRP_ID,
1606
-            '',
1607
-            add_query_arg(
1608
-                ['action' => $message_template_group->is_global() ? 'global_mtps' : 'custom_mtps'],
1609
-                $this->_admin_base_url
1610
-            ),
1611
-            true
1612
-        );
1613
-
1614
-        // add preview button
1615
-        $preview_url    = parent::add_query_args_and_nonce(
1616
-            [
1617
-                'message_type' => $message_template_group->message_type(),
1618
-                'messenger'    => $message_template_group->messenger(),
1619
-                'context'      => $context,
1620
-                'GRP_ID'       => $GRP_ID,
1621
-                'evt_id'       => $EVT_ID ?: false,
1622
-                'action'       => 'preview_message',
1623
-            ],
1624
-            $this->_admin_base_url
1625
-        );
1626
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1627
-                          . esc_html__('Preview', 'event_espresso')
1628
-                          . '</a>';
1629
-
1630
-
1631
-        // setup context switcher
1632
-        $this->_set_context_switcher(
1633
-            $message_template_group,
1634
-            [
1635
-                'page'    => 'espresso_messages',
1636
-                'action'  => 'edit_message_template',
1637
-                'id'      => $GRP_ID,
1638
-                'evt_id'  => $EVT_ID,
1639
-                'context' => $context,
1640
-                'extra'   => $preview_button,
1641
-            ]
1642
-        );
1643
-
1644
-        // main box
1645
-        $this->_template_args['template_fields']                         = $template_fields;
1646
-        $this->_template_args['sidebar_box_id']                          = 'details';
1647
-        $this->_template_args['action']                                  = $action;
1648
-        $this->_template_args['context']                                 = $context;
1649
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1650
-        $this->_template_args['learn_more_about_message_templates_link'] =
1651
-            $this->_learn_more_about_message_templates_link();
1652
-
1653
-        $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1654
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1655
-            $message_template_group,
1656
-            $context,
1657
-            $context_label
1658
-        );
1659
-        $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1660
-        $this->_template_args['before_admin_page_content'] .= '</div>';
1661
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1662
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1663
-
1664
-        $this->_template_path = $this->_template_args['GRP_ID']
1665
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1666
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1667
-
1668
-        // send along EE_Message_Template_Group object for further template use.
1669
-        $this->_template_args['MTP'] = $message_template_group;
1670
-
1671
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1672
-            $this->_template_path,
1673
-            $this->_template_args,
1674
-            true
1675
-        );
1676
-
1677
-        // finally, let's set the admin_page title
1678
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1679
-
1680
-        // we need to take care of setting the shortcodes property for use elsewhere.
1681
-        $this->_set_shortcodes();
1682
-
1683
-        // final template wrapper
1684
-        $this->display_admin_page_with_sidebar();
1685
-    }
1686
-
1687
-
1688
-    public function filter_tinymce_init($mceInit, $editor_id)
1689
-    {
1690
-        return $mceInit;
1691
-    }
1692
-
1693
-
1694
-    public function add_context_switcher()
1695
-    {
1696
-        return $this->_context_switcher;
1697
-    }
1698
-
1699
-
1700
-    /**
1701
-     * Adds the activation/deactivation toggle for the message template context.
1702
-     *
1703
-     * @param EE_Message_Template_Group $message_template_group
1704
-     * @param string                    $context
1705
-     * @param string                    $context_label
1706
-     * @return string
1707
-     * @throws DomainException
1708
-     * @throws EE_Error
1709
-     * @throws InvalidIdentifierException
1710
-     * @throws ReflectionException
1711
-     */
1712
-    protected function add_active_context_element(
1713
-        EE_Message_Template_Group $message_template_group,
1714
-        $context,
1715
-        $context_label
1716
-    ) {
1717
-        $template_args = [
1718
-            'context'                   => $context,
1719
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1720
-            'is_active'                 => $message_template_group->is_context_active($context),
1721
-            'on_off_action'             => $message_template_group->is_context_active($context)
1722
-                ? 'context-off'
1723
-                : 'context-on',
1724
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1725
-            'message_template_group_id' => $message_template_group->ID(),
1726
-        ];
1727
-        return EEH_Template::display_template(
1728
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1729
-            $template_args,
1730
-            true
1731
-        );
1732
-    }
1733
-
1734
-
1735
-    /**
1736
-     * Ajax callback for `toggle_context_template` ajax action.
1737
-     * Handles toggling the message context on or off.
1738
-     *
1739
-     * @throws EE_Error
1740
-     * @throws InvalidArgumentException
1741
-     * @throws InvalidDataTypeException
1742
-     * @throws InvalidIdentifierException
1743
-     * @throws InvalidInterfaceException
1744
-     * @throws ReflectionException
1745
-     */
1746
-    public function toggle_context_template()
1747
-    {
1748
-        $success = true;
1749
-        // check for required data
1750
-        if (
1751
-            ! (
1752
-                $this->request->requestParamIsSet('message_template_group_id')
1753
-                && $this->request->requestParamIsSet('context')
1754
-                && $this->request->requestParamIsSet('status')
1755
-            )
1756
-        ) {
1757
-            EE_Error::add_error(
1758
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1759
-                __FILE__,
1760
-                __FUNCTION__,
1761
-                __LINE__
1762
-            );
1763
-            $success = false;
1764
-        }
1765
-
1766
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1767
-        $context = $this->request->getRequestParam('context', '');
1768
-        $status  = $this->request->getRequestParam('status', '');
1769
-
1770
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1771
-
1772
-        if ($status !== 'off' && $status !== 'on') {
1773
-            EE_Error::add_error(
1774
-                sprintf(
1775
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1776
-                    $status
1777
-                ),
1778
-                __FILE__,
1779
-                __FUNCTION__,
1780
-                __LINE__
1781
-            );
1782
-            $success = false;
1783
-        }
1784
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, DataType::INTEGER);
1785
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1786
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1787
-            EE_Error::add_error(
1788
-                sprintf(
1789
-                    esc_html__(
1790
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1791
-                        'event_espresso'
1792
-                    ),
1793
-                    $message_template_group_id,
1794
-                    'EE_Message_Template_Group'
1795
-                ),
1796
-                __FILE__,
1797
-                __FUNCTION__,
1798
-                __LINE__
1799
-            );
1800
-            $success = false;
1801
-        }
1802
-        if ($success) {
1803
-            $success = $status === 'off'
1804
-                ? $message_template_group->deactivate_context($context)
1805
-                : $message_template_group->activate_context($context);
1806
-        }
1807
-        $this->_template_args['success'] = $success;
1808
-        $this->_return_json();
1809
-    }
1810
-
1811
-
1812
-    public function _add_form_element_before()
1813
-    {
1814
-        return '<form method="post" action="'
1815
-               . $this->_template_args['edit_message_template_form_url']
1816
-               . '" id="ee-msg-edit-frm">';
1817
-    }
1818
-
1819
-
1820
-    public function _add_form_element_after()
1821
-    {
1822
-        return '</form>';
1823
-    }
1824
-
1825
-
1826
-    /**
1827
-     * This executes switching the template pack for a message template.
1828
-     *
1829
-     * @throws EE_Error
1830
-     * @throws InvalidDataTypeException
1831
-     * @throws InvalidInterfaceException
1832
-     * @throws InvalidArgumentException
1833
-     * @throws ReflectionException
1834
-     * @since 4.5.0
1835
-     */
1836
-    public function switch_template_pack()
1837
-    {
1838
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
1839
-        $template_pack = $this->request->getRequestParam('template_pack', '');
1840
-
1841
-        // verify we have needed values.
1842
-        if (empty($GRP_ID) || empty($template_pack)) {
1843
-            $this->_template_args['error'] = true;
1844
-            EE_Error::add_error(
1845
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1846
-                __FILE__,
1847
-                __FUNCTION__,
1848
-                __LINE__
1849
-            );
1850
-        } else {
1851
-            // get template, set the new template_pack and then reset to default
1852
-            /** @var EE_Message_Template_Group $message_template_group */
1853
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
1854
-
1855
-            $message_template_group->set_template_pack_name($template_pack);
1856
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
1857
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
1858
-
1859
-            $query_args = $this->_reset_to_default_template();
1860
-
1861
-            if (empty($query_args['id'])) {
1862
-                EE_Error::add_error(
1863
-                    esc_html__(
1864
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1865
-                        'event_espresso'
1866
-                    ),
1867
-                    __FILE__,
1868
-                    __FUNCTION__,
1869
-                    __LINE__
1870
-                );
1871
-                $this->_template_args['error'] = true;
1872
-            } else {
1873
-                $template_label       = $message_template_group->get_template_pack()->label;
1874
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1875
-                EE_Error::add_success(
1876
-                    sprintf(
1877
-                        esc_html__(
1878
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1879
-                            'event_espresso'
1880
-                        ),
1881
-                        $template_label,
1882
-                        $template_pack_labels->template_pack
1883
-                    )
1884
-                );
1885
-                // generate the redirect url for js.
1886
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1887
-
1888
-                $this->_template_args['data']['redirect_url'] = $url;
1889
-                $this->_template_args['success']              = true;
1890
-            }
1891
-
1892
-            $this->_return_json();
1893
-        }
1894
-    }
1895
-
1896
-
1897
-    /**
1898
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1899
-     * they want.
1900
-     *
1901
-     * @access protected
1902
-     * @return array|void
1903
-     * @throws EE_Error
1904
-     * @throws InvalidArgumentException
1905
-     * @throws InvalidDataTypeException
1906
-     * @throws InvalidInterfaceException
1907
-     * @throws ReflectionException
1908
-     */
1909
-    protected function _reset_to_default_template()
1910
-    {
1911
-        $templates    = [];
1912
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
1913
-        $messenger    = $this->request->getRequestParam('msgr');
1914
-        $message_type = $this->request->getRequestParam('mt');
1915
-        // we need to make sure we've got the info we need.
1916
-        if (! ($GRP_ID && $messenger && $message_type)) {
1917
-            EE_Error::add_error(
1918
-                esc_html__(
1919
-                    '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.',
1920
-                    'event_espresso'
1921
-                ),
1922
-                __FILE__,
1923
-                __FUNCTION__,
1924
-                __LINE__
1925
-            );
1926
-        }
1927
-
1928
-        // all templates will be reset to whatever the defaults are
1929
-        // for the global template matching the messenger and message type.
1930
-        $success = ! empty($GRP_ID);
1931
-
1932
-        if ($success) {
1933
-            // let's first determine if the incoming template is a global template,
1934
-            // if it isn't then we need to get the global template matching messenger and message type.
1935
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
1936
-
1937
-
1938
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1939
-            $success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplates($GRP_ID);
1940
-
1941
-            if ($success) {
1942
-                // if successfully deleted, lets generate the new ones.
1943
-                // Note. We set GLOBAL to true, because resets on ANY template
1944
-                // will use the related global template defaults for regeneration.
1945
-                // This means that if a custom template is reset it resets to whatever the related global template is.
1946
-                // HOWEVER, we DO keep the template pack and template variation set
1947
-                // for the current custom template when resetting.
1948
-                $templates = $this->getMessageTemplateManager()->generateNewTemplates(
1949
-                    $messenger,
1950
-                    $message_type,
1951
-                    $GRP_ID,
1952
-                    true
1953
-                );
1954
-            }
1955
-        }
1956
-
1957
-        // any error messages?
1958
-        if (! $success) {
1959
-            EE_Error::add_error(
1960
-                esc_html__(
1961
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
1962
-                    'event_espresso'
1963
-                ),
1964
-                __FILE__,
1965
-                __FUNCTION__,
1966
-                __LINE__
1967
-            );
1968
-        }
1969
-
1970
-        // all good, let's add a success message!
1971
-        if ($success && ! empty($templates)) {
1972
-            // the info for the template we generated is the first element in the returned array
1973
-            EE_Error::overwrite_success();
1974
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
1975
-        }
1976
-
1977
-
1978
-        $query_args = [
1979
-            'id'      => $templates['GRP_ID'] ?? null,
1980
-            'context' => $templates['MTP_context'] ?? null,
1981
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
1982
-        ];
1983
-
1984
-        // if called via ajax then we return query args otherwise redirect
1985
-        if ($this->request->isAjax()) {
1986
-            return $query_args;
1987
-        }
1988
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1989
-    }
1990
-
1991
-
1992
-    /**
1993
-     * Retrieve and set the message preview for display.
1994
-     *
1995
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1996
-     * @return string
1997
-     * @throws ReflectionException
1998
-     * @throws EE_Error
1999
-     * @throws InvalidArgumentException
2000
-     * @throws InvalidDataTypeException
2001
-     * @throws InvalidInterfaceException
2002
-     */
2003
-    public function _preview_message($send = false)
2004
-    {
2005
-        // first make sure we've got the necessary parameters
2006
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2007
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2008
-            EE_Error::add_error(
2009
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2010
-                __FILE__,
2011
-                __FUNCTION__,
2012
-                __LINE__
2013
-            );
2014
-        }
2015
-
2016
-        $context = $this->request->getRequestParam('context');
2017
-        // get the preview!
2018
-        $preview = EED_Messages::preview_message(
2019
-            $this->_active_message_type_name,
2020
-            $context,
2021
-            $this->_active_messenger_name,
2022
-            $send
2023
-        );
2024
-
2025
-        if ($send) {
2026
-            return $preview;
2027
-        }
2028
-
2029
-        // if we have an evt_id set on the request, use it.
2030
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
2031
-
2032
-        // let's add a button to go back to the edit view
2033
-        $query_args             = [
2034
-            'id'      => $GRP_ID,
2035
-            'evt_id'  => $EVT_ID,
2036
-            'context' => $context,
2037
-            'action'  => 'edit_message_template',
2038
-        ];
2039
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2040
-        $preview_button         = '<a href="'
2041
-                                  . $go_back_url
2042
-                                  . '" class="button--secondary messages-preview-go-back-button">'
2043
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2044
-                                  . '</a>';
2045
-        $message_types          = $this->get_installed_message_types();
2046
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2047
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2048
-            ? ucwords($active_messenger->label['singular'])
2049
-            : esc_html__('Unknown Messenger', 'event_espresso');
2050
-        // let's provide a helpful title for context
2051
-        $preview_title = sprintf(
2052
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2053
-            $active_messenger_label,
2054
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2055
-        );
2056
-        if (empty($preview)) {
2057
-            $this->noEventsErrorMessage();
2058
-        }
2059
-        // setup display of preview.
2060
-        $this->_admin_page_title                    = $preview_title;
2061
-        $this->_template_args['admin_page_title']   = $preview_title;
2062
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2063
-        $this->_template_args['data']['force_json'] = true;
2064
-
2065
-        return '';
2066
-    }
2067
-
2068
-
2069
-    /**
2070
-     * Used to set an error if there are no events available for generating a preview/test send.
2071
-     *
2072
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2073
-     */
2074
-    protected function noEventsErrorMessage($test_send = false)
2075
-    {
2076
-        $events_url = parent::add_query_args_and_nonce(
2077
-            [
2078
-                'action' => 'default',
2079
-                'page'   => 'espresso_events',
2080
-            ],
2081
-            admin_url('admin.php')
2082
-        );
2083
-        $message    = $test_send
2084
-            ? esc_html__(
2085
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2086
-                'event_espresso'
2087
-            )
2088
-            : esc_html__(
2089
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2090
-                'event_espresso'
2091
-            );
2092
-
2093
-        EE_Error::add_attention(
2094
-            sprintf(
2095
-                $message,
2096
-                "<a href='{$events_url}'>",
2097
-                '</a>'
2098
-            )
2099
-        );
2100
-    }
2101
-
2102
-
2103
-    /**
2104
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2105
-     * gets called automatically.
2106
-     *
2107
-     * @return void
2108
-     * @throws EE_Error
2109
-     * @since 4.5.0
2110
-     */
2111
-    protected function _display_preview_message()
2112
-    {
2113
-        $this->display_admin_page_with_no_sidebar();
2114
-    }
2115
-
2116
-
2117
-    /**
2118
-     * registers metaboxes that should show up on the "edit_message_template" page
2119
-     *
2120
-     * @access protected
2121
-     * @return void
2122
-     */
2123
-    protected function _register_edit_meta_boxes()
2124
-    {
2125
-        $this->addMetaBox(
2126
-            'mtp_valid_shortcodes',
2127
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2128
-            [$this, 'shortcode_meta_box'],
2129
-            $this->_current_screen->id,
2130
-            'side'
2131
-        );
2132
-        $this->addMetaBox(
2133
-            'mtp_extra_actions',
2134
-            esc_html__('Extra Actions', 'event_espresso'),
2135
-            [$this, 'extra_actions_meta_box'],
2136
-            $this->_current_screen->id,
2137
-            'side',
2138
-            'high'
2139
-        );
2140
-        $this->addMetaBox(
2141
-            'mtp_templates',
2142
-            esc_html__('Template Styles', 'event_espresso'),
2143
-            [$this, 'template_pack_meta_box'],
2144
-            $this->_current_screen->id,
2145
-            'side',
2146
-            'high'
2147
-        );
2148
-    }
2149
-
2150
-
2151
-    /**
2152
-     * metabox content for all template pack and variation selection.
2153
-     *
2154
-     * @return void
2155
-     * @throws DomainException
2156
-     * @throws EE_Error
2157
-     * @throws InvalidArgumentException
2158
-     * @throws ReflectionException
2159
-     * @throws InvalidDataTypeException
2160
-     * @throws InvalidInterfaceException
2161
-     * @since 4.5.0
2162
-     */
2163
-    public function template_pack_meta_box()
2164
-    {
2165
-        $this->_set_message_template_group();
2166
-
2167
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2168
-
2169
-        $tp_select_values = [];
2170
-
2171
-        foreach ($tp_collection as $tp) {
2172
-            // only include template packs that support this messenger and message type!
2173
-            $supports = $tp->get_supports();
2174
-            if (
2175
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2176
-                || ! in_array(
2177
-                    $this->_message_template_group->message_type(),
2178
-                    $supports[ $this->_message_template_group->messenger() ],
2179
-                    true
2180
-                )
2181
-            ) {
2182
-                // not supported
2183
-                continue;
2184
-            }
2185
-
2186
-            $tp_select_values[] = [
2187
-                'text' => $tp->label,
2188
-                'id'   => $tp->dbref,
2189
-            ];
2190
-        }
2191
-
2192
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2193
-        // the default template pack.  This still allows for the odd template pack to override.
2194
-        if (empty($tp_select_values)) {
2195
-            $tp_select_values[] = [
2196
-                'text' => esc_html__('Default', 'event_espresso'),
2197
-                'id'   => 'default',
2198
-            ];
2199
-        }
2200
-
2201
-        // setup variation select values for the currently selected template.
2202
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2203
-            $this->_message_template_group->messenger(),
2204
-            $this->_message_template_group->message_type()
2205
-        );
2206
-        $variations_select_values = [];
2207
-        foreach ($variations as $variation => $label) {
2208
-            $variations_select_values[] = [
2209
-                'text' => $label,
2210
-                'id'   => $variation,
2211
-            ];
2212
-        }
2213
-
2214
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2215
-
2216
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2217
-            'MTP_template_pack',
2218
-            $tp_select_values,
2219
-            $this->_message_template_group->get_template_pack_name()
2220
-        );
2221
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2222
-            'MTP_template_variation',
2223
-            $variations_select_values,
2224
-            $this->_message_template_group->get_template_pack_variation()
2225
-        );
2226
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2227
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2228
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2229
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2230
-
2231
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2232
-
2233
-        EEH_Template::display_template($template, $template_args);
2234
-    }
2235
-
2236
-
2237
-    /**
2238
-     * This meta box holds any extra actions related to Message Templates
2239
-     * For now, this includes Resetting templates to defaults and sending a test email.
2240
-     *
2241
-     * @access  public
2242
-     * @return void
2243
-     * @throws EE_Error
2244
-     */
2245
-    public function extra_actions_meta_box()
2246
-    {
2247
-        $template_form_fields = [];
2248
-
2249
-        $extra_args = [
2250
-            'msgr'   => $this->_message_template_group->messenger(),
2251
-            'mt'     => $this->_message_template_group->message_type(),
2252
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2253
-        ];
2254
-        // first we need to see if there are any fields
2255
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2256
-
2257
-        if (! empty($fields)) {
2258
-            // yup there be fields
2259
-            foreach ($fields as $field => $config) {
2260
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2261
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2262
-                $default  = $config['default'] ?? '';
2263
-                $default  = $config['value'] ?? $default;
2264
-
2265
-                // if type is hidden and the value is empty
2266
-                // something may have gone wrong so let's correct with the defaults
2267
-                $fix                = $config['input'] === 'hidden'
2268
-                                      && isset($existing[ $field ])
2269
-                                      && empty($existing[ $field ])
2270
-                    ? $default
2271
-                    : '';
2272
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2273
-                    ? $existing[ $field ]
2274
-                    : $fix;
2275
-
2276
-                $template_form_fields[ $field_id ] = [
2277
-                    'name'       => 'test_settings_fld[' . $field . ']',
2278
-                    'label'      => $config['label'],
2279
-                    'input'      => $config['input'],
2280
-                    'type'       => $config['type'],
2281
-                    'required'   => $config['required'],
2282
-                    'validation' => $config['validation'],
2283
-                    'value'      => $existing[ $field ] ?? $default,
2284
-                    'css_class'  => $config['css_class'],
2285
-                    'options'    => $config['options'] ?? [],
2286
-                    'default'    => $default,
2287
-                    'format'     => $config['format'],
2288
-                ];
2289
-            }
2290
-        }
2291
-
2292
-        $test_settings_html = ! empty($template_form_fields)
2293
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2294
-            : '';
2295
-
2296
-        // print out $test_settings_fields
2297
-        if (! empty($test_settings_html)) {
2298
-            $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2299
-            $test_settings_html .= 'name="test_button" value="';
2300
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2301
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2302
-        }
2303
-
2304
-        // and button
2305
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2306
-        $test_settings_html .= '<p>';
2307
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2308
-        $test_settings_html .= '</p>';
2309
-        $test_settings_html .= $this->get_action_link_or_button(
2310
-            'reset_to_default',
2311
-            'reset',
2312
-            $extra_args,
2313
-            'button--primary reset-default-button'
2314
-        );
2315
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2316
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2317
-    }
2318
-
2319
-
2320
-    /**
2321
-     * This returns the shortcode selector skeleton for a given context and field.
2322
-     *
2323
-     * @param string $field           The name of the field retrieving shortcodes for.
2324
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2325
-     * @return string
2326
-     * @throws DomainException
2327
-     * @throws EE_Error
2328
-     * @throws InvalidArgumentException
2329
-     * @throws ReflectionException
2330
-     * @throws InvalidDataTypeException
2331
-     * @throws InvalidInterfaceException
2332
-     * @since 4.9.rc.000
2333
-     */
2334
-    protected function _get_shortcode_selector($field, $linked_input_id)
2335
-    {
2336
-        $template_args = [
2337
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2338
-            'fieldname'       => $field,
2339
-            'linked_input_id' => $linked_input_id,
2340
-        ];
2341
-
2342
-        return EEH_Template::display_template(
2343
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2344
-            $template_args,
2345
-            true
2346
-        );
2347
-    }
2348
-
2349
-
2350
-    /**
2351
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2352
-     * page)
2353
-     *
2354
-     * @access public
2355
-     * @return void
2356
-     * @throws EE_Error
2357
-     * @throws InvalidArgumentException
2358
-     * @throws ReflectionException
2359
-     * @throws InvalidDataTypeException
2360
-     * @throws InvalidInterfaceException
2361
-     */
2362
-    public function shortcode_meta_box()
2363
-    {
2364
-        $shortcodes = $this->_get_shortcodes([], false);
2365
-        // just make sure the shortcodes property is set
2366
-        // $messenger = $this->_message_template_group->messenger_obj();
2367
-        // now let's set the content depending on the status of the shortcodes array
2368
-        if (empty($shortcodes)) {
2369
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2370
-            return;
2371
-        }
2372
-        ?>
60
+	/**
61
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
62
+	 * group is.  If there is no group then it automatically gets set to default.
63
+	 *
64
+	 * @since 4.5.0
65
+	 */
66
+	protected string $_variation = '';
67
+
68
+
69
+	/**
70
+	 * @param bool $routing
71
+	 * @throws EE_Error
72
+	 * @throws ReflectionException
73
+	 */
74
+	public function __construct($routing = true)
75
+	{
76
+		// make sure messages autoloader is running
77
+		EED_Messages::set_autoloaders();
78
+		parent::__construct($routing);
79
+	}
80
+
81
+
82
+	/**
83
+	 * @return EEM_Message
84
+	 * @throws EE_Error
85
+	 * @throws ReflectionException
86
+	 */
87
+	public function getMsgModel(): EEM_Message
88
+	{
89
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
90
+			$this->MSG_MODEL = EEM_Message::instance();
91
+		}
92
+		return $this->MSG_MODEL;
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return EEM_Message_Template
98
+	 * @throws EE_Error
99
+	 * @throws ReflectionException
100
+	 */
101
+	public function getMtpModel(): EEM_Message_Template
102
+	{
103
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
104
+			$this->MTP_MODEL = EEM_Message_Template::instance();
105
+		}
106
+		return $this->MTP_MODEL;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return EEM_Message_Template_Group
112
+	 * @throws EE_Error
113
+	 * @throws ReflectionException
114
+	 */
115
+	public function getMtgModel(): EEM_Message_Template_Group
116
+	{
117
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
118
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
119
+		}
120
+		return $this->MTG_MODEL;
121
+	}
122
+
123
+
124
+	public function getMessageTemplateManager(): MessageTemplateManager
125
+	{
126
+		if (! $this->message_template_manager instanceof MessageTemplateManager) {
127
+			$this->message_template_manager = $this->loader->getShared(MessageTemplateManager::class);
128
+		}
129
+		return $this->message_template_manager;
130
+	}
131
+
132
+
133
+	/**
134
+	 * @throws EE_Error
135
+	 * @throws ReflectionException
136
+	 */
137
+	protected function _init_page_props()
138
+	{
139
+		$this->page_slug        = EE_MSG_PG_SLUG;
140
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
141
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
142
+		$this->_admin_base_path = EE_MSG_ADMIN;
143
+
144
+		$messenger                       = $this->request->getRequestParam('messenger', '');
145
+		$message_type                    = $this->request->getRequestParam('message_type', '');
146
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
147
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
148
+
149
+		$this->_load_message_resource_manager();
150
+	}
151
+
152
+
153
+	protected function _load_message_resource_manager()
154
+	{
155
+		if (! $this->_message_resource_manager instanceof EE_Message_Resource_Manager) {
156
+			$this->_message_resource_manager = $this->loader->getShared(EE_Message_Resource_Manager::class);
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Generate select input with provided messenger options array.
163
+	 *
164
+	 * @param array $messenger_options Array of messengers indexed by slug and values are the messenger labels.
165
+	 * @return string
166
+	 * @throws EE_Error
167
+	 */
168
+	public function get_messengers_select_input($messenger_options)
169
+	{
170
+		// if empty or just one value then just return an empty string
171
+		if (
172
+			empty($messenger_options)
173
+			|| ! is_array($messenger_options)
174
+			|| count($messenger_options) === 1
175
+		) {
176
+			return '';
177
+		}
178
+		// merge in default
179
+		$messenger_options = array_merge(
180
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
181
+			$messenger_options
182
+		);
183
+		$input             = new EE_Select_Input(
184
+			$messenger_options,
185
+			[
186
+				'html_name'  => 'ee_messenger_filter_by',
187
+				'html_id'    => 'ee_messenger_filter_by',
188
+				'html_class' => 'wide',
189
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
190
+			]
191
+		);
192
+
193
+		return $input->get_html_for_input();
194
+	}
195
+
196
+
197
+	/**
198
+	 * Generate select input with provided message type options array.
199
+	 *
200
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
201
+	 *                                    message type labels
202
+	 * @return string
203
+	 * @throws EE_Error
204
+	 */
205
+	public function get_message_types_select_input($message_type_options)
206
+	{
207
+		// if empty or count of options is 1 then just return an empty string
208
+		if (
209
+			empty($message_type_options)
210
+			|| ! is_array($message_type_options)
211
+			|| count($message_type_options) === 1
212
+		) {
213
+			return '';
214
+		}
215
+		// merge in default
216
+		$message_type_options = array_merge(
217
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
218
+			$message_type_options
219
+		);
220
+		$input                = new EE_Select_Input(
221
+			$message_type_options,
222
+			[
223
+				'html_name'  => 'ee_message_type_filter_by',
224
+				'html_id'    => 'ee_message_type_filter_by',
225
+				'html_class' => 'wide',
226
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
227
+			]
228
+		);
229
+
230
+		return $input->get_html_for_input();
231
+	}
232
+
233
+
234
+	/**
235
+	 * Generate select input with provide message type contexts array.
236
+	 *
237
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
238
+	 *                               context label.
239
+	 * @return string
240
+	 * @throws EE_Error
241
+	 */
242
+	public function get_contexts_for_message_types_select_input($context_options)
243
+	{
244
+		// if empty or count of options is one then just return empty string
245
+		if (
246
+			empty($context_options)
247
+			|| ! is_array($context_options)
248
+			|| count($context_options) === 1
249
+		) {
250
+			return '';
251
+		}
252
+		// merge in default
253
+		$context_options = array_merge(
254
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
255
+			$context_options
256
+		);
257
+		$input           = new EE_Select_Input(
258
+			$context_options,
259
+			[
260
+				'html_name'  => 'ee_context_filter_by',
261
+				'html_id'    => 'ee_context_filter_by',
262
+				'html_class' => 'wide',
263
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
264
+			]
265
+		);
266
+
267
+		return $input->get_html_for_input();
268
+	}
269
+
270
+
271
+	protected function _ajax_hooks()
272
+	{
273
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
274
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
275
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
276
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
277
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
278
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
279
+	}
280
+
281
+
282
+	protected function _define_page_props()
283
+	{
284
+		$this->_admin_page_title = $this->page_label;
285
+		$this->_labels           = [
286
+			'buttons'    => [
287
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
288
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
289
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
290
+			],
291
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
292
+		];
293
+	}
294
+
295
+
296
+	/**
297
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
298
+	 *
299
+	 * @access protected
300
+	 * @return void
301
+	 */
302
+	protected function _set_page_routes()
303
+	{
304
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
305
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, DataType::INTEGER);
306
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, DataType::INTEGER);
307
+
308
+		$this->_page_routes = [
309
+			'default'                          => [
310
+				'func'       => [$this, '_message_queue_list_table'],
311
+				'capability' => 'ee_read_global_messages',
312
+			],
313
+			'global_mtps'                      => [
314
+				'func'       => [$this, '_ee_default_messages_overview_list_table'],
315
+				'capability' => 'ee_read_global_messages',
316
+			],
317
+			'custom_mtps'                      => [
318
+				'func'       => [$this, '_custom_mtps_preview'],
319
+				'capability' => 'ee_read_messages',
320
+			],
321
+			'add_new_message_template'         => [
322
+				'func'       => [$this, 'insertMessageTemplate'],
323
+				'capability' => 'ee_edit_messages',
324
+				'noheader'   => true,
325
+			],
326
+			'edit_message_template'            => [
327
+				'func'       => [$this, '_edit_message_template'],
328
+				'capability' => 'ee_edit_message',
329
+				'obj_id'     => $GRP_ID,
330
+			],
331
+			'preview_message'                  => [
332
+				'func'               => [$this, '_preview_message'],
333
+				'capability'         => 'ee_read_message',
334
+				'obj_id'             => $GRP_ID,
335
+				'noheader'           => true,
336
+				'headers_sent_route' => 'display_preview_message',
337
+			],
338
+			'display_preview_message'          => [
339
+				'func'       => [$this, '_display_preview_message'],
340
+				'capability' => 'ee_read_message',
341
+				'obj_id'     => $GRP_ID,
342
+			],
343
+			'insert_message_template'          => [
344
+				'func'       => [$this, 'insertMessageTemplate'],
345
+				'capability' => 'ee_edit_messages',
346
+				'noheader'   => true,
347
+			],
348
+			'update_message_template'          => [
349
+				'func'       => [$this, 'updateMessageTemplate'],
350
+				'capability' => 'ee_edit_message',
351
+				'obj_id'     => $GRP_ID,
352
+				'noheader'   => true,
353
+			],
354
+			'trash_message_template'           => [
355
+				'func'       => [$this, '_trash_or_restore_message_template'],
356
+				'capability' => 'ee_delete_message',
357
+				'obj_id'     => $GRP_ID,
358
+				'args'       => ['trash' => true, 'all' => true],
359
+				'noheader'   => true,
360
+			],
361
+			'trash_message_template_context'   => [
362
+				'func'       => [$this, '_trash_or_restore_message_template'],
363
+				'capability' => 'ee_delete_message',
364
+				'obj_id'     => $GRP_ID,
365
+				'args'       => ['trash' => true],
366
+				'noheader'   => true,
367
+			],
368
+			'restore_message_template'         => [
369
+				'func'       => [$this, '_trash_or_restore_message_template'],
370
+				'capability' => 'ee_delete_message',
371
+				'obj_id'     => $GRP_ID,
372
+				'args'       => ['trash' => false, 'all' => true],
373
+				'noheader'   => true,
374
+			],
375
+			'restore_message_template_context' => [
376
+				'func'       => [$this, '_trash_or_restore_message_template'],
377
+				'capability' => 'ee_delete_message',
378
+				'obj_id'     => $GRP_ID,
379
+				'args'       => ['trash' => false],
380
+				'noheader'   => true,
381
+			],
382
+			'delete_message_template'          => [
383
+				'func'       => [$this, '_delete_message_template'],
384
+				'capability' => 'ee_delete_message',
385
+				'obj_id'     => $GRP_ID,
386
+				'noheader'   => true,
387
+			],
388
+			'reset_to_default'                 => [
389
+				'func'       => [$this, '_reset_to_default_template'],
390
+				'capability' => 'ee_edit_message',
391
+				'obj_id'     => $GRP_ID,
392
+				'noheader'   => true,
393
+			],
394
+			'settings'                         => [
395
+				'func'       => [$this, '_settings'],
396
+				'capability' => 'manage_options',
397
+			],
398
+			'update_global_settings'           => [
399
+				'func'       => [$this, '_update_global_settings'],
400
+				'capability' => 'manage_options',
401
+				'noheader'   => true,
402
+			],
403
+			'generate_now'                     => [
404
+				'func'       => [$this, '_generate_now'],
405
+				'capability' => 'ee_send_message',
406
+				'noheader'   => true,
407
+			],
408
+			'generate_and_send_now'            => [
409
+				'func'       => [$this, '_generate_and_send_now'],
410
+				'capability' => 'ee_send_message',
411
+				'noheader'   => true,
412
+			],
413
+			'queue_for_resending'              => [
414
+				'func'       => [$this, '_queue_for_resending'],
415
+				'capability' => 'ee_send_message',
416
+				'noheader'   => true,
417
+			],
418
+			'send_now'                         => [
419
+				'func'       => [$this, '_send_now'],
420
+				'capability' => 'ee_send_message',
421
+				'noheader'   => true,
422
+			],
423
+			'delete_ee_message'                => [
424
+				'func'       => [$this, '_delete_ee_messages'],
425
+				'capability' => 'ee_delete_messages',
426
+				'noheader'   => true,
427
+			],
428
+			'delete_ee_messages'               => [
429
+				'func'       => [$this, '_delete_ee_messages'],
430
+				'capability' => 'ee_delete_messages',
431
+				'noheader'   => true,
432
+				'obj_id'     => $MSG_ID,
433
+			],
434
+		];
435
+	}
436
+
437
+
438
+	protected function _set_page_config()
439
+	{
440
+		$this->_page_config = [
441
+			'default'                  => [
442
+				'nav'           => [
443
+					'label' => esc_html__('Message Activity', 'event_espresso'),
444
+					'icon'  => 'dashicons-email',
445
+					'order' => 10,
446
+				],
447
+				'list_table'    => 'EE_Message_List_Table',
448
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
449
+				'require_nonce' => false,
450
+			],
451
+			'global_mtps'              => [
452
+				'nav'           => [
453
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
454
+					'icon'  => 'dashicons-layout',
455
+					'order' => 20,
456
+				],
457
+				'list_table'    => 'Messages_Template_List_Table',
458
+				'help_tabs'     => [
459
+					'messages_overview_help_tab'                                => [
460
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
461
+						'filename' => 'messages_overview',
462
+					],
463
+					'messages_overview_messages_table_column_headings_help_tab' => [
464
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
465
+						'filename' => 'messages_overview_table_column_headings',
466
+					],
467
+					'messages_overview_messages_filters_help_tab'               => [
468
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
469
+						'filename' => 'messages_overview_filters',
470
+					],
471
+					'messages_overview_messages_views_help_tab'                 => [
472
+						'title'    => esc_html__('Message Views', 'event_espresso'),
473
+						'filename' => 'messages_overview_views',
474
+					],
475
+					'message_overview_message_types_help_tab'                   => [
476
+						'title'    => esc_html__('Message Types', 'event_espresso'),
477
+						'filename' => 'messages_overview_types',
478
+					],
479
+					'messages_overview_messengers_help_tab'                     => [
480
+						'title'    => esc_html__('Messengers', 'event_espresso'),
481
+						'filename' => 'messages_overview_messengers',
482
+					],
483
+				],
484
+				'require_nonce' => false,
485
+			],
486
+			'custom_mtps'              => [
487
+				'nav'           => [
488
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
489
+					'icon'  => 'dashicons-admin-customizer',
490
+					'order' => 30,
491
+				],
492
+				'help_tabs'     => [],
493
+				'require_nonce' => false,
494
+			],
495
+			'add_new_message_template' => [
496
+				'nav'           => [
497
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
498
+					'icon'       => 'dashicons-plus-alt',
499
+					'order'      => 5,
500
+					'persistent' => false,
501
+				],
502
+				'require_nonce' => false,
503
+			],
504
+			'edit_message_template'    => [
505
+				'labels'        => [
506
+					'buttons'    => [
507
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
508
+					],
509
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
510
+				],
511
+				'nav'           => [
512
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
513
+					'icon'       => 'dashicons-edit-large',
514
+					'order'      => 5,
515
+					'persistent' => false,
516
+					'url'        => '',
517
+				],
518
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
519
+				'has_metaboxes' => true,
520
+				'help_tabs'     => [
521
+					'edit_message_template'            => [
522
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
523
+						'callback' => 'edit_message_template_help_tab',
524
+					],
525
+					'message_templates_help_tab'       => [
526
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
527
+						'filename' => 'messages_templates',
528
+					],
529
+					'message_template_shortcodes'      => [
530
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
531
+						'callback' => 'message_template_shortcodes_help_tab',
532
+					],
533
+					'message_preview_help_tab'         => [
534
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
535
+						'filename' => 'messages_preview',
536
+					],
537
+					'messages_overview_other_help_tab' => [
538
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
539
+						'filename' => 'messages_overview_other',
540
+					],
541
+				],
542
+				'require_nonce' => false,
543
+			],
544
+			'display_preview_message'  => [
545
+				'nav'           => [
546
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
547
+					'icon'       => 'dashicons-visibility-bar',
548
+					'order'      => 5,
549
+					'url'        => '',
550
+					'persistent' => false,
551
+				],
552
+				'help_tabs'     => [
553
+					'preview_message' => [
554
+						'title'    => esc_html__('About Previews', 'event_espresso'),
555
+						'callback' => 'preview_message_help_tab',
556
+					],
557
+				],
558
+				'require_nonce' => false,
559
+			],
560
+			'settings'                 => [
561
+				'nav'           => [
562
+					'label' => esc_html__('Settings', 'event_espresso'),
563
+					'icon'  => 'dashicons-admin-generic',
564
+					'order' => 40,
565
+				],
566
+				'metaboxes'     => ['_messages_settings_metaboxes'],
567
+				'help_tabs'     => [
568
+					'messages_settings_help_tab'               => [
569
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
570
+						'filename' => 'messages_settings',
571
+					],
572
+					'messages_settings_message_types_help_tab' => [
573
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
574
+						'filename' => 'messages_settings_message_types',
575
+					],
576
+					'messages_settings_messengers_help_tab'    => [
577
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
578
+						'filename' => 'messages_settings_messengers',
579
+					],
580
+				],
581
+				'require_nonce' => false,
582
+			],
583
+		];
584
+	}
585
+
586
+
587
+	protected function _add_screen_options()
588
+	{
589
+		// todo
590
+	}
591
+
592
+
593
+	protected function _add_screen_options_global_mtps()
594
+	{
595
+		/**
596
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
597
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
598
+		 */
599
+		$page_title              = $this->_admin_page_title;
600
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
601
+		$this->_per_page_screen_option();
602
+		$this->_admin_page_title = $page_title;
603
+	}
604
+
605
+
606
+	protected function _add_screen_options_default()
607
+	{
608
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
609
+		$this->_per_page_screen_option();
610
+	}
611
+
612
+
613
+	// none of the below group are currently used for Messages
614
+	protected function _add_feature_pointers()
615
+	{
616
+	}
617
+
618
+
619
+	public function admin_init()
620
+	{
621
+	}
622
+
623
+
624
+	public function admin_notices()
625
+	{
626
+	}
627
+
628
+
629
+	public function admin_footer_scripts()
630
+	{
631
+	}
632
+
633
+
634
+	public function messages_help_tab()
635
+	{
636
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
637
+	}
638
+
639
+
640
+	public function messengers_help_tab()
641
+	{
642
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
643
+	}
644
+
645
+
646
+	public function message_types_help_tab()
647
+	{
648
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
649
+	}
650
+
651
+
652
+	public function messages_overview_help_tab()
653
+	{
654
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
655
+	}
656
+
657
+
658
+	public function message_templates_help_tab()
659
+	{
660
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
661
+	}
662
+
663
+
664
+	public function edit_message_template_help_tab()
665
+	{
666
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
667
+						. esc_attr__('Editor Title', 'event_espresso')
668
+						. '" />';
669
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
670
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
671
+						. '" />';
672
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
673
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
674
+						. '" />';
675
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
676
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
677
+						. '" />';
678
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
679
+						. esc_attr__('Publish Metabox', 'event_espresso')
680
+						. '" />';
681
+		EEH_Template::display_template(
682
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
683
+			$args
684
+		);
685
+	}
686
+
687
+
688
+	/**
689
+	 * @throws ReflectionException
690
+	 * @throws EE_Error
691
+	 */
692
+	public function message_template_shortcodes_help_tab()
693
+	{
694
+		$this->_set_shortcodes();
695
+		$args['shortcodes'] = $this->_shortcodes;
696
+		EEH_Template::display_template(
697
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
698
+			$args
699
+		);
700
+	}
701
+
702
+
703
+	public function preview_message_help_tab()
704
+	{
705
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
706
+	}
707
+
708
+
709
+	public function settings_help_tab()
710
+	{
711
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
712
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
713
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
714
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
715
+		$args['img3'] = '<div class="ee-switch">'
716
+						. '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
717
+						. '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
718
+						. '</div>';
719
+		$args['img4'] = '<div class="switch">'
720
+						. '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
721
+						. '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
722
+						. '</div>';
723
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
724
+	}
725
+
726
+
727
+	public function load_scripts_styles()
728
+	{
729
+		wp_enqueue_style(
730
+			'espresso_ee_msg',
731
+			EE_MSG_ASSETS_URL . 'ee_message_admin.css',
732
+			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
733
+			EVENT_ESPRESSO_VERSION
734
+		);
735
+		wp_enqueue_style(
736
+			'ee_message_shortcodes',
737
+			EE_MSG_ASSETS_URL . 'ee_message_shortcodes.css',
738
+			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
739
+			EVENT_ESPRESSO_VERSION
740
+		);
741
+
742
+		wp_register_script(
743
+			'ee-messages-settings',
744
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
745
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
746
+			EVENT_ESPRESSO_VERSION,
747
+			true
748
+		);
749
+		wp_register_script(
750
+			'ee-msg-list-table-js',
751
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
752
+			['ee-dialog'],
753
+			EVENT_ESPRESSO_VERSION
754
+		);
755
+	}
756
+
757
+
758
+	public function load_scripts_styles_default()
759
+	{
760
+		wp_enqueue_script('ee-msg-list-table-js');
761
+	}
762
+
763
+
764
+	public function wp_editor_css($mce_css)
765
+	{
766
+		// if we're on the edit_message_template route
767
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
768
+			$message_type_name = $this->_active_message_type_name;
769
+
770
+			// we're going to REPLACE the existing mce css
771
+			// we need to get the css file location from the active messenger
772
+			$mce_css = $this->_active_messenger->get_variation(
773
+				$this->_template_pack,
774
+				$message_type_name,
775
+				true,
776
+				'wpeditor',
777
+				$this->_variation
778
+			);
779
+		}
780
+
781
+		return $mce_css;
782
+	}
783
+
784
+
785
+	/**
786
+	 * @throws EE_Error
787
+	 * @throws ReflectionException
788
+	 */
789
+	public function load_scripts_styles_edit_message_template()
790
+	{
791
+		$this->_set_shortcodes();
792
+
793
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
794
+			esc_html__(
795
+				'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.',
796
+				'event_espresso'
797
+			),
798
+			$this->_message_template_group->messenger_obj()->label['singular'],
799
+			$this->_message_template_group->message_type_obj()->label['singular']
800
+		);
801
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
802
+			'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?',
803
+			'event_espresso'
804
+		);
805
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
806
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
807
+			'event_espresso'
808
+		);
809
+
810
+		wp_register_script(
811
+			'ee_msgs_edit_js',
812
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
813
+			['jquery'],
814
+			EVENT_ESPRESSO_VERSION
815
+		);
816
+
817
+		wp_enqueue_script('ee_admin_js');
818
+		wp_enqueue_script('ee_msgs_edit_js');
819
+
820
+		// add in special css for tiny_mce
821
+		add_filter('mce_css', [$this, 'wp_editor_css']);
822
+	}
823
+
824
+
825
+	/**
826
+	 * @throws EE_Error
827
+	 * @throws ReflectionException
828
+	 */
829
+	public function load_scripts_styles_display_preview_message()
830
+	{
831
+		$this->_set_message_template_group();
832
+		if ($this->_active_messenger_name) {
833
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
834
+				$this->_active_messenger_name
835
+			);
836
+		}
837
+
838
+		wp_enqueue_style(
839
+			'espresso_preview_css',
840
+			$this->_active_messenger->get_variation(
841
+				$this->_template_pack,
842
+				$this->_active_message_type_name,
843
+				true,
844
+				'preview',
845
+				$this->_variation
846
+			)
847
+		);
848
+	}
849
+
850
+
851
+	public function load_scripts_styles_settings()
852
+	{
853
+		wp_register_style(
854
+			'ee-message-settings',
855
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
856
+			[],
857
+			EVENT_ESPRESSO_VERSION
858
+		);
859
+		wp_enqueue_style('ee-text-links');
860
+		wp_enqueue_style('ee-message-settings');
861
+		wp_enqueue_script('ee-messages-settings');
862
+	}
863
+
864
+
865
+	/**
866
+	 * set views array for List Table
867
+	 */
868
+	public function _set_list_table_views_global_mtps()
869
+	{
870
+		$this->_views = [
871
+			'in_use' => [
872
+				'slug'  => 'in_use',
873
+				'label' => esc_html__('In Use', 'event_espresso'),
874
+				'count' => 0,
875
+			],
876
+		];
877
+	}
878
+
879
+
880
+	/**
881
+	 * Set views array for the Custom Template List Table
882
+	 */
883
+	public function _set_list_table_views_custom_mtps()
884
+	{
885
+		$this->_set_list_table_views_global_mtps();
886
+		$this->_views['in_use']['bulk_action'] = [
887
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
888
+		];
889
+	}
890
+
891
+
892
+	/**
893
+	 * set views array for message queue list table
894
+	 *
895
+	 * @throws InvalidDataTypeException
896
+	 * @throws InvalidInterfaceException
897
+	 * @throws InvalidArgumentException
898
+	 * @throws EE_Error
899
+	 * @throws ReflectionException
900
+	 */
901
+	public function _set_list_table_views_default()
902
+	{
903
+		EE_Registry::instance()->load_helper('Template');
904
+
905
+		$common_bulk_actions = $this->capabilities->current_user_can(
906
+			'ee_send_message',
907
+			'message_list_table_bulk_actions'
908
+		)
909
+			? [
910
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
911
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
912
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
913
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
914
+			]
915
+			: [];
916
+
917
+		$delete_bulk_action = $this->capabilities->current_user_can(
918
+			'ee_delete_messages',
919
+			'message_list_table_bulk_actions'
920
+		)
921
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
922
+			: [];
923
+
924
+
925
+		$this->_views = [
926
+			'all' => [
927
+				'slug'        => 'all',
928
+				'label'       => esc_html__('All', 'event_espresso'),
929
+				'count'       => 0,
930
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
931
+			],
932
+		];
933
+
934
+
935
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
936
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
937
+				continue;
938
+			}
939
+			$status_bulk_actions = $common_bulk_actions;
940
+			// unset bulk actions not applying to status
941
+			if (! empty($status_bulk_actions)) {
942
+				switch ($status) {
943
+					case EEM_Message::status_idle:
944
+					case EEM_Message::status_resend:
945
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
946
+						break;
947
+
948
+					case EEM_Message::status_failed:
949
+					case EEM_Message::status_debug_only:
950
+					case EEM_Message::status_messenger_executing:
951
+						$status_bulk_actions = [];
952
+						break;
953
+
954
+					case EEM_Message::status_incomplete:
955
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
956
+						break;
957
+
958
+					case EEM_Message::status_retry:
959
+					case EEM_Message::status_sent:
960
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
961
+						break;
962
+				}
963
+			}
964
+
965
+			// skip adding messenger executing status to views because it will be included with the Failed view.
966
+			if ($status === EEM_Message::status_messenger_executing) {
967
+				continue;
968
+			}
969
+
970
+			$this->_views[ strtolower($status) ] = [
971
+				'slug'        => strtolower($status),
972
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
973
+				'count'       => 0,
974
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
975
+			];
976
+		}
977
+	}
978
+
979
+
980
+	/**
981
+	 * @throws EE_Error
982
+	 */
983
+	protected function _ee_default_messages_overview_list_table()
984
+	{
985
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
986
+		$this->display_admin_list_table_page_with_no_sidebar();
987
+	}
988
+
989
+
990
+	/**
991
+	 * @throws EE_Error
992
+	 * @throws ReflectionException
993
+	 */
994
+	protected function _message_queue_list_table()
995
+	{
996
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
997
+		$this->_template_args['per_column']        = 6;
998
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
999
+		$message_results                           = trim(EEM_Message::instance()->get_pretty_label_for_results());
1000
+		$this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1001
+		$this->display_admin_list_table_page_with_no_sidebar();
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 * @throws EE_Error
1007
+	 */
1008
+	protected function _message_legend_items()
1009
+	{
1010
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1011
+		$action_items       = [];
1012
+
1013
+		foreach ($action_css_classes as $action_item => $action_details) {
1014
+			if ($action_item === 'see_notifications_for') {
1015
+				continue;
1016
+			}
1017
+			$action_items[ $action_item ] = [
1018
+				'class' => $action_details['css_class'],
1019
+				'desc'  => $action_details['label'],
1020
+			];
1021
+		}
1022
+
1023
+		/** @var array $status_items status legend setup */
1024
+		$status_items = [
1025
+			'sent_status'                => [
1026
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1027
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1028
+			],
1029
+			'idle_status'                => [
1030
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1031
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1032
+			],
1033
+			'failed_status'              => [
1034
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1035
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1036
+			],
1037
+			'messenger_executing_status' => [
1038
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1039
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1040
+			],
1041
+			'resend_status'              => [
1042
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1043
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1044
+			],
1045
+			'incomplete_status'          => [
1046
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1047
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1048
+			],
1049
+			'retry_status'               => [
1050
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1051
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1052
+			],
1053
+		];
1054
+		if (EEM_Message::debug()) {
1055
+			$status_items['debug_only_status'] = [
1056
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1057
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1058
+			];
1059
+		}
1060
+
1061
+		return array_merge($action_items, $status_items);
1062
+	}
1063
+
1064
+
1065
+	/**
1066
+	 * @throws EE_Error
1067
+	 */
1068
+	protected function _custom_mtps_preview()
1069
+	{
1070
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1071
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1072
+												. ' alt="' . esc_attr__(
1073
+													'Preview Custom Message Templates screenshot',
1074
+													'event_espresso'
1075
+												) . '" />';
1076
+		$this->_template_args['preview_text'] = '<strong>'
1077
+												. esc_html__(
1078
+													'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.',
1079
+													'event_espresso'
1080
+												)
1081
+												. '</strong>';
1082
+
1083
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1084
+	}
1085
+
1086
+
1087
+	/**
1088
+	 * get_message_templates
1089
+	 * This gets all the message templates for listing on the overview list.
1090
+	 *
1091
+	 * @param int    $per_page the amount of templates groups to show per page
1092
+	 * @param string $type     the current _view we're getting templates for
1093
+	 * @param bool   $count    return count?
1094
+	 * @param bool   $all      disregard any paging info (get all data);
1095
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1096
+	 * @return array|int
1097
+	 * @throws EE_Error
1098
+	 * @throws InvalidArgumentException
1099
+	 * @throws InvalidDataTypeException
1100
+	 * @throws InvalidInterfaceException
1101
+	 * @throws ReflectionException
1102
+	 */
1103
+	public function get_message_templates(
1104
+		int $per_page = 10,
1105
+		string $type = 'in_use',
1106
+		bool $count = false,
1107
+		bool $all = false,
1108
+		bool $global = true
1109
+	) {
1110
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1111
+		// ensure that the orderby param is actually set within the request data
1112
+		$this->request->setRequestParam('orderby', $orderby);
1113
+		$order        = $this->request->getRequestParam('order', 'ASC');
1114
+		$current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
1115
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
1116
+
1117
+		$offset = ($current_page - 1) * $per_page;
1118
+		$limit  = $all ? null : [$offset, $per_page];
1119
+
1120
+		// options will match what is in the _views array property
1121
+		return $type === 'in_use'
1122
+			? $this->getMtgModel()->get_all_active_message_templates(
1123
+				$orderby,
1124
+				$order,
1125
+				$limit,
1126
+				$count,
1127
+				$global,
1128
+				true
1129
+			)
1130
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1131
+				$orderby,
1132
+				$order,
1133
+				$limit,
1134
+				$count,
1135
+				$global
1136
+			);
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * filters etc might need a list of installed message_types
1142
+	 *
1143
+	 * @return array an array of message type objects
1144
+	 */
1145
+	public function get_installed_message_types(): array
1146
+	{
1147
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1148
+		$installed               = [];
1149
+
1150
+		foreach ($installed_message_types as $message_type) {
1151
+			$installed[ $message_type->name ] = $message_type;
1152
+		}
1153
+
1154
+		return $installed;
1155
+	}
1156
+
1157
+
1158
+	/**
1159
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1160
+	 *
1161
+	 * @param string     $message_type
1162
+	 * @param string     $messenger
1163
+	 * @param int|string $GRP_ID
1164
+	 * @throws EE_error
1165
+	 * @throws ReflectionException
1166
+	 * @deprecated 5.0.8.p
1167
+	 */
1168
+	public function add_message_template(string $message_type = '', string $messenger = '', $GRP_ID = '')
1169
+	{
1170
+		$this->insertMessageTemplate();
1171
+	}
1172
+
1173
+
1174
+	/**
1175
+	 * @param string $message_type     message type slug
1176
+	 * @param string $messenger        messenger slug
1177
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1178
+	 *                                 off of.
1179
+	 * @throws EE_error
1180
+	 * @throws ReflectionException
1181
+	 * @deprecated 4.10.29.p
1182
+	 */
1183
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1184
+	{
1185
+		$this->insertMessageTemplate($message_type, $messenger, $GRP_ID);
1186
+	}
1187
+
1188
+
1189
+	/**
1190
+	 * _edit_message_template
1191
+	 *
1192
+	 * @access protected
1193
+	 * @return void
1194
+	 * @throws InvalidIdentifierException
1195
+	 * @throws DomainException
1196
+	 * @throws EE_Error
1197
+	 * @throws InvalidArgumentException
1198
+	 * @throws ReflectionException
1199
+	 * @throws InvalidDataTypeException
1200
+	 * @throws InvalidInterfaceException
1201
+	 */
1202
+	protected function _edit_message_template()
1203
+	{
1204
+		$template_fields = '';
1205
+		$sidebar_fields  = '';
1206
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1207
+		// valid html in the templates.
1208
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1209
+
1210
+		$GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
1211
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', $GRP_ID, DataType::INTEGER);
1212
+
1213
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
1214
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, DataType::INTEGER);
1215
+
1216
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1217
+		$message_template_group = $this->_message_template_group;
1218
+		$c_label                = $message_template_group->context_label();
1219
+		$c_config               = $message_template_group->contexts_config();
1220
+
1221
+		reset($c_config);
1222
+		$context = $this->request->getRequestParam('context', key($c_config));
1223
+		$context = strtolower($context);
1224
+
1225
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1226
+
1227
+		$edit_message_template_form_url = add_query_arg(
1228
+			['action' => $action, 'noheader' => true],
1229
+			EE_MSG_ADMIN_URL
1230
+		);
1231
+
1232
+		// set active messenger for this view
1233
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1234
+			$message_template_group->messenger()
1235
+		);
1236
+		$this->_active_message_type_name = $message_template_group->message_type();
1237
+
1238
+
1239
+		// Do we have any validation errors?
1240
+		$validators = $this->_get_transient();
1241
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1242
+
1243
+
1244
+		// we need to assemble the title from Various details
1245
+		$context_label = sprintf(
1246
+			esc_html__('(%s %s)', 'event_espresso'),
1247
+			$c_config[ $context ]['label'],
1248
+			ucwords($c_label['label'])
1249
+		);
1250
+
1251
+		$title = sprintf(
1252
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1253
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1254
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1255
+			$context_label
1256
+		);
1257
+
1258
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1259
+		$this->_template_args['message_template'] = $message_template_group;
1260
+		$this->_template_args['is_extra_fields']  = false;
1261
+
1262
+
1263
+		// let's get EEH_MSG_Template so we can get template form fields
1264
+		$template_field_structure = EEH_MSG_Template::get_fields(
1265
+			$message_template_group->messenger(),
1266
+			$message_template_group->message_type()
1267
+		);
1268
+
1269
+		if (! $template_field_structure) {
1270
+			$template_field_structure = false;
1271
+			$template_fields          = esc_html__(
1272
+				'There was an error in assembling the fields for this display (you should see an error message)',
1273
+				'event_espresso'
1274
+			);
1275
+		}
1276
+
1277
+		$message_templates = $message_template_group->context_templates();
1278
+
1279
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1280
+		// will get handled in the "extra" array.
1281
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1282
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1283
+				unset($template_field_structure[ $context ][ $reference_field ]);
1284
+			}
1285
+		}
1286
+
1287
+		// let's loop through the template_field_structure and actually assemble the input fields!
1288
+		if (! empty($template_field_structure)) {
1289
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1290
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1291
+				// the extra array and reset them.
1292
+				if ($template_field === 'extra') {
1293
+					$this->_template_args['is_extra_fields'] = true;
1294
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1295
+						$message_template = $message_templates[ $context ][ $reference_field ];
1296
+						$content          = $message_template instanceof EE_Message_Template
1297
+							? $message_template->get('MTP_content')
1298
+							: '';
1299
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1300
+							// let's verify if we need this extra field via the shortcodes parameter.
1301
+							$continue = false;
1302
+							if (isset($extra_array['shortcodes_required'])) {
1303
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1304
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1305
+										$continue = true;
1306
+									}
1307
+								}
1308
+								if ($continue) {
1309
+									continue;
1310
+								}
1311
+							}
1312
+
1313
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1314
+
1315
+							$template_form_fields[ $field_id ]         = $extra_array;
1316
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1317
+																		 . $reference_field
1318
+																		 . '][content]['
1319
+																		 . $extra_field . ']';
1320
+							$css_class                                 = $extra_array['css_class'] ?? '';
1321
+
1322
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1323
+																			  && in_array($extra_field, $v_fields, true)
1324
+																			  && (
1325
+																				  is_array($validators[ $extra_field ])
1326
+																				  && isset($validators[ $extra_field ]['msg'])
1327
+																			  )
1328
+								? 'validate-error ' . $css_class
1329
+								: $css_class;
1330
+
1331
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1332
+																		  && isset($content[ $extra_field ])
1333
+								? $content[ $extra_field ]
1334
+								: '';
1335
+
1336
+							// do we have a validation error?  if we do then let's use that value instead
1337
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1338
+								? $validators[ $extra_field ]['value']
1339
+								: $template_form_fields[ $field_id ]['value'];
1340
+
1341
+
1342
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1343
+
1344
+							// shortcode selector
1345
+							$field_name_to_use                                   = $extra_field === 'main'
1346
+								? 'content'
1347
+								: $extra_field;
1348
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1349
+								$field_name_to_use,
1350
+								$field_id
1351
+							);
1352
+						}
1353
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1354
+						$template_field_template_name_id = $reference_field . '-name';
1355
+
1356
+						$template_form_fields[ $template_field_MTP_id ] = [
1357
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1358
+							'label'      => null,
1359
+							'input'      => 'hidden',
1360
+							'type'       => 'int',
1361
+							'required'   => false,
1362
+							'validation' => false,
1363
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1364
+							'css_class'  => '',
1365
+							'format'     => '%d',
1366
+							'db-col'     => 'MTP_ID',
1367
+						];
1368
+
1369
+						$template_form_fields[ $template_field_template_name_id ] = [
1370
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1371
+							'label'      => null,
1372
+							'input'      => 'hidden',
1373
+							'type'       => 'string',
1374
+							'required'   => false,
1375
+							'validation' => true,
1376
+							'value'      => $reference_field,
1377
+							'css_class'  => '',
1378
+							'format'     => '%s',
1379
+							'db-col'     => 'MTP_template_field',
1380
+						];
1381
+					}
1382
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1383
+				} else {
1384
+					$field_id                                   = $template_field . '-content';
1385
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1386
+					$template_form_fields[ $field_id ]['name']  =
1387
+						'MTP_template_fields[' . $template_field . '][content]';
1388
+					$message_template                           =
1389
+						$message_templates[ $context ][ $template_field ] ?? null;
1390
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1391
+																  && is_array($message_templates[ $context ])
1392
+																  && $message_template instanceof EE_Message_Template
1393
+						? $message_template->get('MTP_content')
1394
+						: '';
1395
+
1396
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1397
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1398
+						? $validators[ $template_field ]['value']
1399
+						: $template_form_fields[ $field_id ]['value'];
1400
+
1401
+
1402
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1403
+					$css_class                                      = $field_setup_array['css_class'] ?? '';
1404
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1405
+																	  && in_array($template_field, $v_fields, true)
1406
+																	  && isset($validators[ $template_field ]['msg'])
1407
+						? 'validate-error ' . $css_class
1408
+						: $css_class;
1409
+
1410
+					// shortcode selector
1411
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1412
+						$template_field,
1413
+						$field_id
1414
+					);
1415
+				}
1416
+
1417
+				// k took care of content field(s) now let's take care of others.
1418
+
1419
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1420
+				$template_field_field_template_name_id = $template_field . '-name';
1421
+
1422
+				// foreach template field there are actually two form fields created
1423
+				$template_form_fields[ $template_field_MTP_id ] = [
1424
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1425
+					'label'      => null,
1426
+					'input'      => 'hidden',
1427
+					'type'       => 'int',
1428
+					'required'   => false,
1429
+					'validation' => true,
1430
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1431
+					'css_class'  => '',
1432
+					'format'     => '%d',
1433
+					'db-col'     => 'MTP_ID',
1434
+				];
1435
+
1436
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1437
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1438
+					'label'      => null,
1439
+					'input'      => 'hidden',
1440
+					'type'       => 'string',
1441
+					'required'   => false,
1442
+					'validation' => true,
1443
+					'value'      => $template_field,
1444
+					'css_class'  => '',
1445
+					'format'     => '%s',
1446
+					'db-col'     => 'MTP_template_field',
1447
+				];
1448
+			}
1449
+
1450
+			// add other fields
1451
+			$template_form_fields['ee-msg-current-context'] = [
1452
+				'name'       => 'MTP_context',
1453
+				'label'      => null,
1454
+				'input'      => 'hidden',
1455
+				'type'       => 'string',
1456
+				'required'   => false,
1457
+				'validation' => true,
1458
+				'value'      => $context,
1459
+				'css_class'  => '',
1460
+				'format'     => '%s',
1461
+				'db-col'     => 'MTP_context',
1462
+			];
1463
+
1464
+			$template_form_fields['ee-msg-grp-id'] = [
1465
+				'name'       => 'GRP_ID',
1466
+				'label'      => null,
1467
+				'input'      => 'hidden',
1468
+				'type'       => 'int',
1469
+				'required'   => false,
1470
+				'validation' => true,
1471
+				'value'      => $GRP_ID,
1472
+				'css_class'  => '',
1473
+				'format'     => '%d',
1474
+				'db-col'     => 'GRP_ID',
1475
+			];
1476
+
1477
+			$template_form_fields['ee-msg-messenger'] = [
1478
+				'name'       => 'MTP_messenger',
1479
+				'label'      => null,
1480
+				'input'      => 'hidden',
1481
+				'type'       => 'string',
1482
+				'required'   => false,
1483
+				'validation' => true,
1484
+				'value'      => $message_template_group->messenger(),
1485
+				'css_class'  => '',
1486
+				'format'     => '%s',
1487
+				'db-col'     => 'MTP_messenger',
1488
+			];
1489
+
1490
+			$template_form_fields['ee-msg-message-type'] = [
1491
+				'name'       => 'MTP_message_type',
1492
+				'label'      => null,
1493
+				'input'      => 'hidden',
1494
+				'type'       => 'string',
1495
+				'required'   => false,
1496
+				'validation' => true,
1497
+				'value'      => $message_template_group->message_type(),
1498
+				'css_class'  => '',
1499
+				'format'     => '%s',
1500
+				'db-col'     => 'MTP_message_type',
1501
+			];
1502
+
1503
+			$sidebar_form_fields['ee-msg-is-global'] = [
1504
+				'name'       => 'MTP_is_global',
1505
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1506
+				'input'      => 'hidden',
1507
+				'type'       => 'int',
1508
+				'required'   => false,
1509
+				'validation' => true,
1510
+				'value'      => $message_template_group->get('MTP_is_global'),
1511
+				'css_class'  => '',
1512
+				'format'     => '%d',
1513
+				'db-col'     => 'MTP_is_global',
1514
+			];
1515
+
1516
+			$sidebar_form_fields['ee-msg-is-override'] = [
1517
+				'name'       => 'MTP_is_override',
1518
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1519
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1520
+				'type'       => 'int',
1521
+				'required'   => false,
1522
+				'validation' => true,
1523
+				'value'      => $message_template_group->get('MTP_is_override'),
1524
+				'css_class'  => '',
1525
+				'format'     => '%d',
1526
+				'db-col'     => 'MTP_is_override',
1527
+			];
1528
+
1529
+			$sidebar_form_fields['ee-msg-is-active'] = [
1530
+				'name'       => 'MTP_is_active',
1531
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1532
+				'input'      => 'hidden',
1533
+				'type'       => 'int',
1534
+				'required'   => false,
1535
+				'validation' => true,
1536
+				'value'      => $message_template_group->is_active(),
1537
+				'css_class'  => '',
1538
+				'format'     => '%d',
1539
+				'db-col'     => 'MTP_is_active',
1540
+			];
1541
+
1542
+			$sidebar_form_fields['ee-msg-deleted'] = [
1543
+				'name'       => 'MTP_deleted',
1544
+				'label'      => null,
1545
+				'input'      => 'hidden',
1546
+				'type'       => 'int',
1547
+				'required'   => false,
1548
+				'validation' => true,
1549
+				'value'      => $message_template_group->get('MTP_deleted'),
1550
+				'css_class'  => '',
1551
+				'format'     => '%d',
1552
+				'db-col'     => 'MTP_deleted',
1553
+			];
1554
+			$sidebar_form_fields['ee-msg-author']  = [
1555
+				'name'       => 'MTP_user_id',
1556
+				'label'      => esc_html__('Author', 'event_espresso'),
1557
+				'input'      => 'hidden',
1558
+				'type'       => 'int',
1559
+				'required'   => false,
1560
+				'validation' => false,
1561
+				'value'      => $message_template_group->user(),
1562
+				'format'     => '%d',
1563
+				'db-col'     => 'MTP_user_id',
1564
+			];
1565
+
1566
+			$sidebar_form_fields['ee-msg-route'] = [
1567
+				'name'  => 'action',
1568
+				'input' => 'hidden',
1569
+				'type'  => 'string',
1570
+				'value' => $action,
1571
+			];
1572
+
1573
+			$sidebar_form_fields['ee-msg-id']        = [
1574
+				'name'  => 'id',
1575
+				'input' => 'hidden',
1576
+				'type'  => 'int',
1577
+				'value' => $GRP_ID,
1578
+			];
1579
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1580
+				'name'  => $action . '_nonce',
1581
+				'input' => 'hidden',
1582
+				'type'  => 'string',
1583
+				'value' => wp_create_nonce($action . '_nonce'),
1584
+			];
1585
+
1586
+			$template_switch = $this->request->getRequestParam('template_switch');
1587
+			if ($template_switch) {
1588
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1589
+					'name'  => 'template_switch',
1590
+					'input' => 'hidden',
1591
+					'type'  => 'int',
1592
+					'value' => 1,
1593
+				];
1594
+			}
1595
+
1596
+
1597
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1598
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1599
+		} //end if ( !empty($template_field_structure) )
1600
+
1601
+		// set extra content for publish box
1602
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1603
+		$this->_set_publish_post_box_vars(
1604
+			'id',
1605
+			$GRP_ID,
1606
+			'',
1607
+			add_query_arg(
1608
+				['action' => $message_template_group->is_global() ? 'global_mtps' : 'custom_mtps'],
1609
+				$this->_admin_base_url
1610
+			),
1611
+			true
1612
+		);
1613
+
1614
+		// add preview button
1615
+		$preview_url    = parent::add_query_args_and_nonce(
1616
+			[
1617
+				'message_type' => $message_template_group->message_type(),
1618
+				'messenger'    => $message_template_group->messenger(),
1619
+				'context'      => $context,
1620
+				'GRP_ID'       => $GRP_ID,
1621
+				'evt_id'       => $EVT_ID ?: false,
1622
+				'action'       => 'preview_message',
1623
+			],
1624
+			$this->_admin_base_url
1625
+		);
1626
+		$preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1627
+						  . esc_html__('Preview', 'event_espresso')
1628
+						  . '</a>';
1629
+
1630
+
1631
+		// setup context switcher
1632
+		$this->_set_context_switcher(
1633
+			$message_template_group,
1634
+			[
1635
+				'page'    => 'espresso_messages',
1636
+				'action'  => 'edit_message_template',
1637
+				'id'      => $GRP_ID,
1638
+				'evt_id'  => $EVT_ID,
1639
+				'context' => $context,
1640
+				'extra'   => $preview_button,
1641
+			]
1642
+		);
1643
+
1644
+		// main box
1645
+		$this->_template_args['template_fields']                         = $template_fields;
1646
+		$this->_template_args['sidebar_box_id']                          = 'details';
1647
+		$this->_template_args['action']                                  = $action;
1648
+		$this->_template_args['context']                                 = $context;
1649
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1650
+		$this->_template_args['learn_more_about_message_templates_link'] =
1651
+			$this->_learn_more_about_message_templates_link();
1652
+
1653
+		$this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1654
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1655
+			$message_template_group,
1656
+			$context,
1657
+			$context_label
1658
+		);
1659
+		$this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1660
+		$this->_template_args['before_admin_page_content'] .= '</div>';
1661
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1662
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1663
+
1664
+		$this->_template_path = $this->_template_args['GRP_ID']
1665
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1666
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1667
+
1668
+		// send along EE_Message_Template_Group object for further template use.
1669
+		$this->_template_args['MTP'] = $message_template_group;
1670
+
1671
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1672
+			$this->_template_path,
1673
+			$this->_template_args,
1674
+			true
1675
+		);
1676
+
1677
+		// finally, let's set the admin_page title
1678
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1679
+
1680
+		// we need to take care of setting the shortcodes property for use elsewhere.
1681
+		$this->_set_shortcodes();
1682
+
1683
+		// final template wrapper
1684
+		$this->display_admin_page_with_sidebar();
1685
+	}
1686
+
1687
+
1688
+	public function filter_tinymce_init($mceInit, $editor_id)
1689
+	{
1690
+		return $mceInit;
1691
+	}
1692
+
1693
+
1694
+	public function add_context_switcher()
1695
+	{
1696
+		return $this->_context_switcher;
1697
+	}
1698
+
1699
+
1700
+	/**
1701
+	 * Adds the activation/deactivation toggle for the message template context.
1702
+	 *
1703
+	 * @param EE_Message_Template_Group $message_template_group
1704
+	 * @param string                    $context
1705
+	 * @param string                    $context_label
1706
+	 * @return string
1707
+	 * @throws DomainException
1708
+	 * @throws EE_Error
1709
+	 * @throws InvalidIdentifierException
1710
+	 * @throws ReflectionException
1711
+	 */
1712
+	protected function add_active_context_element(
1713
+		EE_Message_Template_Group $message_template_group,
1714
+		$context,
1715
+		$context_label
1716
+	) {
1717
+		$template_args = [
1718
+			'context'                   => $context,
1719
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1720
+			'is_active'                 => $message_template_group->is_context_active($context),
1721
+			'on_off_action'             => $message_template_group->is_context_active($context)
1722
+				? 'context-off'
1723
+				: 'context-on',
1724
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1725
+			'message_template_group_id' => $message_template_group->ID(),
1726
+		];
1727
+		return EEH_Template::display_template(
1728
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1729
+			$template_args,
1730
+			true
1731
+		);
1732
+	}
1733
+
1734
+
1735
+	/**
1736
+	 * Ajax callback for `toggle_context_template` ajax action.
1737
+	 * Handles toggling the message context on or off.
1738
+	 *
1739
+	 * @throws EE_Error
1740
+	 * @throws InvalidArgumentException
1741
+	 * @throws InvalidDataTypeException
1742
+	 * @throws InvalidIdentifierException
1743
+	 * @throws InvalidInterfaceException
1744
+	 * @throws ReflectionException
1745
+	 */
1746
+	public function toggle_context_template()
1747
+	{
1748
+		$success = true;
1749
+		// check for required data
1750
+		if (
1751
+			! (
1752
+				$this->request->requestParamIsSet('message_template_group_id')
1753
+				&& $this->request->requestParamIsSet('context')
1754
+				&& $this->request->requestParamIsSet('status')
1755
+			)
1756
+		) {
1757
+			EE_Error::add_error(
1758
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1759
+				__FILE__,
1760
+				__FUNCTION__,
1761
+				__LINE__
1762
+			);
1763
+			$success = false;
1764
+		}
1765
+
1766
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1767
+		$context = $this->request->getRequestParam('context', '');
1768
+		$status  = $this->request->getRequestParam('status', '');
1769
+
1770
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1771
+
1772
+		if ($status !== 'off' && $status !== 'on') {
1773
+			EE_Error::add_error(
1774
+				sprintf(
1775
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1776
+					$status
1777
+				),
1778
+				__FILE__,
1779
+				__FUNCTION__,
1780
+				__LINE__
1781
+			);
1782
+			$success = false;
1783
+		}
1784
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, DataType::INTEGER);
1785
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1786
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1787
+			EE_Error::add_error(
1788
+				sprintf(
1789
+					esc_html__(
1790
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1791
+						'event_espresso'
1792
+					),
1793
+					$message_template_group_id,
1794
+					'EE_Message_Template_Group'
1795
+				),
1796
+				__FILE__,
1797
+				__FUNCTION__,
1798
+				__LINE__
1799
+			);
1800
+			$success = false;
1801
+		}
1802
+		if ($success) {
1803
+			$success = $status === 'off'
1804
+				? $message_template_group->deactivate_context($context)
1805
+				: $message_template_group->activate_context($context);
1806
+		}
1807
+		$this->_template_args['success'] = $success;
1808
+		$this->_return_json();
1809
+	}
1810
+
1811
+
1812
+	public function _add_form_element_before()
1813
+	{
1814
+		return '<form method="post" action="'
1815
+			   . $this->_template_args['edit_message_template_form_url']
1816
+			   . '" id="ee-msg-edit-frm">';
1817
+	}
1818
+
1819
+
1820
+	public function _add_form_element_after()
1821
+	{
1822
+		return '</form>';
1823
+	}
1824
+
1825
+
1826
+	/**
1827
+	 * This executes switching the template pack for a message template.
1828
+	 *
1829
+	 * @throws EE_Error
1830
+	 * @throws InvalidDataTypeException
1831
+	 * @throws InvalidInterfaceException
1832
+	 * @throws InvalidArgumentException
1833
+	 * @throws ReflectionException
1834
+	 * @since 4.5.0
1835
+	 */
1836
+	public function switch_template_pack()
1837
+	{
1838
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
1839
+		$template_pack = $this->request->getRequestParam('template_pack', '');
1840
+
1841
+		// verify we have needed values.
1842
+		if (empty($GRP_ID) || empty($template_pack)) {
1843
+			$this->_template_args['error'] = true;
1844
+			EE_Error::add_error(
1845
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1846
+				__FILE__,
1847
+				__FUNCTION__,
1848
+				__LINE__
1849
+			);
1850
+		} else {
1851
+			// get template, set the new template_pack and then reset to default
1852
+			/** @var EE_Message_Template_Group $message_template_group */
1853
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
1854
+
1855
+			$message_template_group->set_template_pack_name($template_pack);
1856
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
1857
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
1858
+
1859
+			$query_args = $this->_reset_to_default_template();
1860
+
1861
+			if (empty($query_args['id'])) {
1862
+				EE_Error::add_error(
1863
+					esc_html__(
1864
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1865
+						'event_espresso'
1866
+					),
1867
+					__FILE__,
1868
+					__FUNCTION__,
1869
+					__LINE__
1870
+				);
1871
+				$this->_template_args['error'] = true;
1872
+			} else {
1873
+				$template_label       = $message_template_group->get_template_pack()->label;
1874
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1875
+				EE_Error::add_success(
1876
+					sprintf(
1877
+						esc_html__(
1878
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1879
+							'event_espresso'
1880
+						),
1881
+						$template_label,
1882
+						$template_pack_labels->template_pack
1883
+					)
1884
+				);
1885
+				// generate the redirect url for js.
1886
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1887
+
1888
+				$this->_template_args['data']['redirect_url'] = $url;
1889
+				$this->_template_args['success']              = true;
1890
+			}
1891
+
1892
+			$this->_return_json();
1893
+		}
1894
+	}
1895
+
1896
+
1897
+	/**
1898
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1899
+	 * they want.
1900
+	 *
1901
+	 * @access protected
1902
+	 * @return array|void
1903
+	 * @throws EE_Error
1904
+	 * @throws InvalidArgumentException
1905
+	 * @throws InvalidDataTypeException
1906
+	 * @throws InvalidInterfaceException
1907
+	 * @throws ReflectionException
1908
+	 */
1909
+	protected function _reset_to_default_template()
1910
+	{
1911
+		$templates    = [];
1912
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
1913
+		$messenger    = $this->request->getRequestParam('msgr');
1914
+		$message_type = $this->request->getRequestParam('mt');
1915
+		// we need to make sure we've got the info we need.
1916
+		if (! ($GRP_ID && $messenger && $message_type)) {
1917
+			EE_Error::add_error(
1918
+				esc_html__(
1919
+					'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.',
1920
+					'event_espresso'
1921
+				),
1922
+				__FILE__,
1923
+				__FUNCTION__,
1924
+				__LINE__
1925
+			);
1926
+		}
1927
+
1928
+		// all templates will be reset to whatever the defaults are
1929
+		// for the global template matching the messenger and message type.
1930
+		$success = ! empty($GRP_ID);
1931
+
1932
+		if ($success) {
1933
+			// let's first determine if the incoming template is a global template,
1934
+			// if it isn't then we need to get the global template matching messenger and message type.
1935
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
1936
+
1937
+
1938
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1939
+			$success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplates($GRP_ID);
1940
+
1941
+			if ($success) {
1942
+				// if successfully deleted, lets generate the new ones.
1943
+				// Note. We set GLOBAL to true, because resets on ANY template
1944
+				// will use the related global template defaults for regeneration.
1945
+				// This means that if a custom template is reset it resets to whatever the related global template is.
1946
+				// HOWEVER, we DO keep the template pack and template variation set
1947
+				// for the current custom template when resetting.
1948
+				$templates = $this->getMessageTemplateManager()->generateNewTemplates(
1949
+					$messenger,
1950
+					$message_type,
1951
+					$GRP_ID,
1952
+					true
1953
+				);
1954
+			}
1955
+		}
1956
+
1957
+		// any error messages?
1958
+		if (! $success) {
1959
+			EE_Error::add_error(
1960
+				esc_html__(
1961
+					'Something went wrong with deleting existing templates. Unable to reset to default',
1962
+					'event_espresso'
1963
+				),
1964
+				__FILE__,
1965
+				__FUNCTION__,
1966
+				__LINE__
1967
+			);
1968
+		}
1969
+
1970
+		// all good, let's add a success message!
1971
+		if ($success && ! empty($templates)) {
1972
+			// the info for the template we generated is the first element in the returned array
1973
+			EE_Error::overwrite_success();
1974
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
1975
+		}
1976
+
1977
+
1978
+		$query_args = [
1979
+			'id'      => $templates['GRP_ID'] ?? null,
1980
+			'context' => $templates['MTP_context'] ?? null,
1981
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
1982
+		];
1983
+
1984
+		// if called via ajax then we return query args otherwise redirect
1985
+		if ($this->request->isAjax()) {
1986
+			return $query_args;
1987
+		}
1988
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1989
+	}
1990
+
1991
+
1992
+	/**
1993
+	 * Retrieve and set the message preview for display.
1994
+	 *
1995
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1996
+	 * @return string
1997
+	 * @throws ReflectionException
1998
+	 * @throws EE_Error
1999
+	 * @throws InvalidArgumentException
2000
+	 * @throws InvalidDataTypeException
2001
+	 * @throws InvalidInterfaceException
2002
+	 */
2003
+	public function _preview_message($send = false)
2004
+	{
2005
+		// first make sure we've got the necessary parameters
2006
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2007
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2008
+			EE_Error::add_error(
2009
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2010
+				__FILE__,
2011
+				__FUNCTION__,
2012
+				__LINE__
2013
+			);
2014
+		}
2015
+
2016
+		$context = $this->request->getRequestParam('context');
2017
+		// get the preview!
2018
+		$preview = EED_Messages::preview_message(
2019
+			$this->_active_message_type_name,
2020
+			$context,
2021
+			$this->_active_messenger_name,
2022
+			$send
2023
+		);
2024
+
2025
+		if ($send) {
2026
+			return $preview;
2027
+		}
2028
+
2029
+		// if we have an evt_id set on the request, use it.
2030
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
2031
+
2032
+		// let's add a button to go back to the edit view
2033
+		$query_args             = [
2034
+			'id'      => $GRP_ID,
2035
+			'evt_id'  => $EVT_ID,
2036
+			'context' => $context,
2037
+			'action'  => 'edit_message_template',
2038
+		];
2039
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2040
+		$preview_button         = '<a href="'
2041
+								  . $go_back_url
2042
+								  . '" class="button--secondary messages-preview-go-back-button">'
2043
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2044
+								  . '</a>';
2045
+		$message_types          = $this->get_installed_message_types();
2046
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2047
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2048
+			? ucwords($active_messenger->label['singular'])
2049
+			: esc_html__('Unknown Messenger', 'event_espresso');
2050
+		// let's provide a helpful title for context
2051
+		$preview_title = sprintf(
2052
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2053
+			$active_messenger_label,
2054
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2055
+		);
2056
+		if (empty($preview)) {
2057
+			$this->noEventsErrorMessage();
2058
+		}
2059
+		// setup display of preview.
2060
+		$this->_admin_page_title                    = $preview_title;
2061
+		$this->_template_args['admin_page_title']   = $preview_title;
2062
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2063
+		$this->_template_args['data']['force_json'] = true;
2064
+
2065
+		return '';
2066
+	}
2067
+
2068
+
2069
+	/**
2070
+	 * Used to set an error if there are no events available for generating a preview/test send.
2071
+	 *
2072
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2073
+	 */
2074
+	protected function noEventsErrorMessage($test_send = false)
2075
+	{
2076
+		$events_url = parent::add_query_args_and_nonce(
2077
+			[
2078
+				'action' => 'default',
2079
+				'page'   => 'espresso_events',
2080
+			],
2081
+			admin_url('admin.php')
2082
+		);
2083
+		$message    = $test_send
2084
+			? esc_html__(
2085
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2086
+				'event_espresso'
2087
+			)
2088
+			: esc_html__(
2089
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2090
+				'event_espresso'
2091
+			);
2092
+
2093
+		EE_Error::add_attention(
2094
+			sprintf(
2095
+				$message,
2096
+				"<a href='{$events_url}'>",
2097
+				'</a>'
2098
+			)
2099
+		);
2100
+	}
2101
+
2102
+
2103
+	/**
2104
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2105
+	 * gets called automatically.
2106
+	 *
2107
+	 * @return void
2108
+	 * @throws EE_Error
2109
+	 * @since 4.5.0
2110
+	 */
2111
+	protected function _display_preview_message()
2112
+	{
2113
+		$this->display_admin_page_with_no_sidebar();
2114
+	}
2115
+
2116
+
2117
+	/**
2118
+	 * registers metaboxes that should show up on the "edit_message_template" page
2119
+	 *
2120
+	 * @access protected
2121
+	 * @return void
2122
+	 */
2123
+	protected function _register_edit_meta_boxes()
2124
+	{
2125
+		$this->addMetaBox(
2126
+			'mtp_valid_shortcodes',
2127
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2128
+			[$this, 'shortcode_meta_box'],
2129
+			$this->_current_screen->id,
2130
+			'side'
2131
+		);
2132
+		$this->addMetaBox(
2133
+			'mtp_extra_actions',
2134
+			esc_html__('Extra Actions', 'event_espresso'),
2135
+			[$this, 'extra_actions_meta_box'],
2136
+			$this->_current_screen->id,
2137
+			'side',
2138
+			'high'
2139
+		);
2140
+		$this->addMetaBox(
2141
+			'mtp_templates',
2142
+			esc_html__('Template Styles', 'event_espresso'),
2143
+			[$this, 'template_pack_meta_box'],
2144
+			$this->_current_screen->id,
2145
+			'side',
2146
+			'high'
2147
+		);
2148
+	}
2149
+
2150
+
2151
+	/**
2152
+	 * metabox content for all template pack and variation selection.
2153
+	 *
2154
+	 * @return void
2155
+	 * @throws DomainException
2156
+	 * @throws EE_Error
2157
+	 * @throws InvalidArgumentException
2158
+	 * @throws ReflectionException
2159
+	 * @throws InvalidDataTypeException
2160
+	 * @throws InvalidInterfaceException
2161
+	 * @since 4.5.0
2162
+	 */
2163
+	public function template_pack_meta_box()
2164
+	{
2165
+		$this->_set_message_template_group();
2166
+
2167
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2168
+
2169
+		$tp_select_values = [];
2170
+
2171
+		foreach ($tp_collection as $tp) {
2172
+			// only include template packs that support this messenger and message type!
2173
+			$supports = $tp->get_supports();
2174
+			if (
2175
+				! isset($supports[ $this->_message_template_group->messenger() ])
2176
+				|| ! in_array(
2177
+					$this->_message_template_group->message_type(),
2178
+					$supports[ $this->_message_template_group->messenger() ],
2179
+					true
2180
+				)
2181
+			) {
2182
+				// not supported
2183
+				continue;
2184
+			}
2185
+
2186
+			$tp_select_values[] = [
2187
+				'text' => $tp->label,
2188
+				'id'   => $tp->dbref,
2189
+			];
2190
+		}
2191
+
2192
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2193
+		// the default template pack.  This still allows for the odd template pack to override.
2194
+		if (empty($tp_select_values)) {
2195
+			$tp_select_values[] = [
2196
+				'text' => esc_html__('Default', 'event_espresso'),
2197
+				'id'   => 'default',
2198
+			];
2199
+		}
2200
+
2201
+		// setup variation select values for the currently selected template.
2202
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2203
+			$this->_message_template_group->messenger(),
2204
+			$this->_message_template_group->message_type()
2205
+		);
2206
+		$variations_select_values = [];
2207
+		foreach ($variations as $variation => $label) {
2208
+			$variations_select_values[] = [
2209
+				'text' => $label,
2210
+				'id'   => $variation,
2211
+			];
2212
+		}
2213
+
2214
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2215
+
2216
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2217
+			'MTP_template_pack',
2218
+			$tp_select_values,
2219
+			$this->_message_template_group->get_template_pack_name()
2220
+		);
2221
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2222
+			'MTP_template_variation',
2223
+			$variations_select_values,
2224
+			$this->_message_template_group->get_template_pack_variation()
2225
+		);
2226
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2227
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2228
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2229
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2230
+
2231
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2232
+
2233
+		EEH_Template::display_template($template, $template_args);
2234
+	}
2235
+
2236
+
2237
+	/**
2238
+	 * This meta box holds any extra actions related to Message Templates
2239
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2240
+	 *
2241
+	 * @access  public
2242
+	 * @return void
2243
+	 * @throws EE_Error
2244
+	 */
2245
+	public function extra_actions_meta_box()
2246
+	{
2247
+		$template_form_fields = [];
2248
+
2249
+		$extra_args = [
2250
+			'msgr'   => $this->_message_template_group->messenger(),
2251
+			'mt'     => $this->_message_template_group->message_type(),
2252
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2253
+		];
2254
+		// first we need to see if there are any fields
2255
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2256
+
2257
+		if (! empty($fields)) {
2258
+			// yup there be fields
2259
+			foreach ($fields as $field => $config) {
2260
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2261
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2262
+				$default  = $config['default'] ?? '';
2263
+				$default  = $config['value'] ?? $default;
2264
+
2265
+				// if type is hidden and the value is empty
2266
+				// something may have gone wrong so let's correct with the defaults
2267
+				$fix                = $config['input'] === 'hidden'
2268
+									  && isset($existing[ $field ])
2269
+									  && empty($existing[ $field ])
2270
+					? $default
2271
+					: '';
2272
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2273
+					? $existing[ $field ]
2274
+					: $fix;
2275
+
2276
+				$template_form_fields[ $field_id ] = [
2277
+					'name'       => 'test_settings_fld[' . $field . ']',
2278
+					'label'      => $config['label'],
2279
+					'input'      => $config['input'],
2280
+					'type'       => $config['type'],
2281
+					'required'   => $config['required'],
2282
+					'validation' => $config['validation'],
2283
+					'value'      => $existing[ $field ] ?? $default,
2284
+					'css_class'  => $config['css_class'],
2285
+					'options'    => $config['options'] ?? [],
2286
+					'default'    => $default,
2287
+					'format'     => $config['format'],
2288
+				];
2289
+			}
2290
+		}
2291
+
2292
+		$test_settings_html = ! empty($template_form_fields)
2293
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2294
+			: '';
2295
+
2296
+		// print out $test_settings_fields
2297
+		if (! empty($test_settings_html)) {
2298
+			$test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2299
+			$test_settings_html .= 'name="test_button" value="';
2300
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2301
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2302
+		}
2303
+
2304
+		// and button
2305
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2306
+		$test_settings_html .= '<p>';
2307
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2308
+		$test_settings_html .= '</p>';
2309
+		$test_settings_html .= $this->get_action_link_or_button(
2310
+			'reset_to_default',
2311
+			'reset',
2312
+			$extra_args,
2313
+			'button--primary reset-default-button'
2314
+		);
2315
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2316
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2317
+	}
2318
+
2319
+
2320
+	/**
2321
+	 * This returns the shortcode selector skeleton for a given context and field.
2322
+	 *
2323
+	 * @param string $field           The name of the field retrieving shortcodes for.
2324
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2325
+	 * @return string
2326
+	 * @throws DomainException
2327
+	 * @throws EE_Error
2328
+	 * @throws InvalidArgumentException
2329
+	 * @throws ReflectionException
2330
+	 * @throws InvalidDataTypeException
2331
+	 * @throws InvalidInterfaceException
2332
+	 * @since 4.9.rc.000
2333
+	 */
2334
+	protected function _get_shortcode_selector($field, $linked_input_id)
2335
+	{
2336
+		$template_args = [
2337
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2338
+			'fieldname'       => $field,
2339
+			'linked_input_id' => $linked_input_id,
2340
+		];
2341
+
2342
+		return EEH_Template::display_template(
2343
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2344
+			$template_args,
2345
+			true
2346
+		);
2347
+	}
2348
+
2349
+
2350
+	/**
2351
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2352
+	 * page)
2353
+	 *
2354
+	 * @access public
2355
+	 * @return void
2356
+	 * @throws EE_Error
2357
+	 * @throws InvalidArgumentException
2358
+	 * @throws ReflectionException
2359
+	 * @throws InvalidDataTypeException
2360
+	 * @throws InvalidInterfaceException
2361
+	 */
2362
+	public function shortcode_meta_box()
2363
+	{
2364
+		$shortcodes = $this->_get_shortcodes([], false);
2365
+		// just make sure the shortcodes property is set
2366
+		// $messenger = $this->_message_template_group->messenger_obj();
2367
+		// now let's set the content depending on the status of the shortcodes array
2368
+		if (empty($shortcodes)) {
2369
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2370
+			return;
2371
+		}
2372
+		?>
2373 2373
         <div style="float:right; margin-top:10px">
2374 2374
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2375
-            ?>
2375
+			?>
2376 2376
         </div>
2377 2377
         <p class="small-text">
2378 2378
             <?php printf(
2379
-                esc_html__(
2380
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2381
-                    'event_espresso'
2382
-                ),
2383
-                '<span class="dashicons dashicons-shortcode"></span>'
2384
-            ); ?>
2379
+				esc_html__(
2380
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2381
+					'event_espresso'
2382
+				),
2383
+				'<span class="dashicons dashicons-shortcode"></span>'
2384
+			); ?>
2385 2385
         </p>
2386 2386
         <?php
2387
-    }
2388
-
2389
-
2390
-    /**
2391
-     * used to set the $_shortcodes property for when its needed elsewhere.
2392
-     *
2393
-     * @access protected
2394
-     * @return void
2395
-     * @throws EE_Error
2396
-     * @throws InvalidArgumentException
2397
-     * @throws ReflectionException
2398
-     * @throws InvalidDataTypeException
2399
-     * @throws InvalidInterfaceException
2400
-     */
2401
-    protected function _set_shortcodes()
2402
-    {
2403
-        // no need to run this if the property is already set
2404
-        if (! empty($this->_shortcodes)) {
2405
-            return;
2406
-        }
2407
-
2408
-        $this->_shortcodes = $this->_get_shortcodes();
2409
-    }
2410
-
2411
-
2412
-    /**
2413
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2414
-     * property)
2415
-     *
2416
-     * @access  protected
2417
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2418
-     *                         for. Defaults to all (for the given context)
2419
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2420
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2421
-     *                         true just an array of shortcode/label pairs.
2422
-     * @throws EE_Error
2423
-     * @throws InvalidArgumentException
2424
-     * @throws ReflectionException
2425
-     * @throws InvalidDataTypeException
2426
-     * @throws InvalidInterfaceException
2427
-     */
2428
-    protected function _get_shortcodes(array $fields = [], bool $merged = true): array
2429
-    {
2430
-        $this->_set_message_template_group();
2431
-
2432
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2433
-        $GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2434
-        if (empty($GRP_ID)) {
2435
-            return [];
2436
-        }
2437
-        $context = $this->request->getRequestParam(
2438
-            'messenger',
2439
-            key($this->_message_template_group->contexts_config())
2440
-        );
2441
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2442
-    }
2443
-
2444
-
2445
-    /**
2446
-     * This sets the _message_template property (containing the called message_template object)
2447
-     *
2448
-     * @access protected
2449
-     * @return void
2450
-     * @throws EE_Error
2451
-     * @throws InvalidArgumentException
2452
-     * @throws ReflectionException
2453
-     * @throws InvalidDataTypeException
2454
-     * @throws InvalidInterfaceException
2455
-     */
2456
-    protected function _set_message_template_group()
2457
-    {
2458
-        // get out if this is already set.
2459
-        if (! empty($this->_message_template_group)) {
2460
-            return;
2461
-        }
2462
-
2463
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2464
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, DataType::INTEGER);
2465
-
2466
-        // let's get the message templates
2467
-        $this->_message_template_group = ! empty($GRP_ID)
2468
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2469
-            : $this->getMtgModel()->create_default_object();
2470
-
2471
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2472
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2473
-    }
2474
-
2475
-
2476
-    /**
2477
-     * sets up a context switcher for edit forms
2478
-     *
2479
-     * @access  protected
2480
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2481
-     * @param array                     $args                  various things the context switcher needs.
2482
-     * @throws EE_Error
2483
-     */
2484
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, array $args)
2485
-    {
2486
-        $context_details = $template_group_object->contexts_config();
2487
-        $context_label   = $template_group_object->context_label();
2488
-        ob_start();
2489
-        ?>
2387
+	}
2388
+
2389
+
2390
+	/**
2391
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2392
+	 *
2393
+	 * @access protected
2394
+	 * @return void
2395
+	 * @throws EE_Error
2396
+	 * @throws InvalidArgumentException
2397
+	 * @throws ReflectionException
2398
+	 * @throws InvalidDataTypeException
2399
+	 * @throws InvalidInterfaceException
2400
+	 */
2401
+	protected function _set_shortcodes()
2402
+	{
2403
+		// no need to run this if the property is already set
2404
+		if (! empty($this->_shortcodes)) {
2405
+			return;
2406
+		}
2407
+
2408
+		$this->_shortcodes = $this->_get_shortcodes();
2409
+	}
2410
+
2411
+
2412
+	/**
2413
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2414
+	 * property)
2415
+	 *
2416
+	 * @access  protected
2417
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2418
+	 *                         for. Defaults to all (for the given context)
2419
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2420
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2421
+	 *                         true just an array of shortcode/label pairs.
2422
+	 * @throws EE_Error
2423
+	 * @throws InvalidArgumentException
2424
+	 * @throws ReflectionException
2425
+	 * @throws InvalidDataTypeException
2426
+	 * @throws InvalidInterfaceException
2427
+	 */
2428
+	protected function _get_shortcodes(array $fields = [], bool $merged = true): array
2429
+	{
2430
+		$this->_set_message_template_group();
2431
+
2432
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2433
+		$GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2434
+		if (empty($GRP_ID)) {
2435
+			return [];
2436
+		}
2437
+		$context = $this->request->getRequestParam(
2438
+			'messenger',
2439
+			key($this->_message_template_group->contexts_config())
2440
+		);
2441
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2442
+	}
2443
+
2444
+
2445
+	/**
2446
+	 * This sets the _message_template property (containing the called message_template object)
2447
+	 *
2448
+	 * @access protected
2449
+	 * @return void
2450
+	 * @throws EE_Error
2451
+	 * @throws InvalidArgumentException
2452
+	 * @throws ReflectionException
2453
+	 * @throws InvalidDataTypeException
2454
+	 * @throws InvalidInterfaceException
2455
+	 */
2456
+	protected function _set_message_template_group()
2457
+	{
2458
+		// get out if this is already set.
2459
+		if (! empty($this->_message_template_group)) {
2460
+			return;
2461
+		}
2462
+
2463
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2464
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, DataType::INTEGER);
2465
+
2466
+		// let's get the message templates
2467
+		$this->_message_template_group = ! empty($GRP_ID)
2468
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2469
+			: $this->getMtgModel()->create_default_object();
2470
+
2471
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2472
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2473
+	}
2474
+
2475
+
2476
+	/**
2477
+	 * sets up a context switcher for edit forms
2478
+	 *
2479
+	 * @access  protected
2480
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2481
+	 * @param array                     $args                  various things the context switcher needs.
2482
+	 * @throws EE_Error
2483
+	 */
2484
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, array $args)
2485
+	{
2486
+		$context_details = $template_group_object->contexts_config();
2487
+		$context_label   = $template_group_object->context_label();
2488
+		ob_start();
2489
+		?>
2490 2490
         <div class="ee-msg-switcher-container">
2491 2491
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2492 2492
                 <?php
2493
-                foreach ($args as $name => $value) {
2494
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2495
-                        continue;
2496
-                    }
2497
-                    ?>
2493
+				foreach ($args as $name => $value) {
2494
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2495
+						continue;
2496
+					}
2497
+					?>
2498 2498
                     <input type="hidden"
2499 2499
                            name="<?php echo esc_attr($name); ?>"
2500 2500
                            value="<?php echo esc_attr($value); ?>"
2501 2501
                     />
2502 2502
                     <?php
2503
-                }
2504
-                // setup nonce_url
2505
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2506
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2507
-                ?>
2503
+				}
2504
+				// setup nonce_url
2505
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2506
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2507
+				?>
2508 2508
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2509 2509
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2510 2510
                 </label>
2511 2511
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2512 2512
                     <?php
2513
-                    $context_templates = $template_group_object->context_templates();
2514
-                    if (is_array($context_templates)) :
2515
-                        foreach ($context_templates as $context => $template_fields) :
2516
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2517
-                            ?>
2513
+					$context_templates = $template_group_object->context_templates();
2514
+					if (is_array($context_templates)) :
2515
+						foreach ($context_templates as $context => $template_fields) :
2516
+							$checked = ($context === $args['context']) ? 'selected' : '';
2517
+							?>
2518 2518
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2519 2519
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2520 2520
                             </option>
2521 2521
                         <?php endforeach;
2522
-                    endif; ?>
2522
+					endif; ?>
2523 2523
                 </select>
2524 2524
                 <?php $button_text = sprintf(
2525
-                    esc_html__('Switch %s', 'event_espresso'),
2526
-                    ucwords($context_label['label'])
2527
-                ); ?>
2525
+					esc_html__('Switch %s', 'event_espresso'),
2526
+					ucwords($context_label['label'])
2527
+				); ?>
2528 2528
                 <input class='button--secondary'
2529 2529
                        id="submit-msg-context-switcher-sbmt"
2530 2530
                        type="submit"
@@ -2534,1622 +2534,1622 @@  discard block
 block discarded – undo
2534 2534
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2535 2535
         </div> <!-- end .ee-msg-switcher-container -->
2536 2536
         <?php $this->_context_switcher = ob_get_clean();
2537
-    }
2538
-
2539
-
2540
-    /**
2541
-     * @throws EE_Error
2542
-     * @throws ReflectionException
2543
-     * @deprecated 5.0.8.p
2544
-     */
2545
-    protected function _insert_or_update_message_template($new = false)
2546
-    {
2547
-        if ($new) {
2548
-            $this->insertMessageTemplate();
2549
-        } else {
2550
-            $this->updateMessageTemplate();
2551
-        }
2552
-    }
2553
-
2554
-
2555
-    /**
2556
-     * @throws EE_Error
2557
-     * @throws ReflectionException
2558
-     */
2559
-    protected function insertMessageTemplate(): void
2560
-    {
2561
-        $success   = true;
2562
-        $templates = [];
2563
-        try {
2564
-            $templates = $this->getMessageTemplateManager()->generateNewTemplates();
2565
-        } catch (Exception $exception) {
2566
-            $success = false;
2567
-            EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2568
-        }
2569
-
2570
-        /** @var MessageTemplateRequestData $form_data */
2571
-        $form_data = $this->loader->getShared(MessageTemplateRequestData::class);
2572
-        $this->_redirect_after_action(
2573
-            $success && isset($templates['GRP_ID'], $templates['MTP_context']),
2574
-            $this->generateUpdateDescription($form_data->messenger(), $form_data->messageType(), $form_data->context()),
2575
-            'created',
2576
-            [
2577
-                'id'      => $templates['GRP_ID'] ?? 0,
2578
-                'context' => $templates['MTP_context'] ?? '',
2579
-                'action'  => 'edit_message_template',
2580
-            ],
2581
-            $this->performTestSendAfterUpdate($form_data->messenger(), $form_data->messageType(), $form_data->context())
2582
-        );
2583
-    }
2584
-
2585
-
2586
-    /**
2587
-     * @throws EE_Error
2588
-     * @throws ReflectionException
2589
-     */
2590
-    protected function updateMessageTemplate(): void
2591
-    {
2592
-        $success = true;
2593
-        try {
2594
-            $this->getMessageTemplateManager()->updateExistingTemplates();
2595
-        } catch (Exception $exception) {
2596
-            $success = false;
2597
-            EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2598
-        }
2599
-
2600
-        /** @var MessageTemplateRequestData $form_data */
2601
-        $form_data = $this->loader->getShared(MessageTemplateRequestData::class);
2602
-
2603
-        $this->_redirect_after_action(
2604
-            $success,
2605
-            $this->generateUpdateDescription($form_data->messenger(), $form_data->messageType(), $form_data->context()),
2606
-            'updated',
2607
-            [
2608
-                'id'      => $form_data->groupID(),
2609
-                'context' => $form_data->context(),
2610
-                'action'  => 'edit_message_template',
2611
-            ],
2612
-            $this->performTestSendAfterUpdate($form_data->messenger(), $form_data->messageType(), $form_data->context())
2613
-        );
2614
-    }
2615
-
2616
-
2617
-    /**
2618
-     * @param string $messenger
2619
-     * @param string $message_type
2620
-     * @param string $context
2621
-     * @return string
2622
-     * @since 4.10.29.p
2623
-     */
2624
-    private function generateUpdateDescription(string $messenger, string $message_type, string $context): string
2625
-    {
2626
-        // need the message type and messenger objects to be able to use the labels for the notices
2627
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
2628
-        $messenger_label  = $messenger_object instanceof EE_messenger
2629
-            ? ucwords($messenger_object->label['singular'])
2630
-            : '';
2631
-
2632
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
2633
-        $message_type_label  = $message_type_object instanceof EE_message_type
2634
-            ? ucwords($message_type_object->label['singular'])
2635
-            : '';
2636
-
2637
-        $context   = ucwords(str_replace('_', ' ', $context));
2638
-        $item_desc = $messenger_label && $message_type_label
2639
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2640
-            : '';
2641
-        $item_desc .= 'Message Template';
2642
-        return $item_desc;
2643
-    }
2644
-
2645
-
2646
-    /**
2647
-     * @param string $messenger
2648
-     * @param string $message_type
2649
-     * @param string $context
2650
-     * @return bool
2651
-     * @throws EE_Error
2652
-     * @throws ReflectionException
2653
-     * @since 4.10.29.p
2654
-     */
2655
-    private function performTestSendAfterUpdate(string $messenger, string $message_type, string $context): bool
2656
-    {
2657
-        // was a test send triggered?
2658
-        if ($this->request->requestParamIsSet('test_button')) {
2659
-            EE_Error::overwrite_success();
2660
-            $this->_do_test_send($context, $messenger, $message_type);
2661
-            return true;
2662
-        }
2663
-        return false;
2664
-    }
2665
-
2666
-
2667
-    /**
2668
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2669
-     *
2670
-     * @param string $context      what context being tested
2671
-     * @param string $messenger    messenger being tested
2672
-     * @param string $message_type message type being tested
2673
-     * @throws EE_Error
2674
-     * @throws InvalidArgumentException
2675
-     * @throws InvalidDataTypeException
2676
-     * @throws InvalidInterfaceException
2677
-     * @throws ReflectionException
2678
-     */
2679
-    protected function _do_test_send(string $context, string $messenger, string $message_type)
2680
-    {
2681
-        // set things up for preview
2682
-        $this->request->setRequestParam('messenger', $messenger);
2683
-        $this->request->setRequestParam('message_type', $message_type);
2684
-        $this->request->setRequestParam('context', $context);
2685
-        $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2686
-
2687
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
2688
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
2689
-
2690
-        // let's save any existing fields that might be required by the messenger
2691
-        if (
2692
-            ! empty($test_settings_fld)
2693
-            && $active_messenger instanceof EE_messenger
2694
-            && apply_filters(
2695
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2696
-                true,
2697
-                $test_settings_fld,
2698
-                $active_messenger
2699
-            )
2700
-        ) {
2701
-            $active_messenger->set_existing_test_settings($test_settings_fld);
2702
-        }
2703
-
2704
-        /**
2705
-         * Use filter to add additional controls on whether message can send or not
2706
-         */
2707
-        if (
2708
-            apply_filters(
2709
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
2710
-                true,
2711
-                $context,
2712
-                $this->request->requestParams(),
2713
-                $messenger,
2714
-                $message_type
2715
-            )
2716
-        ) {
2717
-            if (EEM_Event::instance()->count() > 0) {
2718
-                $success = $this->_preview_message(true);
2719
-                if ($success) {
2720
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
2721
-                } else {
2722
-                    EE_Error::add_error(
2723
-                        esc_html__('The test message was not sent', 'event_espresso'),
2724
-                        __FILE__,
2725
-                        __FUNCTION__,
2726
-                        __LINE__
2727
-                    );
2728
-                }
2729
-            } else {
2730
-                $this->noEventsErrorMessage(true);
2731
-            }
2732
-        }
2733
-    }
2734
-
2735
-
2736
-    /**
2737
-     * [_trash_or_restore_message_template]
2738
-     *
2739
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2740
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2741
-     *                        an individual context (FALSE).
2742
-     * @return void
2743
-     * @throws EE_Error
2744
-     * @throws InvalidArgumentException
2745
-     * @throws InvalidDataTypeException
2746
-     * @throws InvalidInterfaceException
2747
-     * @throws ReflectionException
2748
-     */
2749
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2750
-    {
2751
-        $success = 1;
2752
-
2753
-        // incoming GRP_IDs
2754
-        if ($all) {
2755
-            // Checkboxes
2756
-            $checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2757
-            if (! empty($checkboxes)) {
2758
-                // if array has more than one element then success message should be plural.
2759
-                // todo: what about nonce?
2760
-                $success = count($checkboxes) > 1 ? 2 : 1;
2761
-
2762
-                // cycle through checkboxes
2763
-                foreach (array_keys($checkboxes) as $GRP_ID) {
2764
-                    $trashed_or_restored = $trash
2765
-                        ? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2766
-                        : $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2767
-                    if (! $trashed_or_restored) {
2768
-                        $success = 0;
2769
-                    }
2770
-                }
2771
-            } else {
2772
-                // grab single GRP_ID and handle
2773
-                $GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2774
-                if (! empty($GRP_ID)) {
2775
-                    $trashed_or_restored = $trash
2776
-                        ? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2777
-                        : $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2778
-                    if (! $trashed_or_restored) {
2779
-                        $success = 0;
2780
-                    }
2781
-                } else {
2782
-                    $success = 0;
2783
-                }
2784
-            }
2785
-        }
2786
-
2787
-        $action_desc = $trash
2788
-            ? esc_html__('moved to the trash', 'event_espresso')
2789
-            : esc_html__('restored', 'event_espresso');
2790
-
2791
-        $template_switch = $this->request->getRequestParam('template_switch', false, DataType::BOOLEAN);
2792
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
2793
-
2794
-        $item_desc = $all ? _n(
2795
-            'Message Template Group',
2796
-            'Message Template Groups',
2797
-            $success,
2798
-            'event_espresso'
2799
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2800
-
2801
-        $item_desc = $template_switch
2802
-            ? _n('template', 'templates', $success, 'event_espresso')
2803
-            : $item_desc;
2804
-
2805
-        $this->_redirect_after_action(
2806
-            $success,
2807
-            $item_desc,
2808
-            $action_desc,
2809
-            [
2810
-                'action' => $this->request->getRequestParam('return'),
2811
-            ]
2812
-        );
2813
-    }
2814
-
2815
-
2816
-    /**
2817
-     * [_delete_message_template]
2818
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2819
-     *
2820
-     * @return void
2821
-     * @throws EE_Error
2822
-     * @throws InvalidArgumentException
2823
-     * @throws InvalidDataTypeException
2824
-     * @throws InvalidInterfaceException
2825
-     * @throws ReflectionException
2826
-     */
2827
-    protected function _delete_message_template()
2828
-    {
2829
-        // checkboxes
2830
-        $checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2831
-        if (! empty($checkboxes)) {
2832
-            // if array has more than one element then success message should be plural
2833
-            $success = count($checkboxes) > 1 ? 2 : 1;
2834
-
2835
-            // cycle through bulk action checkboxes
2836
-            foreach (array_keys($checkboxes) as $GRP_ID) {
2837
-                $success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplateGroup($GRP_ID) ? $success
2838
-                    : false;
2839
-            }
2840
-        } else {
2841
-            // grab single grp_id and delete
2842
-            $GRP_ID  = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2843
-            $success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplateGroup($GRP_ID);
2844
-        }
2845
-
2846
-        $this->_redirect_after_action(
2847
-            $success,
2848
-            'Message Templates',
2849
-            'deleted',
2850
-            [
2851
-                'action' => $this->request->getRequestParam('return'),
2852
-            ]
2853
-        );
2854
-    }
2855
-
2856
-
2857
-    /**
2858
-     *    _learn_more_about_message_templates_link
2859
-     *
2860
-     * @access protected
2861
-     * @return string
2862
-     */
2863
-    protected function _learn_more_about_message_templates_link()
2864
-    {
2865
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
2866
-               . esc_html__('learn more about how message templates works', 'event_espresso')
2867
-               . '</a>';
2868
-    }
2869
-
2870
-
2871
-    /**
2872
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2873
-     * ajax and other routes.
2874
-     *
2875
-     * @return void
2876
-     * @throws DomainException
2877
-     * @throws EE_Error
2878
-     */
2879
-    protected function _settings()
2880
-    {
2881
-        $this->_set_m_mt_settings();
2882
-        // let's setup the messenger tabs
2883
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
2884
-            $this->_m_mt_settings['messenger_tabs'],
2885
-            'messenger_links',
2886
-            '|',
2887
-            $this->request->getRequestParam('selected_messenger', 'email')
2888
-        );
2889
-
2890
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2891
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2892
-
2893
-        $this->display_admin_page_with_sidebar();
2894
-    }
2895
-
2896
-
2897
-    /**
2898
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2899
-     *
2900
-     * @access protected
2901
-     * @return void
2902
-     * @throws DomainException
2903
-     */
2904
-    protected function _set_m_mt_settings()
2905
-    {
2906
-        // first if this is already set then lets get out no need to regenerate data.
2907
-        if (! empty($this->_m_mt_settings)) {
2908
-            return;
2909
-        }
2910
-
2911
-        // get all installed messengers and message_types
2912
-        $messengers    = $this->_message_resource_manager->installed_messengers();
2913
-        $message_types = $this->_message_resource_manager->installed_message_types();
2914
-
2915
-
2916
-        // assemble the array for the _tab_text_links helper
2917
-
2918
-        foreach ($messengers as $messenger) {
2919
-            $active                                                     =
2920
-                $this->_message_resource_manager->is_messenger_active($messenger->name);
2921
-            $class                                                      =
2922
-                'ee-messenger-' . sanitize_key($messenger->label['singular']);
2923
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
2924
-                'label' => ucwords($messenger->label['singular']),
2925
-                'class' => $active ? "{$class} messenger-active" : $class,
2926
-                'href'  => $messenger->name,
2927
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
2928
-                'slug'  => $messenger->name,
2929
-                'obj'   => $messenger,
2930
-                'icon'  => $active
2931
-                    ? '<span class="dashicons dashicons-yes-alt"></span>'
2932
-                    : '<span class="dashicons dashicons-remove"></span>',
2933
-            ];
2934
-
2935
-
2936
-            $message_types_for_messenger = $messenger->get_valid_message_types();
2937
-
2938
-            foreach ($message_types as $message_type) {
2939
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
2940
-                // it shouldn't show in either the inactive OR active metabox.
2941
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
2942
-                    continue;
2943
-                }
2944
-
2945
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
2946
-                    $messenger->name,
2947
-                    $message_type->name
2948
-                )
2949
-                    ? 'active'
2950
-                    : 'inactive';
2951
-
2952
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
2953
-                    'label'    => ucwords($message_type->label['singular']),
2954
-                    'class'    => 'message-type-' . $a_or_i,
2955
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2956
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2957
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2958
-                    'title'    => $a_or_i === 'active'
2959
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2960
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
2961
-                    'content'  => $a_or_i === 'active'
2962
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
2963
-                        : $this->_message_type_settings_content($message_type, $messenger),
2964
-                    'slug'     => $message_type->name,
2965
-                    'active'   => $a_or_i === 'active',
2966
-                    'obj'      => $message_type,
2967
-                ];
2968
-            }
2969
-        }
2970
-    }
2971
-
2972
-
2973
-    /**
2974
-     * This just prepares the content for the message type settings
2975
-     *
2976
-     * @param EE_message_type $message_type The message type object
2977
-     * @param EE_messenger    $messenger    The messenger object
2978
-     * @param boolean         $active       Whether the message type is active or not
2979
-     * @return string html output for the content
2980
-     * @throws DomainException
2981
-     */
2982
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
2983
-    {
2984
-        // get message type fields
2985
-        $fields                                         = $message_type->get_admin_settings_fields();
2986
-        $settings_template_args['template_form_fields'] = '';
2987
-
2988
-        if (! empty($fields) && $active) {
2989
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2990
-            foreach ($fields as $fldname => $fldprops) {
2991
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2992
-                $template_form_field[ $field_id ] = [
2993
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2994
-                    'label'      => $fldprops['label'],
2995
-                    'input'      => $fldprops['field_type'],
2996
-                    'type'       => $fldprops['value_type'],
2997
-                    'required'   => $fldprops['required'],
2998
-                    'validation' => $fldprops['validation'],
2999
-                    'value'      => $existing_settings[ $fldname ] ?? $fldprops['default'],
3000
-                    'options'    => $fldprops['options'] ?? [],
3001
-                    'default'    => $existing_settings[ $fldname ] ?? $fldprops['default'],
3002
-                    'css_class'  => 'no-drag',
3003
-                    'format'     => $fldprops['format'],
3004
-                ];
3005
-            }
3006
-
3007
-
3008
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3009
-                ? $this->_generate_admin_form_fields(
3010
-                    $template_form_field,
3011
-                    'string',
3012
-                    'ee_mt_activate_form'
3013
-                )
3014
-                : '';
3015
-        }
3016
-
3017
-        $settings_template_args['description'] = $message_type->description;
3018
-        // we also need some hidden fields
3019
-        $hidden_fields = [
3020
-            'message_type_settings[messenger]' . $message_type->name    => [
3021
-                'type'  => 'hidden',
3022
-                'value' => $messenger->name,
3023
-            ],
3024
-            'message_type_settings[message_type]' . $message_type->name => [
3025
-                'type'  => 'hidden',
3026
-                'value' => $message_type->name,
3027
-            ],
3028
-            'type' . $message_type->name                                => [
3029
-                'type'  => 'hidden',
3030
-                'value' => 'message_type',
3031
-            ],
3032
-        ];
3033
-
3034
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3035
-            $hidden_fields,
3036
-            'array'
3037
-        );
3038
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3039
-            ? ' hidden'
3040
-            : '';
3041
-
3042
-
3043
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3044
-        return EEH_Template::display_template($template, $settings_template_args, true);
3045
-    }
3046
-
3047
-
3048
-    /**
3049
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3050
-     *
3051
-     * @access protected
3052
-     * @return void
3053
-     * @throws DomainException
3054
-     */
3055
-    protected function _messages_settings_metaboxes()
3056
-    {
3057
-        $this->_set_m_mt_settings();
3058
-        $m_boxes         = $mt_boxes = [];
3059
-        $m_template_args = $mt_template_args = [];
3060
-
3061
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3062
-
3063
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3064
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3065
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3066
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3067
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3068
-
3069
-                // messenger meta boxes
3070
-                $active         = $selected_messenger === $messenger;
3071
-                $active_mt_tabs = $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] ?? '';
3072
-
3073
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3074
-                    esc_html__('%s Settings', 'event_espresso'),
3075
-                    $tab_array['label']
3076
-                );
3077
-
3078
-                $m_template_args[ $messenger . '_a_box' ] = [
3079
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3080
-                    'inactive_message_types' => isset(
3081
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3082
-                    )
3083
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3084
-                        : '',
3085
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3086
-                    'hidden'                 => $active ? '' : ' hidden',
3087
-                    'hide_on_message'        => $hide_on_message,
3088
-                    'messenger'              => $messenger,
3089
-                    'active'                 => $active,
3090
-                ];
3091
-
3092
-                // message type meta boxes
3093
-                // (which is really just the inactive container for each messenger
3094
-                // showing inactive message types for that messenger)
3095
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3096
-                $mt_template_args[ $messenger . '_i_box' ] = [
3097
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3098
-                    'inactive_message_types' => isset(
3099
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3100
-                    )
3101
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3102
-                        : '',
3103
-                    'hidden'                 => $active ? '' : ' hidden',
3104
-                    'hide_on_message'        => $hide_on_message,
3105
-                    'hide_off_message'       => $hide_off_message,
3106
-                    'messenger'              => $messenger,
3107
-                    'active'                 => $active,
3108
-                ];
3109
-            }
3110
-        }
3111
-
3112
-
3113
-        // register messenger metaboxes
3114
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3115
-        foreach ($m_boxes as $box => $label) {
3116
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3117
-            $msgr          = str_replace('_a_box', '', $box);
3118
-            $this->addMetaBox(
3119
-                'espresso_' . $msgr . '_settings',
3120
-                $label,
3121
-                function ($post, $metabox) {
3122
-                    EEH_Template::display_template(
3123
-                        $metabox['args']['template_path'],
3124
-                        $metabox['args']['template_args']
3125
-                    );
3126
-                },
3127
-                $this->_current_screen->id,
3128
-                'normal',
3129
-                'high',
3130
-                $callback_args
3131
-            );
3132
-        }
3133
-
3134
-        // register message type metaboxes
3135
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3136
-        foreach ($mt_boxes as $box => $label) {
3137
-            $callback_args = [
3138
-                'template_path' => $mt_template_path,
3139
-                'template_args' => $mt_template_args[ $box ],
3140
-            ];
3141
-            $mt            = str_replace('_i_box', '', $box);
3142
-            $this->addMetaBox(
3143
-                'espresso_' . $mt . '_inactive_mts',
3144
-                $label,
3145
-                function ($post, $metabox) {
3146
-                    EEH_Template::display_template(
3147
-                        $metabox['args']['template_path'],
3148
-                        $metabox['args']['template_args']
3149
-                    );
3150
-                },
3151
-                $this->_current_screen->id,
3152
-                'side',
3153
-                'high',
3154
-                $callback_args
3155
-            );
3156
-        }
3157
-
3158
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3159
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3160
-        if (is_main_site()) {
3161
-            $this->addMetaBox(
3162
-                'espresso_global_message_settings',
3163
-                esc_html__('Global Message Settings', 'event_espresso'),
3164
-                [$this, 'global_messages_settings_metabox_content'],
3165
-                $this->_current_screen->id,
3166
-                'normal',
3167
-                'low',
3168
-                []
3169
-            );
3170
-        }
3171
-    }
3172
-
3173
-
3174
-    /**
3175
-     *  This generates the content for the global messages settings metabox.
3176
-     *
3177
-     * @return void
3178
-     * @throws EE_Error
3179
-     * @throws InvalidArgumentException
3180
-     * @throws ReflectionException
3181
-     * @throws InvalidDataTypeException
3182
-     * @throws InvalidInterfaceException
3183
-     */
3184
-    public function global_messages_settings_metabox_content()
3185
-    {
3186
-        $form = $this->_generate_global_settings_form();
3187
-        echo wp_kses(
3188
-            $form->form_open(
3189
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3190
-                'POST'
3191
-            ),
3192
-            AllowedTags::getWithFormTags()
3193
-        );
3194
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3195
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3196
-    }
3197
-
3198
-
3199
-    /**
3200
-     * This generates and returns the form object for the global messages settings.
3201
-     *
3202
-     * @return EE_Form_Section_Proper
3203
-     * @throws EE_Error
3204
-     * @throws InvalidArgumentException
3205
-     * @throws ReflectionException
3206
-     * @throws InvalidDataTypeException
3207
-     * @throws InvalidInterfaceException
3208
-     */
3209
-    protected function _generate_global_settings_form()
3210
-    {
3211
-        /** @var EE_Network_Core_Config $network_config */
3212
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3213
-
3214
-        return new EE_Form_Section_Proper(
3215
-            [
3216
-                'name'            => 'global_messages_settings',
3217
-                'html_id'         => 'global_messages_settings',
3218
-                'html_class'      => 'form-table',
3219
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3220
-                'subsections'     => apply_filters(
3221
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3222
-                    [
3223
-                        'do_messages_on_same_request' => new EE_Select_Input(
3224
-                            [
3225
-                                true  => esc_html__('On the same request', 'event_espresso'),
3226
-                                false => esc_html__('On a separate request', 'event_espresso'),
3227
-                            ],
3228
-                            [
3229
-                                'default'         => $network_config->do_messages_on_same_request,
3230
-                                'html_label_text' => esc_html__(
3231
-                                    'Generate and send all messages:',
3232
-                                    'event_espresso'
3233
-                                ),
3234
-                                'html_help_text'  => esc_html__(
3235
-                                    '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.',
3236
-                                    'event_espresso'
3237
-                                ),
3238
-                            ]
3239
-                        ),
3240
-                        'delete_threshold'            => new EE_Select_Input(
3241
-                            [
3242
-                                0  => esc_html__('Forever', 'event_espresso'),
3243
-                                3  => esc_html__('3 Months', 'event_espresso'),
3244
-                                6  => esc_html__('6 Months', 'event_espresso'),
3245
-                                9  => esc_html__('9 Months', 'event_espresso'),
3246
-                                12 => esc_html__('12 Months', 'event_espresso'),
3247
-                                24 => esc_html__('24 Months', 'event_espresso'),
3248
-                                36 => esc_html__('36 Months', 'event_espresso'),
3249
-                            ],
3250
-                            [
3251
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3252
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3253
-                                'html_help_text'  => esc_html__(
3254
-                                    'You can control how long a record of processed messages is kept via this option.',
3255
-                                    'event_espresso'
3256
-                                ),
3257
-                            ]
3258
-                        ),
3259
-                        'update_settings'             => new EE_Submit_Input(
3260
-                            [
3261
-                                'default'         => esc_html__('Update', 'event_espresso'),
3262
-                                'html_label_text' => '',
3263
-                            ]
3264
-                        ),
3265
-                    ]
3266
-                ),
3267
-            ]
3268
-        );
3269
-    }
3270
-
3271
-
3272
-    /**
3273
-     * This handles updating the global settings set on the admin page.
3274
-     *
3275
-     * @throws EE_Error
3276
-     * @throws InvalidDataTypeException
3277
-     * @throws InvalidInterfaceException
3278
-     * @throws InvalidArgumentException
3279
-     * @throws ReflectionException
3280
-     */
3281
-    protected function _update_global_settings()
3282
-    {
3283
-        /** @var EE_Network_Core_Config $network_config */
3284
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3285
-        $messages_config = EE_Registry::instance()->CFG->messages;
3286
-        $form            = $this->_generate_global_settings_form();
3287
-        if ($form->was_submitted()) {
3288
-            $form->receive_form_submission();
3289
-            if ($form->is_valid()) {
3290
-                $valid_data = $form->valid_data();
3291
-                // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
3292
-                foreach ($valid_data as $property => $value) {
3293
-                    $setter = 'set_' . $property;
3294
-                    if (method_exists($network_config, $setter)) {
3295
-                        $network_config->{$setter}($value);
3296
-                    } elseif (
3297
-                        property_exists($network_config, $property)
3298
-                        && $network_config->{$property} !== $value
3299
-                    ) {
3300
-                        $network_config->{$property} = $value;
3301
-                    } elseif (
3302
-                        property_exists($messages_config, $property)
3303
-                        && $messages_config->{$property} !== $value
3304
-                    ) {
3305
-                        $messages_config->{$property} = $value;
3306
-                    }
3307
-                }
3308
-                // only update if the form submission was valid!
3309
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3310
-                EE_Registry::instance()->CFG->update_espresso_config();
3311
-                EE_Error::overwrite_success();
3312
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3313
-            }
3314
-        }
3315
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3316
-    }
3317
-
3318
-
3319
-    /**
3320
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3321
-     *
3322
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3323
-     * @return string html formatted tabs
3324
-     * @throws DomainException
3325
-     */
3326
-    protected function _get_mt_tabs($tab_array)
3327
-    {
3328
-        $tab_array = (array) $tab_array;
3329
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3330
-        $tabs      = '';
3331
-
3332
-        foreach ($tab_array as $tab) {
3333
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3334
-        }
3335
-
3336
-        return $tabs;
3337
-    }
3338
-
3339
-
3340
-    /**
3341
-     * This prepares the content of the messenger meta box admin settings
3342
-     *
3343
-     * @param EE_messenger $messenger The messenger we're setting up content for
3344
-     * @return string html formatted content
3345
-     * @throws DomainException
3346
-     */
3347
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3348
-    {
3349
-        $fields = $messenger->get_admin_settings_fields();
3350
-
3351
-        $settings_template_args['template_form_fields'] = '';
3352
-        // is $messenger active?
3353
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3354
-
3355
-
3356
-        if (! empty($fields)) {
3357
-            $existing_settings = $messenger->get_existing_admin_settings();
3358
-
3359
-            foreach ($fields as $field_name => $field_props) {
3360
-                $field_id                         = $messenger->name . '-' . $field_name;
3361
-                $template_form_field[ $field_id ] = [
3362
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3363
-                    'label'      => $field_props['label'],
3364
-                    'input'      => $field_props['field_type'],
3365
-                    'type'       => $field_props['value_type'],
3366
-                    'required'   => $field_props['required'],
3367
-                    'validation' => $field_props['validation'],
3368
-                    'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3369
-                    'css_class'  => '',
3370
-                    'format'     => $field_props['format'],
3371
-                ];
3372
-            }
3373
-
3374
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3375
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3376
-                : '';
3377
-        }
3378
-
3379
-        // we also need some hidden fields
3380
-        $settings_template_args['hidden_fields'] = [
3381
-            'messenger_settings[messenger]' . $messenger->name => [
3382
-                'type'  => 'hidden',
3383
-                'value' => $messenger->name,
3384
-            ],
3385
-            'type' . $messenger->name                          => [
3386
-                'type'  => 'hidden',
3387
-                'value' => 'messenger',
3388
-            ],
3389
-        ];
3390
-
3391
-        // make sure any active message types that are existing are included in the hidden fields
3392
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3393
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3394
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3395
-                    'type'  => 'hidden',
3396
-                    'value' => $mt,
3397
-                ];
3398
-            }
3399
-        }
3400
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3401
-            $settings_template_args['hidden_fields'],
3402
-            'array'
3403
-        );
3404
-        $active                                  =
3405
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3406
-
3407
-        $settings_template_args['messenger']           = $messenger->name;
3408
-        $settings_template_args['description']         = $messenger->description;
3409
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3410
-
3411
-
3412
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3413
-            $messenger->name
3414
-        )
3415
-            ? $settings_template_args['show_hide_edit_form']
3416
-            : ' hidden';
3417
-
3418
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3419
-            ? ' hidden'
3420
-            : $settings_template_args['show_hide_edit_form'];
3421
-
3422
-
3423
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3424
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3425
-        $settings_template_args['on_off_status'] = $active;
3426
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3427
-        return EEH_Template::display_template(
3428
-            $template,
3429
-            $settings_template_args,
3430
-            true
3431
-        );
3432
-    }
3433
-
3434
-
3435
-    /**
3436
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3437
-     *
3438
-     * @throws DomainException
3439
-     * @throws EE_Error
3440
-     * @throws InvalidDataTypeException
3441
-     * @throws InvalidInterfaceException
3442
-     * @throws InvalidArgumentException
3443
-     * @throws ReflectionException
3444
-     */
3445
-    public function activate_messenger_toggle()
3446
-    {
3447
-        $success = true;
3448
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3449
-        // let's check that we have required data
3450
-
3451
-        if (! $this->_active_messenger_name) {
3452
-            EE_Error::add_error(
3453
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3454
-                __FILE__,
3455
-                __FUNCTION__,
3456
-                __LINE__
3457
-            );
3458
-            $success = false;
3459
-        }
3460
-
3461
-        // do a nonce check here since we're not arriving via a normal route
3462
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
3463
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
3464
-
3465
-        $this->_verify_nonce($nonce, $nonce_ref);
3466
-
3467
-
3468
-        $status = $this->request->getRequestParam('status');
3469
-        if (! $status) {
3470
-            EE_Error::add_error(
3471
-                esc_html__(
3472
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3473
-                    'event_espresso'
3474
-                ),
3475
-                __FILE__,
3476
-                __FUNCTION__,
3477
-                __LINE__
3478
-            );
3479
-            $success = false;
3480
-        }
3481
-
3482
-        // do check to verify we have a valid status.
3483
-        if ($status !== 'off' && $status !== 'on') {
3484
-            EE_Error::add_error(
3485
-                sprintf(
3486
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3487
-                    $status
3488
-                ),
3489
-                __FILE__,
3490
-                __FUNCTION__,
3491
-                __LINE__
3492
-            );
3493
-            $success = false;
3494
-        }
3495
-
3496
-        if ($success) {
3497
-            // made it here?  Stop dawdling then!!
3498
-            $success = $status === 'off'
3499
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
3500
-                : $this->_activate_messenger($this->_active_messenger_name);
3501
-        }
3502
-
3503
-        $this->_template_args['success'] = $success;
3504
-
3505
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
3506
-        $this->_return_json();
3507
-    }
3508
-
3509
-
3510
-    /**
3511
-     * used by ajax from the messages settings page to activate|deactivate a message type
3512
-     *
3513
-     * @throws DomainException
3514
-     * @throws EE_Error
3515
-     * @throws ReflectionException
3516
-     * @throws InvalidDataTypeException
3517
-     * @throws InvalidInterfaceException
3518
-     * @throws InvalidArgumentException
3519
-     */
3520
-    public function activate_mt_toggle()
3521
-    {
3522
-        $success = true;
3523
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3524
-
3525
-        // let's make sure we have the necessary data
3526
-        if (! $this->_active_message_type_name) {
3527
-            EE_Error::add_error(
3528
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3529
-                __FILE__,
3530
-                __FUNCTION__,
3531
-                __LINE__
3532
-            );
3533
-            $success = false;
3534
-        }
3535
-
3536
-        if (! $this->_active_messenger_name) {
3537
-            EE_Error::add_error(
3538
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3539
-                __FILE__,
3540
-                __FUNCTION__,
3541
-                __LINE__
3542
-            );
3543
-            $success = false;
3544
-        }
3545
-
3546
-        $status = $this->request->getRequestParam('status');
3547
-        if (! $status) {
3548
-            EE_Error::add_error(
3549
-                esc_html__(
3550
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3551
-                    'event_espresso'
3552
-                ),
3553
-                __FILE__,
3554
-                __FUNCTION__,
3555
-                __LINE__
3556
-            );
3557
-            $success = false;
3558
-        }
3559
-
3560
-
3561
-        // do check to verify we have a valid status.
3562
-        if ($status !== 'activate' && $status !== 'deactivate') {
3563
-            EE_Error::add_error(
3564
-                sprintf(
3565
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3566
-                    $status
3567
-                ),
3568
-                __FILE__,
3569
-                __FUNCTION__,
3570
-                __LINE__
3571
-            );
3572
-            $success = false;
3573
-        }
3574
-
3575
-
3576
-        // do a nonce check here since we're not arriving via a normal route
3577
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
3578
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
3579
-
3580
-        if ($success) {
3581
-            // made it here? um, what are you waiting for then?
3582
-            $success = $status === 'deactivate'
3583
-                ? $this->_deactivate_message_type_for_messenger(
3584
-                    $this->_active_messenger_name,
3585
-                    $this->_active_message_type_name
3586
-                )
3587
-                : $this->_activate_message_type_for_messenger(
3588
-                    $this->_active_messenger_name,
3589
-                    $this->_active_message_type_name
3590
-                );
3591
-        }
3592
-
3593
-        $this->_template_args['success'] = $success;
3594
-        $this->_return_json();
3595
-    }
3596
-
3597
-
3598
-    /**
3599
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3600
-     *
3601
-     * @param string $messenger_name The name of the messenger being activated
3602
-     * @return bool
3603
-     * @throws DomainException
3604
-     * @throws EE_Error
3605
-     * @throws InvalidArgumentException
3606
-     * @throws ReflectionException
3607
-     * @throws InvalidDataTypeException
3608
-     * @throws InvalidInterfaceException
3609
-     */
3610
-    protected function _activate_messenger($messenger_name)
3611
-    {
3612
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3613
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
3614
-            ? $active_messenger->get_default_message_types()
3615
-            : [];
3616
-
3617
-        // ensure is active
3618
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
3619
-
3620
-        // set response_data for reload
3621
-        foreach ($message_types_to_activate as $message_type_name) {
3622
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3623
-            if (
3624
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
3625
-                    $messenger_name,
3626
-                    $message_type_name
3627
-                )
3628
-                && $message_type instanceof EE_message_type
3629
-            ) {
3630
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3631
-                if ($message_type->get_admin_settings_fields()) {
3632
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3633
-                }
3634
-            }
3635
-        }
3636
-
3637
-        // add success message for activating messenger
3638
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3639
-    }
3640
-
3641
-
3642
-    /**
3643
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3644
-     *
3645
-     * @param string $messenger_name The name of the messenger being activated
3646
-     * @return bool
3647
-     * @throws DomainException
3648
-     * @throws EE_Error
3649
-     * @throws InvalidArgumentException
3650
-     * @throws ReflectionException
3651
-     * @throws InvalidDataTypeException
3652
-     * @throws InvalidInterfaceException
3653
-     */
3654
-    protected function _deactivate_messenger($messenger_name)
3655
-    {
3656
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3657
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3658
-
3659
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3660
-    }
3661
-
3662
-
3663
-    /**
3664
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3665
-     *
3666
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3667
-     * @param string $message_type_name The name of the message type being activated for the messenger
3668
-     * @return bool
3669
-     * @throws DomainException
3670
-     * @throws EE_Error
3671
-     * @throws InvalidArgumentException
3672
-     * @throws ReflectionException
3673
-     * @throws InvalidDataTypeException
3674
-     * @throws InvalidInterfaceException
3675
-     */
3676
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3677
-    {
3678
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
3679
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3680
-
3681
-        // ensure is active
3682
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
3683
-
3684
-        // set response for load
3685
-        if (
3686
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
3687
-                $messenger_name,
3688
-                $message_type_name
3689
-            )
3690
-        ) {
3691
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3692
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3693
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3694
-            }
3695
-        }
3696
-
3697
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
3698
-            $active_messenger,
3699
-            $message_type_to_activate
3700
-        );
3701
-    }
3702
-
3703
-
3704
-    /**
3705
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3706
-     *
3707
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3708
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3709
-     * @return bool
3710
-     * @throws DomainException
3711
-     * @throws EE_Error
3712
-     * @throws InvalidArgumentException
3713
-     * @throws ReflectionException
3714
-     * @throws InvalidDataTypeException
3715
-     * @throws InvalidInterfaceException
3716
-     */
3717
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3718
-    {
3719
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3720
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3721
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3722
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3723
-
3724
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
3725
-            $active_messenger,
3726
-            $message_type_to_deactivate
3727
-        );
3728
-    }
3729
-
3730
-
3731
-    /**
3732
-     * This just initializes the defaults for activating messenger and message type responses.
3733
-     */
3734
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
3735
-    {
3736
-        $this->_template_args['data']['active_mts'] = [];
3737
-        $this->_template_args['data']['mt_reload']  = [];
3738
-    }
3739
-
3740
-
3741
-    /**
3742
-     * Setup appropriate response for activating a messenger and/or message types
3743
-     *
3744
-     * @param EE_messenger         $messenger
3745
-     * @param EE_message_type|null $message_type
3746
-     * @return bool
3747
-     * @throws DomainException
3748
-     * @throws EE_Error
3749
-     * @throws InvalidArgumentException
3750
-     * @throws ReflectionException
3751
-     * @throws InvalidDataTypeException
3752
-     * @throws InvalidInterfaceException
3753
-     */
3754
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
3755
-        $messenger,
3756
-        EE_Message_Type $message_type = null
3757
-    ) {
3758
-        // if $messenger isn't a valid messenger object then get out.
3759
-        if (! $messenger instanceof EE_Messenger) {
3760
-            EE_Error::add_error(
3761
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
3762
-                __FILE__,
3763
-                __FUNCTION__,
3764
-                __LINE__
3765
-            );
3766
-            return false;
3767
-        }
3768
-        // activated
3769
-        if ($this->_template_args['data']['active_mts']) {
3770
-            EE_Error::overwrite_success();
3771
-            // activated a message type with the messenger
3772
-            if ($message_type instanceof EE_message_type) {
3773
-                EE_Error::add_success(
3774
-                    sprintf(
3775
-                        esc_html__(
3776
-                            '%s message type has been successfully activated with the %s messenger',
3777
-                            'event_espresso'
3778
-                        ),
3779
-                        ucwords($message_type->label['singular']),
3780
-                        ucwords($messenger->label['singular'])
3781
-                    )
3782
-                );
3783
-
3784
-                // if message type was invoice then let's make sure we activate the invoice payment method.
3785
-                if ($message_type->name === 'invoice') {
3786
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
3787
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3788
-                    if ($pm instanceof EE_Payment_Method) {
3789
-                        EE_Error::add_attention(
3790
-                            esc_html__(
3791
-                                '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.',
3792
-                                'event_espresso'
3793
-                            )
3794
-                        );
3795
-                    }
3796
-                }
3797
-                // just toggles the entire messenger
3798
-            } else {
3799
-                EE_Error::add_success(
3800
-                    sprintf(
3801
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
3802
-                        ucwords($messenger->label['singular'])
3803
-                    )
3804
-                );
3805
-            }
3806
-
3807
-            return true;
3808
-
3809
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3810
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3811
-            // in which case we just give a success message for the messenger being successfully activated.
3812
-        } else {
3813
-            if (! $messenger->get_default_message_types()) {
3814
-                // messenger doesn't have any default message types so still a success.
3815
-                EE_Error::add_success(
3816
-                    sprintf(
3817
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
3818
-                        ucwords($messenger->label['singular'])
3819
-                    )
3820
-                );
3821
-
3822
-                return true;
3823
-            } else {
3824
-                EE_Error::add_error(
3825
-                    $message_type instanceof EE_message_type
3826
-                        ? sprintf(
3827
-                        esc_html__(
3828
-                            '%s message type was not successfully activated with the %s messenger',
3829
-                            'event_espresso'
3830
-                        ),
3831
-                        ucwords($message_type->label['singular']),
3832
-                        ucwords($messenger->label['singular'])
3833
-                    )
3834
-                        : sprintf(
3835
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
3836
-                        ucwords($messenger->label['singular'])
3837
-                    ),
3838
-                    __FILE__,
3839
-                    __FUNCTION__,
3840
-                    __LINE__
3841
-                );
3842
-
3843
-                return false;
3844
-            }
3845
-        }
3846
-    }
3847
-
3848
-
3849
-    /**
3850
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
3851
-     *
3852
-     * @param EE_messenger         $messenger
3853
-     * @param EE_message_type|null $message_type
3854
-     * @return bool
3855
-     * @throws DomainException
3856
-     * @throws EE_Error
3857
-     * @throws InvalidArgumentException
3858
-     * @throws ReflectionException
3859
-     * @throws InvalidDataTypeException
3860
-     * @throws InvalidInterfaceException
3861
-     */
3862
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3863
-        $messenger,
3864
-        EE_message_type $message_type = null
3865
-    ) {
3866
-        EE_Error::overwrite_success();
3867
-
3868
-        // if $messenger isn't a valid messenger object then get out.
3869
-        if (! $messenger instanceof EE_Messenger) {
3870
-            EE_Error::add_error(
3871
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3872
-                __FILE__,
3873
-                __FUNCTION__,
3874
-                __LINE__
3875
-            );
3876
-
3877
-            return false;
3878
-        }
3879
-
3880
-        if ($message_type instanceof EE_message_type) {
3881
-            $message_type_name = $message_type->name;
3882
-            EE_Error::add_success(
3883
-                sprintf(
3884
-                    esc_html__(
3885
-                        '%s message type has been successfully deactivated for the %s messenger.',
3886
-                        'event_espresso'
3887
-                    ),
3888
-                    ucwords($message_type->label['singular']),
3889
-                    ucwords($messenger->label['singular'])
3890
-                )
3891
-            );
3892
-        } else {
3893
-            $message_type_name = '';
3894
-            EE_Error::add_success(
3895
-                sprintf(
3896
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
3897
-                    ucwords($messenger->label['singular'])
3898
-                )
3899
-            );
3900
-        }
3901
-
3902
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3903
-        if (
3904
-            $messenger->name === 'html'
3905
-            && (
3906
-                is_null($message_type)
3907
-                || $message_type_name === 'invoice'
3908
-            )
3909
-        ) {
3910
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
3911
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3912
-            if ($count_updated > 0) {
3913
-                $msg = $message_type_name === 'invoice'
3914
-                    ? esc_html__(
3915
-                        '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.',
3916
-                        'event_espresso'
3917
-                    )
3918
-                    : esc_html__(
3919
-                        '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.',
3920
-                        'event_espresso'
3921
-                    );
3922
-                EE_Error::add_attention($msg);
3923
-            }
3924
-        }
3925
-
3926
-        return true;
3927
-    }
3928
-
3929
-
3930
-    /**
3931
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3932
-     *
3933
-     * @throws DomainException
3934
-     * @throws EE_Error
3935
-     * @throws EE_Error
3936
-     */
3937
-    public function update_mt_form()
3938
-    {
3939
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
3940
-            EE_Error::add_error(
3941
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
3942
-                __FILE__,
3943
-                __FUNCTION__,
3944
-                __LINE__
3945
-            );
3946
-            $this->_return_json();
3947
-        }
3948
-
3949
-        $message_types = $this->get_installed_message_types();
3950
-        $message_type  = $message_types[ $this->_active_message_type_name ];
3951
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
3952
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
3953
-
3954
-        $this->_template_args['success'] = true;
3955
-        $this->_template_args['content'] = $content;
3956
-        $this->_return_json();
3957
-    }
3958
-
3959
-
3960
-    /**
3961
-     * this handles saving the settings for a messenger or message type
3962
-     *
3963
-     * @throws EE_Error
3964
-     * @throws EE_Error
3965
-     */
3966
-    public function save_settings()
3967
-    {
3968
-        $type = $this->request->getRequestParam('type');
3969
-        if (! $type) {
3970
-            EE_Error::add_error(
3971
-                esc_html__(
3972
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
3973
-                    'event_espresso'
3974
-                ),
3975
-                __FILE__,
3976
-                __FUNCTION__,
3977
-                __LINE__
3978
-            );
3979
-            $this->_template_args['error'] = true;
3980
-            $this->_return_json();
3981
-        }
3982
-
3983
-
3984
-        if ($type === 'messenger') {
3985
-            // this should be an array.
3986
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
3987
-            $messenger = $settings['messenger'];
3988
-            // remove messenger and message_types from settings array
3989
-            unset($settings['messenger'], $settings['message_types']);
3990
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3991
-        } elseif ($type === 'message_type') {
3992
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
3993
-            $messenger    = $settings['messenger'];
3994
-            $message_type = $settings['message_type'];
3995
-            // remove messenger and message_types from settings array
3996
-            unset($settings['messenger'], $settings['message_types']);
3997
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3998
-        }
3999
-
4000
-        // okay we should have the data all setup.  Now we just update!
4001
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4002
-
4003
-        if ($success) {
4004
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4005
-        } else {
4006
-            EE_Error::add_error(
4007
-                esc_html__('Settings did not get updated', 'event_espresso'),
4008
-                __FILE__,
4009
-                __FUNCTION__,
4010
-                __LINE__
4011
-            );
4012
-        }
4013
-
4014
-        $this->_template_args['success'] = $success;
4015
-        $this->_return_json();
4016
-    }
4017
-
4018
-
4019
-
4020
-
4021
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4022
-
4023
-
4024
-    /**
4025
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4026
-     * However, this does not send immediately, it just queues for sending.
4027
-     *
4028
-     * @throws EE_Error
4029
-     * @throws InvalidDataTypeException
4030
-     * @throws InvalidInterfaceException
4031
-     * @throws InvalidArgumentException
4032
-     * @throws ReflectionException
4033
-     * @since 4.9.0
4034
-     */
4035
-    protected function _generate_now()
4036
-    {
4037
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4038
-        $this->_redirect_after_action(false, '', '', [], true);
4039
-    }
4040
-
4041
-
4042
-    /**
4043
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4044
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4045
-     *
4046
-     * @throws EE_Error
4047
-     * @throws InvalidDataTypeException
4048
-     * @throws InvalidInterfaceException
4049
-     * @throws InvalidArgumentException
4050
-     * @throws ReflectionException
4051
-     * @since 4.9.0
4052
-     */
4053
-    protected function _generate_and_send_now()
4054
-    {
4055
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4056
-        $this->_redirect_after_action(false, '', '', [], true);
4057
-    }
4058
-
4059
-
4060
-    /**
4061
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4062
-     *
4063
-     * @throws EE_Error
4064
-     * @throws InvalidDataTypeException
4065
-     * @throws InvalidInterfaceException
4066
-     * @throws InvalidArgumentException
4067
-     * @throws ReflectionException
4068
-     * @since 4.9.0
4069
-     */
4070
-    protected function _queue_for_resending()
4071
-    {
4072
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4073
-        $this->_redirect_after_action(false, '', '', [], true);
4074
-    }
4075
-
4076
-
4077
-    /**
4078
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4079
-     *
4080
-     * @throws EE_Error
4081
-     * @throws InvalidDataTypeException
4082
-     * @throws InvalidInterfaceException
4083
-     * @throws InvalidArgumentException
4084
-     * @throws ReflectionException
4085
-     * @since 4.9.0
4086
-     */
4087
-    protected function _send_now()
4088
-    {
4089
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4090
-        $this->_redirect_after_action(false, '', '', [], true);
4091
-    }
4092
-
4093
-
4094
-    /**
4095
-     * Deletes EE_messages for IDs in the request.
4096
-     *
4097
-     * @throws EE_Error
4098
-     * @throws InvalidDataTypeException
4099
-     * @throws InvalidInterfaceException
4100
-     * @throws InvalidArgumentException
4101
-     * @throws ReflectionException
4102
-     * @since 4.9.0
4103
-     */
4104
-    protected function _delete_ee_messages()
4105
-    {
4106
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4107
-        $deleted_count = 0;
4108
-        foreach ($MSG_IDs as $MSG_ID) {
4109
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4110
-                $deleted_count++;
4111
-            }
4112
-        }
4113
-        if ($deleted_count) {
4114
-            EE_Error::add_success(
4115
-                esc_html(
4116
-                    _n(
4117
-                        'Message successfully deleted',
4118
-                        'Messages successfully deleted',
4119
-                        $deleted_count,
4120
-                        'event_espresso'
4121
-                    )
4122
-                )
4123
-            );
4124
-        } else {
4125
-            EE_Error::add_error(
4126
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4127
-                __FILE__,
4128
-                __FUNCTION__,
4129
-                __LINE__
4130
-            );
4131
-        }
4132
-        $this->_redirect_after_action(false, '', '', [], true);
4133
-    }
4134
-
4135
-
4136
-    /**
4137
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4138
-     *
4139
-     * @return array
4140
-     * @since 4.9.0
4141
-     */
4142
-    protected function _get_msg_ids_from_request()
4143
-    {
4144
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4145
-        if (empty($MSG_IDs)) {
4146
-            return [];
4147
-        }
4148
-        // if 'MSG_ID' was just a single ID (not an array)
4149
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4150
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4151
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4152
-            ? $MSG_IDs
4153
-            : array_keys($MSG_IDs);
4154
-    }
2537
+	}
2538
+
2539
+
2540
+	/**
2541
+	 * @throws EE_Error
2542
+	 * @throws ReflectionException
2543
+	 * @deprecated 5.0.8.p
2544
+	 */
2545
+	protected function _insert_or_update_message_template($new = false)
2546
+	{
2547
+		if ($new) {
2548
+			$this->insertMessageTemplate();
2549
+		} else {
2550
+			$this->updateMessageTemplate();
2551
+		}
2552
+	}
2553
+
2554
+
2555
+	/**
2556
+	 * @throws EE_Error
2557
+	 * @throws ReflectionException
2558
+	 */
2559
+	protected function insertMessageTemplate(): void
2560
+	{
2561
+		$success   = true;
2562
+		$templates = [];
2563
+		try {
2564
+			$templates = $this->getMessageTemplateManager()->generateNewTemplates();
2565
+		} catch (Exception $exception) {
2566
+			$success = false;
2567
+			EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2568
+		}
2569
+
2570
+		/** @var MessageTemplateRequestData $form_data */
2571
+		$form_data = $this->loader->getShared(MessageTemplateRequestData::class);
2572
+		$this->_redirect_after_action(
2573
+			$success && isset($templates['GRP_ID'], $templates['MTP_context']),
2574
+			$this->generateUpdateDescription($form_data->messenger(), $form_data->messageType(), $form_data->context()),
2575
+			'created',
2576
+			[
2577
+				'id'      => $templates['GRP_ID'] ?? 0,
2578
+				'context' => $templates['MTP_context'] ?? '',
2579
+				'action'  => 'edit_message_template',
2580
+			],
2581
+			$this->performTestSendAfterUpdate($form_data->messenger(), $form_data->messageType(), $form_data->context())
2582
+		);
2583
+	}
2584
+
2585
+
2586
+	/**
2587
+	 * @throws EE_Error
2588
+	 * @throws ReflectionException
2589
+	 */
2590
+	protected function updateMessageTemplate(): void
2591
+	{
2592
+		$success = true;
2593
+		try {
2594
+			$this->getMessageTemplateManager()->updateExistingTemplates();
2595
+		} catch (Exception $exception) {
2596
+			$success = false;
2597
+			EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2598
+		}
2599
+
2600
+		/** @var MessageTemplateRequestData $form_data */
2601
+		$form_data = $this->loader->getShared(MessageTemplateRequestData::class);
2602
+
2603
+		$this->_redirect_after_action(
2604
+			$success,
2605
+			$this->generateUpdateDescription($form_data->messenger(), $form_data->messageType(), $form_data->context()),
2606
+			'updated',
2607
+			[
2608
+				'id'      => $form_data->groupID(),
2609
+				'context' => $form_data->context(),
2610
+				'action'  => 'edit_message_template',
2611
+			],
2612
+			$this->performTestSendAfterUpdate($form_data->messenger(), $form_data->messageType(), $form_data->context())
2613
+		);
2614
+	}
2615
+
2616
+
2617
+	/**
2618
+	 * @param string $messenger
2619
+	 * @param string $message_type
2620
+	 * @param string $context
2621
+	 * @return string
2622
+	 * @since 4.10.29.p
2623
+	 */
2624
+	private function generateUpdateDescription(string $messenger, string $message_type, string $context): string
2625
+	{
2626
+		// need the message type and messenger objects to be able to use the labels for the notices
2627
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
2628
+		$messenger_label  = $messenger_object instanceof EE_messenger
2629
+			? ucwords($messenger_object->label['singular'])
2630
+			: '';
2631
+
2632
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
2633
+		$message_type_label  = $message_type_object instanceof EE_message_type
2634
+			? ucwords($message_type_object->label['singular'])
2635
+			: '';
2636
+
2637
+		$context   = ucwords(str_replace('_', ' ', $context));
2638
+		$item_desc = $messenger_label && $message_type_label
2639
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2640
+			: '';
2641
+		$item_desc .= 'Message Template';
2642
+		return $item_desc;
2643
+	}
2644
+
2645
+
2646
+	/**
2647
+	 * @param string $messenger
2648
+	 * @param string $message_type
2649
+	 * @param string $context
2650
+	 * @return bool
2651
+	 * @throws EE_Error
2652
+	 * @throws ReflectionException
2653
+	 * @since 4.10.29.p
2654
+	 */
2655
+	private function performTestSendAfterUpdate(string $messenger, string $message_type, string $context): bool
2656
+	{
2657
+		// was a test send triggered?
2658
+		if ($this->request->requestParamIsSet('test_button')) {
2659
+			EE_Error::overwrite_success();
2660
+			$this->_do_test_send($context, $messenger, $message_type);
2661
+			return true;
2662
+		}
2663
+		return false;
2664
+	}
2665
+
2666
+
2667
+	/**
2668
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2669
+	 *
2670
+	 * @param string $context      what context being tested
2671
+	 * @param string $messenger    messenger being tested
2672
+	 * @param string $message_type message type being tested
2673
+	 * @throws EE_Error
2674
+	 * @throws InvalidArgumentException
2675
+	 * @throws InvalidDataTypeException
2676
+	 * @throws InvalidInterfaceException
2677
+	 * @throws ReflectionException
2678
+	 */
2679
+	protected function _do_test_send(string $context, string $messenger, string $message_type)
2680
+	{
2681
+		// set things up for preview
2682
+		$this->request->setRequestParam('messenger', $messenger);
2683
+		$this->request->setRequestParam('message_type', $message_type);
2684
+		$this->request->setRequestParam('context', $context);
2685
+		$this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2686
+
2687
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
2688
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
2689
+
2690
+		// let's save any existing fields that might be required by the messenger
2691
+		if (
2692
+			! empty($test_settings_fld)
2693
+			&& $active_messenger instanceof EE_messenger
2694
+			&& apply_filters(
2695
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2696
+				true,
2697
+				$test_settings_fld,
2698
+				$active_messenger
2699
+			)
2700
+		) {
2701
+			$active_messenger->set_existing_test_settings($test_settings_fld);
2702
+		}
2703
+
2704
+		/**
2705
+		 * Use filter to add additional controls on whether message can send or not
2706
+		 */
2707
+		if (
2708
+			apply_filters(
2709
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
2710
+				true,
2711
+				$context,
2712
+				$this->request->requestParams(),
2713
+				$messenger,
2714
+				$message_type
2715
+			)
2716
+		) {
2717
+			if (EEM_Event::instance()->count() > 0) {
2718
+				$success = $this->_preview_message(true);
2719
+				if ($success) {
2720
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
2721
+				} else {
2722
+					EE_Error::add_error(
2723
+						esc_html__('The test message was not sent', 'event_espresso'),
2724
+						__FILE__,
2725
+						__FUNCTION__,
2726
+						__LINE__
2727
+					);
2728
+				}
2729
+			} else {
2730
+				$this->noEventsErrorMessage(true);
2731
+			}
2732
+		}
2733
+	}
2734
+
2735
+
2736
+	/**
2737
+	 * [_trash_or_restore_message_template]
2738
+	 *
2739
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2740
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2741
+	 *                        an individual context (FALSE).
2742
+	 * @return void
2743
+	 * @throws EE_Error
2744
+	 * @throws InvalidArgumentException
2745
+	 * @throws InvalidDataTypeException
2746
+	 * @throws InvalidInterfaceException
2747
+	 * @throws ReflectionException
2748
+	 */
2749
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2750
+	{
2751
+		$success = 1;
2752
+
2753
+		// incoming GRP_IDs
2754
+		if ($all) {
2755
+			// Checkboxes
2756
+			$checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2757
+			if (! empty($checkboxes)) {
2758
+				// if array has more than one element then success message should be plural.
2759
+				// todo: what about nonce?
2760
+				$success = count($checkboxes) > 1 ? 2 : 1;
2761
+
2762
+				// cycle through checkboxes
2763
+				foreach (array_keys($checkboxes) as $GRP_ID) {
2764
+					$trashed_or_restored = $trash
2765
+						? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2766
+						: $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2767
+					if (! $trashed_or_restored) {
2768
+						$success = 0;
2769
+					}
2770
+				}
2771
+			} else {
2772
+				// grab single GRP_ID and handle
2773
+				$GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2774
+				if (! empty($GRP_ID)) {
2775
+					$trashed_or_restored = $trash
2776
+						? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2777
+						: $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2778
+					if (! $trashed_or_restored) {
2779
+						$success = 0;
2780
+					}
2781
+				} else {
2782
+					$success = 0;
2783
+				}
2784
+			}
2785
+		}
2786
+
2787
+		$action_desc = $trash
2788
+			? esc_html__('moved to the trash', 'event_espresso')
2789
+			: esc_html__('restored', 'event_espresso');
2790
+
2791
+		$template_switch = $this->request->getRequestParam('template_switch', false, DataType::BOOLEAN);
2792
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
2793
+
2794
+		$item_desc = $all ? _n(
2795
+			'Message Template Group',
2796
+			'Message Template Groups',
2797
+			$success,
2798
+			'event_espresso'
2799
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2800
+
2801
+		$item_desc = $template_switch
2802
+			? _n('template', 'templates', $success, 'event_espresso')
2803
+			: $item_desc;
2804
+
2805
+		$this->_redirect_after_action(
2806
+			$success,
2807
+			$item_desc,
2808
+			$action_desc,
2809
+			[
2810
+				'action' => $this->request->getRequestParam('return'),
2811
+			]
2812
+		);
2813
+	}
2814
+
2815
+
2816
+	/**
2817
+	 * [_delete_message_template]
2818
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2819
+	 *
2820
+	 * @return void
2821
+	 * @throws EE_Error
2822
+	 * @throws InvalidArgumentException
2823
+	 * @throws InvalidDataTypeException
2824
+	 * @throws InvalidInterfaceException
2825
+	 * @throws ReflectionException
2826
+	 */
2827
+	protected function _delete_message_template()
2828
+	{
2829
+		// checkboxes
2830
+		$checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2831
+		if (! empty($checkboxes)) {
2832
+			// if array has more than one element then success message should be plural
2833
+			$success = count($checkboxes) > 1 ? 2 : 1;
2834
+
2835
+			// cycle through bulk action checkboxes
2836
+			foreach (array_keys($checkboxes) as $GRP_ID) {
2837
+				$success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplateGroup($GRP_ID) ? $success
2838
+					: false;
2839
+			}
2840
+		} else {
2841
+			// grab single grp_id and delete
2842
+			$GRP_ID  = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2843
+			$success = $this->getMessageTemplateManager()->permanentlyDeleteMessageTemplateGroup($GRP_ID);
2844
+		}
2845
+
2846
+		$this->_redirect_after_action(
2847
+			$success,
2848
+			'Message Templates',
2849
+			'deleted',
2850
+			[
2851
+				'action' => $this->request->getRequestParam('return'),
2852
+			]
2853
+		);
2854
+	}
2855
+
2856
+
2857
+	/**
2858
+	 *    _learn_more_about_message_templates_link
2859
+	 *
2860
+	 * @access protected
2861
+	 * @return string
2862
+	 */
2863
+	protected function _learn_more_about_message_templates_link()
2864
+	{
2865
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
2866
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
2867
+			   . '</a>';
2868
+	}
2869
+
2870
+
2871
+	/**
2872
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2873
+	 * ajax and other routes.
2874
+	 *
2875
+	 * @return void
2876
+	 * @throws DomainException
2877
+	 * @throws EE_Error
2878
+	 */
2879
+	protected function _settings()
2880
+	{
2881
+		$this->_set_m_mt_settings();
2882
+		// let's setup the messenger tabs
2883
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
2884
+			$this->_m_mt_settings['messenger_tabs'],
2885
+			'messenger_links',
2886
+			'|',
2887
+			$this->request->getRequestParam('selected_messenger', 'email')
2888
+		);
2889
+
2890
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2891
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2892
+
2893
+		$this->display_admin_page_with_sidebar();
2894
+	}
2895
+
2896
+
2897
+	/**
2898
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2899
+	 *
2900
+	 * @access protected
2901
+	 * @return void
2902
+	 * @throws DomainException
2903
+	 */
2904
+	protected function _set_m_mt_settings()
2905
+	{
2906
+		// first if this is already set then lets get out no need to regenerate data.
2907
+		if (! empty($this->_m_mt_settings)) {
2908
+			return;
2909
+		}
2910
+
2911
+		// get all installed messengers and message_types
2912
+		$messengers    = $this->_message_resource_manager->installed_messengers();
2913
+		$message_types = $this->_message_resource_manager->installed_message_types();
2914
+
2915
+
2916
+		// assemble the array for the _tab_text_links helper
2917
+
2918
+		foreach ($messengers as $messenger) {
2919
+			$active                                                     =
2920
+				$this->_message_resource_manager->is_messenger_active($messenger->name);
2921
+			$class                                                      =
2922
+				'ee-messenger-' . sanitize_key($messenger->label['singular']);
2923
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
2924
+				'label' => ucwords($messenger->label['singular']),
2925
+				'class' => $active ? "{$class} messenger-active" : $class,
2926
+				'href'  => $messenger->name,
2927
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
2928
+				'slug'  => $messenger->name,
2929
+				'obj'   => $messenger,
2930
+				'icon'  => $active
2931
+					? '<span class="dashicons dashicons-yes-alt"></span>'
2932
+					: '<span class="dashicons dashicons-remove"></span>',
2933
+			];
2934
+
2935
+
2936
+			$message_types_for_messenger = $messenger->get_valid_message_types();
2937
+
2938
+			foreach ($message_types as $message_type) {
2939
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
2940
+				// it shouldn't show in either the inactive OR active metabox.
2941
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
2942
+					continue;
2943
+				}
2944
+
2945
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
2946
+					$messenger->name,
2947
+					$message_type->name
2948
+				)
2949
+					? 'active'
2950
+					: 'inactive';
2951
+
2952
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
2953
+					'label'    => ucwords($message_type->label['singular']),
2954
+					'class'    => 'message-type-' . $a_or_i,
2955
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2956
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2957
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2958
+					'title'    => $a_or_i === 'active'
2959
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2960
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
2961
+					'content'  => $a_or_i === 'active'
2962
+						? $this->_message_type_settings_content($message_type, $messenger, true)
2963
+						: $this->_message_type_settings_content($message_type, $messenger),
2964
+					'slug'     => $message_type->name,
2965
+					'active'   => $a_or_i === 'active',
2966
+					'obj'      => $message_type,
2967
+				];
2968
+			}
2969
+		}
2970
+	}
2971
+
2972
+
2973
+	/**
2974
+	 * This just prepares the content for the message type settings
2975
+	 *
2976
+	 * @param EE_message_type $message_type The message type object
2977
+	 * @param EE_messenger    $messenger    The messenger object
2978
+	 * @param boolean         $active       Whether the message type is active or not
2979
+	 * @return string html output for the content
2980
+	 * @throws DomainException
2981
+	 */
2982
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
2983
+	{
2984
+		// get message type fields
2985
+		$fields                                         = $message_type->get_admin_settings_fields();
2986
+		$settings_template_args['template_form_fields'] = '';
2987
+
2988
+		if (! empty($fields) && $active) {
2989
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2990
+			foreach ($fields as $fldname => $fldprops) {
2991
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2992
+				$template_form_field[ $field_id ] = [
2993
+					'name'       => 'message_type_settings[' . $fldname . ']',
2994
+					'label'      => $fldprops['label'],
2995
+					'input'      => $fldprops['field_type'],
2996
+					'type'       => $fldprops['value_type'],
2997
+					'required'   => $fldprops['required'],
2998
+					'validation' => $fldprops['validation'],
2999
+					'value'      => $existing_settings[ $fldname ] ?? $fldprops['default'],
3000
+					'options'    => $fldprops['options'] ?? [],
3001
+					'default'    => $existing_settings[ $fldname ] ?? $fldprops['default'],
3002
+					'css_class'  => 'no-drag',
3003
+					'format'     => $fldprops['format'],
3004
+				];
3005
+			}
3006
+
3007
+
3008
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3009
+				? $this->_generate_admin_form_fields(
3010
+					$template_form_field,
3011
+					'string',
3012
+					'ee_mt_activate_form'
3013
+				)
3014
+				: '';
3015
+		}
3016
+
3017
+		$settings_template_args['description'] = $message_type->description;
3018
+		// we also need some hidden fields
3019
+		$hidden_fields = [
3020
+			'message_type_settings[messenger]' . $message_type->name    => [
3021
+				'type'  => 'hidden',
3022
+				'value' => $messenger->name,
3023
+			],
3024
+			'message_type_settings[message_type]' . $message_type->name => [
3025
+				'type'  => 'hidden',
3026
+				'value' => $message_type->name,
3027
+			],
3028
+			'type' . $message_type->name                                => [
3029
+				'type'  => 'hidden',
3030
+				'value' => 'message_type',
3031
+			],
3032
+		];
3033
+
3034
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3035
+			$hidden_fields,
3036
+			'array'
3037
+		);
3038
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3039
+			? ' hidden'
3040
+			: '';
3041
+
3042
+
3043
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3044
+		return EEH_Template::display_template($template, $settings_template_args, true);
3045
+	}
3046
+
3047
+
3048
+	/**
3049
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3050
+	 *
3051
+	 * @access protected
3052
+	 * @return void
3053
+	 * @throws DomainException
3054
+	 */
3055
+	protected function _messages_settings_metaboxes()
3056
+	{
3057
+		$this->_set_m_mt_settings();
3058
+		$m_boxes         = $mt_boxes = [];
3059
+		$m_template_args = $mt_template_args = [];
3060
+
3061
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3062
+
3063
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3064
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3065
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3066
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3067
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3068
+
3069
+				// messenger meta boxes
3070
+				$active         = $selected_messenger === $messenger;
3071
+				$active_mt_tabs = $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] ?? '';
3072
+
3073
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3074
+					esc_html__('%s Settings', 'event_espresso'),
3075
+					$tab_array['label']
3076
+				);
3077
+
3078
+				$m_template_args[ $messenger . '_a_box' ] = [
3079
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3080
+					'inactive_message_types' => isset(
3081
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3082
+					)
3083
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3084
+						: '',
3085
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3086
+					'hidden'                 => $active ? '' : ' hidden',
3087
+					'hide_on_message'        => $hide_on_message,
3088
+					'messenger'              => $messenger,
3089
+					'active'                 => $active,
3090
+				];
3091
+
3092
+				// message type meta boxes
3093
+				// (which is really just the inactive container for each messenger
3094
+				// showing inactive message types for that messenger)
3095
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3096
+				$mt_template_args[ $messenger . '_i_box' ] = [
3097
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3098
+					'inactive_message_types' => isset(
3099
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3100
+					)
3101
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3102
+						: '',
3103
+					'hidden'                 => $active ? '' : ' hidden',
3104
+					'hide_on_message'        => $hide_on_message,
3105
+					'hide_off_message'       => $hide_off_message,
3106
+					'messenger'              => $messenger,
3107
+					'active'                 => $active,
3108
+				];
3109
+			}
3110
+		}
3111
+
3112
+
3113
+		// register messenger metaboxes
3114
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3115
+		foreach ($m_boxes as $box => $label) {
3116
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3117
+			$msgr          = str_replace('_a_box', '', $box);
3118
+			$this->addMetaBox(
3119
+				'espresso_' . $msgr . '_settings',
3120
+				$label,
3121
+				function ($post, $metabox) {
3122
+					EEH_Template::display_template(
3123
+						$metabox['args']['template_path'],
3124
+						$metabox['args']['template_args']
3125
+					);
3126
+				},
3127
+				$this->_current_screen->id,
3128
+				'normal',
3129
+				'high',
3130
+				$callback_args
3131
+			);
3132
+		}
3133
+
3134
+		// register message type metaboxes
3135
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3136
+		foreach ($mt_boxes as $box => $label) {
3137
+			$callback_args = [
3138
+				'template_path' => $mt_template_path,
3139
+				'template_args' => $mt_template_args[ $box ],
3140
+			];
3141
+			$mt            = str_replace('_i_box', '', $box);
3142
+			$this->addMetaBox(
3143
+				'espresso_' . $mt . '_inactive_mts',
3144
+				$label,
3145
+				function ($post, $metabox) {
3146
+					EEH_Template::display_template(
3147
+						$metabox['args']['template_path'],
3148
+						$metabox['args']['template_args']
3149
+					);
3150
+				},
3151
+				$this->_current_screen->id,
3152
+				'side',
3153
+				'high',
3154
+				$callback_args
3155
+			);
3156
+		}
3157
+
3158
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3159
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3160
+		if (is_main_site()) {
3161
+			$this->addMetaBox(
3162
+				'espresso_global_message_settings',
3163
+				esc_html__('Global Message Settings', 'event_espresso'),
3164
+				[$this, 'global_messages_settings_metabox_content'],
3165
+				$this->_current_screen->id,
3166
+				'normal',
3167
+				'low',
3168
+				[]
3169
+			);
3170
+		}
3171
+	}
3172
+
3173
+
3174
+	/**
3175
+	 *  This generates the content for the global messages settings metabox.
3176
+	 *
3177
+	 * @return void
3178
+	 * @throws EE_Error
3179
+	 * @throws InvalidArgumentException
3180
+	 * @throws ReflectionException
3181
+	 * @throws InvalidDataTypeException
3182
+	 * @throws InvalidInterfaceException
3183
+	 */
3184
+	public function global_messages_settings_metabox_content()
3185
+	{
3186
+		$form = $this->_generate_global_settings_form();
3187
+		echo wp_kses(
3188
+			$form->form_open(
3189
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3190
+				'POST'
3191
+			),
3192
+			AllowedTags::getWithFormTags()
3193
+		);
3194
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3195
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3196
+	}
3197
+
3198
+
3199
+	/**
3200
+	 * This generates and returns the form object for the global messages settings.
3201
+	 *
3202
+	 * @return EE_Form_Section_Proper
3203
+	 * @throws EE_Error
3204
+	 * @throws InvalidArgumentException
3205
+	 * @throws ReflectionException
3206
+	 * @throws InvalidDataTypeException
3207
+	 * @throws InvalidInterfaceException
3208
+	 */
3209
+	protected function _generate_global_settings_form()
3210
+	{
3211
+		/** @var EE_Network_Core_Config $network_config */
3212
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3213
+
3214
+		return new EE_Form_Section_Proper(
3215
+			[
3216
+				'name'            => 'global_messages_settings',
3217
+				'html_id'         => 'global_messages_settings',
3218
+				'html_class'      => 'form-table',
3219
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3220
+				'subsections'     => apply_filters(
3221
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3222
+					[
3223
+						'do_messages_on_same_request' => new EE_Select_Input(
3224
+							[
3225
+								true  => esc_html__('On the same request', 'event_espresso'),
3226
+								false => esc_html__('On a separate request', 'event_espresso'),
3227
+							],
3228
+							[
3229
+								'default'         => $network_config->do_messages_on_same_request,
3230
+								'html_label_text' => esc_html__(
3231
+									'Generate and send all messages:',
3232
+									'event_espresso'
3233
+								),
3234
+								'html_help_text'  => esc_html__(
3235
+									'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.',
3236
+									'event_espresso'
3237
+								),
3238
+							]
3239
+						),
3240
+						'delete_threshold'            => new EE_Select_Input(
3241
+							[
3242
+								0  => esc_html__('Forever', 'event_espresso'),
3243
+								3  => esc_html__('3 Months', 'event_espresso'),
3244
+								6  => esc_html__('6 Months', 'event_espresso'),
3245
+								9  => esc_html__('9 Months', 'event_espresso'),
3246
+								12 => esc_html__('12 Months', 'event_espresso'),
3247
+								24 => esc_html__('24 Months', 'event_espresso'),
3248
+								36 => esc_html__('36 Months', 'event_espresso'),
3249
+							],
3250
+							[
3251
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3252
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3253
+								'html_help_text'  => esc_html__(
3254
+									'You can control how long a record of processed messages is kept via this option.',
3255
+									'event_espresso'
3256
+								),
3257
+							]
3258
+						),
3259
+						'update_settings'             => new EE_Submit_Input(
3260
+							[
3261
+								'default'         => esc_html__('Update', 'event_espresso'),
3262
+								'html_label_text' => '',
3263
+							]
3264
+						),
3265
+					]
3266
+				),
3267
+			]
3268
+		);
3269
+	}
3270
+
3271
+
3272
+	/**
3273
+	 * This handles updating the global settings set on the admin page.
3274
+	 *
3275
+	 * @throws EE_Error
3276
+	 * @throws InvalidDataTypeException
3277
+	 * @throws InvalidInterfaceException
3278
+	 * @throws InvalidArgumentException
3279
+	 * @throws ReflectionException
3280
+	 */
3281
+	protected function _update_global_settings()
3282
+	{
3283
+		/** @var EE_Network_Core_Config $network_config */
3284
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3285
+		$messages_config = EE_Registry::instance()->CFG->messages;
3286
+		$form            = $this->_generate_global_settings_form();
3287
+		if ($form->was_submitted()) {
3288
+			$form->receive_form_submission();
3289
+			if ($form->is_valid()) {
3290
+				$valid_data = $form->valid_data();
3291
+				// \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
3292
+				foreach ($valid_data as $property => $value) {
3293
+					$setter = 'set_' . $property;
3294
+					if (method_exists($network_config, $setter)) {
3295
+						$network_config->{$setter}($value);
3296
+					} elseif (
3297
+						property_exists($network_config, $property)
3298
+						&& $network_config->{$property} !== $value
3299
+					) {
3300
+						$network_config->{$property} = $value;
3301
+					} elseif (
3302
+						property_exists($messages_config, $property)
3303
+						&& $messages_config->{$property} !== $value
3304
+					) {
3305
+						$messages_config->{$property} = $value;
3306
+					}
3307
+				}
3308
+				// only update if the form submission was valid!
3309
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3310
+				EE_Registry::instance()->CFG->update_espresso_config();
3311
+				EE_Error::overwrite_success();
3312
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3313
+			}
3314
+		}
3315
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3316
+	}
3317
+
3318
+
3319
+	/**
3320
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3321
+	 *
3322
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3323
+	 * @return string html formatted tabs
3324
+	 * @throws DomainException
3325
+	 */
3326
+	protected function _get_mt_tabs($tab_array)
3327
+	{
3328
+		$tab_array = (array) $tab_array;
3329
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3330
+		$tabs      = '';
3331
+
3332
+		foreach ($tab_array as $tab) {
3333
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3334
+		}
3335
+
3336
+		return $tabs;
3337
+	}
3338
+
3339
+
3340
+	/**
3341
+	 * This prepares the content of the messenger meta box admin settings
3342
+	 *
3343
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3344
+	 * @return string html formatted content
3345
+	 * @throws DomainException
3346
+	 */
3347
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3348
+	{
3349
+		$fields = $messenger->get_admin_settings_fields();
3350
+
3351
+		$settings_template_args['template_form_fields'] = '';
3352
+		// is $messenger active?
3353
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3354
+
3355
+
3356
+		if (! empty($fields)) {
3357
+			$existing_settings = $messenger->get_existing_admin_settings();
3358
+
3359
+			foreach ($fields as $field_name => $field_props) {
3360
+				$field_id                         = $messenger->name . '-' . $field_name;
3361
+				$template_form_field[ $field_id ] = [
3362
+					'name'       => 'messenger_settings[' . $field_id . ']',
3363
+					'label'      => $field_props['label'],
3364
+					'input'      => $field_props['field_type'],
3365
+					'type'       => $field_props['value_type'],
3366
+					'required'   => $field_props['required'],
3367
+					'validation' => $field_props['validation'],
3368
+					'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3369
+					'css_class'  => '',
3370
+					'format'     => $field_props['format'],
3371
+				];
3372
+			}
3373
+
3374
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3375
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3376
+				: '';
3377
+		}
3378
+
3379
+		// we also need some hidden fields
3380
+		$settings_template_args['hidden_fields'] = [
3381
+			'messenger_settings[messenger]' . $messenger->name => [
3382
+				'type'  => 'hidden',
3383
+				'value' => $messenger->name,
3384
+			],
3385
+			'type' . $messenger->name                          => [
3386
+				'type'  => 'hidden',
3387
+				'value' => 'messenger',
3388
+			],
3389
+		];
3390
+
3391
+		// make sure any active message types that are existing are included in the hidden fields
3392
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3393
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3394
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3395
+					'type'  => 'hidden',
3396
+					'value' => $mt,
3397
+				];
3398
+			}
3399
+		}
3400
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3401
+			$settings_template_args['hidden_fields'],
3402
+			'array'
3403
+		);
3404
+		$active                                  =
3405
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3406
+
3407
+		$settings_template_args['messenger']           = $messenger->name;
3408
+		$settings_template_args['description']         = $messenger->description;
3409
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3410
+
3411
+
3412
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3413
+			$messenger->name
3414
+		)
3415
+			? $settings_template_args['show_hide_edit_form']
3416
+			: ' hidden';
3417
+
3418
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3419
+			? ' hidden'
3420
+			: $settings_template_args['show_hide_edit_form'];
3421
+
3422
+
3423
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3424
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3425
+		$settings_template_args['on_off_status'] = $active;
3426
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3427
+		return EEH_Template::display_template(
3428
+			$template,
3429
+			$settings_template_args,
3430
+			true
3431
+		);
3432
+	}
3433
+
3434
+
3435
+	/**
3436
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3437
+	 *
3438
+	 * @throws DomainException
3439
+	 * @throws EE_Error
3440
+	 * @throws InvalidDataTypeException
3441
+	 * @throws InvalidInterfaceException
3442
+	 * @throws InvalidArgumentException
3443
+	 * @throws ReflectionException
3444
+	 */
3445
+	public function activate_messenger_toggle()
3446
+	{
3447
+		$success = true;
3448
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3449
+		// let's check that we have required data
3450
+
3451
+		if (! $this->_active_messenger_name) {
3452
+			EE_Error::add_error(
3453
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3454
+				__FILE__,
3455
+				__FUNCTION__,
3456
+				__LINE__
3457
+			);
3458
+			$success = false;
3459
+		}
3460
+
3461
+		// do a nonce check here since we're not arriving via a normal route
3462
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
3463
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
3464
+
3465
+		$this->_verify_nonce($nonce, $nonce_ref);
3466
+
3467
+
3468
+		$status = $this->request->getRequestParam('status');
3469
+		if (! $status) {
3470
+			EE_Error::add_error(
3471
+				esc_html__(
3472
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3473
+					'event_espresso'
3474
+				),
3475
+				__FILE__,
3476
+				__FUNCTION__,
3477
+				__LINE__
3478
+			);
3479
+			$success = false;
3480
+		}
3481
+
3482
+		// do check to verify we have a valid status.
3483
+		if ($status !== 'off' && $status !== 'on') {
3484
+			EE_Error::add_error(
3485
+				sprintf(
3486
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3487
+					$status
3488
+				),
3489
+				__FILE__,
3490
+				__FUNCTION__,
3491
+				__LINE__
3492
+			);
3493
+			$success = false;
3494
+		}
3495
+
3496
+		if ($success) {
3497
+			// made it here?  Stop dawdling then!!
3498
+			$success = $status === 'off'
3499
+				? $this->_deactivate_messenger($this->_active_messenger_name)
3500
+				: $this->_activate_messenger($this->_active_messenger_name);
3501
+		}
3502
+
3503
+		$this->_template_args['success'] = $success;
3504
+
3505
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
3506
+		$this->_return_json();
3507
+	}
3508
+
3509
+
3510
+	/**
3511
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3512
+	 *
3513
+	 * @throws DomainException
3514
+	 * @throws EE_Error
3515
+	 * @throws ReflectionException
3516
+	 * @throws InvalidDataTypeException
3517
+	 * @throws InvalidInterfaceException
3518
+	 * @throws InvalidArgumentException
3519
+	 */
3520
+	public function activate_mt_toggle()
3521
+	{
3522
+		$success = true;
3523
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3524
+
3525
+		// let's make sure we have the necessary data
3526
+		if (! $this->_active_message_type_name) {
3527
+			EE_Error::add_error(
3528
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3529
+				__FILE__,
3530
+				__FUNCTION__,
3531
+				__LINE__
3532
+			);
3533
+			$success = false;
3534
+		}
3535
+
3536
+		if (! $this->_active_messenger_name) {
3537
+			EE_Error::add_error(
3538
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3539
+				__FILE__,
3540
+				__FUNCTION__,
3541
+				__LINE__
3542
+			);
3543
+			$success = false;
3544
+		}
3545
+
3546
+		$status = $this->request->getRequestParam('status');
3547
+		if (! $status) {
3548
+			EE_Error::add_error(
3549
+				esc_html__(
3550
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3551
+					'event_espresso'
3552
+				),
3553
+				__FILE__,
3554
+				__FUNCTION__,
3555
+				__LINE__
3556
+			);
3557
+			$success = false;
3558
+		}
3559
+
3560
+
3561
+		// do check to verify we have a valid status.
3562
+		if ($status !== 'activate' && $status !== 'deactivate') {
3563
+			EE_Error::add_error(
3564
+				sprintf(
3565
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3566
+					$status
3567
+				),
3568
+				__FILE__,
3569
+				__FUNCTION__,
3570
+				__LINE__
3571
+			);
3572
+			$success = false;
3573
+		}
3574
+
3575
+
3576
+		// do a nonce check here since we're not arriving via a normal route
3577
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
3578
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
3579
+
3580
+		if ($success) {
3581
+			// made it here? um, what are you waiting for then?
3582
+			$success = $status === 'deactivate'
3583
+				? $this->_deactivate_message_type_for_messenger(
3584
+					$this->_active_messenger_name,
3585
+					$this->_active_message_type_name
3586
+				)
3587
+				: $this->_activate_message_type_for_messenger(
3588
+					$this->_active_messenger_name,
3589
+					$this->_active_message_type_name
3590
+				);
3591
+		}
3592
+
3593
+		$this->_template_args['success'] = $success;
3594
+		$this->_return_json();
3595
+	}
3596
+
3597
+
3598
+	/**
3599
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3600
+	 *
3601
+	 * @param string $messenger_name The name of the messenger being activated
3602
+	 * @return bool
3603
+	 * @throws DomainException
3604
+	 * @throws EE_Error
3605
+	 * @throws InvalidArgumentException
3606
+	 * @throws ReflectionException
3607
+	 * @throws InvalidDataTypeException
3608
+	 * @throws InvalidInterfaceException
3609
+	 */
3610
+	protected function _activate_messenger($messenger_name)
3611
+	{
3612
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3613
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
3614
+			? $active_messenger->get_default_message_types()
3615
+			: [];
3616
+
3617
+		// ensure is active
3618
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
3619
+
3620
+		// set response_data for reload
3621
+		foreach ($message_types_to_activate as $message_type_name) {
3622
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3623
+			if (
3624
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
3625
+					$messenger_name,
3626
+					$message_type_name
3627
+				)
3628
+				&& $message_type instanceof EE_message_type
3629
+			) {
3630
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3631
+				if ($message_type->get_admin_settings_fields()) {
3632
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3633
+				}
3634
+			}
3635
+		}
3636
+
3637
+		// add success message for activating messenger
3638
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3639
+	}
3640
+
3641
+
3642
+	/**
3643
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3644
+	 *
3645
+	 * @param string $messenger_name The name of the messenger being activated
3646
+	 * @return bool
3647
+	 * @throws DomainException
3648
+	 * @throws EE_Error
3649
+	 * @throws InvalidArgumentException
3650
+	 * @throws ReflectionException
3651
+	 * @throws InvalidDataTypeException
3652
+	 * @throws InvalidInterfaceException
3653
+	 */
3654
+	protected function _deactivate_messenger($messenger_name)
3655
+	{
3656
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3657
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3658
+
3659
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3660
+	}
3661
+
3662
+
3663
+	/**
3664
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3665
+	 *
3666
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3667
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3668
+	 * @return bool
3669
+	 * @throws DomainException
3670
+	 * @throws EE_Error
3671
+	 * @throws InvalidArgumentException
3672
+	 * @throws ReflectionException
3673
+	 * @throws InvalidDataTypeException
3674
+	 * @throws InvalidInterfaceException
3675
+	 */
3676
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3677
+	{
3678
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
3679
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3680
+
3681
+		// ensure is active
3682
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
3683
+
3684
+		// set response for load
3685
+		if (
3686
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
3687
+				$messenger_name,
3688
+				$message_type_name
3689
+			)
3690
+		) {
3691
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3692
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3693
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3694
+			}
3695
+		}
3696
+
3697
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
3698
+			$active_messenger,
3699
+			$message_type_to_activate
3700
+		);
3701
+	}
3702
+
3703
+
3704
+	/**
3705
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3706
+	 *
3707
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3708
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3709
+	 * @return bool
3710
+	 * @throws DomainException
3711
+	 * @throws EE_Error
3712
+	 * @throws InvalidArgumentException
3713
+	 * @throws ReflectionException
3714
+	 * @throws InvalidDataTypeException
3715
+	 * @throws InvalidInterfaceException
3716
+	 */
3717
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3718
+	{
3719
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3720
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3721
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3722
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3723
+
3724
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
3725
+			$active_messenger,
3726
+			$message_type_to_deactivate
3727
+		);
3728
+	}
3729
+
3730
+
3731
+	/**
3732
+	 * This just initializes the defaults for activating messenger and message type responses.
3733
+	 */
3734
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
3735
+	{
3736
+		$this->_template_args['data']['active_mts'] = [];
3737
+		$this->_template_args['data']['mt_reload']  = [];
3738
+	}
3739
+
3740
+
3741
+	/**
3742
+	 * Setup appropriate response for activating a messenger and/or message types
3743
+	 *
3744
+	 * @param EE_messenger         $messenger
3745
+	 * @param EE_message_type|null $message_type
3746
+	 * @return bool
3747
+	 * @throws DomainException
3748
+	 * @throws EE_Error
3749
+	 * @throws InvalidArgumentException
3750
+	 * @throws ReflectionException
3751
+	 * @throws InvalidDataTypeException
3752
+	 * @throws InvalidInterfaceException
3753
+	 */
3754
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
3755
+		$messenger,
3756
+		EE_Message_Type $message_type = null
3757
+	) {
3758
+		// if $messenger isn't a valid messenger object then get out.
3759
+		if (! $messenger instanceof EE_Messenger) {
3760
+			EE_Error::add_error(
3761
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
3762
+				__FILE__,
3763
+				__FUNCTION__,
3764
+				__LINE__
3765
+			);
3766
+			return false;
3767
+		}
3768
+		// activated
3769
+		if ($this->_template_args['data']['active_mts']) {
3770
+			EE_Error::overwrite_success();
3771
+			// activated a message type with the messenger
3772
+			if ($message_type instanceof EE_message_type) {
3773
+				EE_Error::add_success(
3774
+					sprintf(
3775
+						esc_html__(
3776
+							'%s message type has been successfully activated with the %s messenger',
3777
+							'event_espresso'
3778
+						),
3779
+						ucwords($message_type->label['singular']),
3780
+						ucwords($messenger->label['singular'])
3781
+					)
3782
+				);
3783
+
3784
+				// if message type was invoice then let's make sure we activate the invoice payment method.
3785
+				if ($message_type->name === 'invoice') {
3786
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
3787
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3788
+					if ($pm instanceof EE_Payment_Method) {
3789
+						EE_Error::add_attention(
3790
+							esc_html__(
3791
+								'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.',
3792
+								'event_espresso'
3793
+							)
3794
+						);
3795
+					}
3796
+				}
3797
+				// just toggles the entire messenger
3798
+			} else {
3799
+				EE_Error::add_success(
3800
+					sprintf(
3801
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
3802
+						ucwords($messenger->label['singular'])
3803
+					)
3804
+				);
3805
+			}
3806
+
3807
+			return true;
3808
+
3809
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3810
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3811
+			// in which case we just give a success message for the messenger being successfully activated.
3812
+		} else {
3813
+			if (! $messenger->get_default_message_types()) {
3814
+				// messenger doesn't have any default message types so still a success.
3815
+				EE_Error::add_success(
3816
+					sprintf(
3817
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
3818
+						ucwords($messenger->label['singular'])
3819
+					)
3820
+				);
3821
+
3822
+				return true;
3823
+			} else {
3824
+				EE_Error::add_error(
3825
+					$message_type instanceof EE_message_type
3826
+						? sprintf(
3827
+						esc_html__(
3828
+							'%s message type was not successfully activated with the %s messenger',
3829
+							'event_espresso'
3830
+						),
3831
+						ucwords($message_type->label['singular']),
3832
+						ucwords($messenger->label['singular'])
3833
+					)
3834
+						: sprintf(
3835
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
3836
+						ucwords($messenger->label['singular'])
3837
+					),
3838
+					__FILE__,
3839
+					__FUNCTION__,
3840
+					__LINE__
3841
+				);
3842
+
3843
+				return false;
3844
+			}
3845
+		}
3846
+	}
3847
+
3848
+
3849
+	/**
3850
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
3851
+	 *
3852
+	 * @param EE_messenger         $messenger
3853
+	 * @param EE_message_type|null $message_type
3854
+	 * @return bool
3855
+	 * @throws DomainException
3856
+	 * @throws EE_Error
3857
+	 * @throws InvalidArgumentException
3858
+	 * @throws ReflectionException
3859
+	 * @throws InvalidDataTypeException
3860
+	 * @throws InvalidInterfaceException
3861
+	 */
3862
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3863
+		$messenger,
3864
+		EE_message_type $message_type = null
3865
+	) {
3866
+		EE_Error::overwrite_success();
3867
+
3868
+		// if $messenger isn't a valid messenger object then get out.
3869
+		if (! $messenger instanceof EE_Messenger) {
3870
+			EE_Error::add_error(
3871
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3872
+				__FILE__,
3873
+				__FUNCTION__,
3874
+				__LINE__
3875
+			);
3876
+
3877
+			return false;
3878
+		}
3879
+
3880
+		if ($message_type instanceof EE_message_type) {
3881
+			$message_type_name = $message_type->name;
3882
+			EE_Error::add_success(
3883
+				sprintf(
3884
+					esc_html__(
3885
+						'%s message type has been successfully deactivated for the %s messenger.',
3886
+						'event_espresso'
3887
+					),
3888
+					ucwords($message_type->label['singular']),
3889
+					ucwords($messenger->label['singular'])
3890
+				)
3891
+			);
3892
+		} else {
3893
+			$message_type_name = '';
3894
+			EE_Error::add_success(
3895
+				sprintf(
3896
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
3897
+					ucwords($messenger->label['singular'])
3898
+				)
3899
+			);
3900
+		}
3901
+
3902
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3903
+		if (
3904
+			$messenger->name === 'html'
3905
+			&& (
3906
+				is_null($message_type)
3907
+				|| $message_type_name === 'invoice'
3908
+			)
3909
+		) {
3910
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
3911
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3912
+			if ($count_updated > 0) {
3913
+				$msg = $message_type_name === 'invoice'
3914
+					? esc_html__(
3915
+						'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.',
3916
+						'event_espresso'
3917
+					)
3918
+					: esc_html__(
3919
+						'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.',
3920
+						'event_espresso'
3921
+					);
3922
+				EE_Error::add_attention($msg);
3923
+			}
3924
+		}
3925
+
3926
+		return true;
3927
+	}
3928
+
3929
+
3930
+	/**
3931
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3932
+	 *
3933
+	 * @throws DomainException
3934
+	 * @throws EE_Error
3935
+	 * @throws EE_Error
3936
+	 */
3937
+	public function update_mt_form()
3938
+	{
3939
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
3940
+			EE_Error::add_error(
3941
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
3942
+				__FILE__,
3943
+				__FUNCTION__,
3944
+				__LINE__
3945
+			);
3946
+			$this->_return_json();
3947
+		}
3948
+
3949
+		$message_types = $this->get_installed_message_types();
3950
+		$message_type  = $message_types[ $this->_active_message_type_name ];
3951
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
3952
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
3953
+
3954
+		$this->_template_args['success'] = true;
3955
+		$this->_template_args['content'] = $content;
3956
+		$this->_return_json();
3957
+	}
3958
+
3959
+
3960
+	/**
3961
+	 * this handles saving the settings for a messenger or message type
3962
+	 *
3963
+	 * @throws EE_Error
3964
+	 * @throws EE_Error
3965
+	 */
3966
+	public function save_settings()
3967
+	{
3968
+		$type = $this->request->getRequestParam('type');
3969
+		if (! $type) {
3970
+			EE_Error::add_error(
3971
+				esc_html__(
3972
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
3973
+					'event_espresso'
3974
+				),
3975
+				__FILE__,
3976
+				__FUNCTION__,
3977
+				__LINE__
3978
+			);
3979
+			$this->_template_args['error'] = true;
3980
+			$this->_return_json();
3981
+		}
3982
+
3983
+
3984
+		if ($type === 'messenger') {
3985
+			// this should be an array.
3986
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
3987
+			$messenger = $settings['messenger'];
3988
+			// remove messenger and message_types from settings array
3989
+			unset($settings['messenger'], $settings['message_types']);
3990
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3991
+		} elseif ($type === 'message_type') {
3992
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
3993
+			$messenger    = $settings['messenger'];
3994
+			$message_type = $settings['message_type'];
3995
+			// remove messenger and message_types from settings array
3996
+			unset($settings['messenger'], $settings['message_types']);
3997
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3998
+		}
3999
+
4000
+		// okay we should have the data all setup.  Now we just update!
4001
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4002
+
4003
+		if ($success) {
4004
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4005
+		} else {
4006
+			EE_Error::add_error(
4007
+				esc_html__('Settings did not get updated', 'event_espresso'),
4008
+				__FILE__,
4009
+				__FUNCTION__,
4010
+				__LINE__
4011
+			);
4012
+		}
4013
+
4014
+		$this->_template_args['success'] = $success;
4015
+		$this->_return_json();
4016
+	}
4017
+
4018
+
4019
+
4020
+
4021
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4022
+
4023
+
4024
+	/**
4025
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4026
+	 * However, this does not send immediately, it just queues for sending.
4027
+	 *
4028
+	 * @throws EE_Error
4029
+	 * @throws InvalidDataTypeException
4030
+	 * @throws InvalidInterfaceException
4031
+	 * @throws InvalidArgumentException
4032
+	 * @throws ReflectionException
4033
+	 * @since 4.9.0
4034
+	 */
4035
+	protected function _generate_now()
4036
+	{
4037
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4038
+		$this->_redirect_after_action(false, '', '', [], true);
4039
+	}
4040
+
4041
+
4042
+	/**
4043
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4044
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4045
+	 *
4046
+	 * @throws EE_Error
4047
+	 * @throws InvalidDataTypeException
4048
+	 * @throws InvalidInterfaceException
4049
+	 * @throws InvalidArgumentException
4050
+	 * @throws ReflectionException
4051
+	 * @since 4.9.0
4052
+	 */
4053
+	protected function _generate_and_send_now()
4054
+	{
4055
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4056
+		$this->_redirect_after_action(false, '', '', [], true);
4057
+	}
4058
+
4059
+
4060
+	/**
4061
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4062
+	 *
4063
+	 * @throws EE_Error
4064
+	 * @throws InvalidDataTypeException
4065
+	 * @throws InvalidInterfaceException
4066
+	 * @throws InvalidArgumentException
4067
+	 * @throws ReflectionException
4068
+	 * @since 4.9.0
4069
+	 */
4070
+	protected function _queue_for_resending()
4071
+	{
4072
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4073
+		$this->_redirect_after_action(false, '', '', [], true);
4074
+	}
4075
+
4076
+
4077
+	/**
4078
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4079
+	 *
4080
+	 * @throws EE_Error
4081
+	 * @throws InvalidDataTypeException
4082
+	 * @throws InvalidInterfaceException
4083
+	 * @throws InvalidArgumentException
4084
+	 * @throws ReflectionException
4085
+	 * @since 4.9.0
4086
+	 */
4087
+	protected function _send_now()
4088
+	{
4089
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4090
+		$this->_redirect_after_action(false, '', '', [], true);
4091
+	}
4092
+
4093
+
4094
+	/**
4095
+	 * Deletes EE_messages for IDs in the request.
4096
+	 *
4097
+	 * @throws EE_Error
4098
+	 * @throws InvalidDataTypeException
4099
+	 * @throws InvalidInterfaceException
4100
+	 * @throws InvalidArgumentException
4101
+	 * @throws ReflectionException
4102
+	 * @since 4.9.0
4103
+	 */
4104
+	protected function _delete_ee_messages()
4105
+	{
4106
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4107
+		$deleted_count = 0;
4108
+		foreach ($MSG_IDs as $MSG_ID) {
4109
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4110
+				$deleted_count++;
4111
+			}
4112
+		}
4113
+		if ($deleted_count) {
4114
+			EE_Error::add_success(
4115
+				esc_html(
4116
+					_n(
4117
+						'Message successfully deleted',
4118
+						'Messages successfully deleted',
4119
+						$deleted_count,
4120
+						'event_espresso'
4121
+					)
4122
+				)
4123
+			);
4124
+		} else {
4125
+			EE_Error::add_error(
4126
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4127
+				__FILE__,
4128
+				__FUNCTION__,
4129
+				__LINE__
4130
+			);
4131
+		}
4132
+		$this->_redirect_after_action(false, '', '', [], true);
4133
+	}
4134
+
4135
+
4136
+	/**
4137
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4138
+	 *
4139
+	 * @return array
4140
+	 * @since 4.9.0
4141
+	 */
4142
+	protected function _get_msg_ids_from_request()
4143
+	{
4144
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4145
+		if (empty($MSG_IDs)) {
4146
+			return [];
4147
+		}
4148
+		// if 'MSG_ID' was just a single ID (not an array)
4149
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4150
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4151
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4152
+			? $MSG_IDs
4153
+			: array_keys($MSG_IDs);
4154
+	}
4155 4155
 }
Please login to merge, or discard this patch.
Spacing   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function getMsgModel(): EEM_Message
88 88
     {
89
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
89
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
90 90
             $this->MSG_MODEL = EEM_Message::instance();
91 91
         }
92 92
         return $this->MSG_MODEL;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function getMtpModel(): EEM_Message_Template
102 102
     {
103
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
103
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
104 104
             $this->MTP_MODEL = EEM_Message_Template::instance();
105 105
         }
106 106
         return $this->MTP_MODEL;
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function getMtgModel(): EEM_Message_Template_Group
116 116
     {
117
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
117
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
118 118
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
119 119
         }
120 120
         return $this->MTG_MODEL;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 
124 124
     public function getMessageTemplateManager(): MessageTemplateManager
125 125
     {
126
-        if (! $this->message_template_manager instanceof MessageTemplateManager) {
126
+        if ( ! $this->message_template_manager instanceof MessageTemplateManager) {
127 127
             $this->message_template_manager = $this->loader->getShared(MessageTemplateManager::class);
128 128
         }
129 129
         return $this->message_template_manager;
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 
153 153
     protected function _load_message_resource_manager()
154 154
     {
155
-        if (! $this->_message_resource_manager instanceof EE_Message_Resource_Manager) {
155
+        if ( ! $this->_message_resource_manager instanceof EE_Message_Resource_Manager) {
156 156
             $this->_message_resource_manager = $this->loader->getShared(EE_Message_Resource_Manager::class);
157 157
         }
158 158
     }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
181 181
             $messenger_options
182 182
         );
183
-        $input             = new EE_Select_Input(
183
+        $input = new EE_Select_Input(
184 184
             $messenger_options,
185 185
             [
186 186
                 'html_name'  => 'ee_messenger_filter_by',
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
218 218
             $message_type_options
219 219
         );
220
-        $input                = new EE_Select_Input(
220
+        $input = new EE_Select_Input(
221 221
             $message_type_options,
222 222
             [
223 223
                 'html_name'  => 'ee_message_type_filter_by',
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
255 255
             $context_options
256 256
         );
257
-        $input           = new EE_Select_Input(
257
+        $input = new EE_Select_Input(
258 258
             $context_options,
259 259
             [
260 260
                 'html_name'  => 'ee_context_filter_by',
@@ -633,53 +633,53 @@  discard block
 block discarded – undo
633 633
 
634 634
     public function messages_help_tab()
635 635
     {
636
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
636
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
637 637
     }
638 638
 
639 639
 
640 640
     public function messengers_help_tab()
641 641
     {
642
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
642
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
643 643
     }
644 644
 
645 645
 
646 646
     public function message_types_help_tab()
647 647
     {
648
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
648
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
649 649
     }
650 650
 
651 651
 
652 652
     public function messages_overview_help_tab()
653 653
     {
654
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
654
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
655 655
     }
656 656
 
657 657
 
658 658
     public function message_templates_help_tab()
659 659
     {
660
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
660
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
661 661
     }
662 662
 
663 663
 
664 664
     public function edit_message_template_help_tab()
665 665
     {
666
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
666
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
667 667
                         . esc_attr__('Editor Title', 'event_espresso')
668 668
                         . '" />';
669
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
669
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
670 670
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
671 671
                         . '" />';
672
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
672
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
673 673
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
674 674
                         . '" />';
675
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
675
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
676 676
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
677 677
                         . '" />';
678
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
678
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
679 679
                         . esc_attr__('Publish Metabox', 'event_espresso')
680 680
                         . '" />';
681 681
         EEH_Template::display_template(
682
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
682
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
683 683
             $args
684 684
         );
685 685
     }
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
         $this->_set_shortcodes();
695 695
         $args['shortcodes'] = $this->_shortcodes;
696 696
         EEH_Template::display_template(
697
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
697
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
698 698
             $args
699 699
         );
700 700
     }
@@ -702,16 +702,16 @@  discard block
 block discarded – undo
702 702
 
703 703
     public function preview_message_help_tab()
704 704
     {
705
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
705
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
706 706
     }
707 707
 
708 708
 
709 709
     public function settings_help_tab()
710 710
     {
711
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
712
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
713
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
714
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
711
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
712
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
713
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
714
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
715 715
         $args['img3'] = '<div class="ee-switch">'
716 716
                         . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
717 717
                         . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
                         . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
721 721
                         . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
722 722
                         . '</div>';
723
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
723
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
724 724
     }
725 725
 
726 726
 
@@ -728,27 +728,27 @@  discard block
 block discarded – undo
728 728
     {
729 729
         wp_enqueue_style(
730 730
             'espresso_ee_msg',
731
-            EE_MSG_ASSETS_URL . 'ee_message_admin.css',
731
+            EE_MSG_ASSETS_URL.'ee_message_admin.css',
732 732
             [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
733 733
             EVENT_ESPRESSO_VERSION
734 734
         );
735 735
         wp_enqueue_style(
736 736
             'ee_message_shortcodes',
737
-            EE_MSG_ASSETS_URL . 'ee_message_shortcodes.css',
737
+            EE_MSG_ASSETS_URL.'ee_message_shortcodes.css',
738 738
             [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
739 739
             EVENT_ESPRESSO_VERSION
740 740
         );
741 741
 
742 742
         wp_register_script(
743 743
             'ee-messages-settings',
744
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
744
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
745 745
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
746 746
             EVENT_ESPRESSO_VERSION,
747 747
             true
748 748
         );
749 749
         wp_register_script(
750 750
             'ee-msg-list-table-js',
751
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
751
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
752 752
             ['ee-dialog'],
753 753
             EVENT_ESPRESSO_VERSION
754 754
         );
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
     {
791 791
         $this->_set_shortcodes();
792 792
 
793
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
793
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
794 794
             esc_html__(
795 795
                 '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.',
796 796
                 'event_espresso'
@@ -802,14 +802,14 @@  discard block
 block discarded – undo
802 802
             '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?',
803 803
             'event_espresso'
804 804
         );
805
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
805
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
806 806
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
807 807
             'event_espresso'
808 808
         );
809 809
 
810 810
         wp_register_script(
811 811
             'ee_msgs_edit_js',
812
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
812
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
813 813
             ['jquery'],
814 814
             EVENT_ESPRESSO_VERSION
815 815
         );
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
     {
853 853
         wp_register_style(
854 854
             'ee-message-settings',
855
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
855
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
856 856
             [],
857 857
             EVENT_ESPRESSO_VERSION
858 858
         );
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
             }
939 939
             $status_bulk_actions = $common_bulk_actions;
940 940
             // unset bulk actions not applying to status
941
-            if (! empty($status_bulk_actions)) {
941
+            if ( ! empty($status_bulk_actions)) {
942 942
                 switch ($status) {
943 943
                     case EEM_Message::status_idle:
944 944
                     case EEM_Message::status_resend:
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
                 continue;
968 968
             }
969 969
 
970
-            $this->_views[ strtolower($status) ] = [
970
+            $this->_views[strtolower($status)] = [
971 971
                 'slug'        => strtolower($status),
972 972
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
973 973
                 'count'       => 0,
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
             if ($action_item === 'see_notifications_for') {
1015 1015
                 continue;
1016 1016
             }
1017
-            $action_items[ $action_item ] = [
1017
+            $action_items[$action_item] = [
1018 1018
                 'class' => $action_details['css_class'],
1019 1019
                 'desc'  => $action_details['label'],
1020 1020
             ];
@@ -1023,37 +1023,37 @@  discard block
 block discarded – undo
1023 1023
         /** @var array $status_items status legend setup */
1024 1024
         $status_items = [
1025 1025
             'sent_status'                => [
1026
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1026
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_sent,
1027 1027
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1028 1028
             ],
1029 1029
             'idle_status'                => [
1030
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1030
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_idle,
1031 1031
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1032 1032
             ],
1033 1033
             'failed_status'              => [
1034
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1034
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_failed,
1035 1035
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1036 1036
             ],
1037 1037
             'messenger_executing_status' => [
1038
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1038
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_messenger_executing,
1039 1039
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1040 1040
             ],
1041 1041
             'resend_status'              => [
1042
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1042
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_resend,
1043 1043
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1044 1044
             ],
1045 1045
             'incomplete_status'          => [
1046
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1046
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_incomplete,
1047 1047
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1048 1048
             ],
1049 1049
             'retry_status'               => [
1050
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1050
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_retry,
1051 1051
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1052 1052
             ],
1053 1053
         ];
1054 1054
         if (EEM_Message::debug()) {
1055 1055
             $status_items['debug_only_status'] = [
1056
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1056
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_debug_only,
1057 1057
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1058 1058
             ];
1059 1059
         }
@@ -1068,11 +1068,11 @@  discard block
 block discarded – undo
1068 1068
     protected function _custom_mtps_preview()
1069 1069
     {
1070 1070
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1071
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1072
-                                                . ' alt="' . esc_attr__(
1071
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1072
+                                                . ' alt="'.esc_attr__(
1073 1073
                                                     'Preview Custom Message Templates screenshot',
1074 1074
                                                     'event_espresso'
1075
-                                                ) . '" />';
1075
+                                                ).'" />';
1076 1076
         $this->_template_args['preview_text'] = '<strong>'
1077 1077
                                                 . esc_html__(
1078 1078
                                                     '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.',
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
         $installed               = [];
1149 1149
 
1150 1150
         foreach ($installed_message_types as $message_type) {
1151
-            $installed[ $message_type->name ] = $message_type;
1151
+            $installed[$message_type->name] = $message_type;
1152 1152
         }
1153 1153
 
1154 1154
         return $installed;
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
         // we need to assemble the title from Various details
1245 1245
         $context_label = sprintf(
1246 1246
             esc_html__('(%s %s)', 'event_espresso'),
1247
-            $c_config[ $context ]['label'],
1247
+            $c_config[$context]['label'],
1248 1248
             ucwords($c_label['label'])
1249 1249
         );
1250 1250
 
@@ -1266,7 +1266,7 @@  discard block
 block discarded – undo
1266 1266
             $message_template_group->message_type()
1267 1267
         );
1268 1268
 
1269
-        if (! $template_field_structure) {
1269
+        if ( ! $template_field_structure) {
1270 1270
             $template_field_structure = false;
1271 1271
             $template_fields          = esc_html__(
1272 1272
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1278,21 +1278,21 @@  discard block
 block discarded – undo
1278 1278
 
1279 1279
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1280 1280
         // will get handled in the "extra" array.
1281
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1282
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1283
-                unset($template_field_structure[ $context ][ $reference_field ]);
1281
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1282
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1283
+                unset($template_field_structure[$context][$reference_field]);
1284 1284
             }
1285 1285
         }
1286 1286
 
1287 1287
         // let's loop through the template_field_structure and actually assemble the input fields!
1288
-        if (! empty($template_field_structure)) {
1289
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1288
+        if ( ! empty($template_field_structure)) {
1289
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1290 1290
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1291 1291
                 // the extra array and reset them.
1292 1292
                 if ($template_field === 'extra') {
1293 1293
                     $this->_template_args['is_extra_fields'] = true;
1294 1294
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1295
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1295
+                        $message_template = $message_templates[$context][$reference_field];
1296 1296
                         $content          = $message_template instanceof EE_Message_Template
1297 1297
                             ? $message_template->get('MTP_content')
1298 1298
                             : '';
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
                             $continue = false;
1302 1302
                             if (isset($extra_array['shortcodes_required'])) {
1303 1303
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1304
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1304
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1305 1305
                                         $continue = true;
1306 1306
                                     }
1307 1307
                                 }
@@ -1310,51 +1310,51 @@  discard block
 block discarded – undo
1310 1310
                                 }
1311 1311
                             }
1312 1312
 
1313
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1313
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1314 1314
 
1315
-                            $template_form_fields[ $field_id ]         = $extra_array;
1316
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1315
+                            $template_form_fields[$field_id]         = $extra_array;
1316
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1317 1317
                                                                          . $reference_field
1318 1318
                                                                          . '][content]['
1319
-                                                                         . $extra_field . ']';
1320
-                            $css_class                                 = $extra_array['css_class'] ?? '';
1319
+                                                                         . $extra_field.']';
1320
+                            $css_class = $extra_array['css_class'] ?? '';
1321 1321
 
1322
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1322
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1323 1323
                                                                               && in_array($extra_field, $v_fields, true)
1324 1324
                                                                               && (
1325
-                                                                                  is_array($validators[ $extra_field ])
1326
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1325
+                                                                                  is_array($validators[$extra_field])
1326
+                                                                                  && isset($validators[$extra_field]['msg'])
1327 1327
                                                                               )
1328
-                                ? 'validate-error ' . $css_class
1328
+                                ? 'validate-error '.$css_class
1329 1329
                                 : $css_class;
1330 1330
 
1331
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1332
-                                                                          && isset($content[ $extra_field ])
1333
-                                ? $content[ $extra_field ]
1331
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1332
+                                                                          && isset($content[$extra_field])
1333
+                                ? $content[$extra_field]
1334 1334
                                 : '';
1335 1335
 
1336 1336
                             // do we have a validation error?  if we do then let's use that value instead
1337
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1338
-                                ? $validators[ $extra_field ]['value']
1339
-                                : $template_form_fields[ $field_id ]['value'];
1337
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1338
+                                ? $validators[$extra_field]['value']
1339
+                                : $template_form_fields[$field_id]['value'];
1340 1340
 
1341 1341
 
1342
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1342
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1343 1343
 
1344 1344
                             // shortcode selector
1345 1345
                             $field_name_to_use                                   = $extra_field === 'main'
1346 1346
                                 ? 'content'
1347 1347
                                 : $extra_field;
1348
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1348
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1349 1349
                                 $field_name_to_use,
1350 1350
                                 $field_id
1351 1351
                             );
1352 1352
                         }
1353
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1354
-                        $template_field_template_name_id = $reference_field . '-name';
1353
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1354
+                        $template_field_template_name_id = $reference_field.'-name';
1355 1355
 
1356
-                        $template_form_fields[ $template_field_MTP_id ] = [
1357
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1356
+                        $template_form_fields[$template_field_MTP_id] = [
1357
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1358 1358
                             'label'      => null,
1359 1359
                             'input'      => 'hidden',
1360 1360
                             'type'       => 'int',
@@ -1366,8 +1366,8 @@  discard block
 block discarded – undo
1366 1366
                             'db-col'     => 'MTP_ID',
1367 1367
                         ];
1368 1368
 
1369
-                        $template_form_fields[ $template_field_template_name_id ] = [
1370
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1369
+                        $template_form_fields[$template_field_template_name_id] = [
1370
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1371 1371
                             'label'      => null,
1372 1372
                             'input'      => 'hidden',
1373 1373
                             'type'       => 'string',
@@ -1381,34 +1381,34 @@  discard block
 block discarded – undo
1381 1381
                     }
1382 1382
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1383 1383
                 } else {
1384
-                    $field_id                                   = $template_field . '-content';
1385
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1386
-                    $template_form_fields[ $field_id ]['name']  =
1387
-                        'MTP_template_fields[' . $template_field . '][content]';
1384
+                    $field_id                                   = $template_field.'-content';
1385
+                    $template_form_fields[$field_id]          = $field_setup_array;
1386
+                    $template_form_fields[$field_id]['name']  =
1387
+                        'MTP_template_fields['.$template_field.'][content]';
1388 1388
                     $message_template                           =
1389
-                        $message_templates[ $context ][ $template_field ] ?? null;
1390
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1391
-                                                                  && is_array($message_templates[ $context ])
1389
+                        $message_templates[$context][$template_field] ?? null;
1390
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1391
+                                                                  && is_array($message_templates[$context])
1392 1392
                                                                   && $message_template instanceof EE_Message_Template
1393 1393
                         ? $message_template->get('MTP_content')
1394 1394
                         : '';
1395 1395
 
1396 1396
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1397
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1398
-                        ? $validators[ $template_field ]['value']
1399
-                        : $template_form_fields[ $field_id ]['value'];
1397
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1398
+                        ? $validators[$template_field]['value']
1399
+                        : $template_form_fields[$field_id]['value'];
1400 1400
 
1401 1401
 
1402
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1402
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1403 1403
                     $css_class                                      = $field_setup_array['css_class'] ?? '';
1404
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1404
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1405 1405
                                                                       && in_array($template_field, $v_fields, true)
1406
-                                                                      && isset($validators[ $template_field ]['msg'])
1407
-                        ? 'validate-error ' . $css_class
1406
+                                                                      && isset($validators[$template_field]['msg'])
1407
+                        ? 'validate-error '.$css_class
1408 1408
                         : $css_class;
1409 1409
 
1410 1410
                     // shortcode selector
1411
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1411
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1412 1412
                         $template_field,
1413 1413
                         $field_id
1414 1414
                     );
@@ -1416,12 +1416,12 @@  discard block
 block discarded – undo
1416 1416
 
1417 1417
                 // k took care of content field(s) now let's take care of others.
1418 1418
 
1419
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1420
-                $template_field_field_template_name_id = $template_field . '-name';
1419
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1420
+                $template_field_field_template_name_id = $template_field.'-name';
1421 1421
 
1422 1422
                 // foreach template field there are actually two form fields created
1423
-                $template_form_fields[ $template_field_MTP_id ] = [
1424
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1423
+                $template_form_fields[$template_field_MTP_id] = [
1424
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1425 1425
                     'label'      => null,
1426 1426
                     'input'      => 'hidden',
1427 1427
                     'type'       => 'int',
@@ -1433,8 +1433,8 @@  discard block
 block discarded – undo
1433 1433
                     'db-col'     => 'MTP_ID',
1434 1434
                 ];
1435 1435
 
1436
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1437
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1436
+                $template_form_fields[$template_field_field_template_name_id] = [
1437
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1438 1438
                     'label'      => null,
1439 1439
                     'input'      => 'hidden',
1440 1440
                     'type'       => 'string',
@@ -1551,7 +1551,7 @@  discard block
 block discarded – undo
1551 1551
                 'format'     => '%d',
1552 1552
                 'db-col'     => 'MTP_deleted',
1553 1553
             ];
1554
-            $sidebar_form_fields['ee-msg-author']  = [
1554
+            $sidebar_form_fields['ee-msg-author'] = [
1555 1555
                 'name'       => 'MTP_user_id',
1556 1556
                 'label'      => esc_html__('Author', 'event_espresso'),
1557 1557
                 'input'      => 'hidden',
@@ -1570,17 +1570,17 @@  discard block
 block discarded – undo
1570 1570
                 'value' => $action,
1571 1571
             ];
1572 1572
 
1573
-            $sidebar_form_fields['ee-msg-id']        = [
1573
+            $sidebar_form_fields['ee-msg-id'] = [
1574 1574
                 'name'  => 'id',
1575 1575
                 'input' => 'hidden',
1576 1576
                 'type'  => 'int',
1577 1577
                 'value' => $GRP_ID,
1578 1578
             ];
1579 1579
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1580
-                'name'  => $action . '_nonce',
1580
+                'name'  => $action.'_nonce',
1581 1581
                 'input' => 'hidden',
1582 1582
                 'type'  => 'string',
1583
-                'value' => wp_create_nonce($action . '_nonce'),
1583
+                'value' => wp_create_nonce($action.'_nonce'),
1584 1584
             ];
1585 1585
 
1586 1586
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1612,7 +1612,7 @@  discard block
 block discarded – undo
1612 1612
         );
1613 1613
 
1614 1614
         // add preview button
1615
-        $preview_url    = parent::add_query_args_and_nonce(
1615
+        $preview_url = parent::add_query_args_and_nonce(
1616 1616
             [
1617 1617
                 'message_type' => $message_template_group->message_type(),
1618 1618
                 'messenger'    => $message_template_group->messenger(),
@@ -1623,7 +1623,7 @@  discard block
 block discarded – undo
1623 1623
             ],
1624 1624
             $this->_admin_base_url
1625 1625
         );
1626
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1626
+        $preview_button = '<a href="'.$preview_url.'" class="button--secondary messages-preview-button">'
1627 1627
                           . esc_html__('Preview', 'event_espresso')
1628 1628
                           . '</a>';
1629 1629
 
@@ -1659,11 +1659,11 @@  discard block
 block discarded – undo
1659 1659
         $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1660 1660
         $this->_template_args['before_admin_page_content'] .= '</div>';
1661 1661
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1662
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1662
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1663 1663
 
1664 1664
         $this->_template_path = $this->_template_args['GRP_ID']
1665 1665
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1666
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1666
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1667 1667
 
1668 1668
         // send along EE_Message_Template_Group object for further template use.
1669 1669
         $this->_template_args['MTP'] = $message_template_group;
@@ -1716,7 +1716,7 @@  discard block
 block discarded – undo
1716 1716
     ) {
1717 1717
         $template_args = [
1718 1718
             'context'                   => $context,
1719
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1719
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1720 1720
             'is_active'                 => $message_template_group->is_context_active($context),
1721 1721
             'on_off_action'             => $message_template_group->is_context_active($context)
1722 1722
                 ? 'context-off'
@@ -1725,7 +1725,7 @@  discard block
 block discarded – undo
1725 1725
             'message_template_group_id' => $message_template_group->ID(),
1726 1726
         ];
1727 1727
         return EEH_Template::display_template(
1728
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1728
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1729 1729
             $template_args,
1730 1730
             true
1731 1731
         );
@@ -1783,7 +1783,7 @@  discard block
 block discarded – undo
1783 1783
         }
1784 1784
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, DataType::INTEGER);
1785 1785
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1786
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1786
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1787 1787
             EE_Error::add_error(
1788 1788
                 sprintf(
1789 1789
                     esc_html__(
@@ -1913,7 +1913,7 @@  discard block
 block discarded – undo
1913 1913
         $messenger    = $this->request->getRequestParam('msgr');
1914 1914
         $message_type = $this->request->getRequestParam('mt');
1915 1915
         // we need to make sure we've got the info we need.
1916
-        if (! ($GRP_ID && $messenger && $message_type)) {
1916
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
1917 1917
             EE_Error::add_error(
1918 1918
                 esc_html__(
1919 1919
                     '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.',
@@ -1955,7 +1955,7 @@  discard block
 block discarded – undo
1955 1955
         }
1956 1956
 
1957 1957
         // any error messages?
1958
-        if (! $success) {
1958
+        if ( ! $success) {
1959 1959
             EE_Error::add_error(
1960 1960
                 esc_html__(
1961 1961
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2004,7 +2004,7 @@  discard block
 block discarded – undo
2004 2004
     {
2005 2005
         // first make sure we've got the necessary parameters
2006 2006
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, DataType::INTEGER);
2007
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2007
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2008 2008
             EE_Error::add_error(
2009 2009
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2010 2010
                 __FILE__,
@@ -2030,7 +2030,7 @@  discard block
 block discarded – undo
2030 2030
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, DataType::INTEGER);
2031 2031
 
2032 2032
         // let's add a button to go back to the edit view
2033
-        $query_args             = [
2033
+        $query_args = [
2034 2034
             'id'      => $GRP_ID,
2035 2035
             'evt_id'  => $EVT_ID,
2036 2036
             'context' => $context,
@@ -2051,7 +2051,7 @@  discard block
 block discarded – undo
2051 2051
         $preview_title = sprintf(
2052 2052
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2053 2053
             $active_messenger_label,
2054
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2054
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2055 2055
         );
2056 2056
         if (empty($preview)) {
2057 2057
             $this->noEventsErrorMessage();
@@ -2059,7 +2059,7 @@  discard block
 block discarded – undo
2059 2059
         // setup display of preview.
2060 2060
         $this->_admin_page_title                    = $preview_title;
2061 2061
         $this->_template_args['admin_page_title']   = $preview_title;
2062
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2062
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2063 2063
         $this->_template_args['data']['force_json'] = true;
2064 2064
 
2065 2065
         return '';
@@ -2080,7 +2080,7 @@  discard block
 block discarded – undo
2080 2080
             ],
2081 2081
             admin_url('admin.php')
2082 2082
         );
2083
-        $message    = $test_send
2083
+        $message = $test_send
2084 2084
             ? esc_html__(
2085 2085
                 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2086 2086
                 'event_espresso'
@@ -2172,10 +2172,10 @@  discard block
 block discarded – undo
2172 2172
             // only include template packs that support this messenger and message type!
2173 2173
             $supports = $tp->get_supports();
2174 2174
             if (
2175
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2175
+                ! isset($supports[$this->_message_template_group->messenger()])
2176 2176
                 || ! in_array(
2177 2177
                     $this->_message_template_group->message_type(),
2178
-                    $supports[ $this->_message_template_group->messenger() ],
2178
+                    $supports[$this->_message_template_group->messenger()],
2179 2179
                     true
2180 2180
                 )
2181 2181
             ) {
@@ -2199,7 +2199,7 @@  discard block
 block discarded – undo
2199 2199
         }
2200 2200
 
2201 2201
         // setup variation select values for the currently selected template.
2202
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2202
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2203 2203
             $this->_message_template_group->messenger(),
2204 2204
             $this->_message_template_group->message_type()
2205 2205
         );
@@ -2213,12 +2213,12 @@  discard block
 block discarded – undo
2213 2213
 
2214 2214
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2215 2215
 
2216
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2216
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2217 2217
             'MTP_template_pack',
2218 2218
             $tp_select_values,
2219 2219
             $this->_message_template_group->get_template_pack_name()
2220 2220
         );
2221
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2221
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2222 2222
             'MTP_template_variation',
2223 2223
             $variations_select_values,
2224 2224
             $this->_message_template_group->get_template_pack_variation()
@@ -2228,7 +2228,7 @@  discard block
 block discarded – undo
2228 2228
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2229 2229
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2230 2230
 
2231
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2231
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2232 2232
 
2233 2233
         EEH_Template::display_template($template, $template_args);
2234 2234
     }
@@ -2254,33 +2254,33 @@  discard block
 block discarded – undo
2254 2254
         // first we need to see if there are any fields
2255 2255
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2256 2256
 
2257
-        if (! empty($fields)) {
2257
+        if ( ! empty($fields)) {
2258 2258
             // yup there be fields
2259 2259
             foreach ($fields as $field => $config) {
2260
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2260
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2261 2261
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2262 2262
                 $default  = $config['default'] ?? '';
2263 2263
                 $default  = $config['value'] ?? $default;
2264 2264
 
2265 2265
                 // if type is hidden and the value is empty
2266 2266
                 // something may have gone wrong so let's correct with the defaults
2267
-                $fix                = $config['input'] === 'hidden'
2268
-                                      && isset($existing[ $field ])
2269
-                                      && empty($existing[ $field ])
2267
+                $fix = $config['input'] === 'hidden'
2268
+                                      && isset($existing[$field])
2269
+                                      && empty($existing[$field])
2270 2270
                     ? $default
2271 2271
                     : '';
2272
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2273
-                    ? $existing[ $field ]
2272
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2273
+                    ? $existing[$field]
2274 2274
                     : $fix;
2275 2275
 
2276
-                $template_form_fields[ $field_id ] = [
2277
-                    'name'       => 'test_settings_fld[' . $field . ']',
2276
+                $template_form_fields[$field_id] = [
2277
+                    'name'       => 'test_settings_fld['.$field.']',
2278 2278
                     'label'      => $config['label'],
2279 2279
                     'input'      => $config['input'],
2280 2280
                     'type'       => $config['type'],
2281 2281
                     'required'   => $config['required'],
2282 2282
                     'validation' => $config['validation'],
2283
-                    'value'      => $existing[ $field ] ?? $default,
2283
+                    'value'      => $existing[$field] ?? $default,
2284 2284
                     'css_class'  => $config['css_class'],
2285 2285
                     'options'    => $config['options'] ?? [],
2286 2286
                     'default'    => $default,
@@ -2294,7 +2294,7 @@  discard block
 block discarded – undo
2294 2294
             : '';
2295 2295
 
2296 2296
         // print out $test_settings_fields
2297
-        if (! empty($test_settings_html)) {
2297
+        if ( ! empty($test_settings_html)) {
2298 2298
             $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2299 2299
             $test_settings_html .= 'name="test_button" value="';
2300 2300
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2340,7 +2340,7 @@  discard block
 block discarded – undo
2340 2340
         ];
2341 2341
 
2342 2342
         return EEH_Template::display_template(
2343
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2343
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2344 2344
             $template_args,
2345 2345
             true
2346 2346
         );
@@ -2366,7 +2366,7 @@  discard block
 block discarded – undo
2366 2366
         // $messenger = $this->_message_template_group->messenger_obj();
2367 2367
         // now let's set the content depending on the status of the shortcodes array
2368 2368
         if (empty($shortcodes)) {
2369
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2369
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2370 2370
             return;
2371 2371
         }
2372 2372
         ?>
@@ -2401,7 +2401,7 @@  discard block
 block discarded – undo
2401 2401
     protected function _set_shortcodes()
2402 2402
     {
2403 2403
         // no need to run this if the property is already set
2404
-        if (! empty($this->_shortcodes)) {
2404
+        if ( ! empty($this->_shortcodes)) {
2405 2405
             return;
2406 2406
         }
2407 2407
 
@@ -2456,7 +2456,7 @@  discard block
 block discarded – undo
2456 2456
     protected function _set_message_template_group()
2457 2457
     {
2458 2458
         // get out if this is already set.
2459
-        if (! empty($this->_message_template_group)) {
2459
+        if ( ! empty($this->_message_template_group)) {
2460 2460
             return;
2461 2461
         }
2462 2462
 
@@ -2502,8 +2502,8 @@  discard block
 block discarded – undo
2502 2502
                     <?php
2503 2503
                 }
2504 2504
                 // setup nonce_url
2505
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2506
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2505
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2506
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2507 2507
                 ?>
2508 2508
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2509 2509
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2516,7 +2516,7 @@  discard block
 block discarded – undo
2516 2516
                             $checked = ($context === $args['context']) ? 'selected' : '';
2517 2517
                             ?>
2518 2518
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2519
-                                <?php echo esc_html($context_details[ $context ]['label']); ?>
2519
+                                <?php echo esc_html($context_details[$context]['label']); ?>
2520 2520
                             </option>
2521 2521
                         <?php endforeach;
2522 2522
                     endif; ?>
@@ -2636,7 +2636,7 @@  discard block
 block discarded – undo
2636 2636
 
2637 2637
         $context   = ucwords(str_replace('_', ' ', $context));
2638 2638
         $item_desc = $messenger_label && $message_type_label
2639
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2639
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
2640 2640
             : '';
2641 2641
         $item_desc .= 'Message Template';
2642 2642
         return $item_desc;
@@ -2754,7 +2754,7 @@  discard block
 block discarded – undo
2754 2754
         if ($all) {
2755 2755
             // Checkboxes
2756 2756
             $checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2757
-            if (! empty($checkboxes)) {
2757
+            if ( ! empty($checkboxes)) {
2758 2758
                 // if array has more than one element then success message should be plural.
2759 2759
                 // todo: what about nonce?
2760 2760
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -2764,18 +2764,18 @@  discard block
 block discarded – undo
2764 2764
                     $trashed_or_restored = $trash
2765 2765
                         ? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2766 2766
                         : $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2767
-                    if (! $trashed_or_restored) {
2767
+                    if ( ! $trashed_or_restored) {
2768 2768
                         $success = 0;
2769 2769
                     }
2770 2770
                 }
2771 2771
             } else {
2772 2772
                 // grab single GRP_ID and handle
2773 2773
                 $GRP_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
2774
-                if (! empty($GRP_ID)) {
2774
+                if ( ! empty($GRP_ID)) {
2775 2775
                     $trashed_or_restored = $trash
2776 2776
                         ? $this->getMessageTemplateManager()->trashMessageTemplate($GRP_ID)
2777 2777
                         : $this->getMessageTemplateManager()->restoreMessageTemplate($GRP_ID);
2778
-                    if (! $trashed_or_restored) {
2778
+                    if ( ! $trashed_or_restored) {
2779 2779
                         $success = 0;
2780 2780
                     }
2781 2781
                 } else {
@@ -2828,7 +2828,7 @@  discard block
 block discarded – undo
2828 2828
     {
2829 2829
         // checkboxes
2830 2830
         $checkboxes = $this->request->getRequestParam('checkbox', [], DataType::INTEGER, true);
2831
-        if (! empty($checkboxes)) {
2831
+        if ( ! empty($checkboxes)) {
2832 2832
             // if array has more than one element then success message should be plural
2833 2833
             $success = count($checkboxes) > 1 ? 2 : 1;
2834 2834
 
@@ -2904,7 +2904,7 @@  discard block
 block discarded – undo
2904 2904
     protected function _set_m_mt_settings()
2905 2905
     {
2906 2906
         // first if this is already set then lets get out no need to regenerate data.
2907
-        if (! empty($this->_m_mt_settings)) {
2907
+        if ( ! empty($this->_m_mt_settings)) {
2908 2908
             return;
2909 2909
         }
2910 2910
 
@@ -2919,8 +2919,8 @@  discard block
 block discarded – undo
2919 2919
             $active                                                     =
2920 2920
                 $this->_message_resource_manager->is_messenger_active($messenger->name);
2921 2921
             $class                                                      =
2922
-                'ee-messenger-' . sanitize_key($messenger->label['singular']);
2923
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
2922
+                'ee-messenger-'.sanitize_key($messenger->label['singular']);
2923
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
2924 2924
                 'label' => ucwords($messenger->label['singular']),
2925 2925
                 'class' => $active ? "{$class} messenger-active" : $class,
2926 2926
                 'href'  => $messenger->name,
@@ -2938,7 +2938,7 @@  discard block
 block discarded – undo
2938 2938
             foreach ($message_types as $message_type) {
2939 2939
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
2940 2940
                 // it shouldn't show in either the inactive OR active metabox.
2941
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
2941
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
2942 2942
                     continue;
2943 2943
                 }
2944 2944
 
@@ -2949,12 +2949,12 @@  discard block
 block discarded – undo
2949 2949
                     ? 'active'
2950 2950
                     : 'inactive';
2951 2951
 
2952
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
2952
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
2953 2953
                     'label'    => ucwords($message_type->label['singular']),
2954
-                    'class'    => 'message-type-' . $a_or_i,
2955
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2956
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2957
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2954
+                    'class'    => 'message-type-'.$a_or_i,
2955
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
2956
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
2957
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
2958 2958
                     'title'    => $a_or_i === 'active'
2959 2959
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2960 2960
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -2985,20 +2985,20 @@  discard block
 block discarded – undo
2985 2985
         $fields                                         = $message_type->get_admin_settings_fields();
2986 2986
         $settings_template_args['template_form_fields'] = '';
2987 2987
 
2988
-        if (! empty($fields) && $active) {
2988
+        if ( ! empty($fields) && $active) {
2989 2989
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2990 2990
             foreach ($fields as $fldname => $fldprops) {
2991
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2992
-                $template_form_field[ $field_id ] = [
2993
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2991
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
2992
+                $template_form_field[$field_id] = [
2993
+                    'name'       => 'message_type_settings['.$fldname.']',
2994 2994
                     'label'      => $fldprops['label'],
2995 2995
                     'input'      => $fldprops['field_type'],
2996 2996
                     'type'       => $fldprops['value_type'],
2997 2997
                     'required'   => $fldprops['required'],
2998 2998
                     'validation' => $fldprops['validation'],
2999
-                    'value'      => $existing_settings[ $fldname ] ?? $fldprops['default'],
2999
+                    'value'      => $existing_settings[$fldname] ?? $fldprops['default'],
3000 3000
                     'options'    => $fldprops['options'] ?? [],
3001
-                    'default'    => $existing_settings[ $fldname ] ?? $fldprops['default'],
3001
+                    'default'    => $existing_settings[$fldname] ?? $fldprops['default'],
3002 3002
                     'css_class'  => 'no-drag',
3003 3003
                     'format'     => $fldprops['format'],
3004 3004
                 ];
@@ -3017,15 +3017,15 @@  discard block
 block discarded – undo
3017 3017
         $settings_template_args['description'] = $message_type->description;
3018 3018
         // we also need some hidden fields
3019 3019
         $hidden_fields = [
3020
-            'message_type_settings[messenger]' . $message_type->name    => [
3020
+            'message_type_settings[messenger]'.$message_type->name    => [
3021 3021
                 'type'  => 'hidden',
3022 3022
                 'value' => $messenger->name,
3023 3023
             ],
3024
-            'message_type_settings[message_type]' . $message_type->name => [
3024
+            'message_type_settings[message_type]'.$message_type->name => [
3025 3025
                 'type'  => 'hidden',
3026 3026
                 'value' => $message_type->name,
3027 3027
             ],
3028
-            'type' . $message_type->name                                => [
3028
+            'type'.$message_type->name                                => [
3029 3029
                 'type'  => 'hidden',
3030 3030
                 'value' => 'message_type',
3031 3031
             ],
@@ -3035,12 +3035,12 @@  discard block
 block discarded – undo
3035 3035
             $hidden_fields,
3036 3036
             'array'
3037 3037
         );
3038
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3038
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3039 3039
             ? ' hidden'
3040 3040
             : '';
3041 3041
 
3042 3042
 
3043
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3043
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3044 3044
         return EEH_Template::display_template($template, $settings_template_args, true);
3045 3045
     }
3046 3046
 
@@ -3068,19 +3068,19 @@  discard block
 block discarded – undo
3068 3068
 
3069 3069
                 // messenger meta boxes
3070 3070
                 $active         = $selected_messenger === $messenger;
3071
-                $active_mt_tabs = $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] ?? '';
3071
+                $active_mt_tabs = $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] ?? '';
3072 3072
 
3073
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3073
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3074 3074
                     esc_html__('%s Settings', 'event_espresso'),
3075 3075
                     $tab_array['label']
3076 3076
                 );
3077 3077
 
3078
-                $m_template_args[ $messenger . '_a_box' ] = [
3078
+                $m_template_args[$messenger.'_a_box'] = [
3079 3079
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3080 3080
                     'inactive_message_types' => isset(
3081
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3081
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3082 3082
                     )
3083
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3083
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3084 3084
                         : '',
3085 3085
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3086 3086
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3092,13 +3092,13 @@  discard block
 block discarded – undo
3092 3092
                 // message type meta boxes
3093 3093
                 // (which is really just the inactive container for each messenger
3094 3094
                 // showing inactive message types for that messenger)
3095
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3096
-                $mt_template_args[ $messenger . '_i_box' ] = [
3095
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3096
+                $mt_template_args[$messenger.'_i_box'] = [
3097 3097
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3098 3098
                     'inactive_message_types' => isset(
3099
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3099
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3100 3100
                     )
3101
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3101
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3102 3102
                         : '',
3103 3103
                     'hidden'                 => $active ? '' : ' hidden',
3104 3104
                     'hide_on_message'        => $hide_on_message,
@@ -3111,14 +3111,14 @@  discard block
 block discarded – undo
3111 3111
 
3112 3112
 
3113 3113
         // register messenger metaboxes
3114
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3114
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3115 3115
         foreach ($m_boxes as $box => $label) {
3116
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3116
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3117 3117
             $msgr          = str_replace('_a_box', '', $box);
3118 3118
             $this->addMetaBox(
3119
-                'espresso_' . $msgr . '_settings',
3119
+                'espresso_'.$msgr.'_settings',
3120 3120
                 $label,
3121
-                function ($post, $metabox) {
3121
+                function($post, $metabox) {
3122 3122
                     EEH_Template::display_template(
3123 3123
                         $metabox['args']['template_path'],
3124 3124
                         $metabox['args']['template_args']
@@ -3132,17 +3132,17 @@  discard block
 block discarded – undo
3132 3132
         }
3133 3133
 
3134 3134
         // register message type metaboxes
3135
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3135
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3136 3136
         foreach ($mt_boxes as $box => $label) {
3137 3137
             $callback_args = [
3138 3138
                 'template_path' => $mt_template_path,
3139
-                'template_args' => $mt_template_args[ $box ],
3139
+                'template_args' => $mt_template_args[$box],
3140 3140
             ];
3141
-            $mt            = str_replace('_i_box', '', $box);
3141
+            $mt = str_replace('_i_box', '', $box);
3142 3142
             $this->addMetaBox(
3143
-                'espresso_' . $mt . '_inactive_mts',
3143
+                'espresso_'.$mt.'_inactive_mts',
3144 3144
                 $label,
3145
-                function ($post, $metabox) {
3145
+                function($post, $metabox) {
3146 3146
                     EEH_Template::display_template(
3147 3147
                         $metabox['args']['template_path'],
3148 3148
                         $metabox['args']['template_args']
@@ -3290,7 +3290,7 @@  discard block
 block discarded – undo
3290 3290
                 $valid_data = $form->valid_data();
3291 3291
                 // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
3292 3292
                 foreach ($valid_data as $property => $value) {
3293
-                    $setter = 'set_' . $property;
3293
+                    $setter = 'set_'.$property;
3294 3294
                     if (method_exists($network_config, $setter)) {
3295 3295
                         $network_config->{$setter}($value);
3296 3296
                     } elseif (
@@ -3326,7 +3326,7 @@  discard block
 block discarded – undo
3326 3326
     protected function _get_mt_tabs($tab_array)
3327 3327
     {
3328 3328
         $tab_array = (array) $tab_array;
3329
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3329
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3330 3330
         $tabs      = '';
3331 3331
 
3332 3332
         foreach ($tab_array as $tab) {
@@ -3353,19 +3353,19 @@  discard block
 block discarded – undo
3353 3353
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3354 3354
 
3355 3355
 
3356
-        if (! empty($fields)) {
3356
+        if ( ! empty($fields)) {
3357 3357
             $existing_settings = $messenger->get_existing_admin_settings();
3358 3358
 
3359 3359
             foreach ($fields as $field_name => $field_props) {
3360
-                $field_id                         = $messenger->name . '-' . $field_name;
3361
-                $template_form_field[ $field_id ] = [
3362
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3360
+                $field_id                         = $messenger->name.'-'.$field_name;
3361
+                $template_form_field[$field_id] = [
3362
+                    'name'       => 'messenger_settings['.$field_id.']',
3363 3363
                     'label'      => $field_props['label'],
3364 3364
                     'input'      => $field_props['field_type'],
3365 3365
                     'type'       => $field_props['value_type'],
3366 3366
                     'required'   => $field_props['required'],
3367 3367
                     'validation' => $field_props['validation'],
3368
-                    'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3368
+                    'value'      => $existing_settings[$field_id] ?? $field_props['default'],
3369 3369
                     'css_class'  => '',
3370 3370
                     'format'     => $field_props['format'],
3371 3371
                 ];
@@ -3378,20 +3378,20 @@  discard block
 block discarded – undo
3378 3378
 
3379 3379
         // we also need some hidden fields
3380 3380
         $settings_template_args['hidden_fields'] = [
3381
-            'messenger_settings[messenger]' . $messenger->name => [
3381
+            'messenger_settings[messenger]'.$messenger->name => [
3382 3382
                 'type'  => 'hidden',
3383 3383
                 'value' => $messenger->name,
3384 3384
             ],
3385
-            'type' . $messenger->name                          => [
3385
+            'type'.$messenger->name                          => [
3386 3386
                 'type'  => 'hidden',
3387 3387
                 'value' => 'messenger',
3388 3388
             ],
3389 3389
         ];
3390 3390
 
3391 3391
         // make sure any active message types that are existing are included in the hidden fields
3392
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3393
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3394
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3392
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3393
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3394
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3395 3395
                     'type'  => 'hidden',
3396 3396
                     'value' => $mt,
3397 3397
                 ];
@@ -3401,7 +3401,7 @@  discard block
 block discarded – undo
3401 3401
             $settings_template_args['hidden_fields'],
3402 3402
             'array'
3403 3403
         );
3404
-        $active                                  =
3404
+        $active =
3405 3405
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3406 3406
 
3407 3407
         $settings_template_args['messenger']           = $messenger->name;
@@ -3421,9 +3421,9 @@  discard block
 block discarded – undo
3421 3421
 
3422 3422
 
3423 3423
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3424
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3424
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3425 3425
         $settings_template_args['on_off_status'] = $active;
3426
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3426
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3427 3427
         return EEH_Template::display_template(
3428 3428
             $template,
3429 3429
             $settings_template_args,
@@ -3448,7 +3448,7 @@  discard block
 block discarded – undo
3448 3448
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3449 3449
         // let's check that we have required data
3450 3450
 
3451
-        if (! $this->_active_messenger_name) {
3451
+        if ( ! $this->_active_messenger_name) {
3452 3452
             EE_Error::add_error(
3453 3453
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3454 3454
                 __FILE__,
@@ -3466,7 +3466,7 @@  discard block
 block discarded – undo
3466 3466
 
3467 3467
 
3468 3468
         $status = $this->request->getRequestParam('status');
3469
-        if (! $status) {
3469
+        if ( ! $status) {
3470 3470
             EE_Error::add_error(
3471 3471
                 esc_html__(
3472 3472
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3523,7 +3523,7 @@  discard block
 block discarded – undo
3523 3523
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3524 3524
 
3525 3525
         // let's make sure we have the necessary data
3526
-        if (! $this->_active_message_type_name) {
3526
+        if ( ! $this->_active_message_type_name) {
3527 3527
             EE_Error::add_error(
3528 3528
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3529 3529
                 __FILE__,
@@ -3533,7 +3533,7 @@  discard block
 block discarded – undo
3533 3533
             $success = false;
3534 3534
         }
3535 3535
 
3536
-        if (! $this->_active_messenger_name) {
3536
+        if ( ! $this->_active_messenger_name) {
3537 3537
             EE_Error::add_error(
3538 3538
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3539 3539
                 __FILE__,
@@ -3544,7 +3544,7 @@  discard block
 block discarded – undo
3544 3544
         }
3545 3545
 
3546 3546
         $status = $this->request->getRequestParam('status');
3547
-        if (! $status) {
3547
+        if ( ! $status) {
3548 3548
             EE_Error::add_error(
3549 3549
                 esc_html__(
3550 3550
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3756,7 +3756,7 @@  discard block
 block discarded – undo
3756 3756
         EE_Message_Type $message_type = null
3757 3757
     ) {
3758 3758
         // if $messenger isn't a valid messenger object then get out.
3759
-        if (! $messenger instanceof EE_Messenger) {
3759
+        if ( ! $messenger instanceof EE_Messenger) {
3760 3760
             EE_Error::add_error(
3761 3761
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
3762 3762
                 __FILE__,
@@ -3810,7 +3810,7 @@  discard block
 block discarded – undo
3810 3810
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3811 3811
             // in which case we just give a success message for the messenger being successfully activated.
3812 3812
         } else {
3813
-            if (! $messenger->get_default_message_types()) {
3813
+            if ( ! $messenger->get_default_message_types()) {
3814 3814
                 // messenger doesn't have any default message types so still a success.
3815 3815
                 EE_Error::add_success(
3816 3816
                     sprintf(
@@ -3866,7 +3866,7 @@  discard block
 block discarded – undo
3866 3866
         EE_Error::overwrite_success();
3867 3867
 
3868 3868
         // if $messenger isn't a valid messenger object then get out.
3869
-        if (! $messenger instanceof EE_Messenger) {
3869
+        if ( ! $messenger instanceof EE_Messenger) {
3870 3870
             EE_Error::add_error(
3871 3871
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3872 3872
                 __FILE__,
@@ -3936,7 +3936,7 @@  discard block
 block discarded – undo
3936 3936
      */
3937 3937
     public function update_mt_form()
3938 3938
     {
3939
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
3939
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
3940 3940
             EE_Error::add_error(
3941 3941
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
3942 3942
                 __FILE__,
@@ -3947,7 +3947,7 @@  discard block
 block discarded – undo
3947 3947
         }
3948 3948
 
3949 3949
         $message_types = $this->get_installed_message_types();
3950
-        $message_type  = $message_types[ $this->_active_message_type_name ];
3950
+        $message_type  = $message_types[$this->_active_message_type_name];
3951 3951
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
3952 3952
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
3953 3953
 
@@ -3966,7 +3966,7 @@  discard block
 block discarded – undo
3966 3966
     public function save_settings()
3967 3967
     {
3968 3968
         $type = $this->request->getRequestParam('type');
3969
-        if (! $type) {
3969
+        if ( ! $type) {
3970 3970
             EE_Error::add_error(
3971 3971
                 esc_html__(
3972 3972
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.
core/domain/services/wp_queries/EventListQuery.php 1 patch
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -16,198 +16,198 @@
 block discarded – undo
16 16
  */
17 17
 class EventListQuery extends WP_Query
18 18
 {
19
-    /**
20
-     * @var string $title
21
-     */
22
-    private $title;
23
-
24
-    /**
25
-     * @var integer $limit
26
-     */
27
-    private $limit = 10;
28
-
29
-    /**
30
-     * @var string $css_class
31
-     */
32
-    private $css_class;
33
-
34
-    /**
35
-     * @var boolean $show_expired
36
-     */
37
-    private $show_expired = false;
38
-
39
-    /**
40
-     * @var string $month
41
-     */
42
-    private $month;
43
-
44
-    /**
45
-     * @var string $category_slug
46
-     */
47
-    private $category_slug;
48
-
49
-    /**
50
-     * @var string $order_by
51
-     */
52
-    private $order_by;
53
-
54
-    /**
55
-     * @var string $sort
56
-     */
57
-    private $sort;
58
-
59
-    /**
60
-     * @var boolean $show_title
61
-     */
62
-    private $show_title = true;
63
-
64
-
65
-    /**
66
-     * EE_Event_List_Query Constructor     *
67
-     *
68
-     * @param array $args
69
-     */
70
-    public function __construct($args = array())
71
-    {
72
-        $args = $this->parseArgs((array) $args);
73
-        $this->setupEventQueryHelper();
74
-        $this->setupFilters();
75
-        $args = $this->getQueryArgs($args);
76
-        // run the query
77
-        parent::__construct($args);
78
-    }
79
-
80
-
81
-    /**
82
-     * @param array $args
83
-     * @return array
84
-     */
85
-    private function parseArgs(array $args)
86
-    {
87
-        // incoming args could be a mix of WP query args + EE shortcode args
88
-        foreach ($args as $property => $value) {
89
-            // if the arg is a property of this class, then it's an EE shortcode arg
90
-            if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) {
91
-                // set the property value
92
-                $this->{$property} = $value;
93
-                // then remove it from the array of args that will later be passed to WP_Query()
94
-                unset($args[ $property ]);
95
-            }
96
-        }
97
-        return $args;
98
-    }
99
-
100
-
101
-    private function setupEventQueryHelper()
102
-    {
103
-        // add query filters
104
-        EEH_Event_Query::add_query_filters();
105
-        // set params that will get used by the filters
106
-        EEH_Event_Query::set_query_params(
107
-            $this->month,
108
-            $this->category_slug,
109
-            $this->show_expired,
110
-            $this->order_by,
111
-            $this->sort
112
-        );
113
-    }
114
-
115
-
116
-    private function setupFilters()
117
-    {
118
-        // first off, let's remove any filters from previous queries
119
-        remove_filter(
120
-            'FHEE__archive_espresso_events_template__show_header',
121
-            array($this, 'show_event_list_title')
122
-        );
123
-        remove_filter(
124
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
125
-            array($this, 'event_list_title')
126
-        );
127
-        remove_all_filters('FHEE__content_espresso_events__event_class');
128
-        // Event List Title ?
129
-        add_filter(
130
-            'FHEE__archive_espresso_events_template__show_header',
131
-            array($this, 'show_event_list_title')
132
-        );
133
-        add_filter(
134
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
135
-            array($this, 'event_list_title'),
136
-            10,
137
-            1
138
-        );
139
-        // add the css class
140
-        add_filter(
141
-            'FHEE__content_espresso_events__event_class',
142
-            array($this, 'event_list_css'),
143
-            10,
144
-            1
145
-        );
146
-    }
147
-
148
-
149
-    private function getQueryArgs(array $args)
150
-    {
151
-        // the current "page" we are viewing
152
-        $paged = max(1, get_query_var('paged'));
153
-        // Force these args
154
-        return array_merge(
155
-            $args,
156
-            array(
157
-                'post_type'              => EspressoPostType::EVENTS,
158
-                'posts_per_page'         => $this->limit,
159
-                'update_post_term_cache' => false,
160
-                'update_post_meta_cache' => false,
161
-                'paged'                  => $paged,
162
-                'offset'                 => ($paged - 1) * $this->limit,
163
-            )
164
-        );
165
-    }
166
-
167
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
168
-
169
-    /**
170
-     * show_event_list_title
171
-     *
172
-     * @return boolean
173
-     */
174
-    public function show_event_list_title()
175
-    {
176
-        return filter_var(
177
-            $this->show_title,
178
-            FILTER_VALIDATE_BOOLEAN
179
-        );
180
-    }
181
-
182
-
183
-    /**
184
-     * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter
185
-     *
186
-     * @param string $event_list_title
187
-     * @return    string
188
-     */
189
-    public function event_list_title($event_list_title = '')
190
-    {
191
-        if (! empty($this->title)) {
192
-            return $this->title;
193
-        }
194
-        return $event_list_title;
195
-    }
196
-
197
-
198
-    /**
199
-     * callback for FHEE__content_espresso_events__event_class filter
200
-     *
201
-     * @param string $event_list_css
202
-     * @return string
203
-     */
204
-    public function event_list_css($event_list_css = '')
205
-    {
206
-        $event_list_css .= ! empty($event_list_css) ? ' ' : '';
207
-        $event_list_css .= ! empty($this->css_class) ? $this->css_class : '';
208
-        $event_list_css .= ! empty($event_list_css) ? ' ' : '';
209
-        $event_list_css .= ! empty($this->category_slug) ? $this->category_slug : '';
210
-        return $event_list_css;
211
-    }
212
-    // phpcs:enable
19
+	/**
20
+	 * @var string $title
21
+	 */
22
+	private $title;
23
+
24
+	/**
25
+	 * @var integer $limit
26
+	 */
27
+	private $limit = 10;
28
+
29
+	/**
30
+	 * @var string $css_class
31
+	 */
32
+	private $css_class;
33
+
34
+	/**
35
+	 * @var boolean $show_expired
36
+	 */
37
+	private $show_expired = false;
38
+
39
+	/**
40
+	 * @var string $month
41
+	 */
42
+	private $month;
43
+
44
+	/**
45
+	 * @var string $category_slug
46
+	 */
47
+	private $category_slug;
48
+
49
+	/**
50
+	 * @var string $order_by
51
+	 */
52
+	private $order_by;
53
+
54
+	/**
55
+	 * @var string $sort
56
+	 */
57
+	private $sort;
58
+
59
+	/**
60
+	 * @var boolean $show_title
61
+	 */
62
+	private $show_title = true;
63
+
64
+
65
+	/**
66
+	 * EE_Event_List_Query Constructor     *
67
+	 *
68
+	 * @param array $args
69
+	 */
70
+	public function __construct($args = array())
71
+	{
72
+		$args = $this->parseArgs((array) $args);
73
+		$this->setupEventQueryHelper();
74
+		$this->setupFilters();
75
+		$args = $this->getQueryArgs($args);
76
+		// run the query
77
+		parent::__construct($args);
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param array $args
83
+	 * @return array
84
+	 */
85
+	private function parseArgs(array $args)
86
+	{
87
+		// incoming args could be a mix of WP query args + EE shortcode args
88
+		foreach ($args as $property => $value) {
89
+			// if the arg is a property of this class, then it's an EE shortcode arg
90
+			if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) {
91
+				// set the property value
92
+				$this->{$property} = $value;
93
+				// then remove it from the array of args that will later be passed to WP_Query()
94
+				unset($args[ $property ]);
95
+			}
96
+		}
97
+		return $args;
98
+	}
99
+
100
+
101
+	private function setupEventQueryHelper()
102
+	{
103
+		// add query filters
104
+		EEH_Event_Query::add_query_filters();
105
+		// set params that will get used by the filters
106
+		EEH_Event_Query::set_query_params(
107
+			$this->month,
108
+			$this->category_slug,
109
+			$this->show_expired,
110
+			$this->order_by,
111
+			$this->sort
112
+		);
113
+	}
114
+
115
+
116
+	private function setupFilters()
117
+	{
118
+		// first off, let's remove any filters from previous queries
119
+		remove_filter(
120
+			'FHEE__archive_espresso_events_template__show_header',
121
+			array($this, 'show_event_list_title')
122
+		);
123
+		remove_filter(
124
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
125
+			array($this, 'event_list_title')
126
+		);
127
+		remove_all_filters('FHEE__content_espresso_events__event_class');
128
+		// Event List Title ?
129
+		add_filter(
130
+			'FHEE__archive_espresso_events_template__show_header',
131
+			array($this, 'show_event_list_title')
132
+		);
133
+		add_filter(
134
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
135
+			array($this, 'event_list_title'),
136
+			10,
137
+			1
138
+		);
139
+		// add the css class
140
+		add_filter(
141
+			'FHEE__content_espresso_events__event_class',
142
+			array($this, 'event_list_css'),
143
+			10,
144
+			1
145
+		);
146
+	}
147
+
148
+
149
+	private function getQueryArgs(array $args)
150
+	{
151
+		// the current "page" we are viewing
152
+		$paged = max(1, get_query_var('paged'));
153
+		// Force these args
154
+		return array_merge(
155
+			$args,
156
+			array(
157
+				'post_type'              => EspressoPostType::EVENTS,
158
+				'posts_per_page'         => $this->limit,
159
+				'update_post_term_cache' => false,
160
+				'update_post_meta_cache' => false,
161
+				'paged'                  => $paged,
162
+				'offset'                 => ($paged - 1) * $this->limit,
163
+			)
164
+		);
165
+	}
166
+
167
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
168
+
169
+	/**
170
+	 * show_event_list_title
171
+	 *
172
+	 * @return boolean
173
+	 */
174
+	public function show_event_list_title()
175
+	{
176
+		return filter_var(
177
+			$this->show_title,
178
+			FILTER_VALIDATE_BOOLEAN
179
+		);
180
+	}
181
+
182
+
183
+	/**
184
+	 * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter
185
+	 *
186
+	 * @param string $event_list_title
187
+	 * @return    string
188
+	 */
189
+	public function event_list_title($event_list_title = '')
190
+	{
191
+		if (! empty($this->title)) {
192
+			return $this->title;
193
+		}
194
+		return $event_list_title;
195
+	}
196
+
197
+
198
+	/**
199
+	 * callback for FHEE__content_espresso_events__event_class filter
200
+	 *
201
+	 * @param string $event_list_css
202
+	 * @return string
203
+	 */
204
+	public function event_list_css($event_list_css = '')
205
+	{
206
+		$event_list_css .= ! empty($event_list_css) ? ' ' : '';
207
+		$event_list_css .= ! empty($this->css_class) ? $this->css_class : '';
208
+		$event_list_css .= ! empty($event_list_css) ? ' ' : '';
209
+		$event_list_css .= ! empty($this->category_slug) ? $this->category_slug : '';
210
+		return $event_list_css;
211
+	}
212
+	// phpcs:enable
213 213
 }
Please login to merge, or discard this patch.
core/domain/services/admin/AdminToolBar.php 1 patch
Indentation   +821 added lines, -821 removed lines patch added patch discarded remove patch
@@ -19,825 +19,825 @@
 block discarded – undo
19 19
  */
20 20
 class AdminToolBar
21 21
 {
22
-    private ?WP_Admin_Bar   $admin_bar        = null;
23
-
24
-    private EE_Capabilities $capabilities;
25
-
26
-    private string          $events_admin_url = '';
27
-
28
-    private string          $menu_class       = 'espresso_menu_item_class';
29
-
30
-    private string          $reg_admin_url    = '';
31
-
32
-
33
-    /**
34
-     * AdminToolBar constructor.
35
-     *
36
-     * @param EE_Capabilities $capabilities
37
-     */
38
-    public function __construct(EE_Capabilities $capabilities)
39
-    {
40
-        $this->capabilities = $capabilities;
41
-        add_action('admin_bar_menu', [$this, 'espressoToolbarItems'], 100);
42
-        $this->enqueueAssets();
43
-    }
44
-
45
-
46
-    /**
47
-     *    espresso_toolbar_items
48
-     *
49
-     * @access public
50
-     * @param WP_Admin_Bar $admin_bar
51
-     * @return void
52
-     */
53
-    public function espressoToolbarItems(WP_Admin_Bar $admin_bar)
54
-    {
55
-        // if it's an AJAX request, or user is NOT an admin, or in full M-Mode
56
-        if (
57
-            (defined('DOING_AJAX') && DOING_AJAX)
58
-            || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
59
-            || MaintenanceStatus::isFullSite()
60
-        ) {
61
-            return;
62
-        }
63
-        $this->admin_bar = $admin_bar;
64
-        // we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
65
-        // because they're only defined in each of their respective constructors
66
-        // and this might be a frontend request, in which case they aren't available
67
-        $this->events_admin_url = admin_url('admin.php?page=espresso_events');
68
-        $this->reg_admin_url    = admin_url('admin.php?page=espresso_registrations');
69
-        // now let's add all the menu items
70
-        $this->addTopLevelMenu();
71
-        $this->addEventsSubMenu();
72
-        $this->addEventsAddEditHeader();
73
-        $this->addEventsAddNew();
74
-        $this->addEventsEditCurrentEvent();
75
-        $this->addEventsViewHeader();
76
-        $this->addEventsViewAll();
77
-        $this->addEventsViewToday();
78
-        $this->addEventsViewThisMonth();
79
-        $this->addRegistrationSubMenu();
80
-        $this->addRegistrationOverviewToday();
81
-        $this->addRegistrationOverviewTodayApproved();
82
-        $this->addRegistrationOverviewTodayPendingPayment();
83
-        $this->addRegistrationOverviewTodayNotApproved();
84
-        $this->addRegistrationOverviewTodayCancelled();
85
-        $this->addRegistrationOverviewThisMonth();
86
-        $this->addRegistrationOverviewThisMonthApproved();
87
-        $this->addRegistrationOverviewThisMonthPending();
88
-        $this->addRegistrationOverviewThisMonthNotApproved();
89
-        $this->addRegistrationOverviewThisMonthCancelled();
90
-        $this->addExtensionsAndServices();
91
-        $this->addFontSizeSubMenu();
92
-    }
93
-
94
-
95
-    /**
96
-     * @return void
97
-     */
98
-    private function enqueueAssets()
99
-    {
100
-        wp_register_style(
101
-            'espresso-admin-toolbar',
102
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css',
103
-            ['dashicons'],
104
-            EVENT_ESPRESSO_VERSION
105
-        );
106
-        wp_enqueue_style('espresso-admin-toolbar');
107
-    }
108
-
109
-
110
-    /**
111
-     * @return void
112
-     */
113
-    private function addTopLevelMenu()
114
-    {
115
-        $this->admin_bar->add_menu(
116
-            [
117
-                'id'    => 'espresso-toolbar',
118
-                'title' => '<span class="ab-icon ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
119
-                           . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso')
120
-                           . '</span>',
121
-                'href'  => $this->events_admin_url,
122
-                'meta'  => [
123
-                    'title' => esc_html__('Event Espresso', 'event_espresso'),
124
-                    'class' => $this->menu_class . 'first',
125
-                ],
126
-            ]
127
-        );
128
-    }
129
-
130
-
131
-    /**
132
-     * @return void
133
-     */
134
-    private function addEventsSubMenu()
135
-    {
136
-        if (
137
-            $this->capabilities->current_user_can(
138
-                'ee_read_events',
139
-                'ee_admin_bar_menu_espresso-toolbar-events'
140
-            )
141
-        ) {
142
-            $this->admin_bar->add_menu(
143
-                [
144
-                    'id'     => 'espresso-toolbar-events',
145
-                    'parent' => 'espresso-toolbar',
146
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
147
-                                . esc_html__('Events', 'event_espresso'),
148
-                    'href'   => $this->events_admin_url,
149
-                    'meta'   => [
150
-                        'title'  => esc_html__('Events', 'event_espresso'),
151
-                        'target' => '',
152
-                        'class'  => $this->menu_class,
153
-                    ],
154
-                ]
155
-            );
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * @return void
162
-     */
163
-    private function addEventsAddEditHeader()
164
-    {
165
-        if (
166
-            $this->capabilities->current_user_can(
167
-                'ee_read_events',
168
-                'ee_admin_bar_menu_espresso-toolbar-events-view'
169
-            )
170
-        ) {
171
-            $this->admin_bar->add_menu(
172
-                [
173
-                    'id'     => 'espresso-toolbar-events-add-edit',
174
-                    'parent' => 'espresso-toolbar-events',
175
-                    'title'  => esc_html__('Add / Edit', 'event_espresso'),
176
-                    'href'   => '',
177
-                ]
178
-            );
179
-        }
180
-    }
181
-
182
-
183
-    /**
184
-     * @return void
185
-     */
186
-    private function addEventsAddNew()
187
-    {
188
-        if (
189
-            $this->capabilities->current_user_can(
190
-                'ee_edit_events',
191
-                'ee_admin_bar_menu_espresso-toolbar-events-new'
192
-            )
193
-        ) {
194
-            $this->admin_bar->add_menu(
195
-                [
196
-                    'id'     => 'espresso-toolbar-events-new',
197
-                    'parent' => 'espresso-toolbar-events',
198
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
199
-                                . esc_html__('Add New', 'event_espresso'),
200
-                    'href'   => EEH_URL::add_query_args_and_nonce(
201
-                        ['action' => 'create_new'],
202
-                        $this->events_admin_url
203
-                    ),
204
-                    'meta'   => [
205
-                        'title'  => esc_html__('Add New', 'event_espresso'),
206
-                        'target' => '',
207
-                        'class'  => $this->menu_class,
208
-                    ],
209
-                ]
210
-            );
211
-        }
212
-    }
213
-
214
-
215
-    /**
216
-     * @return void
217
-     */
218
-    private function addEventsEditCurrentEvent()
219
-    {
220
-        if (is_single() && (get_post_type() === EspressoPostType::EVENTS)) {
221
-            // Current post
222
-            global $post;
223
-            if (
224
-                $this->capabilities->current_user_can(
225
-                    'ee_edit_event',
226
-                    'ee_admin_bar_menu_espresso-toolbar-events-edit',
227
-                    $post->ID
228
-                )
229
-            ) {
230
-                $this->admin_bar->add_menu(
231
-                    [
232
-                        'id'     => 'espresso-toolbar-events-edit',
233
-                        'parent' => 'espresso-toolbar-events',
234
-                        'title'  => '<span class="ee-toolbar-icon"></span>'
235
-                                    . esc_html__('Edit Event', 'event_espresso'),
236
-                        'href'   => EEH_URL::add_query_args_and_nonce(
237
-                            [
238
-                                'action' => 'edit',
239
-                                'post'   => $post->ID,
240
-                            ],
241
-                            $this->events_admin_url
242
-                        ),
243
-                        'meta'   => [
244
-                            'title'  => esc_html__('Edit Event', 'event_espresso'),
245
-                            'target' => '',
246
-                            'class'  => $this->menu_class,
247
-                        ],
248
-                    ]
249
-                );
250
-            }
251
-        }
252
-    }
253
-
254
-
255
-    /**
256
-     * @return void
257
-     */
258
-    private function addEventsViewHeader()
259
-    {
260
-        if (
261
-            $this->capabilities->current_user_can(
262
-                'ee_read_events',
263
-                'ee_admin_bar_menu_espresso-toolbar-events-view'
264
-            )
265
-        ) {
266
-            $this->admin_bar->add_menu(
267
-                [
268
-                    'id'     => 'espresso-toolbar-events-view',
269
-                    'parent' => 'espresso-toolbar-events',
270
-                    'title'  => esc_html__('View', 'event_espresso'),
271
-                    'href'   => '',
272
-                ]
273
-            );
274
-        }
275
-    }
276
-
277
-
278
-    /**
279
-     * @return void
280
-     */
281
-    private function addEventsViewAll()
282
-    {
283
-        if (
284
-            $this->capabilities->current_user_can(
285
-                'ee_read_events',
286
-                'ee_admin_bar_menu_espresso-toolbar-events-all'
287
-            )
288
-        ) {
289
-            $this->admin_bar->add_menu(
290
-                [
291
-                    'id'     => 'espresso-toolbar-events-all',
292
-                    'parent' => 'espresso-toolbar-events',
293
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
294
-                                . esc_html__('All', 'event_espresso'),
295
-                    'href'   => $this->events_admin_url,
296
-                    'meta'   => [
297
-                        'title'  => esc_html__('All', 'event_espresso'),
298
-                        'target' => '',
299
-                        'class'  => $this->menu_class,
300
-                    ],
301
-                ]
302
-            );
303
-        }
304
-    }
305
-
306
-
307
-    /**
308
-     * @return void
309
-     */
310
-    private function addEventsViewToday()
311
-    {
312
-        if (
313
-            $this->capabilities->current_user_can(
314
-                'ee_read_events',
315
-                'ee_admin_bar_menu_espresso-toolbar-events-today'
316
-            )
317
-        ) {
318
-            $this->admin_bar->add_menu(
319
-                [
320
-                    'id'     => 'espresso-toolbar-events-today',
321
-                    'parent' => 'espresso-toolbar-events',
322
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
323
-                                . esc_html__('Today', 'event_espresso'),
324
-                    'href'   => EEH_URL::add_query_args_and_nonce(
325
-                        [
326
-                            'action' => 'default',
327
-                            'status' => 'today',
328
-                        ],
329
-                        $this->events_admin_url
330
-                    ),
331
-                    'meta'   => [
332
-                        'title'  => esc_html__('Today', 'event_espresso'),
333
-                        'target' => '',
334
-                        'class'  => $this->menu_class,
335
-                    ],
336
-                ]
337
-            );
338
-        }
339
-    }
340
-
341
-
342
-    /**
343
-     * @return void
344
-     */
345
-    private function addEventsViewThisMonth()
346
-    {
347
-        if (
348
-            $this->capabilities->current_user_can(
349
-                'ee_read_events',
350
-                'ee_admin_bar_menu_espresso-toolbar-events-month'
351
-            )
352
-        ) {
353
-            $this->admin_bar->add_menu(
354
-                [
355
-                    'id'     => 'espresso-toolbar-events-month',
356
-                    'parent' => 'espresso-toolbar-events',
357
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
358
-                                . esc_html__('This Month', 'event_espresso'),
359
-                    'href'   => EEH_URL::add_query_args_and_nonce(
360
-                        [
361
-                            'action' => 'default',
362
-                            'status' => 'month',
363
-                        ],
364
-                        $this->events_admin_url
365
-                    ),
366
-                    'meta'   => [
367
-                        'title'  => esc_html__('This Month', 'event_espresso'),
368
-                        'target' => '',
369
-                        'class'  => $this->menu_class,
370
-                    ],
371
-                ]
372
-            );
373
-        }
374
-    }
375
-
376
-
377
-    /**
378
-     * @return void
379
-     */
380
-    private function addRegistrationSubMenu()
381
-    {
382
-        if (
383
-            $this->capabilities->current_user_can(
384
-                'ee_read_registrations',
385
-                'ee_admin_bar_menu_espresso-toolbar-registrations'
386
-            )
387
-        ) {
388
-            $this->admin_bar->add_menu(
389
-                [
390
-                    'id'     => 'espresso-toolbar-registrations',
391
-                    'parent' => 'espresso-toolbar',
392
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
393
-                                . esc_html__('Registrations', 'event_espresso'),
394
-                    'href'   => $this->reg_admin_url,
395
-                    'meta'   => [
396
-                        'title'  => esc_html__('Registrations', 'event_espresso'),
397
-                        'target' => '',
398
-                        'class'  => $this->menu_class,
399
-                    ],
400
-                ]
401
-            );
402
-        }
403
-    }
404
-
405
-
406
-    /**
407
-     * @return void
408
-     */
409
-    private function addRegistrationOverviewToday()
410
-    {
411
-        if (
412
-            $this->capabilities->current_user_can(
413
-                'ee_read_registrations',
414
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today'
415
-            )
416
-        ) {
417
-            $this->admin_bar->add_menu(
418
-                [
419
-                    'id'     => 'espresso-toolbar-registrations-today',
420
-                    'parent' => 'espresso-toolbar-registrations',
421
-                    'title'  => esc_html__('Today', 'event_espresso'),
422
-                    'href'   => '',
423
-                    'meta'   => [
424
-                        'title'  => esc_html__('Today', 'event_espresso'),
425
-                        'target' => '',
426
-                        'class'  => $this->menu_class,
427
-                    ],
428
-                ]
429
-            );
430
-        }
431
-    }
432
-
433
-
434
-    /**
435
-     * @return void
436
-     */
437
-    private function addRegistrationOverviewTodayApproved()
438
-    {
439
-        if (
440
-            $this->capabilities->current_user_can(
441
-                'ee_read_registrations',
442
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved'
443
-            )
444
-        ) {
445
-            $this->admin_bar->add_menu(
446
-                [
447
-                    'id'     => 'espresso-toolbar-registrations-today-approved',
448
-                    'parent' => 'espresso-toolbar-registrations',
449
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
450
-                                . esc_html__('Approved', 'event_espresso'),
451
-                    'href'   => EEH_URL::add_query_args_and_nonce(
452
-                        [
453
-                            'action'      => 'default',
454
-                            'status'      => 'today',
455
-                            '_reg_status' => EEM_Registration::status_id_approved,
456
-                        ],
457
-                        $this->reg_admin_url
458
-                    ),
459
-                    'meta'   => [
460
-                        'title'  => esc_html__('Approved', 'event_espresso'),
461
-                        'target' => '',
462
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
463
-                    ],
464
-                ]
465
-            );
466
-        }
467
-    }
468
-
469
-
470
-    /**
471
-     * @return void
472
-     */
473
-    private function addRegistrationOverviewTodayPendingPayment()
474
-    {
475
-        if (
476
-            $this->capabilities->current_user_can(
477
-                'ee_read_registrations',
478
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending'
479
-            )
480
-        ) {
481
-            $this->admin_bar->add_menu(
482
-                [
483
-                    'id'     => 'espresso-toolbar-registrations-today-pending',
484
-                    'parent' => 'espresso-toolbar-registrations',
485
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
486
-                                . esc_html__('Pending', 'event_espresso'),
487
-                    'href'   => EEH_URL::add_query_args_and_nonce(
488
-                        [
489
-                            'action'      => 'default',
490
-                            'status'      => 'today',
491
-                            '_reg_status' => EEM_Registration::status_id_pending_payment,
492
-                        ],
493
-                        $this->reg_admin_url
494
-                    ),
495
-                    'meta'   => [
496
-                        'title'  => esc_html__('Pending Payment', 'event_espresso'),
497
-                        'target' => '',
498
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
499
-                    ],
500
-                ]
501
-            );
502
-        }
503
-    }
504
-
505
-
506
-    /**
507
-     * @return void
508
-     */
509
-    private function addRegistrationOverviewTodayNotApproved()
510
-    {
511
-        if (
512
-            $this->capabilities->current_user_can(
513
-                'ee_read_registrations',
514
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved'
515
-            )
516
-        ) {
517
-            $this->admin_bar->add_menu(
518
-                [
519
-                    'id'     => 'espresso-toolbar-registrations-today-not-approved',
520
-                    'parent' => 'espresso-toolbar-registrations',
521
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
522
-                                . esc_html__('Not Approved', 'event_espresso'),
523
-                    'href'   => EEH_URL::add_query_args_and_nonce(
524
-                        [
525
-                            'action'      => 'default',
526
-                            'status'      => 'today',
527
-                            '_reg_status' => EEM_Registration::status_id_not_approved,
528
-                        ],
529
-                        $this->reg_admin_url
530
-                    ),
531
-                    'meta'   => [
532
-                        'title'  => esc_html__('Not Approved', 'event_espresso'),
533
-                        'target' => '',
534
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
535
-                    ],
536
-                ]
537
-            );
538
-        }
539
-    }
540
-
541
-
542
-    /**
543
-     * @return void
544
-     */
545
-    private function addRegistrationOverviewTodayCancelled()
546
-    {
547
-        if (
548
-            $this->capabilities->current_user_can(
549
-                'ee_read_registrations',
550
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled'
551
-            )
552
-        ) {
553
-            $this->admin_bar->add_menu(
554
-                [
555
-                    'id'     => 'espresso-toolbar-registrations-today-cancelled',
556
-                    'parent' => 'espresso-toolbar-registrations',
557
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
558
-                                . esc_html__('Cancelled', 'event_espresso'),
559
-                    'href'   => EEH_URL::add_query_args_and_nonce(
560
-                        [
561
-                            'action'      => 'default',
562
-                            'status'      => 'today',
563
-                            '_reg_status' => EEM_Registration::status_id_cancelled,
564
-                        ],
565
-                        $this->reg_admin_url
566
-                    ),
567
-                    'meta'   => [
568
-                        'title'  => esc_html__('Cancelled', 'event_espresso'),
569
-                        'target' => '',
570
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
571
-                    ],
572
-                ]
573
-            );
574
-        }
575
-    }
576
-
577
-
578
-    /**
579
-     * @return void
580
-     */
581
-    private function addRegistrationOverviewThisMonth()
582
-    {
583
-        if (
584
-            $this->capabilities->current_user_can(
585
-                'ee_read_registrations',
586
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month'
587
-            )
588
-        ) {
589
-            $this->admin_bar->add_menu(
590
-                [
591
-                    'id'     => 'espresso-toolbar-registrations-month',
592
-                    'parent' => 'espresso-toolbar-registrations',
593
-                    'title'  => esc_html__('This Month', 'event_espresso'),
594
-                    'href'   => '', // EEH_URL::add_query_args_and_nonce(
595
-                    //     array(
596
-                    //         'action' => 'default',
597
-                    //         'status' => 'month'
598
-                    //     ),
599
-                    //     $this->reg_admin_url
600
-                    // ),
601
-                    'meta'   => [
602
-                        'title'  => esc_html__('This Month', 'event_espresso'),
603
-                        'target' => '',
604
-                        'class'  => $this->menu_class,
605
-                    ],
606
-                ]
607
-            );
608
-        }
609
-    }
610
-
611
-
612
-    /**
613
-     * @return void
614
-     */
615
-    private function addRegistrationOverviewThisMonthApproved()
616
-    {
617
-        if (
618
-            $this->capabilities->current_user_can(
619
-                'ee_read_registrations',
620
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved'
621
-            )
622
-        ) {
623
-            $this->admin_bar->add_menu(
624
-                [
625
-                    'id'     => 'espresso-toolbar-registrations-month-approved',
626
-                    'parent' => 'espresso-toolbar-registrations',
627
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
628
-                                . esc_html__('Approved', 'event_espresso'),
629
-                    'href'   => EEH_URL::add_query_args_and_nonce(
630
-                        [
631
-                            'action'      => 'default',
632
-                            'status'      => 'month',
633
-                            '_reg_status' => EEM_Registration::status_id_approved,
634
-                        ],
635
-                        $this->reg_admin_url
636
-                    ),
637
-                    'meta'   => [
638
-                        'title'  => esc_html__('Approved', 'event_espresso'),
639
-                        'target' => '',
640
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
641
-                    ],
642
-                ]
643
-            );
644
-        }
645
-    }
646
-
647
-
648
-    /**
649
-     * @return void
650
-     */
651
-    private function addRegistrationOverviewThisMonthPending()
652
-    {
653
-        if (
654
-            $this->capabilities->current_user_can(
655
-                'ee_read_registrations',
656
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending'
657
-            )
658
-        ) {
659
-            $this->admin_bar->add_menu(
660
-                [
661
-                    'id'     => 'espresso-toolbar-registrations-month-pending',
662
-                    'parent' => 'espresso-toolbar-registrations',
663
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
664
-                                . esc_html__('Pending', 'event_espresso'),
665
-                    'href'   => EEH_URL::add_query_args_and_nonce(
666
-                        [
667
-                            'action'      => 'default',
668
-                            'status'      => 'month',
669
-                            '_reg_status' => EEM_Registration::status_id_pending_payment,
670
-                        ],
671
-                        $this->reg_admin_url
672
-                    ),
673
-                    'meta'   => [
674
-                        'title'  => esc_html__('Pending', 'event_espresso'),
675
-                        'target' => '',
676
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
677
-                    ],
678
-                ]
679
-            );
680
-        }
681
-    }
682
-
683
-
684
-    /**
685
-     * @return void
686
-     */
687
-    private function addRegistrationOverviewThisMonthNotApproved()
688
-    {
689
-        if (
690
-            $this->capabilities->current_user_can(
691
-                'ee_read_registrations',
692
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved'
693
-            )
694
-        ) {
695
-            $this->admin_bar->add_menu(
696
-                [
697
-                    'id'     => 'espresso-toolbar-registrations-month-not-approved',
698
-                    'parent' => 'espresso-toolbar-registrations',
699
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
700
-                                . esc_html__('Not Approved', 'event_espresso'),
701
-                    'href'   => EEH_URL::add_query_args_and_nonce(
702
-                        [
703
-                            'action'      => 'default',
704
-                            'status'      => 'month',
705
-                            '_reg_status' => EEM_Registration::status_id_not_approved,
706
-                        ],
707
-                        $this->reg_admin_url
708
-                    ),
709
-                    'meta'   => [
710
-                        'title'  => esc_html__('Not Approved', 'event_espresso'),
711
-                        'target' => '',
712
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
713
-                    ],
714
-                ]
715
-            );
716
-        }
717
-    }
718
-
719
-
720
-    /**
721
-     * @return void
722
-     */
723
-    private function addRegistrationOverviewThisMonthCancelled()
724
-    {
725
-        if (
726
-            $this->capabilities->current_user_can(
727
-                'ee_read_registrations',
728
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled'
729
-            )
730
-        ) {
731
-            $this->admin_bar->add_menu(
732
-                [
733
-                    'id'     => 'espresso-toolbar-registrations-month-cancelled',
734
-                    'parent' => 'espresso-toolbar-registrations',
735
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
736
-                                . esc_html__('Cancelled', 'event_espresso'),
737
-                    'href'   => EEH_URL::add_query_args_and_nonce(
738
-                        [
739
-                            'action'      => 'default',
740
-                            'status'      => 'month',
741
-                            '_reg_status' => EEM_Registration::status_id_cancelled,
742
-                        ],
743
-                        $this->reg_admin_url
744
-                    ),
745
-                    'meta'   => [
746
-                        'title'  => esc_html__('Cancelled', 'event_espresso'),
747
-                        'target' => '',
748
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
749
-                    ],
750
-                ]
751
-            );
752
-        }
753
-    }
754
-
755
-
756
-    /**
757
-     * @return void
758
-     */
759
-    private function addExtensionsAndServices()
760
-    {
761
-        if (
762
-            $this->capabilities->current_user_can(
763
-                'ee_read_ee',
764
-                'ee_admin_bar_menu_espresso-toolbar-extensions-and-services'
765
-            )
766
-        ) {
767
-            $this->admin_bar->add_menu(
768
-                [
769
-                    'id'     => 'espresso-toolbar-extensions-and-services',
770
-                    'parent' => 'espresso-toolbar',
771
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
772
-                                . esc_html__('Extensions & Services', 'event_espresso'),
773
-                    'href'   => admin_url('admin.php?page=espresso_packages'),
774
-                    'meta'   => [
775
-                        'title'  => esc_html__('Extensions & Services', 'event_espresso'),
776
-                        'target' => '',
777
-                        'class'  => $this->menu_class,
778
-                    ],
779
-                ]
780
-            );
781
-        }
782
-    }
783
-
784
-
785
-    /**
786
-     * @return void
787
-     */
788
-    private function addFontSizeSubMenu()
789
-    {
790
-        if (! is_admin()) {
791
-            return;
792
-        }
793
-        $this->admin_bar->add_menu(
794
-            [
795
-                'id'     => 'espresso-toolbar-font-size',
796
-                'parent' => 'espresso-toolbar',
797
-                'title'  => '<span class="ee-toolbar-icon"></span>'
798
-                            . esc_html__('Set Font Size', 'event_espresso'),
799
-                'href'   => '',
800
-                'meta'   => [
801
-                    'title'  => esc_html__('Set Font Size', 'event_espresso'),
802
-                    'target' => '',
803
-                    'class'  => $this->menu_class,
804
-                ],
805
-            ]
806
-        );
807
-
808
-        $settings_admin_url = admin_url('admin.php?page=espresso_general_settings');
809
-
810
-        $font_sizes = [
811
-            'tiny'    => AdminFontSize::FONT_SIZE_TINY,
812
-            'smaller' => AdminFontSize::FONT_SIZE_SMALLER,
813
-            'small'   => AdminFontSize::FONT_SIZE_SMALL,
814
-            'default' => AdminFontSize::FONT_SIZE_DEFAULT,
815
-            'big'     => AdminFontSize::FONT_SIZE_BIG,
816
-            'bigger'  => AdminFontSize::FONT_SIZE_BIGGER,
817
-        ];
818
-
819
-        foreach ($font_sizes as $font_size => $value) {
820
-            $this->admin_bar->add_menu(
821
-                [
822
-                    'id'     => "espresso-toolbar-set-font-size-$font_size",
823
-                    'parent' => 'espresso-toolbar-font-size',
824
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
825
-                                . sprintf(
826
-                                    /* translators: Font Size Small */
827
-                                    esc_html__('Font Size %1$s', 'event_espresso'),
828
-                                    ucwords($font_size)
829
-                                ),
830
-                    'href'   => EEH_URL::add_query_args_and_nonce(
831
-                        ['action' => 'set_font_size', 'font_size' => $value],
832
-                        $settings_admin_url
833
-                    ),
834
-                    'meta'   => [
835
-                        'title'  => esc_html__('increases or decreases the Event Espresso admin font size', 'event_espresso'),
836
-                        'target' => '',
837
-                        'class'  => $this->menu_class,
838
-                    ],
839
-                ]
840
-            );
841
-        }
842
-    }
22
+	private ?WP_Admin_Bar   $admin_bar        = null;
23
+
24
+	private EE_Capabilities $capabilities;
25
+
26
+	private string          $events_admin_url = '';
27
+
28
+	private string          $menu_class       = 'espresso_menu_item_class';
29
+
30
+	private string          $reg_admin_url    = '';
31
+
32
+
33
+	/**
34
+	 * AdminToolBar constructor.
35
+	 *
36
+	 * @param EE_Capabilities $capabilities
37
+	 */
38
+	public function __construct(EE_Capabilities $capabilities)
39
+	{
40
+		$this->capabilities = $capabilities;
41
+		add_action('admin_bar_menu', [$this, 'espressoToolbarItems'], 100);
42
+		$this->enqueueAssets();
43
+	}
44
+
45
+
46
+	/**
47
+	 *    espresso_toolbar_items
48
+	 *
49
+	 * @access public
50
+	 * @param WP_Admin_Bar $admin_bar
51
+	 * @return void
52
+	 */
53
+	public function espressoToolbarItems(WP_Admin_Bar $admin_bar)
54
+	{
55
+		// if it's an AJAX request, or user is NOT an admin, or in full M-Mode
56
+		if (
57
+			(defined('DOING_AJAX') && DOING_AJAX)
58
+			|| ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
59
+			|| MaintenanceStatus::isFullSite()
60
+		) {
61
+			return;
62
+		}
63
+		$this->admin_bar = $admin_bar;
64
+		// we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
65
+		// because they're only defined in each of their respective constructors
66
+		// and this might be a frontend request, in which case they aren't available
67
+		$this->events_admin_url = admin_url('admin.php?page=espresso_events');
68
+		$this->reg_admin_url    = admin_url('admin.php?page=espresso_registrations');
69
+		// now let's add all the menu items
70
+		$this->addTopLevelMenu();
71
+		$this->addEventsSubMenu();
72
+		$this->addEventsAddEditHeader();
73
+		$this->addEventsAddNew();
74
+		$this->addEventsEditCurrentEvent();
75
+		$this->addEventsViewHeader();
76
+		$this->addEventsViewAll();
77
+		$this->addEventsViewToday();
78
+		$this->addEventsViewThisMonth();
79
+		$this->addRegistrationSubMenu();
80
+		$this->addRegistrationOverviewToday();
81
+		$this->addRegistrationOverviewTodayApproved();
82
+		$this->addRegistrationOverviewTodayPendingPayment();
83
+		$this->addRegistrationOverviewTodayNotApproved();
84
+		$this->addRegistrationOverviewTodayCancelled();
85
+		$this->addRegistrationOverviewThisMonth();
86
+		$this->addRegistrationOverviewThisMonthApproved();
87
+		$this->addRegistrationOverviewThisMonthPending();
88
+		$this->addRegistrationOverviewThisMonthNotApproved();
89
+		$this->addRegistrationOverviewThisMonthCancelled();
90
+		$this->addExtensionsAndServices();
91
+		$this->addFontSizeSubMenu();
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return void
97
+	 */
98
+	private function enqueueAssets()
99
+	{
100
+		wp_register_style(
101
+			'espresso-admin-toolbar',
102
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css',
103
+			['dashicons'],
104
+			EVENT_ESPRESSO_VERSION
105
+		);
106
+		wp_enqueue_style('espresso-admin-toolbar');
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return void
112
+	 */
113
+	private function addTopLevelMenu()
114
+	{
115
+		$this->admin_bar->add_menu(
116
+			[
117
+				'id'    => 'espresso-toolbar',
118
+				'title' => '<span class="ab-icon ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
119
+						   . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso')
120
+						   . '</span>',
121
+				'href'  => $this->events_admin_url,
122
+				'meta'  => [
123
+					'title' => esc_html__('Event Espresso', 'event_espresso'),
124
+					'class' => $this->menu_class . 'first',
125
+				],
126
+			]
127
+		);
128
+	}
129
+
130
+
131
+	/**
132
+	 * @return void
133
+	 */
134
+	private function addEventsSubMenu()
135
+	{
136
+		if (
137
+			$this->capabilities->current_user_can(
138
+				'ee_read_events',
139
+				'ee_admin_bar_menu_espresso-toolbar-events'
140
+			)
141
+		) {
142
+			$this->admin_bar->add_menu(
143
+				[
144
+					'id'     => 'espresso-toolbar-events',
145
+					'parent' => 'espresso-toolbar',
146
+					'title'  => '<span class="ee-toolbar-icon"></span>'
147
+								. esc_html__('Events', 'event_espresso'),
148
+					'href'   => $this->events_admin_url,
149
+					'meta'   => [
150
+						'title'  => esc_html__('Events', 'event_espresso'),
151
+						'target' => '',
152
+						'class'  => $this->menu_class,
153
+					],
154
+				]
155
+			);
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * @return void
162
+	 */
163
+	private function addEventsAddEditHeader()
164
+	{
165
+		if (
166
+			$this->capabilities->current_user_can(
167
+				'ee_read_events',
168
+				'ee_admin_bar_menu_espresso-toolbar-events-view'
169
+			)
170
+		) {
171
+			$this->admin_bar->add_menu(
172
+				[
173
+					'id'     => 'espresso-toolbar-events-add-edit',
174
+					'parent' => 'espresso-toolbar-events',
175
+					'title'  => esc_html__('Add / Edit', 'event_espresso'),
176
+					'href'   => '',
177
+				]
178
+			);
179
+		}
180
+	}
181
+
182
+
183
+	/**
184
+	 * @return void
185
+	 */
186
+	private function addEventsAddNew()
187
+	{
188
+		if (
189
+			$this->capabilities->current_user_can(
190
+				'ee_edit_events',
191
+				'ee_admin_bar_menu_espresso-toolbar-events-new'
192
+			)
193
+		) {
194
+			$this->admin_bar->add_menu(
195
+				[
196
+					'id'     => 'espresso-toolbar-events-new',
197
+					'parent' => 'espresso-toolbar-events',
198
+					'title'  => '<span class="ee-toolbar-icon"></span>'
199
+								. esc_html__('Add New', 'event_espresso'),
200
+					'href'   => EEH_URL::add_query_args_and_nonce(
201
+						['action' => 'create_new'],
202
+						$this->events_admin_url
203
+					),
204
+					'meta'   => [
205
+						'title'  => esc_html__('Add New', 'event_espresso'),
206
+						'target' => '',
207
+						'class'  => $this->menu_class,
208
+					],
209
+				]
210
+			);
211
+		}
212
+	}
213
+
214
+
215
+	/**
216
+	 * @return void
217
+	 */
218
+	private function addEventsEditCurrentEvent()
219
+	{
220
+		if (is_single() && (get_post_type() === EspressoPostType::EVENTS)) {
221
+			// Current post
222
+			global $post;
223
+			if (
224
+				$this->capabilities->current_user_can(
225
+					'ee_edit_event',
226
+					'ee_admin_bar_menu_espresso-toolbar-events-edit',
227
+					$post->ID
228
+				)
229
+			) {
230
+				$this->admin_bar->add_menu(
231
+					[
232
+						'id'     => 'espresso-toolbar-events-edit',
233
+						'parent' => 'espresso-toolbar-events',
234
+						'title'  => '<span class="ee-toolbar-icon"></span>'
235
+									. esc_html__('Edit Event', 'event_espresso'),
236
+						'href'   => EEH_URL::add_query_args_and_nonce(
237
+							[
238
+								'action' => 'edit',
239
+								'post'   => $post->ID,
240
+							],
241
+							$this->events_admin_url
242
+						),
243
+						'meta'   => [
244
+							'title'  => esc_html__('Edit Event', 'event_espresso'),
245
+							'target' => '',
246
+							'class'  => $this->menu_class,
247
+						],
248
+					]
249
+				);
250
+			}
251
+		}
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return void
257
+	 */
258
+	private function addEventsViewHeader()
259
+	{
260
+		if (
261
+			$this->capabilities->current_user_can(
262
+				'ee_read_events',
263
+				'ee_admin_bar_menu_espresso-toolbar-events-view'
264
+			)
265
+		) {
266
+			$this->admin_bar->add_menu(
267
+				[
268
+					'id'     => 'espresso-toolbar-events-view',
269
+					'parent' => 'espresso-toolbar-events',
270
+					'title'  => esc_html__('View', 'event_espresso'),
271
+					'href'   => '',
272
+				]
273
+			);
274
+		}
275
+	}
276
+
277
+
278
+	/**
279
+	 * @return void
280
+	 */
281
+	private function addEventsViewAll()
282
+	{
283
+		if (
284
+			$this->capabilities->current_user_can(
285
+				'ee_read_events',
286
+				'ee_admin_bar_menu_espresso-toolbar-events-all'
287
+			)
288
+		) {
289
+			$this->admin_bar->add_menu(
290
+				[
291
+					'id'     => 'espresso-toolbar-events-all',
292
+					'parent' => 'espresso-toolbar-events',
293
+					'title'  => '<span class="ee-toolbar-icon"></span>'
294
+								. esc_html__('All', 'event_espresso'),
295
+					'href'   => $this->events_admin_url,
296
+					'meta'   => [
297
+						'title'  => esc_html__('All', 'event_espresso'),
298
+						'target' => '',
299
+						'class'  => $this->menu_class,
300
+					],
301
+				]
302
+			);
303
+		}
304
+	}
305
+
306
+
307
+	/**
308
+	 * @return void
309
+	 */
310
+	private function addEventsViewToday()
311
+	{
312
+		if (
313
+			$this->capabilities->current_user_can(
314
+				'ee_read_events',
315
+				'ee_admin_bar_menu_espresso-toolbar-events-today'
316
+			)
317
+		) {
318
+			$this->admin_bar->add_menu(
319
+				[
320
+					'id'     => 'espresso-toolbar-events-today',
321
+					'parent' => 'espresso-toolbar-events',
322
+					'title'  => '<span class="ee-toolbar-icon"></span>'
323
+								. esc_html__('Today', 'event_espresso'),
324
+					'href'   => EEH_URL::add_query_args_and_nonce(
325
+						[
326
+							'action' => 'default',
327
+							'status' => 'today',
328
+						],
329
+						$this->events_admin_url
330
+					),
331
+					'meta'   => [
332
+						'title'  => esc_html__('Today', 'event_espresso'),
333
+						'target' => '',
334
+						'class'  => $this->menu_class,
335
+					],
336
+				]
337
+			);
338
+		}
339
+	}
340
+
341
+
342
+	/**
343
+	 * @return void
344
+	 */
345
+	private function addEventsViewThisMonth()
346
+	{
347
+		if (
348
+			$this->capabilities->current_user_can(
349
+				'ee_read_events',
350
+				'ee_admin_bar_menu_espresso-toolbar-events-month'
351
+			)
352
+		) {
353
+			$this->admin_bar->add_menu(
354
+				[
355
+					'id'     => 'espresso-toolbar-events-month',
356
+					'parent' => 'espresso-toolbar-events',
357
+					'title'  => '<span class="ee-toolbar-icon"></span>'
358
+								. esc_html__('This Month', 'event_espresso'),
359
+					'href'   => EEH_URL::add_query_args_and_nonce(
360
+						[
361
+							'action' => 'default',
362
+							'status' => 'month',
363
+						],
364
+						$this->events_admin_url
365
+					),
366
+					'meta'   => [
367
+						'title'  => esc_html__('This Month', 'event_espresso'),
368
+						'target' => '',
369
+						'class'  => $this->menu_class,
370
+					],
371
+				]
372
+			);
373
+		}
374
+	}
375
+
376
+
377
+	/**
378
+	 * @return void
379
+	 */
380
+	private function addRegistrationSubMenu()
381
+	{
382
+		if (
383
+			$this->capabilities->current_user_can(
384
+				'ee_read_registrations',
385
+				'ee_admin_bar_menu_espresso-toolbar-registrations'
386
+			)
387
+		) {
388
+			$this->admin_bar->add_menu(
389
+				[
390
+					'id'     => 'espresso-toolbar-registrations',
391
+					'parent' => 'espresso-toolbar',
392
+					'title'  => '<span class="ee-toolbar-icon"></span>'
393
+								. esc_html__('Registrations', 'event_espresso'),
394
+					'href'   => $this->reg_admin_url,
395
+					'meta'   => [
396
+						'title'  => esc_html__('Registrations', 'event_espresso'),
397
+						'target' => '',
398
+						'class'  => $this->menu_class,
399
+					],
400
+				]
401
+			);
402
+		}
403
+	}
404
+
405
+
406
+	/**
407
+	 * @return void
408
+	 */
409
+	private function addRegistrationOverviewToday()
410
+	{
411
+		if (
412
+			$this->capabilities->current_user_can(
413
+				'ee_read_registrations',
414
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today'
415
+			)
416
+		) {
417
+			$this->admin_bar->add_menu(
418
+				[
419
+					'id'     => 'espresso-toolbar-registrations-today',
420
+					'parent' => 'espresso-toolbar-registrations',
421
+					'title'  => esc_html__('Today', 'event_espresso'),
422
+					'href'   => '',
423
+					'meta'   => [
424
+						'title'  => esc_html__('Today', 'event_espresso'),
425
+						'target' => '',
426
+						'class'  => $this->menu_class,
427
+					],
428
+				]
429
+			);
430
+		}
431
+	}
432
+
433
+
434
+	/**
435
+	 * @return void
436
+	 */
437
+	private function addRegistrationOverviewTodayApproved()
438
+	{
439
+		if (
440
+			$this->capabilities->current_user_can(
441
+				'ee_read_registrations',
442
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved'
443
+			)
444
+		) {
445
+			$this->admin_bar->add_menu(
446
+				[
447
+					'id'     => 'espresso-toolbar-registrations-today-approved',
448
+					'parent' => 'espresso-toolbar-registrations',
449
+					'title'  => '<span class="ee-toolbar-icon"></span>'
450
+								. esc_html__('Approved', 'event_espresso'),
451
+					'href'   => EEH_URL::add_query_args_and_nonce(
452
+						[
453
+							'action'      => 'default',
454
+							'status'      => 'today',
455
+							'_reg_status' => EEM_Registration::status_id_approved,
456
+						],
457
+						$this->reg_admin_url
458
+					),
459
+					'meta'   => [
460
+						'title'  => esc_html__('Approved', 'event_espresso'),
461
+						'target' => '',
462
+						'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
463
+					],
464
+				]
465
+			);
466
+		}
467
+	}
468
+
469
+
470
+	/**
471
+	 * @return void
472
+	 */
473
+	private function addRegistrationOverviewTodayPendingPayment()
474
+	{
475
+		if (
476
+			$this->capabilities->current_user_can(
477
+				'ee_read_registrations',
478
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending'
479
+			)
480
+		) {
481
+			$this->admin_bar->add_menu(
482
+				[
483
+					'id'     => 'espresso-toolbar-registrations-today-pending',
484
+					'parent' => 'espresso-toolbar-registrations',
485
+					'title'  => '<span class="ee-toolbar-icon"></span>'
486
+								. esc_html__('Pending', 'event_espresso'),
487
+					'href'   => EEH_URL::add_query_args_and_nonce(
488
+						[
489
+							'action'      => 'default',
490
+							'status'      => 'today',
491
+							'_reg_status' => EEM_Registration::status_id_pending_payment,
492
+						],
493
+						$this->reg_admin_url
494
+					),
495
+					'meta'   => [
496
+						'title'  => esc_html__('Pending Payment', 'event_espresso'),
497
+						'target' => '',
498
+						'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
499
+					],
500
+				]
501
+			);
502
+		}
503
+	}
504
+
505
+
506
+	/**
507
+	 * @return void
508
+	 */
509
+	private function addRegistrationOverviewTodayNotApproved()
510
+	{
511
+		if (
512
+			$this->capabilities->current_user_can(
513
+				'ee_read_registrations',
514
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved'
515
+			)
516
+		) {
517
+			$this->admin_bar->add_menu(
518
+				[
519
+					'id'     => 'espresso-toolbar-registrations-today-not-approved',
520
+					'parent' => 'espresso-toolbar-registrations',
521
+					'title'  => '<span class="ee-toolbar-icon"></span>'
522
+								. esc_html__('Not Approved', 'event_espresso'),
523
+					'href'   => EEH_URL::add_query_args_and_nonce(
524
+						[
525
+							'action'      => 'default',
526
+							'status'      => 'today',
527
+							'_reg_status' => EEM_Registration::status_id_not_approved,
528
+						],
529
+						$this->reg_admin_url
530
+					),
531
+					'meta'   => [
532
+						'title'  => esc_html__('Not Approved', 'event_espresso'),
533
+						'target' => '',
534
+						'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
535
+					],
536
+				]
537
+			);
538
+		}
539
+	}
540
+
541
+
542
+	/**
543
+	 * @return void
544
+	 */
545
+	private function addRegistrationOverviewTodayCancelled()
546
+	{
547
+		if (
548
+			$this->capabilities->current_user_can(
549
+				'ee_read_registrations',
550
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled'
551
+			)
552
+		) {
553
+			$this->admin_bar->add_menu(
554
+				[
555
+					'id'     => 'espresso-toolbar-registrations-today-cancelled',
556
+					'parent' => 'espresso-toolbar-registrations',
557
+					'title'  => '<span class="ee-toolbar-icon"></span>'
558
+								. esc_html__('Cancelled', 'event_espresso'),
559
+					'href'   => EEH_URL::add_query_args_and_nonce(
560
+						[
561
+							'action'      => 'default',
562
+							'status'      => 'today',
563
+							'_reg_status' => EEM_Registration::status_id_cancelled,
564
+						],
565
+						$this->reg_admin_url
566
+					),
567
+					'meta'   => [
568
+						'title'  => esc_html__('Cancelled', 'event_espresso'),
569
+						'target' => '',
570
+						'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
571
+					],
572
+				]
573
+			);
574
+		}
575
+	}
576
+
577
+
578
+	/**
579
+	 * @return void
580
+	 */
581
+	private function addRegistrationOverviewThisMonth()
582
+	{
583
+		if (
584
+			$this->capabilities->current_user_can(
585
+				'ee_read_registrations',
586
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month'
587
+			)
588
+		) {
589
+			$this->admin_bar->add_menu(
590
+				[
591
+					'id'     => 'espresso-toolbar-registrations-month',
592
+					'parent' => 'espresso-toolbar-registrations',
593
+					'title'  => esc_html__('This Month', 'event_espresso'),
594
+					'href'   => '', // EEH_URL::add_query_args_and_nonce(
595
+					//     array(
596
+					//         'action' => 'default',
597
+					//         'status' => 'month'
598
+					//     ),
599
+					//     $this->reg_admin_url
600
+					// ),
601
+					'meta'   => [
602
+						'title'  => esc_html__('This Month', 'event_espresso'),
603
+						'target' => '',
604
+						'class'  => $this->menu_class,
605
+					],
606
+				]
607
+			);
608
+		}
609
+	}
610
+
611
+
612
+	/**
613
+	 * @return void
614
+	 */
615
+	private function addRegistrationOverviewThisMonthApproved()
616
+	{
617
+		if (
618
+			$this->capabilities->current_user_can(
619
+				'ee_read_registrations',
620
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved'
621
+			)
622
+		) {
623
+			$this->admin_bar->add_menu(
624
+				[
625
+					'id'     => 'espresso-toolbar-registrations-month-approved',
626
+					'parent' => 'espresso-toolbar-registrations',
627
+					'title'  => '<span class="ee-toolbar-icon"></span>'
628
+								. esc_html__('Approved', 'event_espresso'),
629
+					'href'   => EEH_URL::add_query_args_and_nonce(
630
+						[
631
+							'action'      => 'default',
632
+							'status'      => 'month',
633
+							'_reg_status' => EEM_Registration::status_id_approved,
634
+						],
635
+						$this->reg_admin_url
636
+					),
637
+					'meta'   => [
638
+						'title'  => esc_html__('Approved', 'event_espresso'),
639
+						'target' => '',
640
+						'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
641
+					],
642
+				]
643
+			);
644
+		}
645
+	}
646
+
647
+
648
+	/**
649
+	 * @return void
650
+	 */
651
+	private function addRegistrationOverviewThisMonthPending()
652
+	{
653
+		if (
654
+			$this->capabilities->current_user_can(
655
+				'ee_read_registrations',
656
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending'
657
+			)
658
+		) {
659
+			$this->admin_bar->add_menu(
660
+				[
661
+					'id'     => 'espresso-toolbar-registrations-month-pending',
662
+					'parent' => 'espresso-toolbar-registrations',
663
+					'title'  => '<span class="ee-toolbar-icon"></span>'
664
+								. esc_html__('Pending', 'event_espresso'),
665
+					'href'   => EEH_URL::add_query_args_and_nonce(
666
+						[
667
+							'action'      => 'default',
668
+							'status'      => 'month',
669
+							'_reg_status' => EEM_Registration::status_id_pending_payment,
670
+						],
671
+						$this->reg_admin_url
672
+					),
673
+					'meta'   => [
674
+						'title'  => esc_html__('Pending', 'event_espresso'),
675
+						'target' => '',
676
+						'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
677
+					],
678
+				]
679
+			);
680
+		}
681
+	}
682
+
683
+
684
+	/**
685
+	 * @return void
686
+	 */
687
+	private function addRegistrationOverviewThisMonthNotApproved()
688
+	{
689
+		if (
690
+			$this->capabilities->current_user_can(
691
+				'ee_read_registrations',
692
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved'
693
+			)
694
+		) {
695
+			$this->admin_bar->add_menu(
696
+				[
697
+					'id'     => 'espresso-toolbar-registrations-month-not-approved',
698
+					'parent' => 'espresso-toolbar-registrations',
699
+					'title'  => '<span class="ee-toolbar-icon"></span>'
700
+								. esc_html__('Not Approved', 'event_espresso'),
701
+					'href'   => EEH_URL::add_query_args_and_nonce(
702
+						[
703
+							'action'      => 'default',
704
+							'status'      => 'month',
705
+							'_reg_status' => EEM_Registration::status_id_not_approved,
706
+						],
707
+						$this->reg_admin_url
708
+					),
709
+					'meta'   => [
710
+						'title'  => esc_html__('Not Approved', 'event_espresso'),
711
+						'target' => '',
712
+						'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
713
+					],
714
+				]
715
+			);
716
+		}
717
+	}
718
+
719
+
720
+	/**
721
+	 * @return void
722
+	 */
723
+	private function addRegistrationOverviewThisMonthCancelled()
724
+	{
725
+		if (
726
+			$this->capabilities->current_user_can(
727
+				'ee_read_registrations',
728
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled'
729
+			)
730
+		) {
731
+			$this->admin_bar->add_menu(
732
+				[
733
+					'id'     => 'espresso-toolbar-registrations-month-cancelled',
734
+					'parent' => 'espresso-toolbar-registrations',
735
+					'title'  => '<span class="ee-toolbar-icon"></span>'
736
+								. esc_html__('Cancelled', 'event_espresso'),
737
+					'href'   => EEH_URL::add_query_args_and_nonce(
738
+						[
739
+							'action'      => 'default',
740
+							'status'      => 'month',
741
+							'_reg_status' => EEM_Registration::status_id_cancelled,
742
+						],
743
+						$this->reg_admin_url
744
+					),
745
+					'meta'   => [
746
+						'title'  => esc_html__('Cancelled', 'event_espresso'),
747
+						'target' => '',
748
+						'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
749
+					],
750
+				]
751
+			);
752
+		}
753
+	}
754
+
755
+
756
+	/**
757
+	 * @return void
758
+	 */
759
+	private function addExtensionsAndServices()
760
+	{
761
+		if (
762
+			$this->capabilities->current_user_can(
763
+				'ee_read_ee',
764
+				'ee_admin_bar_menu_espresso-toolbar-extensions-and-services'
765
+			)
766
+		) {
767
+			$this->admin_bar->add_menu(
768
+				[
769
+					'id'     => 'espresso-toolbar-extensions-and-services',
770
+					'parent' => 'espresso-toolbar',
771
+					'title'  => '<span class="ee-toolbar-icon"></span>'
772
+								. esc_html__('Extensions & Services', 'event_espresso'),
773
+					'href'   => admin_url('admin.php?page=espresso_packages'),
774
+					'meta'   => [
775
+						'title'  => esc_html__('Extensions & Services', 'event_espresso'),
776
+						'target' => '',
777
+						'class'  => $this->menu_class,
778
+					],
779
+				]
780
+			);
781
+		}
782
+	}
783
+
784
+
785
+	/**
786
+	 * @return void
787
+	 */
788
+	private function addFontSizeSubMenu()
789
+	{
790
+		if (! is_admin()) {
791
+			return;
792
+		}
793
+		$this->admin_bar->add_menu(
794
+			[
795
+				'id'     => 'espresso-toolbar-font-size',
796
+				'parent' => 'espresso-toolbar',
797
+				'title'  => '<span class="ee-toolbar-icon"></span>'
798
+							. esc_html__('Set Font Size', 'event_espresso'),
799
+				'href'   => '',
800
+				'meta'   => [
801
+					'title'  => esc_html__('Set Font Size', 'event_espresso'),
802
+					'target' => '',
803
+					'class'  => $this->menu_class,
804
+				],
805
+			]
806
+		);
807
+
808
+		$settings_admin_url = admin_url('admin.php?page=espresso_general_settings');
809
+
810
+		$font_sizes = [
811
+			'tiny'    => AdminFontSize::FONT_SIZE_TINY,
812
+			'smaller' => AdminFontSize::FONT_SIZE_SMALLER,
813
+			'small'   => AdminFontSize::FONT_SIZE_SMALL,
814
+			'default' => AdminFontSize::FONT_SIZE_DEFAULT,
815
+			'big'     => AdminFontSize::FONT_SIZE_BIG,
816
+			'bigger'  => AdminFontSize::FONT_SIZE_BIGGER,
817
+		];
818
+
819
+		foreach ($font_sizes as $font_size => $value) {
820
+			$this->admin_bar->add_menu(
821
+				[
822
+					'id'     => "espresso-toolbar-set-font-size-$font_size",
823
+					'parent' => 'espresso-toolbar-font-size',
824
+					'title'  => '<span class="ee-toolbar-icon"></span>'
825
+								. sprintf(
826
+									/* translators: Font Size Small */
827
+									esc_html__('Font Size %1$s', 'event_espresso'),
828
+									ucwords($font_size)
829
+								),
830
+					'href'   => EEH_URL::add_query_args_and_nonce(
831
+						['action' => 'set_font_size', 'font_size' => $value],
832
+						$settings_admin_url
833
+					),
834
+					'meta'   => [
835
+						'title'  => esc_html__('increases or decreases the Event Espresso admin font size', 'event_espresso'),
836
+						'target' => '',
837
+						'class'  => $this->menu_class,
838
+					],
839
+				]
840
+			);
841
+		}
842
+	}
843 843
 }
Please login to merge, or discard this patch.
admin/registrations/list_table/csv_reports/RegistrationsCsvReportParams.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -13,83 +13,83 @@
 block discarded – undo
13 13
  */
14 14
 class RegistrationsCsvReportParams
15 15
 {
16
-    /**
17
-     * @param string $return_url
18
-     * @param array  $request_params
19
-     * @param int    $EVT_ID
20
-     * @param int    $DTT_ID
21
-     * @return array
22
-     */
23
-    public static function getRequestParams(
24
-        string $return_url,
25
-        array $request_params = [],
26
-        int $EVT_ID = 0,
27
-        int $DTT_ID = 0
28
-    ): array {
29
-        if (
30
-            ! EE_Capabilities::instance()->current_user_can(
31
-                'ee_read_registrations',
32
-                'espresso_registrations_registrations_reports',
33
-                $EVT_ID
34
-            )
35
-        ) {
36
-            return [];
37
-        }
38
-        unset($request_params['_wp_http_referer']);
39
-        add_action(
40
-            'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
41
-            [RegistrationsCsvReportParams::class, 'csvReportNotice']
42
-        );
16
+	/**
17
+	 * @param string $return_url
18
+	 * @param array  $request_params
19
+	 * @param int    $EVT_ID
20
+	 * @param int    $DTT_ID
21
+	 * @return array
22
+	 */
23
+	public static function getRequestParams(
24
+		string $return_url,
25
+		array $request_params = [],
26
+		int $EVT_ID = 0,
27
+		int $DTT_ID = 0
28
+	): array {
29
+		if (
30
+			! EE_Capabilities::instance()->current_user_can(
31
+				'ee_read_registrations',
32
+				'espresso_registrations_registrations_reports',
33
+				$EVT_ID
34
+			)
35
+		) {
36
+			return [];
37
+		}
38
+		unset($request_params['_wp_http_referer']);
39
+		add_action(
40
+			'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
41
+			[RegistrationsCsvReportParams::class, 'csvReportNotice']
42
+		);
43 43
 
44
-        $route_details = [
45
-            'route'         => 'registrations_report',
46
-            'extra_request' => [ 'return_url' => $return_url ],
47
-            'btn_class'     => 'button button--primary',
48
-        ];
49
-        if (! empty($EVT_ID)) {
50
-            $route_details['extra_request']['EVT_ID'] = $EVT_ID;
51
-        }
52
-        if ($DTT_ID) {
53
-            $route_details['extra_request']['DTT_ID'] = $DTT_ID;
54
-        }
55
-        // detect views (status) or searches (s) and set "use_filters" to true
56
-        if (
57
-            isset($request_params['_reg_status'])
58
-            || isset($request_params['datetime_id'])
59
-            || isset($request_params['event_id'])
60
-            || isset($request_params['s'])
61
-            || isset($request_params['status'])
62
-            || isset($request_params['ticket_id'])
63
-        ) {
64
-            $request_params['use_filters'] = true;
65
-            $route_details['extra_request']['use_filters'] = true;
66
-        }
67
-        if (
68
-            isset($request_params['use_filters'])
69
-            && filter_var($request_params['use_filters'], FILTER_VALIDATE_BOOLEAN)
70
-        ) {
71
-            $route_details['extra_request']['filters'] = array_diff_key(
72
-                $request_params,
73
-                [
74
-                    'page'          => '',
75
-                    'action'        => '',
76
-                    'default_nonce' => '',
77
-                ]
78
-            );
79
-            unset($route_details['extra_request']['filters']['use_filters']);
80
-        }
81
-        return $route_details;
82
-    }
44
+		$route_details = [
45
+			'route'         => 'registrations_report',
46
+			'extra_request' => [ 'return_url' => $return_url ],
47
+			'btn_class'     => 'button button--primary',
48
+		];
49
+		if (! empty($EVT_ID)) {
50
+			$route_details['extra_request']['EVT_ID'] = $EVT_ID;
51
+		}
52
+		if ($DTT_ID) {
53
+			$route_details['extra_request']['DTT_ID'] = $DTT_ID;
54
+		}
55
+		// detect views (status) or searches (s) and set "use_filters" to true
56
+		if (
57
+			isset($request_params['_reg_status'])
58
+			|| isset($request_params['datetime_id'])
59
+			|| isset($request_params['event_id'])
60
+			|| isset($request_params['s'])
61
+			|| isset($request_params['status'])
62
+			|| isset($request_params['ticket_id'])
63
+		) {
64
+			$request_params['use_filters'] = true;
65
+			$route_details['extra_request']['use_filters'] = true;
66
+		}
67
+		if (
68
+			isset($request_params['use_filters'])
69
+			&& filter_var($request_params['use_filters'], FILTER_VALIDATE_BOOLEAN)
70
+		) {
71
+			$route_details['extra_request']['filters'] = array_diff_key(
72
+				$request_params,
73
+				[
74
+					'page'          => '',
75
+					'action'        => '',
76
+					'default_nonce' => '',
77
+				]
78
+			);
79
+			unset($route_details['extra_request']['filters']['use_filters']);
80
+		}
81
+		return $route_details;
82
+	}
83 83
 
84 84
 
85
-    public static function csvReportNotice()
86
-    {
87
-        echo '
85
+	public static function csvReportNotice()
86
+	{
87
+		echo '
88 88
     <span class="csv-report-notice__wrapper">
89 89
         <span class="dashicons dashicons-info"></span>
90 90
         <span class="csv-report-notice__text">
91 91
         ' .  esc_html('All Registration CSV Reports are now triggered by the preceding button') . '
92 92
         </span>
93 93
     </span>';
94
-    }
94
+	}
95 95
 }
Please login to merge, or discard this patch.
core/domain/services/admin/privacy/export/ExportCheckins.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -16,112 +16,112 @@
 block discarded – undo
16 16
  */
17 17
 class ExportCheckins implements PersonalDataExporterInterface
18 18
 {
19
-    /**
20
-     * @var EEM_Checkin
21
-     */
22
-    protected $checkin_model;
19
+	/**
20
+	 * @var EEM_Checkin
21
+	 */
22
+	protected $checkin_model;
23 23
 
24
-    /**
25
-     * ExportCheckins constructor.
26
-     *
27
-     * @param EEM_Checkin $checkin_model
28
-     */
29
-    public function __construct(EEM_Checkin $checkin_model)
30
-    {
31
-        $this->checkin_model = $checkin_model;
32
-    }
24
+	/**
25
+	 * ExportCheckins constructor.
26
+	 *
27
+	 * @param EEM_Checkin $checkin_model
28
+	 */
29
+	public function __construct(EEM_Checkin $checkin_model)
30
+	{
31
+		$this->checkin_model = $checkin_model;
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * Returns data for export.
37
-     *
38
-     * @param string    $email_address ,
39
-     * @param int       $page          starts at 1, not 0
40
-     * @return array {
41
-     * @type array      $data          {
42
-     * @type array {
43
-     * @type string     $group_id      (not translated, same for all exports)
44
-     * @type string     $group_label   (translated string)
45
-     * @type string|int $item_id
46
-     * @type array      $data          {
47
-     * @type array {
48
-     * @type string     $name          what's shown in the left-column of the export row
49
-     * @type string     $value         what's showin the right-column of the export row
50
-     *                                 }
51
-     *                                 }
52
-     *                                 }
53
-     *                                 }
54
-     *                                 }
55
-     */
56
-    public function export($email_address, $page = 1)
57
-    {
58
-        $page_size = 10;
59
-        $checkins = $this->checkin_model->get_all(
60
-            array(
61
-                array(
62
-                    'Registration.Attendee.ATT_email' => $email_address,
63
-                ),
64
-                'limit'      => array(
65
-                    ($page - 1) * $page_size,
66
-                    $page_size,
67
-                ),
68
-                'force_join' => array('Registration.Event'),
69
-            )
70
-        );
35
+	/**
36
+	 * Returns data for export.
37
+	 *
38
+	 * @param string    $email_address ,
39
+	 * @param int       $page          starts at 1, not 0
40
+	 * @return array {
41
+	 * @type array      $data          {
42
+	 * @type array {
43
+	 * @type string     $group_id      (not translated, same for all exports)
44
+	 * @type string     $group_label   (translated string)
45
+	 * @type string|int $item_id
46
+	 * @type array      $data          {
47
+	 * @type array {
48
+	 * @type string     $name          what's shown in the left-column of the export row
49
+	 * @type string     $value         what's showin the right-column of the export row
50
+	 *                                 }
51
+	 *                                 }
52
+	 *                                 }
53
+	 *                                 }
54
+	 *                                 }
55
+	 */
56
+	public function export($email_address, $page = 1)
57
+	{
58
+		$page_size = 10;
59
+		$checkins = $this->checkin_model->get_all(
60
+			array(
61
+				array(
62
+					'Registration.Attendee.ATT_email' => $email_address,
63
+				),
64
+				'limit'      => array(
65
+					($page - 1) * $page_size,
66
+					$page_size,
67
+				),
68
+				'force_join' => array('Registration.Event'),
69
+			)
70
+		);
71 71
 
72
-        if (empty($checkins)) {
73
-            return array(
74
-                'data' => array(),
75
-                'done' => true,
76
-            );
77
-        }
72
+		if (empty($checkins)) {
73
+			return array(
74
+				'data' => array(),
75
+				'done' => true,
76
+			);
77
+		}
78 78
 
79
-        $export_items = array();
80
-        foreach ($checkins as $checkin) {
81
-            $reg = $checkin->get_first_related('Registration');
82
-            if ($reg instanceof EE_Registration) {
83
-                $event_name = $reg->event_name();
84
-            } else {
85
-                $event_name = esc_html__('Unknown', 'event_espresso');
86
-            }
87
-            $export_items[] =
88
-                array(
89
-                    'group_id'    => 'check-ins',
90
-                    'group_label' => esc_html__('Event Check-Ins', 'event_espresso'),
91
-                    'item_id'     => $checkin->ID(),
92
-                    'data'        => array(
93
-                        array(
94
-                            'name'  => esc_html__('Time', 'event_espresso'),
95
-                            'value' => $checkin->get_pretty('CHK_timestamp'),
96
-                        ),
97
-                        array(
98
-                            'name'  => esc_html__('Check in/out', 'event_espresso'),
99
-                            'value' => $checkin->status()
100
-                                ? esc_html__('In', 'event_espresso')
101
-                                : esc_html__('Out', 'event_espresso'),
102
-                        ),
103
-                        array(
104
-                            'name'  => esc_html__('Event', 'event_espresso'),
105
-                            'value' => $event_name,
106
-                        ),
107
-                    ),
108
-                );
109
-        }
110
-        return array(
111
-            'data' => $export_items,
112
-            'done' => true,
113
-        );
114
-    }
79
+		$export_items = array();
80
+		foreach ($checkins as $checkin) {
81
+			$reg = $checkin->get_first_related('Registration');
82
+			if ($reg instanceof EE_Registration) {
83
+				$event_name = $reg->event_name();
84
+			} else {
85
+				$event_name = esc_html__('Unknown', 'event_espresso');
86
+			}
87
+			$export_items[] =
88
+				array(
89
+					'group_id'    => 'check-ins',
90
+					'group_label' => esc_html__('Event Check-Ins', 'event_espresso'),
91
+					'item_id'     => $checkin->ID(),
92
+					'data'        => array(
93
+						array(
94
+							'name'  => esc_html__('Time', 'event_espresso'),
95
+							'value' => $checkin->get_pretty('CHK_timestamp'),
96
+						),
97
+						array(
98
+							'name'  => esc_html__('Check in/out', 'event_espresso'),
99
+							'value' => $checkin->status()
100
+								? esc_html__('In', 'event_espresso')
101
+								: esc_html__('Out', 'event_espresso'),
102
+						),
103
+						array(
104
+							'name'  => esc_html__('Event', 'event_espresso'),
105
+							'value' => $event_name,
106
+						),
107
+					),
108
+				);
109
+		}
110
+		return array(
111
+			'data' => $export_items,
112
+			'done' => true,
113
+		);
114
+	}
115 115
 
116
-    /**
117
-     * Gets the Translated name of this exporter
118
-     *
119
-     * @return string
120
-     */
121
-    public function name()
122
-    {
123
-        return esc_html__('Event Espresso Check-ins Exporter', 'event_espresso');
124
-    }
116
+	/**
117
+	 * Gets the Translated name of this exporter
118
+	 *
119
+	 * @return string
120
+	 */
121
+	public function name()
122
+	{
123
+		return esc_html__('Event Espresso Check-ins Exporter', 'event_espresso');
124
+	}
125 125
 }
126 126
 // End of file ExportCheckins.php
127 127
 // Location: EventEspresso\core\domain\services\admin\privacy\export/ExportCheckins.php
Please login to merge, or discard this patch.
core/domain/services/admin/events/editor/ui/DuplicateEventButton.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,23 +15,23 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class DuplicateEventButton extends PermalinkHtmlHook
17 17
 {
18
-    public static function addButton(string $html, int $post_id): string
19
-    {
20
-        // make sure this is only when editing
21
-        if (empty($post_id)) {
22
-            return $html;
23
-        }
24
-        $post = get_post($post_id);
25
-        // make sure this is EE event
26
-        if (! $post || $post->post_type !== EspressoPostType::EVENTS) {
27
-            return $html;
28
-        }
29
-        $href  = EEH_URL::add_query_args_and_nonce(
30
-            ['action' => 'duplicate_event', 'EVT_ID' => $post_id],
31
-            admin_url('admin.php?page=espresso_events')
32
-        );
33
-        $title = esc_attr__('Duplicate', 'event_espresso');
34
-        $html  .= "
18
+	public static function addButton(string $html, int $post_id): string
19
+	{
20
+		// make sure this is only when editing
21
+		if (empty($post_id)) {
22
+			return $html;
23
+		}
24
+		$post = get_post($post_id);
25
+		// make sure this is EE event
26
+		if (! $post || $post->post_type !== EspressoPostType::EVENTS) {
27
+			return $html;
28
+		}
29
+		$href  = EEH_URL::add_query_args_and_nonce(
30
+			['action' => 'duplicate_event', 'EVT_ID' => $post_id],
31
+			admin_url('admin.php?page=espresso_events')
32
+		);
33
+		$title = esc_attr__('Duplicate', 'event_espresso');
34
+		$html  .= "
35 35
             <a aria-label='$title'
36 36
                class='button button--tiny button--secondary'
37 37
                href='$href'
@@ -41,6 +41,6 @@  discard block
 block discarded – undo
41 41
                 <span class='dashicons dashicons-admin-page'></span>
42 42
                 $title
43 43
             </a>";
44
-        return $html;
45
-    }
44
+		return $html;
45
+	}
46 46
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@
 block discarded – undo
23 23
         }
24 24
         $post = get_post($post_id);
25 25
         // make sure this is EE event
26
-        if (! $post || $post->post_type !== EspressoPostType::EVENTS) {
26
+        if ( ! $post || $post->post_type !== EspressoPostType::EVENTS) {
27 27
             return $html;
28 28
         }
29
-        $href  = EEH_URL::add_query_args_and_nonce(
29
+        $href = EEH_URL::add_query_args_and_nonce(
30 30
             ['action' => 'duplicate_event', 'EVT_ID' => $post_id],
31 31
             admin_url('admin.php?page=espresso_events')
32 32
         );
33 33
         $title = esc_attr__('Duplicate', 'event_espresso');
34
-        $html  .= "
34
+        $html .= "
35 35
             <a aria-label='$title'
36 36
                class='button button--tiny button--secondary'
37 37
                href='$href'
Please login to merge, or discard this patch.
domain/services/admin/events/editor/ui/TicketSelectorShortcodeButton.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -14,22 +14,22 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class TicketSelectorShortcodeButton extends PermalinkHtmlHook
16 16
 {
17
-    public static function addButton(string $html, int $post_id): string
18
-    {
19
-        // make sure this is only when editing
20
-        if (empty($post_id)) {
21
-            return $html;
22
-        }
23
-        $post = get_post($post_id);
24
-        // make sure this is EE event
25
-        if (! $post || $post->post_type !== EspressoPostType::EVENTS) {
26
-            return $html;
27
-        }
28
-        $onclick   =
29
-            'prompt("Ticket Selector Shortcode:", jQuery("#espresso-ticket-selector-shortlink").val()); return false;';
30
-        $shortcode = esc_attr("[ESPRESSO_TICKET_SELECTOR event_id='$post_id']");
31
-        $title     = esc_html__('Ticket Selector Shortcode', 'event_espresso');
32
-        $html      .= "
17
+	public static function addButton(string $html, int $post_id): string
18
+	{
19
+		// make sure this is only when editing
20
+		if (empty($post_id)) {
21
+			return $html;
22
+		}
23
+		$post = get_post($post_id);
24
+		// make sure this is EE event
25
+		if (! $post || $post->post_type !== EspressoPostType::EVENTS) {
26
+			return $html;
27
+		}
28
+		$onclick   =
29
+			'prompt("Ticket Selector Shortcode:", jQuery("#espresso-ticket-selector-shortlink").val()); return false;';
30
+		$shortcode = esc_attr("[ESPRESSO_TICKET_SELECTOR event_id='$post_id']");
31
+		$title     = esc_html__('Ticket Selector Shortcode', 'event_espresso');
32
+		$html      .= "
33 33
             <a class='button button--tiny button--secondary'
34 34
                onclick='$onclick'
35 35
                href='#'
@@ -39,6 +39,6 @@  discard block
 block discarded – undo
39 39
                 $title
40 40
             </a>
41 41
             <input id='espresso-ticket-selector-shortlink' type='hidden' value='$shortcode'>";
42
-        return $html;
43
-    }
42
+		return $html;
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@
 block discarded – undo
22 22
         }
23 23
         $post = get_post($post_id);
24 24
         // make sure this is EE event
25
-        if (! $post || $post->post_type !== EspressoPostType::EVENTS) {
25
+        if ( ! $post || $post->post_type !== EspressoPostType::EVENTS) {
26 26
             return $html;
27 27
         }
28 28
         $onclick   =
29 29
             'prompt("Ticket Selector Shortcode:", jQuery("#espresso-ticket-selector-shortlink").val()); return false;';
30 30
         $shortcode = esc_attr("[ESPRESSO_TICKET_SELECTOR event_id='$post_id']");
31 31
         $title     = esc_html__('Ticket Selector Shortcode', 'event_espresso');
32
-        $html      .= "
32
+        $html .= "
33 33
             <a class='button button--tiny button--secondary'
34 34
                onclick='$onclick'
35 35
                href='#'
Please login to merge, or discard this patch.