Completed
Branch ADMIN-REFRESH (b2fee6)
by
unknown
05:07 queued 02:36
created
admin_pages/registrations/EE_Registrations_List_Table.class.php 2 patches
Indentation   +1001 added lines, -1001 removed lines patch added patch discarded remove patch
@@ -15,724 +15,724 @@  discard block
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @var Registrations_Admin_Page
20
-     */
21
-    protected $_admin_page;
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    private $_status;
27
-
28
-    /**
29
-     * An array of transaction details for the related transaction to the registration being processed.
30
-     * This is set via the _set_related_details method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_transaction_details = [];
35
-
36
-    /**
37
-     * An array of event details for the related event to the registration being processed.
38
-     * This is set via the _set_related_details method.
39
-     *
40
-     * @var array
41
-     */
42
-    protected $_event_details = [];
43
-
44
-
45
-    /**
46
-     * @param Registrations_Admin_Page $admin_page
47
-     */
48
-    public function __construct(Registrations_Admin_Page $admin_page)
49
-    {
50
-        $req_data = $admin_page->get_request_data();
51
-        if (! empty($req_data['event_id'])) {
52
-            $extra_query_args = [];
53
-            foreach ($admin_page->get_views() as $view_details) {
54
-                $extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
55
-            }
56
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57
-        }
58
-        parent::__construct($admin_page);
59
-        $this->_status = $this->_admin_page->get_registration_status_array();
60
-    }
61
-
62
-
63
-    /**
64
-     * @return void
65
-     * @throws EE_Error
66
-     */
67
-    protected function _setup_data()
68
-    {
69
-        $this->_data           = $this->_admin_page->get_registrations($this->_per_page);
70
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
71
-    }
72
-
73
-
74
-    /**
75
-     * @return void
76
-     */
77
-    protected function _set_properties()
78
-    {
79
-        $return_url          = $this->getReturnUrl();
80
-        $this->_wp_list_args = [
81
-            'singular' => esc_html__('registration', 'event_espresso'),
82
-            'plural'   => esc_html__('registrations', 'event_espresso'),
83
-            'ajax'     => true,
84
-            'screen'   => $this->_admin_page->get_current_screen()->id,
85
-        ];
86
-        $req_data            = $this->_admin_page->get_request_data();
87
-        if (isset($req_data['event_id'])) {
88
-            $this->_columns        = [
89
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
90
-                'id'          => esc_html__('ID', 'event_espresso'),
91
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
92
-                'ATT_email'        => esc_html__('Email', 'event_espresso'),
93
-                '_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
94
-                'PRC_amount'       => esc_html__('TKT Price', 'event_espresso'),
95
-                '_REG_final_price' => esc_html__('Final Price', 'event_espresso'),
96
-                'TXN_total'        => esc_html__('Total Txn', 'event_espresso'),
97
-                'TXN_paid'         => esc_html__('Paid', 'event_espresso'),
98
-                'actions' => $this->actionsColumnHeader(),
99
-            ];
100
-            $this->_bottom_buttons = [
101
-                'report' => [
102
-                    'route'         => 'registrations_report',
103
-                    'extra_request' => [
104
-                        'EVT_ID'     => $this->_req_data['event_id'] ?? null,
105
-                        'return_url' => $return_url,
106
-                    ],
107
-                ],
108
-            ];
109
-        } else {
110
-            $this->_columns        = [
111
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
112
-                'id'          => esc_html__('ID', 'event_espresso'),
113
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
114
-                '_REG_date'        => esc_html__('TXN Date', 'event_espresso'),
115
-                'event_name'       => esc_html__('Event', 'event_espresso'),
116
-                'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
117
-                '_REG_final_price' => esc_html__('Price', 'event_espresso'),
118
-                '_REG_paid'        => esc_html__('Paid', 'event_espresso'),
119
-                'actions' => $this->actionsColumnHeader(),
120
-            ];
121
-            $this->_bottom_buttons = [
122
-                'report_all' => [
123
-                    'route'         => 'registrations_report',
124
-                    'extra_request' => [
125
-                        'return_url' => $return_url,
126
-                    ],
127
-                ],
128
-            ];
129
-        }
130
-        $this->_bottom_buttons['report_filtered'] = [
131
-            'route'         => 'registrations_report',
132
-            'extra_request' => [
133
-                'use_filters' => true,
134
-                'return_url'  => $return_url,
135
-            ],
136
-        ];
137
-        $filters                                  = array_diff_key(
138
-            $this->_req_data,
139
-            array_flip(
140
-                [
141
-                    'page',
142
-                    'action',
143
-                    'default_nonce',
144
-                ]
145
-            )
146
-        );
147
-        if (! empty($filters)) {
148
-            $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
149
-        }
150
-        $this->_primary_column   = 'id';
151
-        $this->_sortable_columns = [
152
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
153
-            /**
154
-             * Allows users to change the default sort if they wish.
155
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
156
-             * name.
157
-             */
158
-            'ATT_fname'     => [
159
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
160
-                true,
161
-                $this,
162
-            ]
163
-                ? ['ATT_lname' => false]
164
-                : ['ATT_fname' => false],
165
-            'event_name'    => ['event_name' => false],
166
-            'DTT_EVT_start' => ['DTT_EVT_start' => false],
167
-            'id'       => ['REG_ID' => false],
168
-        ];
169
-        $this->_hidden_columns   = [];
170
-    }
171
-
172
-
173
-    /**
174
-     * This simply sets up the row class for the table rows.
175
-     * Allows for easier overriding of child methods for setting up sorting.
176
-     *
177
-     * @param EE_Registration $registration the current item
178
-     * @return string
179
-     */
180
-    protected function _get_row_class($registration)
181
-    {
182
-        $class = parent::_get_row_class($registration);
183
-        if ($this->_has_checkbox_column) {
184
-            $class .= ' has-checkbox-column';
185
-        }
186
-        return $class;
187
-    }
188
-
189
-
190
-    /**
191
-     * Set the $_transaction_details property if not set yet.
192
-     *
193
-     * @param EE_Registration $registration
194
-     * @throws EE_Error
195
-     * @throws InvalidArgumentException
196
-     * @throws ReflectionException
197
-     * @throws InvalidDataTypeException
198
-     * @throws InvalidInterfaceException
199
-     */
200
-    protected function _set_related_details(EE_Registration $registration)
201
-    {
202
-        $transaction                = $registration->get_first_related('Transaction');
203
-        $status                     = $transaction instanceof EE_Transaction
204
-            ? $transaction->status_ID()
205
-            : EEM_Transaction::failed_status_code;
206
-        $this->_transaction_details = [
207
-            'transaction' => $transaction,
208
-            'status'      => $status,
209
-            'id'          => $transaction instanceof EE_Transaction
210
-                ? $transaction->ID()
211
-                : 0,
212
-            'title_attr'  => sprintf(
213
-                esc_html__('View Transaction Details (%s)', 'event_espresso'),
214
-                EEH_Template::pretty_status($status, false, 'sentence')
215
-            ),
216
-        ];
217
-        try {
218
-            $event = $registration->event();
219
-        } catch (EntityNotFoundException $e) {
220
-            $event = null;
221
-        }
222
-        $status               = $event instanceof EE_Event
223
-            ? $event->get_active_status()
224
-            : EE_Datetime::inactive;
225
-        $this->_event_details = [
226
-            'event'      => $event,
227
-            'status'     => $status,
228
-            'id'         => $event instanceof EE_Event
229
-                ? $event->ID()
230
-                : 0,
231
-            'title_attr' => sprintf(
232
-                esc_html__('Edit Event (%s)', 'event_espresso'),
233
-                EEH_Template::pretty_status($status, false, 'sentence')
234
-            ),
235
-        ];
236
-    }
237
-
238
-
239
-    /**
240
-     *    _get_table_filters
241
-     *
242
-     * @return array
243
-     */
244
-    protected function _get_table_filters()
245
-    {
246
-        $filters = [];
247
-        // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
248
-        // methods.
249
-        $cur_date     = $this->_req_data['month_range'] ?? '';
250
-        $cur_category = $this->_req_data['EVT_CAT'] ?? -1;
251
-        $reg_status   = $this->_req_data['_reg_status'] ?? '';
252
-        $filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
253
-        $filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
254
-        $status       = [];
255
-        $status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
256
-        foreach ($this->_status as $key => $value) {
257
-            $status[] = ['id' => $key, 'text' => $value];
258
-        }
259
-        if ($this->_view !== 'incomplete') {
260
-            $filters[] = EEH_Form_Fields::select_input(
261
-                '_reg_status',
262
-                $status,
263
-                isset($this->_req_data['_reg_status'])
264
-                    ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
265
-                    : ''
266
-            );
267
-        }
268
-        if (isset($this->_req_data['event_id'])) {
269
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
270
-        }
271
-        return $filters;
272
-    }
273
-
274
-
275
-    /**
276
-     * @return void
277
-     * @throws EE_Error
278
-     * @throws InvalidArgumentException
279
-     * @throws InvalidDataTypeException
280
-     * @throws InvalidInterfaceException
281
-     */
282
-    protected function _add_view_counts()
283
-    {
284
-        $this->_views['all']['count']   = $this->_total_registrations();
285
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
286
-        $this->_views['today']['count'] = $this->_total_registrations_today();
287
-        if (
288
-            EE_Registry::instance()->CAP->current_user_can(
289
-                'ee_delete_registrations',
290
-                'espresso_registrations_trash_registrations'
291
-            )
292
-        ) {
293
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
294
-            $this->_views['trash']['count']      = $this->_total_registrations('trash');
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * @param string $view
301
-     * @return int
302
-     * @throws EE_Error
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidDataTypeException
305
-     * @throws InvalidInterfaceException
306
-     */
307
-    protected function _total_registrations($view = '')
308
-    {
309
-        $_where = [];
310
-        $EVT_ID = isset($this->_req_data['event_id'])
311
-            ? absint($this->_req_data['event_id'])
312
-            : false;
313
-        if ($EVT_ID) {
314
-            $_where['EVT_ID'] = $EVT_ID;
315
-        }
316
-        switch ($view) {
317
-            case 'trash':
318
-                return EEM_Registration::instance()->count_deleted([$_where]);
319
-            case 'incomplete':
320
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
321
-                break;
322
-            default:
323
-                $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
324
-        }
325
-        return EEM_Registration::instance()->count([$_where]);
326
-    }
327
-
328
-
329
-    /**
330
-     * @return int
331
-     * @throws EE_Error
332
-     * @throws InvalidArgumentException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    protected function _total_registrations_this_month()
337
-    {
338
-        $EVT_ID          = isset($this->_req_data['event_id'])
339
-            ? absint($this->_req_data['event_id'])
340
-            : false;
341
-        $_where          = $EVT_ID
342
-            ? ['EVT_ID' => $EVT_ID]
343
-            : [];
344
-        $this_year_r     = date('Y', current_time('timestamp'));
345
-        $time_start      = ' 00:00:00';
346
-        $time_end        = ' 23:59:59';
347
-        $this_month_r    = date('m', current_time('timestamp'));
348
-        $days_this_month = date('t', current_time('timestamp'));
349
-        // setup date query.
350
-        $beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
351
-            'REG_date',
352
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
353
-            'Y-m-d H:i:s'
354
-        );
355
-        $end_string         = EEM_Registration::instance()->convert_datetime_for_query(
356
-            'REG_date',
357
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
358
-            'Y-m-d H:i:s'
359
-        );
360
-        $_where['REG_date'] = [
361
-            'BETWEEN',
362
-            [
363
-                $beginning_string,
364
-                $end_string,
365
-            ],
366
-        ];
367
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
368
-        return EEM_Registration::instance()->count([$_where]);
369
-    }
370
-
371
-
372
-    /**
373
-     * @return int
374
-     * @throws EE_Error
375
-     * @throws InvalidArgumentException
376
-     * @throws InvalidDataTypeException
377
-     * @throws InvalidInterfaceException
378
-     */
379
-    protected function _total_registrations_today()
380
-    {
381
-        $EVT_ID             = isset($this->_req_data['event_id'])
382
-            ? absint($this->_req_data['event_id'])
383
-            : false;
384
-        $_where             = $EVT_ID
385
-            ? ['EVT_ID' => $EVT_ID]
386
-            : [];
387
-        $current_date       = date('Y-m-d', current_time('timestamp'));
388
-        $time_start         = ' 00:00:00';
389
-        $time_end           = ' 23:59:59';
390
-        $_where['REG_date'] = [
391
-            'BETWEEN',
392
-            [
393
-                EEM_Registration::instance()->convert_datetime_for_query(
394
-                    'REG_date',
395
-                    $current_date . $time_start,
396
-                    'Y-m-d H:i:s'
397
-                ),
398
-                EEM_Registration::instance()->convert_datetime_for_query(
399
-                    'REG_date',
400
-                    $current_date . $time_end,
401
-                    'Y-m-d H:i:s'
402
-                ),
403
-            ],
404
-        ];
405
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
406
-        return EEM_Registration::instance()->count([$_where]);
407
-    }
408
-
409
-
410
-    /**
411
-     * @param EE_Registration $registration
412
-     * @return string
413
-     * @throws EE_Error
414
-     * @throws InvalidArgumentException
415
-     * @throws InvalidDataTypeException
416
-     * @throws InvalidInterfaceException
417
-     * @throws ReflectionException
418
-     */
419
-    public function column_cb($registration)
420
-    {
421
-        /** checkbox/lock **/
422
-        $REG_ID = $registration->ID();
423
-        $transaction   = $registration->get_first_related('Transaction');
424
-        $payment_count = $transaction instanceof EE_Transaction
425
-            ? $transaction->count_related('Payment')
426
-            : 0;
427
-        $content = $payment_count > 0 || ! EE_Registry::instance()->CAP->current_user_can(
428
-            'ee_edit_registration',
429
-            'registration_list_table_checkbox_input',
430
-            $REG_ID
431
-        )
432
-            ? '<input disabled type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />
18
+	/**
19
+	 * @var Registrations_Admin_Page
20
+	 */
21
+	protected $_admin_page;
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private $_status;
27
+
28
+	/**
29
+	 * An array of transaction details for the related transaction to the registration being processed.
30
+	 * This is set via the _set_related_details method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_transaction_details = [];
35
+
36
+	/**
37
+	 * An array of event details for the related event to the registration being processed.
38
+	 * This is set via the _set_related_details method.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected $_event_details = [];
43
+
44
+
45
+	/**
46
+	 * @param Registrations_Admin_Page $admin_page
47
+	 */
48
+	public function __construct(Registrations_Admin_Page $admin_page)
49
+	{
50
+		$req_data = $admin_page->get_request_data();
51
+		if (! empty($req_data['event_id'])) {
52
+			$extra_query_args = [];
53
+			foreach ($admin_page->get_views() as $view_details) {
54
+				$extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
55
+			}
56
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57
+		}
58
+		parent::__construct($admin_page);
59
+		$this->_status = $this->_admin_page->get_registration_status_array();
60
+	}
61
+
62
+
63
+	/**
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 */
67
+	protected function _setup_data()
68
+	{
69
+		$this->_data           = $this->_admin_page->get_registrations($this->_per_page);
70
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return void
76
+	 */
77
+	protected function _set_properties()
78
+	{
79
+		$return_url          = $this->getReturnUrl();
80
+		$this->_wp_list_args = [
81
+			'singular' => esc_html__('registration', 'event_espresso'),
82
+			'plural'   => esc_html__('registrations', 'event_espresso'),
83
+			'ajax'     => true,
84
+			'screen'   => $this->_admin_page->get_current_screen()->id,
85
+		];
86
+		$req_data            = $this->_admin_page->get_request_data();
87
+		if (isset($req_data['event_id'])) {
88
+			$this->_columns        = [
89
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
90
+				'id'          => esc_html__('ID', 'event_espresso'),
91
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
92
+				'ATT_email'        => esc_html__('Email', 'event_espresso'),
93
+				'_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
94
+				'PRC_amount'       => esc_html__('TKT Price', 'event_espresso'),
95
+				'_REG_final_price' => esc_html__('Final Price', 'event_espresso'),
96
+				'TXN_total'        => esc_html__('Total Txn', 'event_espresso'),
97
+				'TXN_paid'         => esc_html__('Paid', 'event_espresso'),
98
+				'actions' => $this->actionsColumnHeader(),
99
+			];
100
+			$this->_bottom_buttons = [
101
+				'report' => [
102
+					'route'         => 'registrations_report',
103
+					'extra_request' => [
104
+						'EVT_ID'     => $this->_req_data['event_id'] ?? null,
105
+						'return_url' => $return_url,
106
+					],
107
+				],
108
+			];
109
+		} else {
110
+			$this->_columns        = [
111
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
112
+				'id'          => esc_html__('ID', 'event_espresso'),
113
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
114
+				'_REG_date'        => esc_html__('TXN Date', 'event_espresso'),
115
+				'event_name'       => esc_html__('Event', 'event_espresso'),
116
+				'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
117
+				'_REG_final_price' => esc_html__('Price', 'event_espresso'),
118
+				'_REG_paid'        => esc_html__('Paid', 'event_espresso'),
119
+				'actions' => $this->actionsColumnHeader(),
120
+			];
121
+			$this->_bottom_buttons = [
122
+				'report_all' => [
123
+					'route'         => 'registrations_report',
124
+					'extra_request' => [
125
+						'return_url' => $return_url,
126
+					],
127
+				],
128
+			];
129
+		}
130
+		$this->_bottom_buttons['report_filtered'] = [
131
+			'route'         => 'registrations_report',
132
+			'extra_request' => [
133
+				'use_filters' => true,
134
+				'return_url'  => $return_url,
135
+			],
136
+		];
137
+		$filters                                  = array_diff_key(
138
+			$this->_req_data,
139
+			array_flip(
140
+				[
141
+					'page',
142
+					'action',
143
+					'default_nonce',
144
+				]
145
+			)
146
+		);
147
+		if (! empty($filters)) {
148
+			$this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
149
+		}
150
+		$this->_primary_column   = 'id';
151
+		$this->_sortable_columns = [
152
+			'_REG_date'     => ['_REG_date' => true],   // true means its already sorted
153
+			/**
154
+			 * Allows users to change the default sort if they wish.
155
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
156
+			 * name.
157
+			 */
158
+			'ATT_fname'     => [
159
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
160
+				true,
161
+				$this,
162
+			]
163
+				? ['ATT_lname' => false]
164
+				: ['ATT_fname' => false],
165
+			'event_name'    => ['event_name' => false],
166
+			'DTT_EVT_start' => ['DTT_EVT_start' => false],
167
+			'id'       => ['REG_ID' => false],
168
+		];
169
+		$this->_hidden_columns   = [];
170
+	}
171
+
172
+
173
+	/**
174
+	 * This simply sets up the row class for the table rows.
175
+	 * Allows for easier overriding of child methods for setting up sorting.
176
+	 *
177
+	 * @param EE_Registration $registration the current item
178
+	 * @return string
179
+	 */
180
+	protected function _get_row_class($registration)
181
+	{
182
+		$class = parent::_get_row_class($registration);
183
+		if ($this->_has_checkbox_column) {
184
+			$class .= ' has-checkbox-column';
185
+		}
186
+		return $class;
187
+	}
188
+
189
+
190
+	/**
191
+	 * Set the $_transaction_details property if not set yet.
192
+	 *
193
+	 * @param EE_Registration $registration
194
+	 * @throws EE_Error
195
+	 * @throws InvalidArgumentException
196
+	 * @throws ReflectionException
197
+	 * @throws InvalidDataTypeException
198
+	 * @throws InvalidInterfaceException
199
+	 */
200
+	protected function _set_related_details(EE_Registration $registration)
201
+	{
202
+		$transaction                = $registration->get_first_related('Transaction');
203
+		$status                     = $transaction instanceof EE_Transaction
204
+			? $transaction->status_ID()
205
+			: EEM_Transaction::failed_status_code;
206
+		$this->_transaction_details = [
207
+			'transaction' => $transaction,
208
+			'status'      => $status,
209
+			'id'          => $transaction instanceof EE_Transaction
210
+				? $transaction->ID()
211
+				: 0,
212
+			'title_attr'  => sprintf(
213
+				esc_html__('View Transaction Details (%s)', 'event_espresso'),
214
+				EEH_Template::pretty_status($status, false, 'sentence')
215
+			),
216
+		];
217
+		try {
218
+			$event = $registration->event();
219
+		} catch (EntityNotFoundException $e) {
220
+			$event = null;
221
+		}
222
+		$status               = $event instanceof EE_Event
223
+			? $event->get_active_status()
224
+			: EE_Datetime::inactive;
225
+		$this->_event_details = [
226
+			'event'      => $event,
227
+			'status'     => $status,
228
+			'id'         => $event instanceof EE_Event
229
+				? $event->ID()
230
+				: 0,
231
+			'title_attr' => sprintf(
232
+				esc_html__('Edit Event (%s)', 'event_espresso'),
233
+				EEH_Template::pretty_status($status, false, 'sentence')
234
+			),
235
+		];
236
+	}
237
+
238
+
239
+	/**
240
+	 *    _get_table_filters
241
+	 *
242
+	 * @return array
243
+	 */
244
+	protected function _get_table_filters()
245
+	{
246
+		$filters = [];
247
+		// todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
248
+		// methods.
249
+		$cur_date     = $this->_req_data['month_range'] ?? '';
250
+		$cur_category = $this->_req_data['EVT_CAT'] ?? -1;
251
+		$reg_status   = $this->_req_data['_reg_status'] ?? '';
252
+		$filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
253
+		$filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
254
+		$status       = [];
255
+		$status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
256
+		foreach ($this->_status as $key => $value) {
257
+			$status[] = ['id' => $key, 'text' => $value];
258
+		}
259
+		if ($this->_view !== 'incomplete') {
260
+			$filters[] = EEH_Form_Fields::select_input(
261
+				'_reg_status',
262
+				$status,
263
+				isset($this->_req_data['_reg_status'])
264
+					? strtoupper(sanitize_key($this->_req_data['_reg_status']))
265
+					: ''
266
+			);
267
+		}
268
+		if (isset($this->_req_data['event_id'])) {
269
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
270
+		}
271
+		return $filters;
272
+	}
273
+
274
+
275
+	/**
276
+	 * @return void
277
+	 * @throws EE_Error
278
+	 * @throws InvalidArgumentException
279
+	 * @throws InvalidDataTypeException
280
+	 * @throws InvalidInterfaceException
281
+	 */
282
+	protected function _add_view_counts()
283
+	{
284
+		$this->_views['all']['count']   = $this->_total_registrations();
285
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
286
+		$this->_views['today']['count'] = $this->_total_registrations_today();
287
+		if (
288
+			EE_Registry::instance()->CAP->current_user_can(
289
+				'ee_delete_registrations',
290
+				'espresso_registrations_trash_registrations'
291
+			)
292
+		) {
293
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
294
+			$this->_views['trash']['count']      = $this->_total_registrations('trash');
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * @param string $view
301
+	 * @return int
302
+	 * @throws EE_Error
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidDataTypeException
305
+	 * @throws InvalidInterfaceException
306
+	 */
307
+	protected function _total_registrations($view = '')
308
+	{
309
+		$_where = [];
310
+		$EVT_ID = isset($this->_req_data['event_id'])
311
+			? absint($this->_req_data['event_id'])
312
+			: false;
313
+		if ($EVT_ID) {
314
+			$_where['EVT_ID'] = $EVT_ID;
315
+		}
316
+		switch ($view) {
317
+			case 'trash':
318
+				return EEM_Registration::instance()->count_deleted([$_where]);
319
+			case 'incomplete':
320
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
321
+				break;
322
+			default:
323
+				$_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
324
+		}
325
+		return EEM_Registration::instance()->count([$_where]);
326
+	}
327
+
328
+
329
+	/**
330
+	 * @return int
331
+	 * @throws EE_Error
332
+	 * @throws InvalidArgumentException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	protected function _total_registrations_this_month()
337
+	{
338
+		$EVT_ID          = isset($this->_req_data['event_id'])
339
+			? absint($this->_req_data['event_id'])
340
+			: false;
341
+		$_where          = $EVT_ID
342
+			? ['EVT_ID' => $EVT_ID]
343
+			: [];
344
+		$this_year_r     = date('Y', current_time('timestamp'));
345
+		$time_start      = ' 00:00:00';
346
+		$time_end        = ' 23:59:59';
347
+		$this_month_r    = date('m', current_time('timestamp'));
348
+		$days_this_month = date('t', current_time('timestamp'));
349
+		// setup date query.
350
+		$beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
351
+			'REG_date',
352
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
353
+			'Y-m-d H:i:s'
354
+		);
355
+		$end_string         = EEM_Registration::instance()->convert_datetime_for_query(
356
+			'REG_date',
357
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
358
+			'Y-m-d H:i:s'
359
+		);
360
+		$_where['REG_date'] = [
361
+			'BETWEEN',
362
+			[
363
+				$beginning_string,
364
+				$end_string,
365
+			],
366
+		];
367
+		$_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
368
+		return EEM_Registration::instance()->count([$_where]);
369
+	}
370
+
371
+
372
+	/**
373
+	 * @return int
374
+	 * @throws EE_Error
375
+	 * @throws InvalidArgumentException
376
+	 * @throws InvalidDataTypeException
377
+	 * @throws InvalidInterfaceException
378
+	 */
379
+	protected function _total_registrations_today()
380
+	{
381
+		$EVT_ID             = isset($this->_req_data['event_id'])
382
+			? absint($this->_req_data['event_id'])
383
+			: false;
384
+		$_where             = $EVT_ID
385
+			? ['EVT_ID' => $EVT_ID]
386
+			: [];
387
+		$current_date       = date('Y-m-d', current_time('timestamp'));
388
+		$time_start         = ' 00:00:00';
389
+		$time_end           = ' 23:59:59';
390
+		$_where['REG_date'] = [
391
+			'BETWEEN',
392
+			[
393
+				EEM_Registration::instance()->convert_datetime_for_query(
394
+					'REG_date',
395
+					$current_date . $time_start,
396
+					'Y-m-d H:i:s'
397
+				),
398
+				EEM_Registration::instance()->convert_datetime_for_query(
399
+					'REG_date',
400
+					$current_date . $time_end,
401
+					'Y-m-d H:i:s'
402
+				),
403
+			],
404
+		];
405
+		$_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
406
+		return EEM_Registration::instance()->count([$_where]);
407
+	}
408
+
409
+
410
+	/**
411
+	 * @param EE_Registration $registration
412
+	 * @return string
413
+	 * @throws EE_Error
414
+	 * @throws InvalidArgumentException
415
+	 * @throws InvalidDataTypeException
416
+	 * @throws InvalidInterfaceException
417
+	 * @throws ReflectionException
418
+	 */
419
+	public function column_cb($registration)
420
+	{
421
+		/** checkbox/lock **/
422
+		$REG_ID = $registration->ID();
423
+		$transaction   = $registration->get_first_related('Transaction');
424
+		$payment_count = $transaction instanceof EE_Transaction
425
+			? $transaction->count_related('Payment')
426
+			: 0;
427
+		$content = $payment_count > 0 || ! EE_Registry::instance()->CAP->current_user_can(
428
+			'ee_edit_registration',
429
+			'registration_list_table_checkbox_input',
430
+			$REG_ID
431
+		)
432
+			? '<input disabled type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />
433 433
                 <span class="dashicons dashicons-lock"></span>'
434
-            : '<input type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />';
435
-
436
-        return $this->columnContent('cb', $content, 'center');
437
-    }
438
-
439
-
440
-    /**
441
-     * @param EE_Registration $registration
442
-     * @return string
443
-     * @throws EE_Error
444
-     * @throws InvalidArgumentException
445
-     * @throws InvalidDataTypeException
446
-     * @throws InvalidInterfaceException
447
-     * @throws ReflectionException
448
-     */
449
-    public function column_id(EE_Registration $registration)
450
-    {
451
-        $content  = $registration->ID();
452
-        $content .= '<span class="show-on-mobile-view-only">';
453
-        $content  .= $this->column_ATT_fname($registration, false);
454
-        $content .= '</span>';
455
-
456
-        return $this->columnContent('id', $content, 'end');
457
-    }
458
-
459
-
460
-    /**
461
-     * @param EE_Registration $registration
462
-     * @return string
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws InvalidDataTypeException
466
-     * @throws InvalidInterfaceException
467
-     * @throws ReflectionException
468
-     */
469
-    public function column_ATT_fname(EE_Registration $registration, $prep_content = true)
470
-    {
471
-        $attendee      = $registration->attendee();
472
-        $edit_link_url  = EE_Admin_Page::add_query_args_and_nonce(
473
-            [
474
-                'action'  => 'view_registration',
475
-                '_REG_ID' => $registration->ID(),
476
-            ],
477
-            REG_ADMIN_URL
478
-        );
479
-        $attendee_name = $attendee instanceof EE_Attendee
480
-            ? $attendee->full_name()
481
-            : '';
482
-
483
-        $status        = esc_attr($registration->status_ID());
484
-        $pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
485
-
486
-        $content = '
434
+			: '<input type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />';
435
+
436
+		return $this->columnContent('cb', $content, 'center');
437
+	}
438
+
439
+
440
+	/**
441
+	 * @param EE_Registration $registration
442
+	 * @return string
443
+	 * @throws EE_Error
444
+	 * @throws InvalidArgumentException
445
+	 * @throws InvalidDataTypeException
446
+	 * @throws InvalidInterfaceException
447
+	 * @throws ReflectionException
448
+	 */
449
+	public function column_id(EE_Registration $registration)
450
+	{
451
+		$content  = $registration->ID();
452
+		$content .= '<span class="show-on-mobile-view-only">';
453
+		$content  .= $this->column_ATT_fname($registration, false);
454
+		$content .= '</span>';
455
+
456
+		return $this->columnContent('id', $content, 'end');
457
+	}
458
+
459
+
460
+	/**
461
+	 * @param EE_Registration $registration
462
+	 * @return string
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws InvalidDataTypeException
466
+	 * @throws InvalidInterfaceException
467
+	 * @throws ReflectionException
468
+	 */
469
+	public function column_ATT_fname(EE_Registration $registration, $prep_content = true)
470
+	{
471
+		$attendee      = $registration->attendee();
472
+		$edit_link_url  = EE_Admin_Page::add_query_args_and_nonce(
473
+			[
474
+				'action'  => 'view_registration',
475
+				'_REG_ID' => $registration->ID(),
476
+			],
477
+			REG_ADMIN_URL
478
+		);
479
+		$attendee_name = $attendee instanceof EE_Attendee
480
+			? $attendee->full_name()
481
+			: '';
482
+
483
+		$status        = esc_attr($registration->status_ID());
484
+		$pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
485
+
486
+		$content = '
487 487
         <div class="ee-layout-row">
488 488
             <span aria-label="' . $pretty_status . '" 
489 489
                   class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"
490 490
             ></span>';
491 491
 
492
-        $content .= EE_Registry::instance()->CAP->current_user_can(
493
-            'ee_read_registration',
494
-            'espresso_registrations_view_registration',
495
-            $registration->ID()
496
-        )
497
-            ? '
492
+		$content .= EE_Registry::instance()->CAP->current_user_can(
493
+			'ee_read_registration',
494
+			'espresso_registrations_view_registration',
495
+			$registration->ID()
496
+		)
497
+			? '
498 498
             <a  href="' . $edit_link_url . '"  
499 499
                 class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" 
500 500
                 aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
501 501
             >
502 502
                 ' . $attendee_name . '
503 503
             </a>'
504
-            : $attendee_name;
505
-
506
-        $content .= $registration->count() === 1
507
-            ? '<sup><span class="dashicons dashicons-star-filled gold-icon"></span></sup>'
508
-            : '';
509
-
510
-        $transaction   = $registration->get_first_related('Transaction');
511
-        $payment_count = $transaction instanceof EE_Transaction
512
-            ? $transaction->count_related('Payment')
513
-            : 0;
514
-
515
-        // append group count to name
516
-        $content .= '<span class="reg-count-group-size">';
517
-        $content .= sprintf(
518
-            esc_html__('(%1$s / %2$s)', 'event_espresso'),
519
-            $registration->count(),
520
-            $registration->group_size()
521
-        );
522
-        $content .= '</span>
504
+			: $attendee_name;
505
+
506
+		$content .= $registration->count() === 1
507
+			? '<sup><span class="dashicons dashicons-star-filled gold-icon"></span></sup>'
508
+			: '';
509
+
510
+		$transaction   = $registration->get_first_related('Transaction');
511
+		$payment_count = $transaction instanceof EE_Transaction
512
+			? $transaction->count_related('Payment')
513
+			: 0;
514
+
515
+		// append group count to name
516
+		$content .= '<span class="reg-count-group-size">';
517
+		$content .= sprintf(
518
+			esc_html__('(%1$s / %2$s)', 'event_espresso'),
519
+			$registration->count(),
520
+			$registration->group_size()
521
+		);
522
+		$content .= '</span>
523 523
         </div>';
524 524
 
525
-        // append reg_code
526
-        $content .= sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $registration->get('REG_code'));
527
-        $action = ['_REG_ID' => $registration->ID()];
528
-        if (isset($this->_req_data['event_id'])) {
529
-            $action['event_id'] = $registration->event_ID();
530
-        }
531
-        // trash/restore/delete actions
532
-        $actions = [];
533
-        if (
534
-            $this->_view !== 'trash'
535
-            && $payment_count === 0
536
-            && EE_Registry::instance()->CAP->current_user_can(
537
-                'ee_delete_registration',
538
-                'espresso_registrations_trash_registrations',
539
-                $registration->ID()
540
-            )
541
-        ) {
542
-            $action['action'] = 'trash_registrations';
543
-            $trash_link_url    = EE_Admin_Page::add_query_args_and_nonce(
544
-                $action,
545
-                REG_ADMIN_URL
546
-            );
547
-            $actions['trash'] = '<a class="ee-aria-tooltip" href="'
548
-                                . $trash_link_url
549
-                                . '" aria-label="'
550
-                                . esc_attr__('Trash Registration', 'event_espresso')
551
-                                . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
552
-        } elseif ($this->_view === 'trash') {
553
-            // restore registration link
554
-            if (
555
-                EE_Registry::instance()->CAP->current_user_can(
556
-                    'ee_delete_registration',
557
-                    'espresso_registrations_restore_registrations',
558
-                    $registration->ID()
559
-                )
560
-            ) {
561
-                $action['action']   = 'restore_registrations';
562
-                $restore_link_url    = EE_Admin_Page::add_query_args_and_nonce(
563
-                    $action,
564
-                    REG_ADMIN_URL
565
-                );
566
-                $actions['restore'] = '<a class="ee-aria-tooltip" href="'
567
-                                      . $restore_link_url
568
-                                      . '" aria-label="'
569
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
570
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
571
-            }
572
-            if (
573
-                EE_Registry::instance()->CAP->current_user_can(
574
-                    'ee_delete_registration',
575
-                    'espresso_registrations_ee_delete_registrations',
576
-                    $registration->ID()
577
-                )
578
-            ) {
579
-                $action['action']  = 'delete_registrations';
580
-                $delete_link_url    = EE_Admin_Page::add_query_args_and_nonce(
581
-                    $action,
582
-                    REG_ADMIN_URL
583
-                );
584
-                $actions['delete'] = '<a class="ee-aria-tooltip" href="'
585
-                                     . $delete_link_url
586
-                                     . '" aria-label="'
587
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
588
-                                     . '">'
589
-                                     . esc_html__('Delete', 'event_espresso')
590
-                                     . '</a>';
591
-            }
592
-        }
593
-        $content = sprintf('%1$s %2$s', $content, $this->row_actions($actions));
594
-
595
-        return $prep_content ? $this->columnContent('ATT_fname', $content) : $content;
596
-    }
597
-
598
-
599
-    /**
600
-     * @param EE_Registration $registration
601
-     * @return string
602
-     * @throws EE_Error
603
-     * @throws InvalidArgumentException
604
-     * @throws InvalidDataTypeException
605
-     * @throws InvalidInterfaceException
606
-     * @throws ReflectionException
607
-     */
608
-    public function column__REG_date(EE_Registration $registration, $prep_content = true)
609
-    {
610
-        $this->_set_related_details($registration);
611
-        // Build row actions
612
-        $view_link_url = EE_Admin_Page::add_query_args_and_nonce(
613
-            [
614
-                'action' => 'view_transaction',
615
-                'TXN_ID' => $this->_transaction_details['id'],
616
-            ],
617
-            TXN_ADMIN_URL
618
-        );
619
-        $content    = EE_Registry::instance()->CAP->current_user_can(
620
-            'ee_read_transaction',
621
-            'espresso_transactions_view_transaction'
622
-        )
623
-            ? '<a class="ee-aria-tooltip ee-status-color--' . $this->_transaction_details['status'] . '" href="'
624
-              . $view_link_url
625
-              . '" aria-label="'
626
-              . esc_attr($this->_transaction_details['title_attr'])
627
-              . '">'
628
-              . $registration->get_i18n_datetime('REG_date', 'M jS Y g:i a')
629
-              . '</a>'
630
-            : $registration->get_i18n_datetime('REG_date');
631
-
632
-        $content .= ' <span class="ee-status-text-small">'
633
-                    . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
634
-                    . '</span>';
635
-
636
-        return $prep_content ? $this->columnContent('_REG_date', $content) : $content;
637
-    }
638
-
639
-
640
-    /**
641
-     * @param EE_Registration $registration
642
-     * @return string
643
-     * @throws EE_Error
644
-     * @throws InvalidArgumentException
645
-     * @throws InvalidDataTypeException
646
-     * @throws InvalidInterfaceException
647
-     * @throws ReflectionException
648
-     */
649
-    public function column_event_name(EE_Registration $registration)
650
-    {
651
-        $this->_set_related_details($registration);
652
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
653
-        $EVT_ID     = $registration->event_ID();
654
-        $event_name = $registration->event_name();
655
-        $event_name =
656
-            $event_name
657
-                ?: esc_html__("No Associated Event", 'event_espresso');
658
-        $event_name = wp_trim_words($event_name, 30, '...');
659
-        if ($EVT_ID) {
660
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
661
-                ['action' => 'edit', 'post' => $EVT_ID],
662
-                EVENTS_ADMIN_URL
663
-            );
664
-            $edit_event              =
665
-                EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
666
-                    ? '<a class="ee-aria-tooltip ee-status-color--'
667
-                      . $this->_event_details['status']
668
-                      . '" href="'
669
-                      . $edit_event_url
670
-                      . '" aria-label="'
671
-                      . esc_attr($this->_event_details['title_attr'])
672
-                      . '">'
673
-                      . $event_name
674
-                      . '</a>'
675
-                    : $event_name;
676
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
677
-            $actions['event_filter'] = '
525
+		// append reg_code
526
+		$content .= sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $registration->get('REG_code'));
527
+		$action = ['_REG_ID' => $registration->ID()];
528
+		if (isset($this->_req_data['event_id'])) {
529
+			$action['event_id'] = $registration->event_ID();
530
+		}
531
+		// trash/restore/delete actions
532
+		$actions = [];
533
+		if (
534
+			$this->_view !== 'trash'
535
+			&& $payment_count === 0
536
+			&& EE_Registry::instance()->CAP->current_user_can(
537
+				'ee_delete_registration',
538
+				'espresso_registrations_trash_registrations',
539
+				$registration->ID()
540
+			)
541
+		) {
542
+			$action['action'] = 'trash_registrations';
543
+			$trash_link_url    = EE_Admin_Page::add_query_args_and_nonce(
544
+				$action,
545
+				REG_ADMIN_URL
546
+			);
547
+			$actions['trash'] = '<a class="ee-aria-tooltip" href="'
548
+								. $trash_link_url
549
+								. '" aria-label="'
550
+								. esc_attr__('Trash Registration', 'event_espresso')
551
+								. '">' . esc_html__('Trash', 'event_espresso') . '</a>';
552
+		} elseif ($this->_view === 'trash') {
553
+			// restore registration link
554
+			if (
555
+				EE_Registry::instance()->CAP->current_user_can(
556
+					'ee_delete_registration',
557
+					'espresso_registrations_restore_registrations',
558
+					$registration->ID()
559
+				)
560
+			) {
561
+				$action['action']   = 'restore_registrations';
562
+				$restore_link_url    = EE_Admin_Page::add_query_args_and_nonce(
563
+					$action,
564
+					REG_ADMIN_URL
565
+				);
566
+				$actions['restore'] = '<a class="ee-aria-tooltip" href="'
567
+									  . $restore_link_url
568
+									  . '" aria-label="'
569
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
570
+									  . esc_html__('Restore', 'event_espresso') . '</a>';
571
+			}
572
+			if (
573
+				EE_Registry::instance()->CAP->current_user_can(
574
+					'ee_delete_registration',
575
+					'espresso_registrations_ee_delete_registrations',
576
+					$registration->ID()
577
+				)
578
+			) {
579
+				$action['action']  = 'delete_registrations';
580
+				$delete_link_url    = EE_Admin_Page::add_query_args_and_nonce(
581
+					$action,
582
+					REG_ADMIN_URL
583
+				);
584
+				$actions['delete'] = '<a class="ee-aria-tooltip" href="'
585
+									 . $delete_link_url
586
+									 . '" aria-label="'
587
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
588
+									 . '">'
589
+									 . esc_html__('Delete', 'event_espresso')
590
+									 . '</a>';
591
+			}
592
+		}
593
+		$content = sprintf('%1$s %2$s', $content, $this->row_actions($actions));
594
+
595
+		return $prep_content ? $this->columnContent('ATT_fname', $content) : $content;
596
+	}
597
+
598
+
599
+	/**
600
+	 * @param EE_Registration $registration
601
+	 * @return string
602
+	 * @throws EE_Error
603
+	 * @throws InvalidArgumentException
604
+	 * @throws InvalidDataTypeException
605
+	 * @throws InvalidInterfaceException
606
+	 * @throws ReflectionException
607
+	 */
608
+	public function column__REG_date(EE_Registration $registration, $prep_content = true)
609
+	{
610
+		$this->_set_related_details($registration);
611
+		// Build row actions
612
+		$view_link_url = EE_Admin_Page::add_query_args_and_nonce(
613
+			[
614
+				'action' => 'view_transaction',
615
+				'TXN_ID' => $this->_transaction_details['id'],
616
+			],
617
+			TXN_ADMIN_URL
618
+		);
619
+		$content    = EE_Registry::instance()->CAP->current_user_can(
620
+			'ee_read_transaction',
621
+			'espresso_transactions_view_transaction'
622
+		)
623
+			? '<a class="ee-aria-tooltip ee-status-color--' . $this->_transaction_details['status'] . '" href="'
624
+			  . $view_link_url
625
+			  . '" aria-label="'
626
+			  . esc_attr($this->_transaction_details['title_attr'])
627
+			  . '">'
628
+			  . $registration->get_i18n_datetime('REG_date', 'M jS Y g:i a')
629
+			  . '</a>'
630
+			: $registration->get_i18n_datetime('REG_date');
631
+
632
+		$content .= ' <span class="ee-status-text-small">'
633
+					. EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
634
+					. '</span>';
635
+
636
+		return $prep_content ? $this->columnContent('_REG_date', $content) : $content;
637
+	}
638
+
639
+
640
+	/**
641
+	 * @param EE_Registration $registration
642
+	 * @return string
643
+	 * @throws EE_Error
644
+	 * @throws InvalidArgumentException
645
+	 * @throws InvalidDataTypeException
646
+	 * @throws InvalidInterfaceException
647
+	 * @throws ReflectionException
648
+	 */
649
+	public function column_event_name(EE_Registration $registration)
650
+	{
651
+		$this->_set_related_details($registration);
652
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
653
+		$EVT_ID     = $registration->event_ID();
654
+		$event_name = $registration->event_name();
655
+		$event_name =
656
+			$event_name
657
+				?: esc_html__("No Associated Event", 'event_espresso');
658
+		$event_name = wp_trim_words($event_name, 30, '...');
659
+		if ($EVT_ID) {
660
+			$edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
661
+				['action' => 'edit', 'post' => $EVT_ID],
662
+				EVENTS_ADMIN_URL
663
+			);
664
+			$edit_event              =
665
+				EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
666
+					? '<a class="ee-aria-tooltip ee-status-color--'
667
+					  . $this->_event_details['status']
668
+					  . '" href="'
669
+					  . $edit_event_url
670
+					  . '" aria-label="'
671
+					  . esc_attr($this->_event_details['title_attr'])
672
+					  . '">'
673
+					  . $event_name
674
+					  . '</a>'
675
+					: $event_name;
676
+			$edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
677
+			$actions['event_filter'] = '
678 678
                 <a  class="ee-aria-tooltip ee-event-filter-link" href="' . $edit_event_url . '" 
679 679
                     aria-label="' . sprintf(
680
-                        esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
681
-                        $event_name
682
-                    ) .'">
680
+						esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
681
+						$event_name
682
+					) .'">
683 683
                     <span class="dashicons dashicons-groups dashicons--small"></span>'
684
-                    . esc_html__('View Registrations', 'event_espresso') .
685
-                '</a>';
686
-        } else {
687
-            $edit_event              = $event_name;
688
-            $actions['event_filter'] = '';
689
-        }
690
-        $content = sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
691
-
692
-        return $this->columnContent('event_name', $content);
693
-    }
694
-
695
-
696
-    /**
697
-     * @param EE_Registration $registration
698
-     * @return string
699
-     * @throws EE_Error
700
-     * @throws InvalidArgumentException
701
-     * @throws InvalidDataTypeException
702
-     * @throws InvalidInterfaceException
703
-     * @throws ReflectionException
704
-     */
705
-    public function column_DTT_EVT_start(EE_Registration $registration)
706
-    {
707
-        $datetime_strings = [];
708
-        $ticket           = $registration->ticket();
709
-        if ($ticket instanceof EE_Ticket) {
710
-            $remove_defaults = ['default_where_conditions' => 'none'];
711
-            $datetimes       = $ticket->datetimes($remove_defaults);
712
-            foreach ($datetimes as $datetime) {
713
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a');
714
-            }
715
-            $content = $this->generateDisplayForDatetimes($datetime_strings);
716
-        } else {
717
-            $content = esc_html__('There is no ticket on this registration', 'event_espresso');
718
-        }
719
-        return $this->columnContent('DTT_EVT_start', $content);
720
-    }
721
-
722
-
723
-    /**
724
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
725
-     *
726
-     * @param array $datetime_strings
727
-     * @return string
728
-     */
729
-    public function generateDisplayForDatetimes(array $datetime_strings): string
730
-    {
731
-        // $content       = '<div class="ee-registration-event-datetimes-container">';
732
-        // get first item for initial visibility
733
-        $content = array_shift($datetime_strings);
734
-        if (! empty($datetime_strings)) {
735
-            $content .= '
684
+					. esc_html__('View Registrations', 'event_espresso') .
685
+				'</a>';
686
+		} else {
687
+			$edit_event              = $event_name;
688
+			$actions['event_filter'] = '';
689
+		}
690
+		$content = sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
691
+
692
+		return $this->columnContent('event_name', $content);
693
+	}
694
+
695
+
696
+	/**
697
+	 * @param EE_Registration $registration
698
+	 * @return string
699
+	 * @throws EE_Error
700
+	 * @throws InvalidArgumentException
701
+	 * @throws InvalidDataTypeException
702
+	 * @throws InvalidInterfaceException
703
+	 * @throws ReflectionException
704
+	 */
705
+	public function column_DTT_EVT_start(EE_Registration $registration)
706
+	{
707
+		$datetime_strings = [];
708
+		$ticket           = $registration->ticket();
709
+		if ($ticket instanceof EE_Ticket) {
710
+			$remove_defaults = ['default_where_conditions' => 'none'];
711
+			$datetimes       = $ticket->datetimes($remove_defaults);
712
+			foreach ($datetimes as $datetime) {
713
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start', 'M jS Y g:i a');
714
+			}
715
+			$content = $this->generateDisplayForDatetimes($datetime_strings);
716
+		} else {
717
+			$content = esc_html__('There is no ticket on this registration', 'event_espresso');
718
+		}
719
+		return $this->columnContent('DTT_EVT_start', $content);
720
+	}
721
+
722
+
723
+	/**
724
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
725
+	 *
726
+	 * @param array $datetime_strings
727
+	 * @return string
728
+	 */
729
+	public function generateDisplayForDatetimes(array $datetime_strings): string
730
+	{
731
+		// $content       = '<div class="ee-registration-event-datetimes-container">';
732
+		// get first item for initial visibility
733
+		$content = array_shift($datetime_strings);
734
+		if (! empty($datetime_strings)) {
735
+			$content .= '
736 736
                 <div class="ee-registration-event-datetimes-container-wrap">
737 737
                     <button aria-label="' . esc_attr__('Click to view all dates', 'event_espresso') . '" 
738 738
                           class="ee-aria-tooltip button button--secondary button--tiny button--icon-only ee-js ee-more-datetimes-toggle"
@@ -743,348 +743,348 @@  discard block
 block discarded – undo
743 743
                         ' . implode("", $datetime_strings) . '
744 744
                     </div>
745 745
                 </div>';
746
-        }
747
-        // $content .= '</div>';
748
-        return $content;
749
-    }
750
-
751
-
752
-    /**
753
-     * @param EE_Registration $registration
754
-     * @return string
755
-     * @throws EE_Error
756
-     * @throws InvalidArgumentException
757
-     * @throws InvalidDataTypeException
758
-     * @throws InvalidInterfaceException
759
-     * @throws ReflectionException
760
-     */
761
-    public function column_ATT_email(EE_Registration $registration)
762
-    {
763
-        $attendee = $registration->get_first_related('Attendee');
764
-        $content = ! $attendee instanceof EE_Attendee
765
-            ? esc_html__('No attached contact record.', 'event_espresso')
766
-            : $attendee->email();
767
-        return $this->columnContent('ATT_email', $content);
768
-    }
769
-
770
-
771
-    /**
772
-     * @param EE_Registration $registration
773
-     * @return string
774
-     */
775
-    public function column__REG_count(EE_Registration $registration)
776
-    {
777
-        $content = sprintf(esc_html__('%1$s / %2$s', 'event_espresso'), $registration->count(), $registration->group_size());
778
-        return $this->columnContent('_REG_count', $content);
779
-    }
780
-
781
-
782
-    /**
783
-     * @param EE_Registration $registration
784
-     * @return string
785
-     * @throws EE_Error
786
-     * @throws ReflectionException
787
-     */
788
-    public function column_PRC_amount(EE_Registration $registration)
789
-    {
790
-        $ticket   = $registration->ticket();
791
-        $req_data = $this->_admin_page->get_request_data();
792
-
793
-        $content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
794
-            ? '<div class="TKT_name">' . $ticket->name() . '</div>'
795
-            : '';
746
+		}
747
+		// $content .= '</div>';
748
+		return $content;
749
+	}
750
+
751
+
752
+	/**
753
+	 * @param EE_Registration $registration
754
+	 * @return string
755
+	 * @throws EE_Error
756
+	 * @throws InvalidArgumentException
757
+	 * @throws InvalidDataTypeException
758
+	 * @throws InvalidInterfaceException
759
+	 * @throws ReflectionException
760
+	 */
761
+	public function column_ATT_email(EE_Registration $registration)
762
+	{
763
+		$attendee = $registration->get_first_related('Attendee');
764
+		$content = ! $attendee instanceof EE_Attendee
765
+			? esc_html__('No attached contact record.', 'event_espresso')
766
+			: $attendee->email();
767
+		return $this->columnContent('ATT_email', $content);
768
+	}
769
+
770
+
771
+	/**
772
+	 * @param EE_Registration $registration
773
+	 * @return string
774
+	 */
775
+	public function column__REG_count(EE_Registration $registration)
776
+	{
777
+		$content = sprintf(esc_html__('%1$s / %2$s', 'event_espresso'), $registration->count(), $registration->group_size());
778
+		return $this->columnContent('_REG_count', $content);
779
+	}
780
+
781
+
782
+	/**
783
+	 * @param EE_Registration $registration
784
+	 * @return string
785
+	 * @throws EE_Error
786
+	 * @throws ReflectionException
787
+	 */
788
+	public function column_PRC_amount(EE_Registration $registration)
789
+	{
790
+		$ticket   = $registration->ticket();
791
+		$req_data = $this->_admin_page->get_request_data();
792
+
793
+		$content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
794
+			? '<div class="TKT_name">' . $ticket->name() . '</div>'
795
+			: '';
796 796
         
797
-        $payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
798
-        $content .= $registration->final_price() > 0
799
-            ? '<span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
797
+		$payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
798
+		$content .= $registration->final_price() > 0
799
+			? '<span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
800 800
                 ' . $registration->pretty_final_price() . '
801 801
                </span>'
802
-            // free event
803
-            : '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
804
-
805
-        return $this->columnContent('PRC_amount', $content, 'end');
806
-    }
807
-
808
-
809
-    /**
810
-     * @param EE_Registration $registration
811
-     * @return string
812
-     * @throws EE_Error
813
-     * @throws ReflectionException
814
-     */
815
-    public function column__REG_final_price(EE_Registration $registration)
816
-    {
817
-        $ticket   = $registration->ticket();
818
-        $req_data = $this->_admin_page->get_request_data();
819
-        $content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
820
-            ? ''
821
-            : '<span class="TKT_name ee-status-color--' . $ticket->ticket_status() . '">' . $ticket->name() . '</span> ';
822
-
823
-        $content  .= '
802
+			// free event
803
+			: '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
804
+
805
+		return $this->columnContent('PRC_amount', $content, 'end');
806
+	}
807
+
808
+
809
+	/**
810
+	 * @param EE_Registration $registration
811
+	 * @return string
812
+	 * @throws EE_Error
813
+	 * @throws ReflectionException
814
+	 */
815
+	public function column__REG_final_price(EE_Registration $registration)
816
+	{
817
+		$ticket   = $registration->ticket();
818
+		$req_data = $this->_admin_page->get_request_data();
819
+		$content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
820
+			? ''
821
+			: '<span class="TKT_name ee-status-color--' . $ticket->ticket_status() . '">' . $ticket->name() . '</span> ';
822
+
823
+		$content  .= '
824 824
             <span class="reg-overview-paid-event-spn">
825 825
                 ' . $registration->pretty_final_price() . '
826 826
             </span>';
827
-        return $this->columnContent('_REG_final_price', $content, 'end');
828
-    }
829
-
830
-
831
-    /**
832
-     * @param EE_Registration $registration
833
-     * @return string
834
-     * @throws EE_Error
835
-     */
836
-    public function column__REG_paid(EE_Registration $registration)
837
-    {
838
-        $payment_method      = $registration->payment_method();
839
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
840
-            ? $payment_method->admin_name()
841
-            : esc_html__('Unknown', 'event_espresso');
842
-
843
-        $payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
844
-        $content        = '
827
+		return $this->columnContent('_REG_final_price', $content, 'end');
828
+	}
829
+
830
+
831
+	/**
832
+	 * @param EE_Registration $registration
833
+	 * @return string
834
+	 * @throws EE_Error
835
+	 */
836
+	public function column__REG_paid(EE_Registration $registration)
837
+	{
838
+		$payment_method      = $registration->payment_method();
839
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
840
+			? $payment_method->admin_name()
841
+			: esc_html__('Unknown', 'event_espresso');
842
+
843
+		$payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
844
+		$content        = '
845 845
             <span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
846 846
                 ' . $registration->pretty_paid() . '
847 847
             </span>';
848
-        if ($registration->paid() > 0) {
849
-            $content .= '<span class="ee-status-text-small">'
850
-                        . sprintf(
851
-                            esc_html__('...via %s', 'event_espresso'),
852
-                            $payment_method_name
853
-                        )
854
-                        . '</span>';
855
-        }
856
-        return $this->columnContent('_REG_paid', $content, 'end');
857
-    }
858
-
859
-
860
-    /**
861
-     * @param EE_Registration $registration
862
-     * @return string
863
-     * @throws EE_Error
864
-     * @throws EntityNotFoundException
865
-     * @throws InvalidArgumentException
866
-     * @throws InvalidDataTypeException
867
-     * @throws InvalidInterfaceException
868
-     * @throws ReflectionException
869
-     */
870
-    public function column_TXN_total(EE_Registration $registration)
871
-    {
872
-        if ($registration->transaction()) {
873
-            $view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
874
-                [
875
-                    'action' => 'view_transaction',
876
-                    'TXN_ID' => $registration->transaction_ID(),
877
-                ],
878
-                TXN_ADMIN_URL
879
-            );
880
-            $content = EE_Registry::instance()->CAP->current_user_can(
881
-                'ee_read_transaction',
882
-                'espresso_transactions_view_transaction',
883
-                $registration->transaction_ID()
884
-            )
885
-                ? '
848
+		if ($registration->paid() > 0) {
849
+			$content .= '<span class="ee-status-text-small">'
850
+						. sprintf(
851
+							esc_html__('...via %s', 'event_espresso'),
852
+							$payment_method_name
853
+						)
854
+						. '</span>';
855
+		}
856
+		return $this->columnContent('_REG_paid', $content, 'end');
857
+	}
858
+
859
+
860
+	/**
861
+	 * @param EE_Registration $registration
862
+	 * @return string
863
+	 * @throws EE_Error
864
+	 * @throws EntityNotFoundException
865
+	 * @throws InvalidArgumentException
866
+	 * @throws InvalidDataTypeException
867
+	 * @throws InvalidInterfaceException
868
+	 * @throws ReflectionException
869
+	 */
870
+	public function column_TXN_total(EE_Registration $registration)
871
+	{
872
+		if ($registration->transaction()) {
873
+			$view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
874
+				[
875
+					'action' => 'view_transaction',
876
+					'TXN_ID' => $registration->transaction_ID(),
877
+				],
878
+				TXN_ADMIN_URL
879
+			);
880
+			$content = EE_Registry::instance()->CAP->current_user_can(
881
+				'ee_read_transaction',
882
+				'espresso_transactions_view_transaction',
883
+				$registration->transaction_ID()
884
+			)
885
+				? '
886 886
                     <a class="ee-aria-tooltip ee-status-color--' . $registration->transaction()->status_ID() . '" 
887 887
                         href="' . $view_txn_link_url . '" 
888 888
                         aria-label="' . esc_attr__('View Transaction', 'event_espresso') . '"
889 889
                     >
890 890
                         ' . $registration->transaction()->pretty_total() . '
891 891
                     </a>'
892
-                : $registration->transaction()->pretty_total();
893
-        } else {
894
-            $content = esc_html__("None", "event_espresso");
895
-        }
896
-        return $this->columnContent('TXN_total', $content, 'end');
897
-    }
898
-
899
-
900
-    /**
901
-     * @param EE_Registration $registration
902
-     * @return string
903
-     * @throws EE_Error
904
-     * @throws EntityNotFoundException
905
-     * @throws InvalidArgumentException
906
-     * @throws InvalidDataTypeException
907
-     * @throws InvalidInterfaceException
908
-     * @throws ReflectionException
909
-     */
910
-    public function column_TXN_paid(EE_Registration $registration)
911
-    {
912
-        $content = '&nbsp;';
913
-        $align = 'end';
914
-        if ($registration->count() === 1) {
915
-            $transaction = $registration->transaction()
916
-                ? $registration->transaction()
917
-                : EE_Transaction::new_instance();
918
-            if ($transaction->paid() >= $transaction->total()) {
919
-                $align = 'center';
920
-                $content = '<span class="dashicons dashicons-yes green-icon"></span>';
921
-            } else {
922
-                $view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
923
-                    [
924
-                        'action' => 'view_transaction',
925
-                        'TXN_ID' => $registration->transaction_ID(),
926
-                    ],
927
-                    TXN_ADMIN_URL
928
-                );
929
-                $content = EE_Registry::instance()->CAP->current_user_can(
930
-                    'ee_read_transaction',
931
-                    'espresso_transactions_view_transaction',
932
-                    $registration->transaction_ID()
933
-                )
934
-                    ? '
892
+				: $registration->transaction()->pretty_total();
893
+		} else {
894
+			$content = esc_html__("None", "event_espresso");
895
+		}
896
+		return $this->columnContent('TXN_total', $content, 'end');
897
+	}
898
+
899
+
900
+	/**
901
+	 * @param EE_Registration $registration
902
+	 * @return string
903
+	 * @throws EE_Error
904
+	 * @throws EntityNotFoundException
905
+	 * @throws InvalidArgumentException
906
+	 * @throws InvalidDataTypeException
907
+	 * @throws InvalidInterfaceException
908
+	 * @throws ReflectionException
909
+	 */
910
+	public function column_TXN_paid(EE_Registration $registration)
911
+	{
912
+		$content = '&nbsp;';
913
+		$align = 'end';
914
+		if ($registration->count() === 1) {
915
+			$transaction = $registration->transaction()
916
+				? $registration->transaction()
917
+				: EE_Transaction::new_instance();
918
+			if ($transaction->paid() >= $transaction->total()) {
919
+				$align = 'center';
920
+				$content = '<span class="dashicons dashicons-yes green-icon"></span>';
921
+			} else {
922
+				$view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
923
+					[
924
+						'action' => 'view_transaction',
925
+						'TXN_ID' => $registration->transaction_ID(),
926
+					],
927
+					TXN_ADMIN_URL
928
+				);
929
+				$content = EE_Registry::instance()->CAP->current_user_can(
930
+					'ee_read_transaction',
931
+					'espresso_transactions_view_transaction',
932
+					$registration->transaction_ID()
933
+				)
934
+					? '
935 935
                     <a class="ee-aria-tooltip ee-status-color--' . $transaction->status_ID() . '" 
936 936
                         href="' . $view_txn_link_url . '"  
937 937
                         aria-label="' . esc_attr__('View Transaction', 'event_espresso') . '"
938 938
                     >
939 939
                         ' . $registration->transaction()->pretty_paid() . '
940 940
                     </a>'
941
-                    :  $registration->transaction()->pretty_paid();
942
-            }
943
-        }
944
-        return $this->columnContent('TXN_paid', $content, $align);
945
-    }
946
-
947
-
948
-    /**
949
-     * @param EE_Registration $registration
950
-     * @return string
951
-     * @throws EE_Error
952
-     * @throws InvalidArgumentException
953
-     * @throws InvalidDataTypeException
954
-     * @throws InvalidInterfaceException
955
-     * @throws ReflectionException
956
-     */
957
-    public function column_actions(EE_Registration $registration)
958
-    {
959
-        $actions  = [];
960
-        $attendee = $registration->attendee();
961
-        $this->_set_related_details($registration);
962
-
963
-        // Build row actions
964
-        if (
965
-            EE_Registry::instance()->CAP->current_user_can(
966
-                'ee_read_registration',
967
-                'espresso_registrations_view_registration',
968
-                $registration->ID()
969
-            )
970
-        ) {
971
-            $view_link_url = EE_Admin_Page::add_query_args_and_nonce(
972
-                [
973
-                    'action'  => 'view_registration',
974
-                    '_REG_ID' => $registration->ID(),
975
-                ],
976
-                REG_ADMIN_URL
977
-            );
978
-            $actions['view_lnk'] = '
941
+					:  $registration->transaction()->pretty_paid();
942
+			}
943
+		}
944
+		return $this->columnContent('TXN_paid', $content, $align);
945
+	}
946
+
947
+
948
+	/**
949
+	 * @param EE_Registration $registration
950
+	 * @return string
951
+	 * @throws EE_Error
952
+	 * @throws InvalidArgumentException
953
+	 * @throws InvalidDataTypeException
954
+	 * @throws InvalidInterfaceException
955
+	 * @throws ReflectionException
956
+	 */
957
+	public function column_actions(EE_Registration $registration)
958
+	{
959
+		$actions  = [];
960
+		$attendee = $registration->attendee();
961
+		$this->_set_related_details($registration);
962
+
963
+		// Build row actions
964
+		if (
965
+			EE_Registry::instance()->CAP->current_user_can(
966
+				'ee_read_registration',
967
+				'espresso_registrations_view_registration',
968
+				$registration->ID()
969
+			)
970
+		) {
971
+			$view_link_url = EE_Admin_Page::add_query_args_and_nonce(
972
+				[
973
+					'action'  => 'view_registration',
974
+					'_REG_ID' => $registration->ID(),
975
+				],
976
+				REG_ADMIN_URL
977
+			);
978
+			$actions['view_lnk'] = '
979 979
                 <a href="' . $view_link_url . '" aria-label="'
980
-                . esc_attr__('View Registration Details', 'event_espresso')
981
-                . '" class="ee-aria-tooltip button button--icon-only">
980
+				. esc_attr__('View Registration Details', 'event_espresso')
981
+				. '" class="ee-aria-tooltip button button--icon-only">
982 982
 				    <span class="dashicons dashicons-clipboard"></span>
983 983
 			    </a>';
984
-        }
985
-
986
-        if (
987
-            $attendee instanceof EE_Attendee
988
-            && EE_Registry::instance()->CAP->current_user_can(
989
-                'ee_edit_contacts',
990
-                'espresso_registrations_edit_attendee'
991
-            )
992
-        ) {
993
-            $edit_link_url = EE_Admin_Page::add_query_args_and_nonce(
994
-                [
995
-                    'action' => 'edit_attendee',
996
-                    'post'   => $registration->attendee_ID(),
997
-                ],
998
-                REG_ADMIN_URL
999
-            );
1000
-            $actions['edit_lnk'] = '
984
+		}
985
+
986
+		if (
987
+			$attendee instanceof EE_Attendee
988
+			&& EE_Registry::instance()->CAP->current_user_can(
989
+				'ee_edit_contacts',
990
+				'espresso_registrations_edit_attendee'
991
+			)
992
+		) {
993
+			$edit_link_url = EE_Admin_Page::add_query_args_and_nonce(
994
+				[
995
+					'action' => 'edit_attendee',
996
+					'post'   => $registration->attendee_ID(),
997
+				],
998
+				REG_ADMIN_URL
999
+			);
1000
+			$actions['edit_lnk'] = '
1001 1001
                 <a href="' . $edit_link_url . '" 
1002 1002
                    aria-label="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" 
1003 1003
                    class="ee-aria-tooltip button button--secondary button--icon-only"
1004 1004
                 >
1005 1005
                     <span class="dashicons dashicons-admin-users"></span>
1006 1006
                 </a>';
1007
-        }
1008
-
1009
-        if (
1010
-            $attendee instanceof EE_Attendee
1011
-            && EE_Registry::instance()->CAP->current_user_can(
1012
-                'ee_send_message',
1013
-                'espresso_registrations_resend_registration',
1014
-                $registration->ID()
1015
-            )
1016
-        ) {
1017
-            $resend_reg_link_url = EE_Admin_Page::add_query_args_and_nonce(
1018
-                [
1019
-                    'action'  => 'resend_registration',
1020
-                    '_REG_ID' => $registration->ID(),
1021
-                ],
1022
-                REG_ADMIN_URL,
1023
-                true
1024
-            );
1025
-            $actions['resend_reg_lnk'] = '
1007
+		}
1008
+
1009
+		if (
1010
+			$attendee instanceof EE_Attendee
1011
+			&& EE_Registry::instance()->CAP->current_user_can(
1012
+				'ee_send_message',
1013
+				'espresso_registrations_resend_registration',
1014
+				$registration->ID()
1015
+			)
1016
+		) {
1017
+			$resend_reg_link_url = EE_Admin_Page::add_query_args_and_nonce(
1018
+				[
1019
+					'action'  => 'resend_registration',
1020
+					'_REG_ID' => $registration->ID(),
1021
+				],
1022
+				REG_ADMIN_URL,
1023
+				true
1024
+			);
1025
+			$actions['resend_reg_lnk'] = '
1026 1026
 			    <a href="' . $resend_reg_link_url . '" aria-label="'
1027
-                . esc_attr__('Resend Registration Details', 'event_espresso')
1028
-                . '" class="ee-aria-tooltip button button--icon-only">
1027
+				. esc_attr__('Resend Registration Details', 'event_espresso')
1028
+				. '" class="ee-aria-tooltip button button--icon-only">
1029 1029
 			        <span class="dashicons dashicons-email-alt"></span>
1030 1030
 			    </a>';
1031
-        }
1032
-
1033
-        if (
1034
-            EE_Registry::instance()->CAP->current_user_can(
1035
-                'ee_read_transaction',
1036
-                'espresso_transactions_view_transaction',
1037
-                $this->_transaction_details['id']
1038
-            )
1039
-        ) {
1040
-            $view_txn_link_url        = EE_Admin_Page::add_query_args_and_nonce(
1041
-                [
1042
-                    'action' => 'view_transaction',
1043
-                    'TXN_ID' => $this->_transaction_details['id'],
1044
-                ],
1045
-                TXN_ADMIN_URL
1046
-            );
1047
-            $actions['view_txn_lnk'] = '
1031
+		}
1032
+
1033
+		if (
1034
+			EE_Registry::instance()->CAP->current_user_can(
1035
+				'ee_read_transaction',
1036
+				'espresso_transactions_view_transaction',
1037
+				$this->_transaction_details['id']
1038
+			)
1039
+		) {
1040
+			$view_txn_link_url        = EE_Admin_Page::add_query_args_and_nonce(
1041
+				[
1042
+					'action' => 'view_transaction',
1043
+					'TXN_ID' => $this->_transaction_details['id'],
1044
+				],
1045
+				TXN_ADMIN_URL
1046
+			);
1047
+			$actions['view_txn_lnk'] = '
1048 1048
                 <a class="ee-aria-tooltip button button--icon-only" 
1049 1049
                    href="' . $view_txn_link_url . '"  
1050 1050
                    aria-label="' . $this->_transaction_details['title_attr'] . '"
1051 1051
                 >
1052 1052
                     <span class="dashicons dashicons-cart"></span>
1053 1053
                 </a>';
1054
-        }
1055
-
1056
-        // only show invoice link if message type is active.
1057
-        if (
1058
-            $attendee instanceof EE_Attendee
1059
-            && $registration->is_primary_registrant()
1060
-            && EEH_MSG_Template::is_mt_active('invoice')
1061
-        ) {
1062
-            $actions['dl_invoice_lnk'] = '
1054
+		}
1055
+
1056
+		// only show invoice link if message type is active.
1057
+		if (
1058
+			$attendee instanceof EE_Attendee
1059
+			&& $registration->is_primary_registrant()
1060
+			&& EEH_MSG_Template::is_mt_active('invoice')
1061
+		) {
1062
+			$actions['dl_invoice_lnk'] = '
1063 1063
                 <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso')
1064
-                . '" target="_blank" href="' . $registration->invoice_url() . '" class="ee-aria-tooltip button button--icon-only">
1064
+				. '" target="_blank" href="' . $registration->invoice_url() . '" class="ee-aria-tooltip button button--icon-only">
1065 1065
                     <span class="dashicons dashicons-media-spreadsheet"></span>
1066 1066
                 </a>';
1067
-        }
1067
+		}
1068 1068
 
1069
-        // message list table link (filtered by REG_ID
1070
-        if (
1071
-            EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')
1072
-        ) {
1073
-            $actions['filtered_messages_link'] = '
1069
+		// message list table link (filtered by REG_ID
1070
+		if (
1071
+			EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')
1072
+		) {
1073
+			$actions['filtered_messages_link'] = '
1074 1074
                 ' . EEH_MSG_Template::get_message_action_link(
1075
-                'see_notifications_for',
1076
-                null,
1077
-                ['_REG_ID' => $registration->ID()]
1078
-            );
1079
-        }
1080
-
1081
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $registration, $this);
1082
-        $content = $this->_action_string(
1083
-            implode('', $actions),
1084
-            $registration,
1085
-            'div',
1086
-            'reg-overview-actions ee-list-table-actions'
1087
-        );
1088
-        return $this->columnContent('actions', $this->actionsModalMenu($content));
1089
-    }
1075
+				'see_notifications_for',
1076
+				null,
1077
+				['_REG_ID' => $registration->ID()]
1078
+			);
1079
+		}
1080
+
1081
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $registration, $this);
1082
+		$content = $this->_action_string(
1083
+			implode('', $actions),
1084
+			$registration,
1085
+			'div',
1086
+			'reg-overview-actions ee-list-table-actions'
1087
+		);
1088
+		return $this->columnContent('actions', $this->actionsModalMenu($content));
1089
+	}
1090 1090
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
     public function __construct(Registrations_Admin_Page $admin_page)
49 49
     {
50 50
         $req_data = $admin_page->get_request_data();
51
-        if (! empty($req_data['event_id'])) {
51
+        if ( ! empty($req_data['event_id'])) {
52 52
             $extra_query_args = [];
53 53
             foreach ($admin_page->get_views() as $view_details) {
54
-                $extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
54
+                $extra_query_args[$view_details['slug']] = ['event_id' => $req_data['event_id']];
55 55
             }
56 56
             $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57 57
         }
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
             'ajax'     => true,
84 84
             'screen'   => $this->_admin_page->get_current_screen()->id,
85 85
         ];
86
-        $req_data            = $this->_admin_page->get_request_data();
86
+        $req_data = $this->_admin_page->get_request_data();
87 87
         if (isset($req_data['event_id'])) {
88
-            $this->_columns        = [
88
+            $this->_columns = [
89 89
                 'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
90 90
                 'id'          => esc_html__('ID', 'event_espresso'),
91 91
                 'ATT_fname'        => esc_html__('Name', 'event_espresso'),
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                 ],
108 108
             ];
109 109
         } else {
110
-            $this->_columns        = [
110
+            $this->_columns = [
111 111
                 'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
112 112
                 'id'          => esc_html__('ID', 'event_espresso'),
113 113
                 'ATT_fname'        => esc_html__('Name', 'event_espresso'),
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                 'return_url'  => $return_url,
135 135
             ],
136 136
         ];
137
-        $filters                                  = array_diff_key(
137
+        $filters = array_diff_key(
138 138
             $this->_req_data,
139 139
             array_flip(
140 140
                 [
@@ -144,12 +144,12 @@  discard block
 block discarded – undo
144 144
                 ]
145 145
             )
146 146
         );
147
-        if (! empty($filters)) {
147
+        if ( ! empty($filters)) {
148 148
             $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
149 149
         }
150 150
         $this->_primary_column   = 'id';
151 151
         $this->_sortable_columns = [
152
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
152
+            '_REG_date'     => ['_REG_date' => true], // true means its already sorted
153 153
             /**
154 154
              * Allows users to change the default sort if they wish.
155 155
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
             'DTT_EVT_start' => ['DTT_EVT_start' => false],
167 167
             'id'       => ['REG_ID' => false],
168 168
         ];
169
-        $this->_hidden_columns   = [];
169
+        $this->_hidden_columns = [];
170 170
     }
171 171
 
172 172
 
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
         $this_month_r    = date('m', current_time('timestamp'));
348 348
         $days_this_month = date('t', current_time('timestamp'));
349 349
         // setup date query.
350
-        $beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
350
+        $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
351 351
             'REG_date',
352
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
352
+            $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start,
353 353
             'Y-m-d H:i:s'
354 354
         );
355
-        $end_string         = EEM_Registration::instance()->convert_datetime_for_query(
355
+        $end_string = EEM_Registration::instance()->convert_datetime_for_query(
356 356
             'REG_date',
357
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
357
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end,
358 358
             'Y-m-d H:i:s'
359 359
         );
360 360
         $_where['REG_date'] = [
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
                 $end_string,
365 365
             ],
366 366
         ];
367
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
367
+        $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
368 368
         return EEM_Registration::instance()->count([$_where]);
369 369
     }
370 370
 
@@ -392,17 +392,17 @@  discard block
 block discarded – undo
392 392
             [
393 393
                 EEM_Registration::instance()->convert_datetime_for_query(
394 394
                     'REG_date',
395
-                    $current_date . $time_start,
395
+                    $current_date.$time_start,
396 396
                     'Y-m-d H:i:s'
397 397
                 ),
398 398
                 EEM_Registration::instance()->convert_datetime_for_query(
399 399
                     'REG_date',
400
-                    $current_date . $time_end,
400
+                    $current_date.$time_end,
401 401
                     'Y-m-d H:i:s'
402 402
                 ),
403 403
             ],
404 404
         ];
405
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
405
+        $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
406 406
         return EEM_Registration::instance()->count([$_where]);
407 407
     }
408 408
 
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
             'registration_list_table_checkbox_input',
430 430
             $REG_ID
431 431
         )
432
-            ? '<input disabled type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />
432
+            ? '<input disabled type="checkbox" name="_REG_ID[]" value="'.$REG_ID.'" />
433 433
                 <span class="dashicons dashicons-lock"></span>'
434
-            : '<input type="checkbox" name="_REG_ID[]" value="' . $REG_ID . '" />';
434
+            : '<input type="checkbox" name="_REG_ID[]" value="'.$REG_ID.'" />';
435 435
 
436 436
         return $this->columnContent('cb', $content, 'center');
437 437
     }
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
     {
451 451
         $content  = $registration->ID();
452 452
         $content .= '<span class="show-on-mobile-view-only">';
453
-        $content  .= $this->column_ATT_fname($registration, false);
453
+        $content .= $this->column_ATT_fname($registration, false);
454 454
         $content .= '</span>';
455 455
 
456 456
         return $this->columnContent('id', $content, 'end');
@@ -468,8 +468,8 @@  discard block
 block discarded – undo
468 468
      */
469 469
     public function column_ATT_fname(EE_Registration $registration, $prep_content = true)
470 470
     {
471
-        $attendee      = $registration->attendee();
472
-        $edit_link_url  = EE_Admin_Page::add_query_args_and_nonce(
471
+        $attendee = $registration->attendee();
472
+        $edit_link_url = EE_Admin_Page::add_query_args_and_nonce(
473 473
             [
474 474
                 'action'  => 'view_registration',
475 475
                 '_REG_ID' => $registration->ID(),
@@ -485,8 +485,8 @@  discard block
 block discarded – undo
485 485
 
486 486
         $content = '
487 487
         <div class="ee-layout-row">
488
-            <span aria-label="' . $pretty_status . '" 
489
-                  class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"
488
+            <span aria-label="' . $pretty_status.'" 
489
+                  class="ee-status-dot ee-status-bg--' . $status.' ee-aria-tooltip"
490 490
             ></span>';
491 491
 
492 492
         $content .= EE_Registry::instance()->CAP->current_user_can(
@@ -495,11 +495,11 @@  discard block
 block discarded – undo
495 495
             $registration->ID()
496 496
         )
497 497
             ? '
498
-            <a  href="' . $edit_link_url . '"  
499
-                class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" 
500
-                aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
498
+            <a  href="' . $edit_link_url.'"  
499
+                class="row-title ee-status-color--' . $status.' ee-aria-tooltip" 
500
+                aria-label="' . esc_attr__('View Registration Details', 'event_espresso').'"
501 501
             >
502
-                ' . $attendee_name . '
502
+                ' . $attendee_name.'
503 503
             </a>'
504 504
             : $attendee_name;
505 505
 
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
             )
541 541
         ) {
542 542
             $action['action'] = 'trash_registrations';
543
-            $trash_link_url    = EE_Admin_Page::add_query_args_and_nonce(
543
+            $trash_link_url = EE_Admin_Page::add_query_args_and_nonce(
544 544
                 $action,
545 545
                 REG_ADMIN_URL
546 546
             );
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
                                 . $trash_link_url
549 549
                                 . '" aria-label="'
550 550
                                 . esc_attr__('Trash Registration', 'event_espresso')
551
-                                . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
551
+                                . '">'.esc_html__('Trash', 'event_espresso').'</a>';
552 552
         } elseif ($this->_view === 'trash') {
553 553
             // restore registration link
554 554
             if (
@@ -558,16 +558,16 @@  discard block
 block discarded – undo
558 558
                     $registration->ID()
559 559
                 )
560 560
             ) {
561
-                $action['action']   = 'restore_registrations';
562
-                $restore_link_url    = EE_Admin_Page::add_query_args_and_nonce(
561
+                $action['action'] = 'restore_registrations';
562
+                $restore_link_url = EE_Admin_Page::add_query_args_and_nonce(
563 563
                     $action,
564 564
                     REG_ADMIN_URL
565 565
                 );
566 566
                 $actions['restore'] = '<a class="ee-aria-tooltip" href="'
567 567
                                       . $restore_link_url
568 568
                                       . '" aria-label="'
569
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
570
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
569
+                                      . esc_attr__('Restore Registration', 'event_espresso').'">'
570
+                                      . esc_html__('Restore', 'event_espresso').'</a>';
571 571
             }
572 572
             if (
573 573
                 EE_Registry::instance()->CAP->current_user_can(
@@ -576,8 +576,8 @@  discard block
 block discarded – undo
576 576
                     $registration->ID()
577 577
                 )
578 578
             ) {
579
-                $action['action']  = 'delete_registrations';
580
-                $delete_link_url    = EE_Admin_Page::add_query_args_and_nonce(
579
+                $action['action'] = 'delete_registrations';
580
+                $delete_link_url = EE_Admin_Page::add_query_args_and_nonce(
581 581
                     $action,
582 582
                     REG_ADMIN_URL
583 583
                 );
@@ -616,11 +616,11 @@  discard block
 block discarded – undo
616 616
             ],
617 617
             TXN_ADMIN_URL
618 618
         );
619
-        $content    = EE_Registry::instance()->CAP->current_user_can(
619
+        $content = EE_Registry::instance()->CAP->current_user_can(
620 620
             'ee_read_transaction',
621 621
             'espresso_transactions_view_transaction'
622 622
         )
623
-            ? '<a class="ee-aria-tooltip ee-status-color--' . $this->_transaction_details['status'] . '" href="'
623
+            ? '<a class="ee-aria-tooltip ee-status-color--'.$this->_transaction_details['status'].'" href="'
624 624
               . $view_link_url
625 625
               . '" aria-label="'
626 626
               . esc_attr($this->_transaction_details['title_attr'])
@@ -657,11 +657,11 @@  discard block
 block discarded – undo
657 657
                 ?: esc_html__("No Associated Event", 'event_espresso');
658 658
         $event_name = wp_trim_words($event_name, 30, '...');
659 659
         if ($EVT_ID) {
660
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
660
+            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
661 661
                 ['action' => 'edit', 'post' => $EVT_ID],
662 662
                 EVENTS_ADMIN_URL
663 663
             );
664
-            $edit_event              =
664
+            $edit_event =
665 665
                 EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
666 666
                     ? '<a class="ee-aria-tooltip ee-status-color--'
667 667
                       . $this->_event_details['status']
@@ -675,13 +675,13 @@  discard block
 block discarded – undo
675 675
                     : $event_name;
676 676
             $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
677 677
             $actions['event_filter'] = '
678
-                <a  class="ee-aria-tooltip ee-event-filter-link" href="' . $edit_event_url . '" 
678
+                <a  class="ee-aria-tooltip ee-event-filter-link" href="' . $edit_event_url.'" 
679 679
                     aria-label="' . sprintf(
680 680
                         esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
681 681
                         $event_name
682
-                    ) .'">
682
+                    ).'">
683 683
                     <span class="dashicons dashicons-groups dashicons--small"></span>'
684
-                    . esc_html__('View Registrations', 'event_espresso') .
684
+                    . esc_html__('View Registrations', 'event_espresso').
685 685
                 '</a>';
686 686
         } else {
687 687
             $edit_event              = $event_name;
@@ -731,16 +731,16 @@  discard block
 block discarded – undo
731 731
         // $content       = '<div class="ee-registration-event-datetimes-container">';
732 732
         // get first item for initial visibility
733 733
         $content = array_shift($datetime_strings);
734
-        if (! empty($datetime_strings)) {
734
+        if ( ! empty($datetime_strings)) {
735 735
             $content .= '
736 736
                 <div class="ee-registration-event-datetimes-container-wrap">
737
-                    <button aria-label="' . esc_attr__('Click to view all dates', 'event_espresso') . '" 
737
+                    <button aria-label="' . esc_attr__('Click to view all dates', 'event_espresso').'" 
738 738
                           class="ee-aria-tooltip button button--secondary button--tiny button--icon-only ee-js ee-more-datetimes-toggle"
739 739
                     >
740 740
                         <span class="dashicons dashicons-admin-collapse"></span>
741 741
                     </button>
742 742
                     <div class="ee-registration-event-datetimes-container more-items hidden">
743
-                        ' . implode("", $datetime_strings) . '
743
+                        ' . implode("", $datetime_strings).'
744 744
                     </div>
745 745
                 </div>';
746 746
         }
@@ -791,16 +791,16 @@  discard block
 block discarded – undo
791 791
         $req_data = $this->_admin_page->get_request_data();
792 792
 
793 793
         $content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
794
-            ? '<div class="TKT_name">' . $ticket->name() . '</div>'
794
+            ? '<div class="TKT_name">'.$ticket->name().'</div>'
795 795
             : '';
796 796
         
797 797
         $payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
798 798
         $content .= $registration->final_price() > 0
799
-            ? '<span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
800
-                ' . $registration->pretty_final_price() . '
799
+            ? '<span class="reg-overview-paid-event-spn ee-status-color--'.$payment_status.'">
800
+                ' . $registration->pretty_final_price().'
801 801
                </span>'
802 802
             // free event
803
-            : '<span class="reg-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
803
+            : '<span class="reg-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>';
804 804
 
805 805
         return $this->columnContent('PRC_amount', $content, 'end');
806 806
     }
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
         $req_data = $this->_admin_page->get_request_data();
819 819
         $content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
820 820
             ? ''
821
-            : '<span class="TKT_name ee-status-color--' . $ticket->ticket_status() . '">' . $ticket->name() . '</span> ';
821
+            : '<span class="TKT_name ee-status-color--'.$ticket->ticket_status().'">'.$ticket->name().'</span> ';
822 822
 
823
-        $content  .= '
823
+        $content .= '
824 824
             <span class="reg-overview-paid-event-spn">
825
-                ' . $registration->pretty_final_price() . '
825
+                ' . $registration->pretty_final_price().'
826 826
             </span>';
827 827
         return $this->columnContent('_REG_final_price', $content, 'end');
828 828
     }
@@ -842,8 +842,8 @@  discard block
 block discarded – undo
842 842
 
843 843
         $payment_status = $registration->owes_monies_and_can_pay() ? 'TFL' : 'TCM';
844 844
         $content        = '
845
-            <span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status . '">
846
-                ' . $registration->pretty_paid() . '
845
+            <span class="reg-overview-paid-event-spn ee-status-color--' . $payment_status.'">
846
+                ' . $registration->pretty_paid().'
847 847
             </span>';
848 848
         if ($registration->paid() > 0) {
849 849
             $content .= '<span class="ee-status-text-small">'
@@ -883,11 +883,11 @@  discard block
 block discarded – undo
883 883
                 $registration->transaction_ID()
884 884
             )
885 885
                 ? '
886
-                    <a class="ee-aria-tooltip ee-status-color--' . $registration->transaction()->status_ID() . '" 
887
-                        href="' . $view_txn_link_url . '" 
888
-                        aria-label="' . esc_attr__('View Transaction', 'event_espresso') . '"
886
+                    <a class="ee-aria-tooltip ee-status-color--' . $registration->transaction()->status_ID().'" 
887
+                        href="' . $view_txn_link_url.'" 
888
+                        aria-label="' . esc_attr__('View Transaction', 'event_espresso').'"
889 889
                     >
890
-                        ' . $registration->transaction()->pretty_total() . '
890
+                        ' . $registration->transaction()->pretty_total().'
891 891
                     </a>'
892 892
                 : $registration->transaction()->pretty_total();
893 893
         } else {
@@ -932,11 +932,11 @@  discard block
 block discarded – undo
932 932
                     $registration->transaction_ID()
933 933
                 )
934 934
                     ? '
935
-                    <a class="ee-aria-tooltip ee-status-color--' . $transaction->status_ID() . '" 
936
-                        href="' . $view_txn_link_url . '"  
937
-                        aria-label="' . esc_attr__('View Transaction', 'event_espresso') . '"
935
+                    <a class="ee-aria-tooltip ee-status-color--' . $transaction->status_ID().'" 
936
+                        href="' . $view_txn_link_url.'"  
937
+                        aria-label="' . esc_attr__('View Transaction', 'event_espresso').'"
938 938
                     >
939
-                        ' . $registration->transaction()->pretty_paid() . '
939
+                        ' . $registration->transaction()->pretty_paid().'
940 940
                     </a>'
941 941
                     :  $registration->transaction()->pretty_paid();
942 942
             }
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
                 REG_ADMIN_URL
977 977
             );
978 978
             $actions['view_lnk'] = '
979
-                <a href="' . $view_link_url . '" aria-label="'
979
+                <a href="' . $view_link_url.'" aria-label="'
980 980
                 . esc_attr__('View Registration Details', 'event_espresso')
981 981
                 . '" class="ee-aria-tooltip button button--icon-only">
982 982
 				    <span class="dashicons dashicons-clipboard"></span>
@@ -998,8 +998,8 @@  discard block
 block discarded – undo
998 998
                 REG_ADMIN_URL
999 999
             );
1000 1000
             $actions['edit_lnk'] = '
1001
-                <a href="' . $edit_link_url . '" 
1002
-                   aria-label="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" 
1001
+                <a href="' . $edit_link_url.'" 
1002
+                   aria-label="' . esc_attr__('Edit Contact Details', 'event_espresso').'" 
1003 1003
                    class="ee-aria-tooltip button button--secondary button--icon-only"
1004 1004
                 >
1005 1005
                     <span class="dashicons dashicons-admin-users"></span>
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
                 true
1024 1024
             );
1025 1025
             $actions['resend_reg_lnk'] = '
1026
-			    <a href="' . $resend_reg_link_url . '" aria-label="'
1026
+			    <a href="' . $resend_reg_link_url.'" aria-label="'
1027 1027
                 . esc_attr__('Resend Registration Details', 'event_espresso')
1028 1028
                 . '" class="ee-aria-tooltip button button--icon-only">
1029 1029
 			        <span class="dashicons dashicons-email-alt"></span>
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
                 $this->_transaction_details['id']
1038 1038
             )
1039 1039
         ) {
1040
-            $view_txn_link_url        = EE_Admin_Page::add_query_args_and_nonce(
1040
+            $view_txn_link_url = EE_Admin_Page::add_query_args_and_nonce(
1041 1041
                 [
1042 1042
                     'action' => 'view_transaction',
1043 1043
                     'TXN_ID' => $this->_transaction_details['id'],
@@ -1046,8 +1046,8 @@  discard block
 block discarded – undo
1046 1046
             );
1047 1047
             $actions['view_txn_lnk'] = '
1048 1048
                 <a class="ee-aria-tooltip button button--icon-only" 
1049
-                   href="' . $view_txn_link_url . '"  
1050
-                   aria-label="' . $this->_transaction_details['title_attr'] . '"
1049
+                   href="' . $view_txn_link_url.'"  
1050
+                   aria-label="' . $this->_transaction_details['title_attr'].'"
1051 1051
                 >
1052 1052
                     <span class="dashicons dashicons-cart"></span>
1053 1053
                 </a>';
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
         ) {
1062 1062
             $actions['dl_invoice_lnk'] = '
1063 1063
                 <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso')
1064
-                . '" target="_blank" href="' . $registration->invoice_url() . '" class="ee-aria-tooltip button button--icon-only">
1064
+                . '" target="_blank" href="'.$registration->invoice_url().'" class="ee-aria-tooltip button button--icon-only">
1065 1065
                     <span class="dashicons dashicons-media-spreadsheet"></span>
1066 1066
                 </a>';
1067 1067
         }
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Indentation   +3676 added lines, -3676 removed lines patch added patch discarded remove patch
@@ -19,2228 +19,2228 @@  discard block
 block discarded – undo
19 19
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * @var EE_Registration
24
-     */
25
-    private $_registration;
26
-
27
-    /**
28
-     * @var EE_Event
29
-     */
30
-    private $_reg_event;
31
-
32
-    /**
33
-     * @var EE_Session
34
-     */
35
-    private $_session;
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    private static $_reg_status;
41
-
42
-    /**
43
-     * Form for displaying the custom questions for this registration.
44
-     * This gets used a few times throughout the request so its best to cache it
45
-     *
46
-     * @var EE_Registration_Custom_Questions_Form
47
-     */
48
-    protected $_reg_custom_questions_form;
49
-
50
-    /**
51
-     * @var EEM_Registration $registration_model
52
-     */
53
-    private $registration_model;
54
-
55
-    /**
56
-     * @var EEM_Attendee $attendee_model
57
-     */
58
-    private $attendee_model;
59
-
60
-    /**
61
-     * @var EEM_Event $event_model
62
-     */
63
-    private $event_model;
64
-
65
-    /**
66
-     * @var EEM_Status $status_model
67
-     */
68
-    private $status_model;
69
-
70
-
71
-    /**
72
-     * @param bool $routing
73
-     * @throws EE_Error
74
-     * @throws InvalidArgumentException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws ReflectionException
78
-     */
79
-    public function __construct($routing = true)
80
-    {
81
-        parent::__construct($routing);
82
-        add_action('wp_loaded', [$this, 'wp_loaded']);
83
-    }
84
-
85
-
86
-    /**
87
-     * @return EEM_Registration
88
-     * @throws InvalidArgumentException
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @since 4.10.2.p
92
-     */
93
-    protected function getRegistrationModel()
94
-    {
95
-        if (! $this->registration_model instanceof EEM_Registration) {
96
-            $this->registration_model = $this->loader->getShared('EEM_Registration');
97
-        }
98
-        return $this->registration_model;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return EEM_Attendee
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @since 4.10.2.p
108
-     */
109
-    protected function getAttendeeModel()
110
-    {
111
-        if (! $this->attendee_model instanceof EEM_Attendee) {
112
-            $this->attendee_model = $this->loader->getShared('EEM_Attendee');
113
-        }
114
-        return $this->attendee_model;
115
-    }
116
-
117
-
118
-    /**
119
-     * @return EEM_Event
120
-     * @throws InvalidArgumentException
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidInterfaceException
123
-     * @since 4.10.2.p
124
-     */
125
-    protected function getEventModel()
126
-    {
127
-        if (! $this->event_model instanceof EEM_Event) {
128
-            $this->event_model = $this->loader->getShared('EEM_Event');
129
-        }
130
-        return $this->event_model;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return EEM_Status
136
-     * @throws InvalidArgumentException
137
-     * @throws InvalidDataTypeException
138
-     * @throws InvalidInterfaceException
139
-     * @since 4.10.2.p
140
-     */
141
-    protected function getStatusModel()
142
-    {
143
-        if (! $this->status_model instanceof EEM_Status) {
144
-            $this->status_model = $this->loader->getShared('EEM_Status');
145
-        }
146
-        return $this->status_model;
147
-    }
148
-
149
-
150
-    public function wp_loaded()
151
-    {
152
-        // when adding a new registration...
153
-        $action = $this->request->getRequestParam('action');
154
-        if ($action === 'new_registration') {
155
-            EE_System::do_not_cache();
156
-            if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
-                // and it's NOT the attendee information reg step
158
-                // force cookie expiration by setting time to last week
159
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
-                // and update the global
161
-                $_COOKIE['ee_registration_added'] = 0;
162
-            }
163
-        }
164
-    }
165
-
166
-
167
-    protected function _init_page_props()
168
-    {
169
-        $this->page_slug        = REG_PG_SLUG;
170
-        $this->_admin_base_url  = REG_ADMIN_URL;
171
-        $this->_admin_base_path = REG_ADMIN;
172
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
173
-        $this->_cpt_routes      = [
174
-            'add_new_attendee' => 'espresso_attendees',
175
-            'edit_attendee'    => 'espresso_attendees',
176
-            'insert_attendee'  => 'espresso_attendees',
177
-            'update_attendee'  => 'espresso_attendees',
178
-        ];
179
-        $this->_cpt_model_names = [
180
-            'add_new_attendee' => 'EEM_Attendee',
181
-            'edit_attendee'    => 'EEM_Attendee',
182
-        ];
183
-        $this->_cpt_edit_routes = [
184
-            'espresso_attendees' => 'edit_attendee',
185
-        ];
186
-        $this->_pagenow_map     = [
187
-            'add_new_attendee' => 'post-new.php',
188
-            'edit_attendee'    => 'post.php',
189
-            'trash'            => 'post.php',
190
-        ];
191
-        add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
-        // add filters so that the comment urls don't take users to a confusing 404 page
193
-        add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
-    }
195
-
196
-
197
-    /**
198
-     * @param string     $link    The comment permalink with '#comment-$id' appended.
199
-     * @param WP_Comment $comment The current comment object.
200
-     * @return string
201
-     */
202
-    public function clear_comment_link($link, WP_Comment $comment)
203
-    {
204
-        // gotta make sure this only happens on this route
205
-        $post_type = get_post_type($comment->comment_post_ID);
206
-        if ($post_type === 'espresso_attendees') {
207
-            return '#commentsdiv';
208
-        }
209
-        return $link;
210
-    }
211
-
212
-
213
-    protected function _ajax_hooks()
214
-    {
215
-        // todo: all hooks for registrations ajax goes in here
216
-        add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
-    }
218
-
219
-
220
-    protected function _define_page_props()
221
-    {
222
-        $this->_admin_page_title = $this->page_label;
223
-        $this->_labels           = [
224
-            'buttons'                      => [
225
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
-            ],
234
-            'publishbox'                   => [
235
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
-            ],
238
-            'hide_add_button_on_cpt_route' => [
239
-                'edit_attendee' => true,
240
-            ],
241
-        ];
242
-    }
243
-
244
-
245
-    /**
246
-     * grab url requests and route them
247
-     *
248
-     * @return void
249
-     * @throws EE_Error
250
-     */
251
-    public function _set_page_routes()
252
-    {
253
-        $this->_get_registration_status_array();
254
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
-        $REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
-        $ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
-        $this->_page_routes = [
259
-            'default'                             => [
260
-                'func'       => '_registrations_overview_list_table',
261
-                'capability' => 'ee_read_registrations',
262
-            ],
263
-            'view_registration'                   => [
264
-                'func'       => '_registration_details',
265
-                'capability' => 'ee_read_registration',
266
-                'obj_id'     => $REG_ID,
267
-            ],
268
-            'edit_registration'                   => [
269
-                'func'               => '_update_attendee_registration_form',
270
-                'noheader'           => true,
271
-                'headers_sent_route' => 'view_registration',
272
-                'capability'         => 'ee_edit_registration',
273
-                'obj_id'             => $REG_ID,
274
-                '_REG_ID'            => $REG_ID,
275
-            ],
276
-            'trash_registrations'                 => [
277
-                'func'       => '_trash_or_restore_registrations',
278
-                'args'       => ['trash' => true],
279
-                'noheader'   => true,
280
-                'capability' => 'ee_delete_registrations',
281
-            ],
282
-            'restore_registrations'               => [
283
-                'func'       => '_trash_or_restore_registrations',
284
-                'args'       => ['trash' => false],
285
-                'noheader'   => true,
286
-                'capability' => 'ee_delete_registrations',
287
-            ],
288
-            'delete_registrations'                => [
289
-                'func'       => '_delete_registrations',
290
-                'noheader'   => true,
291
-                'capability' => 'ee_delete_registrations',
292
-            ],
293
-            'new_registration'                    => [
294
-                'func'       => 'new_registration',
295
-                'capability' => 'ee_edit_registrations',
296
-            ],
297
-            'process_reg_step'                    => [
298
-                'func'       => 'process_reg_step',
299
-                'noheader'   => true,
300
-                'capability' => 'ee_edit_registrations',
301
-            ],
302
-            'redirect_to_txn'                     => [
303
-                'func'       => 'redirect_to_txn',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-            ],
307
-            'change_reg_status'                   => [
308
-                'func'       => '_change_reg_status',
309
-                'noheader'   => true,
310
-                'capability' => 'ee_edit_registration',
311
-                'obj_id'     => $REG_ID,
312
-            ],
313
-            'approve_registration'                => [
314
-                'func'       => 'approve_registration',
315
-                'noheader'   => true,
316
-                'capability' => 'ee_edit_registration',
317
-                'obj_id'     => $REG_ID,
318
-            ],
319
-            'approve_and_notify_registration'     => [
320
-                'func'       => 'approve_registration',
321
-                'noheader'   => true,
322
-                'args'       => [true],
323
-                'capability' => 'ee_edit_registration',
324
-                'obj_id'     => $REG_ID,
325
-            ],
326
-            'approve_registrations'               => [
327
-                'func'       => 'bulk_action_on_registrations',
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_registrations',
330
-                'args'       => ['approve'],
331
-            ],
332
-            'approve_and_notify_registrations'    => [
333
-                'func'       => 'bulk_action_on_registrations',
334
-                'noheader'   => true,
335
-                'capability' => 'ee_edit_registrations',
336
-                'args'       => ['approve', true],
337
-            ],
338
-            'decline_registration'                => [
339
-                'func'       => 'decline_registration',
340
-                'noheader'   => true,
341
-                'capability' => 'ee_edit_registration',
342
-                'obj_id'     => $REG_ID,
343
-            ],
344
-            'decline_and_notify_registration'     => [
345
-                'func'       => 'decline_registration',
346
-                'noheader'   => true,
347
-                'args'       => [true],
348
-                'capability' => 'ee_edit_registration',
349
-                'obj_id'     => $REG_ID,
350
-            ],
351
-            'decline_registrations'               => [
352
-                'func'       => 'bulk_action_on_registrations',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_edit_registrations',
355
-                'args'       => ['decline'],
356
-            ],
357
-            'decline_and_notify_registrations'    => [
358
-                'func'       => 'bulk_action_on_registrations',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_edit_registrations',
361
-                'args'       => ['decline', true],
362
-            ],
363
-            'pending_registration'                => [
364
-                'func'       => 'pending_registration',
365
-                'noheader'   => true,
366
-                'capability' => 'ee_edit_registration',
367
-                'obj_id'     => $REG_ID,
368
-            ],
369
-            'pending_and_notify_registration'     => [
370
-                'func'       => 'pending_registration',
371
-                'noheader'   => true,
372
-                'args'       => [true],
373
-                'capability' => 'ee_edit_registration',
374
-                'obj_id'     => $REG_ID,
375
-            ],
376
-            'pending_registrations'               => [
377
-                'func'       => 'bulk_action_on_registrations',
378
-                'noheader'   => true,
379
-                'capability' => 'ee_edit_registrations',
380
-                'args'       => ['pending'],
381
-            ],
382
-            'pending_and_notify_registrations'    => [
383
-                'func'       => 'bulk_action_on_registrations',
384
-                'noheader'   => true,
385
-                'capability' => 'ee_edit_registrations',
386
-                'args'       => ['pending', true],
387
-            ],
388
-            'no_approve_registration'             => [
389
-                'func'       => 'not_approve_registration',
390
-                'noheader'   => true,
391
-                'capability' => 'ee_edit_registration',
392
-                'obj_id'     => $REG_ID,
393
-            ],
394
-            'no_approve_and_notify_registration'  => [
395
-                'func'       => 'not_approve_registration',
396
-                'noheader'   => true,
397
-                'args'       => [true],
398
-                'capability' => 'ee_edit_registration',
399
-                'obj_id'     => $REG_ID,
400
-            ],
401
-            'no_approve_registrations'            => [
402
-                'func'       => 'bulk_action_on_registrations',
403
-                'noheader'   => true,
404
-                'capability' => 'ee_edit_registrations',
405
-                'args'       => ['not_approve'],
406
-            ],
407
-            'no_approve_and_notify_registrations' => [
408
-                'func'       => 'bulk_action_on_registrations',
409
-                'noheader'   => true,
410
-                'capability' => 'ee_edit_registrations',
411
-                'args'       => ['not_approve', true],
412
-            ],
413
-            'cancel_registration'                 => [
414
-                'func'       => 'cancel_registration',
415
-                'noheader'   => true,
416
-                'capability' => 'ee_edit_registration',
417
-                'obj_id'     => $REG_ID,
418
-            ],
419
-            'cancel_and_notify_registration'      => [
420
-                'func'       => 'cancel_registration',
421
-                'noheader'   => true,
422
-                'args'       => [true],
423
-                'capability' => 'ee_edit_registration',
424
-                'obj_id'     => $REG_ID,
425
-            ],
426
-            'cancel_registrations'                => [
427
-                'func'       => 'bulk_action_on_registrations',
428
-                'noheader'   => true,
429
-                'capability' => 'ee_edit_registrations',
430
-                'args'       => ['cancel'],
431
-            ],
432
-            'cancel_and_notify_registrations'     => [
433
-                'func'       => 'bulk_action_on_registrations',
434
-                'noheader'   => true,
435
-                'capability' => 'ee_edit_registrations',
436
-                'args'       => ['cancel', true],
437
-            ],
438
-            'wait_list_registration'              => [
439
-                'func'       => 'wait_list_registration',
440
-                'noheader'   => true,
441
-                'capability' => 'ee_edit_registration',
442
-                'obj_id'     => $REG_ID,
443
-            ],
444
-            'wait_list_and_notify_registration'   => [
445
-                'func'       => 'wait_list_registration',
446
-                'noheader'   => true,
447
-                'args'       => [true],
448
-                'capability' => 'ee_edit_registration',
449
-                'obj_id'     => $REG_ID,
450
-            ],
451
-            'contact_list'                        => [
452
-                'func'       => '_attendee_contact_list_table',
453
-                'capability' => 'ee_read_contacts',
454
-            ],
455
-            'add_new_attendee'                    => [
456
-                'func' => '_create_new_cpt_item',
457
-                'args' => [
458
-                    'new_attendee' => true,
459
-                    'capability'   => 'ee_edit_contacts',
460
-                ],
461
-            ],
462
-            'edit_attendee'                       => [
463
-                'func'       => '_edit_cpt_item',
464
-                'capability' => 'ee_edit_contacts',
465
-                'obj_id'     => $ATT_ID,
466
-            ],
467
-            'duplicate_attendee'                  => [
468
-                'func'       => '_duplicate_attendee',
469
-                'noheader'   => true,
470
-                'capability' => 'ee_edit_contacts',
471
-                'obj_id'     => $ATT_ID,
472
-            ],
473
-            'insert_attendee'                     => [
474
-                'func'       => '_insert_or_update_attendee',
475
-                'args'       => [
476
-                    'new_attendee' => true,
477
-                ],
478
-                'noheader'   => true,
479
-                'capability' => 'ee_edit_contacts',
480
-            ],
481
-            'update_attendee'                     => [
482
-                'func'       => '_insert_or_update_attendee',
483
-                'args'       => [
484
-                    'new_attendee' => false,
485
-                ],
486
-                'noheader'   => true,
487
-                'capability' => 'ee_edit_contacts',
488
-                'obj_id'     => $ATT_ID,
489
-            ],
490
-            'trash_attendees'                     => [
491
-                'func'       => '_trash_or_restore_attendees',
492
-                'args'       => [
493
-                    'trash' => 'true',
494
-                ],
495
-                'noheader'   => true,
496
-                'capability' => 'ee_delete_contacts',
497
-            ],
498
-            'trash_attendee'                      => [
499
-                'func'       => '_trash_or_restore_attendees',
500
-                'args'       => [
501
-                    'trash' => true,
502
-                ],
503
-                'noheader'   => true,
504
-                'capability' => 'ee_delete_contacts',
505
-                'obj_id'     => $ATT_ID,
506
-            ],
507
-            'restore_attendees'                   => [
508
-                'func'       => '_trash_or_restore_attendees',
509
-                'args'       => [
510
-                    'trash' => false,
511
-                ],
512
-                'noheader'   => true,
513
-                'capability' => 'ee_delete_contacts',
514
-                'obj_id'     => $ATT_ID,
515
-            ],
516
-            'resend_registration'                 => [
517
-                'func'       => '_resend_registration',
518
-                'noheader'   => true,
519
-                'capability' => 'ee_send_message',
520
-            ],
521
-            'registrations_report'                => [
522
-                'func'       => '_registrations_report',
523
-                'noheader'   => true,
524
-                'capability' => 'ee_read_registrations',
525
-            ],
526
-            'contact_list_export'                 => [
527
-                'func'       => '_contact_list_export',
528
-                'noheader'   => true,
529
-                'capability' => 'export',
530
-            ],
531
-            'contact_list_report'                 => [
532
-                'func'       => '_contact_list_report',
533
-                'noheader'   => true,
534
-                'capability' => 'ee_read_contacts',
535
-            ],
536
-        ];
537
-    }
538
-
539
-
540
-    protected function _set_page_config()
541
-    {
542
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
-        $this->_page_config = [
545
-            'default'           => [
546
-                'nav'           => [
547
-                    'label' => esc_html__('Overview', 'event_espresso'),
548
-                    'order' => 5,
549
-                ],
550
-                'help_tabs'     => [
551
-                    'registrations_overview_help_tab'                       => [
552
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
-                        'filename' => 'registrations_overview',
554
-                    ],
555
-                    'registrations_overview_table_column_headings_help_tab' => [
556
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
-                        'filename' => 'registrations_overview_table_column_headings',
558
-                    ],
559
-                    'registrations_overview_filters_help_tab'               => [
560
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
-                        'filename' => 'registrations_overview_filters',
562
-                    ],
563
-                    'registrations_overview_views_help_tab'                 => [
564
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
565
-                        'filename' => 'registrations_overview_views',
566
-                    ],
567
-                    'registrations_regoverview_other_help_tab'              => [
568
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
-                        'filename' => 'registrations_overview_other',
570
-                    ],
571
-                ],
572
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
573
-                // 'help_tour'     => array('Registration_Overview_Help_Tour'),
574
-                'qtips'         => ['Registration_List_Table_Tips'],
575
-                'list_table'    => 'EE_Registrations_List_Table',
576
-                'require_nonce' => false,
577
-            ],
578
-            'view_registration' => [
579
-                'nav'           => [
580
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
581
-                    'order'      => 15,
582
-                    'url'        => $REG_ID
583
-                        ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
584
-                        : $this->_admin_base_url,
585
-                    'persistent' => false,
586
-                ],
587
-                'help_tabs'     => [
588
-                    'registrations_details_help_tab'                    => [
589
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
590
-                        'filename' => 'registrations_details',
591
-                    ],
592
-                    'registrations_details_table_help_tab'              => [
593
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
594
-                        'filename' => 'registrations_details_table',
595
-                    ],
596
-                    'registrations_details_form_answers_help_tab'       => [
597
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
598
-                        'filename' => 'registrations_details_form_answers',
599
-                    ],
600
-                    'registrations_details_registrant_details_help_tab' => [
601
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
602
-                        'filename' => 'registrations_details_registrant_details',
603
-                    ],
604
-                ],
605
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
606
-                // 'help_tour'     => array('Registration_Details_Help_Tour'),
607
-                'metaboxes'     => array_merge(
608
-                    $this->_default_espresso_metaboxes,
609
-                    ['_registration_details_metaboxes']
610
-                ),
611
-                'require_nonce' => false,
612
-            ],
613
-            'new_registration'  => [
614
-                'nav'           => [
615
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
616
-                    'url'        => '#',
617
-                    'order'      => 15,
618
-                    'persistent' => false,
619
-                ],
620
-                'metaboxes'     => $this->_default_espresso_metaboxes,
621
-                'labels'        => [
622
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
623
-                ],
624
-                'require_nonce' => false,
625
-            ],
626
-            'add_new_attendee'  => [
627
-                'nav'           => [
628
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
629
-                    'order'      => 15,
630
-                    'persistent' => false,
631
-                ],
632
-                'metaboxes'     => array_merge(
633
-                    $this->_default_espresso_metaboxes,
634
-                    ['_publish_post_box', 'attendee_editor_metaboxes']
635
-                ),
636
-                'require_nonce' => false,
637
-            ],
638
-            'edit_attendee'     => [
639
-                'nav'           => [
640
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
641
-                    'order'      => 15,
642
-                    'persistent' => false,
643
-                    'url'        => $ATT_ID
644
-                        ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
645
-                        : $this->_admin_base_url,
646
-                ],
647
-                'metaboxes'     => ['attendee_editor_metaboxes'],
648
-                'require_nonce' => false,
649
-            ],
650
-            'contact_list'      => [
651
-                'nav'           => [
652
-                    'label' => esc_html__('Contact List', 'event_espresso'),
653
-                    'order' => 20,
654
-                ],
655
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
656
-                'help_tabs'     => [
657
-                    'registrations_contact_list_help_tab'                       => [
658
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
659
-                        'filename' => 'registrations_contact_list',
660
-                    ],
661
-                    'registrations_contact-list_table_column_headings_help_tab' => [
662
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
663
-                        'filename' => 'registrations_contact_list_table_column_headings',
664
-                    ],
665
-                    'registrations_contact_list_views_help_tab'                 => [
666
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
667
-                        'filename' => 'registrations_contact_list_views',
668
-                    ],
669
-                    'registrations_contact_list_other_help_tab'                 => [
670
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
671
-                        'filename' => 'registrations_contact_list_other',
672
-                    ],
673
-                ],
674
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
675
-                // 'help_tour'     => array('Contact_List_Help_Tour'),
676
-                'metaboxes'     => [],
677
-                'require_nonce' => false,
678
-            ],
679
-            // override default cpt routes
680
-            'create_new'        => '',
681
-            'edit'              => '',
682
-        ];
683
-    }
684
-
685
-
686
-    /**
687
-     * The below methods aren't used by this class currently
688
-     */
689
-    protected function _add_screen_options()
690
-    {
691
-    }
692
-
693
-
694
-    protected function _add_feature_pointers()
695
-    {
696
-    }
697
-
698
-
699
-    public function admin_init()
700
-    {
701
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
702
-            'click "Update Registration Questions" to save your changes',
703
-            'event_espresso'
704
-        );
705
-    }
706
-
707
-
708
-    public function admin_notices()
709
-    {
710
-    }
711
-
712
-
713
-    public function admin_footer_scripts()
714
-    {
715
-    }
716
-
717
-
718
-    /**
719
-     * get list of registration statuses
720
-     *
721
-     * @return void
722
-     * @throws EE_Error
723
-     */
724
-    private function _get_registration_status_array()
725
-    {
726
-        self::$_reg_status = EEM_Registration::reg_status_array([], true);
727
-    }
728
-
729
-
730
-    /**
731
-     * @throws InvalidArgumentException
732
-     * @throws InvalidDataTypeException
733
-     * @throws InvalidInterfaceException
734
-     * @since 4.10.2.p
735
-     */
736
-    protected function _add_screen_options_default()
737
-    {
738
-        $this->_per_page_screen_option();
739
-    }
740
-
741
-
742
-    /**
743
-     * @throws InvalidArgumentException
744
-     * @throws InvalidDataTypeException
745
-     * @throws InvalidInterfaceException
746
-     * @since 4.10.2.p
747
-     */
748
-    protected function _add_screen_options_contact_list()
749
-    {
750
-        $page_title              = $this->_admin_page_title;
751
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
752
-        $this->_per_page_screen_option();
753
-        $this->_admin_page_title = $page_title;
754
-    }
755
-
756
-
757
-    public function load_scripts_styles()
758
-    {
759
-        // style
760
-        wp_register_style(
761
-            'espresso_reg',
762
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
763
-            ['ee-admin-css'],
764
-            EVENT_ESPRESSO_VERSION
765
-        );
766
-        wp_enqueue_style('espresso_reg');
767
-        // script
768
-        wp_register_script(
769
-            'espresso_reg',
770
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
771
-            ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
772
-            EVENT_ESPRESSO_VERSION,
773
-            true
774
-        );
775
-        wp_enqueue_script('espresso_reg');
776
-    }
777
-
778
-
779
-    /**
780
-     * @throws EE_Error
781
-     * @throws InvalidArgumentException
782
-     * @throws InvalidDataTypeException
783
-     * @throws InvalidInterfaceException
784
-     * @throws ReflectionException
785
-     * @since 4.10.2.p
786
-     */
787
-    public function load_scripts_styles_edit_attendee()
788
-    {
789
-        // stuff to only show up on our attendee edit details page.
790
-        $attendee_details_translations = [
791
-            'att_publish_text' => sprintf(
792
-            /* translators: The date and time */
793
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
794
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
795
-            ),
796
-        ];
797
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
798
-        wp_enqueue_script('jquery-validate');
799
-    }
800
-
801
-
802
-    /**
803
-     * @throws EE_Error
804
-     * @throws InvalidArgumentException
805
-     * @throws InvalidDataTypeException
806
-     * @throws InvalidInterfaceException
807
-     * @throws ReflectionException
808
-     * @since 4.10.2.p
809
-     */
810
-    public function load_scripts_styles_view_registration()
811
-    {
812
-        // styles
813
-        wp_enqueue_style('espresso-ui-theme');
814
-        // scripts
815
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
816
-        $this->_reg_custom_questions_form->wp_enqueue_scripts();
817
-    }
818
-
819
-
820
-    public function load_scripts_styles_contact_list()
821
-    {
822
-        wp_dequeue_style('espresso_reg');
823
-        wp_register_style(
824
-            'espresso_att',
825
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
826
-            ['ee-admin-css'],
827
-            EVENT_ESPRESSO_VERSION
828
-        );
829
-        wp_enqueue_style('espresso_att');
830
-    }
831
-
832
-
833
-    public function load_scripts_styles_new_registration()
834
-    {
835
-        wp_register_script(
836
-            'ee-spco-for-admin',
837
-            REG_ASSETS_URL . 'spco_for_admin.js',
838
-            ['underscore', 'jquery'],
839
-            EVENT_ESPRESSO_VERSION,
840
-            true
841
-        );
842
-        wp_enqueue_script('ee-spco-for-admin');
843
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
844
-        EE_Form_Section_Proper::wp_enqueue_scripts();
845
-        EED_Ticket_Selector::load_tckt_slctr_assets();
846
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
847
-    }
848
-
849
-
850
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
851
-    {
852
-        add_filter('FHEE_load_EE_messages', '__return_true');
853
-    }
854
-
855
-
856
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
857
-    {
858
-        add_filter('FHEE_load_EE_messages', '__return_true');
859
-    }
860
-
861
-
862
-    /**
863
-     * @throws EE_Error
864
-     * @throws InvalidArgumentException
865
-     * @throws InvalidDataTypeException
866
-     * @throws InvalidInterfaceException
867
-     * @throws ReflectionException
868
-     * @since 4.10.2.p
869
-     */
870
-    protected function _set_list_table_views_default()
871
-    {
872
-        // for notification related bulk actions we need to make sure only active messengers have an option.
873
-        EED_Messages::set_autoloaders();
874
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
875
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
876
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
877
-        // key= bulk_action_slug, value= message type.
878
-        $match_array = [
879
-            'approve_registrations'    => 'registration',
880
-            'decline_registrations'    => 'declined_registration',
881
-            'pending_registrations'    => 'pending_approval',
882
-            'no_approve_registrations' => 'not_approved_registration',
883
-            'cancel_registrations'     => 'cancelled_registration',
884
-        ];
885
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
886
-            'ee_send_message',
887
-            'batch_send_messages'
888
-        );
889
-        /** setup reg status bulk actions **/
890
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
891
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
892
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
893
-                'Approve and Notify Registrations',
894
-                'event_espresso'
895
-            );
896
-        }
897
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
898
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
899
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
900
-                'Decline and Notify Registrations',
901
-                'event_espresso'
902
-            );
903
-        }
904
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
905
-            'Set Registrations to Pending Payment',
906
-            'event_espresso'
907
-        );
908
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
909
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
910
-                'Set Registrations to Pending Payment and Notify',
911
-                'event_espresso'
912
-            );
913
-        }
914
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
915
-            'Set Registrations to Not Approved',
916
-            'event_espresso'
917
-        );
918
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
919
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
920
-                'Set Registrations to Not Approved and Notify',
921
-                'event_espresso'
922
-            );
923
-        }
924
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
925
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
926
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
927
-                'Cancel Registrations and Notify',
928
-                'event_espresso'
929
-            );
930
-        }
931
-        $def_reg_status_actions = apply_filters(
932
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
933
-            $def_reg_status_actions,
934
-            $active_mts,
935
-            $can_send
936
-        );
937
-
938
-        $this->_views = [
939
-            'all'   => [
940
-                'slug'        => 'all',
941
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
942
-                'count'       => 0,
943
-                'bulk_action' => array_merge(
944
-                    $def_reg_status_actions,
945
-                    [
946
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
947
-                    ]
948
-                ),
949
-            ],
950
-            'month' => [
951
-                'slug'        => 'month',
952
-                'label'       => esc_html__('This Month', 'event_espresso'),
953
-                'count'       => 0,
954
-                'bulk_action' => array_merge(
955
-                    $def_reg_status_actions,
956
-                    [
957
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
958
-                    ]
959
-                ),
960
-            ],
961
-            'today' => [
962
-                'slug'        => 'today',
963
-                'label'       => sprintf(
964
-                    esc_html__('Today - %s', 'event_espresso'),
965
-                    date('M d, Y', current_time('timestamp'))
966
-                ),
967
-                'count'       => 0,
968
-                'bulk_action' => array_merge(
969
-                    $def_reg_status_actions,
970
-                    [
971
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
972
-                    ]
973
-                ),
974
-            ],
975
-        ];
976
-        if (
977
-            EE_Registry::instance()->CAP->current_user_can(
978
-                'ee_delete_registrations',
979
-                'espresso_registrations_delete_registration'
980
-            )
981
-        ) {
982
-            $this->_views['incomplete'] = [
983
-                'slug'        => 'incomplete',
984
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
985
-                'count'       => 0,
986
-                'bulk_action' => [
987
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
988
-                ],
989
-            ];
990
-            $this->_views['trash']      = [
991
-                'slug'        => 'trash',
992
-                'label'       => esc_html__('Trash', 'event_espresso'),
993
-                'count'       => 0,
994
-                'bulk_action' => [
995
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
996
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
997
-                ],
998
-            ];
999
-        }
1000
-    }
1001
-
1002
-
1003
-    protected function _set_list_table_views_contact_list()
1004
-    {
1005
-        $this->_views = [
1006
-            'in_use' => [
1007
-                'slug'        => 'in_use',
1008
-                'label'       => esc_html__('In Use', 'event_espresso'),
1009
-                'count'       => 0,
1010
-                'bulk_action' => [
1011
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1012
-                ],
1013
-            ],
1014
-        ];
1015
-        if (
1016
-            EE_Registry::instance()->CAP->current_user_can(
1017
-                'ee_delete_contacts',
1018
-                'espresso_registrations_trash_attendees'
1019
-            )
1020
-        ) {
1021
-            $this->_views['trash'] = [
1022
-                'slug'        => 'trash',
1023
-                'label'       => esc_html__('Trash', 'event_espresso'),
1024
-                'count'       => 0,
1025
-                'bulk_action' => [
1026
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1027
-                ],
1028
-            ];
1029
-        }
1030
-    }
1031
-
1032
-
1033
-    /**
1034
-     * @return array
1035
-     * @throws EE_Error
1036
-     */
1037
-    protected function _registration_legend_items()
1038
-    {
1039
-        $fc_items = [
1040
-            'star-icon'        => [
1041
-                'class' => 'dashicons dashicons-star-filled gold-icon',
1042
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1043
-            ],
1044
-            'view_details'     => [
1045
-                'class' => 'dashicons dashicons-clipboard',
1046
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1047
-            ],
1048
-            'edit_attendee'    => [
1049
-                'class' => 'dashicons dashicons-admin-users',
1050
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1051
-            ],
1052
-            'view_transaction' => [
1053
-                'class' => 'dashicons dashicons-cart',
1054
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1055
-            ],
1056
-            'view_invoice'     => [
1057
-                'class' => 'dashicons dashicons-media-spreadsheet',
1058
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1059
-            ],
1060
-        ];
1061
-        if (
1062
-            EE_Registry::instance()->CAP->current_user_can(
1063
-                'ee_send_message',
1064
-                'espresso_registrations_resend_registration'
1065
-            )
1066
-        ) {
1067
-            $fc_items['resend_registration'] = [
1068
-                'class' => 'dashicons dashicons-email-alt',
1069
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1070
-            ];
1071
-        } else {
1072
-            $fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1073
-        }
1074
-        if (
1075
-            EE_Registry::instance()->CAP->current_user_can(
1076
-                'ee_read_global_messages',
1077
-                'view_filtered_messages'
1078
-            )
1079
-        ) {
1080
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1081
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1082
-                $fc_items['view_related_messages'] = [
1083
-                    'class' => $related_for_icon['css_class'],
1084
-                    'desc'  => $related_for_icon['label'],
1085
-                ];
1086
-            }
1087
-        }
1088
-        $sc_items = [
1089
-            'approved_status'   => [
1090
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1091
-                'desc'  => EEH_Template::pretty_status(
1092
-                    EEM_Registration::status_id_approved,
1093
-                    false,
1094
-                    'sentence'
1095
-                ),
1096
-            ],
1097
-            'pending_status'    => [
1098
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1099
-                'desc'  => EEH_Template::pretty_status(
1100
-                    EEM_Registration::status_id_pending_payment,
1101
-                    false,
1102
-                    'sentence'
1103
-                ),
1104
-            ],
1105
-            'wait_list'         => [
1106
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1107
-                'desc'  => EEH_Template::pretty_status(
1108
-                    EEM_Registration::status_id_wait_list,
1109
-                    false,
1110
-                    'sentence'
1111
-                ),
1112
-            ],
1113
-            'incomplete_status' => [
1114
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1115
-                'desc'  => EEH_Template::pretty_status(
1116
-                    EEM_Registration::status_id_incomplete,
1117
-                    false,
1118
-                    'sentence'
1119
-                ),
1120
-            ],
1121
-            'not_approved'      => [
1122
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1123
-                'desc'  => EEH_Template::pretty_status(
1124
-                    EEM_Registration::status_id_not_approved,
1125
-                    false,
1126
-                    'sentence'
1127
-                ),
1128
-            ],
1129
-            'declined_status'   => [
1130
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1131
-                'desc'  => EEH_Template::pretty_status(
1132
-                    EEM_Registration::status_id_declined,
1133
-                    false,
1134
-                    'sentence'
1135
-                ),
1136
-            ],
1137
-            'cancelled_status'  => [
1138
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1139
-                'desc'  => EEH_Template::pretty_status(
1140
-                    EEM_Registration::status_id_cancelled,
1141
-                    false,
1142
-                    'sentence'
1143
-                ),
1144
-            ],
1145
-        ];
1146
-        return array_merge($fc_items, $sc_items);
1147
-    }
1148
-
1149
-
1150
-
1151
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1152
-
1153
-
1154
-    /**
1155
-     * @throws DomainException
1156
-     * @throws EE_Error
1157
-     * @throws InvalidArgumentException
1158
-     * @throws InvalidDataTypeException
1159
-     * @throws InvalidInterfaceException
1160
-     */
1161
-    protected function _registrations_overview_list_table()
1162
-    {
1163
-        $this->appendAddNewRegistrationButtonToPageTitle();
1164
-        $header_text                  = '';
1165
-        $admin_page_header_decorators = [
1166
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1167
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1168
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1169
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1170
-        ];
1171
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1172
-            $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1173
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1174
-        }
1175
-        $this->_template_args['admin_page_header'] = $header_text;
1176
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1177
-        $this->display_admin_list_table_page_with_no_sidebar();
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * @throws EE_Error
1183
-     * @throws InvalidArgumentException
1184
-     * @throws InvalidDataTypeException
1185
-     * @throws InvalidInterfaceException
1186
-     */
1187
-    private function appendAddNewRegistrationButtonToPageTitle()
1188
-    {
1189
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1190
-        if (
1191
-            $EVT_ID
1192
-            && EE_Registry::instance()->CAP->current_user_can(
1193
-                'ee_edit_registrations',
1194
-                'espresso_registrations_new_registration',
1195
-                $EVT_ID
1196
-            )
1197
-        ) {
1198
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1199
-                'new_registration',
1200
-                'add-registrant',
1201
-                ['event_id' => $EVT_ID],
1202
-                'add-new-h2'
1203
-            );
1204
-        }
1205
-    }
1206
-
1207
-
1208
-    /**
1209
-     * This sets the _registration property for the registration details screen
1210
-     *
1211
-     * @return void
1212
-     * @throws EE_Error
1213
-     * @throws InvalidArgumentException
1214
-     * @throws InvalidDataTypeException
1215
-     * @throws InvalidInterfaceException
1216
-     */
1217
-    private function _set_registration_object()
1218
-    {
1219
-        // get out if we've already set the object
1220
-        if ($this->_registration instanceof EE_Registration) {
1221
-            return;
1222
-        }
1223
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1224
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1225
-            return;
1226
-        }
1227
-        $error_msg = sprintf(
1228
-            esc_html__(
1229
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1230
-                'event_espresso'
1231
-            ),
1232
-            $REG_ID
1233
-        );
1234
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1235
-        $this->_registration = null;
1236
-    }
1237
-
1238
-
1239
-    /**
1240
-     * Used to retrieve registrations for the list table.
1241
-     *
1242
-     * @param int  $per_page
1243
-     * @param bool $count
1244
-     * @param bool $this_month
1245
-     * @param bool $today
1246
-     * @return EE_Registration[]|int
1247
-     * @throws EE_Error
1248
-     * @throws InvalidArgumentException
1249
-     * @throws InvalidDataTypeException
1250
-     * @throws InvalidInterfaceException
1251
-     */
1252
-    public function get_registrations(
1253
-        $per_page = 10,
1254
-        $count = false,
1255
-        $this_month = false,
1256
-        $today = false
1257
-    ) {
1258
-        if ($this_month) {
1259
-            $this->request->setRequestParam('status', 'month');
1260
-        }
1261
-        if ($today) {
1262
-            $this->request->setRequestParam('status', 'today');
1263
-        }
1264
-        $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1265
-        /**
1266
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1267
-         *
1268
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1269
-         * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1270
-         *                      or if you have the development copy of EE you can view this at the path:
1271
-         *                      /docs/G--Model-System/model-query-params.md
1272
-         */
1273
-        $query_params['group_by'] = '';
1274
-
1275
-        return $count
1276
-            ? $this->getRegistrationModel()->count($query_params)
1277
-            /** @type EE_Registration[] */
1278
-            : $this->getRegistrationModel()->get_all($query_params);
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1284
-     * Note: this listens to values on the request for some of the query parameters.
1285
-     *
1286
-     * @param array $request
1287
-     * @param int   $per_page
1288
-     * @param bool  $count
1289
-     * @return array
1290
-     * @throws EE_Error
1291
-     * @throws InvalidArgumentException
1292
-     * @throws InvalidDataTypeException
1293
-     * @throws InvalidInterfaceException
1294
-     */
1295
-    protected function _get_registration_query_parameters(
1296
-        $request = [],
1297
-        $per_page = 10,
1298
-        $count = false
1299
-    ) {
1300
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1301
-        $list_table_query_builder = $this->loader->getNew(
1302
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1303
-            [null, null, $request]
1304
-        );
1305
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1306
-    }
1307
-
1308
-
1309
-    public function get_registration_status_array()
1310
-    {
1311
-        return self::$_reg_status;
1312
-    }
1313
-
1314
-
1315
-
1316
-
1317
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1318
-    /**
1319
-     * generates HTML for the View Registration Details Admin page
1320
-     *
1321
-     * @return void
1322
-     * @throws DomainException
1323
-     * @throws EE_Error
1324
-     * @throws InvalidArgumentException
1325
-     * @throws InvalidDataTypeException
1326
-     * @throws InvalidInterfaceException
1327
-     * @throws EntityNotFoundException
1328
-     * @throws ReflectionException
1329
-     */
1330
-    protected function _registration_details()
1331
-    {
1332
-        $this->_template_args = [];
1333
-        $this->_set_registration_object();
1334
-        if (is_object($this->_registration)) {
1335
-            $transaction                                   = $this->_registration->transaction()
1336
-                ? $this->_registration->transaction()
1337
-                : EE_Transaction::new_instance();
1338
-            $this->_session                                = $transaction->session_data();
1339
-            $event_id                                      = $this->_registration->event_ID();
1340
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1341
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1342
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1343
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1344
-            $this->_template_args['grand_total']           = $transaction->total();
1345
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1346
-            // link back to overview
1347
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1348
-            $this->_template_args['registration']                = $this->_registration;
1349
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1350
-                [
1351
-                    'action'   => 'default',
1352
-                    'event_id' => $event_id,
1353
-                ],
1354
-                REG_ADMIN_URL
1355
-            );
1356
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1357
-                [
1358
-                    'action' => 'default',
1359
-                    'EVT_ID' => $event_id,
1360
-                    'page'   => 'espresso_transactions',
1361
-                ],
1362
-                admin_url('admin.php')
1363
-            );
1364
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1365
-                [
1366
-                    'page'   => 'espresso_events',
1367
-                    'action' => 'edit',
1368
-                    'post'   => $event_id,
1369
-                ],
1370
-                admin_url('admin.php')
1371
-            );
1372
-            // next and previous links
1373
-            $next_reg                                      = $this->_registration->next(
1374
-                null,
1375
-                [],
1376
-                'REG_ID'
1377
-            );
1378
-            $this->_template_args['next_registration']     = $next_reg
1379
-                ? $this->_next_link(
1380
-                    EE_Admin_Page::add_query_args_and_nonce(
1381
-                        [
1382
-                            'action'  => 'view_registration',
1383
-                            '_REG_ID' => $next_reg['REG_ID'],
1384
-                        ],
1385
-                        REG_ADMIN_URL
1386
-                    ),
1387
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1388
-                )
1389
-                : '';
1390
-            $previous_reg                                  = $this->_registration->previous(
1391
-                null,
1392
-                [],
1393
-                'REG_ID'
1394
-            );
1395
-            $this->_template_args['previous_registration'] = $previous_reg
1396
-                ? $this->_previous_link(
1397
-                    EE_Admin_Page::add_query_args_and_nonce(
1398
-                        [
1399
-                            'action'  => 'view_registration',
1400
-                            '_REG_ID' => $previous_reg['REG_ID'],
1401
-                        ],
1402
-                        REG_ADMIN_URL
1403
-                    ),
1404
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1405
-                )
1406
-                : '';
1407
-            // grab header
1408
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1409
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1410
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1411
-                $template_path,
1412
-                $this->_template_args,
1413
-                true
1414
-            );
1415
-        } else {
1416
-            $this->_template_args['admin_page_header'] = '';
1417
-            $this->_display_espresso_notices();
1418
-        }
1419
-        // the details template wrapper
1420
-        $this->display_admin_page_with_sidebar();
1421
-    }
1422
-
1423
-
1424
-    /**
1425
-     * @throws EE_Error
1426
-     * @throws InvalidArgumentException
1427
-     * @throws InvalidDataTypeException
1428
-     * @throws InvalidInterfaceException
1429
-     * @throws ReflectionException
1430
-     * @since 4.10.2.p
1431
-     */
1432
-    protected function _registration_details_metaboxes()
1433
-    {
1434
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1435
-        $this->_set_registration_object();
1436
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1437
-        $this->addMetaBox(
1438
-            'edit-reg-status-mbox',
1439
-            esc_html__('Registration Status', 'event_espresso'),
1440
-            [$this, 'set_reg_status_buttons_metabox'],
1441
-            $this->_wp_page_slug
1442
-        );
1443
-        $this->addMetaBox(
1444
-            'edit-reg-details-mbox',
1445
-            '<span>' . esc_html__('Registration Details', 'event_espresso')
1446
-            . '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1447
-            [$this, '_reg_details_meta_box'],
1448
-            $this->_wp_page_slug
1449
-        );
1450
-        if (
1451
-            $attendee instanceof EE_Attendee
1452
-            && EE_Registry::instance()->CAP->current_user_can(
1453
-                'ee_read_registration',
1454
-                'edit-reg-questions-mbox',
1455
-                $this->_registration->ID()
1456
-            )
1457
-        ) {
1458
-            $this->addMetaBox(
1459
-                $this->_wp_page_slug,
1460
-                'edit-reg-questions-mbox',
1461
-                esc_html__('Registration Form Answers', 'event_espresso'),
1462
-                [$this, '_reg_questions_meta_box'],
1463
-                $this->_wp_page_slug
1464
-            );
1465
-        }
1466
-        $this->addMetaBox(
1467
-            'edit-reg-registrant-mbox',
1468
-            esc_html__('Contact Details', 'event_espresso'),
1469
-            [$this, '_reg_registrant_side_meta_box'],
1470
-            $this->_wp_page_slug,
1471
-            'side'
1472
-        );
1473
-        if ($this->_registration->group_size() > 1) {
1474
-            $this->addMetaBox(
1475
-                'edit-reg-attendees-mbox',
1476
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1477
-                [$this, '_reg_attendees_meta_box'],
1478
-                $this->_wp_page_slug
1479
-            );
1480
-        }
1481
-    }
1482
-
1483
-
1484
-    /**
1485
-     * set_reg_status_buttons_metabox
1486
-     *
1487
-     * @return void
1488
-     * @throws EE_Error
1489
-     * @throws EntityNotFoundException
1490
-     * @throws InvalidArgumentException
1491
-     * @throws InvalidDataTypeException
1492
-     * @throws InvalidInterfaceException
1493
-     * @throws ReflectionException
1494
-     */
1495
-    public function set_reg_status_buttons_metabox()
1496
-    {
1497
-        $this->_set_registration_object();
1498
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1499
-        $output                 = $change_reg_status_form->form_open(
1500
-            self::add_query_args_and_nonce(
1501
-                [
1502
-                    'action' => 'change_reg_status',
1503
-                ],
1504
-                REG_ADMIN_URL
1505
-            )
1506
-        );
1507
-        $output                 .= $change_reg_status_form->get_html();
1508
-        $output                 .= $change_reg_status_form->form_close();
1509
-        echo $output; // already escaped
1510
-    }
1511
-
1512
-
1513
-    /**
1514
-     * @return EE_Form_Section_Proper
1515
-     * @throws EE_Error
1516
-     * @throws InvalidArgumentException
1517
-     * @throws InvalidDataTypeException
1518
-     * @throws InvalidInterfaceException
1519
-     * @throws EntityNotFoundException
1520
-     * @throws ReflectionException
1521
-     */
1522
-    protected function _generate_reg_status_change_form()
1523
-    {
1524
-        $reg_status_change_form_array = [
1525
-            'name'            => 'reg_status_change_form',
1526
-            'html_id'         => 'reg-status-change-form',
1527
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1528
-            'subsections'     => [
1529
-                'return'         => new EE_Hidden_Input(
1530
-                    [
1531
-                        'name'    => 'return',
1532
-                        'default' => 'view_registration',
1533
-                    ]
1534
-                ),
1535
-                'REG_ID'         => new EE_Hidden_Input(
1536
-                    [
1537
-                        'name'    => 'REG_ID',
1538
-                        'default' => $this->_registration->ID(),
1539
-                    ]
1540
-                ),
1541
-                'current_status' => new EE_Form_Section_HTML(
1542
-                    EEH_HTML::table(
1543
-                        EEH_HTML::tr(
1544
-                            EEH_HTML::th(
1545
-                                EEH_HTML::label(
1546
-                                    EEH_HTML::strong(
1547
-                                        esc_html__('Current Registration Status', 'event_espresso')
1548
-                                    )
1549
-                                )
1550
-                            )
1551
-                            . EEH_HTML::td(
1552
-                                EEH_HTML::strong(
1553
-                                    $this->_registration->pretty_status(),
1554
-                                    '',
1555
-                                    'status-' . $this->_registration->status_ID(),
1556
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1557
-                                )
1558
-                            )
1559
-                        )
1560
-                    )
1561
-                ),
1562
-            ],
1563
-        ];
1564
-        if (
1565
-            EE_Registry::instance()->CAP->current_user_can(
1566
-                'ee_edit_registration',
1567
-                'toggle_registration_status',
1568
-                $this->_registration->ID()
1569
-            )
1570
-        ) {
1571
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1572
-                $this->_get_reg_statuses(),
1573
-                [
1574
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1575
-                    'default'         => $this->_registration->status_ID(),
1576
-                ]
1577
-            );
1578
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1579
-                [
1580
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1581
-                    'default'         => false,
1582
-                    'html_help_text'  => esc_html__(
1583
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1584
-                        'event_espresso'
1585
-                    ),
1586
-                ]
1587
-            );
1588
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1589
-                [
1590
-                    'html_class'      => 'button--primary',
1591
-                    'html_label_text' => '&nbsp;',
1592
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1593
-                ]
1594
-            );
1595
-        }
1596
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1597
-    }
1598
-
1599
-
1600
-    /**
1601
-     * Returns an array of all the buttons for the various statuses and switch status actions
1602
-     *
1603
-     * @return array
1604
-     * @throws EE_Error
1605
-     * @throws InvalidArgumentException
1606
-     * @throws InvalidDataTypeException
1607
-     * @throws InvalidInterfaceException
1608
-     * @throws EntityNotFoundException
1609
-     */
1610
-    protected function _get_reg_statuses()
1611
-    {
1612
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1613
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1614
-        // get current reg status
1615
-        $current_status = $this->_registration->status_ID();
1616
-        // is registration for free event? This will determine whether to display the pending payment option
1617
-        if (
1618
-            $current_status !== EEM_Registration::status_id_pending_payment
1619
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1620
-        ) {
1621
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1622
-        }
1623
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1624
-    }
1625
-
1626
-
1627
-    /**
1628
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1629
-     *
1630
-     * @param bool $status REG status given for changing registrations to.
1631
-     * @param bool $notify Whether to send messages notifications or not.
1632
-     * @return array (array with reg_id(s) updated and whether update was successful.
1633
-     * @throws DomainException
1634
-     * @throws EE_Error
1635
-     * @throws EntityNotFoundException
1636
-     * @throws InvalidArgumentException
1637
-     * @throws InvalidDataTypeException
1638
-     * @throws InvalidInterfaceException
1639
-     * @throws ReflectionException
1640
-     * @throws RuntimeException
1641
-     */
1642
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1643
-    {
1644
-        $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1645
-            ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1646
-            : $this->request->getRequestParam('_REG_ID', [], 'int', true);
1647
-
1648
-        // sanitize $REG_IDs
1649
-        $REG_IDs = array_map('absint', $REG_IDs);
1650
-        // and remove empty entries
1651
-        $REG_IDs = array_filter($REG_IDs);
1652
-
1653
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1654
-
1655
-        /**
1656
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1657
-         * Currently this value is used downstream by the _process_resend_registration method.
1658
-         *
1659
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1660
-         * @param bool                     $status           The status registrations were changed to.
1661
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1662
-         * @param Registrations_Admin_Page $admin_page_object
1663
-         */
1664
-        $REG_ID = apply_filters(
1665
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1666
-            $result['REG_ID'],
1667
-            $status,
1668
-            $result['success'],
1669
-            $this
1670
-        );
1671
-        $this->request->setRequestParam('_REG_ID', $REG_ID);
1672
-
1673
-        // notify?
1674
-        if (
1675
-            $notify
1676
-            && $result['success']
1677
-            && ! empty($REG_ID)
1678
-            && EE_Registry::instance()->CAP->current_user_can(
1679
-                'ee_send_message',
1680
-                'espresso_registrations_resend_registration'
1681
-            )
1682
-        ) {
1683
-            $this->_process_resend_registration();
1684
-        }
1685
-        return $result;
1686
-    }
1687
-
1688
-
1689
-    /**
1690
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1691
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1692
-     *
1693
-     * @param array  $REG_IDs
1694
-     * @param string $status
1695
-     * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1696
-     *                       slug sent with setting the registration status.
1697
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
-     * @throws EE_Error
1699
-     * @throws InvalidArgumentException
1700
-     * @throws InvalidDataTypeException
1701
-     * @throws InvalidInterfaceException
1702
-     * @throws ReflectionException
1703
-     * @throws RuntimeException
1704
-     * @throws EntityNotFoundException
1705
-     * @throws DomainException
1706
-     */
1707
-    protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1708
-    {
1709
-        $success = false;
1710
-        // typecast $REG_IDs
1711
-        $REG_IDs = (array) $REG_IDs;
1712
-        if (! empty($REG_IDs)) {
1713
-            $success = true;
1714
-            // set default status if none is passed
1715
-            $status         = $status ?: EEM_Registration::status_id_pending_payment;
1716
-            $status_context = $notify
1717
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1718
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1719
-            // loop through REG_ID's and change status
1720
-            foreach ($REG_IDs as $REG_ID) {
1721
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1722
-                if ($registration instanceof EE_Registration) {
1723
-                    $registration->set_status(
1724
-                        $status,
1725
-                        false,
1726
-                        new Context(
1727
-                            $status_context,
1728
-                            esc_html__(
1729
-                                'Manually triggered status change on a Registration Admin Page route.',
1730
-                                'event_espresso'
1731
-                            )
1732
-                        )
1733
-                    );
1734
-                    $result = $registration->save();
1735
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1736
-                    $success = $result !== false ? $success : false;
1737
-                }
1738
-            }
1739
-        }
1740
-
1741
-        // return $success and processed registrations
1742
-        return ['REG_ID' => $REG_IDs, 'success' => $success];
1743
-    }
1744
-
1745
-
1746
-    /**
1747
-     * Common logic for setting up success message and redirecting to appropriate route
1748
-     *
1749
-     * @param string $STS_ID status id for the registration changed to
1750
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1751
-     * @return void
1752
-     * @throws DomainException
1753
-     * @throws EE_Error
1754
-     * @throws EntityNotFoundException
1755
-     * @throws InvalidArgumentException
1756
-     * @throws InvalidDataTypeException
1757
-     * @throws InvalidInterfaceException
1758
-     * @throws ReflectionException
1759
-     * @throws RuntimeException
1760
-     */
1761
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1762
-    {
1763
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1764
-            : ['success' => false];
1765
-        $success = isset($result['success']) && $result['success'];
1766
-        // setup success message
1767
-        if ($success) {
1768
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1769
-                $msg = sprintf(
1770
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1771
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1772
-                );
1773
-            } else {
1774
-                $msg = sprintf(
1775
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1776
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1777
-                );
1778
-            }
1779
-            EE_Error::add_success($msg);
1780
-        } else {
1781
-            EE_Error::add_error(
1782
-                esc_html__(
1783
-                    'Something went wrong, and the status was not changed',
1784
-                    'event_espresso'
1785
-                ),
1786
-                __FILE__,
1787
-                __LINE__,
1788
-                __FUNCTION__
1789
-            );
1790
-        }
1791
-        $return = $this->request->getRequestParam('return');
1792
-        $route  = $return === 'view_registration'
1793
-            ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1794
-            : ['action' => 'default'];
1795
-        $route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1796
-        $this->_redirect_after_action($success, '', '', $route, true);
1797
-    }
1798
-
1799
-
1800
-    /**
1801
-     * incoming reg status change from reg details page.
1802
-     *
1803
-     * @return void
1804
-     * @throws EE_Error
1805
-     * @throws EntityNotFoundException
1806
-     * @throws InvalidArgumentException
1807
-     * @throws InvalidDataTypeException
1808
-     * @throws InvalidInterfaceException
1809
-     * @throws ReflectionException
1810
-     * @throws RuntimeException
1811
-     * @throws DomainException
1812
-     */
1813
-    protected function _change_reg_status()
1814
-    {
1815
-        $this->request->setRequestParam('return', 'view_registration');
1816
-        // set notify based on whether the send notifications toggle is set or not
1817
-        $notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1818
-        $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1819
-        $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1820
-        switch ($reg_status) {
1821
-            case EEM_Registration::status_id_approved:
1822
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1823
-                $this->approve_registration($notify);
1824
-                break;
1825
-            case EEM_Registration::status_id_pending_payment:
1826
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1827
-                $this->pending_registration($notify);
1828
-                break;
1829
-            case EEM_Registration::status_id_not_approved:
1830
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1831
-                $this->not_approve_registration($notify);
1832
-                break;
1833
-            case EEM_Registration::status_id_declined:
1834
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1835
-                $this->decline_registration($notify);
1836
-                break;
1837
-            case EEM_Registration::status_id_cancelled:
1838
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1839
-                $this->cancel_registration($notify);
1840
-                break;
1841
-            case EEM_Registration::status_id_wait_list:
1842
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1843
-                $this->wait_list_registration($notify);
1844
-                break;
1845
-            case EEM_Registration::status_id_incomplete:
1846
-            default:
1847
-                $this->request->unSetRequestParam('return');
1848
-                $this->_reg_status_change_return('');
1849
-                break;
1850
-        }
1851
-    }
1852
-
1853
-
1854
-    /**
1855
-     * Callback for bulk action routes.
1856
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1857
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1858
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1859
-     * when an action is happening on just a single registration).
1860
-     *
1861
-     * @param      $action
1862
-     * @param bool $notify
1863
-     */
1864
-    protected function bulk_action_on_registrations($action, $notify = false)
1865
-    {
1866
-        do_action(
1867
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1868
-            $this,
1869
-            $action,
1870
-            $notify
1871
-        );
1872
-        $method = $action . '_registration';
1873
-        if (method_exists($this, $method)) {
1874
-            $this->$method($notify);
1875
-        }
1876
-    }
1877
-
1878
-
1879
-    /**
1880
-     * approve_registration
1881
-     *
1882
-     * @param bool $notify whether or not to notify the registrant about their approval.
1883
-     * @return void
1884
-     * @throws EE_Error
1885
-     * @throws EntityNotFoundException
1886
-     * @throws InvalidArgumentException
1887
-     * @throws InvalidDataTypeException
1888
-     * @throws InvalidInterfaceException
1889
-     * @throws ReflectionException
1890
-     * @throws RuntimeException
1891
-     * @throws DomainException
1892
-     */
1893
-    protected function approve_registration($notify = false)
1894
-    {
1895
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1896
-    }
1897
-
1898
-
1899
-    /**
1900
-     * decline_registration
1901
-     *
1902
-     * @param bool $notify whether or not to notify the registrant about their status change.
1903
-     * @return void
1904
-     * @throws EE_Error
1905
-     * @throws EntityNotFoundException
1906
-     * @throws InvalidArgumentException
1907
-     * @throws InvalidDataTypeException
1908
-     * @throws InvalidInterfaceException
1909
-     * @throws ReflectionException
1910
-     * @throws RuntimeException
1911
-     * @throws DomainException
1912
-     */
1913
-    protected function decline_registration($notify = false)
1914
-    {
1915
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1916
-    }
1917
-
1918
-
1919
-    /**
1920
-     * cancel_registration
1921
-     *
1922
-     * @param bool $notify whether or not to notify the registrant about their status change.
1923
-     * @return void
1924
-     * @throws EE_Error
1925
-     * @throws EntityNotFoundException
1926
-     * @throws InvalidArgumentException
1927
-     * @throws InvalidDataTypeException
1928
-     * @throws InvalidInterfaceException
1929
-     * @throws ReflectionException
1930
-     * @throws RuntimeException
1931
-     * @throws DomainException
1932
-     */
1933
-    protected function cancel_registration($notify = false)
1934
-    {
1935
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1936
-    }
1937
-
1938
-
1939
-    /**
1940
-     * not_approve_registration
1941
-     *
1942
-     * @param bool $notify whether or not to notify the registrant about their status change.
1943
-     * @return void
1944
-     * @throws EE_Error
1945
-     * @throws EntityNotFoundException
1946
-     * @throws InvalidArgumentException
1947
-     * @throws InvalidDataTypeException
1948
-     * @throws InvalidInterfaceException
1949
-     * @throws ReflectionException
1950
-     * @throws RuntimeException
1951
-     * @throws DomainException
1952
-     */
1953
-    protected function not_approve_registration($notify = false)
1954
-    {
1955
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1956
-    }
1957
-
1958
-
1959
-    /**
1960
-     * decline_registration
1961
-     *
1962
-     * @param bool $notify whether or not to notify the registrant about their status change.
1963
-     * @return void
1964
-     * @throws EE_Error
1965
-     * @throws EntityNotFoundException
1966
-     * @throws InvalidArgumentException
1967
-     * @throws InvalidDataTypeException
1968
-     * @throws InvalidInterfaceException
1969
-     * @throws ReflectionException
1970
-     * @throws RuntimeException
1971
-     * @throws DomainException
1972
-     */
1973
-    protected function pending_registration($notify = false)
1974
-    {
1975
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1976
-    }
1977
-
1978
-
1979
-    /**
1980
-     * waitlist_registration
1981
-     *
1982
-     * @param bool $notify whether or not to notify the registrant about their status change.
1983
-     * @return void
1984
-     * @throws EE_Error
1985
-     * @throws EntityNotFoundException
1986
-     * @throws InvalidArgumentException
1987
-     * @throws InvalidDataTypeException
1988
-     * @throws InvalidInterfaceException
1989
-     * @throws ReflectionException
1990
-     * @throws RuntimeException
1991
-     * @throws DomainException
1992
-     */
1993
-    protected function wait_list_registration($notify = false)
1994
-    {
1995
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1996
-    }
1997
-
1998
-
1999
-    /**
2000
-     * generates HTML for the Registration main meta box
2001
-     *
2002
-     * @return void
2003
-     * @throws DomainException
2004
-     * @throws EE_Error
2005
-     * @throws InvalidArgumentException
2006
-     * @throws InvalidDataTypeException
2007
-     * @throws InvalidInterfaceException
2008
-     * @throws ReflectionException
2009
-     * @throws EntityNotFoundException
2010
-     */
2011
-    public function _reg_details_meta_box()
2012
-    {
2013
-        EEH_Autoloader::register_line_item_display_autoloaders();
2014
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2015
-        EE_Registry::instance()->load_helper('Line_Item');
2016
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2017
-            : EE_Transaction::new_instance();
2018
-        $this->_session = $transaction->session_data();
2019
-        $filters        = new EE_Line_Item_Filter_Collection();
2020
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2021
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2022
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2023
-            $filters,
2024
-            $transaction->total_line_item()
2025
-        );
2026
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2027
-        $line_item_display                       = new EE_Line_Item_Display(
2028
-            'reg_admin_table',
2029
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2030
-        );
2031
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2032
-            $filtered_line_item_tree,
2033
-            ['EE_Registration' => $this->_registration]
2034
-        );
2035
-        $attendee                                = $this->_registration->attendee();
2036
-        if (
2037
-            EE_Registry::instance()->CAP->current_user_can(
2038
-                'ee_read_transaction',
2039
-                'espresso_transactions_view_transaction'
2040
-            )
2041
-        ) {
2042
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2043
-                EE_Admin_Page::add_query_args_and_nonce(
2044
-                    [
2045
-                        'action' => 'view_transaction',
2046
-                        'TXN_ID' => $transaction->ID(),
2047
-                    ],
2048
-                    TXN_ADMIN_URL
2049
-                ),
2050
-                esc_html__(' View Transaction', 'event_espresso'),
2051
-                'button button--secondary right',
2052
-                'dashicons dashicons-cart'
2053
-            );
2054
-        } else {
2055
-            $this->_template_args['view_transaction_button'] = '';
2056
-        }
2057
-        if (
2058
-            $attendee instanceof EE_Attendee
2059
-            && EE_Registry::instance()->CAP->current_user_can(
2060
-                'ee_send_message',
2061
-                'espresso_registrations_resend_registration'
2062
-            )
2063
-        ) {
2064
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2065
-                EE_Admin_Page::add_query_args_and_nonce(
2066
-                    [
2067
-                        'action'      => 'resend_registration',
2068
-                        '_REG_ID'     => $this->_registration->ID(),
2069
-                        'redirect_to' => 'view_registration',
2070
-                    ],
2071
-                    REG_ADMIN_URL
2072
-                ),
2073
-                esc_html__(' Resend Registration', 'event_espresso'),
2074
-                'button button--secondary right',
2075
-                'dashicons dashicons-email-alt'
2076
-            );
2077
-        } else {
2078
-            $this->_template_args['resend_registration_button'] = '';
2079
-        }
2080
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2081
-        $payment                               = $transaction->get_first_related('Payment');
2082
-        $payment                               = ! $payment instanceof EE_Payment
2083
-            ? EE_Payment::new_instance()
2084
-            : $payment;
2085
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2086
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2087
-            ? EE_Payment_Method::new_instance()
2088
-            : $payment_method;
2089
-        $reg_details                           = [
2090
-            'payment_method'       => $payment_method->name(),
2091
-            'response_msg'         => $payment->gateway_response(),
2092
-            'registration_id'      => $this->_registration->get('REG_code'),
2093
-            'registration_session' => $this->_registration->session_ID(),
2094
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2095
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2096
-        ];
2097
-        if (isset($reg_details['registration_id'])) {
2098
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2099
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2100
-                'Registration ID',
2101
-                'event_espresso'
2102
-            );
2103
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2104
-        }
2105
-        if (isset($reg_details['payment_method'])) {
2106
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2107
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2108
-                'Most Recent Payment Method',
2109
-                'event_espresso'
2110
-            );
2111
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2112
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2113
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2114
-                'Payment method response',
2115
-                'event_espresso'
2116
-            );
2117
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2118
-        }
2119
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2120
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2121
-            'Registration Session',
2122
-            'event_espresso'
2123
-        );
2124
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2125
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2126
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2127
-            'Registration placed from IP',
2128
-            'event_espresso'
2129
-        );
2130
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2131
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2132
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2133
-            'Registrant User Agent',
2134
-            'event_espresso'
2135
-        );
2136
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2137
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2138
-            [
2139
-                'action'   => 'default',
2140
-                'event_id' => $this->_registration->event_ID(),
2141
-            ],
2142
-            REG_ADMIN_URL
2143
-        );
2144
-
2145
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2146
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2147
-
2148
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2149
-        EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2150
-    }
2151
-
2152
-
2153
-    /**
2154
-     * generates HTML for the Registration Questions meta box.
2155
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2156
-     * otherwise uses new forms system
2157
-     *
2158
-     * @return void
2159
-     * @throws DomainException
2160
-     * @throws EE_Error
2161
-     * @throws InvalidArgumentException
2162
-     * @throws InvalidDataTypeException
2163
-     * @throws InvalidInterfaceException
2164
-     * @throws ReflectionException
2165
-     */
2166
-    public function _reg_questions_meta_box()
2167
-    {
2168
-        // allow someone to override this method entirely
2169
-        if (
2170
-            apply_filters(
2171
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2172
-                true,
2173
-                $this,
2174
-                $this->_registration
2175
-            )
2176
-        ) {
2177
-            $form = $this->_get_reg_custom_questions_form(
2178
-                $this->_registration->ID()
2179
-            );
2180
-
2181
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2182
-                ? $form->get_html_and_js()
2183
-                : '';
2184
-
2185
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2186
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2187
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2188
-            EEH_Template::display_template($template_path, $this->_template_args);
2189
-        }
2190
-    }
2191
-
2192
-
2193
-    /**
2194
-     * form_before_question_group
2195
-     *
2196
-     * @param string $output
2197
-     * @return        string
2198
-     * @deprecated    as of 4.8.32.rc.000
2199
-     */
2200
-    public function form_before_question_group($output)
2201
-    {
2202
-        EE_Error::doing_it_wrong(
2203
-            __CLASS__ . '::' . __FUNCTION__,
2204
-            esc_html__(
2205
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2206
-                'event_espresso'
2207
-            ),
2208
-            '4.8.32.rc.000'
2209
-        );
2210
-        return '
22
+	/**
23
+	 * @var EE_Registration
24
+	 */
25
+	private $_registration;
26
+
27
+	/**
28
+	 * @var EE_Event
29
+	 */
30
+	private $_reg_event;
31
+
32
+	/**
33
+	 * @var EE_Session
34
+	 */
35
+	private $_session;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private static $_reg_status;
41
+
42
+	/**
43
+	 * Form for displaying the custom questions for this registration.
44
+	 * This gets used a few times throughout the request so its best to cache it
45
+	 *
46
+	 * @var EE_Registration_Custom_Questions_Form
47
+	 */
48
+	protected $_reg_custom_questions_form;
49
+
50
+	/**
51
+	 * @var EEM_Registration $registration_model
52
+	 */
53
+	private $registration_model;
54
+
55
+	/**
56
+	 * @var EEM_Attendee $attendee_model
57
+	 */
58
+	private $attendee_model;
59
+
60
+	/**
61
+	 * @var EEM_Event $event_model
62
+	 */
63
+	private $event_model;
64
+
65
+	/**
66
+	 * @var EEM_Status $status_model
67
+	 */
68
+	private $status_model;
69
+
70
+
71
+	/**
72
+	 * @param bool $routing
73
+	 * @throws EE_Error
74
+	 * @throws InvalidArgumentException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws ReflectionException
78
+	 */
79
+	public function __construct($routing = true)
80
+	{
81
+		parent::__construct($routing);
82
+		add_action('wp_loaded', [$this, 'wp_loaded']);
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return EEM_Registration
88
+	 * @throws InvalidArgumentException
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @since 4.10.2.p
92
+	 */
93
+	protected function getRegistrationModel()
94
+	{
95
+		if (! $this->registration_model instanceof EEM_Registration) {
96
+			$this->registration_model = $this->loader->getShared('EEM_Registration');
97
+		}
98
+		return $this->registration_model;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return EEM_Attendee
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @since 4.10.2.p
108
+	 */
109
+	protected function getAttendeeModel()
110
+	{
111
+		if (! $this->attendee_model instanceof EEM_Attendee) {
112
+			$this->attendee_model = $this->loader->getShared('EEM_Attendee');
113
+		}
114
+		return $this->attendee_model;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return EEM_Event
120
+	 * @throws InvalidArgumentException
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidInterfaceException
123
+	 * @since 4.10.2.p
124
+	 */
125
+	protected function getEventModel()
126
+	{
127
+		if (! $this->event_model instanceof EEM_Event) {
128
+			$this->event_model = $this->loader->getShared('EEM_Event');
129
+		}
130
+		return $this->event_model;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return EEM_Status
136
+	 * @throws InvalidArgumentException
137
+	 * @throws InvalidDataTypeException
138
+	 * @throws InvalidInterfaceException
139
+	 * @since 4.10.2.p
140
+	 */
141
+	protected function getStatusModel()
142
+	{
143
+		if (! $this->status_model instanceof EEM_Status) {
144
+			$this->status_model = $this->loader->getShared('EEM_Status');
145
+		}
146
+		return $this->status_model;
147
+	}
148
+
149
+
150
+	public function wp_loaded()
151
+	{
152
+		// when adding a new registration...
153
+		$action = $this->request->getRequestParam('action');
154
+		if ($action === 'new_registration') {
155
+			EE_System::do_not_cache();
156
+			if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
157
+				// and it's NOT the attendee information reg step
158
+				// force cookie expiration by setting time to last week
159
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
160
+				// and update the global
161
+				$_COOKIE['ee_registration_added'] = 0;
162
+			}
163
+		}
164
+	}
165
+
166
+
167
+	protected function _init_page_props()
168
+	{
169
+		$this->page_slug        = REG_PG_SLUG;
170
+		$this->_admin_base_url  = REG_ADMIN_URL;
171
+		$this->_admin_base_path = REG_ADMIN;
172
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
173
+		$this->_cpt_routes      = [
174
+			'add_new_attendee' => 'espresso_attendees',
175
+			'edit_attendee'    => 'espresso_attendees',
176
+			'insert_attendee'  => 'espresso_attendees',
177
+			'update_attendee'  => 'espresso_attendees',
178
+		];
179
+		$this->_cpt_model_names = [
180
+			'add_new_attendee' => 'EEM_Attendee',
181
+			'edit_attendee'    => 'EEM_Attendee',
182
+		];
183
+		$this->_cpt_edit_routes = [
184
+			'espresso_attendees' => 'edit_attendee',
185
+		];
186
+		$this->_pagenow_map     = [
187
+			'add_new_attendee' => 'post-new.php',
188
+			'edit_attendee'    => 'post.php',
189
+			'trash'            => 'post.php',
190
+		];
191
+		add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
192
+		// add filters so that the comment urls don't take users to a confusing 404 page
193
+		add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param string     $link    The comment permalink with '#comment-$id' appended.
199
+	 * @param WP_Comment $comment The current comment object.
200
+	 * @return string
201
+	 */
202
+	public function clear_comment_link($link, WP_Comment $comment)
203
+	{
204
+		// gotta make sure this only happens on this route
205
+		$post_type = get_post_type($comment->comment_post_ID);
206
+		if ($post_type === 'espresso_attendees') {
207
+			return '#commentsdiv';
208
+		}
209
+		return $link;
210
+	}
211
+
212
+
213
+	protected function _ajax_hooks()
214
+	{
215
+		// todo: all hooks for registrations ajax goes in here
216
+		add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
217
+	}
218
+
219
+
220
+	protected function _define_page_props()
221
+	{
222
+		$this->_admin_page_title = $this->page_label;
223
+		$this->_labels           = [
224
+			'buttons'                      => [
225
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
226
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
227
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
228
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
229
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
230
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
231
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
232
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
233
+			],
234
+			'publishbox'                   => [
235
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
236
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
237
+			],
238
+			'hide_add_button_on_cpt_route' => [
239
+				'edit_attendee' => true,
240
+			],
241
+		];
242
+	}
243
+
244
+
245
+	/**
246
+	 * grab url requests and route them
247
+	 *
248
+	 * @return void
249
+	 * @throws EE_Error
250
+	 */
251
+	public function _set_page_routes()
252
+	{
253
+		$this->_get_registration_status_array();
254
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
255
+		$REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
256
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
257
+		$ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
258
+		$this->_page_routes = [
259
+			'default'                             => [
260
+				'func'       => '_registrations_overview_list_table',
261
+				'capability' => 'ee_read_registrations',
262
+			],
263
+			'view_registration'                   => [
264
+				'func'       => '_registration_details',
265
+				'capability' => 'ee_read_registration',
266
+				'obj_id'     => $REG_ID,
267
+			],
268
+			'edit_registration'                   => [
269
+				'func'               => '_update_attendee_registration_form',
270
+				'noheader'           => true,
271
+				'headers_sent_route' => 'view_registration',
272
+				'capability'         => 'ee_edit_registration',
273
+				'obj_id'             => $REG_ID,
274
+				'_REG_ID'            => $REG_ID,
275
+			],
276
+			'trash_registrations'                 => [
277
+				'func'       => '_trash_or_restore_registrations',
278
+				'args'       => ['trash' => true],
279
+				'noheader'   => true,
280
+				'capability' => 'ee_delete_registrations',
281
+			],
282
+			'restore_registrations'               => [
283
+				'func'       => '_trash_or_restore_registrations',
284
+				'args'       => ['trash' => false],
285
+				'noheader'   => true,
286
+				'capability' => 'ee_delete_registrations',
287
+			],
288
+			'delete_registrations'                => [
289
+				'func'       => '_delete_registrations',
290
+				'noheader'   => true,
291
+				'capability' => 'ee_delete_registrations',
292
+			],
293
+			'new_registration'                    => [
294
+				'func'       => 'new_registration',
295
+				'capability' => 'ee_edit_registrations',
296
+			],
297
+			'process_reg_step'                    => [
298
+				'func'       => 'process_reg_step',
299
+				'noheader'   => true,
300
+				'capability' => 'ee_edit_registrations',
301
+			],
302
+			'redirect_to_txn'                     => [
303
+				'func'       => 'redirect_to_txn',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+			],
307
+			'change_reg_status'                   => [
308
+				'func'       => '_change_reg_status',
309
+				'noheader'   => true,
310
+				'capability' => 'ee_edit_registration',
311
+				'obj_id'     => $REG_ID,
312
+			],
313
+			'approve_registration'                => [
314
+				'func'       => 'approve_registration',
315
+				'noheader'   => true,
316
+				'capability' => 'ee_edit_registration',
317
+				'obj_id'     => $REG_ID,
318
+			],
319
+			'approve_and_notify_registration'     => [
320
+				'func'       => 'approve_registration',
321
+				'noheader'   => true,
322
+				'args'       => [true],
323
+				'capability' => 'ee_edit_registration',
324
+				'obj_id'     => $REG_ID,
325
+			],
326
+			'approve_registrations'               => [
327
+				'func'       => 'bulk_action_on_registrations',
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_registrations',
330
+				'args'       => ['approve'],
331
+			],
332
+			'approve_and_notify_registrations'    => [
333
+				'func'       => 'bulk_action_on_registrations',
334
+				'noheader'   => true,
335
+				'capability' => 'ee_edit_registrations',
336
+				'args'       => ['approve', true],
337
+			],
338
+			'decline_registration'                => [
339
+				'func'       => 'decline_registration',
340
+				'noheader'   => true,
341
+				'capability' => 'ee_edit_registration',
342
+				'obj_id'     => $REG_ID,
343
+			],
344
+			'decline_and_notify_registration'     => [
345
+				'func'       => 'decline_registration',
346
+				'noheader'   => true,
347
+				'args'       => [true],
348
+				'capability' => 'ee_edit_registration',
349
+				'obj_id'     => $REG_ID,
350
+			],
351
+			'decline_registrations'               => [
352
+				'func'       => 'bulk_action_on_registrations',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_edit_registrations',
355
+				'args'       => ['decline'],
356
+			],
357
+			'decline_and_notify_registrations'    => [
358
+				'func'       => 'bulk_action_on_registrations',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_edit_registrations',
361
+				'args'       => ['decline', true],
362
+			],
363
+			'pending_registration'                => [
364
+				'func'       => 'pending_registration',
365
+				'noheader'   => true,
366
+				'capability' => 'ee_edit_registration',
367
+				'obj_id'     => $REG_ID,
368
+			],
369
+			'pending_and_notify_registration'     => [
370
+				'func'       => 'pending_registration',
371
+				'noheader'   => true,
372
+				'args'       => [true],
373
+				'capability' => 'ee_edit_registration',
374
+				'obj_id'     => $REG_ID,
375
+			],
376
+			'pending_registrations'               => [
377
+				'func'       => 'bulk_action_on_registrations',
378
+				'noheader'   => true,
379
+				'capability' => 'ee_edit_registrations',
380
+				'args'       => ['pending'],
381
+			],
382
+			'pending_and_notify_registrations'    => [
383
+				'func'       => 'bulk_action_on_registrations',
384
+				'noheader'   => true,
385
+				'capability' => 'ee_edit_registrations',
386
+				'args'       => ['pending', true],
387
+			],
388
+			'no_approve_registration'             => [
389
+				'func'       => 'not_approve_registration',
390
+				'noheader'   => true,
391
+				'capability' => 'ee_edit_registration',
392
+				'obj_id'     => $REG_ID,
393
+			],
394
+			'no_approve_and_notify_registration'  => [
395
+				'func'       => 'not_approve_registration',
396
+				'noheader'   => true,
397
+				'args'       => [true],
398
+				'capability' => 'ee_edit_registration',
399
+				'obj_id'     => $REG_ID,
400
+			],
401
+			'no_approve_registrations'            => [
402
+				'func'       => 'bulk_action_on_registrations',
403
+				'noheader'   => true,
404
+				'capability' => 'ee_edit_registrations',
405
+				'args'       => ['not_approve'],
406
+			],
407
+			'no_approve_and_notify_registrations' => [
408
+				'func'       => 'bulk_action_on_registrations',
409
+				'noheader'   => true,
410
+				'capability' => 'ee_edit_registrations',
411
+				'args'       => ['not_approve', true],
412
+			],
413
+			'cancel_registration'                 => [
414
+				'func'       => 'cancel_registration',
415
+				'noheader'   => true,
416
+				'capability' => 'ee_edit_registration',
417
+				'obj_id'     => $REG_ID,
418
+			],
419
+			'cancel_and_notify_registration'      => [
420
+				'func'       => 'cancel_registration',
421
+				'noheader'   => true,
422
+				'args'       => [true],
423
+				'capability' => 'ee_edit_registration',
424
+				'obj_id'     => $REG_ID,
425
+			],
426
+			'cancel_registrations'                => [
427
+				'func'       => 'bulk_action_on_registrations',
428
+				'noheader'   => true,
429
+				'capability' => 'ee_edit_registrations',
430
+				'args'       => ['cancel'],
431
+			],
432
+			'cancel_and_notify_registrations'     => [
433
+				'func'       => 'bulk_action_on_registrations',
434
+				'noheader'   => true,
435
+				'capability' => 'ee_edit_registrations',
436
+				'args'       => ['cancel', true],
437
+			],
438
+			'wait_list_registration'              => [
439
+				'func'       => 'wait_list_registration',
440
+				'noheader'   => true,
441
+				'capability' => 'ee_edit_registration',
442
+				'obj_id'     => $REG_ID,
443
+			],
444
+			'wait_list_and_notify_registration'   => [
445
+				'func'       => 'wait_list_registration',
446
+				'noheader'   => true,
447
+				'args'       => [true],
448
+				'capability' => 'ee_edit_registration',
449
+				'obj_id'     => $REG_ID,
450
+			],
451
+			'contact_list'                        => [
452
+				'func'       => '_attendee_contact_list_table',
453
+				'capability' => 'ee_read_contacts',
454
+			],
455
+			'add_new_attendee'                    => [
456
+				'func' => '_create_new_cpt_item',
457
+				'args' => [
458
+					'new_attendee' => true,
459
+					'capability'   => 'ee_edit_contacts',
460
+				],
461
+			],
462
+			'edit_attendee'                       => [
463
+				'func'       => '_edit_cpt_item',
464
+				'capability' => 'ee_edit_contacts',
465
+				'obj_id'     => $ATT_ID,
466
+			],
467
+			'duplicate_attendee'                  => [
468
+				'func'       => '_duplicate_attendee',
469
+				'noheader'   => true,
470
+				'capability' => 'ee_edit_contacts',
471
+				'obj_id'     => $ATT_ID,
472
+			],
473
+			'insert_attendee'                     => [
474
+				'func'       => '_insert_or_update_attendee',
475
+				'args'       => [
476
+					'new_attendee' => true,
477
+				],
478
+				'noheader'   => true,
479
+				'capability' => 'ee_edit_contacts',
480
+			],
481
+			'update_attendee'                     => [
482
+				'func'       => '_insert_or_update_attendee',
483
+				'args'       => [
484
+					'new_attendee' => false,
485
+				],
486
+				'noheader'   => true,
487
+				'capability' => 'ee_edit_contacts',
488
+				'obj_id'     => $ATT_ID,
489
+			],
490
+			'trash_attendees'                     => [
491
+				'func'       => '_trash_or_restore_attendees',
492
+				'args'       => [
493
+					'trash' => 'true',
494
+				],
495
+				'noheader'   => true,
496
+				'capability' => 'ee_delete_contacts',
497
+			],
498
+			'trash_attendee'                      => [
499
+				'func'       => '_trash_or_restore_attendees',
500
+				'args'       => [
501
+					'trash' => true,
502
+				],
503
+				'noheader'   => true,
504
+				'capability' => 'ee_delete_contacts',
505
+				'obj_id'     => $ATT_ID,
506
+			],
507
+			'restore_attendees'                   => [
508
+				'func'       => '_trash_or_restore_attendees',
509
+				'args'       => [
510
+					'trash' => false,
511
+				],
512
+				'noheader'   => true,
513
+				'capability' => 'ee_delete_contacts',
514
+				'obj_id'     => $ATT_ID,
515
+			],
516
+			'resend_registration'                 => [
517
+				'func'       => '_resend_registration',
518
+				'noheader'   => true,
519
+				'capability' => 'ee_send_message',
520
+			],
521
+			'registrations_report'                => [
522
+				'func'       => '_registrations_report',
523
+				'noheader'   => true,
524
+				'capability' => 'ee_read_registrations',
525
+			],
526
+			'contact_list_export'                 => [
527
+				'func'       => '_contact_list_export',
528
+				'noheader'   => true,
529
+				'capability' => 'export',
530
+			],
531
+			'contact_list_report'                 => [
532
+				'func'       => '_contact_list_report',
533
+				'noheader'   => true,
534
+				'capability' => 'ee_read_contacts',
535
+			],
536
+		];
537
+	}
538
+
539
+
540
+	protected function _set_page_config()
541
+	{
542
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
543
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
544
+		$this->_page_config = [
545
+			'default'           => [
546
+				'nav'           => [
547
+					'label' => esc_html__('Overview', 'event_espresso'),
548
+					'order' => 5,
549
+				],
550
+				'help_tabs'     => [
551
+					'registrations_overview_help_tab'                       => [
552
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
553
+						'filename' => 'registrations_overview',
554
+					],
555
+					'registrations_overview_table_column_headings_help_tab' => [
556
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
557
+						'filename' => 'registrations_overview_table_column_headings',
558
+					],
559
+					'registrations_overview_filters_help_tab'               => [
560
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
561
+						'filename' => 'registrations_overview_filters',
562
+					],
563
+					'registrations_overview_views_help_tab'                 => [
564
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
565
+						'filename' => 'registrations_overview_views',
566
+					],
567
+					'registrations_regoverview_other_help_tab'              => [
568
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
569
+						'filename' => 'registrations_overview_other',
570
+					],
571
+				],
572
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
573
+				// 'help_tour'     => array('Registration_Overview_Help_Tour'),
574
+				'qtips'         => ['Registration_List_Table_Tips'],
575
+				'list_table'    => 'EE_Registrations_List_Table',
576
+				'require_nonce' => false,
577
+			],
578
+			'view_registration' => [
579
+				'nav'           => [
580
+					'label'      => esc_html__('REG Details', 'event_espresso'),
581
+					'order'      => 15,
582
+					'url'        => $REG_ID
583
+						? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
584
+						: $this->_admin_base_url,
585
+					'persistent' => false,
586
+				],
587
+				'help_tabs'     => [
588
+					'registrations_details_help_tab'                    => [
589
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
590
+						'filename' => 'registrations_details',
591
+					],
592
+					'registrations_details_table_help_tab'              => [
593
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
594
+						'filename' => 'registrations_details_table',
595
+					],
596
+					'registrations_details_form_answers_help_tab'       => [
597
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
598
+						'filename' => 'registrations_details_form_answers',
599
+					],
600
+					'registrations_details_registrant_details_help_tab' => [
601
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
602
+						'filename' => 'registrations_details_registrant_details',
603
+					],
604
+				],
605
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
606
+				// 'help_tour'     => array('Registration_Details_Help_Tour'),
607
+				'metaboxes'     => array_merge(
608
+					$this->_default_espresso_metaboxes,
609
+					['_registration_details_metaboxes']
610
+				),
611
+				'require_nonce' => false,
612
+			],
613
+			'new_registration'  => [
614
+				'nav'           => [
615
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
616
+					'url'        => '#',
617
+					'order'      => 15,
618
+					'persistent' => false,
619
+				],
620
+				'metaboxes'     => $this->_default_espresso_metaboxes,
621
+				'labels'        => [
622
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
623
+				],
624
+				'require_nonce' => false,
625
+			],
626
+			'add_new_attendee'  => [
627
+				'nav'           => [
628
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
629
+					'order'      => 15,
630
+					'persistent' => false,
631
+				],
632
+				'metaboxes'     => array_merge(
633
+					$this->_default_espresso_metaboxes,
634
+					['_publish_post_box', 'attendee_editor_metaboxes']
635
+				),
636
+				'require_nonce' => false,
637
+			],
638
+			'edit_attendee'     => [
639
+				'nav'           => [
640
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
641
+					'order'      => 15,
642
+					'persistent' => false,
643
+					'url'        => $ATT_ID
644
+						? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
645
+						: $this->_admin_base_url,
646
+				],
647
+				'metaboxes'     => ['attendee_editor_metaboxes'],
648
+				'require_nonce' => false,
649
+			],
650
+			'contact_list'      => [
651
+				'nav'           => [
652
+					'label' => esc_html__('Contact List', 'event_espresso'),
653
+					'order' => 20,
654
+				],
655
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
656
+				'help_tabs'     => [
657
+					'registrations_contact_list_help_tab'                       => [
658
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
659
+						'filename' => 'registrations_contact_list',
660
+					],
661
+					'registrations_contact-list_table_column_headings_help_tab' => [
662
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
663
+						'filename' => 'registrations_contact_list_table_column_headings',
664
+					],
665
+					'registrations_contact_list_views_help_tab'                 => [
666
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
667
+						'filename' => 'registrations_contact_list_views',
668
+					],
669
+					'registrations_contact_list_other_help_tab'                 => [
670
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
671
+						'filename' => 'registrations_contact_list_other',
672
+					],
673
+				],
674
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
675
+				// 'help_tour'     => array('Contact_List_Help_Tour'),
676
+				'metaboxes'     => [],
677
+				'require_nonce' => false,
678
+			],
679
+			// override default cpt routes
680
+			'create_new'        => '',
681
+			'edit'              => '',
682
+		];
683
+	}
684
+
685
+
686
+	/**
687
+	 * The below methods aren't used by this class currently
688
+	 */
689
+	protected function _add_screen_options()
690
+	{
691
+	}
692
+
693
+
694
+	protected function _add_feature_pointers()
695
+	{
696
+	}
697
+
698
+
699
+	public function admin_init()
700
+	{
701
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
702
+			'click "Update Registration Questions" to save your changes',
703
+			'event_espresso'
704
+		);
705
+	}
706
+
707
+
708
+	public function admin_notices()
709
+	{
710
+	}
711
+
712
+
713
+	public function admin_footer_scripts()
714
+	{
715
+	}
716
+
717
+
718
+	/**
719
+	 * get list of registration statuses
720
+	 *
721
+	 * @return void
722
+	 * @throws EE_Error
723
+	 */
724
+	private function _get_registration_status_array()
725
+	{
726
+		self::$_reg_status = EEM_Registration::reg_status_array([], true);
727
+	}
728
+
729
+
730
+	/**
731
+	 * @throws InvalidArgumentException
732
+	 * @throws InvalidDataTypeException
733
+	 * @throws InvalidInterfaceException
734
+	 * @since 4.10.2.p
735
+	 */
736
+	protected function _add_screen_options_default()
737
+	{
738
+		$this->_per_page_screen_option();
739
+	}
740
+
741
+
742
+	/**
743
+	 * @throws InvalidArgumentException
744
+	 * @throws InvalidDataTypeException
745
+	 * @throws InvalidInterfaceException
746
+	 * @since 4.10.2.p
747
+	 */
748
+	protected function _add_screen_options_contact_list()
749
+	{
750
+		$page_title              = $this->_admin_page_title;
751
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
752
+		$this->_per_page_screen_option();
753
+		$this->_admin_page_title = $page_title;
754
+	}
755
+
756
+
757
+	public function load_scripts_styles()
758
+	{
759
+		// style
760
+		wp_register_style(
761
+			'espresso_reg',
762
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
763
+			['ee-admin-css'],
764
+			EVENT_ESPRESSO_VERSION
765
+		);
766
+		wp_enqueue_style('espresso_reg');
767
+		// script
768
+		wp_register_script(
769
+			'espresso_reg',
770
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
771
+			['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
772
+			EVENT_ESPRESSO_VERSION,
773
+			true
774
+		);
775
+		wp_enqueue_script('espresso_reg');
776
+	}
777
+
778
+
779
+	/**
780
+	 * @throws EE_Error
781
+	 * @throws InvalidArgumentException
782
+	 * @throws InvalidDataTypeException
783
+	 * @throws InvalidInterfaceException
784
+	 * @throws ReflectionException
785
+	 * @since 4.10.2.p
786
+	 */
787
+	public function load_scripts_styles_edit_attendee()
788
+	{
789
+		// stuff to only show up on our attendee edit details page.
790
+		$attendee_details_translations = [
791
+			'att_publish_text' => sprintf(
792
+			/* translators: The date and time */
793
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
794
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
795
+			),
796
+		];
797
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
798
+		wp_enqueue_script('jquery-validate');
799
+	}
800
+
801
+
802
+	/**
803
+	 * @throws EE_Error
804
+	 * @throws InvalidArgumentException
805
+	 * @throws InvalidDataTypeException
806
+	 * @throws InvalidInterfaceException
807
+	 * @throws ReflectionException
808
+	 * @since 4.10.2.p
809
+	 */
810
+	public function load_scripts_styles_view_registration()
811
+	{
812
+		// styles
813
+		wp_enqueue_style('espresso-ui-theme');
814
+		// scripts
815
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
816
+		$this->_reg_custom_questions_form->wp_enqueue_scripts();
817
+	}
818
+
819
+
820
+	public function load_scripts_styles_contact_list()
821
+	{
822
+		wp_dequeue_style('espresso_reg');
823
+		wp_register_style(
824
+			'espresso_att',
825
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
826
+			['ee-admin-css'],
827
+			EVENT_ESPRESSO_VERSION
828
+		);
829
+		wp_enqueue_style('espresso_att');
830
+	}
831
+
832
+
833
+	public function load_scripts_styles_new_registration()
834
+	{
835
+		wp_register_script(
836
+			'ee-spco-for-admin',
837
+			REG_ASSETS_URL . 'spco_for_admin.js',
838
+			['underscore', 'jquery'],
839
+			EVENT_ESPRESSO_VERSION,
840
+			true
841
+		);
842
+		wp_enqueue_script('ee-spco-for-admin');
843
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
844
+		EE_Form_Section_Proper::wp_enqueue_scripts();
845
+		EED_Ticket_Selector::load_tckt_slctr_assets();
846
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
847
+	}
848
+
849
+
850
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
851
+	{
852
+		add_filter('FHEE_load_EE_messages', '__return_true');
853
+	}
854
+
855
+
856
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
857
+	{
858
+		add_filter('FHEE_load_EE_messages', '__return_true');
859
+	}
860
+
861
+
862
+	/**
863
+	 * @throws EE_Error
864
+	 * @throws InvalidArgumentException
865
+	 * @throws InvalidDataTypeException
866
+	 * @throws InvalidInterfaceException
867
+	 * @throws ReflectionException
868
+	 * @since 4.10.2.p
869
+	 */
870
+	protected function _set_list_table_views_default()
871
+	{
872
+		// for notification related bulk actions we need to make sure only active messengers have an option.
873
+		EED_Messages::set_autoloaders();
874
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
875
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
876
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
877
+		// key= bulk_action_slug, value= message type.
878
+		$match_array = [
879
+			'approve_registrations'    => 'registration',
880
+			'decline_registrations'    => 'declined_registration',
881
+			'pending_registrations'    => 'pending_approval',
882
+			'no_approve_registrations' => 'not_approved_registration',
883
+			'cancel_registrations'     => 'cancelled_registration',
884
+		];
885
+		$can_send    = EE_Registry::instance()->CAP->current_user_can(
886
+			'ee_send_message',
887
+			'batch_send_messages'
888
+		);
889
+		/** setup reg status bulk actions **/
890
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
891
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
892
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
893
+				'Approve and Notify Registrations',
894
+				'event_espresso'
895
+			);
896
+		}
897
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
898
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
899
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
900
+				'Decline and Notify Registrations',
901
+				'event_espresso'
902
+			);
903
+		}
904
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
905
+			'Set Registrations to Pending Payment',
906
+			'event_espresso'
907
+		);
908
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
909
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
910
+				'Set Registrations to Pending Payment and Notify',
911
+				'event_espresso'
912
+			);
913
+		}
914
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
915
+			'Set Registrations to Not Approved',
916
+			'event_espresso'
917
+		);
918
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
919
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
920
+				'Set Registrations to Not Approved and Notify',
921
+				'event_espresso'
922
+			);
923
+		}
924
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
925
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
926
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
927
+				'Cancel Registrations and Notify',
928
+				'event_espresso'
929
+			);
930
+		}
931
+		$def_reg_status_actions = apply_filters(
932
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
933
+			$def_reg_status_actions,
934
+			$active_mts,
935
+			$can_send
936
+		);
937
+
938
+		$this->_views = [
939
+			'all'   => [
940
+				'slug'        => 'all',
941
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
942
+				'count'       => 0,
943
+				'bulk_action' => array_merge(
944
+					$def_reg_status_actions,
945
+					[
946
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
947
+					]
948
+				),
949
+			],
950
+			'month' => [
951
+				'slug'        => 'month',
952
+				'label'       => esc_html__('This Month', 'event_espresso'),
953
+				'count'       => 0,
954
+				'bulk_action' => array_merge(
955
+					$def_reg_status_actions,
956
+					[
957
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
958
+					]
959
+				),
960
+			],
961
+			'today' => [
962
+				'slug'        => 'today',
963
+				'label'       => sprintf(
964
+					esc_html__('Today - %s', 'event_espresso'),
965
+					date('M d, Y', current_time('timestamp'))
966
+				),
967
+				'count'       => 0,
968
+				'bulk_action' => array_merge(
969
+					$def_reg_status_actions,
970
+					[
971
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
972
+					]
973
+				),
974
+			],
975
+		];
976
+		if (
977
+			EE_Registry::instance()->CAP->current_user_can(
978
+				'ee_delete_registrations',
979
+				'espresso_registrations_delete_registration'
980
+			)
981
+		) {
982
+			$this->_views['incomplete'] = [
983
+				'slug'        => 'incomplete',
984
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
985
+				'count'       => 0,
986
+				'bulk_action' => [
987
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
988
+				],
989
+			];
990
+			$this->_views['trash']      = [
991
+				'slug'        => 'trash',
992
+				'label'       => esc_html__('Trash', 'event_espresso'),
993
+				'count'       => 0,
994
+				'bulk_action' => [
995
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
996
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
997
+				],
998
+			];
999
+		}
1000
+	}
1001
+
1002
+
1003
+	protected function _set_list_table_views_contact_list()
1004
+	{
1005
+		$this->_views = [
1006
+			'in_use' => [
1007
+				'slug'        => 'in_use',
1008
+				'label'       => esc_html__('In Use', 'event_espresso'),
1009
+				'count'       => 0,
1010
+				'bulk_action' => [
1011
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1012
+				],
1013
+			],
1014
+		];
1015
+		if (
1016
+			EE_Registry::instance()->CAP->current_user_can(
1017
+				'ee_delete_contacts',
1018
+				'espresso_registrations_trash_attendees'
1019
+			)
1020
+		) {
1021
+			$this->_views['trash'] = [
1022
+				'slug'        => 'trash',
1023
+				'label'       => esc_html__('Trash', 'event_espresso'),
1024
+				'count'       => 0,
1025
+				'bulk_action' => [
1026
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1027
+				],
1028
+			];
1029
+		}
1030
+	}
1031
+
1032
+
1033
+	/**
1034
+	 * @return array
1035
+	 * @throws EE_Error
1036
+	 */
1037
+	protected function _registration_legend_items()
1038
+	{
1039
+		$fc_items = [
1040
+			'star-icon'        => [
1041
+				'class' => 'dashicons dashicons-star-filled gold-icon',
1042
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1043
+			],
1044
+			'view_details'     => [
1045
+				'class' => 'dashicons dashicons-clipboard',
1046
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1047
+			],
1048
+			'edit_attendee'    => [
1049
+				'class' => 'dashicons dashicons-admin-users',
1050
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1051
+			],
1052
+			'view_transaction' => [
1053
+				'class' => 'dashicons dashicons-cart',
1054
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1055
+			],
1056
+			'view_invoice'     => [
1057
+				'class' => 'dashicons dashicons-media-spreadsheet',
1058
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1059
+			],
1060
+		];
1061
+		if (
1062
+			EE_Registry::instance()->CAP->current_user_can(
1063
+				'ee_send_message',
1064
+				'espresso_registrations_resend_registration'
1065
+			)
1066
+		) {
1067
+			$fc_items['resend_registration'] = [
1068
+				'class' => 'dashicons dashicons-email-alt',
1069
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1070
+			];
1071
+		} else {
1072
+			$fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1073
+		}
1074
+		if (
1075
+			EE_Registry::instance()->CAP->current_user_can(
1076
+				'ee_read_global_messages',
1077
+				'view_filtered_messages'
1078
+			)
1079
+		) {
1080
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1081
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1082
+				$fc_items['view_related_messages'] = [
1083
+					'class' => $related_for_icon['css_class'],
1084
+					'desc'  => $related_for_icon['label'],
1085
+				];
1086
+			}
1087
+		}
1088
+		$sc_items = [
1089
+			'approved_status'   => [
1090
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1091
+				'desc'  => EEH_Template::pretty_status(
1092
+					EEM_Registration::status_id_approved,
1093
+					false,
1094
+					'sentence'
1095
+				),
1096
+			],
1097
+			'pending_status'    => [
1098
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1099
+				'desc'  => EEH_Template::pretty_status(
1100
+					EEM_Registration::status_id_pending_payment,
1101
+					false,
1102
+					'sentence'
1103
+				),
1104
+			],
1105
+			'wait_list'         => [
1106
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1107
+				'desc'  => EEH_Template::pretty_status(
1108
+					EEM_Registration::status_id_wait_list,
1109
+					false,
1110
+					'sentence'
1111
+				),
1112
+			],
1113
+			'incomplete_status' => [
1114
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1115
+				'desc'  => EEH_Template::pretty_status(
1116
+					EEM_Registration::status_id_incomplete,
1117
+					false,
1118
+					'sentence'
1119
+				),
1120
+			],
1121
+			'not_approved'      => [
1122
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1123
+				'desc'  => EEH_Template::pretty_status(
1124
+					EEM_Registration::status_id_not_approved,
1125
+					false,
1126
+					'sentence'
1127
+				),
1128
+			],
1129
+			'declined_status'   => [
1130
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1131
+				'desc'  => EEH_Template::pretty_status(
1132
+					EEM_Registration::status_id_declined,
1133
+					false,
1134
+					'sentence'
1135
+				),
1136
+			],
1137
+			'cancelled_status'  => [
1138
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1139
+				'desc'  => EEH_Template::pretty_status(
1140
+					EEM_Registration::status_id_cancelled,
1141
+					false,
1142
+					'sentence'
1143
+				),
1144
+			],
1145
+		];
1146
+		return array_merge($fc_items, $sc_items);
1147
+	}
1148
+
1149
+
1150
+
1151
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1152
+
1153
+
1154
+	/**
1155
+	 * @throws DomainException
1156
+	 * @throws EE_Error
1157
+	 * @throws InvalidArgumentException
1158
+	 * @throws InvalidDataTypeException
1159
+	 * @throws InvalidInterfaceException
1160
+	 */
1161
+	protected function _registrations_overview_list_table()
1162
+	{
1163
+		$this->appendAddNewRegistrationButtonToPageTitle();
1164
+		$header_text                  = '';
1165
+		$admin_page_header_decorators = [
1166
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1167
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1168
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1169
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1170
+		];
1171
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1172
+			$filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1173
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1174
+		}
1175
+		$this->_template_args['admin_page_header'] = $header_text;
1176
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1177
+		$this->display_admin_list_table_page_with_no_sidebar();
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * @throws EE_Error
1183
+	 * @throws InvalidArgumentException
1184
+	 * @throws InvalidDataTypeException
1185
+	 * @throws InvalidInterfaceException
1186
+	 */
1187
+	private function appendAddNewRegistrationButtonToPageTitle()
1188
+	{
1189
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1190
+		if (
1191
+			$EVT_ID
1192
+			&& EE_Registry::instance()->CAP->current_user_can(
1193
+				'ee_edit_registrations',
1194
+				'espresso_registrations_new_registration',
1195
+				$EVT_ID
1196
+			)
1197
+		) {
1198
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1199
+				'new_registration',
1200
+				'add-registrant',
1201
+				['event_id' => $EVT_ID],
1202
+				'add-new-h2'
1203
+			);
1204
+		}
1205
+	}
1206
+
1207
+
1208
+	/**
1209
+	 * This sets the _registration property for the registration details screen
1210
+	 *
1211
+	 * @return void
1212
+	 * @throws EE_Error
1213
+	 * @throws InvalidArgumentException
1214
+	 * @throws InvalidDataTypeException
1215
+	 * @throws InvalidInterfaceException
1216
+	 */
1217
+	private function _set_registration_object()
1218
+	{
1219
+		// get out if we've already set the object
1220
+		if ($this->_registration instanceof EE_Registration) {
1221
+			return;
1222
+		}
1223
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1224
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1225
+			return;
1226
+		}
1227
+		$error_msg = sprintf(
1228
+			esc_html__(
1229
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1230
+				'event_espresso'
1231
+			),
1232
+			$REG_ID
1233
+		);
1234
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1235
+		$this->_registration = null;
1236
+	}
1237
+
1238
+
1239
+	/**
1240
+	 * Used to retrieve registrations for the list table.
1241
+	 *
1242
+	 * @param int  $per_page
1243
+	 * @param bool $count
1244
+	 * @param bool $this_month
1245
+	 * @param bool $today
1246
+	 * @return EE_Registration[]|int
1247
+	 * @throws EE_Error
1248
+	 * @throws InvalidArgumentException
1249
+	 * @throws InvalidDataTypeException
1250
+	 * @throws InvalidInterfaceException
1251
+	 */
1252
+	public function get_registrations(
1253
+		$per_page = 10,
1254
+		$count = false,
1255
+		$this_month = false,
1256
+		$today = false
1257
+	) {
1258
+		if ($this_month) {
1259
+			$this->request->setRequestParam('status', 'month');
1260
+		}
1261
+		if ($today) {
1262
+			$this->request->setRequestParam('status', 'today');
1263
+		}
1264
+		$query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1265
+		/**
1266
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1267
+		 *
1268
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1269
+		 * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1270
+		 *                      or if you have the development copy of EE you can view this at the path:
1271
+		 *                      /docs/G--Model-System/model-query-params.md
1272
+		 */
1273
+		$query_params['group_by'] = '';
1274
+
1275
+		return $count
1276
+			? $this->getRegistrationModel()->count($query_params)
1277
+			/** @type EE_Registration[] */
1278
+			: $this->getRegistrationModel()->get_all($query_params);
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1284
+	 * Note: this listens to values on the request for some of the query parameters.
1285
+	 *
1286
+	 * @param array $request
1287
+	 * @param int   $per_page
1288
+	 * @param bool  $count
1289
+	 * @return array
1290
+	 * @throws EE_Error
1291
+	 * @throws InvalidArgumentException
1292
+	 * @throws InvalidDataTypeException
1293
+	 * @throws InvalidInterfaceException
1294
+	 */
1295
+	protected function _get_registration_query_parameters(
1296
+		$request = [],
1297
+		$per_page = 10,
1298
+		$count = false
1299
+	) {
1300
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1301
+		$list_table_query_builder = $this->loader->getNew(
1302
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1303
+			[null, null, $request]
1304
+		);
1305
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1306
+	}
1307
+
1308
+
1309
+	public function get_registration_status_array()
1310
+	{
1311
+		return self::$_reg_status;
1312
+	}
1313
+
1314
+
1315
+
1316
+
1317
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1318
+	/**
1319
+	 * generates HTML for the View Registration Details Admin page
1320
+	 *
1321
+	 * @return void
1322
+	 * @throws DomainException
1323
+	 * @throws EE_Error
1324
+	 * @throws InvalidArgumentException
1325
+	 * @throws InvalidDataTypeException
1326
+	 * @throws InvalidInterfaceException
1327
+	 * @throws EntityNotFoundException
1328
+	 * @throws ReflectionException
1329
+	 */
1330
+	protected function _registration_details()
1331
+	{
1332
+		$this->_template_args = [];
1333
+		$this->_set_registration_object();
1334
+		if (is_object($this->_registration)) {
1335
+			$transaction                                   = $this->_registration->transaction()
1336
+				? $this->_registration->transaction()
1337
+				: EE_Transaction::new_instance();
1338
+			$this->_session                                = $transaction->session_data();
1339
+			$event_id                                      = $this->_registration->event_ID();
1340
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1341
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1342
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1343
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1344
+			$this->_template_args['grand_total']           = $transaction->total();
1345
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1346
+			// link back to overview
1347
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1348
+			$this->_template_args['registration']                = $this->_registration;
1349
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1350
+				[
1351
+					'action'   => 'default',
1352
+					'event_id' => $event_id,
1353
+				],
1354
+				REG_ADMIN_URL
1355
+			);
1356
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1357
+				[
1358
+					'action' => 'default',
1359
+					'EVT_ID' => $event_id,
1360
+					'page'   => 'espresso_transactions',
1361
+				],
1362
+				admin_url('admin.php')
1363
+			);
1364
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1365
+				[
1366
+					'page'   => 'espresso_events',
1367
+					'action' => 'edit',
1368
+					'post'   => $event_id,
1369
+				],
1370
+				admin_url('admin.php')
1371
+			);
1372
+			// next and previous links
1373
+			$next_reg                                      = $this->_registration->next(
1374
+				null,
1375
+				[],
1376
+				'REG_ID'
1377
+			);
1378
+			$this->_template_args['next_registration']     = $next_reg
1379
+				? $this->_next_link(
1380
+					EE_Admin_Page::add_query_args_and_nonce(
1381
+						[
1382
+							'action'  => 'view_registration',
1383
+							'_REG_ID' => $next_reg['REG_ID'],
1384
+						],
1385
+						REG_ADMIN_URL
1386
+					),
1387
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1388
+				)
1389
+				: '';
1390
+			$previous_reg                                  = $this->_registration->previous(
1391
+				null,
1392
+				[],
1393
+				'REG_ID'
1394
+			);
1395
+			$this->_template_args['previous_registration'] = $previous_reg
1396
+				? $this->_previous_link(
1397
+					EE_Admin_Page::add_query_args_and_nonce(
1398
+						[
1399
+							'action'  => 'view_registration',
1400
+							'_REG_ID' => $previous_reg['REG_ID'],
1401
+						],
1402
+						REG_ADMIN_URL
1403
+					),
1404
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1405
+				)
1406
+				: '';
1407
+			// grab header
1408
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1409
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1410
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1411
+				$template_path,
1412
+				$this->_template_args,
1413
+				true
1414
+			);
1415
+		} else {
1416
+			$this->_template_args['admin_page_header'] = '';
1417
+			$this->_display_espresso_notices();
1418
+		}
1419
+		// the details template wrapper
1420
+		$this->display_admin_page_with_sidebar();
1421
+	}
1422
+
1423
+
1424
+	/**
1425
+	 * @throws EE_Error
1426
+	 * @throws InvalidArgumentException
1427
+	 * @throws InvalidDataTypeException
1428
+	 * @throws InvalidInterfaceException
1429
+	 * @throws ReflectionException
1430
+	 * @since 4.10.2.p
1431
+	 */
1432
+	protected function _registration_details_metaboxes()
1433
+	{
1434
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1435
+		$this->_set_registration_object();
1436
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1437
+		$this->addMetaBox(
1438
+			'edit-reg-status-mbox',
1439
+			esc_html__('Registration Status', 'event_espresso'),
1440
+			[$this, 'set_reg_status_buttons_metabox'],
1441
+			$this->_wp_page_slug
1442
+		);
1443
+		$this->addMetaBox(
1444
+			'edit-reg-details-mbox',
1445
+			'<span>' . esc_html__('Registration Details', 'event_espresso')
1446
+			. '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1447
+			[$this, '_reg_details_meta_box'],
1448
+			$this->_wp_page_slug
1449
+		);
1450
+		if (
1451
+			$attendee instanceof EE_Attendee
1452
+			&& EE_Registry::instance()->CAP->current_user_can(
1453
+				'ee_read_registration',
1454
+				'edit-reg-questions-mbox',
1455
+				$this->_registration->ID()
1456
+			)
1457
+		) {
1458
+			$this->addMetaBox(
1459
+				$this->_wp_page_slug,
1460
+				'edit-reg-questions-mbox',
1461
+				esc_html__('Registration Form Answers', 'event_espresso'),
1462
+				[$this, '_reg_questions_meta_box'],
1463
+				$this->_wp_page_slug
1464
+			);
1465
+		}
1466
+		$this->addMetaBox(
1467
+			'edit-reg-registrant-mbox',
1468
+			esc_html__('Contact Details', 'event_espresso'),
1469
+			[$this, '_reg_registrant_side_meta_box'],
1470
+			$this->_wp_page_slug,
1471
+			'side'
1472
+		);
1473
+		if ($this->_registration->group_size() > 1) {
1474
+			$this->addMetaBox(
1475
+				'edit-reg-attendees-mbox',
1476
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1477
+				[$this, '_reg_attendees_meta_box'],
1478
+				$this->_wp_page_slug
1479
+			);
1480
+		}
1481
+	}
1482
+
1483
+
1484
+	/**
1485
+	 * set_reg_status_buttons_metabox
1486
+	 *
1487
+	 * @return void
1488
+	 * @throws EE_Error
1489
+	 * @throws EntityNotFoundException
1490
+	 * @throws InvalidArgumentException
1491
+	 * @throws InvalidDataTypeException
1492
+	 * @throws InvalidInterfaceException
1493
+	 * @throws ReflectionException
1494
+	 */
1495
+	public function set_reg_status_buttons_metabox()
1496
+	{
1497
+		$this->_set_registration_object();
1498
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1499
+		$output                 = $change_reg_status_form->form_open(
1500
+			self::add_query_args_and_nonce(
1501
+				[
1502
+					'action' => 'change_reg_status',
1503
+				],
1504
+				REG_ADMIN_URL
1505
+			)
1506
+		);
1507
+		$output                 .= $change_reg_status_form->get_html();
1508
+		$output                 .= $change_reg_status_form->form_close();
1509
+		echo $output; // already escaped
1510
+	}
1511
+
1512
+
1513
+	/**
1514
+	 * @return EE_Form_Section_Proper
1515
+	 * @throws EE_Error
1516
+	 * @throws InvalidArgumentException
1517
+	 * @throws InvalidDataTypeException
1518
+	 * @throws InvalidInterfaceException
1519
+	 * @throws EntityNotFoundException
1520
+	 * @throws ReflectionException
1521
+	 */
1522
+	protected function _generate_reg_status_change_form()
1523
+	{
1524
+		$reg_status_change_form_array = [
1525
+			'name'            => 'reg_status_change_form',
1526
+			'html_id'         => 'reg-status-change-form',
1527
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1528
+			'subsections'     => [
1529
+				'return'         => new EE_Hidden_Input(
1530
+					[
1531
+						'name'    => 'return',
1532
+						'default' => 'view_registration',
1533
+					]
1534
+				),
1535
+				'REG_ID'         => new EE_Hidden_Input(
1536
+					[
1537
+						'name'    => 'REG_ID',
1538
+						'default' => $this->_registration->ID(),
1539
+					]
1540
+				),
1541
+				'current_status' => new EE_Form_Section_HTML(
1542
+					EEH_HTML::table(
1543
+						EEH_HTML::tr(
1544
+							EEH_HTML::th(
1545
+								EEH_HTML::label(
1546
+									EEH_HTML::strong(
1547
+										esc_html__('Current Registration Status', 'event_espresso')
1548
+									)
1549
+								)
1550
+							)
1551
+							. EEH_HTML::td(
1552
+								EEH_HTML::strong(
1553
+									$this->_registration->pretty_status(),
1554
+									'',
1555
+									'status-' . $this->_registration->status_ID(),
1556
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1557
+								)
1558
+							)
1559
+						)
1560
+					)
1561
+				),
1562
+			],
1563
+		];
1564
+		if (
1565
+			EE_Registry::instance()->CAP->current_user_can(
1566
+				'ee_edit_registration',
1567
+				'toggle_registration_status',
1568
+				$this->_registration->ID()
1569
+			)
1570
+		) {
1571
+			$reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1572
+				$this->_get_reg_statuses(),
1573
+				[
1574
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1575
+					'default'         => $this->_registration->status_ID(),
1576
+				]
1577
+			);
1578
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1579
+				[
1580
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1581
+					'default'         => false,
1582
+					'html_help_text'  => esc_html__(
1583
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1584
+						'event_espresso'
1585
+					),
1586
+				]
1587
+			);
1588
+			$reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1589
+				[
1590
+					'html_class'      => 'button--primary',
1591
+					'html_label_text' => '&nbsp;',
1592
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1593
+				]
1594
+			);
1595
+		}
1596
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1597
+	}
1598
+
1599
+
1600
+	/**
1601
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1602
+	 *
1603
+	 * @return array
1604
+	 * @throws EE_Error
1605
+	 * @throws InvalidArgumentException
1606
+	 * @throws InvalidDataTypeException
1607
+	 * @throws InvalidInterfaceException
1608
+	 * @throws EntityNotFoundException
1609
+	 */
1610
+	protected function _get_reg_statuses()
1611
+	{
1612
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1613
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1614
+		// get current reg status
1615
+		$current_status = $this->_registration->status_ID();
1616
+		// is registration for free event? This will determine whether to display the pending payment option
1617
+		if (
1618
+			$current_status !== EEM_Registration::status_id_pending_payment
1619
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1620
+		) {
1621
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1622
+		}
1623
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1624
+	}
1625
+
1626
+
1627
+	/**
1628
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1629
+	 *
1630
+	 * @param bool $status REG status given for changing registrations to.
1631
+	 * @param bool $notify Whether to send messages notifications or not.
1632
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1633
+	 * @throws DomainException
1634
+	 * @throws EE_Error
1635
+	 * @throws EntityNotFoundException
1636
+	 * @throws InvalidArgumentException
1637
+	 * @throws InvalidDataTypeException
1638
+	 * @throws InvalidInterfaceException
1639
+	 * @throws ReflectionException
1640
+	 * @throws RuntimeException
1641
+	 */
1642
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1643
+	{
1644
+		$REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1645
+			? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1646
+			: $this->request->getRequestParam('_REG_ID', [], 'int', true);
1647
+
1648
+		// sanitize $REG_IDs
1649
+		$REG_IDs = array_map('absint', $REG_IDs);
1650
+		// and remove empty entries
1651
+		$REG_IDs = array_filter($REG_IDs);
1652
+
1653
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1654
+
1655
+		/**
1656
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1657
+		 * Currently this value is used downstream by the _process_resend_registration method.
1658
+		 *
1659
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1660
+		 * @param bool                     $status           The status registrations were changed to.
1661
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1662
+		 * @param Registrations_Admin_Page $admin_page_object
1663
+		 */
1664
+		$REG_ID = apply_filters(
1665
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1666
+			$result['REG_ID'],
1667
+			$status,
1668
+			$result['success'],
1669
+			$this
1670
+		);
1671
+		$this->request->setRequestParam('_REG_ID', $REG_ID);
1672
+
1673
+		// notify?
1674
+		if (
1675
+			$notify
1676
+			&& $result['success']
1677
+			&& ! empty($REG_ID)
1678
+			&& EE_Registry::instance()->CAP->current_user_can(
1679
+				'ee_send_message',
1680
+				'espresso_registrations_resend_registration'
1681
+			)
1682
+		) {
1683
+			$this->_process_resend_registration();
1684
+		}
1685
+		return $result;
1686
+	}
1687
+
1688
+
1689
+	/**
1690
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1691
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1692
+	 *
1693
+	 * @param array  $REG_IDs
1694
+	 * @param string $status
1695
+	 * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1696
+	 *                       slug sent with setting the registration status.
1697
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
+	 * @throws EE_Error
1699
+	 * @throws InvalidArgumentException
1700
+	 * @throws InvalidDataTypeException
1701
+	 * @throws InvalidInterfaceException
1702
+	 * @throws ReflectionException
1703
+	 * @throws RuntimeException
1704
+	 * @throws EntityNotFoundException
1705
+	 * @throws DomainException
1706
+	 */
1707
+	protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1708
+	{
1709
+		$success = false;
1710
+		// typecast $REG_IDs
1711
+		$REG_IDs = (array) $REG_IDs;
1712
+		if (! empty($REG_IDs)) {
1713
+			$success = true;
1714
+			// set default status if none is passed
1715
+			$status         = $status ?: EEM_Registration::status_id_pending_payment;
1716
+			$status_context = $notify
1717
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1718
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1719
+			// loop through REG_ID's and change status
1720
+			foreach ($REG_IDs as $REG_ID) {
1721
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1722
+				if ($registration instanceof EE_Registration) {
1723
+					$registration->set_status(
1724
+						$status,
1725
+						false,
1726
+						new Context(
1727
+							$status_context,
1728
+							esc_html__(
1729
+								'Manually triggered status change on a Registration Admin Page route.',
1730
+								'event_espresso'
1731
+							)
1732
+						)
1733
+					);
1734
+					$result = $registration->save();
1735
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1736
+					$success = $result !== false ? $success : false;
1737
+				}
1738
+			}
1739
+		}
1740
+
1741
+		// return $success and processed registrations
1742
+		return ['REG_ID' => $REG_IDs, 'success' => $success];
1743
+	}
1744
+
1745
+
1746
+	/**
1747
+	 * Common logic for setting up success message and redirecting to appropriate route
1748
+	 *
1749
+	 * @param string $STS_ID status id for the registration changed to
1750
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1751
+	 * @return void
1752
+	 * @throws DomainException
1753
+	 * @throws EE_Error
1754
+	 * @throws EntityNotFoundException
1755
+	 * @throws InvalidArgumentException
1756
+	 * @throws InvalidDataTypeException
1757
+	 * @throws InvalidInterfaceException
1758
+	 * @throws ReflectionException
1759
+	 * @throws RuntimeException
1760
+	 */
1761
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1762
+	{
1763
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1764
+			: ['success' => false];
1765
+		$success = isset($result['success']) && $result['success'];
1766
+		// setup success message
1767
+		if ($success) {
1768
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1769
+				$msg = sprintf(
1770
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1771
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1772
+				);
1773
+			} else {
1774
+				$msg = sprintf(
1775
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1776
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1777
+				);
1778
+			}
1779
+			EE_Error::add_success($msg);
1780
+		} else {
1781
+			EE_Error::add_error(
1782
+				esc_html__(
1783
+					'Something went wrong, and the status was not changed',
1784
+					'event_espresso'
1785
+				),
1786
+				__FILE__,
1787
+				__LINE__,
1788
+				__FUNCTION__
1789
+			);
1790
+		}
1791
+		$return = $this->request->getRequestParam('return');
1792
+		$route  = $return === 'view_registration'
1793
+			? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1794
+			: ['action' => 'default'];
1795
+		$route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1796
+		$this->_redirect_after_action($success, '', '', $route, true);
1797
+	}
1798
+
1799
+
1800
+	/**
1801
+	 * incoming reg status change from reg details page.
1802
+	 *
1803
+	 * @return void
1804
+	 * @throws EE_Error
1805
+	 * @throws EntityNotFoundException
1806
+	 * @throws InvalidArgumentException
1807
+	 * @throws InvalidDataTypeException
1808
+	 * @throws InvalidInterfaceException
1809
+	 * @throws ReflectionException
1810
+	 * @throws RuntimeException
1811
+	 * @throws DomainException
1812
+	 */
1813
+	protected function _change_reg_status()
1814
+	{
1815
+		$this->request->setRequestParam('return', 'view_registration');
1816
+		// set notify based on whether the send notifications toggle is set or not
1817
+		$notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1818
+		$reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1819
+		$this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1820
+		switch ($reg_status) {
1821
+			case EEM_Registration::status_id_approved:
1822
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1823
+				$this->approve_registration($notify);
1824
+				break;
1825
+			case EEM_Registration::status_id_pending_payment:
1826
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1827
+				$this->pending_registration($notify);
1828
+				break;
1829
+			case EEM_Registration::status_id_not_approved:
1830
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1831
+				$this->not_approve_registration($notify);
1832
+				break;
1833
+			case EEM_Registration::status_id_declined:
1834
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1835
+				$this->decline_registration($notify);
1836
+				break;
1837
+			case EEM_Registration::status_id_cancelled:
1838
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1839
+				$this->cancel_registration($notify);
1840
+				break;
1841
+			case EEM_Registration::status_id_wait_list:
1842
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1843
+				$this->wait_list_registration($notify);
1844
+				break;
1845
+			case EEM_Registration::status_id_incomplete:
1846
+			default:
1847
+				$this->request->unSetRequestParam('return');
1848
+				$this->_reg_status_change_return('');
1849
+				break;
1850
+		}
1851
+	}
1852
+
1853
+
1854
+	/**
1855
+	 * Callback for bulk action routes.
1856
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1857
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1858
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1859
+	 * when an action is happening on just a single registration).
1860
+	 *
1861
+	 * @param      $action
1862
+	 * @param bool $notify
1863
+	 */
1864
+	protected function bulk_action_on_registrations($action, $notify = false)
1865
+	{
1866
+		do_action(
1867
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1868
+			$this,
1869
+			$action,
1870
+			$notify
1871
+		);
1872
+		$method = $action . '_registration';
1873
+		if (method_exists($this, $method)) {
1874
+			$this->$method($notify);
1875
+		}
1876
+	}
1877
+
1878
+
1879
+	/**
1880
+	 * approve_registration
1881
+	 *
1882
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1883
+	 * @return void
1884
+	 * @throws EE_Error
1885
+	 * @throws EntityNotFoundException
1886
+	 * @throws InvalidArgumentException
1887
+	 * @throws InvalidDataTypeException
1888
+	 * @throws InvalidInterfaceException
1889
+	 * @throws ReflectionException
1890
+	 * @throws RuntimeException
1891
+	 * @throws DomainException
1892
+	 */
1893
+	protected function approve_registration($notify = false)
1894
+	{
1895
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1896
+	}
1897
+
1898
+
1899
+	/**
1900
+	 * decline_registration
1901
+	 *
1902
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1903
+	 * @return void
1904
+	 * @throws EE_Error
1905
+	 * @throws EntityNotFoundException
1906
+	 * @throws InvalidArgumentException
1907
+	 * @throws InvalidDataTypeException
1908
+	 * @throws InvalidInterfaceException
1909
+	 * @throws ReflectionException
1910
+	 * @throws RuntimeException
1911
+	 * @throws DomainException
1912
+	 */
1913
+	protected function decline_registration($notify = false)
1914
+	{
1915
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1916
+	}
1917
+
1918
+
1919
+	/**
1920
+	 * cancel_registration
1921
+	 *
1922
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1923
+	 * @return void
1924
+	 * @throws EE_Error
1925
+	 * @throws EntityNotFoundException
1926
+	 * @throws InvalidArgumentException
1927
+	 * @throws InvalidDataTypeException
1928
+	 * @throws InvalidInterfaceException
1929
+	 * @throws ReflectionException
1930
+	 * @throws RuntimeException
1931
+	 * @throws DomainException
1932
+	 */
1933
+	protected function cancel_registration($notify = false)
1934
+	{
1935
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1936
+	}
1937
+
1938
+
1939
+	/**
1940
+	 * not_approve_registration
1941
+	 *
1942
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1943
+	 * @return void
1944
+	 * @throws EE_Error
1945
+	 * @throws EntityNotFoundException
1946
+	 * @throws InvalidArgumentException
1947
+	 * @throws InvalidDataTypeException
1948
+	 * @throws InvalidInterfaceException
1949
+	 * @throws ReflectionException
1950
+	 * @throws RuntimeException
1951
+	 * @throws DomainException
1952
+	 */
1953
+	protected function not_approve_registration($notify = false)
1954
+	{
1955
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1956
+	}
1957
+
1958
+
1959
+	/**
1960
+	 * decline_registration
1961
+	 *
1962
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1963
+	 * @return void
1964
+	 * @throws EE_Error
1965
+	 * @throws EntityNotFoundException
1966
+	 * @throws InvalidArgumentException
1967
+	 * @throws InvalidDataTypeException
1968
+	 * @throws InvalidInterfaceException
1969
+	 * @throws ReflectionException
1970
+	 * @throws RuntimeException
1971
+	 * @throws DomainException
1972
+	 */
1973
+	protected function pending_registration($notify = false)
1974
+	{
1975
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1976
+	}
1977
+
1978
+
1979
+	/**
1980
+	 * waitlist_registration
1981
+	 *
1982
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1983
+	 * @return void
1984
+	 * @throws EE_Error
1985
+	 * @throws EntityNotFoundException
1986
+	 * @throws InvalidArgumentException
1987
+	 * @throws InvalidDataTypeException
1988
+	 * @throws InvalidInterfaceException
1989
+	 * @throws ReflectionException
1990
+	 * @throws RuntimeException
1991
+	 * @throws DomainException
1992
+	 */
1993
+	protected function wait_list_registration($notify = false)
1994
+	{
1995
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1996
+	}
1997
+
1998
+
1999
+	/**
2000
+	 * generates HTML for the Registration main meta box
2001
+	 *
2002
+	 * @return void
2003
+	 * @throws DomainException
2004
+	 * @throws EE_Error
2005
+	 * @throws InvalidArgumentException
2006
+	 * @throws InvalidDataTypeException
2007
+	 * @throws InvalidInterfaceException
2008
+	 * @throws ReflectionException
2009
+	 * @throws EntityNotFoundException
2010
+	 */
2011
+	public function _reg_details_meta_box()
2012
+	{
2013
+		EEH_Autoloader::register_line_item_display_autoloaders();
2014
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2015
+		EE_Registry::instance()->load_helper('Line_Item');
2016
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2017
+			: EE_Transaction::new_instance();
2018
+		$this->_session = $transaction->session_data();
2019
+		$filters        = new EE_Line_Item_Filter_Collection();
2020
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2021
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2022
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2023
+			$filters,
2024
+			$transaction->total_line_item()
2025
+		);
2026
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2027
+		$line_item_display                       = new EE_Line_Item_Display(
2028
+			'reg_admin_table',
2029
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2030
+		);
2031
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2032
+			$filtered_line_item_tree,
2033
+			['EE_Registration' => $this->_registration]
2034
+		);
2035
+		$attendee                                = $this->_registration->attendee();
2036
+		if (
2037
+			EE_Registry::instance()->CAP->current_user_can(
2038
+				'ee_read_transaction',
2039
+				'espresso_transactions_view_transaction'
2040
+			)
2041
+		) {
2042
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2043
+				EE_Admin_Page::add_query_args_and_nonce(
2044
+					[
2045
+						'action' => 'view_transaction',
2046
+						'TXN_ID' => $transaction->ID(),
2047
+					],
2048
+					TXN_ADMIN_URL
2049
+				),
2050
+				esc_html__(' View Transaction', 'event_espresso'),
2051
+				'button button--secondary right',
2052
+				'dashicons dashicons-cart'
2053
+			);
2054
+		} else {
2055
+			$this->_template_args['view_transaction_button'] = '';
2056
+		}
2057
+		if (
2058
+			$attendee instanceof EE_Attendee
2059
+			&& EE_Registry::instance()->CAP->current_user_can(
2060
+				'ee_send_message',
2061
+				'espresso_registrations_resend_registration'
2062
+			)
2063
+		) {
2064
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2065
+				EE_Admin_Page::add_query_args_and_nonce(
2066
+					[
2067
+						'action'      => 'resend_registration',
2068
+						'_REG_ID'     => $this->_registration->ID(),
2069
+						'redirect_to' => 'view_registration',
2070
+					],
2071
+					REG_ADMIN_URL
2072
+				),
2073
+				esc_html__(' Resend Registration', 'event_espresso'),
2074
+				'button button--secondary right',
2075
+				'dashicons dashicons-email-alt'
2076
+			);
2077
+		} else {
2078
+			$this->_template_args['resend_registration_button'] = '';
2079
+		}
2080
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2081
+		$payment                               = $transaction->get_first_related('Payment');
2082
+		$payment                               = ! $payment instanceof EE_Payment
2083
+			? EE_Payment::new_instance()
2084
+			: $payment;
2085
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2086
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2087
+			? EE_Payment_Method::new_instance()
2088
+			: $payment_method;
2089
+		$reg_details                           = [
2090
+			'payment_method'       => $payment_method->name(),
2091
+			'response_msg'         => $payment->gateway_response(),
2092
+			'registration_id'      => $this->_registration->get('REG_code'),
2093
+			'registration_session' => $this->_registration->session_ID(),
2094
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2095
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2096
+		];
2097
+		if (isset($reg_details['registration_id'])) {
2098
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2099
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2100
+				'Registration ID',
2101
+				'event_espresso'
2102
+			);
2103
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2104
+		}
2105
+		if (isset($reg_details['payment_method'])) {
2106
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2107
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2108
+				'Most Recent Payment Method',
2109
+				'event_espresso'
2110
+			);
2111
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2112
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2113
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2114
+				'Payment method response',
2115
+				'event_espresso'
2116
+			);
2117
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2118
+		}
2119
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2120
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2121
+			'Registration Session',
2122
+			'event_espresso'
2123
+		);
2124
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2125
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2126
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2127
+			'Registration placed from IP',
2128
+			'event_espresso'
2129
+		);
2130
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2131
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2132
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2133
+			'Registrant User Agent',
2134
+			'event_espresso'
2135
+		);
2136
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2137
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2138
+			[
2139
+				'action'   => 'default',
2140
+				'event_id' => $this->_registration->event_ID(),
2141
+			],
2142
+			REG_ADMIN_URL
2143
+		);
2144
+
2145
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2146
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2147
+
2148
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2149
+		EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2150
+	}
2151
+
2152
+
2153
+	/**
2154
+	 * generates HTML for the Registration Questions meta box.
2155
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2156
+	 * otherwise uses new forms system
2157
+	 *
2158
+	 * @return void
2159
+	 * @throws DomainException
2160
+	 * @throws EE_Error
2161
+	 * @throws InvalidArgumentException
2162
+	 * @throws InvalidDataTypeException
2163
+	 * @throws InvalidInterfaceException
2164
+	 * @throws ReflectionException
2165
+	 */
2166
+	public function _reg_questions_meta_box()
2167
+	{
2168
+		// allow someone to override this method entirely
2169
+		if (
2170
+			apply_filters(
2171
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2172
+				true,
2173
+				$this,
2174
+				$this->_registration
2175
+			)
2176
+		) {
2177
+			$form = $this->_get_reg_custom_questions_form(
2178
+				$this->_registration->ID()
2179
+			);
2180
+
2181
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2182
+				? $form->get_html_and_js()
2183
+				: '';
2184
+
2185
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2186
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2187
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2188
+			EEH_Template::display_template($template_path, $this->_template_args);
2189
+		}
2190
+	}
2191
+
2192
+
2193
+	/**
2194
+	 * form_before_question_group
2195
+	 *
2196
+	 * @param string $output
2197
+	 * @return        string
2198
+	 * @deprecated    as of 4.8.32.rc.000
2199
+	 */
2200
+	public function form_before_question_group($output)
2201
+	{
2202
+		EE_Error::doing_it_wrong(
2203
+			__CLASS__ . '::' . __FUNCTION__,
2204
+			esc_html__(
2205
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2206
+				'event_espresso'
2207
+			),
2208
+			'4.8.32.rc.000'
2209
+		);
2210
+		return '
2211 2211
 	<table class="form-table ee-width-100">
2212 2212
 		<tbody>
2213 2213
 			';
2214
-    }
2215
-
2216
-
2217
-    /**
2218
-     * form_after_question_group
2219
-     *
2220
-     * @param string $output
2221
-     * @return        string
2222
-     * @deprecated    as of 4.8.32.rc.000
2223
-     */
2224
-    public function form_after_question_group($output)
2225
-    {
2226
-        EE_Error::doing_it_wrong(
2227
-            __CLASS__ . '::' . __FUNCTION__,
2228
-            esc_html__(
2229
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2230
-                'event_espresso'
2231
-            ),
2232
-            '4.8.32.rc.000'
2233
-        );
2234
-        return '
2214
+	}
2215
+
2216
+
2217
+	/**
2218
+	 * form_after_question_group
2219
+	 *
2220
+	 * @param string $output
2221
+	 * @return        string
2222
+	 * @deprecated    as of 4.8.32.rc.000
2223
+	 */
2224
+	public function form_after_question_group($output)
2225
+	{
2226
+		EE_Error::doing_it_wrong(
2227
+			__CLASS__ . '::' . __FUNCTION__,
2228
+			esc_html__(
2229
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2230
+				'event_espresso'
2231
+			),
2232
+			'4.8.32.rc.000'
2233
+		);
2234
+		return '
2235 2235
 			<tr class="hide-if-no-js">
2236 2236
 				<th> </th>
2237 2237
 				<td class="reg-admin-edit-attendee-question-td">
2238 2238
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2239
-               . esc_attr__('click to edit question', 'event_espresso')
2240
-               . '">
2239
+			   . esc_attr__('click to edit question', 'event_espresso')
2240
+			   . '">
2241 2241
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2242
-               . esc_html__('edit the above question group', 'event_espresso')
2243
-               . '</span>
2242
+			   . esc_html__('edit the above question group', 'event_espresso')
2243
+			   . '</span>
2244 2244
 						<div class="dashicons dashicons-edit"></div>
2245 2245
 					</a>
2246 2246
 				</td>
@@ -2248,636 +2248,636 @@  discard block
 block discarded – undo
2248 2248
 		</tbody>
2249 2249
 	</table>
2250 2250
 ';
2251
-    }
2252
-
2253
-
2254
-    /**
2255
-     * form_form_field_label_wrap
2256
-     *
2257
-     * @param string $label
2258
-     * @return        string
2259
-     * @deprecated    as of 4.8.32.rc.000
2260
-     */
2261
-    public function form_form_field_label_wrap($label)
2262
-    {
2263
-        EE_Error::doing_it_wrong(
2264
-            __CLASS__ . '::' . __FUNCTION__,
2265
-            esc_html__(
2266
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2267
-                'event_espresso'
2268
-            ),
2269
-            '4.8.32.rc.000'
2270
-        );
2271
-        return '
2251
+	}
2252
+
2253
+
2254
+	/**
2255
+	 * form_form_field_label_wrap
2256
+	 *
2257
+	 * @param string $label
2258
+	 * @return        string
2259
+	 * @deprecated    as of 4.8.32.rc.000
2260
+	 */
2261
+	public function form_form_field_label_wrap($label)
2262
+	{
2263
+		EE_Error::doing_it_wrong(
2264
+			__CLASS__ . '::' . __FUNCTION__,
2265
+			esc_html__(
2266
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2267
+				'event_espresso'
2268
+			),
2269
+			'4.8.32.rc.000'
2270
+		);
2271
+		return '
2272 2272
 			<tr>
2273 2273
 				<th>
2274 2274
 					' . $label . '
2275 2275
 				</th>';
2276
-    }
2277
-
2278
-
2279
-    /**
2280
-     * form_form_field_input__wrap
2281
-     *
2282
-     * @param string $input
2283
-     * @return        string
2284
-     * @deprecated    as of 4.8.32.rc.000
2285
-     */
2286
-    public function form_form_field_input__wrap($input)
2287
-    {
2288
-        EE_Error::doing_it_wrong(
2289
-            __CLASS__ . '::' . __FUNCTION__,
2290
-            esc_html__(
2291
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2292
-                'event_espresso'
2293
-            ),
2294
-            '4.8.32.rc.000'
2295
-        );
2296
-        return '
2276
+	}
2277
+
2278
+
2279
+	/**
2280
+	 * form_form_field_input__wrap
2281
+	 *
2282
+	 * @param string $input
2283
+	 * @return        string
2284
+	 * @deprecated    as of 4.8.32.rc.000
2285
+	 */
2286
+	public function form_form_field_input__wrap($input)
2287
+	{
2288
+		EE_Error::doing_it_wrong(
2289
+			__CLASS__ . '::' . __FUNCTION__,
2290
+			esc_html__(
2291
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2292
+				'event_espresso'
2293
+			),
2294
+			'4.8.32.rc.000'
2295
+		);
2296
+		return '
2297 2297
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2298 2298
 					' . $input . '
2299 2299
 				</td>
2300 2300
 			</tr>';
2301
-    }
2302
-
2303
-
2304
-    /**
2305
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2306
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2307
-     * to display the page
2308
-     *
2309
-     * @return void
2310
-     * @throws EE_Error
2311
-     * @throws InvalidArgumentException
2312
-     * @throws InvalidDataTypeException
2313
-     * @throws InvalidInterfaceException
2314
-     * @throws ReflectionException
2315
-     */
2316
-    protected function _update_attendee_registration_form()
2317
-    {
2318
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2319
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2320
-            $REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2321
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2322
-            if ($success) {
2323
-                $what  = esc_html__('Registration Form', 'event_espresso');
2324
-                $route = $REG_ID
2325
-                    ? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2326
-                    : ['action' => 'default'];
2327
-                $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2328
-            }
2329
-        }
2330
-    }
2331
-
2332
-
2333
-    /**
2334
-     * Gets the form for saving registrations custom questions (if done
2335
-     * previously retrieves the cached form object, which may have validation errors in it)
2336
-     *
2337
-     * @param int $REG_ID
2338
-     * @return EE_Registration_Custom_Questions_Form
2339
-     * @throws EE_Error
2340
-     * @throws InvalidArgumentException
2341
-     * @throws InvalidDataTypeException
2342
-     * @throws InvalidInterfaceException
2343
-     * @throws ReflectionException
2344
-     */
2345
-    protected function _get_reg_custom_questions_form($REG_ID)
2346
-    {
2347
-        if (! $this->_reg_custom_questions_form) {
2348
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2349
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2350
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2351
-            );
2352
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2353
-        }
2354
-        return $this->_reg_custom_questions_form;
2355
-    }
2356
-
2357
-
2358
-    /**
2359
-     * Saves
2360
-     *
2361
-     * @param bool $REG_ID
2362
-     * @return bool
2363
-     * @throws EE_Error
2364
-     * @throws InvalidArgumentException
2365
-     * @throws InvalidDataTypeException
2366
-     * @throws InvalidInterfaceException
2367
-     * @throws ReflectionException
2368
-     */
2369
-    private function _save_reg_custom_questions_form($REG_ID = 0)
2370
-    {
2371
-        if (! $REG_ID) {
2372
-            EE_Error::add_error(
2373
-                esc_html__(
2374
-                    'An error occurred. No registration ID was received.',
2375
-                    'event_espresso'
2376
-                ),
2377
-                __FILE__,
2378
-                __FUNCTION__,
2379
-                __LINE__
2380
-            );
2381
-        }
2382
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2383
-        $form->receive_form_submission($this->request->requestParams());
2384
-        $success = false;
2385
-        if ($form->is_valid()) {
2386
-            foreach ($form->subforms() as $question_group_form) {
2387
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2388
-                    $where_conditions    = [
2389
-                        'QST_ID' => $question_id,
2390
-                        'REG_ID' => $REG_ID,
2391
-                    ];
2392
-                    $possibly_new_values = [
2393
-                        'ANS_value' => $input->normalized_value(),
2394
-                    ];
2395
-                    $answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2396
-                    if ($answer instanceof EE_Answer) {
2397
-                        $success = $answer->save($possibly_new_values);
2398
-                    } else {
2399
-                        // insert it then
2400
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2401
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2402
-                        $success     = $answer->save();
2403
-                    }
2404
-                }
2405
-            }
2406
-        } else {
2407
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2408
-        }
2409
-        return $success;
2410
-    }
2411
-
2412
-
2413
-    /**
2414
-     * generates HTML for the Registration main meta box
2415
-     *
2416
-     * @return void
2417
-     * @throws DomainException
2418
-     * @throws EE_Error
2419
-     * @throws InvalidArgumentException
2420
-     * @throws InvalidDataTypeException
2421
-     * @throws InvalidInterfaceException
2422
-     * @throws ReflectionException
2423
-     */
2424
-    public function _reg_attendees_meta_box()
2425
-    {
2426
-        $REG = $this->getRegistrationModel();
2427
-        // get all other registrations on this transaction, and cache
2428
-        // the attendees for them so we don't have to run another query using force_join
2429
-        $registrations                           = $REG->get_all(
2430
-            [
2431
-                [
2432
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2433
-                    'REG_ID' => ['!=', $this->_registration->ID()],
2434
-                ],
2435
-                'force_join'               => ['Attendee'],
2436
-                'default_where_conditions' => 'other_models_only',
2437
-            ]
2438
-        );
2439
-        $this->_template_args['attendees']       = [];
2440
-        $this->_template_args['attendee_notice'] = '';
2441
-        if (
2442
-            empty($registrations)
2443
-            || (is_array($registrations)
2444
-                && ! EEH_Array::get_one_item_from_array($registrations))
2445
-        ) {
2446
-            EE_Error::add_error(
2447
-                esc_html__(
2448
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2449
-                    'event_espresso'
2450
-                ),
2451
-                __FILE__,
2452
-                __FUNCTION__,
2453
-                __LINE__
2454
-            );
2455
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2456
-        } else {
2457
-            $att_nmbr = 1;
2458
-            foreach ($registrations as $registration) {
2459
-                /* @var $registration EE_Registration */
2460
-                $attendee                                                      = $registration->attendee()
2461
-                    ? $registration->attendee()
2462
-                    : $this->getAttendeeModel()->create_default_object();
2463
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2464
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2465
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2466
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2468
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2469
-                    ', ',
2470
-                    $attendee->full_address_as_array()
2471
-                );
2472
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2473
-                    [
2474
-                        'action' => 'edit_attendee',
2475
-                        'post'   => $attendee->ID(),
2476
-                    ],
2477
-                    REG_ADMIN_URL
2478
-                );
2479
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2480
-                    $registration->event_obj() instanceof EE_Event
2481
-                        ? $registration->event_obj()->name()
2482
-                        : '';
2483
-                $att_nmbr++;
2484
-            }
2485
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2486
-        }
2487
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2488
-        EEH_Template::display_template($template_path, $this->_template_args);
2489
-    }
2490
-
2491
-
2492
-    /**
2493
-     * generates HTML for the Edit Registration side meta box
2494
-     *
2495
-     * @return void
2496
-     * @throws DomainException
2497
-     * @throws EE_Error
2498
-     * @throws InvalidArgumentException
2499
-     * @throws InvalidDataTypeException
2500
-     * @throws InvalidInterfaceException
2501
-     * @throws ReflectionException
2502
-     */
2503
-    public function _reg_registrant_side_meta_box()
2504
-    {
2505
-        /*@var $attendee EE_Attendee */
2506
-        $att_check = $this->_registration->attendee();
2507
-        $attendee  = $att_check instanceof EE_Attendee
2508
-            ? $att_check
2509
-            : $this->getAttendeeModel()->create_default_object();
2510
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2511
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2512
-        // primary registration object (that way we know if we need to show create button or not)
2513
-        if (! $this->_registration->is_primary_registrant()) {
2514
-            $primary_registration = $this->_registration->get_primary_registration();
2515
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2516
-                : null;
2517
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2518
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2519
-                // custom attendee object so let's not worry about the primary reg.
2520
-                $primary_registration = null;
2521
-            }
2522
-        } else {
2523
-            $primary_registration = null;
2524
-        }
2525
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2526
-        $this->_template_args['fname']             = $attendee->fname();
2527
-        $this->_template_args['lname']             = $attendee->lname();
2528
-        $this->_template_args['email']             = $attendee->email();
2529
-        $this->_template_args['phone']             = $attendee->phone();
2530
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2531
-        // edit link
2532
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2533
-            [
2534
-                'action' => 'edit_attendee',
2535
-                'post'   => $attendee->ID(),
2536
-            ],
2537
-            REG_ADMIN_URL
2538
-        );
2539
-        $this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2540
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2541
-        // create link
2542
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2543
-            ? EE_Admin_Page::add_query_args_and_nonce(
2544
-                [
2545
-                    'action'  => 'duplicate_attendee',
2546
-                    '_REG_ID' => $this->_registration->ID(),
2547
-                ],
2548
-                REG_ADMIN_URL
2549
-            ) : '';
2550
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2551
-        $this->_template_args['att_check'] = $att_check;
2552
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2553
-        EEH_Template::display_template($template_path, $this->_template_args);
2554
-    }
2555
-
2556
-
2557
-    /**
2558
-     * trash or restore registrations
2559
-     *
2560
-     * @param boolean $trash whether to archive or restore
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     * @throws InvalidArgumentException
2564
-     * @throws InvalidDataTypeException
2565
-     * @throws InvalidInterfaceException
2566
-     * @throws RuntimeException
2567
-     */
2568
-    protected function _trash_or_restore_registrations($trash = true)
2569
-    {
2570
-        // if empty _REG_ID then get out because there's nothing to do
2571
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2572
-        if (empty($REG_IDs)) {
2573
-            EE_Error::add_error(
2574
-                sprintf(
2575
-                    esc_html__(
2576
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2577
-                        'event_espresso'
2578
-                    ),
2579
-                    $trash ? 'trash' : 'restore'
2580
-                ),
2581
-                __FILE__,
2582
-                __LINE__,
2583
-                __FUNCTION__
2584
-            );
2585
-            $this->_redirect_after_action(false, '', '', [], true);
2586
-        }
2587
-        $success        = 0;
2588
-        $overwrite_msgs = false;
2589
-        // Checkboxes
2590
-        $reg_count = count($REG_IDs);
2591
-        // cycle thru checkboxes
2592
-        foreach ($REG_IDs as $REG_ID) {
2593
-            /** @var EE_Registration $REG */
2594
-            $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2595
-            $payments = $REG->registration_payments();
2596
-            if (! empty($payments)) {
2597
-                $name           = $REG->attendee() instanceof EE_Attendee
2598
-                    ? $REG->attendee()->full_name()
2599
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2600
-                $overwrite_msgs = true;
2601
-                EE_Error::add_error(
2602
-                    sprintf(
2603
-                        esc_html__(
2604
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2605
-                            'event_espresso'
2606
-                        ),
2607
-                        $name
2608
-                    ),
2609
-                    __FILE__,
2610
-                    __FUNCTION__,
2611
-                    __LINE__
2612
-                );
2613
-                // can't trash this registration because it has payments.
2614
-                continue;
2615
-            }
2616
-            $updated = $trash ? $REG->delete() : $REG->restore();
2617
-            if ($updated) {
2618
-                $success++;
2619
-            }
2620
-        }
2621
-        $this->_redirect_after_action(
2622
-            $success === $reg_count, // were ALL registrations affected?
2623
-            $success > 1
2624
-                ? esc_html__('Registrations', 'event_espresso')
2625
-                : esc_html__('Registration', 'event_espresso'),
2626
-            $trash
2627
-                ? esc_html__('moved to the trash', 'event_espresso')
2628
-                : esc_html__('restored', 'event_espresso'),
2629
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2630
-            $overwrite_msgs
2631
-        );
2632
-    }
2633
-
2634
-
2635
-    /**
2636
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2637
-     * registration but also.
2638
-     * 1. Removing relations to EE_Attendee
2639
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2640
-     * ALSO trashed.
2641
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2642
-     * 4. Removing relationships between all tickets and the related registrations
2643
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2644
-     * 6. Deleting permanently any related Checkins.
2645
-     *
2646
-     * @return void
2647
-     * @throws EE_Error
2648
-     * @throws InvalidArgumentException
2649
-     * @throws InvalidDataTypeException
2650
-     * @throws InvalidInterfaceException
2651
-     * @throws ReflectionException
2652
-     */
2653
-    protected function _delete_registrations()
2654
-    {
2655
-        $REG_MDL = $this->getRegistrationModel();
2656
-        $success = 0;
2657
-        // Checkboxes
2658
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2659
-
2660
-        if (! empty($REG_IDs)) {
2661
-            // if array has more than one element than success message should be plural
2662
-            $success = count($REG_IDs) > 1 ? 2 : 1;
2663
-            // cycle thru checkboxes
2664
-            foreach ($REG_IDs as $REG_ID) {
2665
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
-                if (! $REG instanceof EE_Registration) {
2667
-                    continue;
2668
-                }
2669
-                $deleted = $this->_delete_registration($REG);
2670
-                if (! $deleted) {
2671
-                    $success = 0;
2672
-                }
2673
-            }
2674
-        }
2675
-
2676
-        $what        = $success > 1
2677
-            ? esc_html__('Registrations', 'event_espresso')
2678
-            : esc_html__('Registration', 'event_espresso');
2679
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2680
-        $this->_redirect_after_action(
2681
-            $success,
2682
-            $what,
2683
-            $action_desc,
2684
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2685
-            true
2686
-        );
2687
-    }
2688
-
2689
-
2690
-    /**
2691
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2692
-     * models get affected.
2693
-     *
2694
-     * @param EE_Registration $REG registration to be deleted permanently
2695
-     * @return bool true = successful deletion, false = fail.
2696
-     * @throws EE_Error
2697
-     * @throws InvalidArgumentException
2698
-     * @throws InvalidDataTypeException
2699
-     * @throws InvalidInterfaceException
2700
-     * @throws ReflectionException
2701
-     */
2702
-    protected function _delete_registration(EE_Registration $REG)
2703
-    {
2704
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2705
-        // registrations on the transaction that are NOT trashed.
2706
-        $TXN = $REG->get_first_related('Transaction');
2707
-        if (! $TXN instanceof EE_Transaction) {
2708
-            EE_Error::add_error(
2709
-                sprintf(
2710
-                    esc_html__(
2711
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2712
-                        'event_espresso'
2713
-                    ),
2714
-                    $REG->id()
2715
-                ),
2716
-                __FILE__,
2717
-                __FUNCTION__,
2718
-                __LINE__
2719
-            );
2720
-            return false;
2721
-        }
2722
-        $REGS        = $TXN->get_many_related('Registration');
2723
-        $all_trashed = true;
2724
-        foreach ($REGS as $registration) {
2725
-            if (! $registration->get('REG_deleted')) {
2726
-                $all_trashed = false;
2727
-            }
2728
-        }
2729
-        if (! $all_trashed) {
2730
-            EE_Error::add_error(
2731
-                esc_html__(
2732
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2733
-                    'event_espresso'
2734
-                ),
2735
-                __FILE__,
2736
-                __FUNCTION__,
2737
-                __LINE__
2738
-            );
2739
-            return false;
2740
-        }
2741
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2742
-        // separately from THIS one).
2743
-        foreach ($REGS as $registration) {
2744
-            // delete related answers
2745
-            $registration->delete_related_permanently('Answer');
2746
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2747
-            $attendee = $registration->get_first_related('Attendee');
2748
-            if ($attendee instanceof EE_Attendee) {
2749
-                $registration->_remove_relation_to($attendee, 'Attendee');
2750
-            }
2751
-            // now remove relationships to tickets on this registration.
2752
-            $registration->_remove_relations('Ticket');
2753
-            // now delete permanently the checkins related to this registration.
2754
-            $registration->delete_related_permanently('Checkin');
2755
-            if ($registration->ID() === $REG->ID()) {
2756
-                continue;
2757
-            } //we don't want to delete permanently the existing registration just yet.
2758
-            // remove relation to transaction for these registrations if NOT the existing registrations
2759
-            $registration->_remove_relations('Transaction');
2760
-            // delete permanently any related messages.
2761
-            $registration->delete_related_permanently('Message');
2762
-            // now delete this registration permanently
2763
-            $registration->delete_permanently();
2764
-        }
2765
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2766
-        // (the transaction and line items should be all that's left).
2767
-        // delete the line items related to the transaction for this registration.
2768
-        $TXN->delete_related_permanently('Line_Item');
2769
-        // we need to remove all the relationships on the transaction
2770
-        $TXN->delete_related_permanently('Payment');
2771
-        $TXN->delete_related_permanently('Extra_Meta');
2772
-        $TXN->delete_related_permanently('Message');
2773
-        // now we can delete this REG permanently (and the transaction of course)
2774
-        $REG->delete_related_permanently('Transaction');
2775
-        return $REG->delete_permanently();
2776
-    }
2777
-
2778
-
2779
-    /**
2780
-     *    generates HTML for the Register New Attendee Admin page
2781
-     *
2782
-     * @throws DomainException
2783
-     * @throws EE_Error
2784
-     * @throws InvalidArgumentException
2785
-     * @throws InvalidDataTypeException
2786
-     * @throws InvalidInterfaceException
2787
-     * @throws ReflectionException
2788
-     */
2789
-    public function new_registration()
2790
-    {
2791
-        if (! $this->_set_reg_event()) {
2792
-            throw new EE_Error(
2793
-                esc_html__(
2794
-                    'Unable to continue with registering because there is no Event ID in the request',
2795
-                    'event_espresso'
2796
-                )
2797
-            );
2798
-        }
2799
-        /** @var CurrentPage $current_page */
2800
-        $current_page = $this->loader->getShared(CurrentPage::class);
2801
-        $current_page->setEspressoPage(true);
2802
-        // gotta start with a clean slate if we're not coming here via ajax
2803
-        if (
2804
-            ! $this->request->isAjax()
2805
-            && (
2806
-                ! $this->request->requestParamIsSet('processing_registration')
2807
-                || $this->request->requestParamIsSet('step_error')
2808
-            )
2809
-        ) {
2810
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2811
-        }
2812
-        $this->_template_args['event_name'] = '';
2813
-        // event name
2814
-        if ($this->_reg_event) {
2815
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2816
-            $edit_event_url                     = self::add_query_args_and_nonce(
2817
-                [
2818
-                    'action' => 'edit',
2819
-                    'post'   => $this->_reg_event->ID(),
2820
-                ],
2821
-                EVENTS_ADMIN_URL
2822
-            );
2823
-            $edit_event_lnk                     = '<a href="'
2824
-                                                  . $edit_event_url
2825
-                                                  . '" title="'
2826
-                                                  . esc_attr__('Edit ', 'event_espresso')
2827
-                                                  . $this->_reg_event->name()
2828
-                                                  . '">'
2829
-                                                  . esc_html__('Edit Event', 'event_espresso')
2830
-                                                  . '</a>';
2831
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2832
-                                                   . $edit_event_lnk
2833
-                                                   . '</span>';
2834
-        }
2835
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2836
-        if ($this->request->isAjax()) {
2837
-            $this->_return_json();
2838
-        }
2839
-        // grab header
2840
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2841
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2842
-            $template_path,
2843
-            $this->_template_args,
2844
-            true
2845
-        );
2846
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2847
-        // the details template wrapper
2848
-        $this->display_admin_page_with_sidebar();
2849
-    }
2850
-
2851
-
2852
-    /**
2853
-     * This returns the content for a registration step
2854
-     *
2855
-     * @return string html
2856
-     * @throws DomainException
2857
-     * @throws EE_Error
2858
-     * @throws InvalidArgumentException
2859
-     * @throws InvalidDataTypeException
2860
-     * @throws InvalidInterfaceException
2861
-     * @throws ReflectionException
2862
-     */
2863
-    protected function _get_registration_step_content()
2864
-    {
2865
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2866
-            $warning_msg = sprintf(
2867
-                esc_html__(
2868
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2869
-                    'event_espresso'
2870
-                ),
2871
-                '<br />',
2872
-                '<h3 class="important-notice">',
2873
-                '</h3>',
2874
-                '<div class="float-right">',
2875
-                '<span id="redirect_timer" class="important-notice">30</span>',
2876
-                '</div>',
2877
-                '<b>',
2878
-                '</b>'
2879
-            );
2880
-            return '
2301
+	}
2302
+
2303
+
2304
+	/**
2305
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2306
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2307
+	 * to display the page
2308
+	 *
2309
+	 * @return void
2310
+	 * @throws EE_Error
2311
+	 * @throws InvalidArgumentException
2312
+	 * @throws InvalidDataTypeException
2313
+	 * @throws InvalidInterfaceException
2314
+	 * @throws ReflectionException
2315
+	 */
2316
+	protected function _update_attendee_registration_form()
2317
+	{
2318
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2319
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2320
+			$REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2321
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2322
+			if ($success) {
2323
+				$what  = esc_html__('Registration Form', 'event_espresso');
2324
+				$route = $REG_ID
2325
+					? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2326
+					: ['action' => 'default'];
2327
+				$this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2328
+			}
2329
+		}
2330
+	}
2331
+
2332
+
2333
+	/**
2334
+	 * Gets the form for saving registrations custom questions (if done
2335
+	 * previously retrieves the cached form object, which may have validation errors in it)
2336
+	 *
2337
+	 * @param int $REG_ID
2338
+	 * @return EE_Registration_Custom_Questions_Form
2339
+	 * @throws EE_Error
2340
+	 * @throws InvalidArgumentException
2341
+	 * @throws InvalidDataTypeException
2342
+	 * @throws InvalidInterfaceException
2343
+	 * @throws ReflectionException
2344
+	 */
2345
+	protected function _get_reg_custom_questions_form($REG_ID)
2346
+	{
2347
+		if (! $this->_reg_custom_questions_form) {
2348
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2349
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2350
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2351
+			);
2352
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2353
+		}
2354
+		return $this->_reg_custom_questions_form;
2355
+	}
2356
+
2357
+
2358
+	/**
2359
+	 * Saves
2360
+	 *
2361
+	 * @param bool $REG_ID
2362
+	 * @return bool
2363
+	 * @throws EE_Error
2364
+	 * @throws InvalidArgumentException
2365
+	 * @throws InvalidDataTypeException
2366
+	 * @throws InvalidInterfaceException
2367
+	 * @throws ReflectionException
2368
+	 */
2369
+	private function _save_reg_custom_questions_form($REG_ID = 0)
2370
+	{
2371
+		if (! $REG_ID) {
2372
+			EE_Error::add_error(
2373
+				esc_html__(
2374
+					'An error occurred. No registration ID was received.',
2375
+					'event_espresso'
2376
+				),
2377
+				__FILE__,
2378
+				__FUNCTION__,
2379
+				__LINE__
2380
+			);
2381
+		}
2382
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2383
+		$form->receive_form_submission($this->request->requestParams());
2384
+		$success = false;
2385
+		if ($form->is_valid()) {
2386
+			foreach ($form->subforms() as $question_group_form) {
2387
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2388
+					$where_conditions    = [
2389
+						'QST_ID' => $question_id,
2390
+						'REG_ID' => $REG_ID,
2391
+					];
2392
+					$possibly_new_values = [
2393
+						'ANS_value' => $input->normalized_value(),
2394
+					];
2395
+					$answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2396
+					if ($answer instanceof EE_Answer) {
2397
+						$success = $answer->save($possibly_new_values);
2398
+					} else {
2399
+						// insert it then
2400
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2401
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2402
+						$success     = $answer->save();
2403
+					}
2404
+				}
2405
+			}
2406
+		} else {
2407
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2408
+		}
2409
+		return $success;
2410
+	}
2411
+
2412
+
2413
+	/**
2414
+	 * generates HTML for the Registration main meta box
2415
+	 *
2416
+	 * @return void
2417
+	 * @throws DomainException
2418
+	 * @throws EE_Error
2419
+	 * @throws InvalidArgumentException
2420
+	 * @throws InvalidDataTypeException
2421
+	 * @throws InvalidInterfaceException
2422
+	 * @throws ReflectionException
2423
+	 */
2424
+	public function _reg_attendees_meta_box()
2425
+	{
2426
+		$REG = $this->getRegistrationModel();
2427
+		// get all other registrations on this transaction, and cache
2428
+		// the attendees for them so we don't have to run another query using force_join
2429
+		$registrations                           = $REG->get_all(
2430
+			[
2431
+				[
2432
+					'TXN_ID' => $this->_registration->transaction_ID(),
2433
+					'REG_ID' => ['!=', $this->_registration->ID()],
2434
+				],
2435
+				'force_join'               => ['Attendee'],
2436
+				'default_where_conditions' => 'other_models_only',
2437
+			]
2438
+		);
2439
+		$this->_template_args['attendees']       = [];
2440
+		$this->_template_args['attendee_notice'] = '';
2441
+		if (
2442
+			empty($registrations)
2443
+			|| (is_array($registrations)
2444
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2445
+		) {
2446
+			EE_Error::add_error(
2447
+				esc_html__(
2448
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2449
+					'event_espresso'
2450
+				),
2451
+				__FILE__,
2452
+				__FUNCTION__,
2453
+				__LINE__
2454
+			);
2455
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2456
+		} else {
2457
+			$att_nmbr = 1;
2458
+			foreach ($registrations as $registration) {
2459
+				/* @var $registration EE_Registration */
2460
+				$attendee                                                      = $registration->attendee()
2461
+					? $registration->attendee()
2462
+					: $this->getAttendeeModel()->create_default_object();
2463
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2464
+				$this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2465
+				$this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2466
+				$this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2467
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2468
+				$this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2469
+					', ',
2470
+					$attendee->full_address_as_array()
2471
+				);
2472
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2473
+					[
2474
+						'action' => 'edit_attendee',
2475
+						'post'   => $attendee->ID(),
2476
+					],
2477
+					REG_ADMIN_URL
2478
+				);
2479
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2480
+					$registration->event_obj() instanceof EE_Event
2481
+						? $registration->event_obj()->name()
2482
+						: '';
2483
+				$att_nmbr++;
2484
+			}
2485
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2486
+		}
2487
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2488
+		EEH_Template::display_template($template_path, $this->_template_args);
2489
+	}
2490
+
2491
+
2492
+	/**
2493
+	 * generates HTML for the Edit Registration side meta box
2494
+	 *
2495
+	 * @return void
2496
+	 * @throws DomainException
2497
+	 * @throws EE_Error
2498
+	 * @throws InvalidArgumentException
2499
+	 * @throws InvalidDataTypeException
2500
+	 * @throws InvalidInterfaceException
2501
+	 * @throws ReflectionException
2502
+	 */
2503
+	public function _reg_registrant_side_meta_box()
2504
+	{
2505
+		/*@var $attendee EE_Attendee */
2506
+		$att_check = $this->_registration->attendee();
2507
+		$attendee  = $att_check instanceof EE_Attendee
2508
+			? $att_check
2509
+			: $this->getAttendeeModel()->create_default_object();
2510
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2511
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2512
+		// primary registration object (that way we know if we need to show create button or not)
2513
+		if (! $this->_registration->is_primary_registrant()) {
2514
+			$primary_registration = $this->_registration->get_primary_registration();
2515
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2516
+				: null;
2517
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2518
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2519
+				// custom attendee object so let's not worry about the primary reg.
2520
+				$primary_registration = null;
2521
+			}
2522
+		} else {
2523
+			$primary_registration = null;
2524
+		}
2525
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2526
+		$this->_template_args['fname']             = $attendee->fname();
2527
+		$this->_template_args['lname']             = $attendee->lname();
2528
+		$this->_template_args['email']             = $attendee->email();
2529
+		$this->_template_args['phone']             = $attendee->phone();
2530
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2531
+		// edit link
2532
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2533
+			[
2534
+				'action' => 'edit_attendee',
2535
+				'post'   => $attendee->ID(),
2536
+			],
2537
+			REG_ADMIN_URL
2538
+		);
2539
+		$this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2540
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2541
+		// create link
2542
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2543
+			? EE_Admin_Page::add_query_args_and_nonce(
2544
+				[
2545
+					'action'  => 'duplicate_attendee',
2546
+					'_REG_ID' => $this->_registration->ID(),
2547
+				],
2548
+				REG_ADMIN_URL
2549
+			) : '';
2550
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2551
+		$this->_template_args['att_check'] = $att_check;
2552
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2553
+		EEH_Template::display_template($template_path, $this->_template_args);
2554
+	}
2555
+
2556
+
2557
+	/**
2558
+	 * trash or restore registrations
2559
+	 *
2560
+	 * @param boolean $trash whether to archive or restore
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 * @throws InvalidArgumentException
2564
+	 * @throws InvalidDataTypeException
2565
+	 * @throws InvalidInterfaceException
2566
+	 * @throws RuntimeException
2567
+	 */
2568
+	protected function _trash_or_restore_registrations($trash = true)
2569
+	{
2570
+		// if empty _REG_ID then get out because there's nothing to do
2571
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2572
+		if (empty($REG_IDs)) {
2573
+			EE_Error::add_error(
2574
+				sprintf(
2575
+					esc_html__(
2576
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2577
+						'event_espresso'
2578
+					),
2579
+					$trash ? 'trash' : 'restore'
2580
+				),
2581
+				__FILE__,
2582
+				__LINE__,
2583
+				__FUNCTION__
2584
+			);
2585
+			$this->_redirect_after_action(false, '', '', [], true);
2586
+		}
2587
+		$success        = 0;
2588
+		$overwrite_msgs = false;
2589
+		// Checkboxes
2590
+		$reg_count = count($REG_IDs);
2591
+		// cycle thru checkboxes
2592
+		foreach ($REG_IDs as $REG_ID) {
2593
+			/** @var EE_Registration $REG */
2594
+			$REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2595
+			$payments = $REG->registration_payments();
2596
+			if (! empty($payments)) {
2597
+				$name           = $REG->attendee() instanceof EE_Attendee
2598
+					? $REG->attendee()->full_name()
2599
+					: esc_html__('Unknown Attendee', 'event_espresso');
2600
+				$overwrite_msgs = true;
2601
+				EE_Error::add_error(
2602
+					sprintf(
2603
+						esc_html__(
2604
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2605
+							'event_espresso'
2606
+						),
2607
+						$name
2608
+					),
2609
+					__FILE__,
2610
+					__FUNCTION__,
2611
+					__LINE__
2612
+				);
2613
+				// can't trash this registration because it has payments.
2614
+				continue;
2615
+			}
2616
+			$updated = $trash ? $REG->delete() : $REG->restore();
2617
+			if ($updated) {
2618
+				$success++;
2619
+			}
2620
+		}
2621
+		$this->_redirect_after_action(
2622
+			$success === $reg_count, // were ALL registrations affected?
2623
+			$success > 1
2624
+				? esc_html__('Registrations', 'event_espresso')
2625
+				: esc_html__('Registration', 'event_espresso'),
2626
+			$trash
2627
+				? esc_html__('moved to the trash', 'event_espresso')
2628
+				: esc_html__('restored', 'event_espresso'),
2629
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2630
+			$overwrite_msgs
2631
+		);
2632
+	}
2633
+
2634
+
2635
+	/**
2636
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2637
+	 * registration but also.
2638
+	 * 1. Removing relations to EE_Attendee
2639
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2640
+	 * ALSO trashed.
2641
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2642
+	 * 4. Removing relationships between all tickets and the related registrations
2643
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2644
+	 * 6. Deleting permanently any related Checkins.
2645
+	 *
2646
+	 * @return void
2647
+	 * @throws EE_Error
2648
+	 * @throws InvalidArgumentException
2649
+	 * @throws InvalidDataTypeException
2650
+	 * @throws InvalidInterfaceException
2651
+	 * @throws ReflectionException
2652
+	 */
2653
+	protected function _delete_registrations()
2654
+	{
2655
+		$REG_MDL = $this->getRegistrationModel();
2656
+		$success = 0;
2657
+		// Checkboxes
2658
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2659
+
2660
+		if (! empty($REG_IDs)) {
2661
+			// if array has more than one element than success message should be plural
2662
+			$success = count($REG_IDs) > 1 ? 2 : 1;
2663
+			// cycle thru checkboxes
2664
+			foreach ($REG_IDs as $REG_ID) {
2665
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
+				if (! $REG instanceof EE_Registration) {
2667
+					continue;
2668
+				}
2669
+				$deleted = $this->_delete_registration($REG);
2670
+				if (! $deleted) {
2671
+					$success = 0;
2672
+				}
2673
+			}
2674
+		}
2675
+
2676
+		$what        = $success > 1
2677
+			? esc_html__('Registrations', 'event_espresso')
2678
+			: esc_html__('Registration', 'event_espresso');
2679
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2680
+		$this->_redirect_after_action(
2681
+			$success,
2682
+			$what,
2683
+			$action_desc,
2684
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2685
+			true
2686
+		);
2687
+	}
2688
+
2689
+
2690
+	/**
2691
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2692
+	 * models get affected.
2693
+	 *
2694
+	 * @param EE_Registration $REG registration to be deleted permanently
2695
+	 * @return bool true = successful deletion, false = fail.
2696
+	 * @throws EE_Error
2697
+	 * @throws InvalidArgumentException
2698
+	 * @throws InvalidDataTypeException
2699
+	 * @throws InvalidInterfaceException
2700
+	 * @throws ReflectionException
2701
+	 */
2702
+	protected function _delete_registration(EE_Registration $REG)
2703
+	{
2704
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2705
+		// registrations on the transaction that are NOT trashed.
2706
+		$TXN = $REG->get_first_related('Transaction');
2707
+		if (! $TXN instanceof EE_Transaction) {
2708
+			EE_Error::add_error(
2709
+				sprintf(
2710
+					esc_html__(
2711
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2712
+						'event_espresso'
2713
+					),
2714
+					$REG->id()
2715
+				),
2716
+				__FILE__,
2717
+				__FUNCTION__,
2718
+				__LINE__
2719
+			);
2720
+			return false;
2721
+		}
2722
+		$REGS        = $TXN->get_many_related('Registration');
2723
+		$all_trashed = true;
2724
+		foreach ($REGS as $registration) {
2725
+			if (! $registration->get('REG_deleted')) {
2726
+				$all_trashed = false;
2727
+			}
2728
+		}
2729
+		if (! $all_trashed) {
2730
+			EE_Error::add_error(
2731
+				esc_html__(
2732
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2733
+					'event_espresso'
2734
+				),
2735
+				__FILE__,
2736
+				__FUNCTION__,
2737
+				__LINE__
2738
+			);
2739
+			return false;
2740
+		}
2741
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2742
+		// separately from THIS one).
2743
+		foreach ($REGS as $registration) {
2744
+			// delete related answers
2745
+			$registration->delete_related_permanently('Answer');
2746
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2747
+			$attendee = $registration->get_first_related('Attendee');
2748
+			if ($attendee instanceof EE_Attendee) {
2749
+				$registration->_remove_relation_to($attendee, 'Attendee');
2750
+			}
2751
+			// now remove relationships to tickets on this registration.
2752
+			$registration->_remove_relations('Ticket');
2753
+			// now delete permanently the checkins related to this registration.
2754
+			$registration->delete_related_permanently('Checkin');
2755
+			if ($registration->ID() === $REG->ID()) {
2756
+				continue;
2757
+			} //we don't want to delete permanently the existing registration just yet.
2758
+			// remove relation to transaction for these registrations if NOT the existing registrations
2759
+			$registration->_remove_relations('Transaction');
2760
+			// delete permanently any related messages.
2761
+			$registration->delete_related_permanently('Message');
2762
+			// now delete this registration permanently
2763
+			$registration->delete_permanently();
2764
+		}
2765
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2766
+		// (the transaction and line items should be all that's left).
2767
+		// delete the line items related to the transaction for this registration.
2768
+		$TXN->delete_related_permanently('Line_Item');
2769
+		// we need to remove all the relationships on the transaction
2770
+		$TXN->delete_related_permanently('Payment');
2771
+		$TXN->delete_related_permanently('Extra_Meta');
2772
+		$TXN->delete_related_permanently('Message');
2773
+		// now we can delete this REG permanently (and the transaction of course)
2774
+		$REG->delete_related_permanently('Transaction');
2775
+		return $REG->delete_permanently();
2776
+	}
2777
+
2778
+
2779
+	/**
2780
+	 *    generates HTML for the Register New Attendee Admin page
2781
+	 *
2782
+	 * @throws DomainException
2783
+	 * @throws EE_Error
2784
+	 * @throws InvalidArgumentException
2785
+	 * @throws InvalidDataTypeException
2786
+	 * @throws InvalidInterfaceException
2787
+	 * @throws ReflectionException
2788
+	 */
2789
+	public function new_registration()
2790
+	{
2791
+		if (! $this->_set_reg_event()) {
2792
+			throw new EE_Error(
2793
+				esc_html__(
2794
+					'Unable to continue with registering because there is no Event ID in the request',
2795
+					'event_espresso'
2796
+				)
2797
+			);
2798
+		}
2799
+		/** @var CurrentPage $current_page */
2800
+		$current_page = $this->loader->getShared(CurrentPage::class);
2801
+		$current_page->setEspressoPage(true);
2802
+		// gotta start with a clean slate if we're not coming here via ajax
2803
+		if (
2804
+			! $this->request->isAjax()
2805
+			&& (
2806
+				! $this->request->requestParamIsSet('processing_registration')
2807
+				|| $this->request->requestParamIsSet('step_error')
2808
+			)
2809
+		) {
2810
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2811
+		}
2812
+		$this->_template_args['event_name'] = '';
2813
+		// event name
2814
+		if ($this->_reg_event) {
2815
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2816
+			$edit_event_url                     = self::add_query_args_and_nonce(
2817
+				[
2818
+					'action' => 'edit',
2819
+					'post'   => $this->_reg_event->ID(),
2820
+				],
2821
+				EVENTS_ADMIN_URL
2822
+			);
2823
+			$edit_event_lnk                     = '<a href="'
2824
+												  . $edit_event_url
2825
+												  . '" title="'
2826
+												  . esc_attr__('Edit ', 'event_espresso')
2827
+												  . $this->_reg_event->name()
2828
+												  . '">'
2829
+												  . esc_html__('Edit Event', 'event_espresso')
2830
+												  . '</a>';
2831
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2832
+												   . $edit_event_lnk
2833
+												   . '</span>';
2834
+		}
2835
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2836
+		if ($this->request->isAjax()) {
2837
+			$this->_return_json();
2838
+		}
2839
+		// grab header
2840
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2841
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2842
+			$template_path,
2843
+			$this->_template_args,
2844
+			true
2845
+		);
2846
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2847
+		// the details template wrapper
2848
+		$this->display_admin_page_with_sidebar();
2849
+	}
2850
+
2851
+
2852
+	/**
2853
+	 * This returns the content for a registration step
2854
+	 *
2855
+	 * @return string html
2856
+	 * @throws DomainException
2857
+	 * @throws EE_Error
2858
+	 * @throws InvalidArgumentException
2859
+	 * @throws InvalidDataTypeException
2860
+	 * @throws InvalidInterfaceException
2861
+	 * @throws ReflectionException
2862
+	 */
2863
+	protected function _get_registration_step_content()
2864
+	{
2865
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2866
+			$warning_msg = sprintf(
2867
+				esc_html__(
2868
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2869
+					'event_espresso'
2870
+				),
2871
+				'<br />',
2872
+				'<h3 class="important-notice">',
2873
+				'</h3>',
2874
+				'<div class="float-right">',
2875
+				'<span id="redirect_timer" class="important-notice">30</span>',
2876
+				'</div>',
2877
+				'<b>',
2878
+				'</b>'
2879
+			);
2880
+			return '
2881 2881
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2882 2882
 	<script >
2883 2883
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2890,844 +2890,844 @@  discard block
 block discarded – undo
2890 2890
 	        }
2891 2891
 	    }, 800 );
2892 2892
 	</script >';
2893
-        }
2894
-        $template_args = [
2895
-            'title'                    => '',
2896
-            'content'                  => '',
2897
-            'step_button_text'         => '',
2898
-            'show_notification_toggle' => false,
2899
-        ];
2900
-        // to indicate we're processing a new registration
2901
-        $hidden_fields = [
2902
-            'processing_registration' => [
2903
-                'type'  => 'hidden',
2904
-                'value' => 0,
2905
-            ],
2906
-            'event_id'                => [
2907
-                'type'  => 'hidden',
2908
-                'value' => $this->_reg_event->ID(),
2909
-            ],
2910
-        ];
2911
-        // if the cart is empty then we know we're at step one, so we'll display the ticket selector
2912
-        $cart = EE_Registry::instance()->SSN->cart();
2913
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2914
-        switch ($step) {
2915
-            case 'ticket':
2916
-                $hidden_fields['processing_registration']['value'] = 1;
2917
-                $template_args['title']                            = esc_html__(
2918
-                    'Step One: Select the Ticket for this registration',
2919
-                    'event_espresso'
2920
-                );
2921
-                $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2922
-                $template_args['content'] .= '</div>';
2923
-                $template_args['step_button_text'] = esc_html__(
2924
-                    'Add Tickets and Continue to Registrant Details',
2925
-                    'event_espresso'
2926
-                );
2927
-                $template_args['show_notification_toggle']         = false;
2928
-                break;
2929
-            case 'questions':
2930
-                $hidden_fields['processing_registration']['value'] = 2;
2931
-                $template_args['title']                            = esc_html__(
2932
-                    'Step Two: Add Registrant Details for this Registration',
2933
-                    'event_espresso'
2934
-                );
2935
-                // in theory, we should be able to run EED_SPCO at this point
2936
-                // because the cart should have been set up properly by the first process_reg_step run.
2937
-                $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2938
-                $template_args['step_button_text'] = esc_html__(
2939
-                    'Save Registration and Continue to Details',
2940
-                    'event_espresso'
2941
-                );
2942
-                $template_args['show_notification_toggle'] = true;
2943
-                break;
2944
-        }
2945
-        // we come back to the process_registration_step route.
2946
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2947
-        return EEH_Template::display_template(
2948
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2949
-            $template_args,
2950
-            true
2951
-        );
2952
-    }
2953
-
2954
-
2955
-    /**
2956
-     * set_reg_event
2957
-     *
2958
-     * @return bool
2959
-     * @throws EE_Error
2960
-     * @throws InvalidArgumentException
2961
-     * @throws InvalidDataTypeException
2962
-     * @throws InvalidInterfaceException
2963
-     */
2964
-    private function _set_reg_event()
2965
-    {
2966
-        if (is_object($this->_reg_event)) {
2967
-            return true;
2968
-        }
2969
-
2970
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2971
-        if (! $EVT_ID) {
2972
-            return false;
2973
-        }
2974
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2975
-        return true;
2976
-    }
2977
-
2978
-
2979
-    /**
2980
-     * process_reg_step
2981
-     *
2982
-     * @return void
2983
-     * @throws DomainException
2984
-     * @throws EE_Error
2985
-     * @throws InvalidArgumentException
2986
-     * @throws InvalidDataTypeException
2987
-     * @throws InvalidInterfaceException
2988
-     * @throws ReflectionException
2989
-     * @throws RuntimeException
2990
-     */
2991
-    public function process_reg_step()
2992
-    {
2993
-        EE_System::do_not_cache();
2994
-        $this->_set_reg_event();
2995
-        /** @var CurrentPage $current_page */
2996
-        $current_page = $this->loader->getShared(CurrentPage::class);
2997
-        $current_page->setEspressoPage(true);
2998
-        $this->request->setRequestParam('uts', time());
2999
-        // what step are we on?
3000
-        $cart = EE_Registry::instance()->SSN->cart();
3001
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3002
-        // if doing ajax then we need to verify the nonce
3003
-        if ($this->request->isAjax()) {
3004
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
3005
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3006
-        }
3007
-        switch ($step) {
3008
-            case 'ticket':
3009
-                // process ticket selection
3010
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3011
-                if ($success) {
3012
-                    EE_Error::add_success(
3013
-                        esc_html__(
3014
-                            'Tickets Selected. Now complete the registration.',
3015
-                            'event_espresso'
3016
-                        )
3017
-                    );
3018
-                } else {
3019
-                    $this->request->setRequestParam('step_error', true);
3020
-                    $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3021
-                }
3022
-                if ($this->request->isAjax()) {
3023
-                    $this->new_registration(); // display next step
3024
-                } else {
3025
-                    $query_args = [
3026
-                        'action'                  => 'new_registration',
3027
-                        'processing_registration' => 1,
3028
-                        'event_id'                => $this->_reg_event->ID(),
3029
-                        'uts'                     => time(),
3030
-                    ];
3031
-                    $this->_redirect_after_action(
3032
-                        false,
3033
-                        '',
3034
-                        '',
3035
-                        $query_args,
3036
-                        true
3037
-                    );
3038
-                }
3039
-                break;
3040
-            case 'questions':
3041
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3042
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3043
-                }
3044
-                // process registration
3045
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3046
-                if ($cart instanceof EE_Cart) {
3047
-                    $grand_total = $cart->get_grand_total();
3048
-                    if ($grand_total instanceof EE_Line_Item) {
3049
-                        $grand_total->save_this_and_descendants_to_txn();
3050
-                    }
3051
-                }
3052
-                if (! $transaction instanceof EE_Transaction) {
3053
-                    $query_args = [
3054
-                        'action'                  => 'new_registration',
3055
-                        'processing_registration' => 2,
3056
-                        'event_id'                => $this->_reg_event->ID(),
3057
-                        'uts'                     => time(),
3058
-                    ];
3059
-                    if ($this->request->isAjax()) {
3060
-                        // display registration form again because there are errors (maybe validation?)
3061
-                        $this->new_registration();
3062
-                        return;
3063
-                    }
3064
-                    $this->_redirect_after_action(
3065
-                        false,
3066
-                        '',
3067
-                        '',
3068
-                        $query_args,
3069
-                        true
3070
-                    );
3071
-                    return;
3072
-                }
3073
-                // maybe update status, and make sure to save transaction if not done already
3074
-                if (! $transaction->update_status_based_on_total_paid()) {
3075
-                    $transaction->save();
3076
-                }
3077
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3078
-                $query_args = [
3079
-                    'action'        => 'redirect_to_txn',
3080
-                    'TXN_ID'        => $transaction->ID(),
3081
-                    'EVT_ID'        => $this->_reg_event->ID(),
3082
-                    'event_name'    => urlencode($this->_reg_event->name()),
3083
-                    'redirect_from' => 'new_registration',
3084
-                ];
3085
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3086
-                break;
3087
-        }
3088
-        // what are you looking here for?  Should be nothing to do at this point.
3089
-    }
3090
-
3091
-
3092
-    /**
3093
-     * redirect_to_txn
3094
-     *
3095
-     * @return void
3096
-     * @throws EE_Error
3097
-     * @throws InvalidArgumentException
3098
-     * @throws InvalidDataTypeException
3099
-     * @throws InvalidInterfaceException
3100
-     * @throws ReflectionException
3101
-     */
3102
-    public function redirect_to_txn()
3103
-    {
3104
-        EE_System::do_not_cache();
3105
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3106
-        $query_args = [
3107
-            'action' => 'view_transaction',
3108
-            'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3109
-            'page'   => 'espresso_transactions',
3110
-        ];
3111
-        if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3112
-            $query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3113
-            $query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3114
-            $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3115
-        }
3116
-        EE_Error::add_success(
3117
-            esc_html__(
3118
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3119
-                'event_espresso'
3120
-            )
3121
-        );
3122
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3123
-    }
3124
-
3125
-
3126
-    /**
3127
-     * generates HTML for the Attendee Contact List
3128
-     *
3129
-     * @return void
3130
-     * @throws DomainException
3131
-     * @throws EE_Error
3132
-     */
3133
-    protected function _attendee_contact_list_table()
3134
-    {
3135
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3136
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3137
-        $this->display_admin_list_table_page_with_no_sidebar();
3138
-    }
3139
-
3140
-
3141
-    /**
3142
-     * get_attendees
3143
-     *
3144
-     * @param      $per_page
3145
-     * @param bool $count whether to return count or data.
3146
-     * @param bool $trash
3147
-     * @return array|int
3148
-     * @throws EE_Error
3149
-     * @throws InvalidArgumentException
3150
-     * @throws InvalidDataTypeException
3151
-     * @throws InvalidInterfaceException
3152
-     */
3153
-    public function get_attendees($per_page, $count = false, $trash = false)
3154
-    {
3155
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3156
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3157
-        $orderby = $this->request->getRequestParam('orderby');
3158
-        switch ($orderby) {
3159
-            case 'ATT_ID':
3160
-            case 'ATT_fname':
3161
-            case 'ATT_email':
3162
-            case 'ATT_city':
3163
-            case 'STA_ID':
3164
-            case 'CNT_ID':
3165
-                break;
3166
-            case 'Registration_Count':
3167
-                $orderby = 'Registration_Count';
3168
-                break;
3169
-            default:
3170
-                $orderby = 'ATT_lname';
3171
-        }
3172
-        $sort         = $this->request->getRequestParam('order', 'ASC');
3173
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
3174
-        $per_page     = absint($per_page) ? $per_page : 10;
3175
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3176
-        $_where       = [];
3177
-        $search_term  = $this->request->getRequestParam('s');
3178
-        if ($search_term) {
3179
-            $search_term  = '%' . $search_term . '%';
3180
-            $_where['OR'] = [
3181
-                'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3182
-                'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3183
-                'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3184
-                'ATT_fname'                         => ['LIKE', $search_term],
3185
-                'ATT_lname'                         => ['LIKE', $search_term],
3186
-                'ATT_short_bio'                     => ['LIKE', $search_term],
3187
-                'ATT_email'                         => ['LIKE', $search_term],
3188
-                'ATT_address'                       => ['LIKE', $search_term],
3189
-                'ATT_address2'                      => ['LIKE', $search_term],
3190
-                'ATT_city'                          => ['LIKE', $search_term],
3191
-                'Country.CNT_name'                  => ['LIKE', $search_term],
3192
-                'State.STA_name'                    => ['LIKE', $search_term],
3193
-                'ATT_phone'                         => ['LIKE', $search_term],
3194
-                'Registration.REG_final_price'      => ['LIKE', $search_term],
3195
-                'Registration.REG_code'             => ['LIKE', $search_term],
3196
-                'Registration.REG_group_size'       => ['LIKE', $search_term],
3197
-            ];
3198
-        }
3199
-        $offset     = ($current_page - 1) * $per_page;
3200
-        $limit      = $count ? null : [$offset, $per_page];
3201
-        $query_args = [
3202
-            $_where,
3203
-            'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3204
-            'limit'         => $limit,
3205
-        ];
3206
-        if (! $count) {
3207
-            $query_args['order_by'] = [$orderby => $sort];
3208
-        }
3209
-        $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3210
-        return $count
3211
-            ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3212
-            : $this->getAttendeeModel()->get_all($query_args);
3213
-    }
3214
-
3215
-
3216
-    /**
3217
-     * This is just taking care of resending the registration confirmation
3218
-     *
3219
-     * @return void
3220
-     * @throws EE_Error
3221
-     * @throws InvalidArgumentException
3222
-     * @throws InvalidDataTypeException
3223
-     * @throws InvalidInterfaceException
3224
-     * @throws ReflectionException
3225
-     */
3226
-    protected function _resend_registration()
3227
-    {
3228
-        $this->_process_resend_registration();
3229
-        $REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3230
-        $redirect_to = $this->request->getRequestParam('redirect_to');
3231
-        $query_args  = $redirect_to
3232
-            ? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3233
-            : ['action' => 'default'];
3234
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3235
-    }
3236
-
3237
-
3238
-    /**
3239
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3240
-     * to use when selecting registrations
3241
-     *
3242
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3243
-     *                                                     the query parameters from the request
3244
-     * @return void ends the request with a redirect or download
3245
-     */
3246
-    public function _registrations_report_base($method_name_for_getting_query_params)
3247
-    {
3248
-        $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3249
-            ? $this->request->getRequestParam('EVT_ID', 0, 'int')
3250
-            : null;
3251
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3252
-            $request_params = $this->request->requestParams();
3253
-            wp_redirect(
3254
-                EE_Admin_Page::add_query_args_and_nonce(
3255
-                    [
3256
-                        'page'        => 'espresso_batch',
3257
-                        'batch'       => 'file',
3258
-                        'EVT_ID'      => $EVT_ID,
3259
-                        'filters'     => urlencode(
3260
-                            serialize(
3261
-                                $this->$method_name_for_getting_query_params(
3262
-                                    EEH_Array::is_set($request_params, 'filters', [])
3263
-                                )
3264
-                            )
3265
-                        ),
3266
-                        'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3267
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3268
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3269
-                    ]
3270
-                )
3271
-            );
3272
-        } else {
3273
-            // Pull the current request params
3274
-            $request_args = $this->request->requestParams();
3275
-            // Set the required request_args to be passed to the export
3276
-            $required_request_args = [
3277
-                'export' => 'report',
3278
-                'action' => 'registrations_report_for_event',
3279
-                'EVT_ID' => $EVT_ID,
3280
-            ];
3281
-            // Merge required request args, overriding any currently set
3282
-            $request_args = array_merge($request_args, $required_request_args);
3283
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3284
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3285
-                $EE_Export = EE_Export::instance($request_args);
3286
-                $EE_Export->export();
3287
-            }
3288
-        }
3289
-    }
3290
-
3291
-
3292
-    /**
3293
-     * Creates a registration report using only query parameters in the request
3294
-     *
3295
-     * @return void
3296
-     */
3297
-    public function _registrations_report()
3298
-    {
3299
-        $this->_registrations_report_base('_get_registration_query_parameters');
3300
-    }
3301
-
3302
-
3303
-    public function _contact_list_export()
3304
-    {
3305
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3306
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3307
-            $EE_Export = EE_Export::instance($this->request->requestParams());
3308
-            $EE_Export->export_attendees();
3309
-        }
3310
-    }
3311
-
3312
-
3313
-    public function _contact_list_report()
3314
-    {
3315
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3316
-            wp_redirect(
3317
-                EE_Admin_Page::add_query_args_and_nonce(
3318
-                    [
3319
-                        'page'        => 'espresso_batch',
3320
-                        'batch'       => 'file',
3321
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3322
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3323
-                    ]
3324
-                )
3325
-            );
3326
-        } else {
3327
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3328
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3329
-                $EE_Export = EE_Export::instance($this->request->requestParams());
3330
-                $EE_Export->report_attendees();
3331
-            }
3332
-        }
3333
-    }
3334
-
3335
-
3336
-
3337
-
3338
-
3339
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3340
-    /**
3341
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3342
-     *
3343
-     * @return void
3344
-     * @throws EE_Error
3345
-     * @throws InvalidArgumentException
3346
-     * @throws InvalidDataTypeException
3347
-     * @throws InvalidInterfaceException
3348
-     * @throws ReflectionException
3349
-     */
3350
-    protected function _duplicate_attendee()
3351
-    {
3352
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3353
-        $action = $this->request->getRequestParam('return', 'default');
3354
-        // verify we have necessary info
3355
-        if (! $REG_ID) {
3356
-            EE_Error::add_error(
3357
-                esc_html__(
3358
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3359
-                    'event_espresso'
3360
-                ),
3361
-                __FILE__,
3362
-                __LINE__,
3363
-                __FUNCTION__
3364
-            );
3365
-            $query_args = ['action' => $action];
3366
-            $this->_redirect_after_action('', '', '', $query_args, true);
3367
-        }
3368
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3369
-        $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3370
-        if (! $registration instanceof EE_Registration) {
3371
-            throw new RuntimeException(
3372
-                sprintf(
3373
-                    esc_html__(
3374
-                        'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3375
-                        'event_espresso'
3376
-                    ),
3377
-                    $REG_ID
3378
-                )
3379
-            );
3380
-        }
3381
-        $attendee = $registration->attendee();
3382
-        // remove relation of existing attendee on registration
3383
-        $registration->_remove_relation_to($attendee, 'Attendee');
3384
-        // new attendee
3385
-        $new_attendee = clone $attendee;
3386
-        $new_attendee->set('ATT_ID', 0);
3387
-        $new_attendee->save();
3388
-        // add new attendee to reg
3389
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3390
-        EE_Error::add_success(
3391
-            esc_html__(
3392
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3393
-                'event_espresso'
3394
-            )
3395
-        );
3396
-        // redirect to edit page for attendee
3397
-        $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3398
-        $this->_redirect_after_action('', '', '', $query_args, true);
3399
-    }
3400
-
3401
-
3402
-    /**
3403
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3404
-     *
3405
-     * @param int     $post_id
3406
-     * @param WP_POST $post
3407
-     * @throws DomainException
3408
-     * @throws EE_Error
3409
-     * @throws InvalidArgumentException
3410
-     * @throws InvalidDataTypeException
3411
-     * @throws InvalidInterfaceException
3412
-     * @throws LogicException
3413
-     * @throws InvalidFormSubmissionException
3414
-     * @throws ReflectionException
3415
-     */
3416
-    protected function _insert_update_cpt_item($post_id, $post)
3417
-    {
3418
-        $success  = true;
3419
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3420
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3421
-            : null;
3422
-        // for attendee updates
3423
-        if ($attendee instanceof EE_Attendee) {
3424
-            // note we should only be UPDATING attendees at this point.
3425
-            $fname          = $this->request->getRequestParam('ATT_fname', '');
3426
-            $lname          = $this->request->getRequestParam('ATT_lname', '');
3427
-            $updated_fields = [
3428
-                'ATT_fname'     => $fname,
3429
-                'ATT_lname'     => $lname,
3430
-                'ATT_full_name' => "{$fname} {$lname}",
3431
-                'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3432
-                'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3433
-                'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3434
-                'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3435
-                'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3436
-                'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3437
-            ];
3438
-            foreach ($updated_fields as $field => $value) {
3439
-                $attendee->set($field, $value);
3440
-            }
3441
-
3442
-            // process contact details metabox form handler (which will also save the attendee)
3443
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3444
-            $success              = $contact_details_form->process($this->request->requestParams());
3445
-
3446
-            $attendee_update_callbacks = apply_filters(
3447
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3448
-                []
3449
-            );
3450
-            foreach ($attendee_update_callbacks as $a_callback) {
3451
-                if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3452
-                    throw new EE_Error(
3453
-                        sprintf(
3454
-                            esc_html__(
3455
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3456
-                                'event_espresso'
3457
-                            ),
3458
-                            $a_callback
3459
-                        )
3460
-                    );
3461
-                }
3462
-            }
3463
-        }
3464
-
3465
-        if ($success === false) {
3466
-            EE_Error::add_error(
3467
-                esc_html__(
3468
-                    'Something went wrong with updating the meta table data for the registration.',
3469
-                    'event_espresso'
3470
-                ),
3471
-                __FILE__,
3472
-                __FUNCTION__,
3473
-                __LINE__
3474
-            );
3475
-        }
3476
-    }
3477
-
3478
-
3479
-    public function trash_cpt_item($post_id)
3480
-    {
3481
-    }
3482
-
3483
-
3484
-    public function delete_cpt_item($post_id)
3485
-    {
3486
-    }
3487
-
3488
-
3489
-    public function restore_cpt_item($post_id)
3490
-    {
3491
-    }
3492
-
3493
-
3494
-    protected function _restore_cpt_item($post_id, $revision_id)
3495
-    {
3496
-    }
3497
-
3498
-
3499
-    /**
3500
-     * @throws EE_Error
3501
-     * @throws ReflectionException
3502
-     * @since 4.10.2.p
3503
-     */
3504
-    public function attendee_editor_metaboxes()
3505
-    {
3506
-        $this->verify_cpt_object();
3507
-        remove_meta_box(
3508
-            'postexcerpt',
3509
-            $this->_cpt_routes[ $this->_req_action ],
3510
-            'normal'
3511
-        );
3512
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3513
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3514
-            $this->addMetaBox(
3515
-                'postexcerpt',
3516
-                esc_html__('Short Biography', 'event_espresso'),
3517
-                'post_excerpt_meta_box',
3518
-                $this->_cpt_routes[ $this->_req_action ]
3519
-            );
3520
-        }
3521
-        if (post_type_supports('espresso_attendees', 'comments')) {
3522
-            $this->addMetaBox(
3523
-                'commentsdiv',
3524
-                esc_html__('Notes on the Contact', 'event_espresso'),
3525
-                'post_comment_meta_box',
3526
-                $this->_cpt_routes[ $this->_req_action ],
3527
-                'normal',
3528
-                'core'
3529
-            );
3530
-        }
3531
-        $this->addMetaBox(
3532
-            'attendee_contact_info',
3533
-            esc_html__('Contact Info', 'event_espresso'),
3534
-            [$this, 'attendee_contact_info'],
3535
-            $this->_cpt_routes[ $this->_req_action ],
3536
-            'side',
3537
-            'core'
3538
-        );
3539
-        $this->addMetaBox(
3540
-            'attendee_details_address',
3541
-            esc_html__('Address Details', 'event_espresso'),
3542
-            [$this, 'attendee_address_details'],
3543
-            $this->_cpt_routes[ $this->_req_action ],
3544
-            'normal',
3545
-            'core'
3546
-        );
3547
-        $this->addMetaBox(
3548
-            'attendee_registrations',
3549
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3550
-            [$this, 'attendee_registrations_meta_box'],
3551
-            $this->_cpt_routes[ $this->_req_action ]
3552
-        );
3553
-    }
3554
-
3555
-
3556
-    /**
3557
-     * Metabox for attendee contact info
3558
-     *
3559
-     * @param WP_Post $post wp post object
3560
-     * @return void attendee contact info ( and form )
3561
-     * @throws EE_Error
3562
-     * @throws InvalidArgumentException
3563
-     * @throws InvalidDataTypeException
3564
-     * @throws InvalidInterfaceException
3565
-     * @throws LogicException
3566
-     * @throws DomainException
3567
-     */
3568
-    public function attendee_contact_info($post)
3569
-    {
3570
-        // get attendee object ( should already have it )
3571
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3572
-        $form->enqueueStylesAndScripts();
3573
-        echo $form->display(); // already escaped
3574
-    }
3575
-
3576
-
3577
-    /**
3578
-     * Return form handler for the contact details metabox
3579
-     *
3580
-     * @param EE_Attendee $attendee
3581
-     * @return AttendeeContactDetailsMetaboxFormHandler
3582
-     * @throws DomainException
3583
-     * @throws InvalidArgumentException
3584
-     * @throws InvalidDataTypeException
3585
-     * @throws InvalidInterfaceException
3586
-     */
3587
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3588
-    {
3589
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3590
-    }
3591
-
3592
-
3593
-    /**
3594
-     * Metabox for attendee details
3595
-     *
3596
-     * @param WP_Post $post wp post object
3597
-     * @throws EE_Error
3598
-     * @throws ReflectionException
3599
-     */
3600
-    public function attendee_address_details($post)
3601
-    {
3602
-        // get attendee object (should already have it)
3603
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3604
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3605
-            new EE_Question_Form_Input(
3606
-                EE_Question::new_instance(
3607
-                    [
3608
-                        'QST_ID'           => 0,
3609
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3610
-                        'QST_system'       => 'admin-state',
3611
-                    ]
3612
-                ),
3613
-                EE_Answer::new_instance(
3614
-                    [
3615
-                        'ANS_ID'    => 0,
3616
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3617
-                    ]
3618
-                ),
3619
-                [
3620
-                    'input_id'       => 'STA_ID',
3621
-                    'input_name'     => 'STA_ID',
3622
-                    'input_prefix'   => '',
3623
-                    'append_qstn_id' => false,
3624
-                ]
3625
-            )
3626
-        );
3627
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3628
-            new EE_Question_Form_Input(
3629
-                EE_Question::new_instance(
3630
-                    [
3631
-                        'QST_ID'           => 0,
3632
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3633
-                        'QST_system'       => 'admin-country',
3634
-                    ]
3635
-                ),
3636
-                EE_Answer::new_instance(
3637
-                    [
3638
-                        'ANS_ID'    => 0,
3639
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3640
-                    ]
3641
-                ),
3642
-                [
3643
-                    'input_id'       => 'CNT_ISO',
3644
-                    'input_name'     => 'CNT_ISO',
3645
-                    'input_prefix'   => '',
3646
-                    'append_qstn_id' => false,
3647
-                ]
3648
-            )
3649
-        );
3650
-        $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3651
-        EEH_Template::display_template($template, $this->_template_args);
3652
-    }
3653
-
3654
-
3655
-    /**
3656
-     * _attendee_details
3657
-     *
3658
-     * @param $post
3659
-     * @return void
3660
-     * @throws DomainException
3661
-     * @throws EE_Error
3662
-     * @throws InvalidArgumentException
3663
-     * @throws InvalidDataTypeException
3664
-     * @throws InvalidInterfaceException
3665
-     * @throws ReflectionException
3666
-     */
3667
-    public function attendee_registrations_meta_box($post)
3668
-    {
3669
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3670
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3671
-        $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3672
-        EEH_Template::display_template($template, $this->_template_args);
3673
-    }
3674
-
3675
-
3676
-    /**
3677
-     * add in the form fields for the attendee edit
3678
-     *
3679
-     * @param WP_Post $post wp post object
3680
-     * @return void echos html for new form.
3681
-     * @throws DomainException
3682
-     */
3683
-    public function after_title_form_fields($post)
3684
-    {
3685
-        if ($post->post_type === 'espresso_attendees') {
3686
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3687
-            $template_args['attendee'] = $this->_cpt_model_obj;
3688
-            EEH_Template::display_template($template, $template_args);
3689
-        }
3690
-    }
3691
-
3692
-
3693
-    /**
3694
-     * _trash_or_restore_attendee
3695
-     *
3696
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3697
-     * @return void
3698
-     * @throws EE_Error
3699
-     * @throws InvalidArgumentException
3700
-     * @throws InvalidDataTypeException
3701
-     * @throws InvalidInterfaceException
3702
-     */
3703
-    protected function _trash_or_restore_attendees($trash = true)
3704
-    {
3705
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3706
-        $status = $trash ? 'trash' : 'publish';
3707
-        // Checkboxes
3708
-        if ($this->request->requestParamIsSet('checkbox')) {
3709
-            $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3710
-            // if array has more than one element than success message should be plural
3711
-            $success = count($ATT_IDs) > 1 ? 2 : 1;
3712
-            // cycle thru checkboxes
3713
-            foreach ($ATT_IDs as $ATT_ID) {
3714
-                $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3715
-                if (! $updated) {
3716
-                    $success = 0;
3717
-                }
3718
-            }
3719
-        } else {
3720
-            // grab single id and delete
3721
-            $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3722
-            // update attendee
3723
-            $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3724
-        }
3725
-        $what        = $success > 1
3726
-            ? esc_html__('Contacts', 'event_espresso')
3727
-            : esc_html__('Contact', 'event_espresso');
3728
-        $action_desc = $trash
3729
-            ? esc_html__('moved to the trash', 'event_espresso')
3730
-            : esc_html__('restored', 'event_espresso');
3731
-        $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3732
-    }
2893
+		}
2894
+		$template_args = [
2895
+			'title'                    => '',
2896
+			'content'                  => '',
2897
+			'step_button_text'         => '',
2898
+			'show_notification_toggle' => false,
2899
+		];
2900
+		// to indicate we're processing a new registration
2901
+		$hidden_fields = [
2902
+			'processing_registration' => [
2903
+				'type'  => 'hidden',
2904
+				'value' => 0,
2905
+			],
2906
+			'event_id'                => [
2907
+				'type'  => 'hidden',
2908
+				'value' => $this->_reg_event->ID(),
2909
+			],
2910
+		];
2911
+		// if the cart is empty then we know we're at step one, so we'll display the ticket selector
2912
+		$cart = EE_Registry::instance()->SSN->cart();
2913
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2914
+		switch ($step) {
2915
+			case 'ticket':
2916
+				$hidden_fields['processing_registration']['value'] = 1;
2917
+				$template_args['title']                            = esc_html__(
2918
+					'Step One: Select the Ticket for this registration',
2919
+					'event_espresso'
2920
+				);
2921
+				$template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2922
+				$template_args['content'] .= '</div>';
2923
+				$template_args['step_button_text'] = esc_html__(
2924
+					'Add Tickets and Continue to Registrant Details',
2925
+					'event_espresso'
2926
+				);
2927
+				$template_args['show_notification_toggle']         = false;
2928
+				break;
2929
+			case 'questions':
2930
+				$hidden_fields['processing_registration']['value'] = 2;
2931
+				$template_args['title']                            = esc_html__(
2932
+					'Step Two: Add Registrant Details for this Registration',
2933
+					'event_espresso'
2934
+				);
2935
+				// in theory, we should be able to run EED_SPCO at this point
2936
+				// because the cart should have been set up properly by the first process_reg_step run.
2937
+				$template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2938
+				$template_args['step_button_text'] = esc_html__(
2939
+					'Save Registration and Continue to Details',
2940
+					'event_espresso'
2941
+				);
2942
+				$template_args['show_notification_toggle'] = true;
2943
+				break;
2944
+		}
2945
+		// we come back to the process_registration_step route.
2946
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2947
+		return EEH_Template::display_template(
2948
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2949
+			$template_args,
2950
+			true
2951
+		);
2952
+	}
2953
+
2954
+
2955
+	/**
2956
+	 * set_reg_event
2957
+	 *
2958
+	 * @return bool
2959
+	 * @throws EE_Error
2960
+	 * @throws InvalidArgumentException
2961
+	 * @throws InvalidDataTypeException
2962
+	 * @throws InvalidInterfaceException
2963
+	 */
2964
+	private function _set_reg_event()
2965
+	{
2966
+		if (is_object($this->_reg_event)) {
2967
+			return true;
2968
+		}
2969
+
2970
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2971
+		if (! $EVT_ID) {
2972
+			return false;
2973
+		}
2974
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2975
+		return true;
2976
+	}
2977
+
2978
+
2979
+	/**
2980
+	 * process_reg_step
2981
+	 *
2982
+	 * @return void
2983
+	 * @throws DomainException
2984
+	 * @throws EE_Error
2985
+	 * @throws InvalidArgumentException
2986
+	 * @throws InvalidDataTypeException
2987
+	 * @throws InvalidInterfaceException
2988
+	 * @throws ReflectionException
2989
+	 * @throws RuntimeException
2990
+	 */
2991
+	public function process_reg_step()
2992
+	{
2993
+		EE_System::do_not_cache();
2994
+		$this->_set_reg_event();
2995
+		/** @var CurrentPage $current_page */
2996
+		$current_page = $this->loader->getShared(CurrentPage::class);
2997
+		$current_page->setEspressoPage(true);
2998
+		$this->request->setRequestParam('uts', time());
2999
+		// what step are we on?
3000
+		$cart = EE_Registry::instance()->SSN->cart();
3001
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3002
+		// if doing ajax then we need to verify the nonce
3003
+		if ($this->request->isAjax()) {
3004
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
3005
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3006
+		}
3007
+		switch ($step) {
3008
+			case 'ticket':
3009
+				// process ticket selection
3010
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3011
+				if ($success) {
3012
+					EE_Error::add_success(
3013
+						esc_html__(
3014
+							'Tickets Selected. Now complete the registration.',
3015
+							'event_espresso'
3016
+						)
3017
+					);
3018
+				} else {
3019
+					$this->request->setRequestParam('step_error', true);
3020
+					$query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
3021
+				}
3022
+				if ($this->request->isAjax()) {
3023
+					$this->new_registration(); // display next step
3024
+				} else {
3025
+					$query_args = [
3026
+						'action'                  => 'new_registration',
3027
+						'processing_registration' => 1,
3028
+						'event_id'                => $this->_reg_event->ID(),
3029
+						'uts'                     => time(),
3030
+					];
3031
+					$this->_redirect_after_action(
3032
+						false,
3033
+						'',
3034
+						'',
3035
+						$query_args,
3036
+						true
3037
+					);
3038
+				}
3039
+				break;
3040
+			case 'questions':
3041
+				if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3042
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3043
+				}
3044
+				// process registration
3045
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3046
+				if ($cart instanceof EE_Cart) {
3047
+					$grand_total = $cart->get_grand_total();
3048
+					if ($grand_total instanceof EE_Line_Item) {
3049
+						$grand_total->save_this_and_descendants_to_txn();
3050
+					}
3051
+				}
3052
+				if (! $transaction instanceof EE_Transaction) {
3053
+					$query_args = [
3054
+						'action'                  => 'new_registration',
3055
+						'processing_registration' => 2,
3056
+						'event_id'                => $this->_reg_event->ID(),
3057
+						'uts'                     => time(),
3058
+					];
3059
+					if ($this->request->isAjax()) {
3060
+						// display registration form again because there are errors (maybe validation?)
3061
+						$this->new_registration();
3062
+						return;
3063
+					}
3064
+					$this->_redirect_after_action(
3065
+						false,
3066
+						'',
3067
+						'',
3068
+						$query_args,
3069
+						true
3070
+					);
3071
+					return;
3072
+				}
3073
+				// maybe update status, and make sure to save transaction if not done already
3074
+				if (! $transaction->update_status_based_on_total_paid()) {
3075
+					$transaction->save();
3076
+				}
3077
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3078
+				$query_args = [
3079
+					'action'        => 'redirect_to_txn',
3080
+					'TXN_ID'        => $transaction->ID(),
3081
+					'EVT_ID'        => $this->_reg_event->ID(),
3082
+					'event_name'    => urlencode($this->_reg_event->name()),
3083
+					'redirect_from' => 'new_registration',
3084
+				];
3085
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3086
+				break;
3087
+		}
3088
+		// what are you looking here for?  Should be nothing to do at this point.
3089
+	}
3090
+
3091
+
3092
+	/**
3093
+	 * redirect_to_txn
3094
+	 *
3095
+	 * @return void
3096
+	 * @throws EE_Error
3097
+	 * @throws InvalidArgumentException
3098
+	 * @throws InvalidDataTypeException
3099
+	 * @throws InvalidInterfaceException
3100
+	 * @throws ReflectionException
3101
+	 */
3102
+	public function redirect_to_txn()
3103
+	{
3104
+		EE_System::do_not_cache();
3105
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3106
+		$query_args = [
3107
+			'action' => 'view_transaction',
3108
+			'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3109
+			'page'   => 'espresso_transactions',
3110
+		];
3111
+		if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3112
+			$query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3113
+			$query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3114
+			$query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3115
+		}
3116
+		EE_Error::add_success(
3117
+			esc_html__(
3118
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3119
+				'event_espresso'
3120
+			)
3121
+		);
3122
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3123
+	}
3124
+
3125
+
3126
+	/**
3127
+	 * generates HTML for the Attendee Contact List
3128
+	 *
3129
+	 * @return void
3130
+	 * @throws DomainException
3131
+	 * @throws EE_Error
3132
+	 */
3133
+	protected function _attendee_contact_list_table()
3134
+	{
3135
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3136
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3137
+		$this->display_admin_list_table_page_with_no_sidebar();
3138
+	}
3139
+
3140
+
3141
+	/**
3142
+	 * get_attendees
3143
+	 *
3144
+	 * @param      $per_page
3145
+	 * @param bool $count whether to return count or data.
3146
+	 * @param bool $trash
3147
+	 * @return array|int
3148
+	 * @throws EE_Error
3149
+	 * @throws InvalidArgumentException
3150
+	 * @throws InvalidDataTypeException
3151
+	 * @throws InvalidInterfaceException
3152
+	 */
3153
+	public function get_attendees($per_page, $count = false, $trash = false)
3154
+	{
3155
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3156
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3157
+		$orderby = $this->request->getRequestParam('orderby');
3158
+		switch ($orderby) {
3159
+			case 'ATT_ID':
3160
+			case 'ATT_fname':
3161
+			case 'ATT_email':
3162
+			case 'ATT_city':
3163
+			case 'STA_ID':
3164
+			case 'CNT_ID':
3165
+				break;
3166
+			case 'Registration_Count':
3167
+				$orderby = 'Registration_Count';
3168
+				break;
3169
+			default:
3170
+				$orderby = 'ATT_lname';
3171
+		}
3172
+		$sort         = $this->request->getRequestParam('order', 'ASC');
3173
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
3174
+		$per_page     = absint($per_page) ? $per_page : 10;
3175
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3176
+		$_where       = [];
3177
+		$search_term  = $this->request->getRequestParam('s');
3178
+		if ($search_term) {
3179
+			$search_term  = '%' . $search_term . '%';
3180
+			$_where['OR'] = [
3181
+				'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3182
+				'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3183
+				'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3184
+				'ATT_fname'                         => ['LIKE', $search_term],
3185
+				'ATT_lname'                         => ['LIKE', $search_term],
3186
+				'ATT_short_bio'                     => ['LIKE', $search_term],
3187
+				'ATT_email'                         => ['LIKE', $search_term],
3188
+				'ATT_address'                       => ['LIKE', $search_term],
3189
+				'ATT_address2'                      => ['LIKE', $search_term],
3190
+				'ATT_city'                          => ['LIKE', $search_term],
3191
+				'Country.CNT_name'                  => ['LIKE', $search_term],
3192
+				'State.STA_name'                    => ['LIKE', $search_term],
3193
+				'ATT_phone'                         => ['LIKE', $search_term],
3194
+				'Registration.REG_final_price'      => ['LIKE', $search_term],
3195
+				'Registration.REG_code'             => ['LIKE', $search_term],
3196
+				'Registration.REG_group_size'       => ['LIKE', $search_term],
3197
+			];
3198
+		}
3199
+		$offset     = ($current_page - 1) * $per_page;
3200
+		$limit      = $count ? null : [$offset, $per_page];
3201
+		$query_args = [
3202
+			$_where,
3203
+			'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3204
+			'limit'         => $limit,
3205
+		];
3206
+		if (! $count) {
3207
+			$query_args['order_by'] = [$orderby => $sort];
3208
+		}
3209
+		$query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3210
+		return $count
3211
+			? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3212
+			: $this->getAttendeeModel()->get_all($query_args);
3213
+	}
3214
+
3215
+
3216
+	/**
3217
+	 * This is just taking care of resending the registration confirmation
3218
+	 *
3219
+	 * @return void
3220
+	 * @throws EE_Error
3221
+	 * @throws InvalidArgumentException
3222
+	 * @throws InvalidDataTypeException
3223
+	 * @throws InvalidInterfaceException
3224
+	 * @throws ReflectionException
3225
+	 */
3226
+	protected function _resend_registration()
3227
+	{
3228
+		$this->_process_resend_registration();
3229
+		$REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3230
+		$redirect_to = $this->request->getRequestParam('redirect_to');
3231
+		$query_args  = $redirect_to
3232
+			? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3233
+			: ['action' => 'default'];
3234
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3235
+	}
3236
+
3237
+
3238
+	/**
3239
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3240
+	 * to use when selecting registrations
3241
+	 *
3242
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3243
+	 *                                                     the query parameters from the request
3244
+	 * @return void ends the request with a redirect or download
3245
+	 */
3246
+	public function _registrations_report_base($method_name_for_getting_query_params)
3247
+	{
3248
+		$EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3249
+			? $this->request->getRequestParam('EVT_ID', 0, 'int')
3250
+			: null;
3251
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3252
+			$request_params = $this->request->requestParams();
3253
+			wp_redirect(
3254
+				EE_Admin_Page::add_query_args_and_nonce(
3255
+					[
3256
+						'page'        => 'espresso_batch',
3257
+						'batch'       => 'file',
3258
+						'EVT_ID'      => $EVT_ID,
3259
+						'filters'     => urlencode(
3260
+							serialize(
3261
+								$this->$method_name_for_getting_query_params(
3262
+									EEH_Array::is_set($request_params, 'filters', [])
3263
+								)
3264
+							)
3265
+						),
3266
+						'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false),
3267
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3268
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3269
+					]
3270
+				)
3271
+			);
3272
+		} else {
3273
+			// Pull the current request params
3274
+			$request_args = $this->request->requestParams();
3275
+			// Set the required request_args to be passed to the export
3276
+			$required_request_args = [
3277
+				'export' => 'report',
3278
+				'action' => 'registrations_report_for_event',
3279
+				'EVT_ID' => $EVT_ID,
3280
+			];
3281
+			// Merge required request args, overriding any currently set
3282
+			$request_args = array_merge($request_args, $required_request_args);
3283
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3284
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3285
+				$EE_Export = EE_Export::instance($request_args);
3286
+				$EE_Export->export();
3287
+			}
3288
+		}
3289
+	}
3290
+
3291
+
3292
+	/**
3293
+	 * Creates a registration report using only query parameters in the request
3294
+	 *
3295
+	 * @return void
3296
+	 */
3297
+	public function _registrations_report()
3298
+	{
3299
+		$this->_registrations_report_base('_get_registration_query_parameters');
3300
+	}
3301
+
3302
+
3303
+	public function _contact_list_export()
3304
+	{
3305
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3306
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3307
+			$EE_Export = EE_Export::instance($this->request->requestParams());
3308
+			$EE_Export->export_attendees();
3309
+		}
3310
+	}
3311
+
3312
+
3313
+	public function _contact_list_report()
3314
+	{
3315
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3316
+			wp_redirect(
3317
+				EE_Admin_Page::add_query_args_and_nonce(
3318
+					[
3319
+						'page'        => 'espresso_batch',
3320
+						'batch'       => 'file',
3321
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3322
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', 'url')),
3323
+					]
3324
+				)
3325
+			);
3326
+		} else {
3327
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3328
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3329
+				$EE_Export = EE_Export::instance($this->request->requestParams());
3330
+				$EE_Export->report_attendees();
3331
+			}
3332
+		}
3333
+	}
3334
+
3335
+
3336
+
3337
+
3338
+
3339
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3340
+	/**
3341
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3342
+	 *
3343
+	 * @return void
3344
+	 * @throws EE_Error
3345
+	 * @throws InvalidArgumentException
3346
+	 * @throws InvalidDataTypeException
3347
+	 * @throws InvalidInterfaceException
3348
+	 * @throws ReflectionException
3349
+	 */
3350
+	protected function _duplicate_attendee()
3351
+	{
3352
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3353
+		$action = $this->request->getRequestParam('return', 'default');
3354
+		// verify we have necessary info
3355
+		if (! $REG_ID) {
3356
+			EE_Error::add_error(
3357
+				esc_html__(
3358
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3359
+					'event_espresso'
3360
+				),
3361
+				__FILE__,
3362
+				__LINE__,
3363
+				__FUNCTION__
3364
+			);
3365
+			$query_args = ['action' => $action];
3366
+			$this->_redirect_after_action('', '', '', $query_args, true);
3367
+		}
3368
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3369
+		$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3370
+		if (! $registration instanceof EE_Registration) {
3371
+			throw new RuntimeException(
3372
+				sprintf(
3373
+					esc_html__(
3374
+						'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3375
+						'event_espresso'
3376
+					),
3377
+					$REG_ID
3378
+				)
3379
+			);
3380
+		}
3381
+		$attendee = $registration->attendee();
3382
+		// remove relation of existing attendee on registration
3383
+		$registration->_remove_relation_to($attendee, 'Attendee');
3384
+		// new attendee
3385
+		$new_attendee = clone $attendee;
3386
+		$new_attendee->set('ATT_ID', 0);
3387
+		$new_attendee->save();
3388
+		// add new attendee to reg
3389
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3390
+		EE_Error::add_success(
3391
+			esc_html__(
3392
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3393
+				'event_espresso'
3394
+			)
3395
+		);
3396
+		// redirect to edit page for attendee
3397
+		$query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3398
+		$this->_redirect_after_action('', '', '', $query_args, true);
3399
+	}
3400
+
3401
+
3402
+	/**
3403
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3404
+	 *
3405
+	 * @param int     $post_id
3406
+	 * @param WP_POST $post
3407
+	 * @throws DomainException
3408
+	 * @throws EE_Error
3409
+	 * @throws InvalidArgumentException
3410
+	 * @throws InvalidDataTypeException
3411
+	 * @throws InvalidInterfaceException
3412
+	 * @throws LogicException
3413
+	 * @throws InvalidFormSubmissionException
3414
+	 * @throws ReflectionException
3415
+	 */
3416
+	protected function _insert_update_cpt_item($post_id, $post)
3417
+	{
3418
+		$success  = true;
3419
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3420
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3421
+			: null;
3422
+		// for attendee updates
3423
+		if ($attendee instanceof EE_Attendee) {
3424
+			// note we should only be UPDATING attendees at this point.
3425
+			$fname          = $this->request->getRequestParam('ATT_fname', '');
3426
+			$lname          = $this->request->getRequestParam('ATT_lname', '');
3427
+			$updated_fields = [
3428
+				'ATT_fname'     => $fname,
3429
+				'ATT_lname'     => $lname,
3430
+				'ATT_full_name' => "{$fname} {$lname}",
3431
+				'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3432
+				'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3433
+				'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3434
+				'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3435
+				'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3436
+				'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3437
+			];
3438
+			foreach ($updated_fields as $field => $value) {
3439
+				$attendee->set($field, $value);
3440
+			}
3441
+
3442
+			// process contact details metabox form handler (which will also save the attendee)
3443
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3444
+			$success              = $contact_details_form->process($this->request->requestParams());
3445
+
3446
+			$attendee_update_callbacks = apply_filters(
3447
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3448
+				[]
3449
+			);
3450
+			foreach ($attendee_update_callbacks as $a_callback) {
3451
+				if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3452
+					throw new EE_Error(
3453
+						sprintf(
3454
+							esc_html__(
3455
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3456
+								'event_espresso'
3457
+							),
3458
+							$a_callback
3459
+						)
3460
+					);
3461
+				}
3462
+			}
3463
+		}
3464
+
3465
+		if ($success === false) {
3466
+			EE_Error::add_error(
3467
+				esc_html__(
3468
+					'Something went wrong with updating the meta table data for the registration.',
3469
+					'event_espresso'
3470
+				),
3471
+				__FILE__,
3472
+				__FUNCTION__,
3473
+				__LINE__
3474
+			);
3475
+		}
3476
+	}
3477
+
3478
+
3479
+	public function trash_cpt_item($post_id)
3480
+	{
3481
+	}
3482
+
3483
+
3484
+	public function delete_cpt_item($post_id)
3485
+	{
3486
+	}
3487
+
3488
+
3489
+	public function restore_cpt_item($post_id)
3490
+	{
3491
+	}
3492
+
3493
+
3494
+	protected function _restore_cpt_item($post_id, $revision_id)
3495
+	{
3496
+	}
3497
+
3498
+
3499
+	/**
3500
+	 * @throws EE_Error
3501
+	 * @throws ReflectionException
3502
+	 * @since 4.10.2.p
3503
+	 */
3504
+	public function attendee_editor_metaboxes()
3505
+	{
3506
+		$this->verify_cpt_object();
3507
+		remove_meta_box(
3508
+			'postexcerpt',
3509
+			$this->_cpt_routes[ $this->_req_action ],
3510
+			'normal'
3511
+		);
3512
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3513
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3514
+			$this->addMetaBox(
3515
+				'postexcerpt',
3516
+				esc_html__('Short Biography', 'event_espresso'),
3517
+				'post_excerpt_meta_box',
3518
+				$this->_cpt_routes[ $this->_req_action ]
3519
+			);
3520
+		}
3521
+		if (post_type_supports('espresso_attendees', 'comments')) {
3522
+			$this->addMetaBox(
3523
+				'commentsdiv',
3524
+				esc_html__('Notes on the Contact', 'event_espresso'),
3525
+				'post_comment_meta_box',
3526
+				$this->_cpt_routes[ $this->_req_action ],
3527
+				'normal',
3528
+				'core'
3529
+			);
3530
+		}
3531
+		$this->addMetaBox(
3532
+			'attendee_contact_info',
3533
+			esc_html__('Contact Info', 'event_espresso'),
3534
+			[$this, 'attendee_contact_info'],
3535
+			$this->_cpt_routes[ $this->_req_action ],
3536
+			'side',
3537
+			'core'
3538
+		);
3539
+		$this->addMetaBox(
3540
+			'attendee_details_address',
3541
+			esc_html__('Address Details', 'event_espresso'),
3542
+			[$this, 'attendee_address_details'],
3543
+			$this->_cpt_routes[ $this->_req_action ],
3544
+			'normal',
3545
+			'core'
3546
+		);
3547
+		$this->addMetaBox(
3548
+			'attendee_registrations',
3549
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3550
+			[$this, 'attendee_registrations_meta_box'],
3551
+			$this->_cpt_routes[ $this->_req_action ]
3552
+		);
3553
+	}
3554
+
3555
+
3556
+	/**
3557
+	 * Metabox for attendee contact info
3558
+	 *
3559
+	 * @param WP_Post $post wp post object
3560
+	 * @return void attendee contact info ( and form )
3561
+	 * @throws EE_Error
3562
+	 * @throws InvalidArgumentException
3563
+	 * @throws InvalidDataTypeException
3564
+	 * @throws InvalidInterfaceException
3565
+	 * @throws LogicException
3566
+	 * @throws DomainException
3567
+	 */
3568
+	public function attendee_contact_info($post)
3569
+	{
3570
+		// get attendee object ( should already have it )
3571
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3572
+		$form->enqueueStylesAndScripts();
3573
+		echo $form->display(); // already escaped
3574
+	}
3575
+
3576
+
3577
+	/**
3578
+	 * Return form handler for the contact details metabox
3579
+	 *
3580
+	 * @param EE_Attendee $attendee
3581
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3582
+	 * @throws DomainException
3583
+	 * @throws InvalidArgumentException
3584
+	 * @throws InvalidDataTypeException
3585
+	 * @throws InvalidInterfaceException
3586
+	 */
3587
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3588
+	{
3589
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3590
+	}
3591
+
3592
+
3593
+	/**
3594
+	 * Metabox for attendee details
3595
+	 *
3596
+	 * @param WP_Post $post wp post object
3597
+	 * @throws EE_Error
3598
+	 * @throws ReflectionException
3599
+	 */
3600
+	public function attendee_address_details($post)
3601
+	{
3602
+		// get attendee object (should already have it)
3603
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3604
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3605
+			new EE_Question_Form_Input(
3606
+				EE_Question::new_instance(
3607
+					[
3608
+						'QST_ID'           => 0,
3609
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3610
+						'QST_system'       => 'admin-state',
3611
+					]
3612
+				),
3613
+				EE_Answer::new_instance(
3614
+					[
3615
+						'ANS_ID'    => 0,
3616
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3617
+					]
3618
+				),
3619
+				[
3620
+					'input_id'       => 'STA_ID',
3621
+					'input_name'     => 'STA_ID',
3622
+					'input_prefix'   => '',
3623
+					'append_qstn_id' => false,
3624
+				]
3625
+			)
3626
+		);
3627
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3628
+			new EE_Question_Form_Input(
3629
+				EE_Question::new_instance(
3630
+					[
3631
+						'QST_ID'           => 0,
3632
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3633
+						'QST_system'       => 'admin-country',
3634
+					]
3635
+				),
3636
+				EE_Answer::new_instance(
3637
+					[
3638
+						'ANS_ID'    => 0,
3639
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3640
+					]
3641
+				),
3642
+				[
3643
+					'input_id'       => 'CNT_ISO',
3644
+					'input_name'     => 'CNT_ISO',
3645
+					'input_prefix'   => '',
3646
+					'append_qstn_id' => false,
3647
+				]
3648
+			)
3649
+		);
3650
+		$template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3651
+		EEH_Template::display_template($template, $this->_template_args);
3652
+	}
3653
+
3654
+
3655
+	/**
3656
+	 * _attendee_details
3657
+	 *
3658
+	 * @param $post
3659
+	 * @return void
3660
+	 * @throws DomainException
3661
+	 * @throws EE_Error
3662
+	 * @throws InvalidArgumentException
3663
+	 * @throws InvalidDataTypeException
3664
+	 * @throws InvalidInterfaceException
3665
+	 * @throws ReflectionException
3666
+	 */
3667
+	public function attendee_registrations_meta_box($post)
3668
+	{
3669
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3670
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3671
+		$template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3672
+		EEH_Template::display_template($template, $this->_template_args);
3673
+	}
3674
+
3675
+
3676
+	/**
3677
+	 * add in the form fields for the attendee edit
3678
+	 *
3679
+	 * @param WP_Post $post wp post object
3680
+	 * @return void echos html for new form.
3681
+	 * @throws DomainException
3682
+	 */
3683
+	public function after_title_form_fields($post)
3684
+	{
3685
+		if ($post->post_type === 'espresso_attendees') {
3686
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3687
+			$template_args['attendee'] = $this->_cpt_model_obj;
3688
+			EEH_Template::display_template($template, $template_args);
3689
+		}
3690
+	}
3691
+
3692
+
3693
+	/**
3694
+	 * _trash_or_restore_attendee
3695
+	 *
3696
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3697
+	 * @return void
3698
+	 * @throws EE_Error
3699
+	 * @throws InvalidArgumentException
3700
+	 * @throws InvalidDataTypeException
3701
+	 * @throws InvalidInterfaceException
3702
+	 */
3703
+	protected function _trash_or_restore_attendees($trash = true)
3704
+	{
3705
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3706
+		$status = $trash ? 'trash' : 'publish';
3707
+		// Checkboxes
3708
+		if ($this->request->requestParamIsSet('checkbox')) {
3709
+			$ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3710
+			// if array has more than one element than success message should be plural
3711
+			$success = count($ATT_IDs) > 1 ? 2 : 1;
3712
+			// cycle thru checkboxes
3713
+			foreach ($ATT_IDs as $ATT_ID) {
3714
+				$updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3715
+				if (! $updated) {
3716
+					$success = 0;
3717
+				}
3718
+			}
3719
+		} else {
3720
+			// grab single id and delete
3721
+			$ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3722
+			// update attendee
3723
+			$success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3724
+		}
3725
+		$what        = $success > 1
3726
+			? esc_html__('Contacts', 'event_espresso')
3727
+			: esc_html__('Contact', 'event_espresso');
3728
+		$action_desc = $trash
3729
+			? esc_html__('moved to the trash', 'event_espresso')
3730
+			: esc_html__('restored', 'event_espresso');
3731
+		$this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3732
+	}
3733 3733
 }
Please login to merge, or discard this patch.
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      */
93 93
     protected function getRegistrationModel()
94 94
     {
95
-        if (! $this->registration_model instanceof EEM_Registration) {
95
+        if ( ! $this->registration_model instanceof EEM_Registration) {
96 96
             $this->registration_model = $this->loader->getShared('EEM_Registration');
97 97
         }
98 98
         return $this->registration_model;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     protected function getAttendeeModel()
110 110
     {
111
-        if (! $this->attendee_model instanceof EEM_Attendee) {
111
+        if ( ! $this->attendee_model instanceof EEM_Attendee) {
112 112
             $this->attendee_model = $this->loader->getShared('EEM_Attendee');
113 113
         }
114 114
         return $this->attendee_model;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     protected function getEventModel()
126 126
     {
127
-        if (! $this->event_model instanceof EEM_Event) {
127
+        if ( ! $this->event_model instanceof EEM_Event) {
128 128
             $this->event_model = $this->loader->getShared('EEM_Event');
129 129
         }
130 130
         return $this->event_model;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     protected function getStatusModel()
142 142
     {
143
-        if (! $this->status_model instanceof EEM_Status) {
143
+        if ( ! $this->status_model instanceof EEM_Status) {
144 144
             $this->status_model = $this->loader->getShared('EEM_Status');
145 145
         }
146 146
         return $this->status_model;
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
         // style
760 760
         wp_register_style(
761 761
             'espresso_reg',
762
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
762
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
763 763
             ['ee-admin-css'],
764 764
             EVENT_ESPRESSO_VERSION
765 765
         );
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
         // script
768 768
         wp_register_script(
769 769
             'espresso_reg',
770
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
770
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
771 771
             ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
772 772
             EVENT_ESPRESSO_VERSION,
773 773
             true
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
             'att_publish_text' => sprintf(
792 792
             /* translators: The date and time */
793 793
                 wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
794
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
794
+                '<b>'.$this->_cpt_model_obj->get_datetime('ATT_created').'</b>'
795 795
             ),
796 796
         ];
797 797
         wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
         wp_dequeue_style('espresso_reg');
823 823
         wp_register_style(
824 824
             'espresso_att',
825
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
825
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
826 826
             ['ee-admin-css'],
827 827
             EVENT_ESPRESSO_VERSION
828 828
         );
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
     {
835 835
         wp_register_script(
836 836
             'ee-spco-for-admin',
837
-            REG_ASSETS_URL . 'spco_for_admin.js',
837
+            REG_ASSETS_URL.'spco_for_admin.js',
838 838
             ['underscore', 'jquery'],
839 839
             EVENT_ESPRESSO_VERSION,
840 840
             true
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
             'no_approve_registrations' => 'not_approved_registration',
883 883
             'cancel_registrations'     => 'cancelled_registration',
884 884
         ];
885
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
885
+        $can_send = EE_Registry::instance()->CAP->current_user_can(
886 886
             'ee_send_message',
887 887
             'batch_send_messages'
888 888
         );
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
988 988
                 ],
989 989
             ];
990
-            $this->_views['trash']      = [
990
+            $this->_views['trash'] = [
991 991
                 'slug'        => 'trash',
992 992
                 'label'       => esc_html__('Trash', 'event_espresso'),
993 993
                 'count'       => 0,
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
         }
1088 1088
         $sc_items = [
1089 1089
             'approved_status'   => [
1090
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1090
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_approved,
1091 1091
                 'desc'  => EEH_Template::pretty_status(
1092 1092
                     EEM_Registration::status_id_approved,
1093 1093
                     false,
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
                 ),
1096 1096
             ],
1097 1097
             'pending_status'    => [
1098
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1098
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_pending_payment,
1099 1099
                 'desc'  => EEH_Template::pretty_status(
1100 1100
                     EEM_Registration::status_id_pending_payment,
1101 1101
                     false,
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
                 ),
1104 1104
             ],
1105 1105
             'wait_list'         => [
1106
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1106
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_wait_list,
1107 1107
                 'desc'  => EEH_Template::pretty_status(
1108 1108
                     EEM_Registration::status_id_wait_list,
1109 1109
                     false,
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
                 ),
1112 1112
             ],
1113 1113
             'incomplete_status' => [
1114
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1114
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_incomplete,
1115 1115
                 'desc'  => EEH_Template::pretty_status(
1116 1116
                     EEM_Registration::status_id_incomplete,
1117 1117
                     false,
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
                 ),
1120 1120
             ],
1121 1121
             'not_approved'      => [
1122
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1122
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_not_approved,
1123 1123
                 'desc'  => EEH_Template::pretty_status(
1124 1124
                     EEM_Registration::status_id_not_approved,
1125 1125
                     false,
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
                 ),
1128 1128
             ],
1129 1129
             'declined_status'   => [
1130
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1130
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_declined,
1131 1131
                 'desc'  => EEH_Template::pretty_status(
1132 1132
                     EEM_Registration::status_id_declined,
1133 1133
                     false,
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
                 ),
1136 1136
             ],
1137 1137
             'cancelled_status'  => [
1138
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1138
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_cancelled,
1139 1139
                 'desc'  => EEH_Template::pretty_status(
1140 1140
                     EEM_Registration::status_id_cancelled,
1141 1141
                     false,
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
                 $EVT_ID
1196 1196
             )
1197 1197
         ) {
1198
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1198
+            $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1199 1199
                 'new_registration',
1200 1200
                 'add-registrant',
1201 1201
                 ['event_id' => $EVT_ID],
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
                 ],
1354 1354
                 REG_ADMIN_URL
1355 1355
             );
1356
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1356
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1357 1357
                 [
1358 1358
                     'action' => 'default',
1359 1359
                     'EVT_ID' => $event_id,
@@ -1361,7 +1361,7 @@  discard block
 block discarded – undo
1361 1361
                 ],
1362 1362
                 admin_url('admin.php')
1363 1363
             );
1364
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1364
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1365 1365
                 [
1366 1366
                     'page'   => 'espresso_events',
1367 1367
                     'action' => 'edit',
@@ -1370,12 +1370,12 @@  discard block
 block discarded – undo
1370 1370
                 admin_url('admin.php')
1371 1371
             );
1372 1372
             // next and previous links
1373
-            $next_reg                                      = $this->_registration->next(
1373
+            $next_reg = $this->_registration->next(
1374 1374
                 null,
1375 1375
                 [],
1376 1376
                 'REG_ID'
1377 1377
             );
1378
-            $this->_template_args['next_registration']     = $next_reg
1378
+            $this->_template_args['next_registration'] = $next_reg
1379 1379
                 ? $this->_next_link(
1380 1380
                     EE_Admin_Page::add_query_args_and_nonce(
1381 1381
                         [
@@ -1387,7 +1387,7 @@  discard block
 block discarded – undo
1387 1387
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1388 1388
                 )
1389 1389
                 : '';
1390
-            $previous_reg                                  = $this->_registration->previous(
1390
+            $previous_reg = $this->_registration->previous(
1391 1391
                 null,
1392 1392
                 [],
1393 1393
                 'REG_ID'
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
                 )
1406 1406
                 : '';
1407 1407
             // grab header
1408
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1408
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1409 1409
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1410 1410
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1411 1411
                 $template_path,
@@ -1442,7 +1442,7 @@  discard block
 block discarded – undo
1442 1442
         );
1443 1443
         $this->addMetaBox(
1444 1444
             'edit-reg-details-mbox',
1445
-            '<span>' . esc_html__('Registration Details', 'event_espresso')
1445
+            '<span>'.esc_html__('Registration Details', 'event_espresso')
1446 1446
             . '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1447 1447
             [$this, '_reg_details_meta_box'],
1448 1448
             $this->_wp_page_slug
@@ -1552,7 +1552,7 @@  discard block
 block discarded – undo
1552 1552
                                 EEH_HTML::strong(
1553 1553
                                     $this->_registration->pretty_status(),
1554 1554
                                     '',
1555
-                                    'status-' . $this->_registration->status_ID(),
1555
+                                    'status-'.$this->_registration->status_ID(),
1556 1556
                                     'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1557 1557
                                 )
1558 1558
                             )
@@ -1568,7 +1568,7 @@  discard block
 block discarded – undo
1568 1568
                 $this->_registration->ID()
1569 1569
             )
1570 1570
         ) {
1571
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1571
+            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1572 1572
                 $this->_get_reg_statuses(),
1573 1573
                 [
1574 1574
                     'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
@@ -1585,7 +1585,7 @@  discard block
 block discarded – undo
1585 1585
                     ),
1586 1586
                 ]
1587 1587
             );
1588
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1588
+            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1589 1589
                 [
1590 1590
                     'html_class'      => 'button--primary',
1591 1591
                     'html_label_text' => '&nbsp;',
@@ -1610,7 +1610,7 @@  discard block
 block discarded – undo
1610 1610
     protected function _get_reg_statuses()
1611 1611
     {
1612 1612
         $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1613
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1613
+        unset($reg_status_array[EEM_Registration::status_id_incomplete]);
1614 1614
         // get current reg status
1615 1615
         $current_status = $this->_registration->status_ID();
1616 1616
         // is registration for free event? This will determine whether to display the pending payment option
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
             $current_status !== EEM_Registration::status_id_pending_payment
1619 1619
             && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1620 1620
         ) {
1621
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1621
+            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1622 1622
         }
1623 1623
         return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1624 1624
     }
@@ -1709,7 +1709,7 @@  discard block
 block discarded – undo
1709 1709
         $success = false;
1710 1710
         // typecast $REG_IDs
1711 1711
         $REG_IDs = (array) $REG_IDs;
1712
-        if (! empty($REG_IDs)) {
1712
+        if ( ! empty($REG_IDs)) {
1713 1713
             $success = true;
1714 1714
             // set default status if none is passed
1715 1715
             $status         = $status ?: EEM_Registration::status_id_pending_payment;
@@ -1869,7 +1869,7 @@  discard block
 block discarded – undo
1869 1869
             $action,
1870 1870
             $notify
1871 1871
         );
1872
-        $method = $action . '_registration';
1872
+        $method = $action.'_registration';
1873 1873
         if (method_exists($this, $method)) {
1874 1874
             $this->$method($notify);
1875 1875
         }
@@ -2019,7 +2019,7 @@  discard block
 block discarded – undo
2019 2019
         $filters        = new EE_Line_Item_Filter_Collection();
2020 2020
         $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2021 2021
         $filters->add(new EE_Non_Zero_Line_Item_Filter());
2022
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
2022
+        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2023 2023
             $filters,
2024 2024
             $transaction->total_line_item()
2025 2025
         );
@@ -2032,7 +2032,7 @@  discard block
 block discarded – undo
2032 2032
             $filtered_line_item_tree,
2033 2033
             ['EE_Registration' => $this->_registration]
2034 2034
         );
2035
-        $attendee                                = $this->_registration->attendee();
2035
+        $attendee = $this->_registration->attendee();
2036 2036
         if (
2037 2037
             EE_Registry::instance()->CAP->current_user_can(
2038 2038
                 'ee_read_transaction',
@@ -2114,7 +2114,7 @@  discard block
 block discarded – undo
2114 2114
                 'Payment method response',
2115 2115
                 'event_espresso'
2116 2116
             );
2117
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2117
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2118 2118
         }
2119 2119
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2120 2120
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2145,7 +2145,7 @@  discard block
 block discarded – undo
2145 2145
         $this->_template_args['REG_ID'] = $this->_registration->ID();
2146 2146
         $this->_template_args['event_id'] = $this->_registration->event_ID();
2147 2147
 
2148
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2148
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2149 2149
         EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2150 2150
     }
2151 2151
 
@@ -2184,7 +2184,7 @@  discard block
 block discarded – undo
2184 2184
 
2185 2185
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2186 2186
             $this->_template_args['REG_ID'] = $this->_registration->ID();
2187
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2187
+            $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2188 2188
             EEH_Template::display_template($template_path, $this->_template_args);
2189 2189
         }
2190 2190
     }
@@ -2200,7 +2200,7 @@  discard block
 block discarded – undo
2200 2200
     public function form_before_question_group($output)
2201 2201
     {
2202 2202
         EE_Error::doing_it_wrong(
2203
-            __CLASS__ . '::' . __FUNCTION__,
2203
+            __CLASS__.'::'.__FUNCTION__,
2204 2204
             esc_html__(
2205 2205
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2206 2206
                 'event_espresso'
@@ -2224,7 +2224,7 @@  discard block
 block discarded – undo
2224 2224
     public function form_after_question_group($output)
2225 2225
     {
2226 2226
         EE_Error::doing_it_wrong(
2227
-            __CLASS__ . '::' . __FUNCTION__,
2227
+            __CLASS__.'::'.__FUNCTION__,
2228 2228
             esc_html__(
2229 2229
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2230 2230
                 'event_espresso'
@@ -2261,7 +2261,7 @@  discard block
 block discarded – undo
2261 2261
     public function form_form_field_label_wrap($label)
2262 2262
     {
2263 2263
         EE_Error::doing_it_wrong(
2264
-            __CLASS__ . '::' . __FUNCTION__,
2264
+            __CLASS__.'::'.__FUNCTION__,
2265 2265
             esc_html__(
2266 2266
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2267 2267
                 'event_espresso'
@@ -2271,7 +2271,7 @@  discard block
 block discarded – undo
2271 2271
         return '
2272 2272
 			<tr>
2273 2273
 				<th>
2274
-					' . $label . '
2274
+					' . $label.'
2275 2275
 				</th>';
2276 2276
     }
2277 2277
 
@@ -2286,7 +2286,7 @@  discard block
 block discarded – undo
2286 2286
     public function form_form_field_input__wrap($input)
2287 2287
     {
2288 2288
         EE_Error::doing_it_wrong(
2289
-            __CLASS__ . '::' . __FUNCTION__,
2289
+            __CLASS__.'::'.__FUNCTION__,
2290 2290
             esc_html__(
2291 2291
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2292 2292
                 'event_espresso'
@@ -2295,7 +2295,7 @@  discard block
 block discarded – undo
2295 2295
         );
2296 2296
         return '
2297 2297
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2298
-					' . $input . '
2298
+					' . $input.'
2299 2299
 				</td>
2300 2300
 			</tr>';
2301 2301
     }
@@ -2344,8 +2344,8 @@  discard block
 block discarded – undo
2344 2344
      */
2345 2345
     protected function _get_reg_custom_questions_form($REG_ID)
2346 2346
     {
2347
-        if (! $this->_reg_custom_questions_form) {
2348
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2347
+        if ( ! $this->_reg_custom_questions_form) {
2348
+            require_once(REG_ADMIN.'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2349 2349
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2350 2350
                 $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2351 2351
             );
@@ -2368,7 +2368,7 @@  discard block
 block discarded – undo
2368 2368
      */
2369 2369
     private function _save_reg_custom_questions_form($REG_ID = 0)
2370 2370
     {
2371
-        if (! $REG_ID) {
2371
+        if ( ! $REG_ID) {
2372 2372
             EE_Error::add_error(
2373 2373
                 esc_html__(
2374 2374
                     'An error occurred. No registration ID was received.',
@@ -2385,7 +2385,7 @@  discard block
 block discarded – undo
2385 2385
         if ($form->is_valid()) {
2386 2386
             foreach ($form->subforms() as $question_group_form) {
2387 2387
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2388
-                    $where_conditions    = [
2388
+                    $where_conditions = [
2389 2389
                         'QST_ID' => $question_id,
2390 2390
                         'REG_ID' => $REG_ID,
2391 2391
                     ];
@@ -2426,7 +2426,7 @@  discard block
 block discarded – undo
2426 2426
         $REG = $this->getRegistrationModel();
2427 2427
         // get all other registrations on this transaction, and cache
2428 2428
         // the attendees for them so we don't have to run another query using force_join
2429
-        $registrations                           = $REG->get_all(
2429
+        $registrations = $REG->get_all(
2430 2430
             [
2431 2431
                 [
2432 2432
                     'TXN_ID' => $this->_registration->transaction_ID(),
@@ -2460,23 +2460,23 @@  discard block
 block discarded – undo
2460 2460
                 $attendee                                                      = $registration->attendee()
2461 2461
                     ? $registration->attendee()
2462 2462
                     : $this->getAttendeeModel()->create_default_object();
2463
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2464
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2465
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2466
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2468
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2463
+                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2464
+                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2465
+                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2466
+                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2467
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2468
+                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2469 2469
                     ', ',
2470 2470
                     $attendee->full_address_as_array()
2471 2471
                 );
2472
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2472
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2473 2473
                     [
2474 2474
                         'action' => 'edit_attendee',
2475 2475
                         'post'   => $attendee->ID(),
2476 2476
                     ],
2477 2477
                     REG_ADMIN_URL
2478 2478
                 );
2479
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2479
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] =
2480 2480
                     $registration->event_obj() instanceof EE_Event
2481 2481
                         ? $registration->event_obj()->name()
2482 2482
                         : '';
@@ -2484,7 +2484,7 @@  discard block
 block discarded – undo
2484 2484
             }
2485 2485
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2486 2486
         }
2487
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2488 2488
         EEH_Template::display_template($template_path, $this->_template_args);
2489 2489
     }
2490 2490
 
@@ -2510,11 +2510,11 @@  discard block
 block discarded – undo
2510 2510
         // now let's determine if this is not the primary registration.  If it isn't then we set the
2511 2511
         // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2512 2512
         // primary registration object (that way we know if we need to show create button or not)
2513
-        if (! $this->_registration->is_primary_registrant()) {
2513
+        if ( ! $this->_registration->is_primary_registrant()) {
2514 2514
             $primary_registration = $this->_registration->get_primary_registration();
2515 2515
             $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2516 2516
                 : null;
2517
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2517
+            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2518 2518
                 // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2519 2519
                 // custom attendee object so let's not worry about the primary reg.
2520 2520
                 $primary_registration = null;
@@ -2529,7 +2529,7 @@  discard block
 block discarded – undo
2529 2529
         $this->_template_args['phone']             = $attendee->phone();
2530 2530
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2531 2531
         // edit link
2532
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2532
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2533 2533
             [
2534 2534
                 'action' => 'edit_attendee',
2535 2535
                 'post'   => $attendee->ID(),
@@ -2539,7 +2539,7 @@  discard block
 block discarded – undo
2539 2539
         $this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2540 2540
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2541 2541
         // create link
2542
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2542
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2543 2543
             ? EE_Admin_Page::add_query_args_and_nonce(
2544 2544
                 [
2545 2545
                     'action'  => 'duplicate_attendee',
@@ -2549,7 +2549,7 @@  discard block
 block discarded – undo
2549 2549
             ) : '';
2550 2550
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2551 2551
         $this->_template_args['att_check'] = $att_check;
2552
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2553 2553
         EEH_Template::display_template($template_path, $this->_template_args);
2554 2554
     }
2555 2555
 
@@ -2593,7 +2593,7 @@  discard block
 block discarded – undo
2593 2593
             /** @var EE_Registration $REG */
2594 2594
             $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2595 2595
             $payments = $REG->registration_payments();
2596
-            if (! empty($payments)) {
2596
+            if ( ! empty($payments)) {
2597 2597
                 $name           = $REG->attendee() instanceof EE_Attendee
2598 2598
                     ? $REG->attendee()->full_name()
2599 2599
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2657,17 +2657,17 @@  discard block
 block discarded – undo
2657 2657
         // Checkboxes
2658 2658
         $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2659 2659
 
2660
-        if (! empty($REG_IDs)) {
2660
+        if ( ! empty($REG_IDs)) {
2661 2661
             // if array has more than one element than success message should be plural
2662 2662
             $success = count($REG_IDs) > 1 ? 2 : 1;
2663 2663
             // cycle thru checkboxes
2664 2664
             foreach ($REG_IDs as $REG_ID) {
2665 2665
                 $REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
-                if (! $REG instanceof EE_Registration) {
2666
+                if ( ! $REG instanceof EE_Registration) {
2667 2667
                     continue;
2668 2668
                 }
2669 2669
                 $deleted = $this->_delete_registration($REG);
2670
-                if (! $deleted) {
2670
+                if ( ! $deleted) {
2671 2671
                     $success = 0;
2672 2672
                 }
2673 2673
             }
@@ -2704,7 +2704,7 @@  discard block
 block discarded – undo
2704 2704
         // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2705 2705
         // registrations on the transaction that are NOT trashed.
2706 2706
         $TXN = $REG->get_first_related('Transaction');
2707
-        if (! $TXN instanceof EE_Transaction) {
2707
+        if ( ! $TXN instanceof EE_Transaction) {
2708 2708
             EE_Error::add_error(
2709 2709
                 sprintf(
2710 2710
                     esc_html__(
@@ -2722,11 +2722,11 @@  discard block
 block discarded – undo
2722 2722
         $REGS        = $TXN->get_many_related('Registration');
2723 2723
         $all_trashed = true;
2724 2724
         foreach ($REGS as $registration) {
2725
-            if (! $registration->get('REG_deleted')) {
2725
+            if ( ! $registration->get('REG_deleted')) {
2726 2726
                 $all_trashed = false;
2727 2727
             }
2728 2728
         }
2729
-        if (! $all_trashed) {
2729
+        if ( ! $all_trashed) {
2730 2730
             EE_Error::add_error(
2731 2731
                 esc_html__(
2732 2732
                     'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
@@ -2788,7 +2788,7 @@  discard block
 block discarded – undo
2788 2788
      */
2789 2789
     public function new_registration()
2790 2790
     {
2791
-        if (! $this->_set_reg_event()) {
2791
+        if ( ! $this->_set_reg_event()) {
2792 2792
             throw new EE_Error(
2793 2793
                 esc_html__(
2794 2794
                     'Unable to continue with registering because there is no Event ID in the request',
@@ -2820,7 +2820,7 @@  discard block
 block discarded – undo
2820 2820
                 ],
2821 2821
                 EVENTS_ADMIN_URL
2822 2822
             );
2823
-            $edit_event_lnk                     = '<a href="'
2823
+            $edit_event_lnk = '<a href="'
2824 2824
                                                   . $edit_event_url
2825 2825
                                                   . '" title="'
2826 2826
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2837,7 +2837,7 @@  discard block
 block discarded – undo
2837 2837
             $this->_return_json();
2838 2838
         }
2839 2839
         // grab header
2840
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2840
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2841 2841
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2842 2842
             $template_path,
2843 2843
             $this->_template_args,
@@ -2878,7 +2878,7 @@  discard block
 block discarded – undo
2878 2878
                 '</b>'
2879 2879
             );
2880 2880
             return '
2881
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2881
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2882 2882
 	<script >
2883 2883
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2884 2884
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2945,7 +2945,7 @@  discard block
 block discarded – undo
2945 2945
         // we come back to the process_registration_step route.
2946 2946
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2947 2947
         return EEH_Template::display_template(
2948
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2948
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2949 2949
             $template_args,
2950 2950
             true
2951 2951
         );
@@ -2968,7 +2968,7 @@  discard block
 block discarded – undo
2968 2968
         }
2969 2969
 
2970 2970
         $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2971
-        if (! $EVT_ID) {
2971
+        if ( ! $EVT_ID) {
2972 2972
             return false;
2973 2973
         }
2974 2974
         $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
@@ -3038,7 +3038,7 @@  discard block
 block discarded – undo
3038 3038
                 }
3039 3039
                 break;
3040 3040
             case 'questions':
3041
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3041
+                if ( ! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3042 3042
                     add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3043 3043
                 }
3044 3044
                 // process registration
@@ -3049,7 +3049,7 @@  discard block
 block discarded – undo
3049 3049
                         $grand_total->save_this_and_descendants_to_txn();
3050 3050
                     }
3051 3051
                 }
3052
-                if (! $transaction instanceof EE_Transaction) {
3052
+                if ( ! $transaction instanceof EE_Transaction) {
3053 3053
                     $query_args = [
3054 3054
                         'action'                  => 'new_registration',
3055 3055
                         'processing_registration' => 2,
@@ -3071,7 +3071,7 @@  discard block
 block discarded – undo
3071 3071
                     return;
3072 3072
                 }
3073 3073
                 // maybe update status, and make sure to save transaction if not done already
3074
-                if (! $transaction->update_status_based_on_total_paid()) {
3074
+                if ( ! $transaction->update_status_based_on_total_paid()) {
3075 3075
                     $transaction->save();
3076 3076
                 }
3077 3077
                 EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
@@ -3153,7 +3153,7 @@  discard block
 block discarded – undo
3153 3153
     public function get_attendees($per_page, $count = false, $trash = false)
3154 3154
     {
3155 3155
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3156
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3156
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3157 3157
         $orderby = $this->request->getRequestParam('orderby');
3158 3158
         switch ($orderby) {
3159 3159
             case 'ATT_ID':
@@ -3176,7 +3176,7 @@  discard block
 block discarded – undo
3176 3176
         $_where       = [];
3177 3177
         $search_term  = $this->request->getRequestParam('s');
3178 3178
         if ($search_term) {
3179
-            $search_term  = '%' . $search_term . '%';
3179
+            $search_term  = '%'.$search_term.'%';
3180 3180
             $_where['OR'] = [
3181 3181
                 'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3182 3182
                 'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
@@ -3203,7 +3203,7 @@  discard block
 block discarded – undo
3203 3203
             'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3204 3204
             'limit'         => $limit,
3205 3205
         ];
3206
-        if (! $count) {
3206
+        if ( ! $count) {
3207 3207
             $query_args['order_by'] = [$orderby => $sort];
3208 3208
         }
3209 3209
         $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
@@ -3248,7 +3248,7 @@  discard block
 block discarded – undo
3248 3248
         $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3249 3249
             ? $this->request->getRequestParam('EVT_ID', 0, 'int')
3250 3250
             : null;
3251
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3251
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3252 3252
             $request_params = $this->request->requestParams();
3253 3253
             wp_redirect(
3254 3254
                 EE_Admin_Page::add_query_args_and_nonce(
@@ -3280,8 +3280,8 @@  discard block
 block discarded – undo
3280 3280
             ];
3281 3281
             // Merge required request args, overriding any currently set
3282 3282
             $request_args = array_merge($request_args, $required_request_args);
3283
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3284
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3283
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3284
+                require_once(EE_CLASSES.'EE_Export.class.php');
3285 3285
                 $EE_Export = EE_Export::instance($request_args);
3286 3286
                 $EE_Export->export();
3287 3287
             }
@@ -3302,8 +3302,8 @@  discard block
 block discarded – undo
3302 3302
 
3303 3303
     public function _contact_list_export()
3304 3304
     {
3305
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3306
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3305
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3306
+            require_once(EE_CLASSES.'EE_Export.class.php');
3307 3307
             $EE_Export = EE_Export::instance($this->request->requestParams());
3308 3308
             $EE_Export->export_attendees();
3309 3309
         }
@@ -3312,7 +3312,7 @@  discard block
 block discarded – undo
3312 3312
 
3313 3313
     public function _contact_list_report()
3314 3314
     {
3315
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3315
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3316 3316
             wp_redirect(
3317 3317
                 EE_Admin_Page::add_query_args_and_nonce(
3318 3318
                     [
@@ -3324,8 +3324,8 @@  discard block
 block discarded – undo
3324 3324
                 )
3325 3325
             );
3326 3326
         } else {
3327
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3328
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3327
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3328
+                require_once(EE_CLASSES.'EE_Export.class.php');
3329 3329
                 $EE_Export = EE_Export::instance($this->request->requestParams());
3330 3330
                 $EE_Export->report_attendees();
3331 3331
             }
@@ -3352,7 +3352,7 @@  discard block
 block discarded – undo
3352 3352
         $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3353 3353
         $action = $this->request->getRequestParam('return', 'default');
3354 3354
         // verify we have necessary info
3355
-        if (! $REG_ID) {
3355
+        if ( ! $REG_ID) {
3356 3356
             EE_Error::add_error(
3357 3357
                 esc_html__(
3358 3358
                     'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
@@ -3367,7 +3367,7 @@  discard block
 block discarded – undo
3367 3367
         }
3368 3368
         // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3369 3369
         $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3370
-        if (! $registration instanceof EE_Registration) {
3370
+        if ( ! $registration instanceof EE_Registration) {
3371 3371
             throw new RuntimeException(
3372 3372
                 sprintf(
3373 3373
                     esc_html__(
@@ -3506,16 +3506,16 @@  discard block
 block discarded – undo
3506 3506
         $this->verify_cpt_object();
3507 3507
         remove_meta_box(
3508 3508
             'postexcerpt',
3509
-            $this->_cpt_routes[ $this->_req_action ],
3509
+            $this->_cpt_routes[$this->_req_action],
3510 3510
             'normal'
3511 3511
         );
3512
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3512
+        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal');
3513 3513
         if (post_type_supports('espresso_attendees', 'excerpt')) {
3514 3514
             $this->addMetaBox(
3515 3515
                 'postexcerpt',
3516 3516
                 esc_html__('Short Biography', 'event_espresso'),
3517 3517
                 'post_excerpt_meta_box',
3518
-                $this->_cpt_routes[ $this->_req_action ]
3518
+                $this->_cpt_routes[$this->_req_action]
3519 3519
             );
3520 3520
         }
3521 3521
         if (post_type_supports('espresso_attendees', 'comments')) {
@@ -3523,7 +3523,7 @@  discard block
 block discarded – undo
3523 3523
                 'commentsdiv',
3524 3524
                 esc_html__('Notes on the Contact', 'event_espresso'),
3525 3525
                 'post_comment_meta_box',
3526
-                $this->_cpt_routes[ $this->_req_action ],
3526
+                $this->_cpt_routes[$this->_req_action],
3527 3527
                 'normal',
3528 3528
                 'core'
3529 3529
             );
@@ -3532,7 +3532,7 @@  discard block
 block discarded – undo
3532 3532
             'attendee_contact_info',
3533 3533
             esc_html__('Contact Info', 'event_espresso'),
3534 3534
             [$this, 'attendee_contact_info'],
3535
-            $this->_cpt_routes[ $this->_req_action ],
3535
+            $this->_cpt_routes[$this->_req_action],
3536 3536
             'side',
3537 3537
             'core'
3538 3538
         );
@@ -3540,7 +3540,7 @@  discard block
 block discarded – undo
3540 3540
             'attendee_details_address',
3541 3541
             esc_html__('Address Details', 'event_espresso'),
3542 3542
             [$this, 'attendee_address_details'],
3543
-            $this->_cpt_routes[ $this->_req_action ],
3543
+            $this->_cpt_routes[$this->_req_action],
3544 3544
             'normal',
3545 3545
             'core'
3546 3546
         );
@@ -3548,7 +3548,7 @@  discard block
 block discarded – undo
3548 3548
             'attendee_registrations',
3549 3549
             esc_html__('Registrations for this Contact', 'event_espresso'),
3550 3550
             [$this, 'attendee_registrations_meta_box'],
3551
-            $this->_cpt_routes[ $this->_req_action ]
3551
+            $this->_cpt_routes[$this->_req_action]
3552 3552
         );
3553 3553
     }
3554 3554
 
@@ -3647,7 +3647,7 @@  discard block
 block discarded – undo
3647 3647
                 ]
3648 3648
             )
3649 3649
         );
3650
-        $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3650
+        $template = REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3651 3651
         EEH_Template::display_template($template, $this->_template_args);
3652 3652
     }
3653 3653
 
@@ -3668,7 +3668,7 @@  discard block
 block discarded – undo
3668 3668
     {
3669 3669
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3670 3670
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3671
-        $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3671
+        $template = REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3672 3672
         EEH_Template::display_template($template, $this->_template_args);
3673 3673
     }
3674 3674
 
@@ -3683,7 +3683,7 @@  discard block
 block discarded – undo
3683 3683
     public function after_title_form_fields($post)
3684 3684
     {
3685 3685
         if ($post->post_type === 'espresso_attendees') {
3686
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3686
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3687 3687
             $template_args['attendee'] = $this->_cpt_model_obj;
3688 3688
             EEH_Template::display_template($template, $template_args);
3689 3689
         }
@@ -3712,7 +3712,7 @@  discard block
 block discarded – undo
3712 3712
             // cycle thru checkboxes
3713 3713
             foreach ($ATT_IDs as $ATT_ID) {
3714 3714
                 $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3715
-                if (! $updated) {
3715
+                if ( ! $updated) {
3716 3716
                     $success = 0;
3717 3717
                 }
3718 3718
             }
Please login to merge, or discard this patch.
templates/reg_admin_details_main_meta_box_attendees.template.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
                 </thead>
27 27
                 <tbody>
28 28
                     <?php
29
-                    foreach ($attendees as $att_nmbr => $attendee) : ?>
29
+					foreach ($attendees as $att_nmbr => $attendee) : ?>
30 30
                         <tr>
31 31
                             <th class='jst-cntr no-pad'>
32 32
                                 <span class="ee-status-dot ee-status-bg--<?php echo esc_attr($attendee['STS_ID']); ?> ee-aria-tooltip"
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
                             </td>
46 46
                             <td class="jst-rght">
47 47
                                 <?php
48
-                                $final_price = number_format((float) $attendee['final_price'], 2);
49
-                                echo esc_html("$currency_sign $final_price");
50
-                                ?>
48
+								$final_price = number_format((float) $attendee['final_price'], 2);
49
+								echo esc_html("$currency_sign $final_price");
50
+								?>
51 51
                             </td>
52 52
                             <td class="jst-left"><?php echo esc_html($attendee['email']); ?></td>
53 53
                             <td class="jst-left"><?php echo esc_html($attendee['address']); ?></td>
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 <div id="admin-primary-mbox-dv" class="admin-primary-mbox-dv">
11 11
     <br />
12 12
     <?php echo esc_html($attendee_notice); ?>
13
-    <?php if (! empty($attendees)) : ?>
13
+    <?php if ( ! empty($attendees)) : ?>
14 14
         <div class="admin-primary-mbox-tbl-wrap">
15 15
             <table id="reg-admin-transaction-attendees-table" class="admin-primary-mbox-tbl striped">
16 16
                 <thead>
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
                         <tr>
31 31
                             <th class='jst-cntr no-pad'>
32 32
                                 <span class="ee-status-dot ee-status-bg--<?php echo esc_attr($attendee['STS_ID']); ?> ee-aria-tooltip"
33
-                                      aria-label="<?php echo esc_attr(EEH_Template::pretty_status($attendee['STS_ID'], false, "sentence" ));?>">
33
+                                      aria-label="<?php echo esc_attr(EEH_Template::pretty_status($attendee['STS_ID'], false, "sentence")); ?>">
34 34
                                 </span>
35 35
                             </th>
36 36
                             <td class="jst-left"><?php echo esc_html($att_nmbr); ?></td>
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
                                    aria-label="<?php esc_attr_e('View details for this attendee', 'event_espresso'); ?>"
41 41
                                    class="ee-aria-tooltip"
42 42
                                 >
43
-                                    <?php echo esc_html($attendee['fname'] . ' ' . $attendee['lname']); ?>
43
+                                    <?php echo esc_html($attendee['fname'].' '.$attendee['lname']); ?>
44 44
                                 </a>
45 45
                             </td>
46 46
                             <td class="jst-rght">
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 2 patches
Indentation   +2528 added lines, -2528 removed lines patch added patch discarded remove patch
@@ -13,2532 +13,2532 @@
 block discarded – undo
13 13
 class Transactions_Admin_Page extends EE_Admin_Page
14 14
 {
15 15
 
16
-    /**
17
-     * @var EE_Transaction
18
-     */
19
-    private $_transaction;
20
-
21
-    /**
22
-     * @var EE_Session
23
-     */
24
-    private $_session;
25
-
26
-    /**
27
-     * @var array $_txn_status
28
-     */
29
-    private static $_txn_status;
30
-
31
-    /**
32
-     * @var array $_pay_status
33
-     */
34
-    private static $_pay_status;
35
-
36
-    /**
37
-     * @var array $_existing_reg_payment_REG_IDs
38
-     */
39
-    protected $_existing_reg_payment_REG_IDs;
40
-
41
-
42
-    /**
43
-     *    _init_page_props
44
-     *
45
-     * @return void
46
-     */
47
-    protected function _init_page_props()
48
-    {
49
-        $this->page_slug        = TXN_PG_SLUG;
50
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
51
-        $this->_admin_base_url  = TXN_ADMIN_URL;
52
-        $this->_admin_base_path = TXN_ADMIN;
53
-    }
54
-
55
-
56
-    /**
57
-     *    _ajax_hooks
58
-     *
59
-     * @return void
60
-     */
61
-    protected function _ajax_hooks()
62
-    {
63
-        add_action('wp_ajax_espresso_apply_payment', [$this, 'apply_payments_or_refunds']);
64
-        add_action('wp_ajax_espresso_apply_refund', [$this, 'apply_payments_or_refunds']);
65
-        add_action('wp_ajax_espresso_delete_payment', [$this, 'delete_payment']);
66
-    }
67
-
68
-
69
-    /**
70
-     *    _define_page_props
71
-     *
72
-     * @return void
73
-     */
74
-    protected function _define_page_props()
75
-    {
76
-        $this->_admin_page_title = $this->page_label;
77
-        $this->_labels           = [
78
-            'buttons' => [
79
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
80
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
81
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
82
-            ],
83
-        ];
84
-    }
85
-
86
-
87
-    /**
88
-     *        grab url requests and route them
89
-     *
90
-     * @access private
91
-     * @return void
92
-     * @throws EE_Error
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     */
97
-    public function _set_page_routes()
98
-    {
99
-
100
-        $this->_set_transaction_status_array();
101
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
102
-
103
-        $this->_page_routes = [
104
-
105
-            'default' => [
106
-                'func'       => '_transactions_overview_list_table',
107
-                'capability' => 'ee_read_transactions',
108
-            ],
109
-
110
-            'view_transaction' => [
111
-                'func'       => '_transaction_details',
112
-                'capability' => 'ee_read_transaction',
113
-                'obj_id'     => $TXN_ID,
114
-            ],
115
-
116
-            'send_payment_reminder' => [
117
-                'func'       => '_send_payment_reminder',
118
-                'noheader'   => true,
119
-                'capability' => 'ee_send_message',
120
-            ],
121
-
122
-            'espresso_apply_payment' => [
123
-                'func'       => 'apply_payments_or_refunds',
124
-                'noheader'   => true,
125
-                'capability' => 'ee_edit_payments',
126
-            ],
127
-
128
-            'espresso_apply_refund' => [
129
-                'func'       => 'apply_payments_or_refunds',
130
-                'noheader'   => true,
131
-                'capability' => 'ee_edit_payments',
132
-            ],
133
-
134
-            'espresso_delete_payment' => [
135
-                'func'       => 'delete_payment',
136
-                'noheader'   => true,
137
-                'capability' => 'ee_delete_payments',
138
-            ],
139
-
140
-            'espresso_recalculate_line_items' => [
141
-                'func'       => 'recalculateLineItems',
142
-                'noheader'   => true,
143
-                'capability' => 'ee_edit_payments',
144
-            ],
145
-
146
-        ];
147
-    }
148
-
149
-
150
-    protected function _set_page_config()
151
-    {
152
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
153
-        $this->_page_config = [
154
-            'default'          => [
155
-                'nav'           => [
156
-                    'label' => esc_html__('Overview', 'event_espresso'),
157
-                    'order' => 10,
158
-                ],
159
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
160
-                'help_tabs'     => [
161
-                    'transactions_overview_help_tab'                       => [
162
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
163
-                        'filename' => 'transactions_overview',
164
-                    ],
165
-                    'transactions_overview_table_column_headings_help_tab' => [
166
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
167
-                        'filename' => 'transactions_overview_table_column_headings',
168
-                    ],
169
-                    'transactions_overview_views_filters_help_tab'         => [
170
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
171
-                        'filename' => 'transactions_overview_views_filters_search',
172
-                    ],
173
-                ],
174
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
175
-                // 'help_tour'     => array('Transactions_Overview_Help_Tour'),
176
-                /**
177
-                 * commented out because currently we are not displaying tips for transaction list table status but this
178
-                 * may change in a later iteration so want to keep the code for then.
179
-                 */
180
-                // 'qtips' => array( 'Transactions_List_Table_Tips' ),
181
-                'require_nonce' => false,
182
-            ],
183
-            'view_transaction' => [
184
-                'nav'       => [
185
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
186
-                    'order'      => 5,
187
-                    'url'        => $TXN_ID
188
-                        ? add_query_arg(['TXN_ID' => $TXN_ID], $this->_current_page_view_url)
189
-                        : $this->_admin_base_url,
190
-                    'persistent' => false,
191
-                ],
192
-                'help_tabs' => [
193
-                    'transactions_view_transaction_help_tab'                                              => [
194
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
195
-                        'filename' => 'transactions_view_transaction',
196
-                    ],
197
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => [
198
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
199
-                        'filename' => 'transactions_view_transaction_transaction_details_table',
200
-                    ],
201
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => [
202
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
203
-                        'filename' => 'transactions_view_transaction_attendees_registered',
204
-                    ],
205
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => [
206
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
207
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
208
-                    ],
209
-                ],
210
-                'qtips'     => ['Transaction_Details_Tips'],
211
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
212
-                // 'help_tour' => array('Transaction_Details_Help_Tour'),
213
-                'metaboxes' => ['_transaction_details_metaboxes'],
214
-
215
-                'require_nonce' => false,
216
-            ],
217
-        ];
218
-    }
219
-
220
-
221
-    /**
222
-     * The below methods aren't used by this class currently
223
-     */
224
-    protected function _add_screen_options()
225
-    {
226
-        // noop
227
-    }
228
-
229
-
230
-    protected function _add_feature_pointers()
231
-    {
232
-        // noop
233
-    }
234
-
235
-
236
-    public function admin_init()
237
-    {
238
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
239
-        $event_name = $this->request->getRequestParam('event_name');
240
-        $redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
241
-        // IF a registration was JUST added via the admin...
242
-        if ($EVT_ID && $event_name && $redirect_from) {
243
-            // then set a cookie so that we can block any attempts to use
244
-            // the back button as a way to enter another registration.
245
-            setcookie('ee_registration_added', $EVT_ID, time() + WEEK_IN_SECONDS, '/');
246
-            // and update the global
247
-            $_COOKIE['ee_registration_added'] = $EVT_ID;
248
-        }
249
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
250
-            'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
251
-            'event_espresso'
252
-        );
253
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
254
-            'An error occurred! Please refresh the page and try again.',
255
-            'event_espresso'
256
-        );
257
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
258
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
259
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
260
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
261
-            'This transaction has been overpaid ! Payments Total',
262
-            'event_espresso'
263
-        );
264
-    }
265
-
266
-
267
-    public function admin_notices()
268
-    {
269
-        // noop
270
-    }
271
-
272
-
273
-    public function admin_footer_scripts()
274
-    {
275
-        // noop
276
-    }
277
-
278
-
279
-    /**
280
-     * _set_transaction_status_array
281
-     * sets list of transaction statuses
282
-     *
283
-     * @access private
284
-     * @return void
285
-     * @throws EE_Error
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidDataTypeException
288
-     * @throws InvalidInterfaceException
289
-     */
290
-    private function _set_transaction_status_array()
291
-    {
292
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
293
-    }
294
-
295
-
296
-    /**
297
-     * get_transaction_status_array
298
-     * return the transaction status array for wp_list_table
299
-     *
300
-     * @access public
301
-     * @return array
302
-     */
303
-    public function get_transaction_status_array()
304
-    {
305
-        return self::$_txn_status;
306
-    }
307
-
308
-
309
-    /**
310
-     *    get list of payment statuses
311
-     *
312
-     * @access private
313
-     * @return void
314
-     * @throws EE_Error
315
-     * @throws InvalidArgumentException
316
-     * @throws InvalidDataTypeException
317
-     * @throws InvalidInterfaceException
318
-     */
319
-    private function _get_payment_status_array()
320
-    {
321
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
322
-        $this->_template_args['payment_status'] = self::$_pay_status;
323
-    }
324
-
325
-
326
-    /**
327
-     *    _add_screen_options_default
328
-     *
329
-     * @access protected
330
-     * @return void
331
-     * @throws InvalidArgumentException
332
-     * @throws InvalidDataTypeException
333
-     * @throws InvalidInterfaceException
334
-     */
335
-    protected function _add_screen_options_default()
336
-    {
337
-        $this->_per_page_screen_option();
338
-    }
339
-
340
-
341
-    /**
342
-     * load_scripts_styles
343
-     *
344
-     * @access public
345
-     * @return void
346
-     */
347
-    public function load_scripts_styles()
348
-    {
349
-        // enqueue style
350
-        wp_register_style(
351
-            'espresso_txn',
352
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
353
-            [],
354
-            EVENT_ESPRESSO_VERSION
355
-        );
356
-        wp_enqueue_style('espresso_txn');
357
-        // scripts
358
-        wp_register_script(
359
-            'espresso_txn',
360
-            TXN_ASSETS_URL . 'espresso_transactions_admin.js',
361
-            [
362
-                'ee_admin_js',
363
-                'ee-datepicker',
364
-                'jquery-ui-datepicker',
365
-                'jquery-ui-draggable',
366
-                'ee-dialog',
367
-                'ee-accounting',
368
-                'ee-serialize-full-array',
369
-            ],
370
-            EVENT_ESPRESSO_VERSION,
371
-            true
372
-        );
373
-        wp_enqueue_script('espresso_txn');
374
-    }
375
-
376
-
377
-    /**
378
-     *    load_scripts_styles_view_transaction
379
-     *
380
-     * @access public
381
-     * @return void
382
-     */
383
-    public function load_scripts_styles_view_transaction()
384
-    {
385
-        // styles
386
-        wp_enqueue_style('espresso-ui-theme');
387
-    }
388
-
389
-
390
-    /**
391
-     *    load_scripts_styles_default
392
-     *
393
-     * @access public
394
-     * @return void
395
-     */
396
-    public function load_scripts_styles_default()
397
-    {
398
-        // styles
399
-        wp_enqueue_style('espresso-ui-theme');
400
-    }
401
-
402
-
403
-    /**
404
-     *    _set_list_table_views_default
405
-     *
406
-     * @access protected
407
-     * @return void
408
-     */
409
-    protected function _set_list_table_views_default()
410
-    {
411
-        $this->_views = [
412
-            'all'        => [
413
-                'slug'  => 'all',
414
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
415
-                'count' => 0,
416
-            ],
417
-            'abandoned'  => [
418
-                'slug'  => 'abandoned',
419
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
420
-                'count' => 0,
421
-            ],
422
-            'incomplete' => [
423
-                'slug'  => 'incomplete',
424
-                'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
425
-                'count' => 0,
426
-            ],
427
-        ];
428
-        if (
429
-            /**
430
-             * Filters whether a link to the "Failed Transactions" list table
431
-             * appears on the Transactions Admin Page list table.
432
-             * List display can be turned back on via the following:
433
-             * add_filter(
434
-             *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
435
-             *     '__return_true'
436
-             * );
437
-             *
438
-             * @param boolean                 $display_failed_txns_list
439
-             * @param Transactions_Admin_Page $this
440
-             * @since 4.9.70.p
441
-             */
442
-            apply_filters(
443
-                'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
444
-                false,
445
-                $this
446
-            )
447
-        ) {
448
-            $this->_views['failed'] = [
449
-                'slug'  => 'failed',
450
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
451
-                'count' => 0,
452
-            ];
453
-        }
454
-    }
455
-
456
-
457
-    /**
458
-     * _set_transaction_object
459
-     * This sets the _transaction property for the transaction details screen
460
-     *
461
-     * @access private
462
-     * @return void
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws RuntimeException
466
-     * @throws InvalidDataTypeException
467
-     * @throws InvalidInterfaceException
468
-     * @throws ReflectionException
469
-     */
470
-    private function _set_transaction_object()
471
-    {
472
-        if ($this->_transaction instanceof EE_Transaction) {
473
-            return;
474
-        } //get out we've already set the object
475
-
476
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
477
-
478
-        // get transaction object
479
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
480
-        $this->_session     = $this->_transaction instanceof EE_Transaction
481
-            ? $this->_transaction->session_data()
482
-            : null;
483
-        if ($this->_transaction instanceof EE_Transaction) {
484
-            $this->_transaction->verify_abandoned_transaction_status();
485
-        }
486
-
487
-        if (! $this->_transaction instanceof EE_Transaction) {
488
-            $error_msg = sprintf(
489
-                esc_html__(
490
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
491
-                    'event_espresso'
492
-                ),
493
-                $TXN_ID
494
-            );
495
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
496
-        }
497
-    }
498
-
499
-
500
-    /**
501
-     *    _transaction_legend_items
502
-     *
503
-     * @access protected
504
-     * @return array
505
-     * @throws EE_Error
506
-     * @throws InvalidArgumentException
507
-     * @throws ReflectionException
508
-     * @throws InvalidDataTypeException
509
-     * @throws InvalidInterfaceException
510
-     */
511
-    protected function _transaction_legend_items()
512
-    {
513
-        EE_Registry::instance()->load_helper('MSG_Template');
514
-        $items = [];
515
-
516
-        if (
517
-            EE_Registry::instance()->CAP->current_user_can(
518
-                'ee_read_global_messages',
519
-                'view_filtered_messages'
520
-            )
521
-        ) {
522
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
523
-            if (
524
-                is_array($related_for_icon)
525
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
526
-            ) {
527
-                $items['view_related_messages'] = [
528
-                    'class' => $related_for_icon['css_class'],
529
-                    'desc'  => $related_for_icon['label'],
530
-                ];
531
-            }
532
-        }
533
-
534
-        $items = apply_filters(
535
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
536
-            array_merge(
537
-                $items,
538
-                [
539
-                    'view_details'          => [
540
-                        'class' => 'dashicons dashicons-cart',
541
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
542
-                    ],
543
-                    'view_invoice'          => [
544
-                        'class' => 'dashicons dashicons-media-spreadsheet',
545
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
546
-                    ],
547
-                    'view_receipt'          => [
548
-                        'class' => 'dashicons dashicons-text-page',
549
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
550
-                    ],
551
-                    'view_registration'     => [
552
-                        'class' => 'dashicons dashicons-clipboard',
553
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
554
-                    ],
555
-                    'payment_overview_link' => [
556
-                        'class' => 'dashicons dashicons-money',
557
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
558
-                    ],
559
-                ]
560
-            )
561
-        );
562
-
563
-        if (
564
-            EEH_MSG_Template::is_mt_active('payment_reminder')
565
-            && EE_Registry::instance()->CAP->current_user_can(
566
-                'ee_send_message',
567
-                'espresso_transactions_send_payment_reminder'
568
-            )
569
-        ) {
570
-            $items['send_payment_reminder'] = [
571
-                'class' => 'dashicons dashicons-email-alt',
572
-                'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
573
-            ];
574
-        } else {
575
-            $items['blank*'] = [
576
-                'class' => '',
577
-                'desc'  => '',
578
-            ];
579
-        }
580
-        $more_items = apply_filters(
581
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
582
-            [
583
-                'overpaid'   => [
584
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::overpaid_status_code,
585
-                    'desc'  => EEH_Template::pretty_status(
586
-                        EEM_Transaction::overpaid_status_code,
587
-                        false,
588
-                        'sentence'
589
-                    ),
590
-                ],
591
-                'complete'   => [
592
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::complete_status_code,
593
-                    'desc'  => EEH_Template::pretty_status(
594
-                        EEM_Transaction::complete_status_code,
595
-                        false,
596
-                        'sentence'
597
-                    ),
598
-                ],
599
-                'incomplete' => [
600
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::incomplete_status_code,
601
-                    'desc'  => EEH_Template::pretty_status(
602
-                        EEM_Transaction::incomplete_status_code,
603
-                        false,
604
-                        'sentence'
605
-                    ),
606
-                ],
607
-                'abandoned'  => [
608
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::abandoned_status_code,
609
-                    'desc'  => EEH_Template::pretty_status(
610
-                        EEM_Transaction::abandoned_status_code,
611
-                        false,
612
-                        'sentence'
613
-                    ),
614
-                ],
615
-                'failed'     => [
616
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::failed_status_code,
617
-                    'desc'  => EEH_Template::pretty_status(
618
-                        EEM_Transaction::failed_status_code,
619
-                        false,
620
-                        'sentence'
621
-                    ),
622
-                ],
623
-            ]
624
-        );
625
-
626
-        return array_merge($items, $more_items);
627
-    }
628
-
629
-
630
-    /**
631
-     *    _transactions_overview_list_table
632
-     *
633
-     * @access protected
634
-     * @return void
635
-     * @throws DomainException
636
-     * @throws EE_Error
637
-     * @throws InvalidArgumentException
638
-     * @throws InvalidDataTypeException
639
-     * @throws InvalidInterfaceException
640
-     * @throws ReflectionException
641
-     */
642
-    protected function _transactions_overview_list_table()
643
-    {
644
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
645
-
646
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
647
-        $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
648
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
649
-            ? sprintf(
650
-                esc_html__('%sViewing Transactions for the Event: %s%s', 'event_espresso'),
651
-                '<h3>',
652
-                '<a href="'
653
-                . EE_Admin_Page::add_query_args_and_nonce(
654
-                    ['action' => 'edit', 'post' => $event->ID()],
655
-                    EVENTS_ADMIN_URL
656
-                )
657
-                . '" title="'
658
-                . esc_attr__('Click to Edit event', 'event_espresso')
659
-                . '">' . $event->name() . '</a>',
660
-                '</h3>'
661
-            )
662
-            : '';
663
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
664
-        $this->display_admin_list_table_page_with_no_sidebar();
665
-    }
666
-
667
-
668
-    /**
669
-     *    _transaction_details
670
-     * generates HTML for the View Transaction Details Admin page
671
-     *
672
-     * @access protected
673
-     * @return void
674
-     * @throws DomainException
675
-     * @throws EE_Error
676
-     * @throws InvalidArgumentException
677
-     * @throws InvalidDataTypeException
678
-     * @throws InvalidInterfaceException
679
-     * @throws RuntimeException
680
-     * @throws ReflectionException
681
-     */
682
-    protected function _transaction_details()
683
-    {
684
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
685
-
686
-        $this->_set_transaction_status_array();
687
-
688
-        $this->_template_args                      = [];
689
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
690
-
691
-        $this->_set_transaction_object();
692
-
693
-        if (! $this->_transaction instanceof EE_Transaction) {
694
-            return;
695
-        }
696
-
697
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
698
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
699
-
700
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
701
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
702
-
703
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
704
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
705
-        $this->_template_args['txn_status']['class'] = $this->_transaction->status_ID();
706
-
707
-        $this->_template_args['grand_total'] = $this->_transaction->total();
708
-        $this->_template_args['total_paid']  = $this->_transaction->paid();
709
-
710
-        $amount_due                         = $this->_transaction->total() - $this->_transaction->paid();
711
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
712
-            $amount_due,
713
-            true
714
-        );
715
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
716
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
717
-                                                  . $this->_template_args['amount_due'];
718
-        } else {
719
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
720
-        }
721
-        $this->_template_args['amount_due_class'] = '';
722
-
723
-        if ($this->_transaction->paid() === $this->_transaction->total()) {
724
-            // paid in full
725
-            $this->_template_args['amount_due'] = false;
726
-        } elseif ($this->_transaction->paid() > $this->_transaction->total()) {
727
-            // overpaid
728
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
729
-        } elseif ($this->_transaction->total() > (float) 0) {
730
-            if ($this->_transaction->paid() > (float) 0) {
731
-                // monies owing
732
-                $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
733
-            } elseif ($this->_transaction->paid() === (float) 0) {
734
-                // no payments made yet
735
-                $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
736
-            }
737
-        } elseif ($this->_transaction->total() === (float) 0) {
738
-            // free event
739
-            $this->_template_args['amount_due'] = false;
740
-        }
741
-
742
-        $payment_method = $this->_transaction->payment_method();
743
-
744
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
745
-            ? $payment_method->admin_name()
746
-            : esc_html__('Unknown', 'event_espresso');
747
-
748
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
749
-        // link back to overview
750
-        $this->_template_args['txn_overview_url'] = $this->request->getServerParam(
751
-            'HTTP_REFERER',
752
-            TXN_ADMIN_URL
753
-        );
754
-
755
-
756
-        // next link
757
-        $next_txn                                 = $this->_transaction->next(
758
-            null,
759
-            [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
760
-            'TXN_ID'
761
-        );
762
-        $this->_template_args['next_transaction'] = $next_txn
763
-            ? $this->_next_link(
764
-                EE_Admin_Page::add_query_args_and_nonce(
765
-                    ['action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']],
766
-                    TXN_ADMIN_URL
767
-                ),
768
-                'dashicons dashicons-arrow-right ee-icon-size-22'
769
-            )
770
-            : '';
771
-        // previous link
772
-        $previous_txn                                 = $this->_transaction->previous(
773
-            null,
774
-            [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
775
-            'TXN_ID'
776
-        );
777
-        $this->_template_args['previous_transaction'] = $previous_txn
778
-            ? $this->_previous_link(
779
-                EE_Admin_Page::add_query_args_and_nonce(
780
-                    ['action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']],
781
-                    TXN_ADMIN_URL
782
-                ),
783
-                'dashicons dashicons-arrow-left ee-icon-size-22'
784
-            )
785
-            : '';
786
-
787
-        $EVT_ID        = $this->request->getRequestParam('EVT_ID', 0, 'int');
788
-        $event_name    = $this->request->getRequestParam('event_name');
789
-        $redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
790
-
791
-        // were we just redirected here after adding a new registration ???
792
-        if ($EVT_ID && $event_name && $redirect_from) {
793
-            if (
794
-                EE_Registry::instance()->CAP->current_user_can(
795
-                    'ee_edit_registrations',
796
-                    'espresso_registrations_new_registration',
797
-                    $EVT_ID
798
-                )
799
-            ) {
800
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button--primary" href="';
801
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
802
-                    [
803
-                        'page'     => 'espresso_registrations',
804
-                        'action'   => 'new_registration',
805
-                        'return'   => 'default',
806
-                        'TXN_ID'   => $this->_transaction->ID(),
807
-                        'event_id' => $EVT_ID,
808
-                    ],
809
-                    REG_ADMIN_URL
810
-                );
811
-                $this->_admin_page_title .= '">';
812
-
813
-                $this->_admin_page_title .= sprintf(
814
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
815
-                    htmlentities(urldecode($event_name), ENT_QUOTES, 'UTF-8')
816
-                );
817
-                $this->_admin_page_title .= '</a>';
818
-            }
819
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
820
-        }
821
-        // grab messages at the last second
822
-        $this->_template_args['notices'] = EE_Error::get_notices();
823
-        // path to template
824
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
825
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
826
-            $template_path,
827
-            $this->_template_args,
828
-            true
829
-        );
830
-
831
-        // the details template wrapper
832
-        $this->display_admin_page_with_sidebar();
833
-    }
834
-
835
-
836
-    /**
837
-     *        _transaction_details_metaboxes
838
-     *
839
-     * @access protected
840
-     * @return void
841
-     * @throws EE_Error
842
-     * @throws InvalidArgumentException
843
-     * @throws InvalidDataTypeException
844
-     * @throws InvalidInterfaceException
845
-     * @throws RuntimeException
846
-     * @throws ReflectionException
847
-     */
848
-    protected function _transaction_details_metaboxes()
849
-    {
850
-
851
-        $this->_set_transaction_object();
852
-
853
-        if (! $this->_transaction instanceof EE_Transaction) {
854
-            return;
855
-        }
856
-        $this->addMetaBox(
857
-            'edit-txn-details-mbox',
858
-            '<span>' . esc_html__('Transaction Details', 'event_espresso')
859
-            . '&nbsp;<span class="dashicons dashicons-cart" ></span></span>',
860
-            [$this, 'txn_details_meta_box'],
861
-            $this->_wp_page_slug
862
-        );
863
-        $this->addMetaBox(
864
-            'edit-txn-attendees-mbox',
865
-            '<span>' . esc_html__('Attendees Registered in this Transaction', 'event_espresso')
866
-            . '&nbsp;<span class="dashicons dashicons-groups" ></span></span>',
867
-            [$this, 'txn_attendees_meta_box'],
868
-            $this->_wp_page_slug,
869
-            'normal',
870
-            'high',
871
-            ['TXN_ID' => $this->_transaction->ID()]
872
-        );
873
-        $this->addMetaBox(
874
-            'edit-txn-registrant-mbox',
875
-            esc_html__('Primary Contact', 'event_espresso'),
876
-            [$this, 'txn_registrant_side_meta_box'],
877
-            $this->_wp_page_slug,
878
-            'side'
879
-        );
880
-        $this->addMetaBox(
881
-            'edit-txn-billing-info-mbox',
882
-            esc_html__('Billing Information', 'event_espresso'),
883
-            [$this, 'txn_billing_info_side_meta_box'],
884
-            $this->_wp_page_slug,
885
-            'side'
886
-        );
887
-    }
888
-
889
-
890
-    /**
891
-     * Callback for transaction actions metabox.
892
-     *
893
-     * @param EE_Transaction|null $transaction
894
-     * @return string
895
-     * @throws DomainException
896
-     * @throws EE_Error
897
-     * @throws InvalidArgumentException
898
-     * @throws InvalidDataTypeException
899
-     * @throws InvalidInterfaceException
900
-     * @throws ReflectionException
901
-     * @throws RuntimeException
902
-     */
903
-    public function getActionButtons(EE_Transaction $transaction = null)
904
-    {
905
-        $content = '';
906
-        $actions = [];
907
-        if (! $transaction instanceof EE_Transaction) {
908
-            return $content;
909
-        }
910
-        /** @var EE_Registration $primary_registration */
911
-        $primary_registration = $transaction->primary_registration();
912
-        $attendee             = $primary_registration instanceof EE_Registration
913
-            ? $primary_registration->attendee()
914
-            : null;
915
-
916
-        if (
917
-            $attendee instanceof EE_Attendee
918
-            && EE_Registry::instance()->CAP->current_user_can(
919
-                'ee_send_message',
920
-                'espresso_transactions_send_payment_reminder'
921
-            )
922
-        ) {
923
-            $actions['payment_reminder'] =
924
-                EEH_MSG_Template::is_mt_active('payment_reminder')
925
-                && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code
926
-                && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code
927
-                    ? EEH_Template::get_button_or_link(
928
-                        EE_Admin_Page::add_query_args_and_nonce(
929
-                            [
930
-                            'action'      => 'send_payment_reminder',
931
-                            'TXN_ID'      => $this->_transaction->ID(),
932
-                            'redirect_to' => 'view_transaction',
933
-                            ],
934
-                            TXN_ADMIN_URL
935
-                        ),
936
-                        esc_html__(' Send Payment Reminder', 'event_espresso'),
937
-                        'button button--secondary',
938
-                        'dashicons dashicons-email-alt'
939
-                    )
940
-                    : '';
941
-        }
942
-
943
-        if (
944
-            EE_Registry::instance()->CAP->current_user_can(
945
-                'ee_edit_payments',
946
-                'espresso_transactions_recalculate_line_items'
947
-            )
948
-        ) {
949
-            $actions['recalculate_line_items'] = EEH_Template::get_button_or_link(
950
-                EE_Admin_Page::add_query_args_and_nonce(
951
-                    [
952
-                        'action'      => 'espresso_recalculate_line_items',
953
-                        'TXN_ID'      => $this->_transaction->ID(),
954
-                        'redirect_to' => 'view_transaction',
955
-                    ],
956
-                    TXN_ADMIN_URL
957
-                ),
958
-                esc_html__(' Recalculate Taxes and Total', 'event_espresso'),
959
-                'button button--secondary',
960
-                'dashicons dashicons-update'
961
-            );
962
-        }
963
-
964
-        if (
965
-            $primary_registration instanceof EE_Registration
966
-            && EEH_MSG_Template::is_mt_active('receipt')
967
-        ) {
968
-            $actions['receipt'] = EEH_Template::get_button_or_link(
969
-                $primary_registration->receipt_url(),
970
-                esc_html__('View Receipt', 'event_espresso'),
971
-                'button button--secondary',
972
-                'dashicons dashicons-text-page'
973
-            );
974
-        }
975
-
976
-        if (
977
-            $primary_registration instanceof EE_Registration
978
-            && EEH_MSG_Template::is_mt_active('invoice')
979
-        ) {
980
-            $actions['invoice'] = EEH_Template::get_button_or_link(
981
-                $primary_registration->invoice_url(),
982
-                esc_html__('View Invoice', 'event_espresso'),
983
-                'button button--secondary',
984
-                'dashicons dashicons-media-spreadsheet'
985
-            );
986
-        }
987
-        $actions = array_filter(
988
-            apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
989
-        );
990
-        if ($actions) {
991
-            // $content = '<ul>';
992
-            // $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
993
-            // $content .= '</uL>';
994
-            $content .= implode('', $actions);
995
-        }
996
-        return $content;
997
-    }
998
-
999
-
1000
-    /**
1001
-     * txn_details_meta_box
1002
-     * generates HTML for the Transaction main meta box
1003
-     *
1004
-     * @return void
1005
-     * @throws DomainException
1006
-     * @throws EE_Error
1007
-     * @throws InvalidArgumentException
1008
-     * @throws InvalidDataTypeException
1009
-     * @throws InvalidInterfaceException
1010
-     * @throws RuntimeException
1011
-     * @throws ReflectionException
1012
-     */
1013
-    public function txn_details_meta_box()
1014
-    {
1015
-        $this->_set_transaction_object();
1016
-        $this->_template_args['TXN_ID']              = $this->_transaction->ID();
1017
-        $this->_template_args['attendee']            =
1018
-            $this->_transaction->primary_registration() instanceof EE_Registration
1019
-                ? $this->_transaction->primary_registration()->attendee()
1020
-                : null;
1021
-        $this->_template_args['can_edit_payments']   = EE_Registry::instance()->CAP->current_user_can(
1022
-            'ee_edit_payments',
1023
-            'apply_payment_or_refund_from_registration_details'
1024
-        );
1025
-        $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1026
-            'ee_delete_payments',
1027
-            'delete_payment_from_registration_details'
1028
-        );
1029
-
1030
-        // get line table
1031
-        EEH_Autoloader::register_line_item_display_autoloaders();
1032
-        $Line_Item_Display                       = new EE_Line_Item_Display(
1033
-            'admin_table',
1034
-            'EE_Admin_Table_Line_Item_Display_Strategy'
1035
-        );
1036
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1037
-            $this->_transaction->total_line_item()
1038
-        );
1039
-        $this->_template_args['REG_code']        =
1040
-            $this->_transaction->primary_registration() instanceof EE_Registration
1041
-                ? $this->_transaction->primary_registration()->reg_code()
1042
-                : null;
1043
-        // process taxes
1044
-        $taxes                         = $this->_transaction->line_items([['LIN_type' => EEM_Line_Item::type_tax]]);
1045
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1046
-
1047
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
1048
-            $this->_transaction->total(),
1049
-            false,
1050
-            false
1051
-        );
1052
-        $this->_template_args['grand_raw_total'] = $this->_transaction->total();
1053
-        $this->_template_args['TXN_status']      = $this->_transaction->status_ID();
1054
-
1055
-        // process payment details
1056
-        $payments = $this->_transaction->payments();
1057
-        if (! empty($payments)) {
1058
-            $this->_template_args['payments']              = $payments;
1059
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1060
-        } else {
1061
-            $this->_template_args['payments']              = false;
1062
-            $this->_template_args['existing_reg_payments'] = [];
1063
-        }
1064
-
1065
-        $this->_template_args['edit_payment_url']   = add_query_arg(['action' => 'edit_payment'], TXN_ADMIN_URL);
1066
-        $this->_template_args['delete_payment_url'] = add_query_arg(
1067
-            ['action' => 'espresso_delete_payment'],
1068
-            TXN_ADMIN_URL
1069
-        );
1070
-
1071
-        if (isset($txn_details['invoice_number'])) {
1072
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1073
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1074
-                'Invoice Number',
1075
-                'event_espresso'
1076
-            );
1077
-        }
1078
-
1079
-        $this->_template_args['txn_details']['registration_session']['value'] =
1080
-            $this->_transaction->primary_registration() instanceof EE_Registration
1081
-                ? $this->_transaction->primary_registration()->session_ID()
1082
-                : null;
1083
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1084
-            'Registration Session',
1085
-            'event_espresso'
1086
-        );
1087
-
1088
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1089
-            ? $this->_session['ip_address']
1090
-            : '';
1091
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1092
-            'Transaction placed from IP',
1093
-            'event_espresso'
1094
-        );
1095
-
1096
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1097
-            ? $this->_session['user_agent']
1098
-            : '';
1099
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1100
-            'Registrant User Agent',
1101
-            'event_espresso'
1102
-        );
1103
-
1104
-        $reg_steps = '<ul>';
1105
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1106
-            if ($reg_step_status === true) {
1107
-                $reg_steps .= '<li style="color:#70cc50">'
1108
-                              . sprintf(
1109
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1110
-                                  ucwords(str_replace('_', ' ', $reg_step))
1111
-                              )
1112
-                              . '</li>';
1113
-            } elseif ($reg_step_status !== false && is_numeric($reg_step_status)) {
1114
-                $reg_steps .= '<li style="color:#2EA2CC">'
1115
-                              . sprintf(
1116
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1117
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1118
-                                  date(
1119
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1120
-                                      $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1121
-                                  )
1122
-                              )
1123
-                              . '</li>';
1124
-            } else {
1125
-                $reg_steps .= '<li style="color:#E76700">'
1126
-                              . sprintf(
1127
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1128
-                                  ucwords(str_replace('_', ' ', $reg_step))
1129
-                              )
1130
-                              . '</li>';
1131
-            }
1132
-        }
1133
-        $reg_steps                                                 .= '</ul>';
1134
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1135
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1136
-            'Registration Step Progress',
1137
-            'event_espresso'
1138
-        );
1139
-
1140
-
1141
-        $this->_get_registrations_to_apply_payment_to();
1142
-        $this->_get_payment_methods($payments);
1143
-        $this->_get_payment_status_array();
1144
-        $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1145
-
1146
-        $this->_template_args['transaction_form_url']    = add_query_arg(
1147
-            [
1148
-                'action'  => 'edit_transaction',
1149
-                'process' => 'transaction',
1150
-            ],
1151
-            TXN_ADMIN_URL
1152
-        );
1153
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(
1154
-            [
1155
-                'page'   => 'espresso_transactions',
1156
-                'action' => 'espresso_apply_payment',
1157
-            ],
1158
-            WP_AJAX_URL
1159
-        );
1160
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(
1161
-            [
1162
-                'page'   => 'espresso_transactions',
1163
-                'action' => 'espresso_delete_payment',
1164
-            ],
1165
-            WP_AJAX_URL
1166
-        );
1167
-
1168
-        $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1169
-
1170
-        // 'espresso_delete_payment_nonce'
1171
-
1172
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1173
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * _get_registration_payment_IDs
1179
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1180
-     *
1181
-     * @access protected
1182
-     * @param EE_Payment[] $payments
1183
-     * @return array
1184
-     * @throws EE_Error
1185
-     * @throws InvalidArgumentException
1186
-     * @throws InvalidDataTypeException
1187
-     * @throws InvalidInterfaceException
1188
-     * @throws ReflectionException
1189
-     */
1190
-    protected function _get_registration_payment_IDs($payments = [])
1191
-    {
1192
-        $existing_reg_payments = [];
1193
-        // get all reg payments for these payments
1194
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(
1195
-            [
1196
-                [
1197
-                    'PAY_ID' => [
1198
-                        'IN',
1199
-                        array_keys($payments),
1200
-                    ],
1201
-                ],
1202
-            ]
1203
-        );
1204
-        if (! empty($reg_payments)) {
1205
-            foreach ($payments as $payment) {
1206
-                if (! $payment instanceof EE_Payment) {
1207
-                    continue;
1208
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1209
-                    $existing_reg_payments[ $payment->ID() ] = [];
1210
-                }
1211
-                foreach ($reg_payments as $reg_payment) {
1212
-                    if (
1213
-                        $reg_payment instanceof EE_Registration_Payment
1214
-                        && $reg_payment->payment_ID() === $payment->ID()
1215
-                    ) {
1216
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1217
-                    }
1218
-                }
1219
-            }
1220
-        }
1221
-
1222
-        return $existing_reg_payments;
1223
-    }
1224
-
1225
-
1226
-    /**
1227
-     * _get_registrations_to_apply_payment_to
1228
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1229
-     * which allows the admin to only apply the payment to the specific registrations
1230
-     *
1231
-     * @access protected
1232
-     * @return void
1233
-     * @throws EE_Error
1234
-     * @throws InvalidArgumentException
1235
-     * @throws InvalidDataTypeException
1236
-     * @throws InvalidInterfaceException
1237
-     * @throws ReflectionException
1238
-     */
1239
-    protected function _get_registrations_to_apply_payment_to()
1240
-    {
1241
-        // we want any registration with an active status (ie: not deleted or cancelled)
1242
-        $query_params                      = [
1243
-            [
1244
-                'STS_ID' => [
1245
-                    'IN',
1246
-                    [
1247
-                        EEM_Registration::status_id_approved,
1248
-                        EEM_Registration::status_id_pending_payment,
1249
-                        EEM_Registration::status_id_not_approved,
1250
-                    ],
1251
-                ],
1252
-            ],
1253
-        ];
1254
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1255
-            '',
1256
-            'txn-admin-apply-payment-to-registrations-dv',
1257
-            '',
1258
-            'clear: both; margin: 1.5em 0 0; display: none;'
1259
-        );
1260
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1261
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl striped');
1262
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1263
-            EEH_HTML::tr(
1264
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1265
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1266
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1267
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1268
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1269
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1270
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1271
-            )
1272
-        );
1273
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1274
-        // get registrations for TXN
1275
-        $registrations         = $this->_transaction->registrations($query_params);
1276
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1277
-        foreach ($registrations as $registration) {
1278
-            if ($registration instanceof EE_Registration) {
1279
-                $attendee_name                     = $registration->attendee() instanceof EE_Attendee
1280
-                    ? $registration->attendee()->full_name()
1281
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1282
-                $owing                             = $registration->final_price() - $registration->paid();
1283
-                $taxable                           = $registration->ticket()->taxable()
1284
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1285
-                    : '';
1286
-                $checked                           = empty($existing_reg_payments)
1287
-                                                     || in_array($registration->ID(), $existing_reg_payments, true)
1288
-                    ? ' checked="checked"'
1289
-                    : '';
1290
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1291
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1292
-                    EEH_HTML::td($registration->ID()) .
1293
-                    EEH_HTML::td($attendee_name) .
1294
-                    EEH_HTML::td(
1295
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1296
-                    ) .
1297
-                    EEH_HTML::td($registration->event_name()) .
1298
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1299
-                    EEH_HTML::td(
1300
-                        EEH_Template::format_currency($owing),
1301
-                        '',
1302
-                        'txn-admin-payment-owing-td jst-cntr'
1303
-                    ) .
1304
-                    EEH_HTML::td(
1305
-                        '<input type="checkbox" value="' . $registration->ID()
1306
-                        . '" name="txn_admin_payment[registrations]"'
1307
-                        . $checked . $disabled . '>',
1308
-                        '',
1309
-                        'jst-cntr'
1310
-                    ),
1311
-                    'apply-payment-registration-row-' . $registration->ID()
1312
-                );
1313
-            }
1314
-        }
1315
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1316
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1317
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1318
-        $registrations_to_apply_payment_to                         .= EEH_HTML::p(
1319
-            esc_html__(
1320
-                'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1321
-                'event_espresso'
1322
-            ),
1323
-            '',
1324
-            'clear description'
1325
-        );
1326
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1327
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1328
-    }
1329
-
1330
-
1331
-    /**
1332
-     * _get_reg_status_selection
1333
-     *
1334
-     * @return void
1335
-     * @throws EE_Error
1336
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1337
-     *         instead of events.
1338
-     * @access protected
1339
-     */
1340
-    protected function _get_reg_status_selection()
1341
-    {
1342
-        // first get all possible statuses
1343
-        $statuses = EEM_Registration::reg_status_array([], true);
1344
-        // let's add a "don't change" option.
1345
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1346
-        $status_array                                        = array_merge($status_array, $statuses);
1347
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1348
-            'txn_reg_status_change[reg_status]',
1349
-            $status_array,
1350
-            'NAN',
1351
-            'id="txn-admin-payment-reg-status-inp"',
1352
-            'txn-reg-status-change-reg-status'
1353
-        );
1354
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1355
-            'delete_txn_reg_status_change[reg_status]',
1356
-            $status_array,
1357
-            'NAN',
1358
-            'delete-txn-admin-payment-reg-status-inp',
1359
-            'delete-txn-reg-status-change-reg-status'
1360
-        );
1361
-    }
1362
-
1363
-
1364
-    /**
1365
-     *    _get_payment_methods
1366
-     * Gets all the payment methods available generally, or the ones that are already
1367
-     * selected on these payments (in case their payment methods are no longer active).
1368
-     * Has the side-effect of updating the template args' payment_methods item
1369
-     *
1370
-     * @access private
1371
-     * @param EE_Payment[] to show on this page
1372
-     * @return void
1373
-     * @throws EE_Error
1374
-     * @throws InvalidArgumentException
1375
-     * @throws InvalidDataTypeException
1376
-     * @throws InvalidInterfaceException
1377
-     * @throws ReflectionException
1378
-     */
1379
-    private function _get_payment_methods($payments = [])
1380
-    {
1381
-        $payment_methods_of_payments = [];
1382
-        foreach ($payments as $payment) {
1383
-            if ($payment instanceof EE_Payment) {
1384
-                $payment_methods_of_payments[] = $payment->ID();
1385
-            }
1386
-        }
1387
-        if ($payment_methods_of_payments) {
1388
-            $query_args = [
1389
-                [
1390
-                    'OR*payment_method_for_payment' => [
1391
-                        'PMD_ID'    => ['IN', $payment_methods_of_payments],
1392
-                        'PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%'],
1393
-                    ],
1394
-                ],
1395
-            ];
1396
-        } else {
1397
-            $query_args = [['PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%']]];
1398
-        }
1399
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1400
-    }
1401
-
1402
-
1403
-    /**
1404
-     * txn_attendees_meta_box
1405
-     *    generates HTML for the Attendees Transaction main meta box
1406
-     *
1407
-     * @access public
1408
-     * @param WP_Post $post
1409
-     * @param array   $metabox
1410
-     * @return void
1411
-     * @throws DomainException
1412
-     * @throws EE_Error
1413
-     * @throws InvalidArgumentException
1414
-     * @throws InvalidDataTypeException
1415
-     * @throws InvalidInterfaceException
1416
-     * @throws ReflectionException
1417
-     */
1418
-    public function txn_attendees_meta_box($post, $metabox = ['args' => []])
1419
-    {
1420
-
1421
-        /** @noinspection NonSecureExtractUsageInspection */
1422
-        extract($metabox['args']);
1423
-        $this->_template_args['post']            = $post;
1424
-        $this->_template_args['event_attendees'] = [];
1425
-        // process items in cart
1426
-        $line_items = $this->_transaction->get_many_related(
1427
-            'Line_Item',
1428
-            [['LIN_type' => 'line-item']]
1429
-        );
1430
-        if (! empty($line_items)) {
1431
-            foreach ($line_items as $item) {
1432
-                if ($item instanceof EE_Line_Item) {
1433
-                    switch ($item->OBJ_type()) {
1434
-                        case 'Event':
1435
-                            break;
1436
-                        case 'Ticket':
1437
-                            $ticket = $item->ticket();
1438
-                            // right now we're only handling tickets here.
1439
-                            // Cause its expected that only tickets will have attendees right?
1440
-                            if (! $ticket instanceof EE_Ticket) {
1441
-                                break;
1442
-                            }
1443
-                            try {
1444
-                                $event_name = $ticket->get_event_name();
1445
-                            } catch (Exception $e) {
1446
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1447
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1448
-                            }
1449
-                            $event_name   .= ' - ' . $item->name();
1450
-                            $ticket_price = EEH_Template::format_currency($item->unit_price());
1451
-                            // now get all of the registrations for this transaction that use this ticket
1452
-                            $registrations = $ticket->registrations(
1453
-                                [['TXN_ID' => $this->_transaction->ID()]]
1454
-                            );
1455
-                            foreach ($registrations as $registration) {
1456
-                                if (! $registration instanceof EE_Registration) {
1457
-                                    break;
1458
-                                }
1459
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1460
-                                    = $registration->status_ID();
1461
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1462
-                                    = $registration->count();
1463
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1464
-                                    = $event_name;
1465
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1466
-                                    = $ticket_price;
1467
-                                // attendee info
1468
-                                $attendee = $registration->get_first_related('Attendee');
1469
-                                if ($attendee instanceof EE_Attendee) {
1470
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1471
-                                        = $attendee->ID();
1472
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1473
-                                        = $attendee->full_name();
1474
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1475
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1476
-                                          . esc_html__(
1477
-                                              ' Event',
1478
-                                              'event_espresso'
1479
-                                          )
1480
-                                          . '">' . $attendee->email() . '</a>';
1481
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1482
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1483
-                                } else {
1484
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']   = '';
1485
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1486
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']    = '';
1487
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']  = '';
1488
-                                }
1489
-                            }
1490
-                            break;
1491
-                    }
1492
-                }
1493
-            }
1494
-
1495
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1496
-                [
1497
-                    'action'  => 'edit_transaction',
1498
-                    'process' => 'attendees',
1499
-                ],
1500
-                TXN_ADMIN_URL
1501
-            );
1502
-            echo EEH_Template::display_template(
1503
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1504
-                $this->_template_args,
1505
-                true
1506
-            );
1507
-        } else {
1508
-            printf(
1509
-                esc_html__(
1510
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1511
-                    'event_espresso'
1512
-                ),
1513
-                '<p class="important-notice">',
1514
-                '</p>'
1515
-            );
1516
-        }
1517
-    }
1518
-
1519
-
1520
-    /**
1521
-     * txn_registrant_side_meta_box
1522
-     * generates HTML for the Edit Transaction side meta box
1523
-     *
1524
-     * @access public
1525
-     * @return void
1526
-     * @throws DomainException
1527
-     * @throws EE_Error
1528
-     * @throws InvalidArgumentException
1529
-     * @throws InvalidDataTypeException
1530
-     * @throws InvalidInterfaceException
1531
-     * @throws ReflectionException
1532
-     */
1533
-    public function txn_registrant_side_meta_box()
1534
-    {
1535
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1536
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1537
-            : null;
1538
-        if (! $primary_att instanceof EE_Attendee) {
1539
-            $this->_template_args['no_attendee_message'] = esc_html__(
1540
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1541
-                'event_espresso'
1542
-            );
1543
-            $primary_att                           = EEM_Attendee::instance()->create_default_object();
1544
-        }
1545
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1546
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1547
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1548
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1549
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1550
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1551
-            [
1552
-                'action' => 'edit_attendee',
1553
-                'post'   => $primary_att->ID(),
1554
-            ],
1555
-            REG_ADMIN_URL
1556
-        );
1557
-        // get formatted address for registrant
1558
-        $formatted_address = EEH_Address::format($primary_att);
1559
-        $formatted_address = $formatted_address !== '<div class="espresso-address-dv"><div></div></div>'
1560
-            ? $formatted_address
1561
-            : '';
1562
-        $this->_template_args['formatted_address'] = $formatted_address;
1563
-        echo EEH_Template::display_template(
1564
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1565
-            $this->_template_args,
1566
-            true
1567
-        );
1568
-    }
1569
-
1570
-
1571
-    /**
1572
-     * txn_billing_info_side_meta_box
1573
-     *    generates HTML for the Edit Transaction side meta box
1574
-     *
1575
-     * @access public
1576
-     * @return void
1577
-     * @throws DomainException
1578
-     * @throws EE_Error
1579
-     * @throws ReflectionException
1580
-     */
1581
-    public function txn_billing_info_side_meta_box()
1582
-    {
1583
-
1584
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1585
-        $this->_template_args['billing_form_url'] = add_query_arg(
1586
-            ['action' => 'edit_transaction', 'process' => 'billing'],
1587
-            TXN_ADMIN_URL
1588
-        );
1589
-
1590
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1591
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1592
-    }
1593
-
1594
-
1595
-    /**
1596
-     * apply_payments_or_refunds
1597
-     *    registers a payment or refund made towards a transaction
1598
-     *
1599
-     * @access public
1600
-     * @return void
1601
-     * @throws EE_Error
1602
-     * @throws InvalidArgumentException
1603
-     * @throws ReflectionException
1604
-     * @throws RuntimeException
1605
-     * @throws InvalidDataTypeException
1606
-     * @throws InvalidInterfaceException
1607
-     */
1608
-    public function apply_payments_or_refunds()
1609
-    {
1610
-        $json_response_data = ['return_data' => false];
1611
-        $valid_data         = $this->_validate_payment_request_data();
1612
-        $has_access         = EE_Registry::instance()->CAP->current_user_can(
1613
-            'ee_edit_payments',
1614
-            'apply_payment_or_refund_from_registration_details'
1615
-        );
1616
-        if (! empty($valid_data) && $has_access) {
1617
-            $PAY_ID = $valid_data['PAY_ID'];
1618
-            // save  the new payment
1619
-            $payment = $this->_create_payment_from_request_data($valid_data);
1620
-            // get the TXN for this payment
1621
-            $transaction = $payment->transaction();
1622
-            // verify transaction
1623
-            if ($transaction instanceof EE_Transaction) {
1624
-                // calculate_total_payments_and_update_status
1625
-                $this->_process_transaction_payments($transaction);
1626
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1627
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1628
-                // apply payment to registrations (if applicable)
1629
-                if (! empty($REG_IDs)) {
1630
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1631
-                    $this->_maybe_send_notifications();
1632
-                    // now process status changes for the same registrations
1633
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1634
-                }
1635
-                $this->_maybe_send_notifications($payment);
1636
-                // prepare to render page
1637
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1638
-                do_action(
1639
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1640
-                    $transaction,
1641
-                    $payment
1642
-                );
1643
-            } else {
1644
-                EE_Error::add_error(
1645
-                    esc_html__(
1646
-                        'A valid Transaction for this payment could not be retrieved.',
1647
-                        'event_espresso'
1648
-                    ),
1649
-                    __FILE__,
1650
-                    __FUNCTION__,
1651
-                    __LINE__
1652
-                );
1653
-            }
1654
-        } elseif ($has_access) {
1655
-            EE_Error::add_error(
1656
-                esc_html__(
1657
-                    'The payment form data could not be processed. Please try again.',
1658
-                    'event_espresso'
1659
-                ),
1660
-                __FILE__,
1661
-                __FUNCTION__,
1662
-                __LINE__
1663
-            );
1664
-        } else {
1665
-            EE_Error::add_error(
1666
-                esc_html__(
1667
-                    'You do not have access to apply payments or refunds to a registration.',
1668
-                    'event_espresso'
1669
-                ),
1670
-                __FILE__,
1671
-                __FUNCTION__,
1672
-                __LINE__
1673
-            );
1674
-        }
1675
-        $notices              = EE_Error::get_notices(
1676
-            false,
1677
-            false,
1678
-            false
1679
-        );
1680
-        $this->_template_args = [
1681
-            'data'    => $json_response_data,
1682
-            'error'   => $notices['errors'],
1683
-            'success' => $notices['success'],
1684
-        ];
1685
-        $this->_return_json();
1686
-    }
1687
-
1688
-
1689
-    /**
1690
-     * _validate_payment_request_data
1691
-     *
1692
-     * @return array
1693
-     * @throws EE_Error
1694
-     * @throws InvalidArgumentException
1695
-     * @throws InvalidDataTypeException
1696
-     * @throws InvalidInterfaceException
1697
-     */
1698
-    protected function _validate_payment_request_data()
1699
-    {
1700
-        if (! $this->request->requestParamIsSet('txn_admin_payment')) {
1701
-            return [];
1702
-        }
1703
-        $payment_form = $this->_generate_payment_form_section();
1704
-        try {
1705
-            if ($payment_form->was_submitted()) {
1706
-                $payment_form->receive_form_submission();
1707
-                if (! $payment_form->is_valid()) {
1708
-                    $submission_error_messages = [];
1709
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1710
-                        if ($validation_error instanceof EE_Validation_Error) {
1711
-                            $form_input = $validation_error->get_form_section();
1712
-                            $submission_error_messages[] = sprintf(
1713
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1714
-                                $form_input instanceof EE_Form_Input_Base ? $form_input->html_label_text() : '',
1715
-                                $validation_error->getMessage()
1716
-                            );
1717
-                        }
1718
-                    }
1719
-                    EE_Error::add_error(
1720
-                        implode('<br />', $submission_error_messages),
1721
-                        __FILE__,
1722
-                        __FUNCTION__,
1723
-                        __LINE__
1724
-                    );
1725
-                    return [];
1726
-                }
1727
-            }
1728
-        } catch (EE_Error $e) {
1729
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1730
-            return [];
1731
-        }
1732
-
1733
-        return $payment_form->valid_data();
1734
-    }
1735
-
1736
-
1737
-    /**
1738
-     * _generate_payment_form_section
1739
-     *
1740
-     * @return EE_Form_Section_Proper
1741
-     * @throws EE_Error
1742
-     */
1743
-    protected function _generate_payment_form_section()
1744
-    {
1745
-        return new EE_Form_Section_Proper(
1746
-            [
1747
-                'name'        => 'txn_admin_payment',
1748
-                'subsections' => [
1749
-                    'PAY_ID'          => new EE_Text_Input(
1750
-                        [
1751
-                            'default'               => 0,
1752
-                            'required'              => false,
1753
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1754
-                            'validation_strategies' => [new EE_Int_Normalization()],
1755
-                        ]
1756
-                    ),
1757
-                    'TXN_ID'          => new EE_Text_Input(
1758
-                        [
1759
-                            'default'               => 0,
1760
-                            'required'              => true,
1761
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1762
-                            'validation_strategies' => [new EE_Int_Normalization()],
1763
-                        ]
1764
-                    ),
1765
-                    'type'            => new EE_Text_Input(
1766
-                        [
1767
-                            'default'               => 1,
1768
-                            'required'              => true,
1769
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1770
-                            'validation_strategies' => [new EE_Int_Normalization()],
1771
-                        ]
1772
-                    ),
1773
-                    'amount'          => new EE_Text_Input(
1774
-                        [
1775
-                            'default'               => 0,
1776
-                            'required'              => true,
1777
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1778
-                            'validation_strategies' => [new EE_Float_Normalization()],
1779
-                        ]
1780
-                    ),
1781
-                    'status'          => new EE_Text_Input(
1782
-                        [
1783
-                            'default'         => EEM_Payment::status_id_approved,
1784
-                            'required'        => true,
1785
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1786
-                        ]
1787
-                    ),
1788
-                    'PMD_ID'          => new EE_Text_Input(
1789
-                        [
1790
-                            'default'               => 2,
1791
-                            'required'              => true,
1792
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1793
-                            'validation_strategies' => [new EE_Int_Normalization()],
1794
-                        ]
1795
-                    ),
1796
-                    'date'            => new EE_Text_Input(
1797
-                        [
1798
-                            'default'         => time(),
1799
-                            'required'        => true,
1800
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1801
-                        ]
1802
-                    ),
1803
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1804
-                        [
1805
-                            'default'               => '',
1806
-                            'required'              => false,
1807
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1808
-                            'validation_strategies' => [
1809
-                                new EE_Max_Length_Validation_Strategy(
1810
-                                    esc_html__('Input too long', 'event_espresso'),
1811
-                                    100
1812
-                                ),
1813
-                            ],
1814
-                        ]
1815
-                    ),
1816
-                    'po_number'       => new EE_Text_Input(
1817
-                        [
1818
-                            'default'               => '',
1819
-                            'required'              => false,
1820
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1821
-                            'validation_strategies' => [
1822
-                                new EE_Max_Length_Validation_Strategy(
1823
-                                    esc_html__('Input too long', 'event_espresso'),
1824
-                                    100
1825
-                                ),
1826
-                            ],
1827
-                        ]
1828
-                    ),
1829
-                    'accounting'      => new EE_Text_Input(
1830
-                        [
1831
-                            'default'               => '',
1832
-                            'required'              => false,
1833
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1834
-                            'validation_strategies' => [
1835
-                                new EE_Max_Length_Validation_Strategy(
1836
-                                    esc_html__('Input too long', 'event_espresso'),
1837
-                                    100
1838
-                                ),
1839
-                            ],
1840
-                        ]
1841
-                    ),
1842
-                ],
1843
-            ]
1844
-        );
1845
-    }
1846
-
1847
-
1848
-    /**
1849
-     * _create_payment_from_request_data
1850
-     *
1851
-     * @param array $valid_data
1852
-     * @return EE_Payment
1853
-     * @throws EE_Error
1854
-     * @throws InvalidArgumentException
1855
-     * @throws InvalidDataTypeException
1856
-     * @throws InvalidInterfaceException
1857
-     * @throws ReflectionException
1858
-     */
1859
-    protected function _create_payment_from_request_data($valid_data)
1860
-    {
1861
-        $PAY_ID = $valid_data['PAY_ID'];
1862
-        // get payment amount
1863
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1864
-        // payments have a type value of 1 and refunds have a type value of -1
1865
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1866
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1867
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1868
-        $date    = $valid_data['date']
1869
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1870
-            : date('Y-m-d g:i a', current_time('timestamp'));
1871
-        $payment = EE_Payment::new_instance(
1872
-            [
1873
-                'TXN_ID'              => $valid_data['TXN_ID'],
1874
-                'STS_ID'              => $valid_data['status'],
1875
-                'PAY_timestamp'       => $date,
1876
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1877
-                'PMD_ID'              => $valid_data['PMD_ID'],
1878
-                'PAY_amount'          => $amount,
1879
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1880
-                'PAY_po_number'       => $valid_data['po_number'],
1881
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1882
-                'PAY_details'         => $valid_data,
1883
-                'PAY_ID'              => $PAY_ID,
1884
-            ],
1885
-            '',
1886
-            ['Y-m-d', 'g:i a']
1887
-        );
1888
-
1889
-        if (! $payment->save()) {
1890
-            EE_Error::add_error(
1891
-                sprintf(
1892
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1893
-                    $payment->ID()
1894
-                ),
1895
-                __FILE__,
1896
-                __FUNCTION__,
1897
-                __LINE__
1898
-            );
1899
-        }
1900
-
1901
-        return $payment;
1902
-    }
1903
-
1904
-
1905
-    /**
1906
-     * _process_transaction_payments
1907
-     *
1908
-     * @param EE_Transaction $transaction
1909
-     * @return void
1910
-     * @throws EE_Error
1911
-     * @throws InvalidArgumentException
1912
-     * @throws ReflectionException
1913
-     * @throws InvalidDataTypeException
1914
-     * @throws InvalidInterfaceException
1915
-     */
1916
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1917
-    {
1918
-        /** @type EE_Transaction_Payments $transaction_payments */
1919
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1920
-        // update the transaction with this payment
1921
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1922
-            EE_Error::add_success(
1923
-                esc_html__(
1924
-                    'The payment has been processed successfully.',
1925
-                    'event_espresso'
1926
-                ),
1927
-                __FILE__,
1928
-                __FUNCTION__,
1929
-                __LINE__
1930
-            );
1931
-        } else {
1932
-            EE_Error::add_error(
1933
-                esc_html__(
1934
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1935
-                    'event_espresso'
1936
-                ),
1937
-                __FILE__,
1938
-                __FUNCTION__,
1939
-                __LINE__
1940
-            );
1941
-        }
1942
-    }
1943
-
1944
-
1945
-    /**
1946
-     * _get_REG_IDs_to_apply_payment_to
1947
-     * returns a list of registration IDs that the payment will apply to
1948
-     *
1949
-     * @param EE_Payment $payment
1950
-     * @return array
1951
-     * @throws EE_Error
1952
-     * @throws InvalidArgumentException
1953
-     * @throws InvalidDataTypeException
1954
-     * @throws InvalidInterfaceException
1955
-     * @throws ReflectionException
1956
-     */
1957
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1958
-    {
1959
-        // grab array of IDs for specific registrations to apply changes to
1960
-        $REG_IDs = $this->request->getRequestParam('txn_admin_payment[registrations]', [], 'int', true);
1961
-        // nothing specified ? then get all reg IDs
1962
-        if (empty($REG_IDs)) {
1963
-            $registrations = $payment->transaction()->registrations();
1964
-            $REG_IDs       = ! empty($registrations)
1965
-                ? array_keys($registrations)
1966
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1967
-        }
1968
-
1969
-        // ensure that REG_IDs are integers and NOT strings
1970
-        return array_map('intval', $REG_IDs);
1971
-    }
1972
-
1973
-
1974
-    /**
1975
-     * @return array
1976
-     */
1977
-    public function existing_reg_payment_REG_IDs()
1978
-    {
1979
-        return $this->_existing_reg_payment_REG_IDs;
1980
-    }
1981
-
1982
-
1983
-    /**
1984
-     * @param array $existing_reg_payment_REG_IDs
1985
-     */
1986
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1987
-    {
1988
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1989
-    }
1990
-
1991
-
1992
-    /**
1993
-     * _get_existing_reg_payment_REG_IDs
1994
-     * returns a list of registration IDs that the payment is currently related to
1995
-     * as recorded in the database
1996
-     *
1997
-     * @param EE_Payment $payment
1998
-     * @return array
1999
-     * @throws EE_Error
2000
-     * @throws InvalidArgumentException
2001
-     * @throws InvalidDataTypeException
2002
-     * @throws InvalidInterfaceException
2003
-     * @throws ReflectionException
2004
-     */
2005
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
2006
-    {
2007
-        if ($this->existing_reg_payment_REG_IDs() === null) {
2008
-            // let's get any existing reg payment records for this payment
2009
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
2010
-            // but we only want the REG IDs, so grab the array keys
2011
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
2012
-                ? array_keys($existing_reg_payment_REG_IDs)
2013
-                : [];
2014
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
2015
-        }
2016
-
2017
-        return $this->existing_reg_payment_REG_IDs();
2018
-    }
2019
-
2020
-
2021
-    /**
2022
-     * _remove_existing_registration_payments
2023
-     * this calculates the difference between existing relations
2024
-     * to the supplied payment and the new list registration IDs,
2025
-     * removes any related registrations that no longer apply,
2026
-     * and then updates the registration paid fields
2027
-     *
2028
-     * @param EE_Payment $payment
2029
-     * @param int        $PAY_ID
2030
-     * @return bool;
2031
-     * @throws EE_Error
2032
-     * @throws InvalidArgumentException
2033
-     * @throws ReflectionException
2034
-     * @throws InvalidDataTypeException
2035
-     * @throws InvalidInterfaceException
2036
-     */
2037
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2038
-    {
2039
-        // newly created payments will have nothing recorded for $PAY_ID
2040
-        if (absint($PAY_ID) === 0) {
2041
-            return false;
2042
-        }
2043
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2044
-        if (empty($existing_reg_payment_REG_IDs)) {
2045
-            return false;
2046
-        }
2047
-        /** @type EE_Transaction_Payments $transaction_payments */
2048
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2049
-
2050
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
2051
-            $payment,
2052
-            [
2053
-                [
2054
-                    'PAY_ID' => $payment->ID(),
2055
-                    'REG_ID' => ['IN', $existing_reg_payment_REG_IDs],
2056
-                ],
2057
-            ]
2058
-        );
2059
-    }
2060
-
2061
-
2062
-    /**
2063
-     * _update_registration_payments
2064
-     * this applies the payments to the selected registrations
2065
-     * but only if they have not already been paid for
2066
-     *
2067
-     * @param EE_Transaction $transaction
2068
-     * @param EE_Payment     $payment
2069
-     * @param array          $REG_IDs
2070
-     * @return void
2071
-     * @throws EE_Error
2072
-     * @throws InvalidArgumentException
2073
-     * @throws ReflectionException
2074
-     * @throws RuntimeException
2075
-     * @throws InvalidDataTypeException
2076
-     * @throws InvalidInterfaceException
2077
-     */
2078
-    protected function _update_registration_payments(
2079
-        EE_Transaction $transaction,
2080
-        EE_Payment $payment,
2081
-        $REG_IDs = []
2082
-    ) {
2083
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2084
-        // so let's do that using our set of REG_IDs from the form
2085
-        $registration_query_where_params = [
2086
-            'REG_ID' => ['IN', $REG_IDs],
2087
-        ];
2088
-        // but add in some conditions regarding payment,
2089
-        // so that we don't apply payments to registrations that are free or have already been paid for
2090
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2091
-        if (! $payment->is_a_refund()) {
2092
-            $registration_query_where_params['REG_final_price']  = ['!=', 0];
2093
-            $registration_query_where_params['REG_final_price*'] = ['!=', 'REG_paid', true];
2094
-        }
2095
-        $registrations = $transaction->registrations([$registration_query_where_params]);
2096
-        if (! empty($registrations)) {
2097
-            /** @type EE_Payment_Processor $payment_processor */
2098
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2099
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
2100
-        }
2101
-    }
2102
-
2103
-
2104
-    /**
2105
-     * _process_registration_status_change
2106
-     * This processes requested registration status changes for all the registrations
2107
-     * on a given transaction and (optionally) sends out notifications for the changes.
2108
-     *
2109
-     * @param EE_Transaction $transaction
2110
-     * @param array          $REG_IDs
2111
-     * @return bool
2112
-     * @throws EE_Error
2113
-     * @throws InvalidArgumentException
2114
-     * @throws ReflectionException
2115
-     * @throws InvalidDataTypeException
2116
-     * @throws InvalidInterfaceException
2117
-     */
2118
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = [])
2119
-    {
2120
-        // first if there is no change in status then we get out.
2121
-        $reg_status = $this->request->getRequestParam('txn_reg_status_change[reg_status]', 'NAN');
2122
-        if ($reg_status === 'NAN') {
2123
-            // no error message, no change requested, just nothing to do man.
2124
-            return false;
2125
-        }
2126
-        /** @type EE_Transaction_Processor $transaction_processor */
2127
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2128
-
2129
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2130
-        return $transaction_processor->manually_update_registration_statuses(
2131
-            $transaction,
2132
-            $reg_status,
2133
-            [['REG_ID' => ['IN', $REG_IDs]]]
2134
-        );
2135
-    }
2136
-
2137
-
2138
-    /**
2139
-     * _build_payment_json_response
2140
-     *
2141
-     * @access public
2142
-     * @param EE_Payment  $payment
2143
-     * @param array       $REG_IDs
2144
-     * @param bool | null $delete_txn_reg_status_change
2145
-     * @return array
2146
-     * @throws EE_Error
2147
-     * @throws InvalidArgumentException
2148
-     * @throws InvalidDataTypeException
2149
-     * @throws InvalidInterfaceException
2150
-     * @throws ReflectionException
2151
-     */
2152
-    protected function _build_payment_json_response(
2153
-        EE_Payment $payment,
2154
-        $REG_IDs = [],
2155
-        $delete_txn_reg_status_change = null
2156
-    ) {
2157
-        // was the payment deleted ?
2158
-        if (is_bool($delete_txn_reg_status_change)) {
2159
-            return [
2160
-                'PAY_ID'                       => $payment->ID(),
2161
-                'amount'                       => $payment->amount(),
2162
-                'total_paid'                   => $payment->transaction()->paid(),
2163
-                'txn_status'                   => $payment->transaction()->status_ID(),
2164
-                'pay_status'                   => $payment->STS_ID(),
2165
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2166
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2167
-            ];
2168
-        }
2169
-
2170
-        $this->_get_payment_status_array();
2171
-        return [
2172
-            'amount'           => $payment->amount(),
2173
-            'total_paid'       => $payment->transaction()->paid(),
2174
-            'txn_status'       => $payment->transaction()->status_ID(),
2175
-            'pay_status'       => $payment->STS_ID(),
2176
-            'PAY_ID'           => $payment->ID(),
2177
-            'STS_ID'           => $payment->STS_ID(),
2178
-            'status'           => self::$_pay_status[ $payment->STS_ID() ],
2179
-            'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2180
-            'method'           => strtoupper($payment->source()),
2181
-            'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2182
-            'gateway'          => $payment->payment_method()
2183
-                ? $payment->payment_method()->admin_name()
2184
-                : esc_html__('Unknown', 'event_espresso'),
2185
-            'gateway_response' => $payment->gateway_response(),
2186
-            'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2187
-            'po_number'        => $payment->po_number(),
2188
-            'extra_accntng'    => $payment->extra_accntng(),
2189
-            'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2190
-        ];
2191
-    }
2192
-
2193
-
2194
-    /**
2195
-     * delete_payment
2196
-     *    delete a payment or refund made towards a transaction
2197
-     *
2198
-     * @access public
2199
-     * @return void
2200
-     * @throws EE_Error
2201
-     * @throws InvalidArgumentException
2202
-     * @throws ReflectionException
2203
-     * @throws InvalidDataTypeException
2204
-     * @throws InvalidInterfaceException
2205
-     */
2206
-    public function delete_payment()
2207
-    {
2208
-        $json_response_data = ['return_data' => false];
2209
-        $PAY_ID = $this->request->getRequestParam('delete_txn_admin_payment[PAY_ID]', 0, 'int');
2210
-
2211
-        $can_delete         = EE_Registry::instance()->CAP->current_user_can(
2212
-            'ee_delete_payments',
2213
-            'delete_payment_from_registration_details'
2214
-        );
2215
-        if ($PAY_ID && $can_delete) {
2216
-            $delete_txn_reg_status_change = $this->request->getRequestParam(
2217
-                'delete_txn_reg_status_change',
2218
-                false,
2219
-                'bool'
2220
-            );
2221
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2222
-            if ($payment instanceof EE_Payment) {
2223
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2224
-                /** @type EE_Transaction_Payments $transaction_payments */
2225
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2226
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2227
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2228
-                        $payment,
2229
-                        $REG_IDs,
2230
-                        $delete_txn_reg_status_change
2231
-                    );
2232
-                    if ($delete_txn_reg_status_change) {
2233
-                        // MAKE sure we also add the delete_txn_req_status_change to the
2234
-                        // request data because that's how messages will be looking for it.
2235
-                        $this->request->setRequestParam('txn_reg_status_change', $delete_txn_reg_status_change);
2236
-                        $this->_maybe_send_notifications();
2237
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2238
-                    }
2239
-                }
2240
-            } else {
2241
-                EE_Error::add_error(
2242
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2243
-                    __FILE__,
2244
-                    __FUNCTION__,
2245
-                    __LINE__
2246
-                );
2247
-            }
2248
-        } elseif ($can_delete) {
2249
-            EE_Error::add_error(
2250
-                esc_html__(
2251
-                    'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2252
-                    'event_espresso'
2253
-                ),
2254
-                __FILE__,
2255
-                __FUNCTION__,
2256
-                __LINE__
2257
-            );
2258
-        } else {
2259
-            EE_Error::add_error(
2260
-                esc_html__(
2261
-                    'You do not have access to delete a payment.',
2262
-                    'event_espresso'
2263
-                ),
2264
-                __FILE__,
2265
-                __FUNCTION__,
2266
-                __LINE__
2267
-            );
2268
-        }
2269
-        $notices              = EE_Error::get_notices(false, false, false);
2270
-        $this->_template_args = [
2271
-            'data'      => $json_response_data,
2272
-            'success'   => $notices['success'],
2273
-            'error'     => $notices['errors'],
2274
-            'attention' => $notices['attention'],
2275
-        ];
2276
-        $this->_return_json();
2277
-    }
2278
-
2279
-
2280
-    /**
2281
-     * _registration_payment_data_array
2282
-     * adds info for 'owing' and 'paid' for each registration to the json response
2283
-     *
2284
-     * @access protected
2285
-     * @param array $REG_IDs
2286
-     * @return array
2287
-     * @throws EE_Error
2288
-     * @throws InvalidArgumentException
2289
-     * @throws InvalidDataTypeException
2290
-     * @throws InvalidInterfaceException
2291
-     * @throws ReflectionException
2292
-     */
2293
-    protected function _registration_payment_data_array($REG_IDs)
2294
-    {
2295
-        $registration_payment_data = [];
2296
-        // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2297
-        if (! empty($REG_IDs)) {
2298
-            $registrations = EEM_Registration::instance()->get_all([['REG_ID' => ['IN', $REG_IDs]]]);
2299
-            foreach ($registrations as $registration) {
2300
-                if ($registration instanceof EE_Registration) {
2301
-                    $registration_payment_data[ $registration->ID() ] = [
2302
-                        'paid'  => $registration->pretty_paid(),
2303
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2304
-                    ];
2305
-                }
2306
-            }
2307
-        }
2308
-
2309
-        return $registration_payment_data;
2310
-    }
2311
-
2312
-
2313
-    /**
2314
-     * _maybe_send_notifications
2315
-     * determines whether or not the admin has indicated that notifications should be sent.
2316
-     * If so, will toggle a filter switch for delivering registration notices.
2317
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2318
-     *
2319
-     * @access protected
2320
-     * @param EE_Payment | null $payment
2321
-     */
2322
-    protected function _maybe_send_notifications($payment = null)
2323
-    {
2324
-        switch ($payment instanceof EE_Payment) {
2325
-            // payment notifications
2326
-            case true:
2327
-                if ($this->request->getRequestParam('txn_payments[send_notifications]', false, 'bool')) {
2328
-                    $this->_process_payment_notification($payment);
2329
-                }
2330
-                break;
2331
-            // registration notifications
2332
-            case false:
2333
-                if ($this->request->getRequestParam('txn_reg_status_change[send_notifications]', false, 'bool')) {
2334
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2335
-                }
2336
-                break;
2337
-        }
2338
-    }
2339
-
2340
-
2341
-    /**
2342
-     * _send_payment_reminder
2343
-     *    generates HTML for the View Transaction Details Admin page
2344
-     *
2345
-     * @access protected
2346
-     * @return void
2347
-     * @throws EE_Error
2348
-     * @throws InvalidArgumentException
2349
-     * @throws InvalidDataTypeException
2350
-     * @throws InvalidInterfaceException
2351
-     */
2352
-    protected function _send_payment_reminder()
2353
-    {
2354
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2355
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2356
-        $redirect_to = $this->request->getRequestParam('redirect_to');
2357
-        $query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2358
-        do_action(
2359
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2360
-            $transaction
2361
-        );
2362
-        $this->_redirect_after_action(
2363
-            false,
2364
-            esc_html__('payment reminder', 'event_espresso'),
2365
-            esc_html__('sent', 'event_espresso'),
2366
-            $query_args,
2367
-            true
2368
-        );
2369
-    }
2370
-
2371
-
2372
-    /**
2373
-     *  get_transactions
2374
-     *    get transactions for given parameters (used by list table)
2375
-     *
2376
-     * @param int     $per_page how many transactions displayed per page
2377
-     * @param boolean $count   return the count or objects
2378
-     * @param string  $view
2379
-     * @return EE_Transaction[]|int int = count || array of transaction objects
2380
-     * @throws EE_Error
2381
-     * @throws InvalidArgumentException
2382
-     * @throws InvalidDataTypeException
2383
-     * @throws InvalidInterfaceException
2384
-     */
2385
-    public function get_transactions($per_page, $count = false, $view = '')
2386
-    {
2387
-        $start_date = wp_strip_all_tags(
2388
-            $this->request->getRequestParam('txn-filter-start-date', date('m/d/Y', strtotime('-10 year')))
2389
-        );
2390
-        $end_date = wp_strip_all_tags(
2391
-            $this->request->getRequestParam('txn-filter-end-date', date('m/d/Y'))
2392
-        );
2393
-
2394
-        // make sure our timestamps start and end right at the boundaries for each day
2395
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2396
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2397
-
2398
-
2399
-        // convert to timestamps
2400
-        $start_date = strtotime($start_date);
2401
-        $end_date   = strtotime($end_date);
2402
-
2403
-        // makes sure start date is the lowest value and vice versa
2404
-        $start_date = min($start_date, $end_date);
2405
-        $end_date   = max($start_date, $end_date);
2406
-
2407
-        // convert to correct format for query
2408
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2409
-            'TXN_timestamp',
2410
-            date('Y-m-d H:i:s', $start_date),
2411
-            'Y-m-d H:i:s'
2412
-        );
2413
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2414
-            'TXN_timestamp',
2415
-            date('Y-m-d H:i:s', $end_date),
2416
-            'Y-m-d H:i:s'
2417
-        );
2418
-
2419
-
2420
-        // set orderby
2421
-        $orderby = $this->request->getRequestParam('orderby');
2422
-
2423
-        switch ($orderby) {
2424
-            case 'TXN_ID':
2425
-                break;
2426
-            case 'ATT_fname':
2427
-                $orderby = 'Registration.Attendee.ATT_fname';
2428
-                break;
2429
-            case 'event_name':
2430
-                $orderby = 'Registration.Event.EVT_name';
2431
-                break;
2432
-            default: // 'TXN_timestamp'
2433
-                $orderby = 'TXN_timestamp';
2434
-        }
2435
-
2436
-        $sort         = $this->request->getRequestParam('order', 'DESC');
2437
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
2438
-
2439
-        $per_page = absint($per_page) ? $per_page : 10;
2440
-        $per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
2441
-
2442
-        $offset = ($current_page - 1) * $per_page;
2443
-        $limit  = [$offset, $per_page];
2444
-
2445
-        $_where = [
2446
-            'TXN_timestamp'          => ['BETWEEN', [$start_date, $end_date]],
2447
-            'Registration.REG_count' => 1,
2448
-        ];
2449
-
2450
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2451
-        if ($EVT_ID) {
2452
-            $_where['Registration.EVT_ID'] = $EVT_ID;
2453
-        }
2454
-
2455
-        $search_term = $this->request->getRequestParam('s');
2456
-        if ($search_term) {
2457
-            $search_term = '%' . $search_term . '%';
2458
-            $_where['OR']  = [
2459
-                'Registration.Event.EVT_name'         => ['LIKE', $search_term],
2460
-                'Registration.Event.EVT_desc'         => ['LIKE', $search_term],
2461
-                'Registration.Event.EVT_short_desc'   => ['LIKE', $search_term],
2462
-                'Registration.Attendee.ATT_full_name' => ['LIKE', $search_term],
2463
-                'Registration.Attendee.ATT_fname'     => ['LIKE', $search_term],
2464
-                'Registration.Attendee.ATT_lname'     => ['LIKE', $search_term],
2465
-                'Registration.Attendee.ATT_short_bio' => ['LIKE', $search_term],
2466
-                'Registration.Attendee.ATT_email'     => ['LIKE', $search_term],
2467
-                'Registration.Attendee.ATT_address'   => ['LIKE', $search_term],
2468
-                'Registration.Attendee.ATT_address2'  => ['LIKE', $search_term],
2469
-                'Registration.Attendee.ATT_city'      => ['LIKE', $search_term],
2470
-                'Registration.REG_final_price'        => ['LIKE', $search_term],
2471
-                'Registration.REG_code'               => ['LIKE', $search_term],
2472
-                'Registration.REG_count'              => ['LIKE', $search_term],
2473
-                'Registration.REG_group_size'         => ['LIKE', $search_term],
2474
-                'Registration.Ticket.TKT_name'        => ['LIKE', $search_term],
2475
-                'Registration.Ticket.TKT_description' => ['LIKE', $search_term],
2476
-                'Payment.PAY_source'                  => ['LIKE', $search_term],
2477
-                'Payment.Payment_Method.PMD_name'     => ['LIKE', $search_term],
2478
-                'TXN_session_data'                    => ['LIKE', $search_term],
2479
-                'Payment.PAY_txn_id_chq_nmbr'         => ['LIKE', $search_term],
2480
-            ];
2481
-        }
2482
-
2483
-        $status = $this->request->getRequestParam('status');
2484
-        // failed transactions
2485
-        $failed     = (! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2486
-        $abandoned  = (! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2487
-        $incomplete = (! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2488
-
2489
-        if ($failed) {
2490
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2491
-        } elseif ($abandoned) {
2492
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2493
-        } elseif ($incomplete) {
2494
-            $_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2495
-        } else {
2496
-            $_where['STS_ID']  = ['!=', EEM_Transaction::failed_status_code];
2497
-            $_where['STS_ID*'] = ['!=', EEM_Transaction::abandoned_status_code];
2498
-        }
2499
-
2500
-        $query_params = apply_filters(
2501
-            'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2502
-            [
2503
-                $_where,
2504
-                'order_by'                 => [$orderby => $sort],
2505
-                'limit'                    => $limit,
2506
-                'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2507
-            ],
2508
-            $this->request->requestParams(),
2509
-            $view,
2510
-            $count
2511
-        );
2512
-
2513
-        return $count
2514
-            ? EEM_Transaction::instance()->count([$query_params[0]], 'TXN_ID', true)
2515
-            : EEM_Transaction::instance()->get_all($query_params);
2516
-    }
2517
-
2518
-
2519
-    /**
2520
-     * @throws EE_Error
2521
-     * @throws InvalidArgumentException
2522
-     * @throws InvalidDataTypeException
2523
-     * @throws InvalidInterfaceException
2524
-     * @throws ReflectionException
2525
-     * @throws RuntimeException
2526
-     * @since 4.9.79.p
2527
-     */
2528
-    public function recalculateLineItems()
2529
-    {
2530
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2531
-        /** @var EE_Transaction $transaction */
2532
-        $transaction     = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2533
-        $success         = $transaction->recalculateLineItems();
2534
-        $redirect_to = $this->request->getRequestParam('redirect_to');
2535
-        $query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2536
-        $this->_redirect_after_action(
2537
-            $success,
2538
-            esc_html__('Transaction taxes and totals', 'event_espresso'),
2539
-            esc_html__('recalculated', 'event_espresso'),
2540
-            $query_args,
2541
-            true
2542
-        );
2543
-    }
16
+	/**
17
+	 * @var EE_Transaction
18
+	 */
19
+	private $_transaction;
20
+
21
+	/**
22
+	 * @var EE_Session
23
+	 */
24
+	private $_session;
25
+
26
+	/**
27
+	 * @var array $_txn_status
28
+	 */
29
+	private static $_txn_status;
30
+
31
+	/**
32
+	 * @var array $_pay_status
33
+	 */
34
+	private static $_pay_status;
35
+
36
+	/**
37
+	 * @var array $_existing_reg_payment_REG_IDs
38
+	 */
39
+	protected $_existing_reg_payment_REG_IDs;
40
+
41
+
42
+	/**
43
+	 *    _init_page_props
44
+	 *
45
+	 * @return void
46
+	 */
47
+	protected function _init_page_props()
48
+	{
49
+		$this->page_slug        = TXN_PG_SLUG;
50
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
51
+		$this->_admin_base_url  = TXN_ADMIN_URL;
52
+		$this->_admin_base_path = TXN_ADMIN;
53
+	}
54
+
55
+
56
+	/**
57
+	 *    _ajax_hooks
58
+	 *
59
+	 * @return void
60
+	 */
61
+	protected function _ajax_hooks()
62
+	{
63
+		add_action('wp_ajax_espresso_apply_payment', [$this, 'apply_payments_or_refunds']);
64
+		add_action('wp_ajax_espresso_apply_refund', [$this, 'apply_payments_or_refunds']);
65
+		add_action('wp_ajax_espresso_delete_payment', [$this, 'delete_payment']);
66
+	}
67
+
68
+
69
+	/**
70
+	 *    _define_page_props
71
+	 *
72
+	 * @return void
73
+	 */
74
+	protected function _define_page_props()
75
+	{
76
+		$this->_admin_page_title = $this->page_label;
77
+		$this->_labels           = [
78
+			'buttons' => [
79
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
80
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
81
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
82
+			],
83
+		];
84
+	}
85
+
86
+
87
+	/**
88
+	 *        grab url requests and route them
89
+	 *
90
+	 * @access private
91
+	 * @return void
92
+	 * @throws EE_Error
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidInterfaceException
96
+	 */
97
+	public function _set_page_routes()
98
+	{
99
+
100
+		$this->_set_transaction_status_array();
101
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
102
+
103
+		$this->_page_routes = [
104
+
105
+			'default' => [
106
+				'func'       => '_transactions_overview_list_table',
107
+				'capability' => 'ee_read_transactions',
108
+			],
109
+
110
+			'view_transaction' => [
111
+				'func'       => '_transaction_details',
112
+				'capability' => 'ee_read_transaction',
113
+				'obj_id'     => $TXN_ID,
114
+			],
115
+
116
+			'send_payment_reminder' => [
117
+				'func'       => '_send_payment_reminder',
118
+				'noheader'   => true,
119
+				'capability' => 'ee_send_message',
120
+			],
121
+
122
+			'espresso_apply_payment' => [
123
+				'func'       => 'apply_payments_or_refunds',
124
+				'noheader'   => true,
125
+				'capability' => 'ee_edit_payments',
126
+			],
127
+
128
+			'espresso_apply_refund' => [
129
+				'func'       => 'apply_payments_or_refunds',
130
+				'noheader'   => true,
131
+				'capability' => 'ee_edit_payments',
132
+			],
133
+
134
+			'espresso_delete_payment' => [
135
+				'func'       => 'delete_payment',
136
+				'noheader'   => true,
137
+				'capability' => 'ee_delete_payments',
138
+			],
139
+
140
+			'espresso_recalculate_line_items' => [
141
+				'func'       => 'recalculateLineItems',
142
+				'noheader'   => true,
143
+				'capability' => 'ee_edit_payments',
144
+			],
145
+
146
+		];
147
+	}
148
+
149
+
150
+	protected function _set_page_config()
151
+	{
152
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
153
+		$this->_page_config = [
154
+			'default'          => [
155
+				'nav'           => [
156
+					'label' => esc_html__('Overview', 'event_espresso'),
157
+					'order' => 10,
158
+				],
159
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
160
+				'help_tabs'     => [
161
+					'transactions_overview_help_tab'                       => [
162
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
163
+						'filename' => 'transactions_overview',
164
+					],
165
+					'transactions_overview_table_column_headings_help_tab' => [
166
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
167
+						'filename' => 'transactions_overview_table_column_headings',
168
+					],
169
+					'transactions_overview_views_filters_help_tab'         => [
170
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
171
+						'filename' => 'transactions_overview_views_filters_search',
172
+					],
173
+				],
174
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
175
+				// 'help_tour'     => array('Transactions_Overview_Help_Tour'),
176
+				/**
177
+				 * commented out because currently we are not displaying tips for transaction list table status but this
178
+				 * may change in a later iteration so want to keep the code for then.
179
+				 */
180
+				// 'qtips' => array( 'Transactions_List_Table_Tips' ),
181
+				'require_nonce' => false,
182
+			],
183
+			'view_transaction' => [
184
+				'nav'       => [
185
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
186
+					'order'      => 5,
187
+					'url'        => $TXN_ID
188
+						? add_query_arg(['TXN_ID' => $TXN_ID], $this->_current_page_view_url)
189
+						: $this->_admin_base_url,
190
+					'persistent' => false,
191
+				],
192
+				'help_tabs' => [
193
+					'transactions_view_transaction_help_tab'                                              => [
194
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
195
+						'filename' => 'transactions_view_transaction',
196
+					],
197
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => [
198
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
199
+						'filename' => 'transactions_view_transaction_transaction_details_table',
200
+					],
201
+					'transactions_view_transaction_attendees_registered_help_tab'                         => [
202
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
203
+						'filename' => 'transactions_view_transaction_attendees_registered',
204
+					],
205
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => [
206
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
207
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
208
+					],
209
+				],
210
+				'qtips'     => ['Transaction_Details_Tips'],
211
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
212
+				// 'help_tour' => array('Transaction_Details_Help_Tour'),
213
+				'metaboxes' => ['_transaction_details_metaboxes'],
214
+
215
+				'require_nonce' => false,
216
+			],
217
+		];
218
+	}
219
+
220
+
221
+	/**
222
+	 * The below methods aren't used by this class currently
223
+	 */
224
+	protected function _add_screen_options()
225
+	{
226
+		// noop
227
+	}
228
+
229
+
230
+	protected function _add_feature_pointers()
231
+	{
232
+		// noop
233
+	}
234
+
235
+
236
+	public function admin_init()
237
+	{
238
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
239
+		$event_name = $this->request->getRequestParam('event_name');
240
+		$redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
241
+		// IF a registration was JUST added via the admin...
242
+		if ($EVT_ID && $event_name && $redirect_from) {
243
+			// then set a cookie so that we can block any attempts to use
244
+			// the back button as a way to enter another registration.
245
+			setcookie('ee_registration_added', $EVT_ID, time() + WEEK_IN_SECONDS, '/');
246
+			// and update the global
247
+			$_COOKIE['ee_registration_added'] = $EVT_ID;
248
+		}
249
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
250
+			'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
251
+			'event_espresso'
252
+		);
253
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
254
+			'An error occurred! Please refresh the page and try again.',
255
+			'event_espresso'
256
+		);
257
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
258
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
259
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
260
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
261
+			'This transaction has been overpaid ! Payments Total',
262
+			'event_espresso'
263
+		);
264
+	}
265
+
266
+
267
+	public function admin_notices()
268
+	{
269
+		// noop
270
+	}
271
+
272
+
273
+	public function admin_footer_scripts()
274
+	{
275
+		// noop
276
+	}
277
+
278
+
279
+	/**
280
+	 * _set_transaction_status_array
281
+	 * sets list of transaction statuses
282
+	 *
283
+	 * @access private
284
+	 * @return void
285
+	 * @throws EE_Error
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidDataTypeException
288
+	 * @throws InvalidInterfaceException
289
+	 */
290
+	private function _set_transaction_status_array()
291
+	{
292
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
293
+	}
294
+
295
+
296
+	/**
297
+	 * get_transaction_status_array
298
+	 * return the transaction status array for wp_list_table
299
+	 *
300
+	 * @access public
301
+	 * @return array
302
+	 */
303
+	public function get_transaction_status_array()
304
+	{
305
+		return self::$_txn_status;
306
+	}
307
+
308
+
309
+	/**
310
+	 *    get list of payment statuses
311
+	 *
312
+	 * @access private
313
+	 * @return void
314
+	 * @throws EE_Error
315
+	 * @throws InvalidArgumentException
316
+	 * @throws InvalidDataTypeException
317
+	 * @throws InvalidInterfaceException
318
+	 */
319
+	private function _get_payment_status_array()
320
+	{
321
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
322
+		$this->_template_args['payment_status'] = self::$_pay_status;
323
+	}
324
+
325
+
326
+	/**
327
+	 *    _add_screen_options_default
328
+	 *
329
+	 * @access protected
330
+	 * @return void
331
+	 * @throws InvalidArgumentException
332
+	 * @throws InvalidDataTypeException
333
+	 * @throws InvalidInterfaceException
334
+	 */
335
+	protected function _add_screen_options_default()
336
+	{
337
+		$this->_per_page_screen_option();
338
+	}
339
+
340
+
341
+	/**
342
+	 * load_scripts_styles
343
+	 *
344
+	 * @access public
345
+	 * @return void
346
+	 */
347
+	public function load_scripts_styles()
348
+	{
349
+		// enqueue style
350
+		wp_register_style(
351
+			'espresso_txn',
352
+			TXN_ASSETS_URL . 'espresso_transactions_admin.css',
353
+			[],
354
+			EVENT_ESPRESSO_VERSION
355
+		);
356
+		wp_enqueue_style('espresso_txn');
357
+		// scripts
358
+		wp_register_script(
359
+			'espresso_txn',
360
+			TXN_ASSETS_URL . 'espresso_transactions_admin.js',
361
+			[
362
+				'ee_admin_js',
363
+				'ee-datepicker',
364
+				'jquery-ui-datepicker',
365
+				'jquery-ui-draggable',
366
+				'ee-dialog',
367
+				'ee-accounting',
368
+				'ee-serialize-full-array',
369
+			],
370
+			EVENT_ESPRESSO_VERSION,
371
+			true
372
+		);
373
+		wp_enqueue_script('espresso_txn');
374
+	}
375
+
376
+
377
+	/**
378
+	 *    load_scripts_styles_view_transaction
379
+	 *
380
+	 * @access public
381
+	 * @return void
382
+	 */
383
+	public function load_scripts_styles_view_transaction()
384
+	{
385
+		// styles
386
+		wp_enqueue_style('espresso-ui-theme');
387
+	}
388
+
389
+
390
+	/**
391
+	 *    load_scripts_styles_default
392
+	 *
393
+	 * @access public
394
+	 * @return void
395
+	 */
396
+	public function load_scripts_styles_default()
397
+	{
398
+		// styles
399
+		wp_enqueue_style('espresso-ui-theme');
400
+	}
401
+
402
+
403
+	/**
404
+	 *    _set_list_table_views_default
405
+	 *
406
+	 * @access protected
407
+	 * @return void
408
+	 */
409
+	protected function _set_list_table_views_default()
410
+	{
411
+		$this->_views = [
412
+			'all'        => [
413
+				'slug'  => 'all',
414
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
415
+				'count' => 0,
416
+			],
417
+			'abandoned'  => [
418
+				'slug'  => 'abandoned',
419
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
420
+				'count' => 0,
421
+			],
422
+			'incomplete' => [
423
+				'slug'  => 'incomplete',
424
+				'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
425
+				'count' => 0,
426
+			],
427
+		];
428
+		if (
429
+			/**
430
+			 * Filters whether a link to the "Failed Transactions" list table
431
+			 * appears on the Transactions Admin Page list table.
432
+			 * List display can be turned back on via the following:
433
+			 * add_filter(
434
+			 *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
435
+			 *     '__return_true'
436
+			 * );
437
+			 *
438
+			 * @param boolean                 $display_failed_txns_list
439
+			 * @param Transactions_Admin_Page $this
440
+			 * @since 4.9.70.p
441
+			 */
442
+			apply_filters(
443
+				'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
444
+				false,
445
+				$this
446
+			)
447
+		) {
448
+			$this->_views['failed'] = [
449
+				'slug'  => 'failed',
450
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
451
+				'count' => 0,
452
+			];
453
+		}
454
+	}
455
+
456
+
457
+	/**
458
+	 * _set_transaction_object
459
+	 * This sets the _transaction property for the transaction details screen
460
+	 *
461
+	 * @access private
462
+	 * @return void
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws RuntimeException
466
+	 * @throws InvalidDataTypeException
467
+	 * @throws InvalidInterfaceException
468
+	 * @throws ReflectionException
469
+	 */
470
+	private function _set_transaction_object()
471
+	{
472
+		if ($this->_transaction instanceof EE_Transaction) {
473
+			return;
474
+		} //get out we've already set the object
475
+
476
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
477
+
478
+		// get transaction object
479
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
480
+		$this->_session     = $this->_transaction instanceof EE_Transaction
481
+			? $this->_transaction->session_data()
482
+			: null;
483
+		if ($this->_transaction instanceof EE_Transaction) {
484
+			$this->_transaction->verify_abandoned_transaction_status();
485
+		}
486
+
487
+		if (! $this->_transaction instanceof EE_Transaction) {
488
+			$error_msg = sprintf(
489
+				esc_html__(
490
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
491
+					'event_espresso'
492
+				),
493
+				$TXN_ID
494
+			);
495
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
496
+		}
497
+	}
498
+
499
+
500
+	/**
501
+	 *    _transaction_legend_items
502
+	 *
503
+	 * @access protected
504
+	 * @return array
505
+	 * @throws EE_Error
506
+	 * @throws InvalidArgumentException
507
+	 * @throws ReflectionException
508
+	 * @throws InvalidDataTypeException
509
+	 * @throws InvalidInterfaceException
510
+	 */
511
+	protected function _transaction_legend_items()
512
+	{
513
+		EE_Registry::instance()->load_helper('MSG_Template');
514
+		$items = [];
515
+
516
+		if (
517
+			EE_Registry::instance()->CAP->current_user_can(
518
+				'ee_read_global_messages',
519
+				'view_filtered_messages'
520
+			)
521
+		) {
522
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
523
+			if (
524
+				is_array($related_for_icon)
525
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
526
+			) {
527
+				$items['view_related_messages'] = [
528
+					'class' => $related_for_icon['css_class'],
529
+					'desc'  => $related_for_icon['label'],
530
+				];
531
+			}
532
+		}
533
+
534
+		$items = apply_filters(
535
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
536
+			array_merge(
537
+				$items,
538
+				[
539
+					'view_details'          => [
540
+						'class' => 'dashicons dashicons-cart',
541
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
542
+					],
543
+					'view_invoice'          => [
544
+						'class' => 'dashicons dashicons-media-spreadsheet',
545
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
546
+					],
547
+					'view_receipt'          => [
548
+						'class' => 'dashicons dashicons-text-page',
549
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
550
+					],
551
+					'view_registration'     => [
552
+						'class' => 'dashicons dashicons-clipboard',
553
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
554
+					],
555
+					'payment_overview_link' => [
556
+						'class' => 'dashicons dashicons-money',
557
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
558
+					],
559
+				]
560
+			)
561
+		);
562
+
563
+		if (
564
+			EEH_MSG_Template::is_mt_active('payment_reminder')
565
+			&& EE_Registry::instance()->CAP->current_user_can(
566
+				'ee_send_message',
567
+				'espresso_transactions_send_payment_reminder'
568
+			)
569
+		) {
570
+			$items['send_payment_reminder'] = [
571
+				'class' => 'dashicons dashicons-email-alt',
572
+				'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
573
+			];
574
+		} else {
575
+			$items['blank*'] = [
576
+				'class' => '',
577
+				'desc'  => '',
578
+			];
579
+		}
580
+		$more_items = apply_filters(
581
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
582
+			[
583
+				'overpaid'   => [
584
+					'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::overpaid_status_code,
585
+					'desc'  => EEH_Template::pretty_status(
586
+						EEM_Transaction::overpaid_status_code,
587
+						false,
588
+						'sentence'
589
+					),
590
+				],
591
+				'complete'   => [
592
+					'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::complete_status_code,
593
+					'desc'  => EEH_Template::pretty_status(
594
+						EEM_Transaction::complete_status_code,
595
+						false,
596
+						'sentence'
597
+					),
598
+				],
599
+				'incomplete' => [
600
+					'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::incomplete_status_code,
601
+					'desc'  => EEH_Template::pretty_status(
602
+						EEM_Transaction::incomplete_status_code,
603
+						false,
604
+						'sentence'
605
+					),
606
+				],
607
+				'abandoned'  => [
608
+					'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::abandoned_status_code,
609
+					'desc'  => EEH_Template::pretty_status(
610
+						EEM_Transaction::abandoned_status_code,
611
+						false,
612
+						'sentence'
613
+					),
614
+				],
615
+				'failed'     => [
616
+					'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::failed_status_code,
617
+					'desc'  => EEH_Template::pretty_status(
618
+						EEM_Transaction::failed_status_code,
619
+						false,
620
+						'sentence'
621
+					),
622
+				],
623
+			]
624
+		);
625
+
626
+		return array_merge($items, $more_items);
627
+	}
628
+
629
+
630
+	/**
631
+	 *    _transactions_overview_list_table
632
+	 *
633
+	 * @access protected
634
+	 * @return void
635
+	 * @throws DomainException
636
+	 * @throws EE_Error
637
+	 * @throws InvalidArgumentException
638
+	 * @throws InvalidDataTypeException
639
+	 * @throws InvalidInterfaceException
640
+	 * @throws ReflectionException
641
+	 */
642
+	protected function _transactions_overview_list_table()
643
+	{
644
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
645
+
646
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
647
+		$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
648
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
649
+			? sprintf(
650
+				esc_html__('%sViewing Transactions for the Event: %s%s', 'event_espresso'),
651
+				'<h3>',
652
+				'<a href="'
653
+				. EE_Admin_Page::add_query_args_and_nonce(
654
+					['action' => 'edit', 'post' => $event->ID()],
655
+					EVENTS_ADMIN_URL
656
+				)
657
+				. '" title="'
658
+				. esc_attr__('Click to Edit event', 'event_espresso')
659
+				. '">' . $event->name() . '</a>',
660
+				'</h3>'
661
+			)
662
+			: '';
663
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
664
+		$this->display_admin_list_table_page_with_no_sidebar();
665
+	}
666
+
667
+
668
+	/**
669
+	 *    _transaction_details
670
+	 * generates HTML for the View Transaction Details Admin page
671
+	 *
672
+	 * @access protected
673
+	 * @return void
674
+	 * @throws DomainException
675
+	 * @throws EE_Error
676
+	 * @throws InvalidArgumentException
677
+	 * @throws InvalidDataTypeException
678
+	 * @throws InvalidInterfaceException
679
+	 * @throws RuntimeException
680
+	 * @throws ReflectionException
681
+	 */
682
+	protected function _transaction_details()
683
+	{
684
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
685
+
686
+		$this->_set_transaction_status_array();
687
+
688
+		$this->_template_args                      = [];
689
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
690
+
691
+		$this->_set_transaction_object();
692
+
693
+		if (! $this->_transaction instanceof EE_Transaction) {
694
+			return;
695
+		}
696
+
697
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
698
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
699
+
700
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
701
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
702
+
703
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
704
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
705
+		$this->_template_args['txn_status']['class'] = $this->_transaction->status_ID();
706
+
707
+		$this->_template_args['grand_total'] = $this->_transaction->total();
708
+		$this->_template_args['total_paid']  = $this->_transaction->paid();
709
+
710
+		$amount_due                         = $this->_transaction->total() - $this->_transaction->paid();
711
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
712
+			$amount_due,
713
+			true
714
+		);
715
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
716
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
717
+												  . $this->_template_args['amount_due'];
718
+		} else {
719
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
720
+		}
721
+		$this->_template_args['amount_due_class'] = '';
722
+
723
+		if ($this->_transaction->paid() === $this->_transaction->total()) {
724
+			// paid in full
725
+			$this->_template_args['amount_due'] = false;
726
+		} elseif ($this->_transaction->paid() > $this->_transaction->total()) {
727
+			// overpaid
728
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
729
+		} elseif ($this->_transaction->total() > (float) 0) {
730
+			if ($this->_transaction->paid() > (float) 0) {
731
+				// monies owing
732
+				$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
733
+			} elseif ($this->_transaction->paid() === (float) 0) {
734
+				// no payments made yet
735
+				$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
736
+			}
737
+		} elseif ($this->_transaction->total() === (float) 0) {
738
+			// free event
739
+			$this->_template_args['amount_due'] = false;
740
+		}
741
+
742
+		$payment_method = $this->_transaction->payment_method();
743
+
744
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
745
+			? $payment_method->admin_name()
746
+			: esc_html__('Unknown', 'event_espresso');
747
+
748
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
749
+		// link back to overview
750
+		$this->_template_args['txn_overview_url'] = $this->request->getServerParam(
751
+			'HTTP_REFERER',
752
+			TXN_ADMIN_URL
753
+		);
754
+
755
+
756
+		// next link
757
+		$next_txn                                 = $this->_transaction->next(
758
+			null,
759
+			[['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
760
+			'TXN_ID'
761
+		);
762
+		$this->_template_args['next_transaction'] = $next_txn
763
+			? $this->_next_link(
764
+				EE_Admin_Page::add_query_args_and_nonce(
765
+					['action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']],
766
+					TXN_ADMIN_URL
767
+				),
768
+				'dashicons dashicons-arrow-right ee-icon-size-22'
769
+			)
770
+			: '';
771
+		// previous link
772
+		$previous_txn                                 = $this->_transaction->previous(
773
+			null,
774
+			[['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
775
+			'TXN_ID'
776
+		);
777
+		$this->_template_args['previous_transaction'] = $previous_txn
778
+			? $this->_previous_link(
779
+				EE_Admin_Page::add_query_args_and_nonce(
780
+					['action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']],
781
+					TXN_ADMIN_URL
782
+				),
783
+				'dashicons dashicons-arrow-left ee-icon-size-22'
784
+			)
785
+			: '';
786
+
787
+		$EVT_ID        = $this->request->getRequestParam('EVT_ID', 0, 'int');
788
+		$event_name    = $this->request->getRequestParam('event_name');
789
+		$redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
790
+
791
+		// were we just redirected here after adding a new registration ???
792
+		if ($EVT_ID && $event_name && $redirect_from) {
793
+			if (
794
+				EE_Registry::instance()->CAP->current_user_can(
795
+					'ee_edit_registrations',
796
+					'espresso_registrations_new_registration',
797
+					$EVT_ID
798
+				)
799
+			) {
800
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button--primary" href="';
801
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
802
+					[
803
+						'page'     => 'espresso_registrations',
804
+						'action'   => 'new_registration',
805
+						'return'   => 'default',
806
+						'TXN_ID'   => $this->_transaction->ID(),
807
+						'event_id' => $EVT_ID,
808
+					],
809
+					REG_ADMIN_URL
810
+				);
811
+				$this->_admin_page_title .= '">';
812
+
813
+				$this->_admin_page_title .= sprintf(
814
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
815
+					htmlentities(urldecode($event_name), ENT_QUOTES, 'UTF-8')
816
+				);
817
+				$this->_admin_page_title .= '</a>';
818
+			}
819
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
820
+		}
821
+		// grab messages at the last second
822
+		$this->_template_args['notices'] = EE_Error::get_notices();
823
+		// path to template
824
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
825
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
826
+			$template_path,
827
+			$this->_template_args,
828
+			true
829
+		);
830
+
831
+		// the details template wrapper
832
+		$this->display_admin_page_with_sidebar();
833
+	}
834
+
835
+
836
+	/**
837
+	 *        _transaction_details_metaboxes
838
+	 *
839
+	 * @access protected
840
+	 * @return void
841
+	 * @throws EE_Error
842
+	 * @throws InvalidArgumentException
843
+	 * @throws InvalidDataTypeException
844
+	 * @throws InvalidInterfaceException
845
+	 * @throws RuntimeException
846
+	 * @throws ReflectionException
847
+	 */
848
+	protected function _transaction_details_metaboxes()
849
+	{
850
+
851
+		$this->_set_transaction_object();
852
+
853
+		if (! $this->_transaction instanceof EE_Transaction) {
854
+			return;
855
+		}
856
+		$this->addMetaBox(
857
+			'edit-txn-details-mbox',
858
+			'<span>' . esc_html__('Transaction Details', 'event_espresso')
859
+			. '&nbsp;<span class="dashicons dashicons-cart" ></span></span>',
860
+			[$this, 'txn_details_meta_box'],
861
+			$this->_wp_page_slug
862
+		);
863
+		$this->addMetaBox(
864
+			'edit-txn-attendees-mbox',
865
+			'<span>' . esc_html__('Attendees Registered in this Transaction', 'event_espresso')
866
+			. '&nbsp;<span class="dashicons dashicons-groups" ></span></span>',
867
+			[$this, 'txn_attendees_meta_box'],
868
+			$this->_wp_page_slug,
869
+			'normal',
870
+			'high',
871
+			['TXN_ID' => $this->_transaction->ID()]
872
+		);
873
+		$this->addMetaBox(
874
+			'edit-txn-registrant-mbox',
875
+			esc_html__('Primary Contact', 'event_espresso'),
876
+			[$this, 'txn_registrant_side_meta_box'],
877
+			$this->_wp_page_slug,
878
+			'side'
879
+		);
880
+		$this->addMetaBox(
881
+			'edit-txn-billing-info-mbox',
882
+			esc_html__('Billing Information', 'event_espresso'),
883
+			[$this, 'txn_billing_info_side_meta_box'],
884
+			$this->_wp_page_slug,
885
+			'side'
886
+		);
887
+	}
888
+
889
+
890
+	/**
891
+	 * Callback for transaction actions metabox.
892
+	 *
893
+	 * @param EE_Transaction|null $transaction
894
+	 * @return string
895
+	 * @throws DomainException
896
+	 * @throws EE_Error
897
+	 * @throws InvalidArgumentException
898
+	 * @throws InvalidDataTypeException
899
+	 * @throws InvalidInterfaceException
900
+	 * @throws ReflectionException
901
+	 * @throws RuntimeException
902
+	 */
903
+	public function getActionButtons(EE_Transaction $transaction = null)
904
+	{
905
+		$content = '';
906
+		$actions = [];
907
+		if (! $transaction instanceof EE_Transaction) {
908
+			return $content;
909
+		}
910
+		/** @var EE_Registration $primary_registration */
911
+		$primary_registration = $transaction->primary_registration();
912
+		$attendee             = $primary_registration instanceof EE_Registration
913
+			? $primary_registration->attendee()
914
+			: null;
915
+
916
+		if (
917
+			$attendee instanceof EE_Attendee
918
+			&& EE_Registry::instance()->CAP->current_user_can(
919
+				'ee_send_message',
920
+				'espresso_transactions_send_payment_reminder'
921
+			)
922
+		) {
923
+			$actions['payment_reminder'] =
924
+				EEH_MSG_Template::is_mt_active('payment_reminder')
925
+				&& $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code
926
+				&& $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code
927
+					? EEH_Template::get_button_or_link(
928
+						EE_Admin_Page::add_query_args_and_nonce(
929
+							[
930
+							'action'      => 'send_payment_reminder',
931
+							'TXN_ID'      => $this->_transaction->ID(),
932
+							'redirect_to' => 'view_transaction',
933
+							],
934
+							TXN_ADMIN_URL
935
+						),
936
+						esc_html__(' Send Payment Reminder', 'event_espresso'),
937
+						'button button--secondary',
938
+						'dashicons dashicons-email-alt'
939
+					)
940
+					: '';
941
+		}
942
+
943
+		if (
944
+			EE_Registry::instance()->CAP->current_user_can(
945
+				'ee_edit_payments',
946
+				'espresso_transactions_recalculate_line_items'
947
+			)
948
+		) {
949
+			$actions['recalculate_line_items'] = EEH_Template::get_button_or_link(
950
+				EE_Admin_Page::add_query_args_and_nonce(
951
+					[
952
+						'action'      => 'espresso_recalculate_line_items',
953
+						'TXN_ID'      => $this->_transaction->ID(),
954
+						'redirect_to' => 'view_transaction',
955
+					],
956
+					TXN_ADMIN_URL
957
+				),
958
+				esc_html__(' Recalculate Taxes and Total', 'event_espresso'),
959
+				'button button--secondary',
960
+				'dashicons dashicons-update'
961
+			);
962
+		}
963
+
964
+		if (
965
+			$primary_registration instanceof EE_Registration
966
+			&& EEH_MSG_Template::is_mt_active('receipt')
967
+		) {
968
+			$actions['receipt'] = EEH_Template::get_button_or_link(
969
+				$primary_registration->receipt_url(),
970
+				esc_html__('View Receipt', 'event_espresso'),
971
+				'button button--secondary',
972
+				'dashicons dashicons-text-page'
973
+			);
974
+		}
975
+
976
+		if (
977
+			$primary_registration instanceof EE_Registration
978
+			&& EEH_MSG_Template::is_mt_active('invoice')
979
+		) {
980
+			$actions['invoice'] = EEH_Template::get_button_or_link(
981
+				$primary_registration->invoice_url(),
982
+				esc_html__('View Invoice', 'event_espresso'),
983
+				'button button--secondary',
984
+				'dashicons dashicons-media-spreadsheet'
985
+			);
986
+		}
987
+		$actions = array_filter(
988
+			apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
989
+		);
990
+		if ($actions) {
991
+			// $content = '<ul>';
992
+			// $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
993
+			// $content .= '</uL>';
994
+			$content .= implode('', $actions);
995
+		}
996
+		return $content;
997
+	}
998
+
999
+
1000
+	/**
1001
+	 * txn_details_meta_box
1002
+	 * generates HTML for the Transaction main meta box
1003
+	 *
1004
+	 * @return void
1005
+	 * @throws DomainException
1006
+	 * @throws EE_Error
1007
+	 * @throws InvalidArgumentException
1008
+	 * @throws InvalidDataTypeException
1009
+	 * @throws InvalidInterfaceException
1010
+	 * @throws RuntimeException
1011
+	 * @throws ReflectionException
1012
+	 */
1013
+	public function txn_details_meta_box()
1014
+	{
1015
+		$this->_set_transaction_object();
1016
+		$this->_template_args['TXN_ID']              = $this->_transaction->ID();
1017
+		$this->_template_args['attendee']            =
1018
+			$this->_transaction->primary_registration() instanceof EE_Registration
1019
+				? $this->_transaction->primary_registration()->attendee()
1020
+				: null;
1021
+		$this->_template_args['can_edit_payments']   = EE_Registry::instance()->CAP->current_user_can(
1022
+			'ee_edit_payments',
1023
+			'apply_payment_or_refund_from_registration_details'
1024
+		);
1025
+		$this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1026
+			'ee_delete_payments',
1027
+			'delete_payment_from_registration_details'
1028
+		);
1029
+
1030
+		// get line table
1031
+		EEH_Autoloader::register_line_item_display_autoloaders();
1032
+		$Line_Item_Display                       = new EE_Line_Item_Display(
1033
+			'admin_table',
1034
+			'EE_Admin_Table_Line_Item_Display_Strategy'
1035
+		);
1036
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1037
+			$this->_transaction->total_line_item()
1038
+		);
1039
+		$this->_template_args['REG_code']        =
1040
+			$this->_transaction->primary_registration() instanceof EE_Registration
1041
+				? $this->_transaction->primary_registration()->reg_code()
1042
+				: null;
1043
+		// process taxes
1044
+		$taxes                         = $this->_transaction->line_items([['LIN_type' => EEM_Line_Item::type_tax]]);
1045
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1046
+
1047
+		$this->_template_args['grand_total']     = EEH_Template::format_currency(
1048
+			$this->_transaction->total(),
1049
+			false,
1050
+			false
1051
+		);
1052
+		$this->_template_args['grand_raw_total'] = $this->_transaction->total();
1053
+		$this->_template_args['TXN_status']      = $this->_transaction->status_ID();
1054
+
1055
+		// process payment details
1056
+		$payments = $this->_transaction->payments();
1057
+		if (! empty($payments)) {
1058
+			$this->_template_args['payments']              = $payments;
1059
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1060
+		} else {
1061
+			$this->_template_args['payments']              = false;
1062
+			$this->_template_args['existing_reg_payments'] = [];
1063
+		}
1064
+
1065
+		$this->_template_args['edit_payment_url']   = add_query_arg(['action' => 'edit_payment'], TXN_ADMIN_URL);
1066
+		$this->_template_args['delete_payment_url'] = add_query_arg(
1067
+			['action' => 'espresso_delete_payment'],
1068
+			TXN_ADMIN_URL
1069
+		);
1070
+
1071
+		if (isset($txn_details['invoice_number'])) {
1072
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1073
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1074
+				'Invoice Number',
1075
+				'event_espresso'
1076
+			);
1077
+		}
1078
+
1079
+		$this->_template_args['txn_details']['registration_session']['value'] =
1080
+			$this->_transaction->primary_registration() instanceof EE_Registration
1081
+				? $this->_transaction->primary_registration()->session_ID()
1082
+				: null;
1083
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1084
+			'Registration Session',
1085
+			'event_espresso'
1086
+		);
1087
+
1088
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1089
+			? $this->_session['ip_address']
1090
+			: '';
1091
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1092
+			'Transaction placed from IP',
1093
+			'event_espresso'
1094
+		);
1095
+
1096
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1097
+			? $this->_session['user_agent']
1098
+			: '';
1099
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1100
+			'Registrant User Agent',
1101
+			'event_espresso'
1102
+		);
1103
+
1104
+		$reg_steps = '<ul>';
1105
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1106
+			if ($reg_step_status === true) {
1107
+				$reg_steps .= '<li style="color:#70cc50">'
1108
+							  . sprintf(
1109
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1110
+								  ucwords(str_replace('_', ' ', $reg_step))
1111
+							  )
1112
+							  . '</li>';
1113
+			} elseif ($reg_step_status !== false && is_numeric($reg_step_status)) {
1114
+				$reg_steps .= '<li style="color:#2EA2CC">'
1115
+							  . sprintf(
1116
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1117
+								  ucwords(str_replace('_', ' ', $reg_step)),
1118
+								  date(
1119
+									  get_option('date_format') . ' ' . get_option('time_format'),
1120
+									  $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1121
+								  )
1122
+							  )
1123
+							  . '</li>';
1124
+			} else {
1125
+				$reg_steps .= '<li style="color:#E76700">'
1126
+							  . sprintf(
1127
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1128
+								  ucwords(str_replace('_', ' ', $reg_step))
1129
+							  )
1130
+							  . '</li>';
1131
+			}
1132
+		}
1133
+		$reg_steps                                                 .= '</ul>';
1134
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1135
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1136
+			'Registration Step Progress',
1137
+			'event_espresso'
1138
+		);
1139
+
1140
+
1141
+		$this->_get_registrations_to_apply_payment_to();
1142
+		$this->_get_payment_methods($payments);
1143
+		$this->_get_payment_status_array();
1144
+		$this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1145
+
1146
+		$this->_template_args['transaction_form_url']    = add_query_arg(
1147
+			[
1148
+				'action'  => 'edit_transaction',
1149
+				'process' => 'transaction',
1150
+			],
1151
+			TXN_ADMIN_URL
1152
+		);
1153
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(
1154
+			[
1155
+				'page'   => 'espresso_transactions',
1156
+				'action' => 'espresso_apply_payment',
1157
+			],
1158
+			WP_AJAX_URL
1159
+		);
1160
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(
1161
+			[
1162
+				'page'   => 'espresso_transactions',
1163
+				'action' => 'espresso_delete_payment',
1164
+			],
1165
+			WP_AJAX_URL
1166
+		);
1167
+
1168
+		$this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1169
+
1170
+		// 'espresso_delete_payment_nonce'
1171
+
1172
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1173
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * _get_registration_payment_IDs
1179
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1180
+	 *
1181
+	 * @access protected
1182
+	 * @param EE_Payment[] $payments
1183
+	 * @return array
1184
+	 * @throws EE_Error
1185
+	 * @throws InvalidArgumentException
1186
+	 * @throws InvalidDataTypeException
1187
+	 * @throws InvalidInterfaceException
1188
+	 * @throws ReflectionException
1189
+	 */
1190
+	protected function _get_registration_payment_IDs($payments = [])
1191
+	{
1192
+		$existing_reg_payments = [];
1193
+		// get all reg payments for these payments
1194
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(
1195
+			[
1196
+				[
1197
+					'PAY_ID' => [
1198
+						'IN',
1199
+						array_keys($payments),
1200
+					],
1201
+				],
1202
+			]
1203
+		);
1204
+		if (! empty($reg_payments)) {
1205
+			foreach ($payments as $payment) {
1206
+				if (! $payment instanceof EE_Payment) {
1207
+					continue;
1208
+				} elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1209
+					$existing_reg_payments[ $payment->ID() ] = [];
1210
+				}
1211
+				foreach ($reg_payments as $reg_payment) {
1212
+					if (
1213
+						$reg_payment instanceof EE_Registration_Payment
1214
+						&& $reg_payment->payment_ID() === $payment->ID()
1215
+					) {
1216
+						$existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1217
+					}
1218
+				}
1219
+			}
1220
+		}
1221
+
1222
+		return $existing_reg_payments;
1223
+	}
1224
+
1225
+
1226
+	/**
1227
+	 * _get_registrations_to_apply_payment_to
1228
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1229
+	 * which allows the admin to only apply the payment to the specific registrations
1230
+	 *
1231
+	 * @access protected
1232
+	 * @return void
1233
+	 * @throws EE_Error
1234
+	 * @throws InvalidArgumentException
1235
+	 * @throws InvalidDataTypeException
1236
+	 * @throws InvalidInterfaceException
1237
+	 * @throws ReflectionException
1238
+	 */
1239
+	protected function _get_registrations_to_apply_payment_to()
1240
+	{
1241
+		// we want any registration with an active status (ie: not deleted or cancelled)
1242
+		$query_params                      = [
1243
+			[
1244
+				'STS_ID' => [
1245
+					'IN',
1246
+					[
1247
+						EEM_Registration::status_id_approved,
1248
+						EEM_Registration::status_id_pending_payment,
1249
+						EEM_Registration::status_id_not_approved,
1250
+					],
1251
+				],
1252
+			],
1253
+		];
1254
+		$registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1255
+			'',
1256
+			'txn-admin-apply-payment-to-registrations-dv',
1257
+			'',
1258
+			'clear: both; margin: 1.5em 0 0; display: none;'
1259
+		);
1260
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1261
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl striped');
1262
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1263
+			EEH_HTML::tr(
1264
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1265
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1266
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1267
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1268
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1269
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1270
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1271
+			)
1272
+		);
1273
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1274
+		// get registrations for TXN
1275
+		$registrations         = $this->_transaction->registrations($query_params);
1276
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1277
+		foreach ($registrations as $registration) {
1278
+			if ($registration instanceof EE_Registration) {
1279
+				$attendee_name                     = $registration->attendee() instanceof EE_Attendee
1280
+					? $registration->attendee()->full_name()
1281
+					: esc_html__('Unknown Attendee', 'event_espresso');
1282
+				$owing                             = $registration->final_price() - $registration->paid();
1283
+				$taxable                           = $registration->ticket()->taxable()
1284
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1285
+					: '';
1286
+				$checked                           = empty($existing_reg_payments)
1287
+													 || in_array($registration->ID(), $existing_reg_payments, true)
1288
+					? ' checked="checked"'
1289
+					: '';
1290
+				$disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1291
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1292
+					EEH_HTML::td($registration->ID()) .
1293
+					EEH_HTML::td($attendee_name) .
1294
+					EEH_HTML::td(
1295
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1296
+					) .
1297
+					EEH_HTML::td($registration->event_name()) .
1298
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1299
+					EEH_HTML::td(
1300
+						EEH_Template::format_currency($owing),
1301
+						'',
1302
+						'txn-admin-payment-owing-td jst-cntr'
1303
+					) .
1304
+					EEH_HTML::td(
1305
+						'<input type="checkbox" value="' . $registration->ID()
1306
+						. '" name="txn_admin_payment[registrations]"'
1307
+						. $checked . $disabled . '>',
1308
+						'',
1309
+						'jst-cntr'
1310
+					),
1311
+					'apply-payment-registration-row-' . $registration->ID()
1312
+				);
1313
+			}
1314
+		}
1315
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1316
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1317
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1318
+		$registrations_to_apply_payment_to                         .= EEH_HTML::p(
1319
+			esc_html__(
1320
+				'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1321
+				'event_espresso'
1322
+			),
1323
+			'',
1324
+			'clear description'
1325
+		);
1326
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1327
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1328
+	}
1329
+
1330
+
1331
+	/**
1332
+	 * _get_reg_status_selection
1333
+	 *
1334
+	 * @return void
1335
+	 * @throws EE_Error
1336
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1337
+	 *         instead of events.
1338
+	 * @access protected
1339
+	 */
1340
+	protected function _get_reg_status_selection()
1341
+	{
1342
+		// first get all possible statuses
1343
+		$statuses = EEM_Registration::reg_status_array([], true);
1344
+		// let's add a "don't change" option.
1345
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1346
+		$status_array                                        = array_merge($status_array, $statuses);
1347
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1348
+			'txn_reg_status_change[reg_status]',
1349
+			$status_array,
1350
+			'NAN',
1351
+			'id="txn-admin-payment-reg-status-inp"',
1352
+			'txn-reg-status-change-reg-status'
1353
+		);
1354
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1355
+			'delete_txn_reg_status_change[reg_status]',
1356
+			$status_array,
1357
+			'NAN',
1358
+			'delete-txn-admin-payment-reg-status-inp',
1359
+			'delete-txn-reg-status-change-reg-status'
1360
+		);
1361
+	}
1362
+
1363
+
1364
+	/**
1365
+	 *    _get_payment_methods
1366
+	 * Gets all the payment methods available generally, or the ones that are already
1367
+	 * selected on these payments (in case their payment methods are no longer active).
1368
+	 * Has the side-effect of updating the template args' payment_methods item
1369
+	 *
1370
+	 * @access private
1371
+	 * @param EE_Payment[] to show on this page
1372
+	 * @return void
1373
+	 * @throws EE_Error
1374
+	 * @throws InvalidArgumentException
1375
+	 * @throws InvalidDataTypeException
1376
+	 * @throws InvalidInterfaceException
1377
+	 * @throws ReflectionException
1378
+	 */
1379
+	private function _get_payment_methods($payments = [])
1380
+	{
1381
+		$payment_methods_of_payments = [];
1382
+		foreach ($payments as $payment) {
1383
+			if ($payment instanceof EE_Payment) {
1384
+				$payment_methods_of_payments[] = $payment->ID();
1385
+			}
1386
+		}
1387
+		if ($payment_methods_of_payments) {
1388
+			$query_args = [
1389
+				[
1390
+					'OR*payment_method_for_payment' => [
1391
+						'PMD_ID'    => ['IN', $payment_methods_of_payments],
1392
+						'PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%'],
1393
+					],
1394
+				],
1395
+			];
1396
+		} else {
1397
+			$query_args = [['PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%']]];
1398
+		}
1399
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1400
+	}
1401
+
1402
+
1403
+	/**
1404
+	 * txn_attendees_meta_box
1405
+	 *    generates HTML for the Attendees Transaction main meta box
1406
+	 *
1407
+	 * @access public
1408
+	 * @param WP_Post $post
1409
+	 * @param array   $metabox
1410
+	 * @return void
1411
+	 * @throws DomainException
1412
+	 * @throws EE_Error
1413
+	 * @throws InvalidArgumentException
1414
+	 * @throws InvalidDataTypeException
1415
+	 * @throws InvalidInterfaceException
1416
+	 * @throws ReflectionException
1417
+	 */
1418
+	public function txn_attendees_meta_box($post, $metabox = ['args' => []])
1419
+	{
1420
+
1421
+		/** @noinspection NonSecureExtractUsageInspection */
1422
+		extract($metabox['args']);
1423
+		$this->_template_args['post']            = $post;
1424
+		$this->_template_args['event_attendees'] = [];
1425
+		// process items in cart
1426
+		$line_items = $this->_transaction->get_many_related(
1427
+			'Line_Item',
1428
+			[['LIN_type' => 'line-item']]
1429
+		);
1430
+		if (! empty($line_items)) {
1431
+			foreach ($line_items as $item) {
1432
+				if ($item instanceof EE_Line_Item) {
1433
+					switch ($item->OBJ_type()) {
1434
+						case 'Event':
1435
+							break;
1436
+						case 'Ticket':
1437
+							$ticket = $item->ticket();
1438
+							// right now we're only handling tickets here.
1439
+							// Cause its expected that only tickets will have attendees right?
1440
+							if (! $ticket instanceof EE_Ticket) {
1441
+								break;
1442
+							}
1443
+							try {
1444
+								$event_name = $ticket->get_event_name();
1445
+							} catch (Exception $e) {
1446
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1447
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1448
+							}
1449
+							$event_name   .= ' - ' . $item->name();
1450
+							$ticket_price = EEH_Template::format_currency($item->unit_price());
1451
+							// now get all of the registrations for this transaction that use this ticket
1452
+							$registrations = $ticket->registrations(
1453
+								[['TXN_ID' => $this->_transaction->ID()]]
1454
+							);
1455
+							foreach ($registrations as $registration) {
1456
+								if (! $registration instanceof EE_Registration) {
1457
+									break;
1458
+								}
1459
+								$this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1460
+									= $registration->status_ID();
1461
+								$this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1462
+									= $registration->count();
1463
+								$this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1464
+									= $event_name;
1465
+								$this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1466
+									= $ticket_price;
1467
+								// attendee info
1468
+								$attendee = $registration->get_first_related('Attendee');
1469
+								if ($attendee instanceof EE_Attendee) {
1470
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1471
+										= $attendee->ID();
1472
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1473
+										= $attendee->full_name();
1474
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']
1475
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1476
+										  . esc_html__(
1477
+											  ' Event',
1478
+											  'event_espresso'
1479
+										  )
1480
+										  . '">' . $attendee->email() . '</a>';
1481
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']
1482
+										= EEH_Address::format($attendee, 'inline', false, false);
1483
+								} else {
1484
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']   = '';
1485
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1486
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']    = '';
1487
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']  = '';
1488
+								}
1489
+							}
1490
+							break;
1491
+					}
1492
+				}
1493
+			}
1494
+
1495
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1496
+				[
1497
+					'action'  => 'edit_transaction',
1498
+					'process' => 'attendees',
1499
+				],
1500
+				TXN_ADMIN_URL
1501
+			);
1502
+			echo EEH_Template::display_template(
1503
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1504
+				$this->_template_args,
1505
+				true
1506
+			);
1507
+		} else {
1508
+			printf(
1509
+				esc_html__(
1510
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1511
+					'event_espresso'
1512
+				),
1513
+				'<p class="important-notice">',
1514
+				'</p>'
1515
+			);
1516
+		}
1517
+	}
1518
+
1519
+
1520
+	/**
1521
+	 * txn_registrant_side_meta_box
1522
+	 * generates HTML for the Edit Transaction side meta box
1523
+	 *
1524
+	 * @access public
1525
+	 * @return void
1526
+	 * @throws DomainException
1527
+	 * @throws EE_Error
1528
+	 * @throws InvalidArgumentException
1529
+	 * @throws InvalidDataTypeException
1530
+	 * @throws InvalidInterfaceException
1531
+	 * @throws ReflectionException
1532
+	 */
1533
+	public function txn_registrant_side_meta_box()
1534
+	{
1535
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1536
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1537
+			: null;
1538
+		if (! $primary_att instanceof EE_Attendee) {
1539
+			$this->_template_args['no_attendee_message'] = esc_html__(
1540
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1541
+				'event_espresso'
1542
+			);
1543
+			$primary_att                           = EEM_Attendee::instance()->create_default_object();
1544
+		}
1545
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1546
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1547
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1548
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1549
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1550
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1551
+			[
1552
+				'action' => 'edit_attendee',
1553
+				'post'   => $primary_att->ID(),
1554
+			],
1555
+			REG_ADMIN_URL
1556
+		);
1557
+		// get formatted address for registrant
1558
+		$formatted_address = EEH_Address::format($primary_att);
1559
+		$formatted_address = $formatted_address !== '<div class="espresso-address-dv"><div></div></div>'
1560
+			? $formatted_address
1561
+			: '';
1562
+		$this->_template_args['formatted_address'] = $formatted_address;
1563
+		echo EEH_Template::display_template(
1564
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1565
+			$this->_template_args,
1566
+			true
1567
+		);
1568
+	}
1569
+
1570
+
1571
+	/**
1572
+	 * txn_billing_info_side_meta_box
1573
+	 *    generates HTML for the Edit Transaction side meta box
1574
+	 *
1575
+	 * @access public
1576
+	 * @return void
1577
+	 * @throws DomainException
1578
+	 * @throws EE_Error
1579
+	 * @throws ReflectionException
1580
+	 */
1581
+	public function txn_billing_info_side_meta_box()
1582
+	{
1583
+
1584
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1585
+		$this->_template_args['billing_form_url'] = add_query_arg(
1586
+			['action' => 'edit_transaction', 'process' => 'billing'],
1587
+			TXN_ADMIN_URL
1588
+		);
1589
+
1590
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1591
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1592
+	}
1593
+
1594
+
1595
+	/**
1596
+	 * apply_payments_or_refunds
1597
+	 *    registers a payment or refund made towards a transaction
1598
+	 *
1599
+	 * @access public
1600
+	 * @return void
1601
+	 * @throws EE_Error
1602
+	 * @throws InvalidArgumentException
1603
+	 * @throws ReflectionException
1604
+	 * @throws RuntimeException
1605
+	 * @throws InvalidDataTypeException
1606
+	 * @throws InvalidInterfaceException
1607
+	 */
1608
+	public function apply_payments_or_refunds()
1609
+	{
1610
+		$json_response_data = ['return_data' => false];
1611
+		$valid_data         = $this->_validate_payment_request_data();
1612
+		$has_access         = EE_Registry::instance()->CAP->current_user_can(
1613
+			'ee_edit_payments',
1614
+			'apply_payment_or_refund_from_registration_details'
1615
+		);
1616
+		if (! empty($valid_data) && $has_access) {
1617
+			$PAY_ID = $valid_data['PAY_ID'];
1618
+			// save  the new payment
1619
+			$payment = $this->_create_payment_from_request_data($valid_data);
1620
+			// get the TXN for this payment
1621
+			$transaction = $payment->transaction();
1622
+			// verify transaction
1623
+			if ($transaction instanceof EE_Transaction) {
1624
+				// calculate_total_payments_and_update_status
1625
+				$this->_process_transaction_payments($transaction);
1626
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1627
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1628
+				// apply payment to registrations (if applicable)
1629
+				if (! empty($REG_IDs)) {
1630
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1631
+					$this->_maybe_send_notifications();
1632
+					// now process status changes for the same registrations
1633
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1634
+				}
1635
+				$this->_maybe_send_notifications($payment);
1636
+				// prepare to render page
1637
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1638
+				do_action(
1639
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1640
+					$transaction,
1641
+					$payment
1642
+				);
1643
+			} else {
1644
+				EE_Error::add_error(
1645
+					esc_html__(
1646
+						'A valid Transaction for this payment could not be retrieved.',
1647
+						'event_espresso'
1648
+					),
1649
+					__FILE__,
1650
+					__FUNCTION__,
1651
+					__LINE__
1652
+				);
1653
+			}
1654
+		} elseif ($has_access) {
1655
+			EE_Error::add_error(
1656
+				esc_html__(
1657
+					'The payment form data could not be processed. Please try again.',
1658
+					'event_espresso'
1659
+				),
1660
+				__FILE__,
1661
+				__FUNCTION__,
1662
+				__LINE__
1663
+			);
1664
+		} else {
1665
+			EE_Error::add_error(
1666
+				esc_html__(
1667
+					'You do not have access to apply payments or refunds to a registration.',
1668
+					'event_espresso'
1669
+				),
1670
+				__FILE__,
1671
+				__FUNCTION__,
1672
+				__LINE__
1673
+			);
1674
+		}
1675
+		$notices              = EE_Error::get_notices(
1676
+			false,
1677
+			false,
1678
+			false
1679
+		);
1680
+		$this->_template_args = [
1681
+			'data'    => $json_response_data,
1682
+			'error'   => $notices['errors'],
1683
+			'success' => $notices['success'],
1684
+		];
1685
+		$this->_return_json();
1686
+	}
1687
+
1688
+
1689
+	/**
1690
+	 * _validate_payment_request_data
1691
+	 *
1692
+	 * @return array
1693
+	 * @throws EE_Error
1694
+	 * @throws InvalidArgumentException
1695
+	 * @throws InvalidDataTypeException
1696
+	 * @throws InvalidInterfaceException
1697
+	 */
1698
+	protected function _validate_payment_request_data()
1699
+	{
1700
+		if (! $this->request->requestParamIsSet('txn_admin_payment')) {
1701
+			return [];
1702
+		}
1703
+		$payment_form = $this->_generate_payment_form_section();
1704
+		try {
1705
+			if ($payment_form->was_submitted()) {
1706
+				$payment_form->receive_form_submission();
1707
+				if (! $payment_form->is_valid()) {
1708
+					$submission_error_messages = [];
1709
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1710
+						if ($validation_error instanceof EE_Validation_Error) {
1711
+							$form_input = $validation_error->get_form_section();
1712
+							$submission_error_messages[] = sprintf(
1713
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1714
+								$form_input instanceof EE_Form_Input_Base ? $form_input->html_label_text() : '',
1715
+								$validation_error->getMessage()
1716
+							);
1717
+						}
1718
+					}
1719
+					EE_Error::add_error(
1720
+						implode('<br />', $submission_error_messages),
1721
+						__FILE__,
1722
+						__FUNCTION__,
1723
+						__LINE__
1724
+					);
1725
+					return [];
1726
+				}
1727
+			}
1728
+		} catch (EE_Error $e) {
1729
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1730
+			return [];
1731
+		}
1732
+
1733
+		return $payment_form->valid_data();
1734
+	}
1735
+
1736
+
1737
+	/**
1738
+	 * _generate_payment_form_section
1739
+	 *
1740
+	 * @return EE_Form_Section_Proper
1741
+	 * @throws EE_Error
1742
+	 */
1743
+	protected function _generate_payment_form_section()
1744
+	{
1745
+		return new EE_Form_Section_Proper(
1746
+			[
1747
+				'name'        => 'txn_admin_payment',
1748
+				'subsections' => [
1749
+					'PAY_ID'          => new EE_Text_Input(
1750
+						[
1751
+							'default'               => 0,
1752
+							'required'              => false,
1753
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1754
+							'validation_strategies' => [new EE_Int_Normalization()],
1755
+						]
1756
+					),
1757
+					'TXN_ID'          => new EE_Text_Input(
1758
+						[
1759
+							'default'               => 0,
1760
+							'required'              => true,
1761
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1762
+							'validation_strategies' => [new EE_Int_Normalization()],
1763
+						]
1764
+					),
1765
+					'type'            => new EE_Text_Input(
1766
+						[
1767
+							'default'               => 1,
1768
+							'required'              => true,
1769
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1770
+							'validation_strategies' => [new EE_Int_Normalization()],
1771
+						]
1772
+					),
1773
+					'amount'          => new EE_Text_Input(
1774
+						[
1775
+							'default'               => 0,
1776
+							'required'              => true,
1777
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1778
+							'validation_strategies' => [new EE_Float_Normalization()],
1779
+						]
1780
+					),
1781
+					'status'          => new EE_Text_Input(
1782
+						[
1783
+							'default'         => EEM_Payment::status_id_approved,
1784
+							'required'        => true,
1785
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1786
+						]
1787
+					),
1788
+					'PMD_ID'          => new EE_Text_Input(
1789
+						[
1790
+							'default'               => 2,
1791
+							'required'              => true,
1792
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1793
+							'validation_strategies' => [new EE_Int_Normalization()],
1794
+						]
1795
+					),
1796
+					'date'            => new EE_Text_Input(
1797
+						[
1798
+							'default'         => time(),
1799
+							'required'        => true,
1800
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1801
+						]
1802
+					),
1803
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1804
+						[
1805
+							'default'               => '',
1806
+							'required'              => false,
1807
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1808
+							'validation_strategies' => [
1809
+								new EE_Max_Length_Validation_Strategy(
1810
+									esc_html__('Input too long', 'event_espresso'),
1811
+									100
1812
+								),
1813
+							],
1814
+						]
1815
+					),
1816
+					'po_number'       => new EE_Text_Input(
1817
+						[
1818
+							'default'               => '',
1819
+							'required'              => false,
1820
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1821
+							'validation_strategies' => [
1822
+								new EE_Max_Length_Validation_Strategy(
1823
+									esc_html__('Input too long', 'event_espresso'),
1824
+									100
1825
+								),
1826
+							],
1827
+						]
1828
+					),
1829
+					'accounting'      => new EE_Text_Input(
1830
+						[
1831
+							'default'               => '',
1832
+							'required'              => false,
1833
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1834
+							'validation_strategies' => [
1835
+								new EE_Max_Length_Validation_Strategy(
1836
+									esc_html__('Input too long', 'event_espresso'),
1837
+									100
1838
+								),
1839
+							],
1840
+						]
1841
+					),
1842
+				],
1843
+			]
1844
+		);
1845
+	}
1846
+
1847
+
1848
+	/**
1849
+	 * _create_payment_from_request_data
1850
+	 *
1851
+	 * @param array $valid_data
1852
+	 * @return EE_Payment
1853
+	 * @throws EE_Error
1854
+	 * @throws InvalidArgumentException
1855
+	 * @throws InvalidDataTypeException
1856
+	 * @throws InvalidInterfaceException
1857
+	 * @throws ReflectionException
1858
+	 */
1859
+	protected function _create_payment_from_request_data($valid_data)
1860
+	{
1861
+		$PAY_ID = $valid_data['PAY_ID'];
1862
+		// get payment amount
1863
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1864
+		// payments have a type value of 1 and refunds have a type value of -1
1865
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1866
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1867
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1868
+		$date    = $valid_data['date']
1869
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1870
+			: date('Y-m-d g:i a', current_time('timestamp'));
1871
+		$payment = EE_Payment::new_instance(
1872
+			[
1873
+				'TXN_ID'              => $valid_data['TXN_ID'],
1874
+				'STS_ID'              => $valid_data['status'],
1875
+				'PAY_timestamp'       => $date,
1876
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1877
+				'PMD_ID'              => $valid_data['PMD_ID'],
1878
+				'PAY_amount'          => $amount,
1879
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1880
+				'PAY_po_number'       => $valid_data['po_number'],
1881
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1882
+				'PAY_details'         => $valid_data,
1883
+				'PAY_ID'              => $PAY_ID,
1884
+			],
1885
+			'',
1886
+			['Y-m-d', 'g:i a']
1887
+		);
1888
+
1889
+		if (! $payment->save()) {
1890
+			EE_Error::add_error(
1891
+				sprintf(
1892
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1893
+					$payment->ID()
1894
+				),
1895
+				__FILE__,
1896
+				__FUNCTION__,
1897
+				__LINE__
1898
+			);
1899
+		}
1900
+
1901
+		return $payment;
1902
+	}
1903
+
1904
+
1905
+	/**
1906
+	 * _process_transaction_payments
1907
+	 *
1908
+	 * @param EE_Transaction $transaction
1909
+	 * @return void
1910
+	 * @throws EE_Error
1911
+	 * @throws InvalidArgumentException
1912
+	 * @throws ReflectionException
1913
+	 * @throws InvalidDataTypeException
1914
+	 * @throws InvalidInterfaceException
1915
+	 */
1916
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1917
+	{
1918
+		/** @type EE_Transaction_Payments $transaction_payments */
1919
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1920
+		// update the transaction with this payment
1921
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1922
+			EE_Error::add_success(
1923
+				esc_html__(
1924
+					'The payment has been processed successfully.',
1925
+					'event_espresso'
1926
+				),
1927
+				__FILE__,
1928
+				__FUNCTION__,
1929
+				__LINE__
1930
+			);
1931
+		} else {
1932
+			EE_Error::add_error(
1933
+				esc_html__(
1934
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1935
+					'event_espresso'
1936
+				),
1937
+				__FILE__,
1938
+				__FUNCTION__,
1939
+				__LINE__
1940
+			);
1941
+		}
1942
+	}
1943
+
1944
+
1945
+	/**
1946
+	 * _get_REG_IDs_to_apply_payment_to
1947
+	 * returns a list of registration IDs that the payment will apply to
1948
+	 *
1949
+	 * @param EE_Payment $payment
1950
+	 * @return array
1951
+	 * @throws EE_Error
1952
+	 * @throws InvalidArgumentException
1953
+	 * @throws InvalidDataTypeException
1954
+	 * @throws InvalidInterfaceException
1955
+	 * @throws ReflectionException
1956
+	 */
1957
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1958
+	{
1959
+		// grab array of IDs for specific registrations to apply changes to
1960
+		$REG_IDs = $this->request->getRequestParam('txn_admin_payment[registrations]', [], 'int', true);
1961
+		// nothing specified ? then get all reg IDs
1962
+		if (empty($REG_IDs)) {
1963
+			$registrations = $payment->transaction()->registrations();
1964
+			$REG_IDs       = ! empty($registrations)
1965
+				? array_keys($registrations)
1966
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1967
+		}
1968
+
1969
+		// ensure that REG_IDs are integers and NOT strings
1970
+		return array_map('intval', $REG_IDs);
1971
+	}
1972
+
1973
+
1974
+	/**
1975
+	 * @return array
1976
+	 */
1977
+	public function existing_reg_payment_REG_IDs()
1978
+	{
1979
+		return $this->_existing_reg_payment_REG_IDs;
1980
+	}
1981
+
1982
+
1983
+	/**
1984
+	 * @param array $existing_reg_payment_REG_IDs
1985
+	 */
1986
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1987
+	{
1988
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1989
+	}
1990
+
1991
+
1992
+	/**
1993
+	 * _get_existing_reg_payment_REG_IDs
1994
+	 * returns a list of registration IDs that the payment is currently related to
1995
+	 * as recorded in the database
1996
+	 *
1997
+	 * @param EE_Payment $payment
1998
+	 * @return array
1999
+	 * @throws EE_Error
2000
+	 * @throws InvalidArgumentException
2001
+	 * @throws InvalidDataTypeException
2002
+	 * @throws InvalidInterfaceException
2003
+	 * @throws ReflectionException
2004
+	 */
2005
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
2006
+	{
2007
+		if ($this->existing_reg_payment_REG_IDs() === null) {
2008
+			// let's get any existing reg payment records for this payment
2009
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
2010
+			// but we only want the REG IDs, so grab the array keys
2011
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
2012
+				? array_keys($existing_reg_payment_REG_IDs)
2013
+				: [];
2014
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
2015
+		}
2016
+
2017
+		return $this->existing_reg_payment_REG_IDs();
2018
+	}
2019
+
2020
+
2021
+	/**
2022
+	 * _remove_existing_registration_payments
2023
+	 * this calculates the difference between existing relations
2024
+	 * to the supplied payment and the new list registration IDs,
2025
+	 * removes any related registrations that no longer apply,
2026
+	 * and then updates the registration paid fields
2027
+	 *
2028
+	 * @param EE_Payment $payment
2029
+	 * @param int        $PAY_ID
2030
+	 * @return bool;
2031
+	 * @throws EE_Error
2032
+	 * @throws InvalidArgumentException
2033
+	 * @throws ReflectionException
2034
+	 * @throws InvalidDataTypeException
2035
+	 * @throws InvalidInterfaceException
2036
+	 */
2037
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2038
+	{
2039
+		// newly created payments will have nothing recorded for $PAY_ID
2040
+		if (absint($PAY_ID) === 0) {
2041
+			return false;
2042
+		}
2043
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2044
+		if (empty($existing_reg_payment_REG_IDs)) {
2045
+			return false;
2046
+		}
2047
+		/** @type EE_Transaction_Payments $transaction_payments */
2048
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2049
+
2050
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
2051
+			$payment,
2052
+			[
2053
+				[
2054
+					'PAY_ID' => $payment->ID(),
2055
+					'REG_ID' => ['IN', $existing_reg_payment_REG_IDs],
2056
+				],
2057
+			]
2058
+		);
2059
+	}
2060
+
2061
+
2062
+	/**
2063
+	 * _update_registration_payments
2064
+	 * this applies the payments to the selected registrations
2065
+	 * but only if they have not already been paid for
2066
+	 *
2067
+	 * @param EE_Transaction $transaction
2068
+	 * @param EE_Payment     $payment
2069
+	 * @param array          $REG_IDs
2070
+	 * @return void
2071
+	 * @throws EE_Error
2072
+	 * @throws InvalidArgumentException
2073
+	 * @throws ReflectionException
2074
+	 * @throws RuntimeException
2075
+	 * @throws InvalidDataTypeException
2076
+	 * @throws InvalidInterfaceException
2077
+	 */
2078
+	protected function _update_registration_payments(
2079
+		EE_Transaction $transaction,
2080
+		EE_Payment $payment,
2081
+		$REG_IDs = []
2082
+	) {
2083
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2084
+		// so let's do that using our set of REG_IDs from the form
2085
+		$registration_query_where_params = [
2086
+			'REG_ID' => ['IN', $REG_IDs],
2087
+		];
2088
+		// but add in some conditions regarding payment,
2089
+		// so that we don't apply payments to registrations that are free or have already been paid for
2090
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2091
+		if (! $payment->is_a_refund()) {
2092
+			$registration_query_where_params['REG_final_price']  = ['!=', 0];
2093
+			$registration_query_where_params['REG_final_price*'] = ['!=', 'REG_paid', true];
2094
+		}
2095
+		$registrations = $transaction->registrations([$registration_query_where_params]);
2096
+		if (! empty($registrations)) {
2097
+			/** @type EE_Payment_Processor $payment_processor */
2098
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2099
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
2100
+		}
2101
+	}
2102
+
2103
+
2104
+	/**
2105
+	 * _process_registration_status_change
2106
+	 * This processes requested registration status changes for all the registrations
2107
+	 * on a given transaction and (optionally) sends out notifications for the changes.
2108
+	 *
2109
+	 * @param EE_Transaction $transaction
2110
+	 * @param array          $REG_IDs
2111
+	 * @return bool
2112
+	 * @throws EE_Error
2113
+	 * @throws InvalidArgumentException
2114
+	 * @throws ReflectionException
2115
+	 * @throws InvalidDataTypeException
2116
+	 * @throws InvalidInterfaceException
2117
+	 */
2118
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = [])
2119
+	{
2120
+		// first if there is no change in status then we get out.
2121
+		$reg_status = $this->request->getRequestParam('txn_reg_status_change[reg_status]', 'NAN');
2122
+		if ($reg_status === 'NAN') {
2123
+			// no error message, no change requested, just nothing to do man.
2124
+			return false;
2125
+		}
2126
+		/** @type EE_Transaction_Processor $transaction_processor */
2127
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2128
+
2129
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2130
+		return $transaction_processor->manually_update_registration_statuses(
2131
+			$transaction,
2132
+			$reg_status,
2133
+			[['REG_ID' => ['IN', $REG_IDs]]]
2134
+		);
2135
+	}
2136
+
2137
+
2138
+	/**
2139
+	 * _build_payment_json_response
2140
+	 *
2141
+	 * @access public
2142
+	 * @param EE_Payment  $payment
2143
+	 * @param array       $REG_IDs
2144
+	 * @param bool | null $delete_txn_reg_status_change
2145
+	 * @return array
2146
+	 * @throws EE_Error
2147
+	 * @throws InvalidArgumentException
2148
+	 * @throws InvalidDataTypeException
2149
+	 * @throws InvalidInterfaceException
2150
+	 * @throws ReflectionException
2151
+	 */
2152
+	protected function _build_payment_json_response(
2153
+		EE_Payment $payment,
2154
+		$REG_IDs = [],
2155
+		$delete_txn_reg_status_change = null
2156
+	) {
2157
+		// was the payment deleted ?
2158
+		if (is_bool($delete_txn_reg_status_change)) {
2159
+			return [
2160
+				'PAY_ID'                       => $payment->ID(),
2161
+				'amount'                       => $payment->amount(),
2162
+				'total_paid'                   => $payment->transaction()->paid(),
2163
+				'txn_status'                   => $payment->transaction()->status_ID(),
2164
+				'pay_status'                   => $payment->STS_ID(),
2165
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2166
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2167
+			];
2168
+		}
2169
+
2170
+		$this->_get_payment_status_array();
2171
+		return [
2172
+			'amount'           => $payment->amount(),
2173
+			'total_paid'       => $payment->transaction()->paid(),
2174
+			'txn_status'       => $payment->transaction()->status_ID(),
2175
+			'pay_status'       => $payment->STS_ID(),
2176
+			'PAY_ID'           => $payment->ID(),
2177
+			'STS_ID'           => $payment->STS_ID(),
2178
+			'status'           => self::$_pay_status[ $payment->STS_ID() ],
2179
+			'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2180
+			'method'           => strtoupper($payment->source()),
2181
+			'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2182
+			'gateway'          => $payment->payment_method()
2183
+				? $payment->payment_method()->admin_name()
2184
+				: esc_html__('Unknown', 'event_espresso'),
2185
+			'gateway_response' => $payment->gateway_response(),
2186
+			'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2187
+			'po_number'        => $payment->po_number(),
2188
+			'extra_accntng'    => $payment->extra_accntng(),
2189
+			'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2190
+		];
2191
+	}
2192
+
2193
+
2194
+	/**
2195
+	 * delete_payment
2196
+	 *    delete a payment or refund made towards a transaction
2197
+	 *
2198
+	 * @access public
2199
+	 * @return void
2200
+	 * @throws EE_Error
2201
+	 * @throws InvalidArgumentException
2202
+	 * @throws ReflectionException
2203
+	 * @throws InvalidDataTypeException
2204
+	 * @throws InvalidInterfaceException
2205
+	 */
2206
+	public function delete_payment()
2207
+	{
2208
+		$json_response_data = ['return_data' => false];
2209
+		$PAY_ID = $this->request->getRequestParam('delete_txn_admin_payment[PAY_ID]', 0, 'int');
2210
+
2211
+		$can_delete         = EE_Registry::instance()->CAP->current_user_can(
2212
+			'ee_delete_payments',
2213
+			'delete_payment_from_registration_details'
2214
+		);
2215
+		if ($PAY_ID && $can_delete) {
2216
+			$delete_txn_reg_status_change = $this->request->getRequestParam(
2217
+				'delete_txn_reg_status_change',
2218
+				false,
2219
+				'bool'
2220
+			);
2221
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2222
+			if ($payment instanceof EE_Payment) {
2223
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2224
+				/** @type EE_Transaction_Payments $transaction_payments */
2225
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2226
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2227
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2228
+						$payment,
2229
+						$REG_IDs,
2230
+						$delete_txn_reg_status_change
2231
+					);
2232
+					if ($delete_txn_reg_status_change) {
2233
+						// MAKE sure we also add the delete_txn_req_status_change to the
2234
+						// request data because that's how messages will be looking for it.
2235
+						$this->request->setRequestParam('txn_reg_status_change', $delete_txn_reg_status_change);
2236
+						$this->_maybe_send_notifications();
2237
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2238
+					}
2239
+				}
2240
+			} else {
2241
+				EE_Error::add_error(
2242
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2243
+					__FILE__,
2244
+					__FUNCTION__,
2245
+					__LINE__
2246
+				);
2247
+			}
2248
+		} elseif ($can_delete) {
2249
+			EE_Error::add_error(
2250
+				esc_html__(
2251
+					'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2252
+					'event_espresso'
2253
+				),
2254
+				__FILE__,
2255
+				__FUNCTION__,
2256
+				__LINE__
2257
+			);
2258
+		} else {
2259
+			EE_Error::add_error(
2260
+				esc_html__(
2261
+					'You do not have access to delete a payment.',
2262
+					'event_espresso'
2263
+				),
2264
+				__FILE__,
2265
+				__FUNCTION__,
2266
+				__LINE__
2267
+			);
2268
+		}
2269
+		$notices              = EE_Error::get_notices(false, false, false);
2270
+		$this->_template_args = [
2271
+			'data'      => $json_response_data,
2272
+			'success'   => $notices['success'],
2273
+			'error'     => $notices['errors'],
2274
+			'attention' => $notices['attention'],
2275
+		];
2276
+		$this->_return_json();
2277
+	}
2278
+
2279
+
2280
+	/**
2281
+	 * _registration_payment_data_array
2282
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2283
+	 *
2284
+	 * @access protected
2285
+	 * @param array $REG_IDs
2286
+	 * @return array
2287
+	 * @throws EE_Error
2288
+	 * @throws InvalidArgumentException
2289
+	 * @throws InvalidDataTypeException
2290
+	 * @throws InvalidInterfaceException
2291
+	 * @throws ReflectionException
2292
+	 */
2293
+	protected function _registration_payment_data_array($REG_IDs)
2294
+	{
2295
+		$registration_payment_data = [];
2296
+		// if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2297
+		if (! empty($REG_IDs)) {
2298
+			$registrations = EEM_Registration::instance()->get_all([['REG_ID' => ['IN', $REG_IDs]]]);
2299
+			foreach ($registrations as $registration) {
2300
+				if ($registration instanceof EE_Registration) {
2301
+					$registration_payment_data[ $registration->ID() ] = [
2302
+						'paid'  => $registration->pretty_paid(),
2303
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2304
+					];
2305
+				}
2306
+			}
2307
+		}
2308
+
2309
+		return $registration_payment_data;
2310
+	}
2311
+
2312
+
2313
+	/**
2314
+	 * _maybe_send_notifications
2315
+	 * determines whether or not the admin has indicated that notifications should be sent.
2316
+	 * If so, will toggle a filter switch for delivering registration notices.
2317
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2318
+	 *
2319
+	 * @access protected
2320
+	 * @param EE_Payment | null $payment
2321
+	 */
2322
+	protected function _maybe_send_notifications($payment = null)
2323
+	{
2324
+		switch ($payment instanceof EE_Payment) {
2325
+			// payment notifications
2326
+			case true:
2327
+				if ($this->request->getRequestParam('txn_payments[send_notifications]', false, 'bool')) {
2328
+					$this->_process_payment_notification($payment);
2329
+				}
2330
+				break;
2331
+			// registration notifications
2332
+			case false:
2333
+				if ($this->request->getRequestParam('txn_reg_status_change[send_notifications]', false, 'bool')) {
2334
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2335
+				}
2336
+				break;
2337
+		}
2338
+	}
2339
+
2340
+
2341
+	/**
2342
+	 * _send_payment_reminder
2343
+	 *    generates HTML for the View Transaction Details Admin page
2344
+	 *
2345
+	 * @access protected
2346
+	 * @return void
2347
+	 * @throws EE_Error
2348
+	 * @throws InvalidArgumentException
2349
+	 * @throws InvalidDataTypeException
2350
+	 * @throws InvalidInterfaceException
2351
+	 */
2352
+	protected function _send_payment_reminder()
2353
+	{
2354
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2355
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2356
+		$redirect_to = $this->request->getRequestParam('redirect_to');
2357
+		$query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2358
+		do_action(
2359
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2360
+			$transaction
2361
+		);
2362
+		$this->_redirect_after_action(
2363
+			false,
2364
+			esc_html__('payment reminder', 'event_espresso'),
2365
+			esc_html__('sent', 'event_espresso'),
2366
+			$query_args,
2367
+			true
2368
+		);
2369
+	}
2370
+
2371
+
2372
+	/**
2373
+	 *  get_transactions
2374
+	 *    get transactions for given parameters (used by list table)
2375
+	 *
2376
+	 * @param int     $per_page how many transactions displayed per page
2377
+	 * @param boolean $count   return the count or objects
2378
+	 * @param string  $view
2379
+	 * @return EE_Transaction[]|int int = count || array of transaction objects
2380
+	 * @throws EE_Error
2381
+	 * @throws InvalidArgumentException
2382
+	 * @throws InvalidDataTypeException
2383
+	 * @throws InvalidInterfaceException
2384
+	 */
2385
+	public function get_transactions($per_page, $count = false, $view = '')
2386
+	{
2387
+		$start_date = wp_strip_all_tags(
2388
+			$this->request->getRequestParam('txn-filter-start-date', date('m/d/Y', strtotime('-10 year')))
2389
+		);
2390
+		$end_date = wp_strip_all_tags(
2391
+			$this->request->getRequestParam('txn-filter-end-date', date('m/d/Y'))
2392
+		);
2393
+
2394
+		// make sure our timestamps start and end right at the boundaries for each day
2395
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2396
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2397
+
2398
+
2399
+		// convert to timestamps
2400
+		$start_date = strtotime($start_date);
2401
+		$end_date   = strtotime($end_date);
2402
+
2403
+		// makes sure start date is the lowest value and vice versa
2404
+		$start_date = min($start_date, $end_date);
2405
+		$end_date   = max($start_date, $end_date);
2406
+
2407
+		// convert to correct format for query
2408
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2409
+			'TXN_timestamp',
2410
+			date('Y-m-d H:i:s', $start_date),
2411
+			'Y-m-d H:i:s'
2412
+		);
2413
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2414
+			'TXN_timestamp',
2415
+			date('Y-m-d H:i:s', $end_date),
2416
+			'Y-m-d H:i:s'
2417
+		);
2418
+
2419
+
2420
+		// set orderby
2421
+		$orderby = $this->request->getRequestParam('orderby');
2422
+
2423
+		switch ($orderby) {
2424
+			case 'TXN_ID':
2425
+				break;
2426
+			case 'ATT_fname':
2427
+				$orderby = 'Registration.Attendee.ATT_fname';
2428
+				break;
2429
+			case 'event_name':
2430
+				$orderby = 'Registration.Event.EVT_name';
2431
+				break;
2432
+			default: // 'TXN_timestamp'
2433
+				$orderby = 'TXN_timestamp';
2434
+		}
2435
+
2436
+		$sort         = $this->request->getRequestParam('order', 'DESC');
2437
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
2438
+
2439
+		$per_page = absint($per_page) ? $per_page : 10;
2440
+		$per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
2441
+
2442
+		$offset = ($current_page - 1) * $per_page;
2443
+		$limit  = [$offset, $per_page];
2444
+
2445
+		$_where = [
2446
+			'TXN_timestamp'          => ['BETWEEN', [$start_date, $end_date]],
2447
+			'Registration.REG_count' => 1,
2448
+		];
2449
+
2450
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2451
+		if ($EVT_ID) {
2452
+			$_where['Registration.EVT_ID'] = $EVT_ID;
2453
+		}
2454
+
2455
+		$search_term = $this->request->getRequestParam('s');
2456
+		if ($search_term) {
2457
+			$search_term = '%' . $search_term . '%';
2458
+			$_where['OR']  = [
2459
+				'Registration.Event.EVT_name'         => ['LIKE', $search_term],
2460
+				'Registration.Event.EVT_desc'         => ['LIKE', $search_term],
2461
+				'Registration.Event.EVT_short_desc'   => ['LIKE', $search_term],
2462
+				'Registration.Attendee.ATT_full_name' => ['LIKE', $search_term],
2463
+				'Registration.Attendee.ATT_fname'     => ['LIKE', $search_term],
2464
+				'Registration.Attendee.ATT_lname'     => ['LIKE', $search_term],
2465
+				'Registration.Attendee.ATT_short_bio' => ['LIKE', $search_term],
2466
+				'Registration.Attendee.ATT_email'     => ['LIKE', $search_term],
2467
+				'Registration.Attendee.ATT_address'   => ['LIKE', $search_term],
2468
+				'Registration.Attendee.ATT_address2'  => ['LIKE', $search_term],
2469
+				'Registration.Attendee.ATT_city'      => ['LIKE', $search_term],
2470
+				'Registration.REG_final_price'        => ['LIKE', $search_term],
2471
+				'Registration.REG_code'               => ['LIKE', $search_term],
2472
+				'Registration.REG_count'              => ['LIKE', $search_term],
2473
+				'Registration.REG_group_size'         => ['LIKE', $search_term],
2474
+				'Registration.Ticket.TKT_name'        => ['LIKE', $search_term],
2475
+				'Registration.Ticket.TKT_description' => ['LIKE', $search_term],
2476
+				'Payment.PAY_source'                  => ['LIKE', $search_term],
2477
+				'Payment.Payment_Method.PMD_name'     => ['LIKE', $search_term],
2478
+				'TXN_session_data'                    => ['LIKE', $search_term],
2479
+				'Payment.PAY_txn_id_chq_nmbr'         => ['LIKE', $search_term],
2480
+			];
2481
+		}
2482
+
2483
+		$status = $this->request->getRequestParam('status');
2484
+		// failed transactions
2485
+		$failed     = (! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2486
+		$abandoned  = (! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2487
+		$incomplete = (! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2488
+
2489
+		if ($failed) {
2490
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2491
+		} elseif ($abandoned) {
2492
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2493
+		} elseif ($incomplete) {
2494
+			$_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2495
+		} else {
2496
+			$_where['STS_ID']  = ['!=', EEM_Transaction::failed_status_code];
2497
+			$_where['STS_ID*'] = ['!=', EEM_Transaction::abandoned_status_code];
2498
+		}
2499
+
2500
+		$query_params = apply_filters(
2501
+			'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2502
+			[
2503
+				$_where,
2504
+				'order_by'                 => [$orderby => $sort],
2505
+				'limit'                    => $limit,
2506
+				'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2507
+			],
2508
+			$this->request->requestParams(),
2509
+			$view,
2510
+			$count
2511
+		);
2512
+
2513
+		return $count
2514
+			? EEM_Transaction::instance()->count([$query_params[0]], 'TXN_ID', true)
2515
+			: EEM_Transaction::instance()->get_all($query_params);
2516
+	}
2517
+
2518
+
2519
+	/**
2520
+	 * @throws EE_Error
2521
+	 * @throws InvalidArgumentException
2522
+	 * @throws InvalidDataTypeException
2523
+	 * @throws InvalidInterfaceException
2524
+	 * @throws ReflectionException
2525
+	 * @throws RuntimeException
2526
+	 * @since 4.9.79.p
2527
+	 */
2528
+	public function recalculateLineItems()
2529
+	{
2530
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2531
+		/** @var EE_Transaction $transaction */
2532
+		$transaction     = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2533
+		$success         = $transaction->recalculateLineItems();
2534
+		$redirect_to = $this->request->getRequestParam('redirect_to');
2535
+		$query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2536
+		$this->_redirect_after_action(
2537
+			$success,
2538
+			esc_html__('Transaction taxes and totals', 'event_espresso'),
2539
+			esc_html__('recalculated', 'event_espresso'),
2540
+			$query_args,
2541
+			true
2542
+		);
2543
+	}
2544 2544
 }
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
             'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
251 251
             'event_espresso'
252 252
         );
253
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
253
+        EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
254 254
             'An error occurred! Please refresh the page and try again.',
255 255
             'event_espresso'
256 256
         );
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
         // enqueue style
350 350
         wp_register_style(
351 351
             'espresso_txn',
352
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
352
+            TXN_ASSETS_URL.'espresso_transactions_admin.css',
353 353
             [],
354 354
             EVENT_ESPRESSO_VERSION
355 355
         );
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
         // scripts
358 358
         wp_register_script(
359 359
             'espresso_txn',
360
-            TXN_ASSETS_URL . 'espresso_transactions_admin.js',
360
+            TXN_ASSETS_URL.'espresso_transactions_admin.js',
361 361
             [
362 362
                 'ee_admin_js',
363 363
                 'ee-datepicker',
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
             $this->_transaction->verify_abandoned_transaction_status();
485 485
         }
486 486
 
487
-        if (! $this->_transaction instanceof EE_Transaction) {
487
+        if ( ! $this->_transaction instanceof EE_Transaction) {
488 488
             $error_msg = sprintf(
489 489
                 esc_html__(
490 490
                     'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
             'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
582 582
             [
583 583
                 'overpaid'   => [
584
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::overpaid_status_code,
584
+                    'class' => 'ee-status-legend ee-status-bg--'.EEM_Transaction::overpaid_status_code,
585 585
                     'desc'  => EEH_Template::pretty_status(
586 586
                         EEM_Transaction::overpaid_status_code,
587 587
                         false,
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
                     ),
590 590
                 ],
591 591
                 'complete'   => [
592
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::complete_status_code,
592
+                    'class' => 'ee-status-legend ee-status-bg--'.EEM_Transaction::complete_status_code,
593 593
                     'desc'  => EEH_Template::pretty_status(
594 594
                         EEM_Transaction::complete_status_code,
595 595
                         false,
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
                     ),
598 598
                 ],
599 599
                 'incomplete' => [
600
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::incomplete_status_code,
600
+                    'class' => 'ee-status-legend ee-status-bg--'.EEM_Transaction::incomplete_status_code,
601 601
                     'desc'  => EEH_Template::pretty_status(
602 602
                         EEM_Transaction::incomplete_status_code,
603 603
                         false,
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
                     ),
606 606
                 ],
607 607
                 'abandoned'  => [
608
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::abandoned_status_code,
608
+                    'class' => 'ee-status-legend ee-status-bg--'.EEM_Transaction::abandoned_status_code,
609 609
                     'desc'  => EEH_Template::pretty_status(
610 610
                         EEM_Transaction::abandoned_status_code,
611 611
                         false,
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
                     ),
614 614
                 ],
615 615
                 'failed'     => [
616
-                    'class' => 'ee-status-legend ee-status-bg--' . EEM_Transaction::failed_status_code,
616
+                    'class' => 'ee-status-legend ee-status-bg--'.EEM_Transaction::failed_status_code,
617 617
                     'desc'  => EEH_Template::pretty_status(
618 618
                         EEM_Transaction::failed_status_code,
619 619
                         false,
@@ -656,11 +656,11 @@  discard block
 block discarded – undo
656 656
                 )
657 657
                 . '" title="'
658 658
                 . esc_attr__('Click to Edit event', 'event_espresso')
659
-                . '">' . $event->name() . '</a>',
659
+                . '">'.$event->name().'</a>',
660 660
                 '</h3>'
661 661
             )
662 662
             : '';
663
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
663
+        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
664 664
         $this->display_admin_list_table_page_with_no_sidebar();
665 665
     }
666 666
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 
691 691
         $this->_set_transaction_object();
692 692
 
693
-        if (! $this->_transaction instanceof EE_Transaction) {
693
+        if ( ! $this->_transaction instanceof EE_Transaction) {
694 694
             return;
695 695
         }
696 696
 
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
         $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
701 701
         $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
702 702
 
703
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
703
+        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->status_ID()];
704 704
         $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
705 705
         $this->_template_args['txn_status']['class'] = $this->_transaction->status_ID();
706 706
 
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 
755 755
 
756 756
         // next link
757
-        $next_txn                                 = $this->_transaction->next(
757
+        $next_txn = $this->_transaction->next(
758 758
             null,
759 759
             [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
760 760
             'TXN_ID'
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
             )
770 770
             : '';
771 771
         // previous link
772
-        $previous_txn                                 = $this->_transaction->previous(
772
+        $previous_txn = $this->_transaction->previous(
773 773
             null,
774 774
             [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
775 775
             'TXN_ID'
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
         // grab messages at the last second
822 822
         $this->_template_args['notices'] = EE_Error::get_notices();
823 823
         // path to template
824
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
824
+        $template_path                             = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php';
825 825
         $this->_template_args['admin_page_header'] = EEH_Template::display_template(
826 826
             $template_path,
827 827
             $this->_template_args,
@@ -850,19 +850,19 @@  discard block
 block discarded – undo
850 850
 
851 851
         $this->_set_transaction_object();
852 852
 
853
-        if (! $this->_transaction instanceof EE_Transaction) {
853
+        if ( ! $this->_transaction instanceof EE_Transaction) {
854 854
             return;
855 855
         }
856 856
         $this->addMetaBox(
857 857
             'edit-txn-details-mbox',
858
-            '<span>' . esc_html__('Transaction Details', 'event_espresso')
858
+            '<span>'.esc_html__('Transaction Details', 'event_espresso')
859 859
             . '&nbsp;<span class="dashicons dashicons-cart" ></span></span>',
860 860
             [$this, 'txn_details_meta_box'],
861 861
             $this->_wp_page_slug
862 862
         );
863 863
         $this->addMetaBox(
864 864
             'edit-txn-attendees-mbox',
865
-            '<span>' . esc_html__('Attendees Registered in this Transaction', 'event_espresso')
865
+            '<span>'.esc_html__('Attendees Registered in this Transaction', 'event_espresso')
866 866
             . '&nbsp;<span class="dashicons dashicons-groups" ></span></span>',
867 867
             [$this, 'txn_attendees_meta_box'],
868 868
             $this->_wp_page_slug,
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
     {
905 905
         $content = '';
906 906
         $actions = [];
907
-        if (! $transaction instanceof EE_Transaction) {
907
+        if ( ! $transaction instanceof EE_Transaction) {
908 908
             return $content;
909 909
         }
910 910
         /** @var EE_Registration $primary_registration */
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
             $this->_transaction->primary_registration() instanceof EE_Registration
1019 1019
                 ? $this->_transaction->primary_registration()->attendee()
1020 1020
                 : null;
1021
-        $this->_template_args['can_edit_payments']   = EE_Registry::instance()->CAP->current_user_can(
1021
+        $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
1022 1022
             'ee_edit_payments',
1023 1023
             'apply_payment_or_refund_from_registration_details'
1024 1024
         );
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 
1030 1030
         // get line table
1031 1031
         EEH_Autoloader::register_line_item_display_autoloaders();
1032
-        $Line_Item_Display                       = new EE_Line_Item_Display(
1032
+        $Line_Item_Display = new EE_Line_Item_Display(
1033 1033
             'admin_table',
1034 1034
             'EE_Admin_Table_Line_Item_Display_Strategy'
1035 1035
         );
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
         $taxes                         = $this->_transaction->line_items([['LIN_type' => EEM_Line_Item::type_tax]]);
1045 1045
         $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1046 1046
 
1047
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
1047
+        $this->_template_args['grand_total'] = EEH_Template::format_currency(
1048 1048
             $this->_transaction->total(),
1049 1049
             false,
1050 1050
             false
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
 
1055 1055
         // process payment details
1056 1056
         $payments = $this->_transaction->payments();
1057
-        if (! empty($payments)) {
1057
+        if ( ! empty($payments)) {
1058 1058
             $this->_template_args['payments']              = $payments;
1059 1059
             $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1060 1060
         } else {
@@ -1116,7 +1116,7 @@  discard block
 block discarded – undo
1116 1116
                                   esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1117 1117
                                   ucwords(str_replace('_', ' ', $reg_step)),
1118 1118
                                   date(
1119
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1119
+                                      get_option('date_format').' '.get_option('time_format'),
1120 1120
                                       $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1121 1121
                                   )
1122 1122
                               )
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
                               . '</li>';
1131 1131
             }
1132 1132
         }
1133
-        $reg_steps                                                 .= '</ul>';
1133
+        $reg_steps .= '</ul>';
1134 1134
         $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1135 1135
         $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1136 1136
             'Registration Step Progress',
@@ -1143,14 +1143,14 @@  discard block
 block discarded – undo
1143 1143
         $this->_get_payment_status_array();
1144 1144
         $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1145 1145
 
1146
-        $this->_template_args['transaction_form_url']    = add_query_arg(
1146
+        $this->_template_args['transaction_form_url'] = add_query_arg(
1147 1147
             [
1148 1148
                 'action'  => 'edit_transaction',
1149 1149
                 'process' => 'transaction',
1150 1150
             ],
1151 1151
             TXN_ADMIN_URL
1152 1152
         );
1153
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(
1153
+        $this->_template_args['apply_payment_form_url'] = add_query_arg(
1154 1154
             [
1155 1155
                 'page'   => 'espresso_transactions',
1156 1156
                 'action' => 'espresso_apply_payment',
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 
1170 1170
         // 'espresso_delete_payment_nonce'
1171 1171
 
1172
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1172
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php';
1173 1173
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1174 1174
     }
1175 1175
 
@@ -1201,19 +1201,19 @@  discard block
 block discarded – undo
1201 1201
                 ],
1202 1202
             ]
1203 1203
         );
1204
-        if (! empty($reg_payments)) {
1204
+        if ( ! empty($reg_payments)) {
1205 1205
             foreach ($payments as $payment) {
1206
-                if (! $payment instanceof EE_Payment) {
1206
+                if ( ! $payment instanceof EE_Payment) {
1207 1207
                     continue;
1208
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1209
-                    $existing_reg_payments[ $payment->ID() ] = [];
1208
+                } elseif ( ! isset($existing_reg_payments[$payment->ID()])) {
1209
+                    $existing_reg_payments[$payment->ID()] = [];
1210 1210
                 }
1211 1211
                 foreach ($reg_payments as $reg_payment) {
1212 1212
                     if (
1213 1213
                         $reg_payment instanceof EE_Registration_Payment
1214 1214
                         && $reg_payment->payment_ID() === $payment->ID()
1215 1215
                     ) {
1216
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1216
+                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1217 1217
                     }
1218 1218
                 }
1219 1219
             }
@@ -1239,7 +1239,7 @@  discard block
 block discarded – undo
1239 1239
     protected function _get_registrations_to_apply_payment_to()
1240 1240
     {
1241 1241
         // we want any registration with an active status (ie: not deleted or cancelled)
1242
-        $query_params                      = [
1242
+        $query_params = [
1243 1243
             [
1244 1244
                 'STS_ID' => [
1245 1245
                     'IN',
@@ -1251,22 +1251,22 @@  discard block
 block discarded – undo
1251 1251
                 ],
1252 1252
             ],
1253 1253
         ];
1254
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1254
+        $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div(
1255 1255
             '',
1256 1256
             'txn-admin-apply-payment-to-registrations-dv',
1257 1257
             '',
1258 1258
             'clear: both; margin: 1.5em 0 0; display: none;'
1259 1259
         );
1260
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1260
+        $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1261 1261
         $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl striped');
1262 1262
         $registrations_to_apply_payment_to .= EEH_HTML::thead(
1263 1263
             EEH_HTML::tr(
1264
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1265
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1266
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1267
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1268
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1269
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1264
+                EEH_HTML::th(esc_html__('ID', 'event_espresso')).
1265
+                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')).
1266
+                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')).
1267
+                EEH_HTML::th(esc_html__('Event', 'event_espresso')).
1268
+                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr').
1269
+                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr').
1270 1270
                 EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1271 1271
             )
1272 1272
         );
@@ -1281,34 +1281,34 @@  discard block
 block discarded – undo
1281 1281
                     : esc_html__('Unknown Attendee', 'event_espresso');
1282 1282
                 $owing                             = $registration->final_price() - $registration->paid();
1283 1283
                 $taxable                           = $registration->ticket()->taxable()
1284
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1284
+                    ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>'
1285 1285
                     : '';
1286 1286
                 $checked                           = empty($existing_reg_payments)
1287 1287
                                                      || in_array($registration->ID(), $existing_reg_payments, true)
1288 1288
                     ? ' checked="checked"'
1289 1289
                     : '';
1290
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1290
+                $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1291 1291
                 $registrations_to_apply_payment_to .= EEH_HTML::tr(
1292
-                    EEH_HTML::td($registration->ID()) .
1293
-                    EEH_HTML::td($attendee_name) .
1292
+                    EEH_HTML::td($registration->ID()).
1293
+                    EEH_HTML::td($attendee_name).
1294 1294
                     EEH_HTML::td(
1295
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1296
-                    ) .
1297
-                    EEH_HTML::td($registration->event_name()) .
1298
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1295
+                        $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable
1296
+                    ).
1297
+                    EEH_HTML::td($registration->event_name()).
1298
+                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr').
1299 1299
                     EEH_HTML::td(
1300 1300
                         EEH_Template::format_currency($owing),
1301 1301
                         '',
1302 1302
                         'txn-admin-payment-owing-td jst-cntr'
1303
-                    ) .
1303
+                    ).
1304 1304
                     EEH_HTML::td(
1305
-                        '<input type="checkbox" value="' . $registration->ID()
1305
+                        '<input type="checkbox" value="'.$registration->ID()
1306 1306
                         . '" name="txn_admin_payment[registrations]"'
1307
-                        . $checked . $disabled . '>',
1307
+                        . $checked.$disabled.'>',
1308 1308
                         '',
1309 1309
                         'jst-cntr'
1310 1310
                     ),
1311
-                    'apply-payment-registration-row-' . $registration->ID()
1311
+                    'apply-payment-registration-row-'.$registration->ID()
1312 1312
                 );
1313 1313
             }
1314 1314
         }
@@ -1323,7 +1323,7 @@  discard block
 block discarded – undo
1323 1323
             '',
1324 1324
             'clear description'
1325 1325
         );
1326
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1326
+        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1327 1327
         $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1328 1328
     }
1329 1329
 
@@ -1389,12 +1389,12 @@  discard block
 block discarded – undo
1389 1389
                 [
1390 1390
                     'OR*payment_method_for_payment' => [
1391 1391
                         'PMD_ID'    => ['IN', $payment_methods_of_payments],
1392
-                        'PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%'],
1392
+                        'PMD_scope' => ['LIKE', '%'.EEM_Payment_Method::scope_admin.'%'],
1393 1393
                     ],
1394 1394
                 ],
1395 1395
             ];
1396 1396
         } else {
1397
-            $query_args = [['PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%']]];
1397
+            $query_args = [['PMD_scope' => ['LIKE', '%'.EEM_Payment_Method::scope_admin.'%']]];
1398 1398
         }
1399 1399
         $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1400 1400
     }
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
             'Line_Item',
1428 1428
             [['LIN_type' => 'line-item']]
1429 1429
         );
1430
-        if (! empty($line_items)) {
1430
+        if ( ! empty($line_items)) {
1431 1431
             foreach ($line_items as $item) {
1432 1432
                 if ($item instanceof EE_Line_Item) {
1433 1433
                     switch ($item->OBJ_type()) {
@@ -1437,7 +1437,7 @@  discard block
 block discarded – undo
1437 1437
                             $ticket = $item->ticket();
1438 1438
                             // right now we're only handling tickets here.
1439 1439
                             // Cause its expected that only tickets will have attendees right?
1440
-                            if (! $ticket instanceof EE_Ticket) {
1440
+                            if ( ! $ticket instanceof EE_Ticket) {
1441 1441
                                 break;
1442 1442
                             }
1443 1443
                             try {
@@ -1446,45 +1446,45 @@  discard block
 block discarded – undo
1446 1446
                                 EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1447 1447
                                 $event_name = esc_html__('Unknown Event', 'event_espresso');
1448 1448
                             }
1449
-                            $event_name   .= ' - ' . $item->name();
1449
+                            $event_name   .= ' - '.$item->name();
1450 1450
                             $ticket_price = EEH_Template::format_currency($item->unit_price());
1451 1451
                             // now get all of the registrations for this transaction that use this ticket
1452 1452
                             $registrations = $ticket->registrations(
1453 1453
                                 [['TXN_ID' => $this->_transaction->ID()]]
1454 1454
                             );
1455 1455
                             foreach ($registrations as $registration) {
1456
-                                if (! $registration instanceof EE_Registration) {
1456
+                                if ( ! $registration instanceof EE_Registration) {
1457 1457
                                     break;
1458 1458
                                 }
1459
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1459
+                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1460 1460
                                     = $registration->status_ID();
1461
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1461
+                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']
1462 1462
                                     = $registration->count();
1463
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1463
+                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1464 1464
                                     = $event_name;
1465
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1465
+                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1466 1466
                                     = $ticket_price;
1467 1467
                                 // attendee info
1468 1468
                                 $attendee = $registration->get_first_related('Attendee');
1469 1469
                                 if ($attendee instanceof EE_Attendee) {
1470
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1470
+                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']
1471 1471
                                         = $attendee->ID();
1472
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1472
+                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1473 1473
                                         = $attendee->full_name();
1474
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1475
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1474
+                                    $this->_template_args['event_attendees'][$registration->ID()]['email']
1475
+                                        = '<a href="mailto:'.$attendee->email().'?subject='.$event_name
1476 1476
                                           . esc_html__(
1477 1477
                                               ' Event',
1478 1478
                                               'event_espresso'
1479 1479
                                           )
1480
-                                          . '">' . $attendee->email() . '</a>';
1481
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1480
+                                          . '">'.$attendee->email().'</a>';
1481
+                                    $this->_template_args['event_attendees'][$registration->ID()]['address']
1482 1482
                                         = EEH_Address::format($attendee, 'inline', false, false);
1483 1483
                                 } else {
1484
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']   = '';
1485
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1486
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']    = '';
1487
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']  = '';
1484
+                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1485
+                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1486
+                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1487
+                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1488 1488
                                 }
1489 1489
                             }
1490 1490
                             break;
@@ -1500,7 +1500,7 @@  discard block
 block discarded – undo
1500 1500
                 TXN_ADMIN_URL
1501 1501
             );
1502 1502
             echo EEH_Template::display_template(
1503
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1503
+                TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php',
1504 1504
                 $this->_template_args,
1505 1505
                 true
1506 1506
             );
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
         $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1536 1536
             ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1537 1537
             : null;
1538
-        if (! $primary_att instanceof EE_Attendee) {
1538
+        if ( ! $primary_att instanceof EE_Attendee) {
1539 1539
             $this->_template_args['no_attendee_message'] = esc_html__(
1540 1540
                 'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1541 1541
                 'event_espresso'
@@ -1561,7 +1561,7 @@  discard block
 block discarded – undo
1561 1561
             : '';
1562 1562
         $this->_template_args['formatted_address'] = $formatted_address;
1563 1563
         echo EEH_Template::display_template(
1564
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1564
+            TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php',
1565 1565
             $this->_template_args,
1566 1566
             true
1567 1567
         );
@@ -1587,7 +1587,7 @@  discard block
 block discarded – undo
1587 1587
             TXN_ADMIN_URL
1588 1588
         );
1589 1589
 
1590
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1590
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php';
1591 1591
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1592 1592
     }
1593 1593
 
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
             'ee_edit_payments',
1614 1614
             'apply_payment_or_refund_from_registration_details'
1615 1615
         );
1616
-        if (! empty($valid_data) && $has_access) {
1616
+        if ( ! empty($valid_data) && $has_access) {
1617 1617
             $PAY_ID = $valid_data['PAY_ID'];
1618 1618
             // save  the new payment
1619 1619
             $payment = $this->_create_payment_from_request_data($valid_data);
@@ -1626,7 +1626,7 @@  discard block
 block discarded – undo
1626 1626
                 $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1627 1627
                 $this->_remove_existing_registration_payments($payment, $PAY_ID);
1628 1628
                 // apply payment to registrations (if applicable)
1629
-                if (! empty($REG_IDs)) {
1629
+                if ( ! empty($REG_IDs)) {
1630 1630
                     $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1631 1631
                     $this->_maybe_send_notifications();
1632 1632
                     // now process status changes for the same registrations
@@ -1672,7 +1672,7 @@  discard block
 block discarded – undo
1672 1672
                 __LINE__
1673 1673
             );
1674 1674
         }
1675
-        $notices              = EE_Error::get_notices(
1675
+        $notices = EE_Error::get_notices(
1676 1676
             false,
1677 1677
             false,
1678 1678
             false
@@ -1697,14 +1697,14 @@  discard block
 block discarded – undo
1697 1697
      */
1698 1698
     protected function _validate_payment_request_data()
1699 1699
     {
1700
-        if (! $this->request->requestParamIsSet('txn_admin_payment')) {
1700
+        if ( ! $this->request->requestParamIsSet('txn_admin_payment')) {
1701 1701
             return [];
1702 1702
         }
1703 1703
         $payment_form = $this->_generate_payment_form_section();
1704 1704
         try {
1705 1705
             if ($payment_form->was_submitted()) {
1706 1706
                 $payment_form->receive_form_submission();
1707
-                if (! $payment_form->is_valid()) {
1707
+                if ( ! $payment_form->is_valid()) {
1708 1708
                     $submission_error_messages = [];
1709 1709
                     foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1710 1710
                         if ($validation_error instanceof EE_Validation_Error) {
@@ -1886,7 +1886,7 @@  discard block
 block discarded – undo
1886 1886
             ['Y-m-d', 'g:i a']
1887 1887
         );
1888 1888
 
1889
-        if (! $payment->save()) {
1889
+        if ( ! $payment->save()) {
1890 1890
             EE_Error::add_error(
1891 1891
                 sprintf(
1892 1892
                     esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
@@ -2088,12 +2088,12 @@  discard block
 block discarded – undo
2088 2088
         // but add in some conditions regarding payment,
2089 2089
         // so that we don't apply payments to registrations that are free or have already been paid for
2090 2090
         // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2091
-        if (! $payment->is_a_refund()) {
2091
+        if ( ! $payment->is_a_refund()) {
2092 2092
             $registration_query_where_params['REG_final_price']  = ['!=', 0];
2093 2093
             $registration_query_where_params['REG_final_price*'] = ['!=', 'REG_paid', true];
2094 2094
         }
2095 2095
         $registrations = $transaction->registrations([$registration_query_where_params]);
2096
-        if (! empty($registrations)) {
2096
+        if ( ! empty($registrations)) {
2097 2097
             /** @type EE_Payment_Processor $payment_processor */
2098 2098
             $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2099 2099
             $payment_processor->process_registration_payments($transaction, $payment, $registrations);
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
             'pay_status'       => $payment->STS_ID(),
2176 2176
             'PAY_ID'           => $payment->ID(),
2177 2177
             'STS_ID'           => $payment->STS_ID(),
2178
-            'status'           => self::$_pay_status[ $payment->STS_ID() ],
2178
+            'status'           => self::$_pay_status[$payment->STS_ID()],
2179 2179
             'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2180 2180
             'method'           => strtoupper($payment->source()),
2181 2181
             'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
@@ -2294,11 +2294,11 @@  discard block
 block discarded – undo
2294 2294
     {
2295 2295
         $registration_payment_data = [];
2296 2296
         // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2297
-        if (! empty($REG_IDs)) {
2297
+        if ( ! empty($REG_IDs)) {
2298 2298
             $registrations = EEM_Registration::instance()->get_all([['REG_ID' => ['IN', $REG_IDs]]]);
2299 2299
             foreach ($registrations as $registration) {
2300 2300
                 if ($registration instanceof EE_Registration) {
2301
-                    $registration_payment_data[ $registration->ID() ] = [
2301
+                    $registration_payment_data[$registration->ID()] = [
2302 2302
                         'paid'  => $registration->pretty_paid(),
2303 2303
                         'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2304 2304
                     ];
@@ -2354,7 +2354,7 @@  discard block
 block discarded – undo
2354 2354
         $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2355 2355
         $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2356 2356
         $redirect_to = $this->request->getRequestParam('redirect_to');
2357
-        $query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2357
+        $query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID, ] : [];
2358 2358
         do_action(
2359 2359
             'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2360 2360
             $transaction
@@ -2392,8 +2392,8 @@  discard block
 block discarded – undo
2392 2392
         );
2393 2393
 
2394 2394
         // make sure our timestamps start and end right at the boundaries for each day
2395
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2396
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2395
+        $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
2396
+        $end_date   = date('Y-m-d', strtotime($end_date)).' 23:59:59';
2397 2397
 
2398 2398
 
2399 2399
         // convert to timestamps
@@ -2410,7 +2410,7 @@  discard block
 block discarded – undo
2410 2410
             date('Y-m-d H:i:s', $start_date),
2411 2411
             'Y-m-d H:i:s'
2412 2412
         );
2413
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2413
+        $end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2414 2414
             'TXN_timestamp',
2415 2415
             date('Y-m-d H:i:s', $end_date),
2416 2416
             'Y-m-d H:i:s'
@@ -2454,8 +2454,8 @@  discard block
 block discarded – undo
2454 2454
 
2455 2455
         $search_term = $this->request->getRequestParam('s');
2456 2456
         if ($search_term) {
2457
-            $search_term = '%' . $search_term . '%';
2458
-            $_where['OR']  = [
2457
+            $search_term = '%'.$search_term.'%';
2458
+            $_where['OR'] = [
2459 2459
                 'Registration.Event.EVT_name'         => ['LIKE', $search_term],
2460 2460
                 'Registration.Event.EVT_desc'         => ['LIKE', $search_term],
2461 2461
                 'Registration.Event.EVT_short_desc'   => ['LIKE', $search_term],
@@ -2482,9 +2482,9 @@  discard block
 block discarded – undo
2482 2482
 
2483 2483
         $status = $this->request->getRequestParam('status');
2484 2484
         // failed transactions
2485
-        $failed     = (! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2486
-        $abandoned  = (! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2487
-        $incomplete = (! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2485
+        $failed     = ( ! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2486
+        $abandoned  = ( ! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2487
+        $incomplete = ( ! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2488 2488
 
2489 2489
         if ($failed) {
2490 2490
             $_where['STS_ID'] = EEM_Transaction::failed_status_code;
@@ -2532,7 +2532,7 @@  discard block
 block discarded – undo
2532 2532
         $transaction     = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2533 2533
         $success         = $transaction->recalculateLineItems();
2534 2534
         $redirect_to = $this->request->getRequestParam('redirect_to');
2535
-        $query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2535
+        $query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID, ] : [];
2536 2536
         $this->_redirect_after_action(
2537 2537
             $success,
2538 2538
             esc_html__('Transaction taxes and totals', 'event_espresso'),
Please login to merge, or discard this patch.
admin_pages/transactions/EE_Admin_Transactions_List_Table.class.php 2 patches
Indentation   +657 added lines, -657 removed lines patch added patch discarded remove patch
@@ -14,122 +14,122 @@  discard block
 block discarded – undo
14 14
 class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table
15 15
 {
16 16
 
17
-    /**
18
-     * @var SessionLifespan $session_lifespan
19
-     */
20
-    private $session_lifespan;
21
-
22
-    private $_status;
23
-
24
-
25
-    /**
26
-     * @param Transactions_Admin_Page $admin_page
27
-     * @param SessionLifespan         $lifespan
28
-     */
29
-    public function __construct(Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
30
-    {
31
-        parent::__construct($admin_page);
32
-        $this->session_lifespan = $lifespan;
33
-        $this->_status = $this->_admin_page->get_transaction_status_array();
34
-    }
35
-
36
-
37
-    /**
38
-     *_setup_data
39
-     */
40
-    protected function _setup_data()
41
-    {
42
-        $this->_data = $this->_admin_page->get_transactions($this->_per_page);
43
-        $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
44
-        $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
45
-    }
46
-
47
-
48
-    /**
49
-     *_set_properties
50
-     */
51
-    protected function _set_properties()
52
-    {
53
-        $this->_wp_list_args = array(
54
-            'singular' => esc_html__('transaction', 'event_espresso'),
55
-            'plural'   => esc_html__('transactions', 'event_espresso'),
56
-            'ajax'     => true,
57
-            'screen'   => $this->_admin_page->get_current_screen()->id,
58
-        );
59
-        $ID_column_name = esc_html__('ID', 'event_espresso');
60
-        $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">';
61
-        $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso');
62
-        $ID_column_name .= '</span> ';
63
-        $this->_columns = array(
64
-            'id'        => $ID_column_name,
65
-            'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'),
66
-            'event_name'    => esc_html__('Event', 'event_espresso'),
67
-            'ATT_fname'     => esc_html__('Primary Registrant', 'event_espresso'),
68
-            'TXN_paid'      => esc_html__('Paid', 'event_espresso'),
69
-            'TXN_total'     => esc_html__('Total', 'event_espresso'),
70
-            'actions' => $this->actionsColumnHeader(),
71
-        );
72
-
73
-        $this->_sortable_columns = array(
74
-            'id'        => array('TXN_ID' => false),
75
-            'event_name'    => array('event_name' => false),
76
-            'ATT_fname'     => array('ATT_fname' => false),
77
-            'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
78
-        );
79
-
80
-        $this->_primary_column = 'TXN_ID';
81
-
82
-        $this->_hidden_columns = array();
83
-    }
84
-
85
-
86
-    /**
87
-     * This simply sets up the row class for the table rows.
88
-     * Allows for easier overriding of child methods for setting up sorting.
89
-     *
90
-     * @param EE_Transaction $transaction the current item
91
-     * @return string
92
-     * @throws EE_Error
93
-     * @throws ReflectionException
94
-     */
95
-    protected function _get_row_class($transaction)
96
-    {
97
-        $class = parent::_get_row_class($transaction);
98
-        // add status class
99
-        $class .= ' txn-status-' . $transaction->status_ID();
100
-        if ($this->_has_checkbox_column) {
101
-            $class .= ' has-checkbox-column';
102
-        }
103
-        return $class;
104
-    }
105
-
106
-
107
-    /**
108
-     * _get_table_filters
109
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
110
-     * get's shown in the table.
111
-     *
112
-     * @abstract
113
-     * @access protected
114
-     * @return array
115
-     */
116
-    protected function _get_table_filters()
117
-    {
118
-        $filters = array();
119
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
120
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
121
-            : date(
122
-                'm/d/Y',
123
-                strtotime('-10 year')
124
-            );
125
-        $end_date = isset($this->_req_data['txn-filter-end-date'])
126
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
127
-            : date(
128
-                'm/d/Y',
129
-                current_time('timestamp')
130
-            );
131
-        ob_start();
132
-        ?>
17
+	/**
18
+	 * @var SessionLifespan $session_lifespan
19
+	 */
20
+	private $session_lifespan;
21
+
22
+	private $_status;
23
+
24
+
25
+	/**
26
+	 * @param Transactions_Admin_Page $admin_page
27
+	 * @param SessionLifespan         $lifespan
28
+	 */
29
+	public function __construct(Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
30
+	{
31
+		parent::__construct($admin_page);
32
+		$this->session_lifespan = $lifespan;
33
+		$this->_status = $this->_admin_page->get_transaction_status_array();
34
+	}
35
+
36
+
37
+	/**
38
+	 *_setup_data
39
+	 */
40
+	protected function _setup_data()
41
+	{
42
+		$this->_data = $this->_admin_page->get_transactions($this->_per_page);
43
+		$status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
44
+		$this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
45
+	}
46
+
47
+
48
+	/**
49
+	 *_set_properties
50
+	 */
51
+	protected function _set_properties()
52
+	{
53
+		$this->_wp_list_args = array(
54
+			'singular' => esc_html__('transaction', 'event_espresso'),
55
+			'plural'   => esc_html__('transactions', 'event_espresso'),
56
+			'ajax'     => true,
57
+			'screen'   => $this->_admin_page->get_current_screen()->id,
58
+		);
59
+		$ID_column_name = esc_html__('ID', 'event_espresso');
60
+		$ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">';
61
+		$ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso');
62
+		$ID_column_name .= '</span> ';
63
+		$this->_columns = array(
64
+			'id'        => $ID_column_name,
65
+			'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'),
66
+			'event_name'    => esc_html__('Event', 'event_espresso'),
67
+			'ATT_fname'     => esc_html__('Primary Registrant', 'event_espresso'),
68
+			'TXN_paid'      => esc_html__('Paid', 'event_espresso'),
69
+			'TXN_total'     => esc_html__('Total', 'event_espresso'),
70
+			'actions' => $this->actionsColumnHeader(),
71
+		);
72
+
73
+		$this->_sortable_columns = array(
74
+			'id'        => array('TXN_ID' => false),
75
+			'event_name'    => array('event_name' => false),
76
+			'ATT_fname'     => array('ATT_fname' => false),
77
+			'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
78
+		);
79
+
80
+		$this->_primary_column = 'TXN_ID';
81
+
82
+		$this->_hidden_columns = array();
83
+	}
84
+
85
+
86
+	/**
87
+	 * This simply sets up the row class for the table rows.
88
+	 * Allows for easier overriding of child methods for setting up sorting.
89
+	 *
90
+	 * @param EE_Transaction $transaction the current item
91
+	 * @return string
92
+	 * @throws EE_Error
93
+	 * @throws ReflectionException
94
+	 */
95
+	protected function _get_row_class($transaction)
96
+	{
97
+		$class = parent::_get_row_class($transaction);
98
+		// add status class
99
+		$class .= ' txn-status-' . $transaction->status_ID();
100
+		if ($this->_has_checkbox_column) {
101
+			$class .= ' has-checkbox-column';
102
+		}
103
+		return $class;
104
+	}
105
+
106
+
107
+	/**
108
+	 * _get_table_filters
109
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
110
+	 * get's shown in the table.
111
+	 *
112
+	 * @abstract
113
+	 * @access protected
114
+	 * @return array
115
+	 */
116
+	protected function _get_table_filters()
117
+	{
118
+		$filters = array();
119
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
120
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
121
+			: date(
122
+				'm/d/Y',
123
+				strtotime('-10 year')
124
+			);
125
+		$end_date = isset($this->_req_data['txn-filter-end-date'])
126
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
127
+			: date(
128
+				'm/d/Y',
129
+				current_time('timestamp')
130
+			);
131
+		ob_start();
132
+		?>
133 133
         <label for="txn-filter-start-date">Display Transactions from </label>
134 134
         <input class="datepicker"
135 135
                id="txn-filter-start-date"
@@ -147,577 +147,577 @@  discard block
 block discarded – undo
147 147
                value="<?php echo esc_html($end_date); ?>"
148 148
         />
149 149
         <?php
150
-        $filters[] = ob_get_contents();
151
-        ob_end_clean();
152
-        return $filters;
153
-    }
154
-
155
-
156
-    /**
157
-     *_add_view_counts
158
-     */
159
-    protected function _add_view_counts()
160
-    {
161
-        foreach ($this->_views as $view) {
162
-            $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
163
-        }
164
-    }
165
-
166
-
167
-    /**
168
-     *    column TXN_ID
169
-     *
170
-     * @param EE_Transaction $transaction
171
-     * @return string
172
-     * @throws EE_Error
173
-     */
174
-    public function column_id(EE_Transaction $transaction)
175
-    {
176
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
177
-            array(
178
-                'action' => 'view_transaction',
179
-                'TXN_ID' => $transaction->ID(),
180
-            ),
181
-            TXN_ADMIN_URL
182
-        );
183
-        $content = '<a class="ee-aria-tooltip" href="' . $view_lnk_url . '"'
184
-                   . ' aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
185
-                   . $transaction->ID()
186
-                   . '</a>';
187
-
188
-        // txn timestamp
189
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
190
-        return $this->columnContent('id', $content, 'end');
191
-    }
192
-
193
-
194
-    /**
195
-     * @param EE_Transaction $transaction
196
-     * @return string
197
-     * @throws EE_Error
198
-     * @throws InvalidArgumentException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidInterfaceException
201
-     */
202
-    protected function _get_txn_timestamp(EE_Transaction $transaction)
203
-    {
204
-        // is TXN less than 2 hours old ?
205
-        if (
206
-            ($transaction->failed() || $transaction->is_abandoned())
207
-            && $this->session_lifespan->expiration() < $transaction->datetime(false, true)
208
-        ) {
209
-            $timestamp = esc_html__('TXN in progress...', 'event_espresso');
210
-        } else {
211
-            $timestamp = $transaction->get_i18n_datetime('TXN_timestamp', 'M jS Y g:i a');
212
-        }
213
-        return $timestamp;
214
-    }
215
-
216
-
217
-    /**
218
-     *    column_cb
219
-     *
220
-     * @param EE_Transaction $transaction
221
-     * @return string
222
-     * @throws EE_Error
223
-     */
224
-    public function column_cb($transaction)
225
-    {
226
-        return sprintf(
227
-            '<input type="checkbox" name="%1$s[]" value="%2$s" />',
228
-            $this->_wp_list_args['singular'],
229
-            $transaction->ID()
230
-        );
231
-    }
232
-
233
-
234
-    /**
235
-     *    column_TXN_timestamp
236
-     *
237
-     * @param EE_Transaction $transaction
238
-     * @return string
239
-     * @throws EE_Error
240
-     * @throws ReflectionException
241
-     */
242
-    public function column_TXN_timestamp(EE_Transaction $transaction)
243
-    {
244
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
245
-            array(
246
-                'action' => 'view_transaction',
247
-                'TXN_ID' => $transaction->ID(),
248
-            ),
249
-            TXN_ADMIN_URL
250
-        );
251
-        $status        = esc_attr($transaction->status_ID());
252
-        $pretty_status = EEH_Template::pretty_status($status, false, 'sentence' );
253
-        return '
150
+		$filters[] = ob_get_contents();
151
+		ob_end_clean();
152
+		return $filters;
153
+	}
154
+
155
+
156
+	/**
157
+	 *_add_view_counts
158
+	 */
159
+	protected function _add_view_counts()
160
+	{
161
+		foreach ($this->_views as $view) {
162
+			$this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
163
+		}
164
+	}
165
+
166
+
167
+	/**
168
+	 *    column TXN_ID
169
+	 *
170
+	 * @param EE_Transaction $transaction
171
+	 * @return string
172
+	 * @throws EE_Error
173
+	 */
174
+	public function column_id(EE_Transaction $transaction)
175
+	{
176
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
177
+			array(
178
+				'action' => 'view_transaction',
179
+				'TXN_ID' => $transaction->ID(),
180
+			),
181
+			TXN_ADMIN_URL
182
+		);
183
+		$content = '<a class="ee-aria-tooltip" href="' . $view_lnk_url . '"'
184
+				   . ' aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
185
+				   . $transaction->ID()
186
+				   . '</a>';
187
+
188
+		// txn timestamp
189
+		$content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
190
+		return $this->columnContent('id', $content, 'end');
191
+	}
192
+
193
+
194
+	/**
195
+	 * @param EE_Transaction $transaction
196
+	 * @return string
197
+	 * @throws EE_Error
198
+	 * @throws InvalidArgumentException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidInterfaceException
201
+	 */
202
+	protected function _get_txn_timestamp(EE_Transaction $transaction)
203
+	{
204
+		// is TXN less than 2 hours old ?
205
+		if (
206
+			($transaction->failed() || $transaction->is_abandoned())
207
+			&& $this->session_lifespan->expiration() < $transaction->datetime(false, true)
208
+		) {
209
+			$timestamp = esc_html__('TXN in progress...', 'event_espresso');
210
+		} else {
211
+			$timestamp = $transaction->get_i18n_datetime('TXN_timestamp', 'M jS Y g:i a');
212
+		}
213
+		return $timestamp;
214
+	}
215
+
216
+
217
+	/**
218
+	 *    column_cb
219
+	 *
220
+	 * @param EE_Transaction $transaction
221
+	 * @return string
222
+	 * @throws EE_Error
223
+	 */
224
+	public function column_cb($transaction)
225
+	{
226
+		return sprintf(
227
+			'<input type="checkbox" name="%1$s[]" value="%2$s" />',
228
+			$this->_wp_list_args['singular'],
229
+			$transaction->ID()
230
+		);
231
+	}
232
+
233
+
234
+	/**
235
+	 *    column_TXN_timestamp
236
+	 *
237
+	 * @param EE_Transaction $transaction
238
+	 * @return string
239
+	 * @throws EE_Error
240
+	 * @throws ReflectionException
241
+	 */
242
+	public function column_TXN_timestamp(EE_Transaction $transaction)
243
+	{
244
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
245
+			array(
246
+				'action' => 'view_transaction',
247
+				'TXN_ID' => $transaction->ID(),
248
+			),
249
+			TXN_ADMIN_URL
250
+		);
251
+		$status        = esc_attr($transaction->status_ID());
252
+		$pretty_status = EEH_Template::pretty_status($status, false, 'sentence' );
253
+		return '
254 254
             <div class="ee-layout-row">
255 255
                 <span aria-label="' . $pretty_status . '"  class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"></span>
256 256
                 <a  href="' . $view_lnk_url . '"                     
257 257
                     class="row-title ee-status-color--' . $status . ' ee-aria-tooltip"
258 258
                     aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID
259
-            () . '">
259
+			() . '">
260 260
                 ' . $this->_get_txn_timestamp($transaction) . '
261 261
                 </a>
262 262
             </div>';
263
-    }
264
-
265
-
266
-    /**
267
-     *    column_TXN_total
268
-     *
269
-     * @param EE_Transaction $transaction
270
-     * @return string
271
-     * @throws EE_Error
272
-     */
273
-    public function column_TXN_total(EE_Transaction $transaction)
274
-    {
275
-        if ($transaction->get('TXN_total') > 0) {
276
-            return '<span class="txn-pad-rght">'
277
-                   . apply_filters(
278
-                       'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
279
-                       $transaction->get_pretty('TXN_total'),
280
-                       $transaction
281
-                   )
282
-                   . '</span>';
283
-        } else {
284
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
285
-        }
286
-    }
287
-
288
-
289
-    /**
290
-     *    column_TXN_paid
291
-     *
292
-     * @param EE_Transaction $transaction
293
-     * @return mixed|string
294
-     * @throws EE_Error
295
-     */
296
-    public function column_TXN_paid(EE_Transaction $transaction)
297
-    {
298
-        $transaction_total = $transaction->get('TXN_total');
299
-        $transaction_paid = $transaction->get('TXN_paid');
300
-
301
-        if (EEH_Money::compare_floats($transaction_total, 0, '>')) {
302
-            // monies owing
303
-            $span_class = 'txn-overview-part-payment-spn';
304
-            if (EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
305
-                // paid in full
306
-                $span_class = 'txn-overview-full-payment-spn';
307
-            } elseif (EEH_Money::compare_floats($transaction_paid, 0, '==')) {
308
-                // no payments made
309
-                $span_class = 'txn-overview-no-payment-spn';
310
-            }
311
-        } else {
312
-            // transaction_total == 0 so this is a free event
313
-            $span_class = 'txn-overview-free-event-spn';
314
-        }
315
-
316
-        $payment_method = $transaction->payment_method();
317
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
318
-            ? $payment_method->admin_name()
319
-            : esc_html__('Unknown', 'event_espresso');
320
-
321
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
322
-                   . $transaction->get_pretty('TXN_paid')
323
-                   . '</span>';
324
-        if ($transaction_paid > 0) {
325
-            $content .= ' <span class="ee-status-text-small">'
326
-                        . sprintf(
327
-                            esc_html__('...via %s', 'event_espresso'),
328
-                            $payment_method_name
329
-                        )
330
-                        . '</span>';
331
-        }
332
-        return "<div>{$content}</div>";
333
-    }
334
-
335
-
336
-    /**
337
-     *    column_ATT_fname
338
-     *
339
-     * @param EE_Transaction $transaction
340
-     * @return string
341
-     * @throws EE_Error
342
-     * @throws InvalidArgumentException
343
-     * @throws InvalidDataTypeException
344
-     * @throws InvalidInterfaceException
345
-     */
346
-    public function column_ATT_fname(EE_Transaction $transaction)
347
-    {
348
-        $primary_reg = $transaction->primary_registration();
349
-        $attendee = $primary_reg->get_first_related('Attendee');
350
-        if ($attendee instanceof EE_Attendee) {
351
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
352
-                array(
353
-                    'action'  => 'view_registration',
354
-                    '_REG_ID' => $primary_reg->ID(),
355
-                ),
356
-                REG_ADMIN_URL
357
-            );
358
-            $content = EE_Registry::instance()->CAP->current_user_can(
359
-                'ee_read_registration',
360
-                'espresso_registrations_view_registration',
361
-                $primary_reg->ID()
362
-            )
363
-                ? '<a href="' . $edit_lnk_url . '"'
364
-                  . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
365
-                  . $attendee->full_name()
366
-                  . '</a>'
367
-                : $attendee->full_name();
368
-            $content .= '<br>' . $attendee->email();
369
-            return $content;
370
-        }
371
-        return $transaction->failed() || $transaction->is_abandoned()
372
-            ? esc_html__('no contact record.', 'event_espresso')
373
-            : esc_html__(
374
-                'No contact record, because the transaction was abandoned or the registration process failed.',
375
-                'event_espresso'
376
-            );
377
-    }
378
-
379
-
380
-    /**
381
-     *    column_ATT_email
382
-     *
383
-     * @param EE_Transaction $transaction
384
-     * @return string
385
-     * @throws EE_Error
386
-     */
387
-    public function column_ATT_email(EE_Transaction $transaction)
388
-    {
389
-        $attendee = $transaction->primary_registration()->get_first_related('Attendee');
390
-        if (! empty($attendee)) {
391
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
392
-                   . $attendee->get('ATT_email')
393
-                   . '</a>';
394
-        } else {
395
-            return $transaction->failed() || $transaction->is_abandoned()
396
-                ? esc_html__('no contact record.', 'event_espresso')
397
-                : esc_html__(
398
-                    'No contact record, because the transaction was abandoned or the registration process failed.',
399
-                    'event_espresso'
400
-                );
401
-        }
402
-    }
403
-
404
-
405
-    /**
406
-     *    column_event_name
407
-     *
408
-     * @param EE_Transaction $transaction
409
-     * @return string
410
-     * @throws EE_Error
411
-     * @throws InvalidArgumentException
412
-     * @throws InvalidDataTypeException
413
-     * @throws InvalidInterfaceException
414
-     */
415
-    public function column_event_name(EE_Transaction $transaction)
416
-    {
417
-        $actions = array();
418
-        $event = $transaction->primary_registration()->get_first_related('Event');
419
-        if (! empty($event)) {
420
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
421
-                array('action' => 'edit', 'post' => $event->ID()),
422
-                EVENTS_ADMIN_URL
423
-            );
424
-            $event_name = $event->get('EVT_name');
425
-
426
-            // filter this view by transactions for this event
427
-            $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
428
-                array(
429
-                    'action' => 'default',
430
-                    'EVT_ID' => $event->ID(),
431
-                ),
432
-                TXN_ADMIN_URL
433
-            );
434
-            if (
435
-                empty($this->_req_data['EVT_ID'])
436
-                && EE_Registry::instance()->CAP->current_user_can(
437
-                    'ee_edit_event',
438
-                    'espresso_events_edit',
439
-                    $event->ID()
440
-                )
441
-            ) {
442
-                $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"'
443
-                                              . ' aria-label="' . esc_attr__(
444
-                                                  'Filter transactions by this event',
445
-                                                  'event_espresso'
446
-                                              ) . '">'
447
-                                              . esc_html__('View Transactions for this event', 'event_espresso')
448
-                                              . '</a>';
449
-            }
450
-
451
-            return sprintf(
452
-                '%1$s %2$s',
453
-                EE_Registry::instance()->CAP->current_user_can(
454
-                    'ee_edit_event',
455
-                    'espresso_events_edit',
456
-                    $event->ID()
457
-                )
458
-                    ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"'
459
-                      . ' aria-label="'
460
-                      . sprintf(
461
-                          esc_attr__('Edit Event: %s', 'event_espresso'),
462
-                          $event->get('EVT_name')
463
-                      )
464
-                      . '">'
465
-                      . wp_trim_words(
466
-                          $event_name,
467
-                          30,
468
-                          '...'
469
-                      )
470
-                      . '</a>'
471
-                    : wp_trim_words($event_name, 30, '...'),
472
-                $this->row_actions($actions)
473
-            );
474
-        } else {
475
-            return esc_html__(
476
-                'The event associated with this transaction via the primary registration cannot be retrieved.',
477
-                'event_espresso'
478
-            );
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     *    column_actions
485
-     *
486
-     * @param EE_Transaction $transaction
487
-     * @return string
488
-     * @throws EE_Error
489
-     */
490
-    public function column_actions(EE_Transaction $transaction)
491
-    {
492
-        return $this->actionsModalMenu(
493
-            $this->_action_string(
494
-                $this->get_transaction_details_link($transaction)
495
-                . $this->get_invoice_link($transaction)
496
-                . $this->get_receipt_link($transaction)
497
-                . $this->get_primary_registration_details_link($transaction)
498
-                . $this->get_send_payment_reminder_trigger_link($transaction)
499
-                . $this->get_payment_overview_link($transaction)
500
-                . $this->get_related_messages_link($transaction),
501
-                $transaction,
502
-                'div',
503
-                'txn-overview-actions ee-list-table-actions'
504
-            )
505
-        );
506
-    }
507
-
508
-
509
-    /**
510
-     * Get the transaction details link.
511
-     *
512
-     * @param EE_Transaction $transaction
513
-     * @return string
514
-     * @throws EE_Error
515
-     */
516
-    protected function get_transaction_details_link(EE_Transaction $transaction)
517
-    {
518
-        $url = EE_Admin_Page::add_query_args_and_nonce(
519
-            array(
520
-                'action' => 'view_transaction',
521
-                'TXN_ID' => $transaction->ID(),
522
-            ),
523
-            TXN_ADMIN_URL
524
-        );
525
-        return '
263
+	}
264
+
265
+
266
+	/**
267
+	 *    column_TXN_total
268
+	 *
269
+	 * @param EE_Transaction $transaction
270
+	 * @return string
271
+	 * @throws EE_Error
272
+	 */
273
+	public function column_TXN_total(EE_Transaction $transaction)
274
+	{
275
+		if ($transaction->get('TXN_total') > 0) {
276
+			return '<span class="txn-pad-rght">'
277
+				   . apply_filters(
278
+					   'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
279
+					   $transaction->get_pretty('TXN_total'),
280
+					   $transaction
281
+				   )
282
+				   . '</span>';
283
+		} else {
284
+			return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
285
+		}
286
+	}
287
+
288
+
289
+	/**
290
+	 *    column_TXN_paid
291
+	 *
292
+	 * @param EE_Transaction $transaction
293
+	 * @return mixed|string
294
+	 * @throws EE_Error
295
+	 */
296
+	public function column_TXN_paid(EE_Transaction $transaction)
297
+	{
298
+		$transaction_total = $transaction->get('TXN_total');
299
+		$transaction_paid = $transaction->get('TXN_paid');
300
+
301
+		if (EEH_Money::compare_floats($transaction_total, 0, '>')) {
302
+			// monies owing
303
+			$span_class = 'txn-overview-part-payment-spn';
304
+			if (EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
305
+				// paid in full
306
+				$span_class = 'txn-overview-full-payment-spn';
307
+			} elseif (EEH_Money::compare_floats($transaction_paid, 0, '==')) {
308
+				// no payments made
309
+				$span_class = 'txn-overview-no-payment-spn';
310
+			}
311
+		} else {
312
+			// transaction_total == 0 so this is a free event
313
+			$span_class = 'txn-overview-free-event-spn';
314
+		}
315
+
316
+		$payment_method = $transaction->payment_method();
317
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
318
+			? $payment_method->admin_name()
319
+			: esc_html__('Unknown', 'event_espresso');
320
+
321
+		$content = '<span class="' . $span_class . ' txn-pad-rght">'
322
+				   . $transaction->get_pretty('TXN_paid')
323
+				   . '</span>';
324
+		if ($transaction_paid > 0) {
325
+			$content .= ' <span class="ee-status-text-small">'
326
+						. sprintf(
327
+							esc_html__('...via %s', 'event_espresso'),
328
+							$payment_method_name
329
+						)
330
+						. '</span>';
331
+		}
332
+		return "<div>{$content}</div>";
333
+	}
334
+
335
+
336
+	/**
337
+	 *    column_ATT_fname
338
+	 *
339
+	 * @param EE_Transaction $transaction
340
+	 * @return string
341
+	 * @throws EE_Error
342
+	 * @throws InvalidArgumentException
343
+	 * @throws InvalidDataTypeException
344
+	 * @throws InvalidInterfaceException
345
+	 */
346
+	public function column_ATT_fname(EE_Transaction $transaction)
347
+	{
348
+		$primary_reg = $transaction->primary_registration();
349
+		$attendee = $primary_reg->get_first_related('Attendee');
350
+		if ($attendee instanceof EE_Attendee) {
351
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
352
+				array(
353
+					'action'  => 'view_registration',
354
+					'_REG_ID' => $primary_reg->ID(),
355
+				),
356
+				REG_ADMIN_URL
357
+			);
358
+			$content = EE_Registry::instance()->CAP->current_user_can(
359
+				'ee_read_registration',
360
+				'espresso_registrations_view_registration',
361
+				$primary_reg->ID()
362
+			)
363
+				? '<a href="' . $edit_lnk_url . '"'
364
+				  . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
365
+				  . $attendee->full_name()
366
+				  . '</a>'
367
+				: $attendee->full_name();
368
+			$content .= '<br>' . $attendee->email();
369
+			return $content;
370
+		}
371
+		return $transaction->failed() || $transaction->is_abandoned()
372
+			? esc_html__('no contact record.', 'event_espresso')
373
+			: esc_html__(
374
+				'No contact record, because the transaction was abandoned or the registration process failed.',
375
+				'event_espresso'
376
+			);
377
+	}
378
+
379
+
380
+	/**
381
+	 *    column_ATT_email
382
+	 *
383
+	 * @param EE_Transaction $transaction
384
+	 * @return string
385
+	 * @throws EE_Error
386
+	 */
387
+	public function column_ATT_email(EE_Transaction $transaction)
388
+	{
389
+		$attendee = $transaction->primary_registration()->get_first_related('Attendee');
390
+		if (! empty($attendee)) {
391
+			return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
392
+				   . $attendee->get('ATT_email')
393
+				   . '</a>';
394
+		} else {
395
+			return $transaction->failed() || $transaction->is_abandoned()
396
+				? esc_html__('no contact record.', 'event_espresso')
397
+				: esc_html__(
398
+					'No contact record, because the transaction was abandoned or the registration process failed.',
399
+					'event_espresso'
400
+				);
401
+		}
402
+	}
403
+
404
+
405
+	/**
406
+	 *    column_event_name
407
+	 *
408
+	 * @param EE_Transaction $transaction
409
+	 * @return string
410
+	 * @throws EE_Error
411
+	 * @throws InvalidArgumentException
412
+	 * @throws InvalidDataTypeException
413
+	 * @throws InvalidInterfaceException
414
+	 */
415
+	public function column_event_name(EE_Transaction $transaction)
416
+	{
417
+		$actions = array();
418
+		$event = $transaction->primary_registration()->get_first_related('Event');
419
+		if (! empty($event)) {
420
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
421
+				array('action' => 'edit', 'post' => $event->ID()),
422
+				EVENTS_ADMIN_URL
423
+			);
424
+			$event_name = $event->get('EVT_name');
425
+
426
+			// filter this view by transactions for this event
427
+			$txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
428
+				array(
429
+					'action' => 'default',
430
+					'EVT_ID' => $event->ID(),
431
+				),
432
+				TXN_ADMIN_URL
433
+			);
434
+			if (
435
+				empty($this->_req_data['EVT_ID'])
436
+				&& EE_Registry::instance()->CAP->current_user_can(
437
+					'ee_edit_event',
438
+					'espresso_events_edit',
439
+					$event->ID()
440
+				)
441
+			) {
442
+				$actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"'
443
+											  . ' aria-label="' . esc_attr__(
444
+												  'Filter transactions by this event',
445
+												  'event_espresso'
446
+											  ) . '">'
447
+											  . esc_html__('View Transactions for this event', 'event_espresso')
448
+											  . '</a>';
449
+			}
450
+
451
+			return sprintf(
452
+				'%1$s %2$s',
453
+				EE_Registry::instance()->CAP->current_user_can(
454
+					'ee_edit_event',
455
+					'espresso_events_edit',
456
+					$event->ID()
457
+				)
458
+					? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"'
459
+					  . ' aria-label="'
460
+					  . sprintf(
461
+						  esc_attr__('Edit Event: %s', 'event_espresso'),
462
+						  $event->get('EVT_name')
463
+					  )
464
+					  . '">'
465
+					  . wp_trim_words(
466
+						  $event_name,
467
+						  30,
468
+						  '...'
469
+					  )
470
+					  . '</a>'
471
+					: wp_trim_words($event_name, 30, '...'),
472
+				$this->row_actions($actions)
473
+			);
474
+		} else {
475
+			return esc_html__(
476
+				'The event associated with this transaction via the primary registration cannot be retrieved.',
477
+				'event_espresso'
478
+			);
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 *    column_actions
485
+	 *
486
+	 * @param EE_Transaction $transaction
487
+	 * @return string
488
+	 * @throws EE_Error
489
+	 */
490
+	public function column_actions(EE_Transaction $transaction)
491
+	{
492
+		return $this->actionsModalMenu(
493
+			$this->_action_string(
494
+				$this->get_transaction_details_link($transaction)
495
+				. $this->get_invoice_link($transaction)
496
+				. $this->get_receipt_link($transaction)
497
+				. $this->get_primary_registration_details_link($transaction)
498
+				. $this->get_send_payment_reminder_trigger_link($transaction)
499
+				. $this->get_payment_overview_link($transaction)
500
+				. $this->get_related_messages_link($transaction),
501
+				$transaction,
502
+				'div',
503
+				'txn-overview-actions ee-list-table-actions'
504
+			)
505
+		);
506
+	}
507
+
508
+
509
+	/**
510
+	 * Get the transaction details link.
511
+	 *
512
+	 * @param EE_Transaction $transaction
513
+	 * @return string
514
+	 * @throws EE_Error
515
+	 */
516
+	protected function get_transaction_details_link(EE_Transaction $transaction)
517
+	{
518
+		$url = EE_Admin_Page::add_query_args_and_nonce(
519
+			array(
520
+				'action' => 'view_transaction',
521
+				'TXN_ID' => $transaction->ID(),
522
+			),
523
+			TXN_ADMIN_URL
524
+		);
525
+		return '
526 526
 				<a class="ee-aria-tooltip button button--icon-only" href="' . $url . '"'
527
-               . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only">
527
+			   . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only">
528 528
 					<span class="dashicons dashicons-cart"></span>
529 529
 				</a>';
530
-    }
531
-
532
-
533
-    /**
534
-     * Get the invoice link for the given registration.
535
-     *
536
-     * @param EE_Transaction $transaction
537
-     * @return string
538
-     * @throws EE_Error
539
-     */
540
-    protected function get_invoice_link(EE_Transaction $transaction)
541
-    {
542
-        $registration = $transaction->primary_registration();
543
-        if ($registration instanceof EE_Registration) {
544
-            $url = $registration->invoice_url();
545
-            // only show invoice link if message type is active.
546
-            if (
547
-                $registration->attendee() instanceof EE_Attendee
548
-                && EEH_MSG_Template::is_mt_active('invoice')
549
-            ) {
550
-                return '
530
+	}
531
+
532
+
533
+	/**
534
+	 * Get the invoice link for the given registration.
535
+	 *
536
+	 * @param EE_Transaction $transaction
537
+	 * @return string
538
+	 * @throws EE_Error
539
+	 */
540
+	protected function get_invoice_link(EE_Transaction $transaction)
541
+	{
542
+		$registration = $transaction->primary_registration();
543
+		if ($registration instanceof EE_Registration) {
544
+			$url = $registration->invoice_url();
545
+			// only show invoice link if message type is active.
546
+			if (
547
+				$registration->attendee() instanceof EE_Attendee
548
+				&& EEH_MSG_Template::is_mt_active('invoice')
549
+			) {
550
+				return '
551 551
                     <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
552
-                       . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
552
+					   . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
553 553
                         <span class="dashicons dashicons-media-spreadsheet"></span>
554 554
                     </a>';
555
-            }
556
-        }
557
-        return '';
558
-    }
559
-
560
-
561
-    /**
562
-     * Get the receipt link for the transaction.
563
-     *
564
-     * @param EE_Transaction $transaction
565
-     * @return string
566
-     * @throws EE_Error
567
-     */
568
-    protected function get_receipt_link(EE_Transaction $transaction)
569
-    {
570
-        $registration = $transaction->primary_registration();
571
-        if ($registration instanceof EE_Registration) {
572
-            $url = $registration->receipt_url();
573
-            // only show receipt link if message type is active.
574
-            if (
575
-                $registration->attendee() instanceof EE_Attendee
576
-                && EEH_MSG_Template::is_mt_active('receipt')
577
-            ) {
578
-                return '
555
+			}
556
+		}
557
+		return '';
558
+	}
559
+
560
+
561
+	/**
562
+	 * Get the receipt link for the transaction.
563
+	 *
564
+	 * @param EE_Transaction $transaction
565
+	 * @return string
566
+	 * @throws EE_Error
567
+	 */
568
+	protected function get_receipt_link(EE_Transaction $transaction)
569
+	{
570
+		$registration = $transaction->primary_registration();
571
+		if ($registration instanceof EE_Registration) {
572
+			$url = $registration->receipt_url();
573
+			// only show receipt link if message type is active.
574
+			if (
575
+				$registration->attendee() instanceof EE_Attendee
576
+				&& EEH_MSG_Template::is_mt_active('receipt')
577
+			) {
578
+				return '
579 579
 				<a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
580
-                       . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
580
+					   . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
581 581
 					<span class="dashicons dashicons-text-page"></span>
582 582
 				</a>';
583
-            }
584
-        }
585
-        return '';
586
-    }
587
-
588
-
589
-    /**
590
-     * Get the link to view the details for the primary registration.
591
-     *
592
-     * @param EE_Transaction $transaction
593
-     * @return string
594
-     * @throws EE_Error
595
-     * @throws InvalidArgumentException
596
-     * @throws InvalidDataTypeException
597
-     * @throws InvalidInterfaceException
598
-     */
599
-    protected function get_primary_registration_details_link(EE_Transaction $transaction)
600
-    {
601
-        $registration = $transaction->primary_registration();
602
-        if ($registration instanceof EE_Registration) {
603
-            $url = EE_Admin_Page::add_query_args_and_nonce(
604
-                array(
605
-                    'action'  => 'view_registration',
606
-                    '_REG_ID' => $registration->ID(),
607
-                ),
608
-                REG_ADMIN_URL
609
-            );
610
-            return EE_Registry::instance()->CAP->current_user_can(
611
-                'ee_read_registration',
612
-                'espresso_registrations_view_registration',
613
-                $registration->ID()
614
-            )
615
-                ? '
583
+			}
584
+		}
585
+		return '';
586
+	}
587
+
588
+
589
+	/**
590
+	 * Get the link to view the details for the primary registration.
591
+	 *
592
+	 * @param EE_Transaction $transaction
593
+	 * @return string
594
+	 * @throws EE_Error
595
+	 * @throws InvalidArgumentException
596
+	 * @throws InvalidDataTypeException
597
+	 * @throws InvalidInterfaceException
598
+	 */
599
+	protected function get_primary_registration_details_link(EE_Transaction $transaction)
600
+	{
601
+		$registration = $transaction->primary_registration();
602
+		if ($registration instanceof EE_Registration) {
603
+			$url = EE_Admin_Page::add_query_args_and_nonce(
604
+				array(
605
+					'action'  => 'view_registration',
606
+					'_REG_ID' => $registration->ID(),
607
+				),
608
+				REG_ADMIN_URL
609
+			);
610
+			return EE_Registry::instance()->CAP->current_user_can(
611
+				'ee_read_registration',
612
+				'espresso_registrations_view_registration',
613
+				$registration->ID()
614
+			)
615
+				? '
616 616
 					<a href="' . $url . '"
617 617
 					    aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '" 
618 618
 					    class="ee-aria-tooltip button button--icon-only"
619 619
                     >
620 620
 						<span class="dashicons dashicons-clipboard"></span>
621 621
 					</a>'
622
-                : '';
623
-        }
624
-        return '';
625
-    }
626
-
627
-
628
-    /**
629
-     * Get send payment reminder trigger link
630
-     *
631
-     * @param EE_Transaction $transaction
632
-     * @return string
633
-     * @throws EE_Error
634
-     * @throws InvalidArgumentException
635
-     * @throws InvalidDataTypeException
636
-     * @throws InvalidInterfaceException
637
-     */
638
-    protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
639
-    {
640
-        $registration = $transaction->primary_registration();
641
-        if (
642
-            $registration instanceof EE_Registration
643
-            && $registration->attendee() instanceof EE_Attendee
644
-            && EEH_MSG_Template::is_mt_active('payment_reminder')
645
-            && ! in_array(
646
-                $transaction->status_ID(),
647
-                array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
648
-                true
649
-            )
650
-            && EE_Registry::instance()->CAP->current_user_can(
651
-                'ee_send_message',
652
-                'espresso_transactions_send_payment_reminder'
653
-            )
654
-        ) {
655
-            $url = EE_Admin_Page::add_query_args_and_nonce(
656
-                array(
657
-                    'action' => 'send_payment_reminder',
658
-                    'TXN_ID' => $transaction->ID(),
659
-                ),
660
-                TXN_ADMIN_URL
661
-            );
662
-            return '
622
+				: '';
623
+		}
624
+		return '';
625
+	}
626
+
627
+
628
+	/**
629
+	 * Get send payment reminder trigger link
630
+	 *
631
+	 * @param EE_Transaction $transaction
632
+	 * @return string
633
+	 * @throws EE_Error
634
+	 * @throws InvalidArgumentException
635
+	 * @throws InvalidDataTypeException
636
+	 * @throws InvalidInterfaceException
637
+	 */
638
+	protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
639
+	{
640
+		$registration = $transaction->primary_registration();
641
+		if (
642
+			$registration instanceof EE_Registration
643
+			&& $registration->attendee() instanceof EE_Attendee
644
+			&& EEH_MSG_Template::is_mt_active('payment_reminder')
645
+			&& ! in_array(
646
+				$transaction->status_ID(),
647
+				array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
648
+				true
649
+			)
650
+			&& EE_Registry::instance()->CAP->current_user_can(
651
+				'ee_send_message',
652
+				'espresso_transactions_send_payment_reminder'
653
+			)
654
+		) {
655
+			$url = EE_Admin_Page::add_query_args_and_nonce(
656
+				array(
657
+					'action' => 'send_payment_reminder',
658
+					'TXN_ID' => $transaction->ID(),
659
+				),
660
+				TXN_ADMIN_URL
661
+			);
662
+			return '
663 663
                 <a href="' . $url . '" 
664 664
                     aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" 
665 665
                     class="ee-aria-tooltip button button--icon-only"
666 666
                 >
667 667
                     <span class="dashicons dashicons-email-alt"></span>
668 668
                 </a>';
669
-        }
670
-        return '';
671
-    }
672
-
673
-
674
-    /**
675
-     * Get link to filtered view in the message activity list table of messages for this transaction.
676
-     *
677
-     * @param EE_Transaction $transaction
678
-     * @return string
679
-     * @throws EE_Error
680
-     * @throws InvalidArgumentException
681
-     * @throws InvalidDataTypeException
682
-     * @throws InvalidInterfaceException
683
-     */
684
-    protected function get_related_messages_link(EE_Transaction $transaction)
685
-    {
686
-        return EE_Registry::instance()->CAP->current_user_can(
687
-            'ee_read_global_messages',
688
-            'view_filtered_messages'
689
-        )
690
-            ? EEH_MSG_Template::get_message_action_link(
691
-                'see_notifications_for',
692
-                null,
693
-                array('TXN_ID' => $transaction->ID())
694
-            )
695
-            : '';
696
-    }
697
-
698
-
699
-    /**
700
-     * Return the link to make a payment on the frontend
701
-     *
702
-     * @param EE_Transaction $transaction
703
-     * @return string
704
-     * @throws EE_Error
705
-     */
706
-    protected function get_payment_overview_link(EE_Transaction $transaction)
707
-    {
708
-        $registration = $transaction->primary_registration();
709
-        if (
710
-            $registration instanceof EE_Registration
711
-            && $transaction->status_ID() !== EEM_Transaction::complete_status_code
712
-            && $registration->owes_monies_and_can_pay()
713
-        ) {
714
-            return '
669
+		}
670
+		return '';
671
+	}
672
+
673
+
674
+	/**
675
+	 * Get link to filtered view in the message activity list table of messages for this transaction.
676
+	 *
677
+	 * @param EE_Transaction $transaction
678
+	 * @return string
679
+	 * @throws EE_Error
680
+	 * @throws InvalidArgumentException
681
+	 * @throws InvalidDataTypeException
682
+	 * @throws InvalidInterfaceException
683
+	 */
684
+	protected function get_related_messages_link(EE_Transaction $transaction)
685
+	{
686
+		return EE_Registry::instance()->CAP->current_user_can(
687
+			'ee_read_global_messages',
688
+			'view_filtered_messages'
689
+		)
690
+			? EEH_MSG_Template::get_message_action_link(
691
+				'see_notifications_for',
692
+				null,
693
+				array('TXN_ID' => $transaction->ID())
694
+			)
695
+			: '';
696
+	}
697
+
698
+
699
+	/**
700
+	 * Return the link to make a payment on the frontend
701
+	 *
702
+	 * @param EE_Transaction $transaction
703
+	 * @return string
704
+	 * @throws EE_Error
705
+	 */
706
+	protected function get_payment_overview_link(EE_Transaction $transaction)
707
+	{
708
+		$registration = $transaction->primary_registration();
709
+		if (
710
+			$registration instanceof EE_Registration
711
+			&& $transaction->status_ID() !== EEM_Transaction::complete_status_code
712
+			&& $registration->owes_monies_and_can_pay()
713
+		) {
714
+			return '
715 715
                 <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
716
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
717
-                   . ' class="ee-aria-tooltip button button--icon-only">
716
+				   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
717
+				   . ' class="ee-aria-tooltip button button--icon-only">
718 718
                     <span class="dashicons dashicons-money"></span>
719 719
                 </a>';
720
-        }
721
-        return '';
722
-    }
720
+		}
721
+		return '';
722
+	}
723 723
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -37 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         );
59 59
         $ID_column_name = esc_html__('ID', 'event_espresso');
60 60
         $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">';
61
-        $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso');
61
+        $ID_column_name .= ' : '.esc_html__('Transaction Date', 'event_espresso');
62 62
         $ID_column_name .= '</span> ';
63 63
         $this->_columns = array(
64 64
             'id'        => $ID_column_name,
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     {
97 97
         $class = parent::_get_row_class($transaction);
98 98
         // add status class
99
-        $class .= ' txn-status-' . $transaction->status_ID();
99
+        $class .= ' txn-status-'.$transaction->status_ID();
100 100
         if ($this->_has_checkbox_column) {
101 101
             $class .= ' has-checkbox-column';
102 102
         }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
     protected function _add_view_counts()
160 160
     {
161 161
         foreach ($this->_views as $view) {
162
-            $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
162
+            $this->_views[$view['slug']]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
163 163
         }
164 164
     }
165 165
 
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
             ),
181 181
             TXN_ADMIN_URL
182 182
         );
183
-        $content = '<a class="ee-aria-tooltip" href="' . $view_lnk_url . '"'
184
-                   . ' aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
183
+        $content = '<a class="ee-aria-tooltip" href="'.$view_lnk_url.'"'
184
+                   . ' aria-label="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">'
185 185
                    . $transaction->ID()
186 186
                    . '</a>';
187 187
 
188 188
         // txn timestamp
189
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
189
+        $content .= '  <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>';
190 190
         return $this->columnContent('id', $content, 'end');
191 191
     }
192 192
 
@@ -249,15 +249,14 @@  discard block
 block discarded – undo
249 249
             TXN_ADMIN_URL
250 250
         );
251 251
         $status        = esc_attr($transaction->status_ID());
252
-        $pretty_status = EEH_Template::pretty_status($status, false, 'sentence' );
252
+        $pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
253 253
         return '
254 254
             <div class="ee-layout-row">
255
-                <span aria-label="' . $pretty_status . '"  class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"></span>
256
-                <a  href="' . $view_lnk_url . '"                     
257
-                    class="row-title ee-status-color--' . $status . ' ee-aria-tooltip"
258
-                    aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID
259
-            () . '">
260
-                ' . $this->_get_txn_timestamp($transaction) . '
255
+                <span aria-label="' . $pretty_status.'"  class="ee-status-dot ee-status-bg--'.$status.' ee-aria-tooltip"></span>
256
+                <a  href="' . $view_lnk_url.'"                     
257
+                    class="row-title ee-status-color--' . $status.' ee-aria-tooltip"
258
+                    aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'">
259
+                ' . $this->_get_txn_timestamp($transaction).'
261 260
                 </a>
262 261
             </div>';
263 262
     }
@@ -281,7 +280,7 @@  discard block
 block discarded – undo
281 280
                    )
282 281
                    . '</span>';
283 282
         } else {
284
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
283
+            return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>';
285 284
         }
286 285
     }
287 286
 
@@ -318,7 +317,7 @@  discard block
 block discarded – undo
318 317
             ? $payment_method->admin_name()
319 318
             : esc_html__('Unknown', 'event_espresso');
320 319
 
321
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
320
+        $content = '<span class="'.$span_class.' txn-pad-rght">'
322 321
                    . $transaction->get_pretty('TXN_paid')
323 322
                    . '</span>';
324 323
         if ($transaction_paid > 0) {
@@ -360,12 +359,12 @@  discard block
 block discarded – undo
360 359
                 'espresso_registrations_view_registration',
361 360
                 $primary_reg->ID()
362 361
             )
363
-                ? '<a href="' . $edit_lnk_url . '"'
364
-                  . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
362
+                ? '<a href="'.$edit_lnk_url.'"'
363
+                  . ' aria-label="'.esc_attr__('View Registration Details', 'event_espresso').'">'
365 364
                   . $attendee->full_name()
366 365
                   . '</a>'
367 366
                 : $attendee->full_name();
368
-            $content .= '<br>' . $attendee->email();
367
+            $content .= '<br>'.$attendee->email();
369 368
             return $content;
370 369
         }
371 370
         return $transaction->failed() || $transaction->is_abandoned()
@@ -387,8 +386,8 @@  discard block
 block discarded – undo
387 386
     public function column_ATT_email(EE_Transaction $transaction)
388 387
     {
389 388
         $attendee = $transaction->primary_registration()->get_first_related('Attendee');
390
-        if (! empty($attendee)) {
391
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
389
+        if ( ! empty($attendee)) {
390
+            return '<a href="mailto:'.$attendee->get('ATT_email').'">'
392 391
                    . $attendee->get('ATT_email')
393 392
                    . '</a>';
394 393
         } else {
@@ -416,7 +415,7 @@  discard block
 block discarded – undo
416 415
     {
417 416
         $actions = array();
418 417
         $event = $transaction->primary_registration()->get_first_related('Event');
419
-        if (! empty($event)) {
418
+        if ( ! empty($event)) {
420 419
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
421 420
                 array('action' => 'edit', 'post' => $event->ID()),
422 421
                 EVENTS_ADMIN_URL
@@ -439,11 +438,11 @@  discard block
 block discarded – undo
439 438
                     $event->ID()
440 439
                 )
441 440
             ) {
442
-                $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"'
443
-                                              . ' aria-label="' . esc_attr__(
441
+                $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="'.$txn_by_event_lnk.'"'
442
+                                              . ' aria-label="'.esc_attr__(
444 443
                                                   'Filter transactions by this event',
445 444
                                                   'event_espresso'
446
-                                              ) . '">'
445
+                                              ).'">'
447 446
                                               . esc_html__('View Transactions for this event', 'event_espresso')
448 447
                                               . '</a>';
449 448
             }
@@ -455,7 +454,7 @@  discard block
 block discarded – undo
455 454
                     'espresso_events_edit',
456 455
                     $event->ID()
457 456
                 )
458
-                    ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"'
457
+                    ? '<a class="ee-aria-tooltip" href="'.$edit_event_url.'"'
459 458
                       . ' aria-label="'
460 459
                       . sprintf(
461 460
                           esc_attr__('Edit Event: %s', 'event_espresso'),
@@ -523,8 +522,8 @@  discard block
 block discarded – undo
523 522
             TXN_ADMIN_URL
524 523
         );
525 524
         return '
526
-				<a class="ee-aria-tooltip button button--icon-only" href="' . $url . '"'
527
-               . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only">
525
+				<a class="ee-aria-tooltip button button--icon-only" href="' . $url.'"'
526
+               . ' aria-label="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="button button--icon-only">
528 527
 					<span class="dashicons dashicons-cart"></span>
529 528
 				</a>';
530 529
     }
@@ -548,8 +547,8 @@  discard block
 block discarded – undo
548 547
                 && EEH_MSG_Template::is_mt_active('invoice')
549 548
             ) {
550 549
                 return '
551
-                    <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
552
-                       . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
550
+                    <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"'
551
+                       . ' target="_blank" href="'.$url.'" class="ee-aria-tooltip button button--icon-only">
553 552
                         <span class="dashicons dashicons-media-spreadsheet"></span>
554 553
                     </a>';
555 554
             }
@@ -576,8 +575,8 @@  discard block
 block discarded – undo
576 575
                 && EEH_MSG_Template::is_mt_active('receipt')
577 576
             ) {
578 577
                 return '
579
-				<a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
580
-                       . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
578
+				<a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"'
579
+                       . ' target="_blank" href="'.$url.'" class="ee-aria-tooltip button button--icon-only">
581 580
 					<span class="dashicons dashicons-text-page"></span>
582 581
 				</a>';
583 582
             }
@@ -613,8 +612,8 @@  discard block
 block discarded – undo
613 612
                 $registration->ID()
614 613
             )
615 614
                 ? '
616
-					<a href="' . $url . '"
617
-					    aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '" 
615
+					<a href="' . $url.'"
616
+					    aria-label="' . esc_attr__('View Registration Details', 'event_espresso').'" 
618 617
 					    class="ee-aria-tooltip button button--icon-only"
619 618
                     >
620 619
 						<span class="dashicons dashicons-clipboard"></span>
@@ -660,8 +659,8 @@  discard block
 block discarded – undo
660 659
                 TXN_ADMIN_URL
661 660
             );
662 661
             return '
663
-                <a href="' . $url . '" 
664
-                    aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" 
662
+                <a href="' . $url.'" 
663
+                    aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso').'" 
665 664
                     class="ee-aria-tooltip button button--icon-only"
666 665
                 >
667 666
                     <span class="dashicons dashicons-email-alt"></span>
@@ -712,8 +711,8 @@  discard block
 block discarded – undo
712 711
             && $registration->owes_monies_and_can_pay()
713 712
         ) {
714 713
             return '
715
-                <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
716
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
714
+                <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"'
715
+                   . ' target="_blank" href="'.$registration->payment_overview_url(true).'"'
717 716
                    . ' class="ee-aria-tooltip button button--icon-only">
718 717
                     <span class="dashicons dashicons-money"></span>
719 718
                 </a>';
Please login to merge, or discard this patch.
templates/txn_admin_details_main_meta_box_attendees.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
                     <?php foreach ($event_attendees as $registration => $attendee) : ?>
23 23
                         <tr style="display: table-row;" >
24 24
                             <td class="jst-cntr no-pad">
25
-                                <span class="ee-status-dot ee-status-bg--<?php echo esc_attr($attendee['STS_ID']);?>">
25
+                                <span class="ee-status-dot ee-status-bg--<?php echo esc_attr($attendee['STS_ID']); ?>">
26 26
                                 </span>
27 27
                             </td>
28 28
                             <td class='jst-left'><?php echo esc_html($attendee['event_ticket_name']); ?></td>
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2908 added lines, -2908 removed lines patch added patch discarded remove patch
@@ -16,2915 +16,2915 @@
 block discarded – undo
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18 18
 
19
-    /**
20
-     * This will hold the event object for event_details screen.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * @var NodeGroupDao
51
+	 */
52
+	protected $model_obj_node_group_persister;
53
+
54
+
55
+	/**
56
+	 * Initialize page props for this admin page group.
57
+	 */
58
+	protected function _init_page_props()
59
+	{
60
+		$this->page_slug        = EVENTS_PG_SLUG;
61
+		$this->page_label       = EVENTS_LABEL;
62
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
63
+		$this->_admin_base_path = EVENTS_ADMIN;
64
+		$this->_cpt_model_names = [
65
+			'create_new' => 'EEM_Event',
66
+			'edit'       => 'EEM_Event',
67
+		];
68
+		$this->_cpt_edit_routes = [
69
+			'espresso_events' => 'edit',
70
+		];
71
+		add_action(
72
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
+			[$this, 'verify_event_edit'],
74
+			10,
75
+			2
76
+		);
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets the ajax hooks used for this admin page group.
82
+	 */
83
+	protected function _ajax_hooks()
84
+	{
85
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Sets the page properties for this admin page group.
91
+	 */
92
+	protected function _define_page_props()
93
+	{
94
+		$this->_admin_page_title = EVENTS_LABEL;
95
+		$this->_labels           = [
96
+			'buttons'      => [
97
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
98
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
+			],
104
+			'editor_title' => [
105
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
+			],
107
+			'publishbox'   => [
108
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
110
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
+			],
114
+		];
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the page routes property for this admin page group.
120
+	 */
121
+	protected function _set_page_routes()
122
+	{
123
+		// load formatter helper
124
+		// load field generator helper
125
+		// is there a evt_id in the request?
126
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
+
129
+		$this->_page_routes = [
130
+			'default'                       => [
131
+				'func'       => '_events_overview_list_table',
132
+				'capability' => 'ee_read_events',
133
+			],
134
+			'create_new'                    => [
135
+				'func'       => '_create_new_cpt_item',
136
+				'capability' => 'ee_edit_events',
137
+			],
138
+			'edit'                          => [
139
+				'func'       => '_edit_cpt_item',
140
+				'capability' => 'ee_edit_event',
141
+				'obj_id'     => $EVT_ID,
142
+			],
143
+			'copy_event'                    => [
144
+				'func'       => '_copy_events',
145
+				'capability' => 'ee_edit_event',
146
+				'obj_id'     => $EVT_ID,
147
+				'noheader'   => true,
148
+			],
149
+			'trash_event'                   => [
150
+				'func'       => '_trash_or_restore_event',
151
+				'args'       => ['event_status' => 'trash'],
152
+				'capability' => 'ee_delete_event',
153
+				'obj_id'     => $EVT_ID,
154
+				'noheader'   => true,
155
+			],
156
+			'trash_events'                  => [
157
+				'func'       => '_trash_or_restore_events',
158
+				'args'       => ['event_status' => 'trash'],
159
+				'capability' => 'ee_delete_events',
160
+				'noheader'   => true,
161
+			],
162
+			'restore_event'                 => [
163
+				'func'       => '_trash_or_restore_event',
164
+				'args'       => ['event_status' => 'draft'],
165
+				'capability' => 'ee_delete_event',
166
+				'obj_id'     => $EVT_ID,
167
+				'noheader'   => true,
168
+			],
169
+			'restore_events'                => [
170
+				'func'       => '_trash_or_restore_events',
171
+				'args'       => ['event_status' => 'draft'],
172
+				'capability' => 'ee_delete_events',
173
+				'noheader'   => true,
174
+			],
175
+			'delete_event'                  => [
176
+				'func'       => '_delete_event',
177
+				'capability' => 'ee_delete_event',
178
+				'obj_id'     => $EVT_ID,
179
+				'noheader'   => true,
180
+			],
181
+			'delete_events'                 => [
182
+				'func'       => '_delete_events',
183
+				'capability' => 'ee_delete_events',
184
+				'noheader'   => true,
185
+			],
186
+			'view_report'                   => [
187
+				'func'       => '_view_report',
188
+				'capability' => 'ee_edit_events',
189
+			],
190
+			'default_event_settings'        => [
191
+				'func'       => '_default_event_settings',
192
+				'capability' => 'manage_options',
193
+			],
194
+			'update_default_event_settings' => [
195
+				'func'       => '_update_default_event_settings',
196
+				'capability' => 'manage_options',
197
+				'noheader'   => true,
198
+			],
199
+			'template_settings'             => [
200
+				'func'       => '_template_settings',
201
+				'capability' => 'manage_options',
202
+			],
203
+			// event category tab related
204
+			'add_category'                  => [
205
+				'func'       => '_category_details',
206
+				'capability' => 'ee_edit_event_category',
207
+				'args'       => ['add'],
208
+			],
209
+			'edit_category'                 => [
210
+				'func'       => '_category_details',
211
+				'capability' => 'ee_edit_event_category',
212
+				'args'       => ['edit'],
213
+			],
214
+			'delete_categories'             => [
215
+				'func'       => '_delete_categories',
216
+				'capability' => 'ee_delete_event_category',
217
+				'noheader'   => true,
218
+			],
219
+			'delete_category'               => [
220
+				'func'       => '_delete_categories',
221
+				'capability' => 'ee_delete_event_category',
222
+				'noheader'   => true,
223
+			],
224
+			'insert_category'               => [
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => ['new_category' => true],
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			],
230
+			'update_category'               => [
231
+				'func'       => '_insert_or_update_category',
232
+				'args'       => ['new_category' => false],
233
+				'capability' => 'ee_edit_event_category',
234
+				'noheader'   => true,
235
+			],
236
+			'category_list'                 => [
237
+				'func'       => '_category_list_table',
238
+				'capability' => 'ee_manage_event_categories',
239
+			],
240
+			'preview_deletion'              => [
241
+				'func'       => 'previewDeletion',
242
+				'capability' => 'ee_delete_events',
243
+			],
244
+			'confirm_deletion'              => [
245
+				'func'       => 'confirmDeletion',
246
+				'capability' => 'ee_delete_events',
247
+				'noheader'   => true,
248
+			],
249
+		];
250
+	}
251
+
252
+
253
+	/**
254
+	 * Set the _page_config property for this admin page group.
255
+	 */
256
+	protected function _set_page_config()
257
+	{
258
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
259
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
+		$this->_page_config = [
261
+			'default'                => [
262
+				'nav'           => [
263
+					'label' => esc_html__('Overview', 'event_espresso'),
264
+					'order' => 10,
265
+				],
266
+				'list_table'    => 'Events_Admin_List_Table',
267
+				'help_tabs'     => [
268
+					'events_overview_help_tab'                       => [
269
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
270
+						'filename' => 'events_overview',
271
+					],
272
+					'events_overview_table_column_headings_help_tab' => [
273
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
+						'filename' => 'events_overview_table_column_headings',
275
+					],
276
+					'events_overview_filters_help_tab'               => [
277
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
+						'filename' => 'events_overview_filters',
279
+					],
280
+					'events_overview_view_help_tab'                  => [
281
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
+						'filename' => 'events_overview_views',
283
+					],
284
+					'events_overview_other_help_tab'                 => [
285
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
+						'filename' => 'events_overview_other',
287
+					],
288
+				],
289
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
290
+				// 'help_tour'     => [
291
+				//     'Event_Overview_Help_Tour',
292
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
293
+				// ],
294
+				'qtips'         => ['EE_Event_List_Table_Tips'],
295
+				'require_nonce' => false,
296
+			],
297
+			'create_new'             => [
298
+				'nav'           => [
299
+					'label'      => esc_html__('Add Event', 'event_espresso'),
300
+					'order'      => 5,
301
+					'persistent' => false,
302
+				],
303
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
304
+				'help_tabs'     => [
305
+					'event_editor_help_tab'                            => [
306
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
307
+						'filename' => 'event_editor',
308
+					],
309
+					'event_editor_title_richtexteditor_help_tab'       => [
310
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
311
+						'filename' => 'event_editor_title_richtexteditor',
312
+					],
313
+					'event_editor_venue_details_help_tab'              => [
314
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
315
+						'filename' => 'event_editor_venue_details',
316
+					],
317
+					'event_editor_event_datetimes_help_tab'            => [
318
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
319
+						'filename' => 'event_editor_event_datetimes',
320
+					],
321
+					'event_editor_event_tickets_help_tab'              => [
322
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
323
+						'filename' => 'event_editor_event_tickets',
324
+					],
325
+					'event_editor_event_registration_options_help_tab' => [
326
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
327
+						'filename' => 'event_editor_event_registration_options',
328
+					],
329
+					'event_editor_tags_categories_help_tab'            => [
330
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
331
+						'filename' => 'event_editor_tags_categories',
332
+					],
333
+					'event_editor_questions_registrants_help_tab'      => [
334
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
335
+						'filename' => 'event_editor_questions_registrants',
336
+					],
337
+					'event_editor_save_new_event_help_tab'             => [
338
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
339
+						'filename' => 'event_editor_save_new_event',
340
+					],
341
+					'event_editor_other_help_tab'                      => [
342
+						'title'    => esc_html__('Event Other', 'event_espresso'),
343
+						'filename' => 'event_editor_other',
344
+					],
345
+				],
346
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
347
+				// 'help_tour'     => [
348
+				//     'Event_Editor_Help_Tour',
349
+				// ],
350
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
351
+				'require_nonce' => false,
352
+			],
353
+			'edit'                   => [
354
+				'nav'           => [
355
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
356
+					'order'      => 5,
357
+					'persistent' => false,
358
+					'url'        => $post_id
359
+						? EE_Admin_Page::add_query_args_and_nonce(
360
+							['post' => $post_id, 'action' => 'edit'],
361
+							$this->_current_page_view_url
362
+						)
363
+						: $this->_admin_base_url,
364
+				],
365
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
366
+				'help_tabs'     => [
367
+					'event_editor_help_tab'                            => [
368
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
369
+						'filename' => 'event_editor',
370
+					],
371
+					'event_editor_title_richtexteditor_help_tab'       => [
372
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
373
+						'filename' => 'event_editor_title_richtexteditor',
374
+					],
375
+					'event_editor_venue_details_help_tab'              => [
376
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
377
+						'filename' => 'event_editor_venue_details',
378
+					],
379
+					'event_editor_event_datetimes_help_tab'            => [
380
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
381
+						'filename' => 'event_editor_event_datetimes',
382
+					],
383
+					'event_editor_event_tickets_help_tab'              => [
384
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
385
+						'filename' => 'event_editor_event_tickets',
386
+					],
387
+					'event_editor_event_registration_options_help_tab' => [
388
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
389
+						'filename' => 'event_editor_event_registration_options',
390
+					],
391
+					'event_editor_tags_categories_help_tab'            => [
392
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
393
+						'filename' => 'event_editor_tags_categories',
394
+					],
395
+					'event_editor_questions_registrants_help_tab'      => [
396
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
397
+						'filename' => 'event_editor_questions_registrants',
398
+					],
399
+					'event_editor_save_new_event_help_tab'             => [
400
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
401
+						'filename' => 'event_editor_save_new_event',
402
+					],
403
+					'event_editor_other_help_tab'                      => [
404
+						'title'    => esc_html__('Event Other', 'event_espresso'),
405
+						'filename' => 'event_editor_other',
406
+					],
407
+				],
408
+				'require_nonce' => false,
409
+			],
410
+			'default_event_settings' => [
411
+				'nav'           => [
412
+					'label' => esc_html__('Default Settings', 'event_espresso'),
413
+					'order' => 40,
414
+				],
415
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
416
+				'labels'        => [
417
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
418
+				],
419
+				'help_tabs'     => [
420
+					'default_settings_help_tab'        => [
421
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
422
+						'filename' => 'events_default_settings',
423
+					],
424
+					'default_settings_status_help_tab' => [
425
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
426
+						'filename' => 'events_default_settings_status',
427
+					],
428
+					'default_maximum_tickets_help_tab' => [
429
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
430
+						'filename' => 'events_default_settings_max_tickets',
431
+					],
432
+				],
433
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
434
+				// 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
435
+				'require_nonce' => false,
436
+			],
437
+			// template settings
438
+			'template_settings'      => [
439
+				'nav'           => [
440
+					'label' => esc_html__('Templates', 'event_espresso'),
441
+					'order' => 30,
442
+				],
443
+				'metaboxes'     => $this->_default_espresso_metaboxes,
444
+				'help_tabs'     => [
445
+					'general_settings_templates_help_tab' => [
446
+						'title'    => esc_html__('Templates', 'event_espresso'),
447
+						'filename' => 'general_settings_templates',
448
+					],
449
+				],
450
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
451
+				// 'help_tour'     => ['Templates_Help_Tour'],
452
+				'require_nonce' => false,
453
+			],
454
+			// event category stuff
455
+			'add_category'           => [
456
+				'nav'           => [
457
+					'label'      => esc_html__('Add Category', 'event_espresso'),
458
+					'order'      => 15,
459
+					'persistent' => false,
460
+				],
461
+				'help_tabs'     => [
462
+					'add_category_help_tab' => [
463
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
464
+						'filename' => 'events_add_category',
465
+					],
466
+				],
467
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
468
+				// 'help_tour'     => ['Event_Add_Category_Help_Tour'],
469
+				'metaboxes'     => ['_publish_post_box'],
470
+				'require_nonce' => false,
471
+			],
472
+			'edit_category'          => [
473
+				'nav'           => [
474
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
475
+					'order'      => 15,
476
+					'persistent' => false,
477
+					'url'        => $EVT_CAT_ID
478
+						? add_query_arg(
479
+							['EVT_CAT_ID' => $EVT_CAT_ID],
480
+							$this->_current_page_view_url
481
+						)
482
+						: $this->_admin_base_url,
483
+				],
484
+				'help_tabs'     => [
485
+					'edit_category_help_tab' => [
486
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
487
+						'filename' => 'events_edit_category',
488
+					],
489
+				],
490
+				/*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
491
+				'metaboxes'     => ['_publish_post_box'],
492
+				'require_nonce' => false,
493
+			],
494
+			'category_list'          => [
495
+				'nav'           => [
496
+					'label' => esc_html__('Categories', 'event_espresso'),
497
+					'order' => 20,
498
+				],
499
+				'list_table'    => 'Event_Categories_Admin_List_Table',
500
+				'help_tabs'     => [
501
+					'events_categories_help_tab'                       => [
502
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
503
+						'filename' => 'events_categories',
504
+					],
505
+					'events_categories_table_column_headings_help_tab' => [
506
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
507
+						'filename' => 'events_categories_table_column_headings',
508
+					],
509
+					'events_categories_view_help_tab'                  => [
510
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
511
+						'filename' => 'events_categories_views',
512
+					],
513
+					'events_categories_other_help_tab'                 => [
514
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
515
+						'filename' => 'events_categories_other',
516
+					],
517
+				],
518
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
519
+				// 'help_tour'     => [
520
+				//     'Event_Categories_Help_Tour',
521
+				// ],
522
+				'metaboxes'     => $this->_default_espresso_metaboxes,
523
+				'require_nonce' => false,
524
+			],
525
+			'preview_deletion'       => [
526
+				'nav'           => [
527
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
528
+					'order'      => 15,
529
+					'persistent' => false,
530
+					'url'        => '',
531
+				],
532
+				'require_nonce' => false,
533
+			],
534
+		];
535
+	}
536
+
537
+
538
+	/**
539
+	 * Used to register any global screen options if necessary for every route in this admin page group.
540
+	 */
541
+	protected function _add_screen_options()
542
+	{
543
+	}
544
+
545
+
546
+	/**
547
+	 * Implementing the screen options for the 'default' route.
548
+	 *
549
+	 * @throws InvalidArgumentException
550
+	 * @throws InvalidDataTypeException
551
+	 * @throws InvalidInterfaceException
552
+	 */
553
+	protected function _add_screen_options_default()
554
+	{
555
+		$this->_per_page_screen_option();
556
+	}
557
+
558
+
559
+	/**
560
+	 * Implementing screen options for the category list route.
561
+	 *
562
+	 * @throws InvalidArgumentException
563
+	 * @throws InvalidDataTypeException
564
+	 * @throws InvalidInterfaceException
565
+	 */
566
+	protected function _add_screen_options_category_list()
567
+	{
568
+		$page_title              = $this->_admin_page_title;
569
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
570
+		$this->_per_page_screen_option();
571
+		$this->_admin_page_title = $page_title;
572
+	}
573
+
574
+
575
+	/**
576
+	 * Used to register any global feature pointers for the admin page group.
577
+	 */
578
+	protected function _add_feature_pointers()
579
+	{
580
+	}
581
+
582
+
583
+	/**
584
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
585
+	 */
586
+	public function load_scripts_styles()
587
+	{
588
+		wp_register_style(
589
+			'events-admin-css',
590
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
591
+			[],
592
+			EVENT_ESPRESSO_VERSION
593
+		);
594
+		wp_register_style(
595
+			'ee-cat-admin',
596
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
597
+			[],
598
+			EVENT_ESPRESSO_VERSION
599
+		);
600
+		wp_enqueue_style('events-admin-css');
601
+		wp_enqueue_style('ee-cat-admin');
602
+		// scripts
603
+		wp_register_script(
604
+			'event_editor_js',
605
+			EVENTS_ASSETS_URL . 'event_editor.js',
606
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
607
+			EVENT_ESPRESSO_VERSION,
608
+			true
609
+		);
610
+	}
611
+
612
+
613
+	/**
614
+	 * Enqueuing scripts and styles specific to this view
615
+	 */
616
+	public function load_scripts_styles_create_new()
617
+	{
618
+		$this->load_scripts_styles_edit();
619
+	}
620
+
621
+
622
+	/**
623
+	 * Enqueuing scripts and styles specific to this view
624
+	 */
625
+	public function load_scripts_styles_edit()
626
+	{
627
+		// styles
628
+		wp_enqueue_style('espresso-ui-theme');
629
+		wp_register_style(
630
+			'event-editor-css',
631
+			EVENTS_ASSETS_URL . 'event-editor.css',
632
+			['ee-admin-css'],
633
+			EVENT_ESPRESSO_VERSION
634
+		);
635
+		wp_enqueue_style('event-editor-css');
636
+		// scripts
637
+		if (! $this->admin_config->useAdvancedEditor()) {
638
+			wp_register_script(
639
+				'event-datetime-metabox',
640
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
641
+				['event_editor_js', 'ee-datepicker'],
642
+				EVENT_ESPRESSO_VERSION
643
+			);
644
+			wp_enqueue_script('event-datetime-metabox');
645
+		}
646
+	}
647
+
648
+
649
+	/**
650
+	 * Populating the _views property for the category list table view.
651
+	 */
652
+	protected function _set_list_table_views_category_list()
653
+	{
654
+		$this->_views = [
655
+			'all' => [
656
+				'slug'        => 'all',
657
+				'label'       => esc_html__('All', 'event_espresso'),
658
+				'count'       => 0,
659
+				'bulk_action' => [
660
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
661
+				],
662
+			],
663
+		];
664
+	}
665
+
666
+
667
+	/**
668
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
669
+	 */
670
+	public function admin_init()
671
+	{
672
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
673
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
674
+			'event_espresso'
675
+		);
676
+	}
677
+
678
+
679
+	/**
680
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
681
+	 * group.
682
+	 */
683
+	public function admin_notices()
684
+	{
685
+	}
686
+
687
+
688
+	/**
689
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
690
+	 * this admin page group.
691
+	 */
692
+	public function admin_footer_scripts()
693
+	{
694
+	}
695
+
696
+
697
+	/**
698
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
699
+	 * warning (via EE_Error::add_error());
700
+	 *
701
+	 * @param EE_Event $event Event object
702
+	 * @param string   $req_type
703
+	 * @return void
704
+	 * @throws EE_Error
705
+	 * @throws ReflectionException
706
+	 */
707
+	public function verify_event_edit($event = null, $req_type = '')
708
+	{
709
+		// don't need to do this when processing
710
+		if (! empty($req_type)) {
711
+			return;
712
+		}
713
+		// no event?
714
+		if (! $event instanceof EE_Event) {
715
+			$event = $this->_cpt_model_obj;
716
+		}
717
+		// STILL no event?
718
+		if (! $event instanceof EE_Event) {
719
+			return;
720
+		}
721
+		$orig_status = $event->status();
722
+		// first check if event is active.
723
+		if (
724
+			$orig_status === EEM_Event::cancelled
725
+			|| $orig_status === EEM_Event::postponed
726
+			|| $event->is_expired()
727
+			|| $event->is_inactive()
728
+		) {
729
+			return;
730
+		}
731
+		// made it here so it IS active... next check that any of the tickets are sold.
732
+		if ($event->is_sold_out(true)) {
733
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
734
+				EE_Error::add_attention(
735
+					sprintf(
736
+						esc_html__(
737
+							'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.',
738
+							'event_espresso'
739
+						),
740
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
741
+					)
742
+				);
743
+			}
744
+			return;
745
+		}
746
+		if ($orig_status === EEM_Event::sold_out) {
747
+			EE_Error::add_attention(
748
+				sprintf(
749
+					esc_html__(
750
+						'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.',
751
+						'event_espresso'
752
+					),
753
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
754
+				)
755
+			);
756
+		}
757
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
758
+		if (! $event->tickets_on_sale()) {
759
+			return;
760
+		}
761
+		// made it here so show warning
762
+		$this->_edit_event_warning();
763
+	}
764
+
765
+
766
+	/**
767
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
768
+	 * When needed, hook this into a EE_Error::add_error() notice.
769
+	 *
770
+	 * @access protected
771
+	 * @return void
772
+	 */
773
+	protected function _edit_event_warning()
774
+	{
775
+		// we don't want to add warnings during these requests
776
+		if ($this->request->getRequestParam('action') === 'editpost') {
777
+			return;
778
+		}
779
+		EE_Error::add_attention(
780
+			sprintf(
781
+				esc_html__(
782
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
783
+					'event_espresso'
784
+				),
785
+				'<a class="espresso-help-tab-lnk">',
786
+				'</a>'
787
+			)
788
+		);
789
+	}
790
+
791
+
792
+	/**
793
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
794
+	 * Otherwise, do the normal logic
795
+	 *
796
+	 * @return void
797
+	 * @throws EE_Error
798
+	 * @throws InvalidArgumentException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws InvalidInterfaceException
801
+	 */
802
+	protected function _create_new_cpt_item()
803
+	{
804
+		$has_timezone_string = get_option('timezone_string');
805
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
806
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
807
+			EE_Error::add_attention(
808
+				sprintf(
809
+					esc_html__(
810
+						'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',
811
+						'event_espresso'
812
+					),
813
+					'<br>',
814
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
815
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
816
+					. '</select>',
817
+					'<button class="button button--secondary timezone-submit">',
818
+					'</button><span class="spinner"></span>'
819
+				),
820
+				__FILE__,
821
+				__FUNCTION__,
822
+				__LINE__
823
+			);
824
+		}
825
+		parent::_create_new_cpt_item();
826
+	}
827
+
828
+
829
+	/**
830
+	 * Sets the _views property for the default route in this admin page group.
831
+	 */
832
+	protected function _set_list_table_views_default()
833
+	{
834
+		$this->_views = [
835
+			'all'   => [
836
+				'slug'        => 'all',
837
+				'label'       => esc_html__('View All Events', 'event_espresso'),
838
+				'count'       => 0,
839
+				'bulk_action' => [
840
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
841
+				],
842
+			],
843
+			'draft' => [
844
+				'slug'        => 'draft',
845
+				'label'       => esc_html__('Draft', 'event_espresso'),
846
+				'count'       => 0,
847
+				'bulk_action' => [
848
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
849
+				],
850
+			],
851
+		];
852
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
853
+			$this->_views['trash'] = [
854
+				'slug'        => 'trash',
855
+				'label'       => esc_html__('Trash', 'event_espresso'),
856
+				'count'       => 0,
857
+				'bulk_action' => [
858
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
859
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
860
+				],
861
+			];
862
+		}
863
+	}
864
+
865
+
866
+	/**
867
+	 * Provides the legend item array for the default list table view.
868
+	 *
869
+	 * @return array
870
+	 * @throws EE_Error
871
+	 * @throws EE_Error
872
+	 */
873
+	protected function _event_legend_items()
874
+	{
875
+		$items    = [
876
+			'view_details'   => [
877
+				'class' => 'dashicons dashicons-search',
878
+				'desc'  => esc_html__('View Event', 'event_espresso'),
879
+			],
880
+			'edit_event'     => [
881
+				'class' => 'dashicons dashicons-calendar-alt',
882
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
883
+			],
884
+			'view_attendees' => [
885
+				'class' => 'dashicons dashicons-groups',
886
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
887
+			],
888
+		];
889
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
890
+		$statuses = [
891
+			'sold_out_status'  => [
892
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
893
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
894
+			],
895
+			'active_status'    => [
896
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
897
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
898
+			],
899
+			'upcoming_status'  => [
900
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
901
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
902
+			],
903
+			'postponed_status' => [
904
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
905
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
906
+			],
907
+			'cancelled_status' => [
908
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
909
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
910
+			],
911
+			'expired_status'   => [
912
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
913
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
914
+			],
915
+			'inactive_status'  => [
916
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
917
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
918
+			],
919
+		];
920
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
921
+		return array_merge($items, $statuses);
922
+	}
923
+
924
+
925
+	/**
926
+	 * @return EEM_Event
927
+	 * @throws EE_Error
928
+	 * @throws InvalidArgumentException
929
+	 * @throws InvalidDataTypeException
930
+	 * @throws InvalidInterfaceException
931
+	 * @throws ReflectionException
932
+	 */
933
+	private function _event_model()
934
+	{
935
+		if (! $this->_event_model instanceof EEM_Event) {
936
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
937
+		}
938
+		return $this->_event_model;
939
+	}
940
+
941
+
942
+	/**
943
+	 * Adds extra buttons to the WP CPT permalink field row.
944
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
945
+	 *
946
+	 * @param string $return    the current html
947
+	 * @param int    $id        the post id for the page
948
+	 * @param string $new_title What the title is
949
+	 * @param string $new_slug  what the slug is
950
+	 * @return string            The new html string for the permalink area
951
+	 */
952
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
953
+	{
954
+		// make sure this is only when editing
955
+		if (! empty($id)) {
956
+			$post = get_post($id);
957
+			$return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
958
+					   . esc_html__('Shortcode', 'event_espresso')
959
+					   . '</a> ';
960
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
961
+					   . $post->ID
962
+					   . ']">';
963
+		}
964
+		return $return;
965
+	}
966
+
967
+
968
+	/**
969
+	 * _events_overview_list_table
970
+	 * This contains the logic for showing the events_overview list
971
+	 *
972
+	 * @access protected
973
+	 * @return void
974
+	 * @throws DomainException
975
+	 * @throws EE_Error
976
+	 * @throws InvalidArgumentException
977
+	 * @throws InvalidDataTypeException
978
+	 * @throws InvalidInterfaceException
979
+	 */
980
+	protected function _events_overview_list_table()
981
+	{
982
+		$after_list_table                           = [];
983
+		$after_list_table['view_event_list_button'] = EEH_HTML::div(
984
+			EEH_Template::get_button_or_link(
985
+				get_post_type_archive_link('espresso_events'),
986
+				esc_html__('View Event Archive Page', 'event_espresso'),
987
+				'button button--small button--secondary'
988
+			),
989
+			'',
990
+			'ee-admin-button-row'
991
+		);
992
+
993
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
994
+		$this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
995
+			'create_new',
996
+			'add',
997
+			[],
998
+			'add-new-h2'
999
+		);
1000
+
1001
+		$this->_template_args['after_list_table']   = array_merge(
1002
+			(array) $this->_template_args['after_list_table'],
1003
+			$after_list_table
1004
+		);
1005
+		$this->display_admin_list_table_page_with_no_sidebar();
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * this allows for extra misc actions in the default WP publish box
1011
+	 *
1012
+	 * @return void
1013
+	 * @throws DomainException
1014
+	 * @throws EE_Error
1015
+	 * @throws InvalidArgumentException
1016
+	 * @throws InvalidDataTypeException
1017
+	 * @throws InvalidInterfaceException
1018
+	 * @throws ReflectionException
1019
+	 */
1020
+	public function extra_misc_actions_publish_box()
1021
+	{
1022
+		$this->_generate_publish_box_extra_content();
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1028
+	 * saved.
1029
+	 * Typically you would use this to save any additional data.
1030
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1031
+	 * ALSO very important.  When a post transitions from scheduled to published,
1032
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1033
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1034
+	 *
1035
+	 * @access protected
1036
+	 * @abstract
1037
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1038
+	 * @param object $post    The post object of the cpt that was saved.
1039
+	 * @return void
1040
+	 * @throws EE_Error
1041
+	 * @throws InvalidArgumentException
1042
+	 * @throws InvalidDataTypeException
1043
+	 * @throws InvalidInterfaceException
1044
+	 * @throws ReflectionException
1045
+	 */
1046
+	protected function _insert_update_cpt_item($post_id, $post)
1047
+	{
1048
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1049
+			// get out we're not processing an event save.
1050
+			return;
1051
+		}
1052
+		$event_values = [
1053
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1054
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1055
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1056
+		];
1057
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1058
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1059
+			$event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1060
+				'display_ticket_selector',
1061
+				false,
1062
+				'bool'
1063
+			);
1064
+			$event_values['EVT_additional_limit']            = min(
1065
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1066
+				$this->request->getRequestParam('additional_limit', null, 'int')
1067
+			);
1068
+			$event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1069
+				'EVT_default_registration_status',
1070
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1071
+			);
1072
+
1073
+			$event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1074
+			$event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1075
+			$event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1076
+		}
1077
+		// update event
1078
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1079
+		// get event_object for other metaboxes...
1080
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1081
+		// i have to setup where conditions to override the filters in the model
1082
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1083
+		$event = $this->_event_model()->get_one(
1084
+			[
1085
+				[
1086
+					$this->_event_model()->primary_key_name() => $post_id,
1087
+					'OR'                                      => [
1088
+						'status'   => $post->post_status,
1089
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1090
+						// but the returned object here has a status of "publish", so use the original post status as well
1091
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1092
+					],
1093
+				],
1094
+			]
1095
+		);
1096
+
1097
+		// the following are default callbacks for event attachment updates
1098
+		// that can be overridden by caffeinated functionality and/or addons.
1099
+		$event_update_callbacks = [];
1100
+		if (! $this->admin_config->useAdvancedEditor()) {
1101
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1102
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1103
+		}
1104
+		$event_update_callbacks = apply_filters(
1105
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1106
+			$event_update_callbacks
1107
+		);
1108
+
1109
+		$att_success = true;
1110
+		foreach ($event_update_callbacks as $e_callback) {
1111
+			$_success = is_callable($e_callback)
1112
+				? $e_callback($event, $this->request->requestParams())
1113
+				: false;
1114
+			// if ANY of these updates fail then we want the appropriate global error message
1115
+			$att_success = $_success !== false ? $att_success : false;
1116
+		}
1117
+		// any errors?
1118
+		if ($success && $att_success === false) {
1119
+			EE_Error::add_error(
1120
+				esc_html__(
1121
+					'Event Details saved successfully but something went wrong with saving attachments.',
1122
+					'event_espresso'
1123
+				),
1124
+				__FILE__,
1125
+				__FUNCTION__,
1126
+				__LINE__
1127
+			);
1128
+		} elseif ($success === false) {
1129
+			EE_Error::add_error(
1130
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1131
+				__FILE__,
1132
+				__FUNCTION__,
1133
+				__LINE__
1134
+			);
1135
+		}
1136
+	}
1137
+
1138
+
1139
+	/**
1140
+	 * @param int $post_id
1141
+	 * @param int $revision_id
1142
+	 * @throws EE_Error
1143
+	 * @throws EE_Error
1144
+	 * @throws ReflectionException
1145
+	 * @see parent::restore_item()
1146
+	 */
1147
+	protected function _restore_cpt_item($post_id, $revision_id)
1148
+	{
1149
+		// copy existing event meta to new post
1150
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1151
+		if ($post_evt instanceof EE_Event) {
1152
+			// meta revision restore
1153
+			$post_evt->restore_revision($revision_id);
1154
+			// related objs restore
1155
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1156
+		}
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * Attach the venue to the Event
1162
+	 *
1163
+	 * @param EE_Event $event Event Object to add the venue to
1164
+	 * @param array    $data  The request data from the form
1165
+	 * @return bool           Success or fail.
1166
+	 * @throws EE_Error
1167
+	 * @throws ReflectionException
1168
+	 */
1169
+	protected function _default_venue_update(EE_Event $event, $data)
1170
+	{
1171
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1172
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1173
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1174
+		// very important.  If we don't have a venue name...
1175
+		// then we'll get out because not necessary to create empty venue
1176
+		if (empty($data['venue_title'])) {
1177
+			return false;
1178
+		}
1179
+		$venue_array = [
1180
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1181
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1182
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1183
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1184
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1185
+				? $data['venue_short_description']
1186
+				: null,
1187
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1188
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1189
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1190
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1191
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1192
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1193
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1194
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1195
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1196
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1197
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1198
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1199
+			'status'              => 'publish',
1200
+		];
1201
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1202
+		if (! empty($venue_id)) {
1203
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1204
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1205
+			// we've gotta make sure that the venue is always attached to a revision..
1206
+			// add_relation_to should take care of making sure that the relation is already present.
1207
+			$event->_add_relation_to($venue_id, 'Venue');
1208
+			return $rows_affected > 0;
1209
+		}
1210
+		// we insert the venue
1211
+		$venue_id = $venue_model->insert($venue_array);
1212
+		$event->_add_relation_to($venue_id, 'Venue');
1213
+		return ! empty($venue_id);
1214
+		// when we have the ancestor come in it's already been handled by the revision save.
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1220
+	 *
1221
+	 * @param EE_Event $event The Event object we're attaching data to
1222
+	 * @param array    $data  The request data from the form
1223
+	 * @return array
1224
+	 * @throws EE_Error
1225
+	 * @throws ReflectionException
1226
+	 * @throws Exception
1227
+	 */
1228
+	protected function _default_tickets_update(EE_Event $event, $data)
1229
+	{
1230
+		if ($this->admin_config->useAdvancedEditor()) {
1231
+			return [];
1232
+		}
1233
+		$datetime       = null;
1234
+		$saved_tickets  = [];
1235
+		$event_timezone = $event->get_timezone();
1236
+		$date_formats   = ['Y-m-d', 'h:i a'];
1237
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1238
+			// trim all values to ensure any excess whitespace is removed.
1239
+			$datetime_data                = array_map('trim', $datetime_data);
1240
+			$datetime_data['DTT_EVT_end'] =
1241
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1242
+					? $datetime_data['DTT_EVT_end']
1243
+					: $datetime_data['DTT_EVT_start'];
1244
+			$datetime_values              = [
1245
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1246
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1247
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1248
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1249
+				'DTT_order'     => $row,
1250
+			];
1251
+			// if we have an id then let's get existing object first and then set the new values.
1252
+			//  Otherwise we instantiate a new object for save.
1253
+			if (! empty($datetime_data['DTT_ID'])) {
1254
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1255
+				if (! $datetime instanceof EE_Ticket) {
1256
+					throw new RuntimeException(
1257
+						sprintf(
1258
+							esc_html__(
1259
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1260
+								'event_espresso'
1261
+							),
1262
+							$datetime_data['DTT_ID']
1263
+						)
1264
+					);
1265
+				}
1266
+				$datetime->set_date_format($date_formats[0]);
1267
+				$datetime->set_time_format($date_formats[1]);
1268
+				foreach ($datetime_values as $field => $value) {
1269
+					$datetime->set($field, $value);
1270
+				}
1271
+			} else {
1272
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1273
+			}
1274
+			if (! $datetime instanceof EE_Datetime) {
1275
+				throw new RuntimeException(
1276
+					sprintf(
1277
+						esc_html__(
1278
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1279
+							'event_espresso'
1280
+						),
1281
+						print_r($datetime_values, true)
1282
+					)
1283
+				);
1284
+			}
1285
+			// before going any further make sure our dates are setup correctly
1286
+			// so that the end date is always equal or greater than the start date.
1287
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1288
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1289
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1290
+			}
1291
+			$datetime->save();
1292
+			$event->_add_relation_to($datetime, 'Datetime');
1293
+		}
1294
+		// no datetimes get deleted so we don't do any of that logic here.
1295
+		// update tickets next
1296
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1297
+
1298
+		// set up some default start and end dates in case those are not present in the incoming data
1299
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1300
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1301
+		// use the start date of the first datetime for the end date
1302
+		$first_datetime   = $event->first_datetime();
1303
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1304
+
1305
+		// now process the incoming data
1306
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1307
+			$update_prices = false;
1308
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1309
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1310
+				: 0;
1311
+			// trim inputs to ensure any excess whitespace is removed.
1312
+			$ticket_data   = array_map('trim', $ticket_data);
1313
+			$ticket_values = [
1314
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1315
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1316
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1317
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1318
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1319
+					? $ticket_data['TKT_start_date']
1320
+					: $default_start_date,
1321
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1322
+					? $ticket_data['TKT_end_date']
1323
+					: $default_end_date,
1324
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1325
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1326
+					? $ticket_data['TKT_qty']
1327
+					: EE_INF,
1328
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1329
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1330
+					? $ticket_data['TKT_uses']
1331
+					: EE_INF,
1332
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1333
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1334
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1335
+				'TKT_price'       => $ticket_price,
1336
+				'TKT_row'         => $row,
1337
+			];
1338
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1339
+			// which means in turn that the prices will become new prices as well.
1340
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1341
+				$ticket_values['TKT_ID']         = 0;
1342
+				$ticket_values['TKT_is_default'] = 0;
1343
+				$update_prices                   = true;
1344
+			}
1345
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1346
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1347
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1348
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1349
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1350
+			if (! empty($ticket_data['TKT_ID'])) {
1351
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1352
+				if (! $existing_ticket instanceof EE_Ticket) {
1353
+					throw new RuntimeException(
1354
+						sprintf(
1355
+							esc_html__(
1356
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1357
+								'event_espresso'
1358
+							),
1359
+							$ticket_data['TKT_ID']
1360
+						)
1361
+					);
1362
+				}
1363
+				$ticket_sold = $existing_ticket->count_related(
1364
+					'Registration',
1365
+					[
1366
+							[
1367
+								'STS_ID' => [
1368
+									'NOT IN',
1369
+									[EEM_Registration::status_id_incomplete],
1370
+								],
1371
+							],
1372
+						]
1373
+				) > 0;
1374
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1375
+				// if they are different then we create a new ticket (if $ticket_sold)
1376
+				// if they aren't different then we go ahead and modify existing ticket.
1377
+				$create_new_ticket = $ticket_sold
1378
+									 && $ticket_price !== $existing_ticket->price()
1379
+									 && ! $existing_ticket->deleted();
1380
+				$existing_ticket->set_date_format($date_formats[0]);
1381
+				$existing_ticket->set_time_format($date_formats[1]);
1382
+				// set new values
1383
+				foreach ($ticket_values as $field => $value) {
1384
+					if ($field == 'TKT_qty') {
1385
+						$existing_ticket->set_qty($value);
1386
+					} elseif ($field == 'TKT_price') {
1387
+						$existing_ticket->set('TKT_price', $ticket_price);
1388
+					} else {
1389
+						$existing_ticket->set($field, $value);
1390
+					}
1391
+				}
1392
+				$ticket = $existing_ticket;
1393
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1394
+				//  Otherwise we have to create a new ticket.
1395
+				if ($create_new_ticket) {
1396
+					// archive the old ticket first
1397
+					$existing_ticket->set('TKT_deleted', 1);
1398
+					$existing_ticket->save();
1399
+					// make sure this ticket is still recorded in our $saved_tickets
1400
+					// so we don't run it through the regular trash routine.
1401
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1402
+					// create new ticket that's a copy of the existing except,
1403
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1404
+					$new_ticket = clone $existing_ticket;
1405
+					$new_ticket->set('TKT_ID', 0);
1406
+					$new_ticket->set('TKT_deleted', 0);
1407
+					$new_ticket->set('TKT_sold', 0);
1408
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1409
+					$update_prices = true;
1410
+					$ticket        = $new_ticket;
1411
+				}
1412
+			} else {
1413
+				// no TKT_id so a new ticket
1414
+				$ticket_values['TKT_price'] = $ticket_price;
1415
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1416
+				$update_prices              = true;
1417
+			}
1418
+			if (! $ticket instanceof EE_Ticket) {
1419
+				throw new RuntimeException(
1420
+					sprintf(
1421
+						esc_html__(
1422
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1423
+							'event_espresso'
1424
+						),
1425
+						print_r($ticket_values, true)
1426
+					)
1427
+				);
1428
+			}
1429
+			// cap ticket qty by datetime reg limits
1430
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1431
+			// update ticket.
1432
+			$ticket->save();
1433
+			// before going any further make sure our dates are setup correctly
1434
+			// so that the end date is always equal or greater than the start date.
1435
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1436
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1437
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1438
+				$ticket->save();
1439
+			}
1440
+			// initially let's add the ticket to the datetime
1441
+			$datetime->_add_relation_to($ticket, 'Ticket');
1442
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1443
+			// add prices to ticket
1444
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1445
+		}
1446
+		// however now we need to handle permanently deleting tickets via the ui.
1447
+		//  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1448
+		//  However, it does allow for deleting tickets that have no tickets sold,
1449
+		// in which case we want to get rid of permanently because there is no need to save in db.
1450
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1451
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1452
+		foreach ($tickets_removed as $id) {
1453
+			$id = absint($id);
1454
+			// get the ticket for this id
1455
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1456
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1457
+				continue;
1458
+			}
1459
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1460
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1461
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1462
+			foreach ($related_datetimes as $related_datetime) {
1463
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1464
+			}
1465
+			// need to do the same for prices (except these prices can also be deleted because again,
1466
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1467
+			$ticket_to_remove->delete_related_permanently('Price');
1468
+			// finally let's delete this ticket
1469
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1470
+			$ticket_to_remove->delete_permanently();
1471
+		}
1472
+		return [$datetime, $saved_tickets];
1473
+	}
1474
+
1475
+
1476
+	/**
1477
+	 * This attaches a list of given prices to a ticket.
1478
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1479
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1480
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1481
+	 *
1482
+	 * @access  private
1483
+	 * @param array     $prices_data Array of prices from the form.
1484
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1485
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1486
+	 * @return  void
1487
+	 * @throws EE_Error
1488
+	 * @throws ReflectionException
1489
+	 */
1490
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1491
+	{
1492
+		$timezone = $ticket->get_timezone();
1493
+		foreach ($prices_data as $row => $price_data) {
1494
+			$price_values = [
1495
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1496
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1497
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1498
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1499
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1500
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1501
+				'PRC_order'      => $row,
1502
+			];
1503
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1504
+				$price_values['PRC_ID'] = 0;
1505
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1506
+			} else {
1507
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1508
+				// update this price with new values
1509
+				foreach ($price_values as $field => $new_price) {
1510
+					$price->set($field, $new_price);
1511
+				}
1512
+			}
1513
+			if (! $price instanceof EE_Price) {
1514
+				throw new RuntimeException(
1515
+					sprintf(
1516
+						esc_html__(
1517
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1518
+							'event_espresso'
1519
+						),
1520
+						print_r($price_values, true)
1521
+					)
1522
+				);
1523
+			}
1524
+			$price->save();
1525
+			$ticket->_add_relation_to($price, 'Price');
1526
+		}
1527
+	}
1528
+
1529
+
1530
+	/**
1531
+	 * Add in our autosave ajax handlers
1532
+	 *
1533
+	 */
1534
+	protected function _ee_autosave_create_new()
1535
+	{
1536
+	}
1537
+
1538
+
1539
+	/**
1540
+	 * More autosave handlers.
1541
+	 */
1542
+	protected function _ee_autosave_edit()
1543
+	{
1544
+	}
1545
+
1546
+
1547
+	/**
1548
+	 * @throws EE_Error
1549
+	 * @throws ReflectionException
1550
+	 */
1551
+	private function _generate_publish_box_extra_content()
1552
+	{
1553
+		// load formatter helper
1554
+		// args for getting related registrations
1555
+		$approved_query_args        = [
1556
+			[
1557
+				'REG_deleted' => 0,
1558
+				'STS_ID'      => EEM_Registration::status_id_approved,
1559
+			],
1560
+		];
1561
+		$not_approved_query_args    = [
1562
+			[
1563
+				'REG_deleted' => 0,
1564
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1565
+			],
1566
+		];
1567
+		$pending_payment_query_args = [
1568
+			[
1569
+				'REG_deleted' => 0,
1570
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1571
+			],
1572
+		];
1573
+		// publish box
1574
+		$publish_box_extra_args = [
1575
+			'view_approved_reg_url'        => add_query_arg(
1576
+				[
1577
+					'action'      => 'default',
1578
+					'event_id'    => $this->_cpt_model_obj->ID(),
1579
+					'_reg_status' => EEM_Registration::status_id_approved,
1580
+				],
1581
+				REG_ADMIN_URL
1582
+			),
1583
+			'view_not_approved_reg_url'    => add_query_arg(
1584
+				[
1585
+					'action'      => 'default',
1586
+					'event_id'    => $this->_cpt_model_obj->ID(),
1587
+					'_reg_status' => EEM_Registration::status_id_not_approved,
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
+				],
1597
+				REG_ADMIN_URL
1598
+			),
1599
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1600
+				'Registration',
1601
+				$approved_query_args
1602
+			),
1603
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1604
+				'Registration',
1605
+				$not_approved_query_args
1606
+			),
1607
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1608
+				'Registration',
1609
+				$pending_payment_query_args
1610
+			),
1611
+			'misc_pub_section_class'       => apply_filters(
1612
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1613
+				'misc-pub-section'
1614
+			),
1615
+		];
1616
+		ob_start();
1617
+		do_action(
1618
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1619
+			$this->_cpt_model_obj
1620
+		);
1621
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1622
+		// load template
1623
+		EEH_Template::display_template(
1624
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1625
+			$publish_box_extra_args
1626
+		);
1627
+	}
1628
+
1629
+
1630
+	/**
1631
+	 * @return EE_Event
1632
+	 */
1633
+	public function get_event_object()
1634
+	{
1635
+		return $this->_cpt_model_obj;
1636
+	}
1637
+
1638
+
1639
+
1640
+
1641
+	/** METABOXES * */
1642
+	/**
1643
+	 * _register_event_editor_meta_boxes
1644
+	 * add all metaboxes related to the event_editor
1645
+	 *
1646
+	 * @return void
1647
+	 * @throws EE_Error
1648
+	 * @throws ReflectionException
1649
+	 */
1650
+	protected function _register_event_editor_meta_boxes()
1651
+	{
1652
+		$this->verify_cpt_object();
1653
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1654
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1655
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1656
+			$this->addMetaBox(
1657
+				'espresso_event_editor_event_options',
1658
+				esc_html__('Event Registration Options', 'event_espresso'),
1659
+				[$this, 'registration_options_meta_box'],
1660
+				$this->page_slug,
1661
+				'side'
1662
+			);
1663
+		}
1664
+		if (! $use_advanced_editor) {
1665
+			$this->addMetaBox(
1666
+				'espresso_event_editor_tickets',
1667
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1668
+				[$this, 'ticket_metabox'],
1669
+				$this->page_slug,
1670
+				'normal',
1671
+				'high'
1672
+			);
1673
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1674
+			add_action(
1675
+				'add_meta_boxes_espresso_events',
1676
+				function () {
1677
+					global $current_screen;
1678
+					remove_meta_box('authordiv', $current_screen, 'normal');
1679
+				},
1680
+				99
1681
+			);
1682
+		}
1683
+		// NOTE: if you're looking for other metaboxes in here,
1684
+		// where a metabox has a related management page in the admin
1685
+		// you will find it setup in the related management page's "_Hooks" file.
1686
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1687
+	}
1688
+
1689
+
1690
+	/**
1691
+	 * @throws DomainException
1692
+	 * @throws EE_Error
1693
+	 * @throws ReflectionException
1694
+	 */
1695
+	public function ticket_metabox()
1696
+	{
1697
+		$existing_datetime_ids = $existing_ticket_ids = [];
1698
+		// defaults for template args
1699
+		$template_args = [
1700
+			'existing_datetime_ids'    => '',
1701
+			'event_datetime_help_link' => '',
1702
+			'ticket_options_help_link' => '',
1703
+			'time'                     => null,
1704
+			'ticket_rows'              => '',
1705
+			'existing_ticket_ids'      => '',
1706
+			'total_ticket_rows'        => 1,
1707
+			'ticket_js_structure'      => '',
1708
+			'trash_icon'               => 'dashicons dashicons-lock',
1709
+			'disabled'                 => '',
1710
+		];
1711
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1712
+		/**
1713
+		 * 1. Start with retrieving Datetimes
1714
+		 * 2. Fore each datetime get related tickets
1715
+		 * 3. For each ticket get related prices
1716
+		 */
1717
+		/** @var EEM_Datetime $datetime_model */
1718
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1719
+		/** @var EEM_Ticket $datetime_model */
1720
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1721
+		$times        = $datetime_model->get_all_event_dates($event_id);
1722
+		/** @type EE_Datetime $first_datetime */
1723
+		$first_datetime = reset($times);
1724
+		// do we get related tickets?
1725
+		if (
1726
+			$first_datetime instanceof EE_Datetime
1727
+			&& $first_datetime->ID() !== 0
1728
+		) {
1729
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1730
+			$template_args['time']   = $first_datetime;
1731
+			$related_tickets         = $first_datetime->tickets(
1732
+				[
1733
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1734
+					'default_where_conditions' => 'none',
1735
+				]
1736
+			);
1737
+			if (! empty($related_tickets)) {
1738
+				$template_args['total_ticket_rows'] = count($related_tickets);
1739
+				$row                                = 0;
1740
+				foreach ($related_tickets as $ticket) {
1741
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1742
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1743
+					$row++;
1744
+				}
1745
+			} else {
1746
+				$template_args['total_ticket_rows'] = 1;
1747
+				/** @type EE_Ticket $ticket */
1748
+				$ticket                       = $ticket_model->create_default_object();
1749
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1750
+			}
1751
+		} else {
1752
+			$template_args['time'] = $times[0];
1753
+			/** @type EE_Ticket[] $tickets */
1754
+			$tickets                      = $ticket_model->get_all_default_tickets();
1755
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1756
+			// NOTE: we're just sending the first default row
1757
+			// (decaf can't manage default tickets so this should be sufficient);
1758
+		}
1759
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1760
+			'event_editor_event_datetimes_help_tab'
1761
+		);
1762
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1763
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1764
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1765
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1766
+			$ticket_model->create_default_object(),
1767
+			true
1768
+		);
1769
+		$template                                  = apply_filters(
1770
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1771
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1772
+		);
1773
+		EEH_Template::display_template($template, $template_args);
1774
+	}
1775
+
1776
+
1777
+	/**
1778
+	 * Setup an individual ticket form for the decaf event editor page
1779
+	 *
1780
+	 * @access private
1781
+	 * @param EE_Ticket $ticket   the ticket object
1782
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1783
+	 * @param int       $row
1784
+	 * @return string generated html for the ticket row.
1785
+	 * @throws EE_Error
1786
+	 * @throws ReflectionException
1787
+	 */
1788
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1789
+	{
1790
+		$template_args = [
1791
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1792
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1793
+				: '',
1794
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1795
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1796
+			'TKT_name'            => $ticket->get('TKT_name'),
1797
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1798
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1799
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1800
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1801
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1802
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1803
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1804
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1805
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1806
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1807
+				: ' disabled=disabled',
1808
+		];
1809
+		$price         = $ticket->ID() !== 0
1810
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1811
+			: null;
1812
+		$price         = $price instanceof EE_Price
1813
+			? $price
1814
+			: EEM_Price::instance()->create_default_object();
1815
+		$price_args    = [
1816
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1817
+			'PRC_amount'            => $price->get('PRC_amount'),
1818
+			'PRT_ID'                => $price->get('PRT_ID'),
1819
+			'PRC_ID'                => $price->get('PRC_ID'),
1820
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1821
+		];
1822
+		// make sure we have default start and end dates if skeleton
1823
+		// handle rows that should NOT be empty
1824
+		if (empty($template_args['TKT_start_date'])) {
1825
+			// if empty then the start date will be now.
1826
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1827
+		}
1828
+		if (empty($template_args['TKT_end_date'])) {
1829
+			// get the earliest datetime (if present);
1830
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1831
+				? $this->_cpt_model_obj->get_first_related(
1832
+					'Datetime',
1833
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1834
+				)
1835
+				: null;
1836
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1837
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1838
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1839
+		}
1840
+		$template_args = array_merge($template_args, $price_args);
1841
+		$template      = apply_filters(
1842
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1843
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1844
+			$ticket
1845
+		);
1846
+		return EEH_Template::display_template($template, $template_args, true);
1847
+	}
1848
+
1849
+
1850
+	/**
1851
+	 * @throws EE_Error
1852
+	 * @throws ReflectionException
1853
+	 */
1854
+	public function registration_options_meta_box()
1855
+	{
1856
+		$yes_no_values             = [
1857
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1858
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1859
+		];
1860
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1861
+			[
1862
+				EEM_Registration::status_id_cancelled,
1863
+				EEM_Registration::status_id_declined,
1864
+				EEM_Registration::status_id_incomplete,
1865
+			],
1866
+			true
1867
+		);
1868
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1869
+		$template_args['_event']                          = $this->_cpt_model_obj;
1870
+		$template_args['event']                           = $this->_cpt_model_obj;
1871
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1872
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1873
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1874
+			'default_reg_status',
1875
+			$default_reg_status_values,
1876
+			$this->_cpt_model_obj->default_registration_status()
1877
+		);
1878
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1879
+			'display_desc',
1880
+			$yes_no_values,
1881
+			$this->_cpt_model_obj->display_description()
1882
+		);
1883
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1884
+			'display_ticket_selector',
1885
+			$yes_no_values,
1886
+			$this->_cpt_model_obj->display_ticket_selector(),
1887
+			'',
1888
+			'',
1889
+			false
1890
+		);
1891
+		$template_args['additional_registration_options'] = apply_filters(
1892
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1893
+			'',
1894
+			$template_args,
1895
+			$yes_no_values,
1896
+			$default_reg_status_values
1897
+		);
1898
+		EEH_Template::display_template(
1899
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1900
+			$template_args
1901
+		);
1902
+	}
1903
+
1904
+
1905
+	/**
1906
+	 * _get_events()
1907
+	 * This method simply returns all the events (for the given _view and paging)
1908
+	 *
1909
+	 * @access public
1910
+	 * @param int  $per_page     count of items per page (20 default);
1911
+	 * @param int  $current_page what is the current page being viewed.
1912
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1913
+	 *                           If FALSE then we return an array of event objects
1914
+	 *                           that match the given _view and paging parameters.
1915
+	 * @return array|int         an array of event objects or a count of them.
1916
+	 * @throws Exception
1917
+	 */
1918
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1919
+	{
1920
+		$EEM_Event   = $this->_event_model();
1921
+		$offset      = ($current_page - 1) * $per_page;
1922
+		$limit       = $count ? null : $offset . ',' . $per_page;
1923
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1924
+		$order       = $this->request->getRequestParam('order', 'DESC');
1925
+		$month_range = $this->request->getRequestParam('month_range');
1926
+		if ($month_range) {
1927
+			$pieces = explode(' ', $month_range, 3);
1928
+			// simulate the FIRST day of the month, that fixes issues for months like February
1929
+			// where PHP doesn't know what to assume for date.
1930
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1931
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1932
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1933
+		}
1934
+		$where  = [];
1935
+		$status = $this->request->getRequestParam('status');
1936
+		// determine what post_status our condition will have for the query.
1937
+		switch ($status) {
1938
+			case 'month':
1939
+			case 'today':
1940
+			case null:
1941
+			case 'all':
1942
+				break;
1943
+			case 'draft':
1944
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1945
+				break;
1946
+			default:
1947
+				$where['status'] = $status;
1948
+		}
1949
+		// categories? The default for all categories is -1
1950
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1951
+		if ($category !== -1) {
1952
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1953
+			$where['Term_Taxonomy.term_id']  = $category;
1954
+		}
1955
+		// date where conditions
1956
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1957
+		if ($month_range) {
1958
+			$DateTime = new DateTime(
1959
+				$year_r . '-' . $month_r . '-01 00:00:00',
1960
+				new DateTimeZone('UTC')
1961
+			);
1962
+			$start    = $DateTime->getTimestamp();
1963
+			// set the datetime to be the end of the month
1964
+			$DateTime->setDate(
1965
+				$year_r,
1966
+				$month_r,
1967
+				$DateTime->format('t')
1968
+			)->setTime(23, 59, 59);
1969
+			$end                             = $DateTime->getTimestamp();
1970
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1971
+		} elseif ($status === 'today') {
1972
+			$DateTime                        =
1973
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1974
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1975
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1976
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1977
+		} elseif ($status === 'month') {
1978
+			$now                             = date('Y-m-01');
1979
+			$DateTime                        =
1980
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1981
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1982
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1983
+														->setTime(23, 59, 59)
1984
+														->format(implode(' ', $start_formats));
1985
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
+		}
1987
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1988
+			$where['EVT_wp_user'] = get_current_user_id();
1989
+		} else {
1990
+			if (! isset($where['status'])) {
1991
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1992
+					$where['OR'] = [
1993
+						'status*restrict_private' => ['!=', 'private'],
1994
+						'AND'                     => [
1995
+							'status*inclusive' => ['=', 'private'],
1996
+							'EVT_wp_user'      => get_current_user_id(),
1997
+						],
1998
+					];
1999
+				}
2000
+			}
2001
+		}
2002
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
2003
+		if (
2004
+			$wp_user
2005
+			&& $wp_user !== get_current_user_id()
2006
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2007
+		) {
2008
+			$where['EVT_wp_user'] = $wp_user;
2009
+		}
2010
+		// search query handling
2011
+		$search_term = $this->request->getRequestParam('s');
2012
+		if ($search_term) {
2013
+			$search_term = '%' . $search_term . '%';
2014
+			$where['OR'] = [
2015
+				'EVT_name'       => ['LIKE', $search_term],
2016
+				'EVT_desc'       => ['LIKE', $search_term],
2017
+				'EVT_short_desc' => ['LIKE', $search_term],
2018
+			];
2019
+		}
2020
+		// filter events by venue.
2021
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
2022
+		if ($venue) {
2023
+			$where['Venue.VNU_ID'] = $venue;
2024
+		}
2025
+		$request_params = $this->request->requestParams();
2026
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2027
+		$query_params   = apply_filters(
2028
+			'FHEE__Events_Admin_Page__get_events__query_params',
2029
+			[
2030
+				$where,
2031
+				'limit'    => $limit,
2032
+				'order_by' => $orderby,
2033
+				'order'    => $order,
2034
+				'group_by' => 'EVT_ID',
2035
+			],
2036
+			$request_params
2037
+		);
2038
+
2039
+		// let's first check if we have special requests coming in.
2040
+		$active_status = $this->request->getRequestParam('active_status');
2041
+		if ($active_status) {
2042
+			switch ($active_status) {
2043
+				case 'upcoming':
2044
+					return $EEM_Event->get_upcoming_events($query_params, $count);
2045
+				case 'expired':
2046
+					return $EEM_Event->get_expired_events($query_params, $count);
2047
+				case 'active':
2048
+					return $EEM_Event->get_active_events($query_params, $count);
2049
+				case 'inactive':
2050
+					return $EEM_Event->get_inactive_events($query_params, $count);
2051
+			}
2052
+		}
2053
+
2054
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2055
+	}
2056
+
2057
+
2058
+	/**
2059
+	 * handling for WordPress CPT actions (trash, restore, delete)
2060
+	 *
2061
+	 * @param string $post_id
2062
+	 * @throws EE_Error
2063
+	 * @throws ReflectionException
2064
+	 */
2065
+	public function trash_cpt_item($post_id)
2066
+	{
2067
+		$this->request->setRequestParam('EVT_ID', $post_id);
2068
+		$this->_trash_or_restore_event('trash', false);
2069
+	}
2070
+
2071
+
2072
+	/**
2073
+	 * @param string $post_id
2074
+	 * @throws EE_Error
2075
+	 * @throws ReflectionException
2076
+	 */
2077
+	public function restore_cpt_item($post_id)
2078
+	{
2079
+		$this->request->setRequestParam('EVT_ID', $post_id);
2080
+		$this->_trash_or_restore_event('draft', false);
2081
+	}
2082
+
2083
+
2084
+	/**
2085
+	 * @param string $post_id
2086
+	 * @throws EE_Error
2087
+	 * @throws EE_Error
2088
+	 */
2089
+	public function delete_cpt_item($post_id)
2090
+	{
2091
+		throw new EE_Error(
2092
+			esc_html__(
2093
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2094
+				'event_espresso'
2095
+			)
2096
+		);
2097
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2098
+		// $this->_delete_event();
2099
+	}
2100
+
2101
+
2102
+	/**
2103
+	 * _trash_or_restore_event
2104
+	 *
2105
+	 * @access protected
2106
+	 * @param string $event_status
2107
+	 * @param bool   $redirect_after
2108
+	 * @throws EE_Error
2109
+	 * @throws EE_Error
2110
+	 * @throws ReflectionException
2111
+	 */
2112
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2113
+	{
2114
+		// determine the event id and set to array.
2115
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2116
+		// loop thru events
2117
+		if ($EVT_ID) {
2118
+			// clean status
2119
+			$event_status = sanitize_key($event_status);
2120
+			// grab status
2121
+			if (! empty($event_status)) {
2122
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2123
+			} else {
2124
+				$success = false;
2125
+				$msg     = esc_html__(
2126
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2127
+					'event_espresso'
2128
+				);
2129
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2130
+			}
2131
+		} else {
2132
+			$success = false;
2133
+			$msg     = esc_html__(
2134
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2135
+				'event_espresso'
2136
+			);
2137
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2138
+		}
2139
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2140
+		if ($redirect_after) {
2141
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2142
+		}
2143
+	}
2144
+
2145
+
2146
+	/**
2147
+	 * _trash_or_restore_events
2148
+	 *
2149
+	 * @access protected
2150
+	 * @param string $event_status
2151
+	 * @return void
2152
+	 * @throws EE_Error
2153
+	 * @throws EE_Error
2154
+	 * @throws ReflectionException
2155
+	 */
2156
+	protected function _trash_or_restore_events($event_status = 'trash')
2157
+	{
2158
+		// clean status
2159
+		$event_status = sanitize_key($event_status);
2160
+		// grab status
2161
+		if (! empty($event_status)) {
2162
+			$success = true;
2163
+			// determine the event id and set to array.
2164
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2165
+			// loop thru events
2166
+			foreach ($EVT_IDs as $EVT_ID) {
2167
+				if ($EVT_ID = absint($EVT_ID)) {
2168
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2169
+					$success = $results !== false ? $success : false;
2170
+				} else {
2171
+					$msg = sprintf(
2172
+						esc_html__(
2173
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2174
+							'event_espresso'
2175
+						),
2176
+						$EVT_ID
2177
+					);
2178
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2179
+					$success = false;
2180
+				}
2181
+			}
2182
+		} else {
2183
+			$success = false;
2184
+			$msg     = esc_html__(
2185
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2186
+				'event_espresso'
2187
+			);
2188
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2189
+		}
2190
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2191
+		$success = $success ? 2 : false;
2192
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2193
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2194
+	}
2195
+
2196
+
2197
+	/**
2198
+	 * @param int    $EVT_ID
2199
+	 * @param string $event_status
2200
+	 * @return bool
2201
+	 * @throws EE_Error
2202
+	 * @throws ReflectionException
2203
+	 */
2204
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2205
+	{
2206
+		// grab event id
2207
+		if (! $EVT_ID) {
2208
+			$msg = esc_html__(
2209
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2210
+				'event_espresso'
2211
+			);
2212
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2213
+			return false;
2214
+		}
2215
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2216
+		// clean status
2217
+		$event_status = sanitize_key($event_status);
2218
+		// grab status
2219
+		if (empty($event_status)) {
2220
+			$msg = esc_html__(
2221
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2222
+				'event_espresso'
2223
+			);
2224
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2225
+			return false;
2226
+		}
2227
+		// was event trashed or restored ?
2228
+		switch ($event_status) {
2229
+			case 'draft':
2230
+				$action = 'restored from the trash';
2231
+				$hook   = 'AHEE_event_restored_from_trash';
2232
+				break;
2233
+			case 'trash':
2234
+				$action = 'moved to the trash';
2235
+				$hook   = 'AHEE_event_moved_to_trash';
2236
+				break;
2237
+			default:
2238
+				$action = 'updated';
2239
+				$hook   = false;
2240
+		}
2241
+		// use class to change status
2242
+		$this->_cpt_model_obj->set_status($event_status);
2243
+		$success = $this->_cpt_model_obj->save();
2244
+		if (! $success) {
2245
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2246
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2247
+			return false;
2248
+		}
2249
+		if ($hook) {
2250
+			do_action($hook);
2251
+		}
2252
+		return true;
2253
+	}
2254
+
2255
+
2256
+	/**
2257
+	 * @param array $event_ids
2258
+	 * @return array
2259
+	 * @since   4.10.23.p
2260
+	 */
2261
+	private function cleanEventIds(array $event_ids)
2262
+	{
2263
+		return array_map('absint', $event_ids);
2264
+	}
2265
+
2266
+
2267
+	/**
2268
+	 * @return array
2269
+	 * @since   4.10.23.p
2270
+	 */
2271
+	private function getEventIdsFromRequest()
2272
+	{
2273
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2274
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2275
+		} else {
2276
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2277
+		}
2278
+	}
2279
+
2280
+
2281
+	/**
2282
+	 * @param bool $preview_delete
2283
+	 * @throws EE_Error
2284
+	 */
2285
+	protected function _delete_event($preview_delete = true)
2286
+	{
2287
+		$this->_delete_events($preview_delete);
2288
+	}
2289
+
2290
+
2291
+	/**
2292
+	 * Gets the tree traversal batch persister.
2293
+	 *
2294
+	 * @return NodeGroupDao
2295
+	 * @throws InvalidArgumentException
2296
+	 * @throws InvalidDataTypeException
2297
+	 * @throws InvalidInterfaceException
2298
+	 * @since 4.10.12.p
2299
+	 */
2300
+	protected function getModelObjNodeGroupPersister()
2301
+	{
2302
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2303
+			$this->model_obj_node_group_persister =
2304
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2305
+		}
2306
+		return $this->model_obj_node_group_persister;
2307
+	}
2308
+
2309
+
2310
+	/**
2311
+	 * @param bool $preview_delete
2312
+	 * @return void
2313
+	 * @throws EE_Error
2314
+	 */
2315
+	protected function _delete_events($preview_delete = true)
2316
+	{
2317
+		$event_ids = $this->getEventIdsFromRequest();
2318
+		if ($preview_delete) {
2319
+			$this->generateDeletionPreview($event_ids);
2320
+		} else {
2321
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2322
+		}
2323
+	}
2324
+
2325
+
2326
+	/**
2327
+	 * @param array $event_ids
2328
+	 */
2329
+	protected function generateDeletionPreview(array $event_ids)
2330
+	{
2331
+		$event_ids = $this->cleanEventIds($event_ids);
2332
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2333
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2334
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2335
+			[
2336
+				'action'            => 'preview_deletion',
2337
+				'deletion_job_code' => $deletion_job_code,
2338
+			],
2339
+			$this->_admin_base_url
2340
+		);
2341
+		EEH_URL::safeRedirectAndExit(
2342
+			EE_Admin_Page::add_query_args_and_nonce(
2343
+				[
2344
+					'page'              => 'espresso_batch',
2345
+					'batch'             => EED_Batch::batch_job,
2346
+					'EVT_IDs'           => $event_ids,
2347
+					'deletion_job_code' => $deletion_job_code,
2348
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2349
+					'return_url'        => urlencode($return_url),
2350
+				],
2351
+				admin_url()
2352
+			)
2353
+		);
2354
+	}
2355
+
2356
+
2357
+	/**
2358
+	 * Checks for a POST submission
2359
+	 *
2360
+	 * @since 4.10.12.p
2361
+	 */
2362
+	protected function confirmDeletion()
2363
+	{
2364
+		$deletion_redirect_logic =
2365
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2366
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2367
+	}
2368
+
2369
+
2370
+	/**
2371
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2372
+	 *
2373
+	 * @throws EE_Error
2374
+	 * @since 4.10.12.p
2375
+	 */
2376
+	protected function previewDeletion()
2377
+	{
2378
+		$preview_deletion_logic =
2379
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2380
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2381
+		$this->display_admin_page_with_no_sidebar();
2382
+	}
2383
+
2384
+
2385
+	/**
2386
+	 * get total number of events
2387
+	 *
2388
+	 * @access public
2389
+	 * @return int
2390
+	 * @throws EE_Error
2391
+	 * @throws EE_Error
2392
+	 */
2393
+	public function total_events()
2394
+	{
2395
+		return EEM_Event::instance()->count(
2396
+			['caps' => 'read_admin'],
2397
+			'EVT_ID',
2398
+			true
2399
+		);
2400
+	}
2401
+
2402
+
2403
+	/**
2404
+	 * get total number of draft events
2405
+	 *
2406
+	 * @access public
2407
+	 * @return int
2408
+	 * @throws EE_Error
2409
+	 * @throws EE_Error
2410
+	 */
2411
+	public function total_events_draft()
2412
+	{
2413
+		return EEM_Event::instance()->count(
2414
+			[
2415
+				['status' => ['IN', ['draft', 'auto-draft']]],
2416
+				'caps' => 'read_admin',
2417
+			],
2418
+			'EVT_ID',
2419
+			true
2420
+		);
2421
+	}
2422
+
2423
+
2424
+	/**
2425
+	 * get total number of trashed events
2426
+	 *
2427
+	 * @access public
2428
+	 * @return int
2429
+	 * @throws EE_Error
2430
+	 * @throws EE_Error
2431
+	 */
2432
+	public function total_trashed_events()
2433
+	{
2434
+		return EEM_Event::instance()->count(
2435
+			[
2436
+				['status' => 'trash'],
2437
+				'caps' => 'read_admin',
2438
+			],
2439
+			'EVT_ID',
2440
+			true
2441
+		);
2442
+	}
2443
+
2444
+
2445
+	/**
2446
+	 *    _default_event_settings
2447
+	 *    This generates the Default Settings Tab
2448
+	 *
2449
+	 * @return void
2450
+	 * @throws DomainException
2451
+	 * @throws EE_Error
2452
+	 * @throws InvalidArgumentException
2453
+	 * @throws InvalidDataTypeException
2454
+	 * @throws InvalidInterfaceException
2455
+	 */
2456
+	protected function _default_event_settings()
2457
+	{
2458
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2459
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2460
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
2461
+			$this->_default_event_settings_form()->get_html(),
2462
+			'',
2463
+			'padding'
2464
+		);
2465
+		$this->display_admin_page_with_sidebar();
2466
+	}
2467
+
2468
+
2469
+	/**
2470
+	 * Return the form for event settings.
2471
+	 *
2472
+	 * @return EE_Form_Section_Proper
2473
+	 * @throws EE_Error
2474
+	 */
2475
+	protected function _default_event_settings_form()
2476
+	{
2477
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2478
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2479
+		// exclude
2480
+			[
2481
+				EEM_Registration::status_id_cancelled,
2482
+				EEM_Registration::status_id_declined,
2483
+				EEM_Registration::status_id_incomplete,
2484
+				EEM_Registration::status_id_wait_list,
2485
+			],
2486
+			true
2487
+		);
2488
+		return new EE_Form_Section_Proper(
2489
+			[
2490
+				'name'            => 'update_default_event_settings',
2491
+				'html_id'         => 'update_default_event_settings',
2492
+				'html_class'      => 'form-table',
2493
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2494
+				'subsections'     => apply_filters(
2495
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2496
+					[
2497
+						'defaults_section_header' => new EE_Form_Section_HTML(
2498
+							EEH_HTML::h2(
2499
+								esc_html__('Default Settings', 'event_espresso'),
2500
+								'',
2501
+								'ee-admin-settings-hdr'
2502
+							)
2503
+						),
2504
+						'default_reg_status'  => new EE_Select_Input(
2505
+							$registration_stati_for_selection,
2506
+							[
2507
+								'default'         => isset($registration_config->default_STS_ID)
2508
+													 && array_key_exists(
2509
+														 $registration_config->default_STS_ID,
2510
+														 $registration_stati_for_selection
2511
+													 )
2512
+									? sanitize_text_field($registration_config->default_STS_ID)
2513
+									: EEM_Registration::status_id_pending_payment,
2514
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2515
+													 . EEH_Template::get_help_tab_link(
2516
+														 'default_settings_status_help_tab'
2517
+													 ),
2518
+								'html_help_text'  => esc_html__(
2519
+									'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.',
2520
+									'event_espresso'
2521
+								),
2522
+							]
2523
+						),
2524
+						'default_max_tickets' => new EE_Integer_Input(
2525
+							[
2526
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2527
+									? $registration_config->default_maximum_number_of_tickets
2528
+									: EEM_Event::get_default_additional_limit(),
2529
+								'html_label_text' => esc_html__(
2530
+									'Default Maximum Tickets Allowed Per Order:',
2531
+									'event_espresso'
2532
+								)
2533
+													 . EEH_Template::get_help_tab_link(
2534
+														 'default_maximum_tickets_help_tab"'
2535
+													 ),
2536
+								'html_help_text'  => esc_html__(
2537
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2538
+									'event_espresso'
2539
+								),
2540
+							]
2541
+						),
2542
+					]
2543
+				),
2544
+			]
2545
+		);
2546
+	}
2547
+
2548
+
2549
+	/**
2550
+	 * @return void
2551
+	 * @throws EE_Error
2552
+	 * @throws InvalidArgumentException
2553
+	 * @throws InvalidDataTypeException
2554
+	 * @throws InvalidInterfaceException
2555
+	 */
2556
+	protected function _update_default_event_settings()
2557
+	{
2558
+		$form = $this->_default_event_settings_form();
2559
+		if ($form->was_submitted()) {
2560
+			$form->receive_form_submission();
2561
+			if ($form->is_valid()) {
2562
+				$registration_config = EE_Registry::instance()->CFG->registration;
2563
+				$valid_data          = $form->valid_data();
2564
+				if (isset($valid_data['default_reg_status'])) {
2565
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2566
+				}
2567
+				if (isset($valid_data['default_max_tickets'])) {
2568
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2569
+				}
2570
+				do_action(
2571
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2572
+					$valid_data,
2573
+					EE_Registry::instance()->CFG,
2574
+					$this
2575
+				);
2576
+				// update because data was valid!
2577
+				EE_Registry::instance()->CFG->update_espresso_config();
2578
+				EE_Error::overwrite_success();
2579
+				EE_Error::add_success(
2580
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2581
+				);
2582
+			}
2583
+		}
2584
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2585
+	}
2586
+
2587
+
2588
+	/*************        Templates        *************
21 2589
      *
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * @var NodeGroupDao
51
-     */
52
-    protected $model_obj_node_group_persister;
53
-
54
-
55
-    /**
56
-     * Initialize page props for this admin page group.
57
-     */
58
-    protected function _init_page_props()
59
-    {
60
-        $this->page_slug        = EVENTS_PG_SLUG;
61
-        $this->page_label       = EVENTS_LABEL;
62
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
63
-        $this->_admin_base_path = EVENTS_ADMIN;
64
-        $this->_cpt_model_names = [
65
-            'create_new' => 'EEM_Event',
66
-            'edit'       => 'EEM_Event',
67
-        ];
68
-        $this->_cpt_edit_routes = [
69
-            'espresso_events' => 'edit',
70
-        ];
71
-        add_action(
72
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
-            [$this, 'verify_event_edit'],
74
-            10,
75
-            2
76
-        );
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets the ajax hooks used for this admin page group.
82
-     */
83
-    protected function _ajax_hooks()
84
-    {
85
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
-    }
87
-
88
-
89
-    /**
90
-     * Sets the page properties for this admin page group.
91
-     */
92
-    protected function _define_page_props()
93
-    {
94
-        $this->_admin_page_title = EVENTS_LABEL;
95
-        $this->_labels           = [
96
-            'buttons'      => [
97
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
98
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
-            ],
104
-            'editor_title' => [
105
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
-            ],
107
-            'publishbox'   => [
108
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
110
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
-            ],
114
-        ];
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the page routes property for this admin page group.
120
-     */
121
-    protected function _set_page_routes()
122
-    {
123
-        // load formatter helper
124
-        // load field generator helper
125
-        // is there a evt_id in the request?
126
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
-
129
-        $this->_page_routes = [
130
-            'default'                       => [
131
-                'func'       => '_events_overview_list_table',
132
-                'capability' => 'ee_read_events',
133
-            ],
134
-            'create_new'                    => [
135
-                'func'       => '_create_new_cpt_item',
136
-                'capability' => 'ee_edit_events',
137
-            ],
138
-            'edit'                          => [
139
-                'func'       => '_edit_cpt_item',
140
-                'capability' => 'ee_edit_event',
141
-                'obj_id'     => $EVT_ID,
142
-            ],
143
-            'copy_event'                    => [
144
-                'func'       => '_copy_events',
145
-                'capability' => 'ee_edit_event',
146
-                'obj_id'     => $EVT_ID,
147
-                'noheader'   => true,
148
-            ],
149
-            'trash_event'                   => [
150
-                'func'       => '_trash_or_restore_event',
151
-                'args'       => ['event_status' => 'trash'],
152
-                'capability' => 'ee_delete_event',
153
-                'obj_id'     => $EVT_ID,
154
-                'noheader'   => true,
155
-            ],
156
-            'trash_events'                  => [
157
-                'func'       => '_trash_or_restore_events',
158
-                'args'       => ['event_status' => 'trash'],
159
-                'capability' => 'ee_delete_events',
160
-                'noheader'   => true,
161
-            ],
162
-            'restore_event'                 => [
163
-                'func'       => '_trash_or_restore_event',
164
-                'args'       => ['event_status' => 'draft'],
165
-                'capability' => 'ee_delete_event',
166
-                'obj_id'     => $EVT_ID,
167
-                'noheader'   => true,
168
-            ],
169
-            'restore_events'                => [
170
-                'func'       => '_trash_or_restore_events',
171
-                'args'       => ['event_status' => 'draft'],
172
-                'capability' => 'ee_delete_events',
173
-                'noheader'   => true,
174
-            ],
175
-            'delete_event'                  => [
176
-                'func'       => '_delete_event',
177
-                'capability' => 'ee_delete_event',
178
-                'obj_id'     => $EVT_ID,
179
-                'noheader'   => true,
180
-            ],
181
-            'delete_events'                 => [
182
-                'func'       => '_delete_events',
183
-                'capability' => 'ee_delete_events',
184
-                'noheader'   => true,
185
-            ],
186
-            'view_report'                   => [
187
-                'func'       => '_view_report',
188
-                'capability' => 'ee_edit_events',
189
-            ],
190
-            'default_event_settings'        => [
191
-                'func'       => '_default_event_settings',
192
-                'capability' => 'manage_options',
193
-            ],
194
-            'update_default_event_settings' => [
195
-                'func'       => '_update_default_event_settings',
196
-                'capability' => 'manage_options',
197
-                'noheader'   => true,
198
-            ],
199
-            'template_settings'             => [
200
-                'func'       => '_template_settings',
201
-                'capability' => 'manage_options',
202
-            ],
203
-            // event category tab related
204
-            'add_category'                  => [
205
-                'func'       => '_category_details',
206
-                'capability' => 'ee_edit_event_category',
207
-                'args'       => ['add'],
208
-            ],
209
-            'edit_category'                 => [
210
-                'func'       => '_category_details',
211
-                'capability' => 'ee_edit_event_category',
212
-                'args'       => ['edit'],
213
-            ],
214
-            'delete_categories'             => [
215
-                'func'       => '_delete_categories',
216
-                'capability' => 'ee_delete_event_category',
217
-                'noheader'   => true,
218
-            ],
219
-            'delete_category'               => [
220
-                'func'       => '_delete_categories',
221
-                'capability' => 'ee_delete_event_category',
222
-                'noheader'   => true,
223
-            ],
224
-            'insert_category'               => [
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => ['new_category' => true],
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ],
230
-            'update_category'               => [
231
-                'func'       => '_insert_or_update_category',
232
-                'args'       => ['new_category' => false],
233
-                'capability' => 'ee_edit_event_category',
234
-                'noheader'   => true,
235
-            ],
236
-            'category_list'                 => [
237
-                'func'       => '_category_list_table',
238
-                'capability' => 'ee_manage_event_categories',
239
-            ],
240
-            'preview_deletion'              => [
241
-                'func'       => 'previewDeletion',
242
-                'capability' => 'ee_delete_events',
243
-            ],
244
-            'confirm_deletion'              => [
245
-                'func'       => 'confirmDeletion',
246
-                'capability' => 'ee_delete_events',
247
-                'noheader'   => true,
248
-            ],
249
-        ];
250
-    }
251
-
252
-
253
-    /**
254
-     * Set the _page_config property for this admin page group.
255
-     */
256
-    protected function _set_page_config()
257
-    {
258
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
259
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
-        $this->_page_config = [
261
-            'default'                => [
262
-                'nav'           => [
263
-                    'label' => esc_html__('Overview', 'event_espresso'),
264
-                    'order' => 10,
265
-                ],
266
-                'list_table'    => 'Events_Admin_List_Table',
267
-                'help_tabs'     => [
268
-                    'events_overview_help_tab'                       => [
269
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
270
-                        'filename' => 'events_overview',
271
-                    ],
272
-                    'events_overview_table_column_headings_help_tab' => [
273
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
-                        'filename' => 'events_overview_table_column_headings',
275
-                    ],
276
-                    'events_overview_filters_help_tab'               => [
277
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
-                        'filename' => 'events_overview_filters',
279
-                    ],
280
-                    'events_overview_view_help_tab'                  => [
281
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
-                        'filename' => 'events_overview_views',
283
-                    ],
284
-                    'events_overview_other_help_tab'                 => [
285
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
-                        'filename' => 'events_overview_other',
287
-                    ],
288
-                ],
289
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
290
-                // 'help_tour'     => [
291
-                //     'Event_Overview_Help_Tour',
292
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
293
-                // ],
294
-                'qtips'         => ['EE_Event_List_Table_Tips'],
295
-                'require_nonce' => false,
296
-            ],
297
-            'create_new'             => [
298
-                'nav'           => [
299
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
300
-                    'order'      => 5,
301
-                    'persistent' => false,
302
-                ],
303
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
304
-                'help_tabs'     => [
305
-                    'event_editor_help_tab'                            => [
306
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
307
-                        'filename' => 'event_editor',
308
-                    ],
309
-                    'event_editor_title_richtexteditor_help_tab'       => [
310
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
311
-                        'filename' => 'event_editor_title_richtexteditor',
312
-                    ],
313
-                    'event_editor_venue_details_help_tab'              => [
314
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
315
-                        'filename' => 'event_editor_venue_details',
316
-                    ],
317
-                    'event_editor_event_datetimes_help_tab'            => [
318
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
319
-                        'filename' => 'event_editor_event_datetimes',
320
-                    ],
321
-                    'event_editor_event_tickets_help_tab'              => [
322
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
323
-                        'filename' => 'event_editor_event_tickets',
324
-                    ],
325
-                    'event_editor_event_registration_options_help_tab' => [
326
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
327
-                        'filename' => 'event_editor_event_registration_options',
328
-                    ],
329
-                    'event_editor_tags_categories_help_tab'            => [
330
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
331
-                        'filename' => 'event_editor_tags_categories',
332
-                    ],
333
-                    'event_editor_questions_registrants_help_tab'      => [
334
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
335
-                        'filename' => 'event_editor_questions_registrants',
336
-                    ],
337
-                    'event_editor_save_new_event_help_tab'             => [
338
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
339
-                        'filename' => 'event_editor_save_new_event',
340
-                    ],
341
-                    'event_editor_other_help_tab'                      => [
342
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
343
-                        'filename' => 'event_editor_other',
344
-                    ],
345
-                ],
346
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
347
-                // 'help_tour'     => [
348
-                //     'Event_Editor_Help_Tour',
349
-                // ],
350
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
351
-                'require_nonce' => false,
352
-            ],
353
-            'edit'                   => [
354
-                'nav'           => [
355
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
356
-                    'order'      => 5,
357
-                    'persistent' => false,
358
-                    'url'        => $post_id
359
-                        ? EE_Admin_Page::add_query_args_and_nonce(
360
-                            ['post' => $post_id, 'action' => 'edit'],
361
-                            $this->_current_page_view_url
362
-                        )
363
-                        : $this->_admin_base_url,
364
-                ],
365
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
366
-                'help_tabs'     => [
367
-                    'event_editor_help_tab'                            => [
368
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
369
-                        'filename' => 'event_editor',
370
-                    ],
371
-                    'event_editor_title_richtexteditor_help_tab'       => [
372
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
373
-                        'filename' => 'event_editor_title_richtexteditor',
374
-                    ],
375
-                    'event_editor_venue_details_help_tab'              => [
376
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
377
-                        'filename' => 'event_editor_venue_details',
378
-                    ],
379
-                    'event_editor_event_datetimes_help_tab'            => [
380
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
381
-                        'filename' => 'event_editor_event_datetimes',
382
-                    ],
383
-                    'event_editor_event_tickets_help_tab'              => [
384
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
385
-                        'filename' => 'event_editor_event_tickets',
386
-                    ],
387
-                    'event_editor_event_registration_options_help_tab' => [
388
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
389
-                        'filename' => 'event_editor_event_registration_options',
390
-                    ],
391
-                    'event_editor_tags_categories_help_tab'            => [
392
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
393
-                        'filename' => 'event_editor_tags_categories',
394
-                    ],
395
-                    'event_editor_questions_registrants_help_tab'      => [
396
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
397
-                        'filename' => 'event_editor_questions_registrants',
398
-                    ],
399
-                    'event_editor_save_new_event_help_tab'             => [
400
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
401
-                        'filename' => 'event_editor_save_new_event',
402
-                    ],
403
-                    'event_editor_other_help_tab'                      => [
404
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
405
-                        'filename' => 'event_editor_other',
406
-                    ],
407
-                ],
408
-                'require_nonce' => false,
409
-            ],
410
-            'default_event_settings' => [
411
-                'nav'           => [
412
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
413
-                    'order' => 40,
414
-                ],
415
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
416
-                'labels'        => [
417
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
418
-                ],
419
-                'help_tabs'     => [
420
-                    'default_settings_help_tab'        => [
421
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
422
-                        'filename' => 'events_default_settings',
423
-                    ],
424
-                    'default_settings_status_help_tab' => [
425
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
426
-                        'filename' => 'events_default_settings_status',
427
-                    ],
428
-                    'default_maximum_tickets_help_tab' => [
429
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
430
-                        'filename' => 'events_default_settings_max_tickets',
431
-                    ],
432
-                ],
433
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
434
-                // 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
435
-                'require_nonce' => false,
436
-            ],
437
-            // template settings
438
-            'template_settings'      => [
439
-                'nav'           => [
440
-                    'label' => esc_html__('Templates', 'event_espresso'),
441
-                    'order' => 30,
442
-                ],
443
-                'metaboxes'     => $this->_default_espresso_metaboxes,
444
-                'help_tabs'     => [
445
-                    'general_settings_templates_help_tab' => [
446
-                        'title'    => esc_html__('Templates', 'event_espresso'),
447
-                        'filename' => 'general_settings_templates',
448
-                    ],
449
-                ],
450
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
451
-                // 'help_tour'     => ['Templates_Help_Tour'],
452
-                'require_nonce' => false,
453
-            ],
454
-            // event category stuff
455
-            'add_category'           => [
456
-                'nav'           => [
457
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
458
-                    'order'      => 15,
459
-                    'persistent' => false,
460
-                ],
461
-                'help_tabs'     => [
462
-                    'add_category_help_tab' => [
463
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
464
-                        'filename' => 'events_add_category',
465
-                    ],
466
-                ],
467
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
468
-                // 'help_tour'     => ['Event_Add_Category_Help_Tour'],
469
-                'metaboxes'     => ['_publish_post_box'],
470
-                'require_nonce' => false,
471
-            ],
472
-            'edit_category'          => [
473
-                'nav'           => [
474
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
475
-                    'order'      => 15,
476
-                    'persistent' => false,
477
-                    'url'        => $EVT_CAT_ID
478
-                        ? add_query_arg(
479
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
480
-                            $this->_current_page_view_url
481
-                        )
482
-                        : $this->_admin_base_url,
483
-                ],
484
-                'help_tabs'     => [
485
-                    'edit_category_help_tab' => [
486
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
487
-                        'filename' => 'events_edit_category',
488
-                    ],
489
-                ],
490
-                /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
491
-                'metaboxes'     => ['_publish_post_box'],
492
-                'require_nonce' => false,
493
-            ],
494
-            'category_list'          => [
495
-                'nav'           => [
496
-                    'label' => esc_html__('Categories', 'event_espresso'),
497
-                    'order' => 20,
498
-                ],
499
-                'list_table'    => 'Event_Categories_Admin_List_Table',
500
-                'help_tabs'     => [
501
-                    'events_categories_help_tab'                       => [
502
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
503
-                        'filename' => 'events_categories',
504
-                    ],
505
-                    'events_categories_table_column_headings_help_tab' => [
506
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
507
-                        'filename' => 'events_categories_table_column_headings',
508
-                    ],
509
-                    'events_categories_view_help_tab'                  => [
510
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
511
-                        'filename' => 'events_categories_views',
512
-                    ],
513
-                    'events_categories_other_help_tab'                 => [
514
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
515
-                        'filename' => 'events_categories_other',
516
-                    ],
517
-                ],
518
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
519
-                // 'help_tour'     => [
520
-                //     'Event_Categories_Help_Tour',
521
-                // ],
522
-                'metaboxes'     => $this->_default_espresso_metaboxes,
523
-                'require_nonce' => false,
524
-            ],
525
-            'preview_deletion'       => [
526
-                'nav'           => [
527
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
528
-                    'order'      => 15,
529
-                    'persistent' => false,
530
-                    'url'        => '',
531
-                ],
532
-                'require_nonce' => false,
533
-            ],
534
-        ];
535
-    }
536
-
537
-
538
-    /**
539
-     * Used to register any global screen options if necessary for every route in this admin page group.
540
-     */
541
-    protected function _add_screen_options()
542
-    {
543
-    }
544
-
545
-
546
-    /**
547
-     * Implementing the screen options for the 'default' route.
548
-     *
549
-     * @throws InvalidArgumentException
550
-     * @throws InvalidDataTypeException
551
-     * @throws InvalidInterfaceException
552
-     */
553
-    protected function _add_screen_options_default()
554
-    {
555
-        $this->_per_page_screen_option();
556
-    }
557
-
558
-
559
-    /**
560
-     * Implementing screen options for the category list route.
561
-     *
562
-     * @throws InvalidArgumentException
563
-     * @throws InvalidDataTypeException
564
-     * @throws InvalidInterfaceException
565
-     */
566
-    protected function _add_screen_options_category_list()
567
-    {
568
-        $page_title              = $this->_admin_page_title;
569
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
570
-        $this->_per_page_screen_option();
571
-        $this->_admin_page_title = $page_title;
572
-    }
573
-
574
-
575
-    /**
576
-     * Used to register any global feature pointers for the admin page group.
577
-     */
578
-    protected function _add_feature_pointers()
579
-    {
580
-    }
581
-
582
-
583
-    /**
584
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
585
-     */
586
-    public function load_scripts_styles()
587
-    {
588
-        wp_register_style(
589
-            'events-admin-css',
590
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
591
-            [],
592
-            EVENT_ESPRESSO_VERSION
593
-        );
594
-        wp_register_style(
595
-            'ee-cat-admin',
596
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
597
-            [],
598
-            EVENT_ESPRESSO_VERSION
599
-        );
600
-        wp_enqueue_style('events-admin-css');
601
-        wp_enqueue_style('ee-cat-admin');
602
-        // scripts
603
-        wp_register_script(
604
-            'event_editor_js',
605
-            EVENTS_ASSETS_URL . 'event_editor.js',
606
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
607
-            EVENT_ESPRESSO_VERSION,
608
-            true
609
-        );
610
-    }
611
-
612
-
613
-    /**
614
-     * Enqueuing scripts and styles specific to this view
615
-     */
616
-    public function load_scripts_styles_create_new()
617
-    {
618
-        $this->load_scripts_styles_edit();
619
-    }
620
-
621
-
622
-    /**
623
-     * Enqueuing scripts and styles specific to this view
624
-     */
625
-    public function load_scripts_styles_edit()
626
-    {
627
-        // styles
628
-        wp_enqueue_style('espresso-ui-theme');
629
-        wp_register_style(
630
-            'event-editor-css',
631
-            EVENTS_ASSETS_URL . 'event-editor.css',
632
-            ['ee-admin-css'],
633
-            EVENT_ESPRESSO_VERSION
634
-        );
635
-        wp_enqueue_style('event-editor-css');
636
-        // scripts
637
-        if (! $this->admin_config->useAdvancedEditor()) {
638
-            wp_register_script(
639
-                'event-datetime-metabox',
640
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
641
-                ['event_editor_js', 'ee-datepicker'],
642
-                EVENT_ESPRESSO_VERSION
643
-            );
644
-            wp_enqueue_script('event-datetime-metabox');
645
-        }
646
-    }
647
-
648
-
649
-    /**
650
-     * Populating the _views property for the category list table view.
651
-     */
652
-    protected function _set_list_table_views_category_list()
653
-    {
654
-        $this->_views = [
655
-            'all' => [
656
-                'slug'        => 'all',
657
-                'label'       => esc_html__('All', 'event_espresso'),
658
-                'count'       => 0,
659
-                'bulk_action' => [
660
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
661
-                ],
662
-            ],
663
-        ];
664
-    }
665
-
666
-
667
-    /**
668
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
669
-     */
670
-    public function admin_init()
671
-    {
672
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
673
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
674
-            'event_espresso'
675
-        );
676
-    }
677
-
678
-
679
-    /**
680
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
681
-     * group.
682
-     */
683
-    public function admin_notices()
684
-    {
685
-    }
686
-
687
-
688
-    /**
689
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
690
-     * this admin page group.
691
-     */
692
-    public function admin_footer_scripts()
693
-    {
694
-    }
695
-
696
-
697
-    /**
698
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
699
-     * warning (via EE_Error::add_error());
700
-     *
701
-     * @param EE_Event $event Event object
702
-     * @param string   $req_type
703
-     * @return void
704
-     * @throws EE_Error
705
-     * @throws ReflectionException
706
-     */
707
-    public function verify_event_edit($event = null, $req_type = '')
708
-    {
709
-        // don't need to do this when processing
710
-        if (! empty($req_type)) {
711
-            return;
712
-        }
713
-        // no event?
714
-        if (! $event instanceof EE_Event) {
715
-            $event = $this->_cpt_model_obj;
716
-        }
717
-        // STILL no event?
718
-        if (! $event instanceof EE_Event) {
719
-            return;
720
-        }
721
-        $orig_status = $event->status();
722
-        // first check if event is active.
723
-        if (
724
-            $orig_status === EEM_Event::cancelled
725
-            || $orig_status === EEM_Event::postponed
726
-            || $event->is_expired()
727
-            || $event->is_inactive()
728
-        ) {
729
-            return;
730
-        }
731
-        // made it here so it IS active... next check that any of the tickets are sold.
732
-        if ($event->is_sold_out(true)) {
733
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
734
-                EE_Error::add_attention(
735
-                    sprintf(
736
-                        esc_html__(
737
-                            '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.',
738
-                            'event_espresso'
739
-                        ),
740
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
741
-                    )
742
-                );
743
-            }
744
-            return;
745
-        }
746
-        if ($orig_status === EEM_Event::sold_out) {
747
-            EE_Error::add_attention(
748
-                sprintf(
749
-                    esc_html__(
750
-                        '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.',
751
-                        'event_espresso'
752
-                    ),
753
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
754
-                )
755
-            );
756
-        }
757
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
758
-        if (! $event->tickets_on_sale()) {
759
-            return;
760
-        }
761
-        // made it here so show warning
762
-        $this->_edit_event_warning();
763
-    }
764
-
765
-
766
-    /**
767
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
768
-     * When needed, hook this into a EE_Error::add_error() notice.
769
-     *
770
-     * @access protected
771
-     * @return void
772
-     */
773
-    protected function _edit_event_warning()
774
-    {
775
-        // we don't want to add warnings during these requests
776
-        if ($this->request->getRequestParam('action') === 'editpost') {
777
-            return;
778
-        }
779
-        EE_Error::add_attention(
780
-            sprintf(
781
-                esc_html__(
782
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
783
-                    'event_espresso'
784
-                ),
785
-                '<a class="espresso-help-tab-lnk">',
786
-                '</a>'
787
-            )
788
-        );
789
-    }
790
-
791
-
792
-    /**
793
-     * When a user is creating a new event, notify them if they haven't set their timezone.
794
-     * Otherwise, do the normal logic
795
-     *
796
-     * @return void
797
-     * @throws EE_Error
798
-     * @throws InvalidArgumentException
799
-     * @throws InvalidDataTypeException
800
-     * @throws InvalidInterfaceException
801
-     */
802
-    protected function _create_new_cpt_item()
803
-    {
804
-        $has_timezone_string = get_option('timezone_string');
805
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
806
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
807
-            EE_Error::add_attention(
808
-                sprintf(
809
-                    esc_html__(
810
-                        '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',
811
-                        'event_espresso'
812
-                    ),
813
-                    '<br>',
814
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
815
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
816
-                    . '</select>',
817
-                    '<button class="button button--secondary timezone-submit">',
818
-                    '</button><span class="spinner"></span>'
819
-                ),
820
-                __FILE__,
821
-                __FUNCTION__,
822
-                __LINE__
823
-            );
824
-        }
825
-        parent::_create_new_cpt_item();
826
-    }
827
-
828
-
829
-    /**
830
-     * Sets the _views property for the default route in this admin page group.
831
-     */
832
-    protected function _set_list_table_views_default()
833
-    {
834
-        $this->_views = [
835
-            'all'   => [
836
-                'slug'        => 'all',
837
-                'label'       => esc_html__('View All Events', 'event_espresso'),
838
-                'count'       => 0,
839
-                'bulk_action' => [
840
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
841
-                ],
842
-            ],
843
-            'draft' => [
844
-                'slug'        => 'draft',
845
-                'label'       => esc_html__('Draft', 'event_espresso'),
846
-                'count'       => 0,
847
-                'bulk_action' => [
848
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
849
-                ],
850
-            ],
851
-        ];
852
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
853
-            $this->_views['trash'] = [
854
-                'slug'        => 'trash',
855
-                'label'       => esc_html__('Trash', 'event_espresso'),
856
-                'count'       => 0,
857
-                'bulk_action' => [
858
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
859
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
860
-                ],
861
-            ];
862
-        }
863
-    }
864
-
865
-
866
-    /**
867
-     * Provides the legend item array for the default list table view.
868
-     *
869
-     * @return array
870
-     * @throws EE_Error
871
-     * @throws EE_Error
872
-     */
873
-    protected function _event_legend_items()
874
-    {
875
-        $items    = [
876
-            'view_details'   => [
877
-                'class' => 'dashicons dashicons-search',
878
-                'desc'  => esc_html__('View Event', 'event_espresso'),
879
-            ],
880
-            'edit_event'     => [
881
-                'class' => 'dashicons dashicons-calendar-alt',
882
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
883
-            ],
884
-            'view_attendees' => [
885
-                'class' => 'dashicons dashicons-groups',
886
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
887
-            ],
888
-        ];
889
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
890
-        $statuses = [
891
-            'sold_out_status'  => [
892
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
893
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
894
-            ],
895
-            'active_status'    => [
896
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
897
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
898
-            ],
899
-            'upcoming_status'  => [
900
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
901
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
902
-            ],
903
-            'postponed_status' => [
904
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
905
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
906
-            ],
907
-            'cancelled_status' => [
908
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
909
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
910
-            ],
911
-            'expired_status'   => [
912
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
913
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
914
-            ],
915
-            'inactive_status'  => [
916
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
917
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
918
-            ],
919
-        ];
920
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
921
-        return array_merge($items, $statuses);
922
-    }
923
-
924
-
925
-    /**
926
-     * @return EEM_Event
927
-     * @throws EE_Error
928
-     * @throws InvalidArgumentException
929
-     * @throws InvalidDataTypeException
930
-     * @throws InvalidInterfaceException
931
-     * @throws ReflectionException
932
-     */
933
-    private function _event_model()
934
-    {
935
-        if (! $this->_event_model instanceof EEM_Event) {
936
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
937
-        }
938
-        return $this->_event_model;
939
-    }
940
-
941
-
942
-    /**
943
-     * Adds extra buttons to the WP CPT permalink field row.
944
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
945
-     *
946
-     * @param string $return    the current html
947
-     * @param int    $id        the post id for the page
948
-     * @param string $new_title What the title is
949
-     * @param string $new_slug  what the slug is
950
-     * @return string            The new html string for the permalink area
951
-     */
952
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
953
-    {
954
-        // make sure this is only when editing
955
-        if (! empty($id)) {
956
-            $post = get_post($id);
957
-            $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
958
-                       . esc_html__('Shortcode', 'event_espresso')
959
-                       . '</a> ';
960
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
961
-                       . $post->ID
962
-                       . ']">';
963
-        }
964
-        return $return;
965
-    }
966
-
967
-
968
-    /**
969
-     * _events_overview_list_table
970
-     * This contains the logic for showing the events_overview list
971
-     *
972
-     * @access protected
973
-     * @return void
974
-     * @throws DomainException
975
-     * @throws EE_Error
976
-     * @throws InvalidArgumentException
977
-     * @throws InvalidDataTypeException
978
-     * @throws InvalidInterfaceException
979
-     */
980
-    protected function _events_overview_list_table()
981
-    {
982
-        $after_list_table                           = [];
983
-        $after_list_table['view_event_list_button'] = EEH_HTML::div(
984
-            EEH_Template::get_button_or_link(
985
-                get_post_type_archive_link('espresso_events'),
986
-                esc_html__('View Event Archive Page', 'event_espresso'),
987
-                'button button--small button--secondary'
988
-            ),
989
-            '',
990
-            'ee-admin-button-row'
991
-        );
992
-
993
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
994
-        $this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
995
-            'create_new',
996
-            'add',
997
-            [],
998
-            'add-new-h2'
999
-        );
1000
-
1001
-        $this->_template_args['after_list_table']   = array_merge(
1002
-            (array) $this->_template_args['after_list_table'],
1003
-            $after_list_table
1004
-        );
1005
-        $this->display_admin_list_table_page_with_no_sidebar();
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * this allows for extra misc actions in the default WP publish box
1011
-     *
1012
-     * @return void
1013
-     * @throws DomainException
1014
-     * @throws EE_Error
1015
-     * @throws InvalidArgumentException
1016
-     * @throws InvalidDataTypeException
1017
-     * @throws InvalidInterfaceException
1018
-     * @throws ReflectionException
1019
-     */
1020
-    public function extra_misc_actions_publish_box()
1021
-    {
1022
-        $this->_generate_publish_box_extra_content();
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1028
-     * saved.
1029
-     * Typically you would use this to save any additional data.
1030
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1031
-     * ALSO very important.  When a post transitions from scheduled to published,
1032
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1033
-     * other meta saves. So MAKE sure that you handle this accordingly.
1034
-     *
1035
-     * @access protected
1036
-     * @abstract
1037
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1038
-     * @param object $post    The post object of the cpt that was saved.
1039
-     * @return void
1040
-     * @throws EE_Error
1041
-     * @throws InvalidArgumentException
1042
-     * @throws InvalidDataTypeException
1043
-     * @throws InvalidInterfaceException
1044
-     * @throws ReflectionException
1045
-     */
1046
-    protected function _insert_update_cpt_item($post_id, $post)
1047
-    {
1048
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1049
-            // get out we're not processing an event save.
1050
-            return;
1051
-        }
1052
-        $event_values = [
1053
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1054
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1055
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1056
-        ];
1057
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1058
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1059
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1060
-                'display_ticket_selector',
1061
-                false,
1062
-                'bool'
1063
-            );
1064
-            $event_values['EVT_additional_limit']            = min(
1065
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1066
-                $this->request->getRequestParam('additional_limit', null, 'int')
1067
-            );
1068
-            $event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1069
-                'EVT_default_registration_status',
1070
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1071
-            );
1072
-
1073
-            $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1074
-            $event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1075
-            $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1076
-        }
1077
-        // update event
1078
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1079
-        // get event_object for other metaboxes...
1080
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1081
-        // i have to setup where conditions to override the filters in the model
1082
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1083
-        $event = $this->_event_model()->get_one(
1084
-            [
1085
-                [
1086
-                    $this->_event_model()->primary_key_name() => $post_id,
1087
-                    'OR'                                      => [
1088
-                        'status'   => $post->post_status,
1089
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1090
-                        // but the returned object here has a status of "publish", so use the original post status as well
1091
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1092
-                    ],
1093
-                ],
1094
-            ]
1095
-        );
1096
-
1097
-        // the following are default callbacks for event attachment updates
1098
-        // that can be overridden by caffeinated functionality and/or addons.
1099
-        $event_update_callbacks = [];
1100
-        if (! $this->admin_config->useAdvancedEditor()) {
1101
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1102
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1103
-        }
1104
-        $event_update_callbacks = apply_filters(
1105
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1106
-            $event_update_callbacks
1107
-        );
1108
-
1109
-        $att_success = true;
1110
-        foreach ($event_update_callbacks as $e_callback) {
1111
-            $_success = is_callable($e_callback)
1112
-                ? $e_callback($event, $this->request->requestParams())
1113
-                : false;
1114
-            // if ANY of these updates fail then we want the appropriate global error message
1115
-            $att_success = $_success !== false ? $att_success : false;
1116
-        }
1117
-        // any errors?
1118
-        if ($success && $att_success === false) {
1119
-            EE_Error::add_error(
1120
-                esc_html__(
1121
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1122
-                    'event_espresso'
1123
-                ),
1124
-                __FILE__,
1125
-                __FUNCTION__,
1126
-                __LINE__
1127
-            );
1128
-        } elseif ($success === false) {
1129
-            EE_Error::add_error(
1130
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1131
-                __FILE__,
1132
-                __FUNCTION__,
1133
-                __LINE__
1134
-            );
1135
-        }
1136
-    }
1137
-
1138
-
1139
-    /**
1140
-     * @param int $post_id
1141
-     * @param int $revision_id
1142
-     * @throws EE_Error
1143
-     * @throws EE_Error
1144
-     * @throws ReflectionException
1145
-     * @see parent::restore_item()
1146
-     */
1147
-    protected function _restore_cpt_item($post_id, $revision_id)
1148
-    {
1149
-        // copy existing event meta to new post
1150
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1151
-        if ($post_evt instanceof EE_Event) {
1152
-            // meta revision restore
1153
-            $post_evt->restore_revision($revision_id);
1154
-            // related objs restore
1155
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1156
-        }
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * Attach the venue to the Event
1162
-     *
1163
-     * @param EE_Event $event Event Object to add the venue to
1164
-     * @param array    $data  The request data from the form
1165
-     * @return bool           Success or fail.
1166
-     * @throws EE_Error
1167
-     * @throws ReflectionException
1168
-     */
1169
-    protected function _default_venue_update(EE_Event $event, $data)
1170
-    {
1171
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1172
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1173
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1174
-        // very important.  If we don't have a venue name...
1175
-        // then we'll get out because not necessary to create empty venue
1176
-        if (empty($data['venue_title'])) {
1177
-            return false;
1178
-        }
1179
-        $venue_array = [
1180
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1181
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1182
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1183
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1184
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1185
-                ? $data['venue_short_description']
1186
-                : null,
1187
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1188
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1189
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1190
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1191
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1192
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1193
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1194
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1195
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1196
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1197
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1198
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1199
-            'status'              => 'publish',
1200
-        ];
1201
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1202
-        if (! empty($venue_id)) {
1203
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1204
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1205
-            // we've gotta make sure that the venue is always attached to a revision..
1206
-            // add_relation_to should take care of making sure that the relation is already present.
1207
-            $event->_add_relation_to($venue_id, 'Venue');
1208
-            return $rows_affected > 0;
1209
-        }
1210
-        // we insert the venue
1211
-        $venue_id = $venue_model->insert($venue_array);
1212
-        $event->_add_relation_to($venue_id, 'Venue');
1213
-        return ! empty($venue_id);
1214
-        // when we have the ancestor come in it's already been handled by the revision save.
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1220
-     *
1221
-     * @param EE_Event $event The Event object we're attaching data to
1222
-     * @param array    $data  The request data from the form
1223
-     * @return array
1224
-     * @throws EE_Error
1225
-     * @throws ReflectionException
1226
-     * @throws Exception
1227
-     */
1228
-    protected function _default_tickets_update(EE_Event $event, $data)
1229
-    {
1230
-        if ($this->admin_config->useAdvancedEditor()) {
1231
-            return [];
1232
-        }
1233
-        $datetime       = null;
1234
-        $saved_tickets  = [];
1235
-        $event_timezone = $event->get_timezone();
1236
-        $date_formats   = ['Y-m-d', 'h:i a'];
1237
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1238
-            // trim all values to ensure any excess whitespace is removed.
1239
-            $datetime_data                = array_map('trim', $datetime_data);
1240
-            $datetime_data['DTT_EVT_end'] =
1241
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1242
-                    ? $datetime_data['DTT_EVT_end']
1243
-                    : $datetime_data['DTT_EVT_start'];
1244
-            $datetime_values              = [
1245
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1246
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1247
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1248
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1249
-                'DTT_order'     => $row,
1250
-            ];
1251
-            // if we have an id then let's get existing object first and then set the new values.
1252
-            //  Otherwise we instantiate a new object for save.
1253
-            if (! empty($datetime_data['DTT_ID'])) {
1254
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1255
-                if (! $datetime instanceof EE_Ticket) {
1256
-                    throw new RuntimeException(
1257
-                        sprintf(
1258
-                            esc_html__(
1259
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1260
-                                'event_espresso'
1261
-                            ),
1262
-                            $datetime_data['DTT_ID']
1263
-                        )
1264
-                    );
1265
-                }
1266
-                $datetime->set_date_format($date_formats[0]);
1267
-                $datetime->set_time_format($date_formats[1]);
1268
-                foreach ($datetime_values as $field => $value) {
1269
-                    $datetime->set($field, $value);
1270
-                }
1271
-            } else {
1272
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1273
-            }
1274
-            if (! $datetime instanceof EE_Datetime) {
1275
-                throw new RuntimeException(
1276
-                    sprintf(
1277
-                        esc_html__(
1278
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1279
-                            'event_espresso'
1280
-                        ),
1281
-                        print_r($datetime_values, true)
1282
-                    )
1283
-                );
1284
-            }
1285
-            // before going any further make sure our dates are setup correctly
1286
-            // so that the end date is always equal or greater than the start date.
1287
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1288
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1289
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1290
-            }
1291
-            $datetime->save();
1292
-            $event->_add_relation_to($datetime, 'Datetime');
1293
-        }
1294
-        // no datetimes get deleted so we don't do any of that logic here.
1295
-        // update tickets next
1296
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1297
-
1298
-        // set up some default start and end dates in case those are not present in the incoming data
1299
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1300
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1301
-        // use the start date of the first datetime for the end date
1302
-        $first_datetime   = $event->first_datetime();
1303
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1304
-
1305
-        // now process the incoming data
1306
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1307
-            $update_prices = false;
1308
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1309
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1310
-                : 0;
1311
-            // trim inputs to ensure any excess whitespace is removed.
1312
-            $ticket_data   = array_map('trim', $ticket_data);
1313
-            $ticket_values = [
1314
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1315
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1316
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1317
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1318
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1319
-                    ? $ticket_data['TKT_start_date']
1320
-                    : $default_start_date,
1321
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1322
-                    ? $ticket_data['TKT_end_date']
1323
-                    : $default_end_date,
1324
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1325
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1326
-                    ? $ticket_data['TKT_qty']
1327
-                    : EE_INF,
1328
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1329
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1330
-                    ? $ticket_data['TKT_uses']
1331
-                    : EE_INF,
1332
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1333
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1334
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1335
-                'TKT_price'       => $ticket_price,
1336
-                'TKT_row'         => $row,
1337
-            ];
1338
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1339
-            // which means in turn that the prices will become new prices as well.
1340
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1341
-                $ticket_values['TKT_ID']         = 0;
1342
-                $ticket_values['TKT_is_default'] = 0;
1343
-                $update_prices                   = true;
1344
-            }
1345
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1346
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1347
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1348
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1349
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1350
-            if (! empty($ticket_data['TKT_ID'])) {
1351
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1352
-                if (! $existing_ticket instanceof EE_Ticket) {
1353
-                    throw new RuntimeException(
1354
-                        sprintf(
1355
-                            esc_html__(
1356
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1357
-                                'event_espresso'
1358
-                            ),
1359
-                            $ticket_data['TKT_ID']
1360
-                        )
1361
-                    );
1362
-                }
1363
-                $ticket_sold = $existing_ticket->count_related(
1364
-                    'Registration',
1365
-                    [
1366
-                            [
1367
-                                'STS_ID' => [
1368
-                                    'NOT IN',
1369
-                                    [EEM_Registration::status_id_incomplete],
1370
-                                ],
1371
-                            ],
1372
-                        ]
1373
-                ) > 0;
1374
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1375
-                // if they are different then we create a new ticket (if $ticket_sold)
1376
-                // if they aren't different then we go ahead and modify existing ticket.
1377
-                $create_new_ticket = $ticket_sold
1378
-                                     && $ticket_price !== $existing_ticket->price()
1379
-                                     && ! $existing_ticket->deleted();
1380
-                $existing_ticket->set_date_format($date_formats[0]);
1381
-                $existing_ticket->set_time_format($date_formats[1]);
1382
-                // set new values
1383
-                foreach ($ticket_values as $field => $value) {
1384
-                    if ($field == 'TKT_qty') {
1385
-                        $existing_ticket->set_qty($value);
1386
-                    } elseif ($field == 'TKT_price') {
1387
-                        $existing_ticket->set('TKT_price', $ticket_price);
1388
-                    } else {
1389
-                        $existing_ticket->set($field, $value);
1390
-                    }
1391
-                }
1392
-                $ticket = $existing_ticket;
1393
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1394
-                //  Otherwise we have to create a new ticket.
1395
-                if ($create_new_ticket) {
1396
-                    // archive the old ticket first
1397
-                    $existing_ticket->set('TKT_deleted', 1);
1398
-                    $existing_ticket->save();
1399
-                    // make sure this ticket is still recorded in our $saved_tickets
1400
-                    // so we don't run it through the regular trash routine.
1401
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1402
-                    // create new ticket that's a copy of the existing except,
1403
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1404
-                    $new_ticket = clone $existing_ticket;
1405
-                    $new_ticket->set('TKT_ID', 0);
1406
-                    $new_ticket->set('TKT_deleted', 0);
1407
-                    $new_ticket->set('TKT_sold', 0);
1408
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1409
-                    $update_prices = true;
1410
-                    $ticket        = $new_ticket;
1411
-                }
1412
-            } else {
1413
-                // no TKT_id so a new ticket
1414
-                $ticket_values['TKT_price'] = $ticket_price;
1415
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1416
-                $update_prices              = true;
1417
-            }
1418
-            if (! $ticket instanceof EE_Ticket) {
1419
-                throw new RuntimeException(
1420
-                    sprintf(
1421
-                        esc_html__(
1422
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1423
-                            'event_espresso'
1424
-                        ),
1425
-                        print_r($ticket_values, true)
1426
-                    )
1427
-                );
1428
-            }
1429
-            // cap ticket qty by datetime reg limits
1430
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1431
-            // update ticket.
1432
-            $ticket->save();
1433
-            // before going any further make sure our dates are setup correctly
1434
-            // so that the end date is always equal or greater than the start date.
1435
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1436
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1437
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1438
-                $ticket->save();
1439
-            }
1440
-            // initially let's add the ticket to the datetime
1441
-            $datetime->_add_relation_to($ticket, 'Ticket');
1442
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1443
-            // add prices to ticket
1444
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1445
-        }
1446
-        // however now we need to handle permanently deleting tickets via the ui.
1447
-        //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1448
-        //  However, it does allow for deleting tickets that have no tickets sold,
1449
-        // in which case we want to get rid of permanently because there is no need to save in db.
1450
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1451
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1452
-        foreach ($tickets_removed as $id) {
1453
-            $id = absint($id);
1454
-            // get the ticket for this id
1455
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1456
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1457
-                continue;
1458
-            }
1459
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1460
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1461
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1462
-            foreach ($related_datetimes as $related_datetime) {
1463
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1464
-            }
1465
-            // need to do the same for prices (except these prices can also be deleted because again,
1466
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1467
-            $ticket_to_remove->delete_related_permanently('Price');
1468
-            // finally let's delete this ticket
1469
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1470
-            $ticket_to_remove->delete_permanently();
1471
-        }
1472
-        return [$datetime, $saved_tickets];
1473
-    }
1474
-
1475
-
1476
-    /**
1477
-     * This attaches a list of given prices to a ticket.
1478
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1479
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1480
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1481
-     *
1482
-     * @access  private
1483
-     * @param array     $prices_data Array of prices from the form.
1484
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1485
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1486
-     * @return  void
1487
-     * @throws EE_Error
1488
-     * @throws ReflectionException
1489
-     */
1490
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1491
-    {
1492
-        $timezone = $ticket->get_timezone();
1493
-        foreach ($prices_data as $row => $price_data) {
1494
-            $price_values = [
1495
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1496
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1497
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1498
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1499
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1500
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1501
-                'PRC_order'      => $row,
1502
-            ];
1503
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1504
-                $price_values['PRC_ID'] = 0;
1505
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1506
-            } else {
1507
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1508
-                // update this price with new values
1509
-                foreach ($price_values as $field => $new_price) {
1510
-                    $price->set($field, $new_price);
1511
-                }
1512
-            }
1513
-            if (! $price instanceof EE_Price) {
1514
-                throw new RuntimeException(
1515
-                    sprintf(
1516
-                        esc_html__(
1517
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1518
-                            'event_espresso'
1519
-                        ),
1520
-                        print_r($price_values, true)
1521
-                    )
1522
-                );
1523
-            }
1524
-            $price->save();
1525
-            $ticket->_add_relation_to($price, 'Price');
1526
-        }
1527
-    }
1528
-
1529
-
1530
-    /**
1531
-     * Add in our autosave ajax handlers
1532
-     *
1533
-     */
1534
-    protected function _ee_autosave_create_new()
1535
-    {
1536
-    }
1537
-
1538
-
1539
-    /**
1540
-     * More autosave handlers.
1541
-     */
1542
-    protected function _ee_autosave_edit()
1543
-    {
1544
-    }
1545
-
1546
-
1547
-    /**
1548
-     * @throws EE_Error
1549
-     * @throws ReflectionException
1550
-     */
1551
-    private function _generate_publish_box_extra_content()
1552
-    {
1553
-        // load formatter helper
1554
-        // args for getting related registrations
1555
-        $approved_query_args        = [
1556
-            [
1557
-                'REG_deleted' => 0,
1558
-                'STS_ID'      => EEM_Registration::status_id_approved,
1559
-            ],
1560
-        ];
1561
-        $not_approved_query_args    = [
1562
-            [
1563
-                'REG_deleted' => 0,
1564
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1565
-            ],
1566
-        ];
1567
-        $pending_payment_query_args = [
1568
-            [
1569
-                'REG_deleted' => 0,
1570
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1571
-            ],
1572
-        ];
1573
-        // publish box
1574
-        $publish_box_extra_args = [
1575
-            'view_approved_reg_url'        => add_query_arg(
1576
-                [
1577
-                    'action'      => 'default',
1578
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1579
-                    '_reg_status' => EEM_Registration::status_id_approved,
1580
-                ],
1581
-                REG_ADMIN_URL
1582
-            ),
1583
-            'view_not_approved_reg_url'    => add_query_arg(
1584
-                [
1585
-                    'action'      => 'default',
1586
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1587
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
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
-                ],
1597
-                REG_ADMIN_URL
1598
-            ),
1599
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1600
-                'Registration',
1601
-                $approved_query_args
1602
-            ),
1603
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1604
-                'Registration',
1605
-                $not_approved_query_args
1606
-            ),
1607
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1608
-                'Registration',
1609
-                $pending_payment_query_args
1610
-            ),
1611
-            'misc_pub_section_class'       => apply_filters(
1612
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1613
-                'misc-pub-section'
1614
-            ),
1615
-        ];
1616
-        ob_start();
1617
-        do_action(
1618
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1619
-            $this->_cpt_model_obj
1620
-        );
1621
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1622
-        // load template
1623
-        EEH_Template::display_template(
1624
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1625
-            $publish_box_extra_args
1626
-        );
1627
-    }
1628
-
1629
-
1630
-    /**
1631
-     * @return EE_Event
1632
-     */
1633
-    public function get_event_object()
1634
-    {
1635
-        return $this->_cpt_model_obj;
1636
-    }
1637
-
1638
-
1639
-
1640
-
1641
-    /** METABOXES * */
1642
-    /**
1643
-     * _register_event_editor_meta_boxes
1644
-     * add all metaboxes related to the event_editor
1645
-     *
1646
-     * @return void
1647
-     * @throws EE_Error
1648
-     * @throws ReflectionException
1649
-     */
1650
-    protected function _register_event_editor_meta_boxes()
1651
-    {
1652
-        $this->verify_cpt_object();
1653
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1654
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1655
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1656
-            $this->addMetaBox(
1657
-                'espresso_event_editor_event_options',
1658
-                esc_html__('Event Registration Options', 'event_espresso'),
1659
-                [$this, 'registration_options_meta_box'],
1660
-                $this->page_slug,
1661
-                'side'
1662
-            );
1663
-        }
1664
-        if (! $use_advanced_editor) {
1665
-            $this->addMetaBox(
1666
-                'espresso_event_editor_tickets',
1667
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1668
-                [$this, 'ticket_metabox'],
1669
-                $this->page_slug,
1670
-                'normal',
1671
-                'high'
1672
-            );
1673
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1674
-            add_action(
1675
-                'add_meta_boxes_espresso_events',
1676
-                function () {
1677
-                    global $current_screen;
1678
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1679
-                },
1680
-                99
1681
-            );
1682
-        }
1683
-        // NOTE: if you're looking for other metaboxes in here,
1684
-        // where a metabox has a related management page in the admin
1685
-        // you will find it setup in the related management page's "_Hooks" file.
1686
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1687
-    }
1688
-
1689
-
1690
-    /**
1691
-     * @throws DomainException
1692
-     * @throws EE_Error
1693
-     * @throws ReflectionException
1694
-     */
1695
-    public function ticket_metabox()
1696
-    {
1697
-        $existing_datetime_ids = $existing_ticket_ids = [];
1698
-        // defaults for template args
1699
-        $template_args = [
1700
-            'existing_datetime_ids'    => '',
1701
-            'event_datetime_help_link' => '',
1702
-            'ticket_options_help_link' => '',
1703
-            'time'                     => null,
1704
-            'ticket_rows'              => '',
1705
-            'existing_ticket_ids'      => '',
1706
-            'total_ticket_rows'        => 1,
1707
-            'ticket_js_structure'      => '',
1708
-            'trash_icon'               => 'dashicons dashicons-lock',
1709
-            'disabled'                 => '',
1710
-        ];
1711
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1712
-        /**
1713
-         * 1. Start with retrieving Datetimes
1714
-         * 2. Fore each datetime get related tickets
1715
-         * 3. For each ticket get related prices
1716
-         */
1717
-        /** @var EEM_Datetime $datetime_model */
1718
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1719
-        /** @var EEM_Ticket $datetime_model */
1720
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1721
-        $times        = $datetime_model->get_all_event_dates($event_id);
1722
-        /** @type EE_Datetime $first_datetime */
1723
-        $first_datetime = reset($times);
1724
-        // do we get related tickets?
1725
-        if (
1726
-            $first_datetime instanceof EE_Datetime
1727
-            && $first_datetime->ID() !== 0
1728
-        ) {
1729
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1730
-            $template_args['time']   = $first_datetime;
1731
-            $related_tickets         = $first_datetime->tickets(
1732
-                [
1733
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1734
-                    'default_where_conditions' => 'none',
1735
-                ]
1736
-            );
1737
-            if (! empty($related_tickets)) {
1738
-                $template_args['total_ticket_rows'] = count($related_tickets);
1739
-                $row                                = 0;
1740
-                foreach ($related_tickets as $ticket) {
1741
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1742
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1743
-                    $row++;
1744
-                }
1745
-            } else {
1746
-                $template_args['total_ticket_rows'] = 1;
1747
-                /** @type EE_Ticket $ticket */
1748
-                $ticket                       = $ticket_model->create_default_object();
1749
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1750
-            }
1751
-        } else {
1752
-            $template_args['time'] = $times[0];
1753
-            /** @type EE_Ticket[] $tickets */
1754
-            $tickets                      = $ticket_model->get_all_default_tickets();
1755
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1756
-            // NOTE: we're just sending the first default row
1757
-            // (decaf can't manage default tickets so this should be sufficient);
1758
-        }
1759
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1760
-            'event_editor_event_datetimes_help_tab'
1761
-        );
1762
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1763
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1764
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1765
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1766
-            $ticket_model->create_default_object(),
1767
-            true
1768
-        );
1769
-        $template                                  = apply_filters(
1770
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1771
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1772
-        );
1773
-        EEH_Template::display_template($template, $template_args);
1774
-    }
1775
-
1776
-
1777
-    /**
1778
-     * Setup an individual ticket form for the decaf event editor page
1779
-     *
1780
-     * @access private
1781
-     * @param EE_Ticket $ticket   the ticket object
1782
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1783
-     * @param int       $row
1784
-     * @return string generated html for the ticket row.
1785
-     * @throws EE_Error
1786
-     * @throws ReflectionException
1787
-     */
1788
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1789
-    {
1790
-        $template_args = [
1791
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1792
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1793
-                : '',
1794
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1795
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1796
-            'TKT_name'            => $ticket->get('TKT_name'),
1797
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1798
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1799
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1800
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1801
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1802
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1803
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1804
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1805
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1806
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1807
-                : ' disabled=disabled',
1808
-        ];
1809
-        $price         = $ticket->ID() !== 0
1810
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1811
-            : null;
1812
-        $price         = $price instanceof EE_Price
1813
-            ? $price
1814
-            : EEM_Price::instance()->create_default_object();
1815
-        $price_args    = [
1816
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1817
-            'PRC_amount'            => $price->get('PRC_amount'),
1818
-            'PRT_ID'                => $price->get('PRT_ID'),
1819
-            'PRC_ID'                => $price->get('PRC_ID'),
1820
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1821
-        ];
1822
-        // make sure we have default start and end dates if skeleton
1823
-        // handle rows that should NOT be empty
1824
-        if (empty($template_args['TKT_start_date'])) {
1825
-            // if empty then the start date will be now.
1826
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1827
-        }
1828
-        if (empty($template_args['TKT_end_date'])) {
1829
-            // get the earliest datetime (if present);
1830
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1831
-                ? $this->_cpt_model_obj->get_first_related(
1832
-                    'Datetime',
1833
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1834
-                )
1835
-                : null;
1836
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1837
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1838
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1839
-        }
1840
-        $template_args = array_merge($template_args, $price_args);
1841
-        $template      = apply_filters(
1842
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1843
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1844
-            $ticket
1845
-        );
1846
-        return EEH_Template::display_template($template, $template_args, true);
1847
-    }
1848
-
1849
-
1850
-    /**
1851
-     * @throws EE_Error
1852
-     * @throws ReflectionException
1853
-     */
1854
-    public function registration_options_meta_box()
1855
-    {
1856
-        $yes_no_values             = [
1857
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1858
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1859
-        ];
1860
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1861
-            [
1862
-                EEM_Registration::status_id_cancelled,
1863
-                EEM_Registration::status_id_declined,
1864
-                EEM_Registration::status_id_incomplete,
1865
-            ],
1866
-            true
1867
-        );
1868
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1869
-        $template_args['_event']                          = $this->_cpt_model_obj;
1870
-        $template_args['event']                           = $this->_cpt_model_obj;
1871
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1872
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1873
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1874
-            'default_reg_status',
1875
-            $default_reg_status_values,
1876
-            $this->_cpt_model_obj->default_registration_status()
1877
-        );
1878
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1879
-            'display_desc',
1880
-            $yes_no_values,
1881
-            $this->_cpt_model_obj->display_description()
1882
-        );
1883
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1884
-            'display_ticket_selector',
1885
-            $yes_no_values,
1886
-            $this->_cpt_model_obj->display_ticket_selector(),
1887
-            '',
1888
-            '',
1889
-            false
1890
-        );
1891
-        $template_args['additional_registration_options'] = apply_filters(
1892
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1893
-            '',
1894
-            $template_args,
1895
-            $yes_no_values,
1896
-            $default_reg_status_values
1897
-        );
1898
-        EEH_Template::display_template(
1899
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1900
-            $template_args
1901
-        );
1902
-    }
1903
-
1904
-
1905
-    /**
1906
-     * _get_events()
1907
-     * This method simply returns all the events (for the given _view and paging)
1908
-     *
1909
-     * @access public
1910
-     * @param int  $per_page     count of items per page (20 default);
1911
-     * @param int  $current_page what is the current page being viewed.
1912
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1913
-     *                           If FALSE then we return an array of event objects
1914
-     *                           that match the given _view and paging parameters.
1915
-     * @return array|int         an array of event objects or a count of them.
1916
-     * @throws Exception
1917
-     */
1918
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1919
-    {
1920
-        $EEM_Event   = $this->_event_model();
1921
-        $offset      = ($current_page - 1) * $per_page;
1922
-        $limit       = $count ? null : $offset . ',' . $per_page;
1923
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1924
-        $order       = $this->request->getRequestParam('order', 'DESC');
1925
-        $month_range = $this->request->getRequestParam('month_range');
1926
-        if ($month_range) {
1927
-            $pieces = explode(' ', $month_range, 3);
1928
-            // simulate the FIRST day of the month, that fixes issues for months like February
1929
-            // where PHP doesn't know what to assume for date.
1930
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1931
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1932
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1933
-        }
1934
-        $where  = [];
1935
-        $status = $this->request->getRequestParam('status');
1936
-        // determine what post_status our condition will have for the query.
1937
-        switch ($status) {
1938
-            case 'month':
1939
-            case 'today':
1940
-            case null:
1941
-            case 'all':
1942
-                break;
1943
-            case 'draft':
1944
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1945
-                break;
1946
-            default:
1947
-                $where['status'] = $status;
1948
-        }
1949
-        // categories? The default for all categories is -1
1950
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1951
-        if ($category !== -1) {
1952
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1953
-            $where['Term_Taxonomy.term_id']  = $category;
1954
-        }
1955
-        // date where conditions
1956
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1957
-        if ($month_range) {
1958
-            $DateTime = new DateTime(
1959
-                $year_r . '-' . $month_r . '-01 00:00:00',
1960
-                new DateTimeZone('UTC')
1961
-            );
1962
-            $start    = $DateTime->getTimestamp();
1963
-            // set the datetime to be the end of the month
1964
-            $DateTime->setDate(
1965
-                $year_r,
1966
-                $month_r,
1967
-                $DateTime->format('t')
1968
-            )->setTime(23, 59, 59);
1969
-            $end                             = $DateTime->getTimestamp();
1970
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1971
-        } elseif ($status === 'today') {
1972
-            $DateTime                        =
1973
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1974
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1975
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1976
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1977
-        } elseif ($status === 'month') {
1978
-            $now                             = date('Y-m-01');
1979
-            $DateTime                        =
1980
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1981
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1982
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1983
-                                                        ->setTime(23, 59, 59)
1984
-                                                        ->format(implode(' ', $start_formats));
1985
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
-        }
1987
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1988
-            $where['EVT_wp_user'] = get_current_user_id();
1989
-        } else {
1990
-            if (! isset($where['status'])) {
1991
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1992
-                    $where['OR'] = [
1993
-                        'status*restrict_private' => ['!=', 'private'],
1994
-                        'AND'                     => [
1995
-                            'status*inclusive' => ['=', 'private'],
1996
-                            'EVT_wp_user'      => get_current_user_id(),
1997
-                        ],
1998
-                    ];
1999
-                }
2000
-            }
2001
-        }
2002
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
2003
-        if (
2004
-            $wp_user
2005
-            && $wp_user !== get_current_user_id()
2006
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2007
-        ) {
2008
-            $where['EVT_wp_user'] = $wp_user;
2009
-        }
2010
-        // search query handling
2011
-        $search_term = $this->request->getRequestParam('s');
2012
-        if ($search_term) {
2013
-            $search_term = '%' . $search_term . '%';
2014
-            $where['OR'] = [
2015
-                'EVT_name'       => ['LIKE', $search_term],
2016
-                'EVT_desc'       => ['LIKE', $search_term],
2017
-                'EVT_short_desc' => ['LIKE', $search_term],
2018
-            ];
2019
-        }
2020
-        // filter events by venue.
2021
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
2022
-        if ($venue) {
2023
-            $where['Venue.VNU_ID'] = $venue;
2024
-        }
2025
-        $request_params = $this->request->requestParams();
2026
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2027
-        $query_params   = apply_filters(
2028
-            'FHEE__Events_Admin_Page__get_events__query_params',
2029
-            [
2030
-                $where,
2031
-                'limit'    => $limit,
2032
-                'order_by' => $orderby,
2033
-                'order'    => $order,
2034
-                'group_by' => 'EVT_ID',
2035
-            ],
2036
-            $request_params
2037
-        );
2038
-
2039
-        // let's first check if we have special requests coming in.
2040
-        $active_status = $this->request->getRequestParam('active_status');
2041
-        if ($active_status) {
2042
-            switch ($active_status) {
2043
-                case 'upcoming':
2044
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
2045
-                case 'expired':
2046
-                    return $EEM_Event->get_expired_events($query_params, $count);
2047
-                case 'active':
2048
-                    return $EEM_Event->get_active_events($query_params, $count);
2049
-                case 'inactive':
2050
-                    return $EEM_Event->get_inactive_events($query_params, $count);
2051
-            }
2052
-        }
2053
-
2054
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2055
-    }
2056
-
2057
-
2058
-    /**
2059
-     * handling for WordPress CPT actions (trash, restore, delete)
2060
-     *
2061
-     * @param string $post_id
2062
-     * @throws EE_Error
2063
-     * @throws ReflectionException
2064
-     */
2065
-    public function trash_cpt_item($post_id)
2066
-    {
2067
-        $this->request->setRequestParam('EVT_ID', $post_id);
2068
-        $this->_trash_or_restore_event('trash', false);
2069
-    }
2070
-
2071
-
2072
-    /**
2073
-     * @param string $post_id
2074
-     * @throws EE_Error
2075
-     * @throws ReflectionException
2076
-     */
2077
-    public function restore_cpt_item($post_id)
2078
-    {
2079
-        $this->request->setRequestParam('EVT_ID', $post_id);
2080
-        $this->_trash_or_restore_event('draft', false);
2081
-    }
2082
-
2083
-
2084
-    /**
2085
-     * @param string $post_id
2086
-     * @throws EE_Error
2087
-     * @throws EE_Error
2088
-     */
2089
-    public function delete_cpt_item($post_id)
2090
-    {
2091
-        throw new EE_Error(
2092
-            esc_html__(
2093
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2094
-                'event_espresso'
2095
-            )
2096
-        );
2097
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2098
-        // $this->_delete_event();
2099
-    }
2100
-
2101
-
2102
-    /**
2103
-     * _trash_or_restore_event
2104
-     *
2105
-     * @access protected
2106
-     * @param string $event_status
2107
-     * @param bool   $redirect_after
2108
-     * @throws EE_Error
2109
-     * @throws EE_Error
2110
-     * @throws ReflectionException
2111
-     */
2112
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2113
-    {
2114
-        // determine the event id and set to array.
2115
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2116
-        // loop thru events
2117
-        if ($EVT_ID) {
2118
-            // clean status
2119
-            $event_status = sanitize_key($event_status);
2120
-            // grab status
2121
-            if (! empty($event_status)) {
2122
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2123
-            } else {
2124
-                $success = false;
2125
-                $msg     = esc_html__(
2126
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2127
-                    'event_espresso'
2128
-                );
2129
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2130
-            }
2131
-        } else {
2132
-            $success = false;
2133
-            $msg     = esc_html__(
2134
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2135
-                'event_espresso'
2136
-            );
2137
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2138
-        }
2139
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2140
-        if ($redirect_after) {
2141
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2142
-        }
2143
-    }
2144
-
2145
-
2146
-    /**
2147
-     * _trash_or_restore_events
2148
-     *
2149
-     * @access protected
2150
-     * @param string $event_status
2151
-     * @return void
2152
-     * @throws EE_Error
2153
-     * @throws EE_Error
2154
-     * @throws ReflectionException
2155
-     */
2156
-    protected function _trash_or_restore_events($event_status = 'trash')
2157
-    {
2158
-        // clean status
2159
-        $event_status = sanitize_key($event_status);
2160
-        // grab status
2161
-        if (! empty($event_status)) {
2162
-            $success = true;
2163
-            // determine the event id and set to array.
2164
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2165
-            // loop thru events
2166
-            foreach ($EVT_IDs as $EVT_ID) {
2167
-                if ($EVT_ID = absint($EVT_ID)) {
2168
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2169
-                    $success = $results !== false ? $success : false;
2170
-                } else {
2171
-                    $msg = sprintf(
2172
-                        esc_html__(
2173
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2174
-                            'event_espresso'
2175
-                        ),
2176
-                        $EVT_ID
2177
-                    );
2178
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2179
-                    $success = false;
2180
-                }
2181
-            }
2182
-        } else {
2183
-            $success = false;
2184
-            $msg     = esc_html__(
2185
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2186
-                'event_espresso'
2187
-            );
2188
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2189
-        }
2190
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2191
-        $success = $success ? 2 : false;
2192
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2193
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2194
-    }
2195
-
2196
-
2197
-    /**
2198
-     * @param int    $EVT_ID
2199
-     * @param string $event_status
2200
-     * @return bool
2201
-     * @throws EE_Error
2202
-     * @throws ReflectionException
2203
-     */
2204
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2205
-    {
2206
-        // grab event id
2207
-        if (! $EVT_ID) {
2208
-            $msg = esc_html__(
2209
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2210
-                'event_espresso'
2211
-            );
2212
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2213
-            return false;
2214
-        }
2215
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2216
-        // clean status
2217
-        $event_status = sanitize_key($event_status);
2218
-        // grab status
2219
-        if (empty($event_status)) {
2220
-            $msg = esc_html__(
2221
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2222
-                'event_espresso'
2223
-            );
2224
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2225
-            return false;
2226
-        }
2227
-        // was event trashed or restored ?
2228
-        switch ($event_status) {
2229
-            case 'draft':
2230
-                $action = 'restored from the trash';
2231
-                $hook   = 'AHEE_event_restored_from_trash';
2232
-                break;
2233
-            case 'trash':
2234
-                $action = 'moved to the trash';
2235
-                $hook   = 'AHEE_event_moved_to_trash';
2236
-                break;
2237
-            default:
2238
-                $action = 'updated';
2239
-                $hook   = false;
2240
-        }
2241
-        // use class to change status
2242
-        $this->_cpt_model_obj->set_status($event_status);
2243
-        $success = $this->_cpt_model_obj->save();
2244
-        if (! $success) {
2245
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2246
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2247
-            return false;
2248
-        }
2249
-        if ($hook) {
2250
-            do_action($hook);
2251
-        }
2252
-        return true;
2253
-    }
2254
-
2255
-
2256
-    /**
2257
-     * @param array $event_ids
2258
-     * @return array
2259
-     * @since   4.10.23.p
2260
-     */
2261
-    private function cleanEventIds(array $event_ids)
2262
-    {
2263
-        return array_map('absint', $event_ids);
2264
-    }
2265
-
2266
-
2267
-    /**
2268
-     * @return array
2269
-     * @since   4.10.23.p
2270
-     */
2271
-    private function getEventIdsFromRequest()
2272
-    {
2273
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2274
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2275
-        } else {
2276
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2277
-        }
2278
-    }
2279
-
2280
-
2281
-    /**
2282
-     * @param bool $preview_delete
2283
-     * @throws EE_Error
2284
-     */
2285
-    protected function _delete_event($preview_delete = true)
2286
-    {
2287
-        $this->_delete_events($preview_delete);
2288
-    }
2289
-
2290
-
2291
-    /**
2292
-     * Gets the tree traversal batch persister.
2293
-     *
2294
-     * @return NodeGroupDao
2295
-     * @throws InvalidArgumentException
2296
-     * @throws InvalidDataTypeException
2297
-     * @throws InvalidInterfaceException
2298
-     * @since 4.10.12.p
2299
-     */
2300
-    protected function getModelObjNodeGroupPersister()
2301
-    {
2302
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2303
-            $this->model_obj_node_group_persister =
2304
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2305
-        }
2306
-        return $this->model_obj_node_group_persister;
2307
-    }
2308
-
2309
-
2310
-    /**
2311
-     * @param bool $preview_delete
2312
-     * @return void
2313
-     * @throws EE_Error
2314
-     */
2315
-    protected function _delete_events($preview_delete = true)
2316
-    {
2317
-        $event_ids = $this->getEventIdsFromRequest();
2318
-        if ($preview_delete) {
2319
-            $this->generateDeletionPreview($event_ids);
2320
-        } else {
2321
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2322
-        }
2323
-    }
2324
-
2325
-
2326
-    /**
2327
-     * @param array $event_ids
2328
-     */
2329
-    protected function generateDeletionPreview(array $event_ids)
2330
-    {
2331
-        $event_ids = $this->cleanEventIds($event_ids);
2332
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2333
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2334
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2335
-            [
2336
-                'action'            => 'preview_deletion',
2337
-                'deletion_job_code' => $deletion_job_code,
2338
-            ],
2339
-            $this->_admin_base_url
2340
-        );
2341
-        EEH_URL::safeRedirectAndExit(
2342
-            EE_Admin_Page::add_query_args_and_nonce(
2343
-                [
2344
-                    'page'              => 'espresso_batch',
2345
-                    'batch'             => EED_Batch::batch_job,
2346
-                    'EVT_IDs'           => $event_ids,
2347
-                    'deletion_job_code' => $deletion_job_code,
2348
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2349
-                    'return_url'        => urlencode($return_url),
2350
-                ],
2351
-                admin_url()
2352
-            )
2353
-        );
2354
-    }
2355
-
2356
-
2357
-    /**
2358
-     * Checks for a POST submission
2359
-     *
2360
-     * @since 4.10.12.p
2361
-     */
2362
-    protected function confirmDeletion()
2363
-    {
2364
-        $deletion_redirect_logic =
2365
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2366
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2367
-    }
2368
-
2369
-
2370
-    /**
2371
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2372
-     *
2373
-     * @throws EE_Error
2374
-     * @since 4.10.12.p
2375
-     */
2376
-    protected function previewDeletion()
2377
-    {
2378
-        $preview_deletion_logic =
2379
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2380
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2381
-        $this->display_admin_page_with_no_sidebar();
2382
-    }
2383
-
2384
-
2385
-    /**
2386
-     * get total number of events
2387
-     *
2388
-     * @access public
2389
-     * @return int
2390
-     * @throws EE_Error
2391
-     * @throws EE_Error
2392
-     */
2393
-    public function total_events()
2394
-    {
2395
-        return EEM_Event::instance()->count(
2396
-            ['caps' => 'read_admin'],
2397
-            'EVT_ID',
2398
-            true
2399
-        );
2400
-    }
2401
-
2402
-
2403
-    /**
2404
-     * get total number of draft events
2405
-     *
2406
-     * @access public
2407
-     * @return int
2408
-     * @throws EE_Error
2409
-     * @throws EE_Error
2410
-     */
2411
-    public function total_events_draft()
2412
-    {
2413
-        return EEM_Event::instance()->count(
2414
-            [
2415
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2416
-                'caps' => 'read_admin',
2417
-            ],
2418
-            'EVT_ID',
2419
-            true
2420
-        );
2421
-    }
2422
-
2423
-
2424
-    /**
2425
-     * get total number of trashed events
2426
-     *
2427
-     * @access public
2428
-     * @return int
2429
-     * @throws EE_Error
2430
-     * @throws EE_Error
2431
-     */
2432
-    public function total_trashed_events()
2433
-    {
2434
-        return EEM_Event::instance()->count(
2435
-            [
2436
-                ['status' => 'trash'],
2437
-                'caps' => 'read_admin',
2438
-            ],
2439
-            'EVT_ID',
2440
-            true
2441
-        );
2442
-    }
2443
-
2444
-
2445
-    /**
2446
-     *    _default_event_settings
2447
-     *    This generates the Default Settings Tab
2448
-     *
2449
-     * @return void
2450
-     * @throws DomainException
2451
-     * @throws EE_Error
2452
-     * @throws InvalidArgumentException
2453
-     * @throws InvalidDataTypeException
2454
-     * @throws InvalidInterfaceException
2455
-     */
2456
-    protected function _default_event_settings()
2457
-    {
2458
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2459
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2460
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
2461
-            $this->_default_event_settings_form()->get_html(),
2462
-            '',
2463
-            'padding'
2464
-        );
2465
-        $this->display_admin_page_with_sidebar();
2466
-    }
2467
-
2468
-
2469
-    /**
2470
-     * Return the form for event settings.
2471
-     *
2472
-     * @return EE_Form_Section_Proper
2473
-     * @throws EE_Error
2474
-     */
2475
-    protected function _default_event_settings_form()
2476
-    {
2477
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2478
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2479
-        // exclude
2480
-            [
2481
-                EEM_Registration::status_id_cancelled,
2482
-                EEM_Registration::status_id_declined,
2483
-                EEM_Registration::status_id_incomplete,
2484
-                EEM_Registration::status_id_wait_list,
2485
-            ],
2486
-            true
2487
-        );
2488
-        return new EE_Form_Section_Proper(
2489
-            [
2490
-                'name'            => 'update_default_event_settings',
2491
-                'html_id'         => 'update_default_event_settings',
2492
-                'html_class'      => 'form-table',
2493
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2494
-                'subsections'     => apply_filters(
2495
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2496
-                    [
2497
-                        'defaults_section_header' => new EE_Form_Section_HTML(
2498
-                            EEH_HTML::h2(
2499
-                                esc_html__('Default Settings', 'event_espresso'),
2500
-                                '',
2501
-                                'ee-admin-settings-hdr'
2502
-                            )
2503
-                        ),
2504
-                        'default_reg_status'  => new EE_Select_Input(
2505
-                            $registration_stati_for_selection,
2506
-                            [
2507
-                                'default'         => isset($registration_config->default_STS_ID)
2508
-                                                     && array_key_exists(
2509
-                                                         $registration_config->default_STS_ID,
2510
-                                                         $registration_stati_for_selection
2511
-                                                     )
2512
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2513
-                                    : EEM_Registration::status_id_pending_payment,
2514
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2515
-                                                     . EEH_Template::get_help_tab_link(
2516
-                                                         'default_settings_status_help_tab'
2517
-                                                     ),
2518
-                                'html_help_text'  => esc_html__(
2519
-                                    '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.',
2520
-                                    'event_espresso'
2521
-                                ),
2522
-                            ]
2523
-                        ),
2524
-                        'default_max_tickets' => new EE_Integer_Input(
2525
-                            [
2526
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2527
-                                    ? $registration_config->default_maximum_number_of_tickets
2528
-                                    : EEM_Event::get_default_additional_limit(),
2529
-                                'html_label_text' => esc_html__(
2530
-                                    'Default Maximum Tickets Allowed Per Order:',
2531
-                                    'event_espresso'
2532
-                                )
2533
-                                                     . EEH_Template::get_help_tab_link(
2534
-                                                         'default_maximum_tickets_help_tab"'
2535
-                                                     ),
2536
-                                'html_help_text'  => esc_html__(
2537
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2538
-                                    'event_espresso'
2539
-                                ),
2540
-                            ]
2541
-                        ),
2542
-                    ]
2543
-                ),
2544
-            ]
2545
-        );
2546
-    }
2547
-
2548
-
2549
-    /**
2550
-     * @return void
2551
-     * @throws EE_Error
2552
-     * @throws InvalidArgumentException
2553
-     * @throws InvalidDataTypeException
2554
-     * @throws InvalidInterfaceException
2555
-     */
2556
-    protected function _update_default_event_settings()
2557
-    {
2558
-        $form = $this->_default_event_settings_form();
2559
-        if ($form->was_submitted()) {
2560
-            $form->receive_form_submission();
2561
-            if ($form->is_valid()) {
2562
-                $registration_config = EE_Registry::instance()->CFG->registration;
2563
-                $valid_data          = $form->valid_data();
2564
-                if (isset($valid_data['default_reg_status'])) {
2565
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2566
-                }
2567
-                if (isset($valid_data['default_max_tickets'])) {
2568
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2569
-                }
2570
-                do_action(
2571
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2572
-                    $valid_data,
2573
-                    EE_Registry::instance()->CFG,
2574
-                    $this
2575
-                );
2576
-                // update because data was valid!
2577
-                EE_Registry::instance()->CFG->update_espresso_config();
2578
-                EE_Error::overwrite_success();
2579
-                EE_Error::add_success(
2580
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2581
-                );
2582
-            }
2583
-        }
2584
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2585
-    }
2586
-
2587
-
2588
-    /*************        Templates        *************
2589
-     *
2590
-     * @throws EE_Error
2591
-     */
2592
-    protected function _template_settings()
2593
-    {
2594
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2595
-        $this->_template_args['preview_img']  = '<img src="'
2596
-                                                . EVENTS_ASSETS_URL
2597
-                                                . '/images/'
2598
-                                                . 'caffeinated_template_features.jpg" alt="'
2599
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2600
-                                                . '" />';
2601
-        $this->_template_args['preview_text'] = '<strong>'
2602
-                                                . esc_html__(
2603
-                                                    '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.',
2604
-                                                    'event_espresso'
2605
-                                                ) . '</strong>';
2606
-        $this->display_admin_caf_preview_page('template_settings_tab');
2607
-    }
2608
-
2609
-
2610
-    /** Event Category Stuff **/
2611
-    /**
2612
-     * set the _category property with the category object for the loaded page.
2613
-     *
2614
-     * @access private
2615
-     * @return void
2616
-     */
2617
-    private function _set_category_object()
2618
-    {
2619
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2620
-            return;
2621
-        } //already have the category object so get out.
2622
-        // set default category object
2623
-        $this->_set_empty_category_object();
2624
-        // only set if we've got an id
2625
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2626
-        if (! $category_ID) {
2627
-            return;
2628
-        }
2629
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2630
-        if (! empty($term)) {
2631
-            $this->_category->category_name       = $term->name;
2632
-            $this->_category->category_identifier = $term->slug;
2633
-            $this->_category->category_desc       = $term->description;
2634
-            $this->_category->id                  = $term->term_id;
2635
-            $this->_category->parent              = $term->parent;
2636
-        }
2637
-    }
2638
-
2639
-
2640
-    /**
2641
-     * Clears out category properties.
2642
-     */
2643
-    private function _set_empty_category_object()
2644
-    {
2645
-        $this->_category                = new stdClass();
2646
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2647
-        $this->_category->id            = $this->_category->parent = 0;
2648
-    }
2649
-
2650
-
2651
-    /**
2652
-     * @throws DomainException
2653
-     * @throws EE_Error
2654
-     * @throws InvalidArgumentException
2655
-     * @throws InvalidDataTypeException
2656
-     * @throws InvalidInterfaceException
2657
-     */
2658
-    protected function _category_list_table()
2659
-    {
2660
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2661
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2662
-        $this->_admin_page_title .= ' ';
2663
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2664
-            'add_category',
2665
-            'add_category',
2666
-            [],
2667
-            'add-new-h2'
2668
-        );
2669
-        $this->display_admin_list_table_page_with_sidebar();
2670
-    }
2671
-
2672
-
2673
-    /**
2674
-     * Output category details view.
2675
-     *
2676
-     * @throws EE_Error
2677
-     * @throws EE_Error
2678
-     */
2679
-    protected function _category_details($view)
2680
-    {
2681
-        // load formatter helper
2682
-        // load field generator helper
2683
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2684
-        $this->_set_add_edit_form_tags($route);
2685
-        $this->_set_category_object();
2686
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2687
-        $delete_action = 'delete_category';
2688
-        // custom redirect
2689
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2690
-            ['action' => 'category_list'],
2691
-            $this->_admin_base_url
2692
-        );
2693
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2694
-        // take care of contents
2695
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2696
-        $this->display_admin_page_with_sidebar();
2697
-    }
2698
-
2699
-
2700
-    /**
2701
-     * Output category details content.
2702
-     *
2703
-     * @throws DomainException
2704
-     */
2705
-    protected function _category_details_content()
2706
-    {
2707
-        $editor_args['category_desc'] = [
2708
-            'type'          => 'wp_editor',
2709
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2710
-            'class'         => 'my_editor_custom',
2711
-            'wpeditor_args' => ['media_buttons' => false],
2712
-        ];
2713
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2714
-        $all_terms                    = get_terms(
2715
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2716
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2717
-        );
2718
-        // setup category select for term parents.
2719
-        $category_select_values[] = [
2720
-            'text' => esc_html__('No Parent', 'event_espresso'),
2721
-            'id'   => 0,
2722
-        ];
2723
-        foreach ($all_terms as $term) {
2724
-            $category_select_values[] = [
2725
-                'text' => $term->name,
2726
-                'id'   => $term->term_id,
2727
-            ];
2728
-        }
2729
-        $category_select = EEH_Form_Fields::select_input(
2730
-            'category_parent',
2731
-            $category_select_values,
2732
-            $this->_category->parent
2733
-        );
2734
-        $template_args   = [
2735
-            'category'                 => $this->_category,
2736
-            'category_select'          => $category_select,
2737
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2738
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2739
-            'disable'                  => '',
2740
-            'disabled_message'         => false,
2741
-        ];
2742
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2743
-        return EEH_Template::display_template($template, $template_args, true);
2744
-    }
2745
-
2746
-
2747
-    /**
2748
-     * Handles deleting categories.
2749
-     *
2750
-     * @throws EE_Error
2751
-     */
2752
-    protected function _delete_categories()
2753
-    {
2754
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2755
-        foreach ($category_IDs as $category_ID) {
2756
-            $this->_delete_category($category_ID);
2757
-        }
2758
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2759
-        $query_args = [
2760
-            'action' => 'category_list',
2761
-        ];
2762
-        $this->_redirect_after_action(0, '', '', $query_args);
2763
-    }
2764
-
2765
-
2766
-    /**
2767
-     * Handles deleting specific category.
2768
-     *
2769
-     * @param int $cat_id
2770
-     */
2771
-    protected function _delete_category($cat_id)
2772
-    {
2773
-        $cat_id = absint($cat_id);
2774
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2775
-    }
2776
-
2777
-
2778
-    /**
2779
-     * Handles triggering the update or insertion of a new category.
2780
-     *
2781
-     * @param bool $new_category true means we're triggering the insert of a new category.
2782
-     * @throws EE_Error
2783
-     * @throws EE_Error
2784
-     */
2785
-    protected function _insert_or_update_category($new_category)
2786
-    {
2787
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2788
-        $success = 0; // we already have a success message so lets not send another.
2789
-        if ($cat_id) {
2790
-            $query_args = [
2791
-                'action'     => 'edit_category',
2792
-                'EVT_CAT_ID' => $cat_id,
2793
-            ];
2794
-        } else {
2795
-            $query_args = ['action' => 'add_category'];
2796
-        }
2797
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2798
-    }
2799
-
2800
-
2801
-    /**
2802
-     * Inserts or updates category
2803
-     *
2804
-     * @param bool $update (true indicates we're updating a category).
2805
-     * @return bool|mixed|string
2806
-     */
2807
-    private function _insert_category($update = false)
2808
-    {
2809
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2810
-        $category_name       = $this->request->getRequestParam('category_name', '');
2811
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2812
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2813
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2814
-
2815
-        if (empty($category_name)) {
2816
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2817
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2818
-            return false;
2819
-        }
2820
-        $term_args = [
2821
-            'name'        => $category_name,
2822
-            'description' => $category_desc,
2823
-            'parent'      => $category_parent,
2824
-        ];
2825
-        // was the category_identifier input disabled?
2826
-        if ($category_identifier) {
2827
-            $term_args['slug'] = $category_identifier;
2828
-        }
2829
-        $insert_ids = $update
2830
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2831
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2832
-        if (! is_array($insert_ids)) {
2833
-            $msg = esc_html__(
2834
-                'An error occurred and the category has not been saved to the database.',
2835
-                'event_espresso'
2836
-            );
2837
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2838
-        } else {
2839
-            $category_ID = $insert_ids['term_id'];
2840
-            $msg         = sprintf(
2841
-                esc_html__('The category %s was successfully saved', 'event_espresso'),
2842
-                $category_name
2843
-            );
2844
-            EE_Error::add_success($msg);
2845
-        }
2846
-        return $category_ID;
2847
-    }
2848
-
2849
-
2850
-    /**
2851
-     * Gets categories or count of categories matching the arguments in the request.
2852
-     *
2853
-     * @param int  $per_page
2854
-     * @param int  $current_page
2855
-     * @param bool $count
2856
-     * @return EE_Term_Taxonomy[]|int
2857
-     * @throws EE_Error
2858
-     */
2859
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2860
-    {
2861
-        // testing term stuff
2862
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2863
-        $order       = $this->request->getRequestParam('order', 'DESC');
2864
-        $limit       = ($current_page - 1) * $per_page;
2865
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2866
-        $search_term = $this->request->getRequestParam('s');
2867
-        if ($search_term) {
2868
-            $search_term = '%' . $search_term . '%';
2869
-            $where['OR'] = [
2870
-                'Term.name'   => ['LIKE', $search_term],
2871
-                'description' => ['LIKE', $search_term],
2872
-            ];
2873
-        }
2874
-        $query_params = [
2875
-            $where,
2876
-            'order_by'   => [$orderby => $order],
2877
-            'limit'      => $limit . ',' . $per_page,
2878
-            'force_join' => ['Term'],
2879
-        ];
2880
-        return $count
2881
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2882
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2883
-    }
2884
-
2885
-    /* end category stuff */
2886
-
2887
-
2888
-    /**************/
2889
-
2890
-
2891
-    /**
2892
-     * Callback for the `ee_save_timezone_setting` ajax action.
2893
-     *
2894
-     * @throws EE_Error
2895
-     * @throws InvalidArgumentException
2896
-     * @throws InvalidDataTypeException
2897
-     * @throws InvalidInterfaceException
2898
-     */
2899
-    public function saveTimezoneString()
2900
-    {
2901
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2902
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2903
-            EE_Error::add_error(
2904
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2905
-                __FILE__,
2906
-                __FUNCTION__,
2907
-                __LINE__
2908
-            );
2909
-            $this->_template_args['error'] = true;
2910
-            $this->_return_json();
2911
-        }
2912
-
2913
-        update_option('timezone_string', $timezone_string);
2914
-        EE_Error::add_success(
2915
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2916
-        );
2917
-        $this->_template_args['success'] = true;
2918
-        $this->_return_json(true, ['action' => 'create_new']);
2919
-    }
2920
-
2921
-
2922
-    /**
2923 2590
      * @throws EE_Error
2924
-     * @deprecated 4.10.25.p
2925 2591
      */
2926
-    public function save_timezonestring_setting()
2927
-    {
2928
-        $this->saveTimezoneString();
2929
-    }
2592
+	protected function _template_settings()
2593
+	{
2594
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2595
+		$this->_template_args['preview_img']  = '<img src="'
2596
+												. EVENTS_ASSETS_URL
2597
+												. '/images/'
2598
+												. 'caffeinated_template_features.jpg" alt="'
2599
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2600
+												. '" />';
2601
+		$this->_template_args['preview_text'] = '<strong>'
2602
+												. esc_html__(
2603
+													'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.',
2604
+													'event_espresso'
2605
+												) . '</strong>';
2606
+		$this->display_admin_caf_preview_page('template_settings_tab');
2607
+	}
2608
+
2609
+
2610
+	/** Event Category Stuff **/
2611
+	/**
2612
+	 * set the _category property with the category object for the loaded page.
2613
+	 *
2614
+	 * @access private
2615
+	 * @return void
2616
+	 */
2617
+	private function _set_category_object()
2618
+	{
2619
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2620
+			return;
2621
+		} //already have the category object so get out.
2622
+		// set default category object
2623
+		$this->_set_empty_category_object();
2624
+		// only set if we've got an id
2625
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2626
+		if (! $category_ID) {
2627
+			return;
2628
+		}
2629
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2630
+		if (! empty($term)) {
2631
+			$this->_category->category_name       = $term->name;
2632
+			$this->_category->category_identifier = $term->slug;
2633
+			$this->_category->category_desc       = $term->description;
2634
+			$this->_category->id                  = $term->term_id;
2635
+			$this->_category->parent              = $term->parent;
2636
+		}
2637
+	}
2638
+
2639
+
2640
+	/**
2641
+	 * Clears out category properties.
2642
+	 */
2643
+	private function _set_empty_category_object()
2644
+	{
2645
+		$this->_category                = new stdClass();
2646
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2647
+		$this->_category->id            = $this->_category->parent = 0;
2648
+	}
2649
+
2650
+
2651
+	/**
2652
+	 * @throws DomainException
2653
+	 * @throws EE_Error
2654
+	 * @throws InvalidArgumentException
2655
+	 * @throws InvalidDataTypeException
2656
+	 * @throws InvalidInterfaceException
2657
+	 */
2658
+	protected function _category_list_table()
2659
+	{
2660
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2661
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2662
+		$this->_admin_page_title .= ' ';
2663
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2664
+			'add_category',
2665
+			'add_category',
2666
+			[],
2667
+			'add-new-h2'
2668
+		);
2669
+		$this->display_admin_list_table_page_with_sidebar();
2670
+	}
2671
+
2672
+
2673
+	/**
2674
+	 * Output category details view.
2675
+	 *
2676
+	 * @throws EE_Error
2677
+	 * @throws EE_Error
2678
+	 */
2679
+	protected function _category_details($view)
2680
+	{
2681
+		// load formatter helper
2682
+		// load field generator helper
2683
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2684
+		$this->_set_add_edit_form_tags($route);
2685
+		$this->_set_category_object();
2686
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2687
+		$delete_action = 'delete_category';
2688
+		// custom redirect
2689
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2690
+			['action' => 'category_list'],
2691
+			$this->_admin_base_url
2692
+		);
2693
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2694
+		// take care of contents
2695
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2696
+		$this->display_admin_page_with_sidebar();
2697
+	}
2698
+
2699
+
2700
+	/**
2701
+	 * Output category details content.
2702
+	 *
2703
+	 * @throws DomainException
2704
+	 */
2705
+	protected function _category_details_content()
2706
+	{
2707
+		$editor_args['category_desc'] = [
2708
+			'type'          => 'wp_editor',
2709
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2710
+			'class'         => 'my_editor_custom',
2711
+			'wpeditor_args' => ['media_buttons' => false],
2712
+		];
2713
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2714
+		$all_terms                    = get_terms(
2715
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2716
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2717
+		);
2718
+		// setup category select for term parents.
2719
+		$category_select_values[] = [
2720
+			'text' => esc_html__('No Parent', 'event_espresso'),
2721
+			'id'   => 0,
2722
+		];
2723
+		foreach ($all_terms as $term) {
2724
+			$category_select_values[] = [
2725
+				'text' => $term->name,
2726
+				'id'   => $term->term_id,
2727
+			];
2728
+		}
2729
+		$category_select = EEH_Form_Fields::select_input(
2730
+			'category_parent',
2731
+			$category_select_values,
2732
+			$this->_category->parent
2733
+		);
2734
+		$template_args   = [
2735
+			'category'                 => $this->_category,
2736
+			'category_select'          => $category_select,
2737
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2738
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2739
+			'disable'                  => '',
2740
+			'disabled_message'         => false,
2741
+		];
2742
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2743
+		return EEH_Template::display_template($template, $template_args, true);
2744
+	}
2745
+
2746
+
2747
+	/**
2748
+	 * Handles deleting categories.
2749
+	 *
2750
+	 * @throws EE_Error
2751
+	 */
2752
+	protected function _delete_categories()
2753
+	{
2754
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2755
+		foreach ($category_IDs as $category_ID) {
2756
+			$this->_delete_category($category_ID);
2757
+		}
2758
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2759
+		$query_args = [
2760
+			'action' => 'category_list',
2761
+		];
2762
+		$this->_redirect_after_action(0, '', '', $query_args);
2763
+	}
2764
+
2765
+
2766
+	/**
2767
+	 * Handles deleting specific category.
2768
+	 *
2769
+	 * @param int $cat_id
2770
+	 */
2771
+	protected function _delete_category($cat_id)
2772
+	{
2773
+		$cat_id = absint($cat_id);
2774
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2775
+	}
2776
+
2777
+
2778
+	/**
2779
+	 * Handles triggering the update or insertion of a new category.
2780
+	 *
2781
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2782
+	 * @throws EE_Error
2783
+	 * @throws EE_Error
2784
+	 */
2785
+	protected function _insert_or_update_category($new_category)
2786
+	{
2787
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2788
+		$success = 0; // we already have a success message so lets not send another.
2789
+		if ($cat_id) {
2790
+			$query_args = [
2791
+				'action'     => 'edit_category',
2792
+				'EVT_CAT_ID' => $cat_id,
2793
+			];
2794
+		} else {
2795
+			$query_args = ['action' => 'add_category'];
2796
+		}
2797
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2798
+	}
2799
+
2800
+
2801
+	/**
2802
+	 * Inserts or updates category
2803
+	 *
2804
+	 * @param bool $update (true indicates we're updating a category).
2805
+	 * @return bool|mixed|string
2806
+	 */
2807
+	private function _insert_category($update = false)
2808
+	{
2809
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2810
+		$category_name       = $this->request->getRequestParam('category_name', '');
2811
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2812
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2813
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2814
+
2815
+		if (empty($category_name)) {
2816
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2817
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2818
+			return false;
2819
+		}
2820
+		$term_args = [
2821
+			'name'        => $category_name,
2822
+			'description' => $category_desc,
2823
+			'parent'      => $category_parent,
2824
+		];
2825
+		// was the category_identifier input disabled?
2826
+		if ($category_identifier) {
2827
+			$term_args['slug'] = $category_identifier;
2828
+		}
2829
+		$insert_ids = $update
2830
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2831
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2832
+		if (! is_array($insert_ids)) {
2833
+			$msg = esc_html__(
2834
+				'An error occurred and the category has not been saved to the database.',
2835
+				'event_espresso'
2836
+			);
2837
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2838
+		} else {
2839
+			$category_ID = $insert_ids['term_id'];
2840
+			$msg         = sprintf(
2841
+				esc_html__('The category %s was successfully saved', 'event_espresso'),
2842
+				$category_name
2843
+			);
2844
+			EE_Error::add_success($msg);
2845
+		}
2846
+		return $category_ID;
2847
+	}
2848
+
2849
+
2850
+	/**
2851
+	 * Gets categories or count of categories matching the arguments in the request.
2852
+	 *
2853
+	 * @param int  $per_page
2854
+	 * @param int  $current_page
2855
+	 * @param bool $count
2856
+	 * @return EE_Term_Taxonomy[]|int
2857
+	 * @throws EE_Error
2858
+	 */
2859
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2860
+	{
2861
+		// testing term stuff
2862
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2863
+		$order       = $this->request->getRequestParam('order', 'DESC');
2864
+		$limit       = ($current_page - 1) * $per_page;
2865
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2866
+		$search_term = $this->request->getRequestParam('s');
2867
+		if ($search_term) {
2868
+			$search_term = '%' . $search_term . '%';
2869
+			$where['OR'] = [
2870
+				'Term.name'   => ['LIKE', $search_term],
2871
+				'description' => ['LIKE', $search_term],
2872
+			];
2873
+		}
2874
+		$query_params = [
2875
+			$where,
2876
+			'order_by'   => [$orderby => $order],
2877
+			'limit'      => $limit . ',' . $per_page,
2878
+			'force_join' => ['Term'],
2879
+		];
2880
+		return $count
2881
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2882
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2883
+	}
2884
+
2885
+	/* end category stuff */
2886
+
2887
+
2888
+	/**************/
2889
+
2890
+
2891
+	/**
2892
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2893
+	 *
2894
+	 * @throws EE_Error
2895
+	 * @throws InvalidArgumentException
2896
+	 * @throws InvalidDataTypeException
2897
+	 * @throws InvalidInterfaceException
2898
+	 */
2899
+	public function saveTimezoneString()
2900
+	{
2901
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2902
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2903
+			EE_Error::add_error(
2904
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2905
+				__FILE__,
2906
+				__FUNCTION__,
2907
+				__LINE__
2908
+			);
2909
+			$this->_template_args['error'] = true;
2910
+			$this->_return_json();
2911
+		}
2912
+
2913
+		update_option('timezone_string', $timezone_string);
2914
+		EE_Error::add_success(
2915
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2916
+		);
2917
+		$this->_template_args['success'] = true;
2918
+		$this->_return_json(true, ['action' => 'create_new']);
2919
+	}
2920
+
2921
+
2922
+	/**
2923
+	 * @throws EE_Error
2924
+	 * @deprecated 4.10.25.p
2925
+	 */
2926
+	public function save_timezonestring_setting()
2927
+	{
2928
+		$this->saveTimezoneString();
2929
+	}
2930 2930
 }
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -587,13 +587,13 @@  discard block
 block discarded – undo
587 587
     {
588 588
         wp_register_style(
589 589
             'events-admin-css',
590
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
590
+            EVENTS_ASSETS_URL.'events-admin-page.css',
591 591
             [],
592 592
             EVENT_ESPRESSO_VERSION
593 593
         );
594 594
         wp_register_style(
595 595
             'ee-cat-admin',
596
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
596
+            EVENTS_ASSETS_URL.'ee-cat-admin.css',
597 597
             [],
598 598
             EVENT_ESPRESSO_VERSION
599 599
         );
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
         // scripts
603 603
         wp_register_script(
604 604
             'event_editor_js',
605
-            EVENTS_ASSETS_URL . 'event_editor.js',
605
+            EVENTS_ASSETS_URL.'event_editor.js',
606 606
             ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
607 607
             EVENT_ESPRESSO_VERSION,
608 608
             true
@@ -628,16 +628,16 @@  discard block
 block discarded – undo
628 628
         wp_enqueue_style('espresso-ui-theme');
629 629
         wp_register_style(
630 630
             'event-editor-css',
631
-            EVENTS_ASSETS_URL . 'event-editor.css',
631
+            EVENTS_ASSETS_URL.'event-editor.css',
632 632
             ['ee-admin-css'],
633 633
             EVENT_ESPRESSO_VERSION
634 634
         );
635 635
         wp_enqueue_style('event-editor-css');
636 636
         // scripts
637
-        if (! $this->admin_config->useAdvancedEditor()) {
637
+        if ( ! $this->admin_config->useAdvancedEditor()) {
638 638
             wp_register_script(
639 639
                 'event-datetime-metabox',
640
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
640
+                EVENTS_ASSETS_URL.'event-datetime-metabox.js',
641 641
                 ['event_editor_js', 'ee-datepicker'],
642 642
                 EVENT_ESPRESSO_VERSION
643 643
             );
@@ -707,15 +707,15 @@  discard block
 block discarded – undo
707 707
     public function verify_event_edit($event = null, $req_type = '')
708 708
     {
709 709
         // don't need to do this when processing
710
-        if (! empty($req_type)) {
710
+        if ( ! empty($req_type)) {
711 711
             return;
712 712
         }
713 713
         // no event?
714
-        if (! $event instanceof EE_Event) {
714
+        if ( ! $event instanceof EE_Event) {
715 715
             $event = $this->_cpt_model_obj;
716 716
         }
717 717
         // STILL no event?
718
-        if (! $event instanceof EE_Event) {
718
+        if ( ! $event instanceof EE_Event) {
719 719
             return;
720 720
         }
721 721
         $orig_status = $event->status();
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
             );
756 756
         }
757 757
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
758
-        if (! $event->tickets_on_sale()) {
758
+        if ( ! $event->tickets_on_sale()) {
759 759
             return;
760 760
         }
761 761
         // made it here so show warning
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
     {
804 804
         $has_timezone_string = get_option('timezone_string');
805 805
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
806
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
806
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
807 807
             EE_Error::add_attention(
808 808
                 sprintf(
809 809
                     esc_html__(
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
      */
873 873
     protected function _event_legend_items()
874 874
     {
875
-        $items    = [
875
+        $items = [
876 876
             'view_details'   => [
877 877
                 'class' => 'dashicons dashicons-search',
878 878
                 'desc'  => esc_html__('View Event', 'event_espresso'),
@@ -889,31 +889,31 @@  discard block
 block discarded – undo
889 889
         $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
890 890
         $statuses = [
891 891
             'sold_out_status'  => [
892
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
892
+                'class' => 'ee-status-legend ee-status-bg--'.EE_Datetime::sold_out,
893 893
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
894 894
             ],
895 895
             'active_status'    => [
896
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
896
+                'class' => 'ee-status-legend ee-status-bg--'.EE_Datetime::active,
897 897
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
898 898
             ],
899 899
             'upcoming_status'  => [
900
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
900
+                'class' => 'ee-status-legend ee-status-bg--'.EE_Datetime::upcoming,
901 901
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
902 902
             ],
903 903
             'postponed_status' => [
904
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
904
+                'class' => 'ee-status-legend ee-status-bg--'.EE_Datetime::postponed,
905 905
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
906 906
             ],
907 907
             'cancelled_status' => [
908
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
908
+                'class' => 'ee-status-legend ee-status-bg--'.EE_Datetime::cancelled,
909 909
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
910 910
             ],
911 911
             'expired_status'   => [
912
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
912
+                'class' => 'ee-status-legend ee-status-bg--'.EE_Datetime::expired,
913 913
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
914 914
             ],
915 915
             'inactive_status'  => [
916
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
916
+                'class' => 'ee-status-legend ee-status-bg--'.EE_Datetime::inactive,
917 917
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
918 918
             ],
919 919
         ];
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
      */
933 933
     private function _event_model()
934 934
     {
935
-        if (! $this->_event_model instanceof EEM_Event) {
935
+        if ( ! $this->_event_model instanceof EEM_Event) {
936 936
             $this->_event_model = EE_Registry::instance()->load_model('Event');
937 937
         }
938 938
         return $this->_event_model;
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
953 953
     {
954 954
         // make sure this is only when editing
955
-        if (! empty($id)) {
955
+        if ( ! empty($id)) {
956 956
             $post = get_post($id);
957 957
             $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
958 958
                        . esc_html__('Shortcode', 'event_espresso')
@@ -991,14 +991,14 @@  discard block
 block discarded – undo
991 991
         );
992 992
 
993 993
         $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
994
-        $this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
994
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
995 995
             'create_new',
996 996
             'add',
997 997
             [],
998 998
             'add-new-h2'
999 999
         );
1000 1000
 
1001
-        $this->_template_args['after_list_table']   = array_merge(
1001
+        $this->_template_args['after_list_table'] = array_merge(
1002 1002
             (array) $this->_template_args['after_list_table'],
1003 1003
             $after_list_table
1004 1004
         );
@@ -1055,13 +1055,13 @@  discard block
 block discarded – undo
1055 1055
             'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1056 1056
         ];
1057 1057
         // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1058
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1059
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1058
+        if ( ! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1059
+            $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam(
1060 1060
                 'display_ticket_selector',
1061 1061
                 false,
1062 1062
                 'bool'
1063 1063
             );
1064
-            $event_values['EVT_additional_limit']            = min(
1064
+            $event_values['EVT_additional_limit'] = min(
1065 1065
                 apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1066 1066
                 $this->request->getRequestParam('additional_limit', null, 'int')
1067 1067
             );
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
         // the following are default callbacks for event attachment updates
1098 1098
         // that can be overridden by caffeinated functionality and/or addons.
1099 1099
         $event_update_callbacks = [];
1100
-        if (! $this->admin_config->useAdvancedEditor()) {
1100
+        if ( ! $this->admin_config->useAdvancedEditor()) {
1101 1101
             $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1102 1102
             $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1103 1103
         }
@@ -1168,7 +1168,7 @@  discard block
 block discarded – undo
1168 1168
      */
1169 1169
     protected function _default_venue_update(EE_Event $event, $data)
1170 1170
     {
1171
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1171
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1172 1172
         $venue_model = EE_Registry::instance()->load_model('Venue');
1173 1173
         $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1174 1174
         // very important.  If we don't have a venue name...
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
             'status'              => 'publish',
1200 1200
         ];
1201 1201
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1202
-        if (! empty($venue_id)) {
1202
+        if ( ! empty($venue_id)) {
1203 1203
             $update_where  = [$venue_model->primary_key_name() => $venue_id];
1204 1204
             $rows_affected = $venue_model->update($venue_array, [$update_where]);
1205 1205
             // we've gotta make sure that the venue is always attached to a revision..
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
                 isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1242 1242
                     ? $datetime_data['DTT_EVT_end']
1243 1243
                     : $datetime_data['DTT_EVT_start'];
1244
-            $datetime_values              = [
1244
+            $datetime_values = [
1245 1245
                 'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1246 1246
                 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1247 1247
                 'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
@@ -1250,9 +1250,9 @@  discard block
 block discarded – undo
1250 1250
             ];
1251 1251
             // if we have an id then let's get existing object first and then set the new values.
1252 1252
             //  Otherwise we instantiate a new object for save.
1253
-            if (! empty($datetime_data['DTT_ID'])) {
1253
+            if ( ! empty($datetime_data['DTT_ID'])) {
1254 1254
                 $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1255
-                if (! $datetime instanceof EE_Ticket) {
1255
+                if ( ! $datetime instanceof EE_Ticket) {
1256 1256
                     throw new RuntimeException(
1257 1257
                         sprintf(
1258 1258
                             esc_html__(
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
             } else {
1272 1272
                 $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1273 1273
             }
1274
-            if (! $datetime instanceof EE_Datetime) {
1274
+            if ( ! $datetime instanceof EE_Datetime) {
1275 1275
                 throw new RuntimeException(
1276 1276
                     sprintf(
1277 1277
                         esc_html__(
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
 
1298 1298
         // set up some default start and end dates in case those are not present in the incoming data
1299 1299
         $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1300
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1300
+        $default_start_date = $default_start_date->format($date_formats[0].' '.$date_formats[1]);
1301 1301
         // use the start date of the first datetime for the end date
1302 1302
         $first_datetime   = $event->first_datetime();
1303 1303
         $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
@@ -1305,8 +1305,8 @@  discard block
 block discarded – undo
1305 1305
         // now process the incoming data
1306 1306
         foreach ($data['edit_tickets'] as $row => $ticket_data) {
1307 1307
             $update_prices = false;
1308
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1309
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1308
+            $ticket_price  = isset($data['edit_prices'][$row][1]['PRC_amount'])
1309
+                ? $data['edit_prices'][$row][1]['PRC_amount']
1310 1310
                 : 0;
1311 1311
             // trim inputs to ensure any excess whitespace is removed.
1312 1312
             $ticket_data   = array_map('trim', $ticket_data);
@@ -1347,9 +1347,9 @@  discard block
 block discarded – undo
1347 1347
             // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1348 1348
             // keep in mind that if the ticket has been sold (and we have changed pricing information),
1349 1349
             // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1350
-            if (! empty($ticket_data['TKT_ID'])) {
1350
+            if ( ! empty($ticket_data['TKT_ID'])) {
1351 1351
                 $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1352
-                if (! $existing_ticket instanceof EE_Ticket) {
1352
+                if ( ! $existing_ticket instanceof EE_Ticket) {
1353 1353
                     throw new RuntimeException(
1354 1354
                         sprintf(
1355 1355
                             esc_html__(
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
                     $existing_ticket->save();
1399 1399
                     // make sure this ticket is still recorded in our $saved_tickets
1400 1400
                     // so we don't run it through the regular trash routine.
1401
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1401
+                    $saved_tickets[$existing_ticket->ID()] = $existing_ticket;
1402 1402
                     // create new ticket that's a copy of the existing except,
1403 1403
                     // (a new id of course and not archived) AND has the new TKT_price associated with it.
1404 1404
                     $new_ticket = clone $existing_ticket;
@@ -1415,7 +1415,7 @@  discard block
 block discarded – undo
1415 1415
                 $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1416 1416
                 $update_prices              = true;
1417 1417
             }
1418
-            if (! $ticket instanceof EE_Ticket) {
1418
+            if ( ! $ticket instanceof EE_Ticket) {
1419 1419
                 throw new RuntimeException(
1420 1420
                     sprintf(
1421 1421
                         esc_html__(
@@ -1439,9 +1439,9 @@  discard block
 block discarded – undo
1439 1439
             }
1440 1440
             // initially let's add the ticket to the datetime
1441 1441
             $datetime->_add_relation_to($ticket, 'Ticket');
1442
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1442
+            $saved_tickets[$ticket->ID()] = $ticket;
1443 1443
             // add prices to ticket
1444
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1444
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $ticket, $update_prices);
1445 1445
         }
1446 1446
         // however now we need to handle permanently deleting tickets via the ui.
1447 1447
         //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
             $id = absint($id);
1454 1454
             // get the ticket for this id
1455 1455
             $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1456
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1456
+            if ( ! $ticket_to_remove instanceof EE_Ticket) {
1457 1457
                 continue;
1458 1458
             }
1459 1459
             // need to get all the related datetimes on this ticket and remove from every single one of them
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
                     $price->set($field, $new_price);
1511 1511
                 }
1512 1512
             }
1513
-            if (! $price instanceof EE_Price) {
1513
+            if ( ! $price instanceof EE_Price) {
1514 1514
                 throw new RuntimeException(
1515 1515
                     sprintf(
1516 1516
                         esc_html__(
@@ -1552,13 +1552,13 @@  discard block
 block discarded – undo
1552 1552
     {
1553 1553
         // load formatter helper
1554 1554
         // args for getting related registrations
1555
-        $approved_query_args        = [
1555
+        $approved_query_args = [
1556 1556
             [
1557 1557
                 'REG_deleted' => 0,
1558 1558
                 'STS_ID'      => EEM_Registration::status_id_approved,
1559 1559
             ],
1560 1560
         ];
1561
-        $not_approved_query_args    = [
1561
+        $not_approved_query_args = [
1562 1562
             [
1563 1563
                 'REG_deleted' => 0,
1564 1564
                 'STS_ID'      => EEM_Registration::status_id_not_approved,
@@ -1621,7 +1621,7 @@  discard block
 block discarded – undo
1621 1621
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1622 1622
         // load template
1623 1623
         EEH_Template::display_template(
1624
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1624
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1625 1625
             $publish_box_extra_args
1626 1626
         );
1627 1627
     }
@@ -1652,7 +1652,7 @@  discard block
 block discarded – undo
1652 1652
         $this->verify_cpt_object();
1653 1653
         $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1654 1654
         // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1655
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1655
+        if ( ! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1656 1656
             $this->addMetaBox(
1657 1657
                 'espresso_event_editor_event_options',
1658 1658
                 esc_html__('Event Registration Options', 'event_espresso'),
@@ -1661,7 +1661,7 @@  discard block
 block discarded – undo
1661 1661
                 'side'
1662 1662
             );
1663 1663
         }
1664
-        if (! $use_advanced_editor) {
1664
+        if ( ! $use_advanced_editor) {
1665 1665
             $this->addMetaBox(
1666 1666
                 'espresso_event_editor_tickets',
1667 1667
                 esc_html__('Event Datetime & Ticket', 'event_espresso'),
@@ -1673,7 +1673,7 @@  discard block
 block discarded – undo
1673 1673
         } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1674 1674
             add_action(
1675 1675
                 'add_meta_boxes_espresso_events',
1676
-                function () {
1676
+                function() {
1677 1677
                     global $current_screen;
1678 1678
                     remove_meta_box('authordiv', $current_screen, 'normal');
1679 1679
                 },
@@ -1708,7 +1708,7 @@  discard block
 block discarded – undo
1708 1708
             'trash_icon'               => 'dashicons dashicons-lock',
1709 1709
             'disabled'                 => '',
1710 1710
         ];
1711
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1711
+        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1712 1712
         /**
1713 1713
          * 1. Start with retrieving Datetimes
1714 1714
          * 2. Fore each datetime get related tickets
@@ -1734,24 +1734,24 @@  discard block
 block discarded – undo
1734 1734
                     'default_where_conditions' => 'none',
1735 1735
                 ]
1736 1736
             );
1737
-            if (! empty($related_tickets)) {
1737
+            if ( ! empty($related_tickets)) {
1738 1738
                 $template_args['total_ticket_rows'] = count($related_tickets);
1739 1739
                 $row                                = 0;
1740 1740
                 foreach ($related_tickets as $ticket) {
1741
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1741
+                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1742 1742
                     $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1743 1743
                     $row++;
1744 1744
                 }
1745 1745
             } else {
1746 1746
                 $template_args['total_ticket_rows'] = 1;
1747 1747
                 /** @type EE_Ticket $ticket */
1748
-                $ticket                       = $ticket_model->create_default_object();
1748
+                $ticket = $ticket_model->create_default_object();
1749 1749
                 $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1750 1750
             }
1751 1751
         } else {
1752 1752
             $template_args['time'] = $times[0];
1753 1753
             /** @type EE_Ticket[] $tickets */
1754
-            $tickets                      = $ticket_model->get_all_default_tickets();
1754
+            $tickets = $ticket_model->get_all_default_tickets();
1755 1755
             $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1756 1756
             // NOTE: we're just sending the first default row
1757 1757
             // (decaf can't manage default tickets so this should be sufficient);
@@ -1766,9 +1766,9 @@  discard block
 block discarded – undo
1766 1766
             $ticket_model->create_default_object(),
1767 1767
             true
1768 1768
         );
1769
-        $template                                  = apply_filters(
1769
+        $template = apply_filters(
1770 1770
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1771
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1771
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1772 1772
         );
1773 1773
         EEH_Template::display_template($template, $template_args);
1774 1774
     }
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1789 1789
     {
1790 1790
         $template_args = [
1791
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1791
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1792 1792
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1793 1793
                 : '',
1794 1794
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1800,10 +1800,10 @@  discard block
 block discarded – undo
1800 1800
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1801 1801
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1802 1802
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1803
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1804
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1803
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1804
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1805 1805
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1806
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1806
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1807 1807
                 : ' disabled=disabled',
1808 1808
         ];
1809 1809
         $price         = $ticket->ID() !== 0
@@ -1827,7 +1827,7 @@  discard block
 block discarded – undo
1827 1827
         }
1828 1828
         if (empty($template_args['TKT_end_date'])) {
1829 1829
             // get the earliest datetime (if present);
1830
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1830
+            $earliest_datetime = $this->_cpt_model_obj->ID() > 0
1831 1831
                 ? $this->_cpt_model_obj->get_first_related(
1832 1832
                     'Datetime',
1833 1833
                     ['order_by' => ['DTT_EVT_start' => 'ASC']]
@@ -1840,7 +1840,7 @@  discard block
 block discarded – undo
1840 1840
         $template_args = array_merge($template_args, $price_args);
1841 1841
         $template      = apply_filters(
1842 1842
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1843
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1843
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1844 1844
             $ticket
1845 1845
         );
1846 1846
         return EEH_Template::display_template($template, $template_args, true);
@@ -1853,7 +1853,7 @@  discard block
 block discarded – undo
1853 1853
      */
1854 1854
     public function registration_options_meta_box()
1855 1855
     {
1856
-        $yes_no_values             = [
1856
+        $yes_no_values = [
1857 1857
             ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1858 1858
             ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1859 1859
         ];
@@ -1875,12 +1875,12 @@  discard block
 block discarded – undo
1875 1875
             $default_reg_status_values,
1876 1876
             $this->_cpt_model_obj->default_registration_status()
1877 1877
         );
1878
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1878
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
1879 1879
             'display_desc',
1880 1880
             $yes_no_values,
1881 1881
             $this->_cpt_model_obj->display_description()
1882 1882
         );
1883
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1883
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1884 1884
             'display_ticket_selector',
1885 1885
             $yes_no_values,
1886 1886
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -1896,7 +1896,7 @@  discard block
 block discarded – undo
1896 1896
             $default_reg_status_values
1897 1897
         );
1898 1898
         EEH_Template::display_template(
1899
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1899
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1900 1900
             $template_args
1901 1901
         );
1902 1902
     }
@@ -1919,7 +1919,7 @@  discard block
 block discarded – undo
1919 1919
     {
1920 1920
         $EEM_Event   = $this->_event_model();
1921 1921
         $offset      = ($current_page - 1) * $per_page;
1922
-        $limit       = $count ? null : $offset . ',' . $per_page;
1922
+        $limit       = $count ? null : $offset.','.$per_page;
1923 1923
         $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1924 1924
         $order       = $this->request->getRequestParam('order', 'DESC');
1925 1925
         $month_range = $this->request->getRequestParam('month_range');
@@ -1956,10 +1956,10 @@  discard block
 block discarded – undo
1956 1956
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1957 1957
         if ($month_range) {
1958 1958
             $DateTime = new DateTime(
1959
-                $year_r . '-' . $month_r . '-01 00:00:00',
1959
+                $year_r.'-'.$month_r.'-01 00:00:00',
1960 1960
                 new DateTimeZone('UTC')
1961 1961
             );
1962
-            $start    = $DateTime->getTimestamp();
1962
+            $start = $DateTime->getTimestamp();
1963 1963
             // set the datetime to be the end of the month
1964 1964
             $DateTime->setDate(
1965 1965
                 $year_r,
@@ -1984,11 +1984,11 @@  discard block
 block discarded – undo
1984 1984
                                                         ->format(implode(' ', $start_formats));
1985 1985
             $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986 1986
         }
1987
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1987
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1988 1988
             $where['EVT_wp_user'] = get_current_user_id();
1989 1989
         } else {
1990
-            if (! isset($where['status'])) {
1991
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1990
+            if ( ! isset($where['status'])) {
1991
+                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1992 1992
                     $where['OR'] = [
1993 1993
                         'status*restrict_private' => ['!=', 'private'],
1994 1994
                         'AND'                     => [
@@ -2010,7 +2010,7 @@  discard block
 block discarded – undo
2010 2010
         // search query handling
2011 2011
         $search_term = $this->request->getRequestParam('s');
2012 2012
         if ($search_term) {
2013
-            $search_term = '%' . $search_term . '%';
2013
+            $search_term = '%'.$search_term.'%';
2014 2014
             $where['OR'] = [
2015 2015
                 'EVT_name'       => ['LIKE', $search_term],
2016 2016
                 'EVT_desc'       => ['LIKE', $search_term],
@@ -2118,7 +2118,7 @@  discard block
 block discarded – undo
2118 2118
             // clean status
2119 2119
             $event_status = sanitize_key($event_status);
2120 2120
             // grab status
2121
-            if (! empty($event_status)) {
2121
+            if ( ! empty($event_status)) {
2122 2122
                 $success = $this->_change_event_status($EVT_ID, $event_status);
2123 2123
             } else {
2124 2124
                 $success = false;
@@ -2158,7 +2158,7 @@  discard block
 block discarded – undo
2158 2158
         // clean status
2159 2159
         $event_status = sanitize_key($event_status);
2160 2160
         // grab status
2161
-        if (! empty($event_status)) {
2161
+        if ( ! empty($event_status)) {
2162 2162
             $success = true;
2163 2163
             // determine the event id and set to array.
2164 2164
             $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
@@ -2204,7 +2204,7 @@  discard block
 block discarded – undo
2204 2204
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2205 2205
     {
2206 2206
         // grab event id
2207
-        if (! $EVT_ID) {
2207
+        if ( ! $EVT_ID) {
2208 2208
             $msg = esc_html__(
2209 2209
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2210 2210
                 'event_espresso'
@@ -2241,7 +2241,7 @@  discard block
 block discarded – undo
2241 2241
         // use class to change status
2242 2242
         $this->_cpt_model_obj->set_status($event_status);
2243 2243
         $success = $this->_cpt_model_obj->save();
2244
-        if (! $success) {
2244
+        if ( ! $success) {
2245 2245
             $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2246 2246
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2247 2247
             return false;
@@ -2299,7 +2299,7 @@  discard block
 block discarded – undo
2299 2299
      */
2300 2300
     protected function getModelObjNodeGroupPersister()
2301 2301
     {
2302
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2302
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2303 2303
             $this->model_obj_node_group_persister =
2304 2304
                 $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2305 2305
         }
@@ -2602,7 +2602,7 @@  discard block
 block discarded – undo
2602 2602
                                                 . esc_html__(
2603 2603
                                                     '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.',
2604 2604
                                                     'event_espresso'
2605
-                                                ) . '</strong>';
2605
+                                                ).'</strong>';
2606 2606
         $this->display_admin_caf_preview_page('template_settings_tab');
2607 2607
     }
2608 2608
 
@@ -2623,11 +2623,11 @@  discard block
 block discarded – undo
2623 2623
         $this->_set_empty_category_object();
2624 2624
         // only set if we've got an id
2625 2625
         $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2626
-        if (! $category_ID) {
2626
+        if ( ! $category_ID) {
2627 2627
             return;
2628 2628
         }
2629 2629
         $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2630
-        if (! empty($term)) {
2630
+        if ( ! empty($term)) {
2631 2631
             $this->_category->category_name       = $term->name;
2632 2632
             $this->_category->category_identifier = $term->slug;
2633 2633
             $this->_category->category_desc       = $term->description;
@@ -2731,7 +2731,7 @@  discard block
 block discarded – undo
2731 2731
             $category_select_values,
2732 2732
             $this->_category->parent
2733 2733
         );
2734
-        $template_args   = [
2734
+        $template_args = [
2735 2735
             'category'                 => $this->_category,
2736 2736
             'category_select'          => $category_select,
2737 2737
             'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
@@ -2739,7 +2739,7 @@  discard block
 block discarded – undo
2739 2739
             'disable'                  => '',
2740 2740
             'disabled_message'         => false,
2741 2741
         ];
2742
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2742
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2743 2743
         return EEH_Template::display_template($template, $template_args, true);
2744 2744
     }
2745 2745
 
@@ -2829,7 +2829,7 @@  discard block
 block discarded – undo
2829 2829
         $insert_ids = $update
2830 2830
             ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2831 2831
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2832
-        if (! is_array($insert_ids)) {
2832
+        if ( ! is_array($insert_ids)) {
2833 2833
             $msg = esc_html__(
2834 2834
                 'An error occurred and the category has not been saved to the database.',
2835 2835
                 'event_espresso'
@@ -2865,7 +2865,7 @@  discard block
 block discarded – undo
2865 2865
         $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2866 2866
         $search_term = $this->request->getRequestParam('s');
2867 2867
         if ($search_term) {
2868
-            $search_term = '%' . $search_term . '%';
2868
+            $search_term = '%'.$search_term.'%';
2869 2869
             $where['OR'] = [
2870 2870
                 'Term.name'   => ['LIKE', $search_term],
2871 2871
                 'description' => ['LIKE', $search_term],
@@ -2874,7 +2874,7 @@  discard block
 block discarded – undo
2874 2874
         $query_params = [
2875 2875
             $where,
2876 2876
             'order_by'   => [$orderby => $order],
2877
-            'limit'      => $limit . ',' . $per_page,
2877
+            'limit'      => $limit.','.$per_page,
2878 2878
             'force_join' => ['Term'],
2879 2879
         ];
2880 2880
         return $count
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_List_Table.class.php 2 patches
Indentation   +565 added lines, -565 removed lines patch added patch discarded remove patch
@@ -15,574 +15,574 @@
 block discarded – undo
15 15
 class Events_Admin_List_Table extends EE_Admin_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Datetime
20
-     */
21
-    private $_dtt;
22
-
23
-
24
-    /**
25
-     * Initial setup of data properties for the list table.
26
-     */
27
-    protected function _setup_data()
28
-    {
29
-        $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
-        $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
-    }
32
-
33
-
34
-    /**
35
-     * Set up of additional properties for the list table.
36
-     *
37
-     * @throws EE_Error
38
-     */
39
-    protected function _set_properties()
40
-    {
41
-        $this->_wp_list_args = array(
42
-            'singular' => esc_html__('event', 'event_espresso'),
43
-            'plural'   => esc_html__('events', 'event_espresso'),
44
-            'ajax'     => true, // for now
45
-            'screen'   => $this->_admin_page->get_current_screen()->id,
46
-        );
47
-        $approved_egistrations = esc_html__('Approved Registrations', 'event_espresso');
48
-        $this->_columns = array(
49
-            'cb'              => '<input type="checkbox" />',
50
-            // 'status'          => '',
51
-            'id'              => esc_html__('ID', 'event_espresso'),
52
-            'name'            => esc_html__('Name', 'event_espresso'),
53
-            'author'          => esc_html__('Author', 'event_espresso'),
54
-            'venue'           => esc_html__('Venue', 'event_espresso'),
55
-            'start_date_time' => esc_html__('Event Start', 'event_espresso'),
56
-            'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
57
-            'attendees'       => '
18
+	/**
19
+	 * @var EE_Datetime
20
+	 */
21
+	private $_dtt;
22
+
23
+
24
+	/**
25
+	 * Initial setup of data properties for the list table.
26
+	 */
27
+	protected function _setup_data()
28
+	{
29
+		$this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
+		$this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
+	}
32
+
33
+
34
+	/**
35
+	 * Set up of additional properties for the list table.
36
+	 *
37
+	 * @throws EE_Error
38
+	 */
39
+	protected function _set_properties()
40
+	{
41
+		$this->_wp_list_args = array(
42
+			'singular' => esc_html__('event', 'event_espresso'),
43
+			'plural'   => esc_html__('events', 'event_espresso'),
44
+			'ajax'     => true, // for now
45
+			'screen'   => $this->_admin_page->get_current_screen()->id,
46
+		);
47
+		$approved_egistrations = esc_html__('Approved Registrations', 'event_espresso');
48
+		$this->_columns = array(
49
+			'cb'              => '<input type="checkbox" />',
50
+			// 'status'          => '',
51
+			'id'              => esc_html__('ID', 'event_espresso'),
52
+			'name'            => esc_html__('Name', 'event_espresso'),
53
+			'author'          => esc_html__('Author', 'event_espresso'),
54
+			'venue'           => esc_html__('Venue', 'event_espresso'),
55
+			'start_date_time' => esc_html__('Event Start', 'event_espresso'),
56
+			'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
57
+			'attendees'       => '
58 58
                 <span class="show-on-mobile-view-only" aria-label="' . $approved_egistrations . '">
59 59
                     ' . $approved_egistrations . '
60 60
                 </span>
61 61
                 <span class="dashicons dashicons-groups ee-icon-color-ee-green"></span>',
62
-            'actions' => $this->actionsColumnHeader(),
63
-        );
64
-        $this->addConditionalColumns();
65
-        $this->_sortable_columns = array(
66
-            'id'              => array('EVT_ID' => true),
67
-            'name'            => array('EVT_name' => false),
68
-            'author'          => array('EVT_wp_user' => false),
69
-            'venue'           => array('Venue.VNU_name' => false),
70
-            'start_date_time' => array('Datetime.DTT_EVT_start' => false),
71
-            'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
72
-        );
73
-
74
-        $this->_primary_column = 'id';
75
-        $this->_hidden_columns = array('author', 'event_category');
76
-    }
77
-
78
-
79
-    /**
80
-     * @return array
81
-     */
82
-    protected function _get_table_filters()
83
-    {
84
-        return array(); // no filters with decaf
85
-    }
86
-
87
-
88
-    /**
89
-     * Setup of views properties.
90
-     *
91
-     * @throws InvalidDataTypeException
92
-     * @throws InvalidInterfaceException
93
-     * @throws InvalidArgumentException
94
-     */
95
-    protected function _add_view_counts()
96
-    {
97
-        $this->_views['all']['count'] = $this->_admin_page->total_events();
98
-        $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
99
-        if (
100
-            EE_Registry::instance()->CAP->current_user_can(
101
-                'ee_delete_events',
102
-                'espresso_events_trash_events'
103
-            )
104
-        ) {
105
-            $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
106
-        }
107
-    }
108
-
109
-
110
-    /**
111
-     * @param EE_Event $item
112
-     * @return string
113
-     */
114
-    protected function _get_row_class($item)
115
-    {
116
-        $class = parent::_get_row_class($item);
117
-        if ($this->_has_checkbox_column) {
118
-            $class .= ' has-checkbox-column';
119
-        }
120
-        return $class;
121
-    }
122
-
123
-
124
-    /**
125
-     * @param EE_Event $item
126
-     * @return string
127
-     * @throws EE_Error
128
-     * @throws ReflectionException
129
-     */
130
-    public function column_cb($item)
131
-    {
132
-        if (! $item instanceof EE_Event) {
133
-            return '';
134
-        }
135
-        $this->_dtt = $item->primary_datetime(); // set this for use in other columns
136
-        $content = sprintf(
137
-            '<input type="checkbox" name="EVT_IDs[]" value="%s" />',
138
-            $item->ID()
139
-        );
140
-        return $this->columnContent('cb', $content, 'center');
141
-    }
142
-
143
-
144
-    /**
145
-     * @param EE_Event $event
146
-     * @return mixed|string
147
-     * @throws EE_Error
148
-     * @throws ReflectionException
149
-     */
150
-    public function column_id(EE_Event $event)
151
-    {
152
-        $content = $event->ID();
153
-        $content .= '<span class="show-on-mobile-view-only">';
154
-        $content .= $this->column_name($event, false);;
155
-        $content .= '</span>';
156
-        return $this->columnContent('id', $content, 'end');
157
-    }
158
-
159
-
160
-    /**
161
-     * @param EE_Event $item
162
-     * @return string
163
-     * @throws EE_Error
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     * @throws ReflectionException
168
-     */
169
-    public function column_name(EE_Event $event, $prep_content = true)
170
-    {
171
-        $edit_query_args = array(
172
-            'action' => 'edit',
173
-            'post'   => $event->ID(),
174
-        );
175
-        $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
176
-        $actions = $this->_column_name_action_setup($event);
177
-        $status = esc_attr($event->get_active_status());
178
-        $pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
179
-        $status_dot = '<span class="ee-status-dot ee-status-bg--' . $status . '"></span>';
180
-        $content = '<div class="ee-layout-row">';
181
-        $content .= '<a class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" aria-label="' .
182
-                    $pretty_status . '" href="' . $edit_link . '">' . $status_dot .
183
-                    $event->name() . '</a>';
184
-        $content .= '</div>';
185
-        $content .= $this->row_actions($actions);
186
-
187
-        return $prep_content ? $this->columnContent('name', $content) : $content;
188
-    }
189
-
190
-
191
-    /**
192
-     * Just a method for setting up the actions for the name column
193
-     *
194
-     * @param EE_Event $event
195
-     * @return array array of actions
196
-     * @throws EE_Error
197
-     * @throws InvalidArgumentException
198
-     * @throws InvalidDataTypeException
199
-     * @throws InvalidInterfaceException
200
-     * @throws ReflectionException
201
-     */
202
-    protected function _column_name_action_setup(EE_Event $event)
203
-    {
204
-        // todo: remove when attendees is active
205
-        if (! defined('REG_ADMIN_URL')) {
206
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
207
-        }
208
-        $actions = array();
209
-        $restore_event_link = '';
210
-        $delete_event_link = '';
211
-        $trash_event_link = '';
212
-        if (
213
-            EE_Registry::instance()->CAP->current_user_can(
214
-                'ee_edit_event',
215
-                'espresso_events_edit',
216
-                $event->ID()
217
-            )
218
-        ) {
219
-            $edit_query_args = array(
220
-                'action' => 'edit',
221
-                'post'   => $event->ID(),
222
-            );
223
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
224
-            $actions['edit'] = '<a href="' . $edit_link . '" class="ee-aria-tooltip" '
225
-                               . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">'
226
-                               . esc_html__('Edit', 'event_espresso')
227
-                               . '</a>';
228
-        }
229
-        if (
230
-            EE_Registry::instance()->CAP->current_user_can(
231
-                'ee_read_registrations',
232
-                'espresso_registrations_view_registration'
233
-            )
234
-            && EE_Registry::instance()->CAP->current_user_can(
235
-                'ee_read_event',
236
-                'espresso_registrations_view_registration',
237
-                $event->ID()
238
-            )
239
-        ) {
240
-            $attendees_query_args = array(
241
-                'action'   => 'default',
242
-                'event_id' => $event->ID(),
243
-            );
244
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
245
-            $actions['attendees'] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip"'
246
-                                    . ' aria-label="' . esc_attr__('View Registrations', 'event_espresso') . '">'
247
-                                    . esc_html__('Registrations', 'event_espresso')
248
-                                    . '</a>';
249
-        }
250
-        if (
251
-            EE_Registry::instance()->CAP->current_user_can(
252
-                'ee_delete_event',
253
-                'espresso_events_trash_event',
254
-                $event->ID()
255
-            )
256
-        ) {
257
-            $trash_event_query_args = array(
258
-                'action' => 'trash_event',
259
-                'EVT_ID' => $event->ID(),
260
-            );
261
-            $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
262
-                $trash_event_query_args,
263
-                EVENTS_ADMIN_URL
264
-            );
265
-        }
266
-        if (
267
-            EE_Registry::instance()->CAP->current_user_can(
268
-                'ee_delete_event',
269
-                'espresso_events_restore_event',
270
-                $event->ID()
271
-            )
272
-        ) {
273
-            $restore_event_query_args = array(
274
-                'action' => 'restore_event',
275
-                'EVT_ID' => $event->ID(),
276
-            );
277
-            $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
278
-                $restore_event_query_args,
279
-                EVENTS_ADMIN_URL
280
-            );
281
-        }
282
-        if (
283
-            EE_Registry::instance()->CAP->current_user_can(
284
-                'ee_delete_event',
285
-                'espresso_events_delete_event',
286
-                $event->ID()
287
-            )
288
-        ) {
289
-            $delete_event_query_args = array(
290
-                'action' => 'delete_event',
291
-                'EVT_ID' => $event->ID(),
292
-            );
293
-            $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
294
-                $delete_event_query_args,
295
-                EVENTS_ADMIN_URL
296
-            );
297
-        }
298
-        $view_link = get_permalink($event->ID());
299
-        $actions['view'] = '<a href="' . $view_link . '" class="ee-aria-tooltip"'
300
-                           . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '">'
301
-                           . esc_html__('View', 'event_espresso')
302
-                           . '</a>';
303
-        if ($event->get('status') === 'trash') {
304
-            if (
305
-                EE_Registry::instance()->CAP->current_user_can(
306
-                    'ee_delete_event',
307
-                    'espresso_events_restore_event',
308
-                    $event->ID()
309
-                )
310
-            ) {
311
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" class="ee-aria-tooltip"'
312
-                                                 . ' aria-label="' . esc_attr__('Restore from Trash', 'event_espresso')
313
-                                                 . '">'
314
-                                                 . esc_html__('Restore from Trash', 'event_espresso')
315
-                                                 . '</a>';
316
-            }
317
-            if (
318
-                EE_Registry::instance()->CAP->current_user_can(
319
-                    'ee_delete_event',
320
-                    'espresso_events_delete_event',
321
-                    $event->ID()
322
-                )
323
-            ) {
324
-                $actions['delete'] = '<a href="' . $delete_event_link . '" class="ee-aria-tooltip"'
325
-                                     . ' aria-label="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
326
-                                     . esc_html__('Delete Permanently', 'event_espresso')
327
-                                     . '</a>';
328
-            }
329
-        } else {
330
-            if (
331
-                EE_Registry::instance()->CAP->current_user_can(
332
-                    'ee_delete_event',
333
-                    'espresso_events_trash_event',
334
-                    $event->ID()
335
-                )
336
-            ) {
337
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '" class="ee-aria-tooltip"'
338
-                                            . ' aria-label="' . esc_attr__('Trash Event', 'event_espresso') . '">'
339
-                                            . esc_html__('Trash', 'event_espresso')
340
-                                            . '</a>';
341
-            }
342
-        }
343
-        return $actions;
344
-    }
345
-
346
-
347
-    /**
348
-     * @param EE_Event $event
349
-     * @return string
350
-     * @throws EE_Error
351
-     * @throws ReflectionException
352
-     */
353
-    public function column_author(EE_Event $event)
354
-    {
355
-        // user author info
356
-        $event_author = get_userdata($event->wp_user());
357
-        $gravatar = get_avatar($event->wp_user(), '24');
358
-        // filter link
359
-        $query_args = array(
360
-            'action'      => 'default',
361
-            'EVT_wp_user' => $event->wp_user(),
362
-        );
363
-        $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
364
-        $content = '<div class="ee-layout-row">';
365
-        $content .= $gravatar . '  <a href="' . $filter_url . '" class="ee-aria-tooltip"'
366
-               . ' aria-label="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
367
-               . $event_author->display_name
368
-               . '</a>';
369
-        $content .= '</div>';
370
-        return $this->columnContent('author', $content);
371
-    }
372
-
373
-
374
-    /**
375
-     * @param EE_Event $event
376
-     * @return string
377
-     * @throws EE_Error
378
-     * @throws ReflectionException
379
-     */
380
-    public function column_event_category(EE_Event $event)
381
-    {
382
-        $event_categories = $event->get_all_event_categories();
383
-        $content = implode(
384
-            ', ',
385
-            array_map(
386
-                function (EE_Term $category) {
387
-                    return $category->name();
388
-                },
389
-                $event_categories
390
-            )
391
-        );
392
-        return $this->columnContent('event_category', $content);
393
-    }
394
-
395
-
396
-    /**
397
-     * @param EE_Event $event
398
-     * @return string
399
-     * @throws EE_Error
400
-     * @throws ReflectionException
401
-     */
402
-    public function column_venue(EE_Event $event)
403
-    {
404
-        $venue = $event->get_first_related('Venue');
405
-        $content = ! empty($venue)
406
-            ? $venue->name()
407
-            : '';
408
-        return $this->columnContent('venue', $content);
409
-    }
410
-
411
-
412
-    /**
413
-     * @param EE_Event $event
414
-     * @return string
415
-     * @throws EE_Error
416
-     * @throws ReflectionException
417
-     */
418
-    public function column_start_date_time(EE_Event $event)
419
-    {
420
-        $content = $this->_dtt instanceof EE_Datetime
421
-            ? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
422
-            : esc_html__('No Date was saved for this Event', 'event_espresso');
423
-        return $this->columnContent('start_date_time', $content);
424
-    }
425
-
426
-
427
-    /**
428
-     * @param EE_Event $event
429
-     * @return string
430
-     * @throws EE_Error
431
-     * @throws ReflectionException
432
-     */
433
-    public function column_reg_begins(EE_Event $event)
434
-    {
435
-        $reg_start = $event->get_ticket_with_earliest_start_time();
436
-        $content = $reg_start instanceof EE_Ticket
437
-            ? $reg_start->get_i18n_datetime('TKT_start_date')
438
-            : esc_html__('No Tickets have been setup for this Event', 'event_espresso');
439
-        return $this->columnContent('reg_begins', $content);
440
-    }
441
-
442
-
443
-    /**
444
-     * @param EE_Event $event
445
-     * @return int|string
446
-     * @throws EE_Error
447
-     * @throws InvalidArgumentException
448
-     * @throws InvalidDataTypeException
449
-     * @throws InvalidInterfaceException
450
-     * @throws ReflectionException
451
-     */
452
-    public function column_attendees(EE_Event $event)
453
-    {
454
-        $attendees_query_args = array(
455
-            'action'   => 'default',
456
-            'event_id' => $event->ID(),
457
-        );
458
-        $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
459
-        $registered_attendees = EEM_Registration::instance()->get_event_registration_count($event->ID());
460
-        $content = EE_Registry::instance()->CAP->current_user_can(
461
-            'ee_read_event',
462
-            'espresso_registrations_view_registration',
463
-            $event->ID()
464
-        )
465
-               && EE_Registry::instance()->CAP->current_user_can(
466
-                   'ee_read_registrations',
467
-                   'espresso_registrations_view_registration'
468
-               )
469
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
470
-            : $registered_attendees;
471
-        return $this->columnContent('attendees', $content, 'center');
472
-    }
473
-
474
-
475
-    /**
476
-     * @param EE_Event $event
477
-     * @return float
478
-     * @throws EE_Error
479
-     * @throws InvalidArgumentException
480
-     * @throws InvalidDataTypeException
481
-     * @throws InvalidInterfaceException
482
-     * @throws ReflectionException
483
-     */
484
-    public function column_tkts_sold(EE_Event $event)
485
-    {
486
-        $content = EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $event->ID())), 'TKT_sold');
487
-        return $this->columnContent('tkts_sold', $content);
488
-    }
489
-
490
-
491
-    /**
492
-     * @param EE_Event $event
493
-     * @return string
494
-     * @throws EE_Error
495
-     * @throws InvalidArgumentException
496
-     * @throws InvalidDataTypeException
497
-     * @throws InvalidInterfaceException
498
-     * @throws ReflectionException
499
-     */
500
-    public function column_actions(EE_Event $event)
501
-    {
502
-        // todo: remove when attendees is active
503
-        if (! defined('REG_ADMIN_URL')) {
504
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
505
-        }
506
-        $action_links = array();
507
-        $view_link = get_permalink($event->ID());
508
-        $action_links[] = '<a href="' . $view_link . '" class="ee-aria-tooltip button button--icon-only"'
509
-                          . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">
62
+			'actions' => $this->actionsColumnHeader(),
63
+		);
64
+		$this->addConditionalColumns();
65
+		$this->_sortable_columns = array(
66
+			'id'              => array('EVT_ID' => true),
67
+			'name'            => array('EVT_name' => false),
68
+			'author'          => array('EVT_wp_user' => false),
69
+			'venue'           => array('Venue.VNU_name' => false),
70
+			'start_date_time' => array('Datetime.DTT_EVT_start' => false),
71
+			'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
72
+		);
73
+
74
+		$this->_primary_column = 'id';
75
+		$this->_hidden_columns = array('author', 'event_category');
76
+	}
77
+
78
+
79
+	/**
80
+	 * @return array
81
+	 */
82
+	protected function _get_table_filters()
83
+	{
84
+		return array(); // no filters with decaf
85
+	}
86
+
87
+
88
+	/**
89
+	 * Setup of views properties.
90
+	 *
91
+	 * @throws InvalidDataTypeException
92
+	 * @throws InvalidInterfaceException
93
+	 * @throws InvalidArgumentException
94
+	 */
95
+	protected function _add_view_counts()
96
+	{
97
+		$this->_views['all']['count'] = $this->_admin_page->total_events();
98
+		$this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
99
+		if (
100
+			EE_Registry::instance()->CAP->current_user_can(
101
+				'ee_delete_events',
102
+				'espresso_events_trash_events'
103
+			)
104
+		) {
105
+			$this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
106
+		}
107
+	}
108
+
109
+
110
+	/**
111
+	 * @param EE_Event $item
112
+	 * @return string
113
+	 */
114
+	protected function _get_row_class($item)
115
+	{
116
+		$class = parent::_get_row_class($item);
117
+		if ($this->_has_checkbox_column) {
118
+			$class .= ' has-checkbox-column';
119
+		}
120
+		return $class;
121
+	}
122
+
123
+
124
+	/**
125
+	 * @param EE_Event $item
126
+	 * @return string
127
+	 * @throws EE_Error
128
+	 * @throws ReflectionException
129
+	 */
130
+	public function column_cb($item)
131
+	{
132
+		if (! $item instanceof EE_Event) {
133
+			return '';
134
+		}
135
+		$this->_dtt = $item->primary_datetime(); // set this for use in other columns
136
+		$content = sprintf(
137
+			'<input type="checkbox" name="EVT_IDs[]" value="%s" />',
138
+			$item->ID()
139
+		);
140
+		return $this->columnContent('cb', $content, 'center');
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param EE_Event $event
146
+	 * @return mixed|string
147
+	 * @throws EE_Error
148
+	 * @throws ReflectionException
149
+	 */
150
+	public function column_id(EE_Event $event)
151
+	{
152
+		$content = $event->ID();
153
+		$content .= '<span class="show-on-mobile-view-only">';
154
+		$content .= $this->column_name($event, false);;
155
+		$content .= '</span>';
156
+		return $this->columnContent('id', $content, 'end');
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param EE_Event $item
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 * @throws ReflectionException
168
+	 */
169
+	public function column_name(EE_Event $event, $prep_content = true)
170
+	{
171
+		$edit_query_args = array(
172
+			'action' => 'edit',
173
+			'post'   => $event->ID(),
174
+		);
175
+		$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
176
+		$actions = $this->_column_name_action_setup($event);
177
+		$status = esc_attr($event->get_active_status());
178
+		$pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
179
+		$status_dot = '<span class="ee-status-dot ee-status-bg--' . $status . '"></span>';
180
+		$content = '<div class="ee-layout-row">';
181
+		$content .= '<a class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" aria-label="' .
182
+					$pretty_status . '" href="' . $edit_link . '">' . $status_dot .
183
+					$event->name() . '</a>';
184
+		$content .= '</div>';
185
+		$content .= $this->row_actions($actions);
186
+
187
+		return $prep_content ? $this->columnContent('name', $content) : $content;
188
+	}
189
+
190
+
191
+	/**
192
+	 * Just a method for setting up the actions for the name column
193
+	 *
194
+	 * @param EE_Event $event
195
+	 * @return array array of actions
196
+	 * @throws EE_Error
197
+	 * @throws InvalidArgumentException
198
+	 * @throws InvalidDataTypeException
199
+	 * @throws InvalidInterfaceException
200
+	 * @throws ReflectionException
201
+	 */
202
+	protected function _column_name_action_setup(EE_Event $event)
203
+	{
204
+		// todo: remove when attendees is active
205
+		if (! defined('REG_ADMIN_URL')) {
206
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
207
+		}
208
+		$actions = array();
209
+		$restore_event_link = '';
210
+		$delete_event_link = '';
211
+		$trash_event_link = '';
212
+		if (
213
+			EE_Registry::instance()->CAP->current_user_can(
214
+				'ee_edit_event',
215
+				'espresso_events_edit',
216
+				$event->ID()
217
+			)
218
+		) {
219
+			$edit_query_args = array(
220
+				'action' => 'edit',
221
+				'post'   => $event->ID(),
222
+			);
223
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
224
+			$actions['edit'] = '<a href="' . $edit_link . '" class="ee-aria-tooltip" '
225
+							   . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">'
226
+							   . esc_html__('Edit', 'event_espresso')
227
+							   . '</a>';
228
+		}
229
+		if (
230
+			EE_Registry::instance()->CAP->current_user_can(
231
+				'ee_read_registrations',
232
+				'espresso_registrations_view_registration'
233
+			)
234
+			&& EE_Registry::instance()->CAP->current_user_can(
235
+				'ee_read_event',
236
+				'espresso_registrations_view_registration',
237
+				$event->ID()
238
+			)
239
+		) {
240
+			$attendees_query_args = array(
241
+				'action'   => 'default',
242
+				'event_id' => $event->ID(),
243
+			);
244
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
245
+			$actions['attendees'] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip"'
246
+									. ' aria-label="' . esc_attr__('View Registrations', 'event_espresso') . '">'
247
+									. esc_html__('Registrations', 'event_espresso')
248
+									. '</a>';
249
+		}
250
+		if (
251
+			EE_Registry::instance()->CAP->current_user_can(
252
+				'ee_delete_event',
253
+				'espresso_events_trash_event',
254
+				$event->ID()
255
+			)
256
+		) {
257
+			$trash_event_query_args = array(
258
+				'action' => 'trash_event',
259
+				'EVT_ID' => $event->ID(),
260
+			);
261
+			$trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
262
+				$trash_event_query_args,
263
+				EVENTS_ADMIN_URL
264
+			);
265
+		}
266
+		if (
267
+			EE_Registry::instance()->CAP->current_user_can(
268
+				'ee_delete_event',
269
+				'espresso_events_restore_event',
270
+				$event->ID()
271
+			)
272
+		) {
273
+			$restore_event_query_args = array(
274
+				'action' => 'restore_event',
275
+				'EVT_ID' => $event->ID(),
276
+			);
277
+			$restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
278
+				$restore_event_query_args,
279
+				EVENTS_ADMIN_URL
280
+			);
281
+		}
282
+		if (
283
+			EE_Registry::instance()->CAP->current_user_can(
284
+				'ee_delete_event',
285
+				'espresso_events_delete_event',
286
+				$event->ID()
287
+			)
288
+		) {
289
+			$delete_event_query_args = array(
290
+				'action' => 'delete_event',
291
+				'EVT_ID' => $event->ID(),
292
+			);
293
+			$delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
294
+				$delete_event_query_args,
295
+				EVENTS_ADMIN_URL
296
+			);
297
+		}
298
+		$view_link = get_permalink($event->ID());
299
+		$actions['view'] = '<a href="' . $view_link . '" class="ee-aria-tooltip"'
300
+						   . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '">'
301
+						   . esc_html__('View', 'event_espresso')
302
+						   . '</a>';
303
+		if ($event->get('status') === 'trash') {
304
+			if (
305
+				EE_Registry::instance()->CAP->current_user_can(
306
+					'ee_delete_event',
307
+					'espresso_events_restore_event',
308
+					$event->ID()
309
+				)
310
+			) {
311
+				$actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" class="ee-aria-tooltip"'
312
+												 . ' aria-label="' . esc_attr__('Restore from Trash', 'event_espresso')
313
+												 . '">'
314
+												 . esc_html__('Restore from Trash', 'event_espresso')
315
+												 . '</a>';
316
+			}
317
+			if (
318
+				EE_Registry::instance()->CAP->current_user_can(
319
+					'ee_delete_event',
320
+					'espresso_events_delete_event',
321
+					$event->ID()
322
+				)
323
+			) {
324
+				$actions['delete'] = '<a href="' . $delete_event_link . '" class="ee-aria-tooltip"'
325
+									 . ' aria-label="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
326
+									 . esc_html__('Delete Permanently', 'event_espresso')
327
+									 . '</a>';
328
+			}
329
+		} else {
330
+			if (
331
+				EE_Registry::instance()->CAP->current_user_can(
332
+					'ee_delete_event',
333
+					'espresso_events_trash_event',
334
+					$event->ID()
335
+				)
336
+			) {
337
+				$actions['move to trash'] = '<a href="' . $trash_event_link . '" class="ee-aria-tooltip"'
338
+											. ' aria-label="' . esc_attr__('Trash Event', 'event_espresso') . '">'
339
+											. esc_html__('Trash', 'event_espresso')
340
+											. '</a>';
341
+			}
342
+		}
343
+		return $actions;
344
+	}
345
+
346
+
347
+	/**
348
+	 * @param EE_Event $event
349
+	 * @return string
350
+	 * @throws EE_Error
351
+	 * @throws ReflectionException
352
+	 */
353
+	public function column_author(EE_Event $event)
354
+	{
355
+		// user author info
356
+		$event_author = get_userdata($event->wp_user());
357
+		$gravatar = get_avatar($event->wp_user(), '24');
358
+		// filter link
359
+		$query_args = array(
360
+			'action'      => 'default',
361
+			'EVT_wp_user' => $event->wp_user(),
362
+		);
363
+		$filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
364
+		$content = '<div class="ee-layout-row">';
365
+		$content .= $gravatar . '  <a href="' . $filter_url . '" class="ee-aria-tooltip"'
366
+			   . ' aria-label="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
367
+			   . $event_author->display_name
368
+			   . '</a>';
369
+		$content .= '</div>';
370
+		return $this->columnContent('author', $content);
371
+	}
372
+
373
+
374
+	/**
375
+	 * @param EE_Event $event
376
+	 * @return string
377
+	 * @throws EE_Error
378
+	 * @throws ReflectionException
379
+	 */
380
+	public function column_event_category(EE_Event $event)
381
+	{
382
+		$event_categories = $event->get_all_event_categories();
383
+		$content = implode(
384
+			', ',
385
+			array_map(
386
+				function (EE_Term $category) {
387
+					return $category->name();
388
+				},
389
+				$event_categories
390
+			)
391
+		);
392
+		return $this->columnContent('event_category', $content);
393
+	}
394
+
395
+
396
+	/**
397
+	 * @param EE_Event $event
398
+	 * @return string
399
+	 * @throws EE_Error
400
+	 * @throws ReflectionException
401
+	 */
402
+	public function column_venue(EE_Event $event)
403
+	{
404
+		$venue = $event->get_first_related('Venue');
405
+		$content = ! empty($venue)
406
+			? $venue->name()
407
+			: '';
408
+		return $this->columnContent('venue', $content);
409
+	}
410
+
411
+
412
+	/**
413
+	 * @param EE_Event $event
414
+	 * @return string
415
+	 * @throws EE_Error
416
+	 * @throws ReflectionException
417
+	 */
418
+	public function column_start_date_time(EE_Event $event)
419
+	{
420
+		$content = $this->_dtt instanceof EE_Datetime
421
+			? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
422
+			: esc_html__('No Date was saved for this Event', 'event_espresso');
423
+		return $this->columnContent('start_date_time', $content);
424
+	}
425
+
426
+
427
+	/**
428
+	 * @param EE_Event $event
429
+	 * @return string
430
+	 * @throws EE_Error
431
+	 * @throws ReflectionException
432
+	 */
433
+	public function column_reg_begins(EE_Event $event)
434
+	{
435
+		$reg_start = $event->get_ticket_with_earliest_start_time();
436
+		$content = $reg_start instanceof EE_Ticket
437
+			? $reg_start->get_i18n_datetime('TKT_start_date')
438
+			: esc_html__('No Tickets have been setup for this Event', 'event_espresso');
439
+		return $this->columnContent('reg_begins', $content);
440
+	}
441
+
442
+
443
+	/**
444
+	 * @param EE_Event $event
445
+	 * @return int|string
446
+	 * @throws EE_Error
447
+	 * @throws InvalidArgumentException
448
+	 * @throws InvalidDataTypeException
449
+	 * @throws InvalidInterfaceException
450
+	 * @throws ReflectionException
451
+	 */
452
+	public function column_attendees(EE_Event $event)
453
+	{
454
+		$attendees_query_args = array(
455
+			'action'   => 'default',
456
+			'event_id' => $event->ID(),
457
+		);
458
+		$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
459
+		$registered_attendees = EEM_Registration::instance()->get_event_registration_count($event->ID());
460
+		$content = EE_Registry::instance()->CAP->current_user_can(
461
+			'ee_read_event',
462
+			'espresso_registrations_view_registration',
463
+			$event->ID()
464
+		)
465
+			   && EE_Registry::instance()->CAP->current_user_can(
466
+				   'ee_read_registrations',
467
+				   'espresso_registrations_view_registration'
468
+			   )
469
+			? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
470
+			: $registered_attendees;
471
+		return $this->columnContent('attendees', $content, 'center');
472
+	}
473
+
474
+
475
+	/**
476
+	 * @param EE_Event $event
477
+	 * @return float
478
+	 * @throws EE_Error
479
+	 * @throws InvalidArgumentException
480
+	 * @throws InvalidDataTypeException
481
+	 * @throws InvalidInterfaceException
482
+	 * @throws ReflectionException
483
+	 */
484
+	public function column_tkts_sold(EE_Event $event)
485
+	{
486
+		$content = EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $event->ID())), 'TKT_sold');
487
+		return $this->columnContent('tkts_sold', $content);
488
+	}
489
+
490
+
491
+	/**
492
+	 * @param EE_Event $event
493
+	 * @return string
494
+	 * @throws EE_Error
495
+	 * @throws InvalidArgumentException
496
+	 * @throws InvalidDataTypeException
497
+	 * @throws InvalidInterfaceException
498
+	 * @throws ReflectionException
499
+	 */
500
+	public function column_actions(EE_Event $event)
501
+	{
502
+		// todo: remove when attendees is active
503
+		if (! defined('REG_ADMIN_URL')) {
504
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
505
+		}
506
+		$action_links = array();
507
+		$view_link = get_permalink($event->ID());
508
+		$action_links[] = '<a href="' . $view_link . '" class="ee-aria-tooltip button button--icon-only"'
509
+						  . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">
510 510
                           <span class="dashicons dashicons-search"></span></a>';
511
-        if (
512
-            EE_Registry::instance()->CAP->current_user_can(
513
-                'ee_edit_event',
514
-                'espresso_events_edit',
515
-                $event->ID()
516
-            )
517
-        ) {
518
-            $edit_query_args = array(
519
-                'action' => 'edit',
520
-                'post'   => $event->ID(),
521
-            );
522
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
523
-            $action_links[] = '<a href="' . $edit_link . '" class="ee-aria-tooltip button button--icon-only"'
524
-                              . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">'
525
-                              . '<span class="dashicons dashicons-calendar-alt"></span>'
526
-                              . '</a>';
527
-        }
528
-        if (
529
-            EE_Registry::instance()->CAP->current_user_can(
530
-                'ee_read_registrations',
531
-                'espresso_registrations_view_registration'
532
-            ) && EE_Registry::instance()->CAP->current_user_can(
533
-                'ee_read_event',
534
-                'espresso_registrations_view_registration',
535
-                $event->ID()
536
-            )
537
-        ) {
538
-            $attendees_query_args = array(
539
-                'action'   => 'default',
540
-                'event_id' => $event->ID(),
541
-            );
542
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
543
-            $action_links[] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip button button--icon-only"'
544
-                              . ' aria-label="' . esc_attr__('View Registrants', 'event_espresso') . '">'
545
-                              . '<span class="dashicons dashicons-groups"></span>'
546
-                              . '</a>';
547
-        }
548
-        $action_links = apply_filters(
549
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
550
-            $action_links,
551
-            $event
552
-        );
553
-        $content = $this->_action_string(
554
-            implode("\n\t", $action_links),
555
-            $event,
556
-            'div',
557
-            'event-overview-actions ee-list-table-actions'
558
-        );
559
-        return $this->columnContent('actions', $this->actionsModalMenu($content));
560
-    }
561
-
562
-
563
-    /**
564
-     * Helper for adding columns conditionally
565
-     *
566
-     * @throws EE_Error
567
-     * @throws InvalidArgumentException
568
-     * @throws InvalidDataTypeException
569
-     * @throws InvalidInterfaceException
570
-     */
571
-    private function addConditionalColumns()
572
-    {
573
-        $event_category_count = EEM_Term::instance()->count(
574
-            [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
575
-        );
576
-        if ($event_category_count === 0) {
577
-            return;
578
-        }
579
-        $column_array = [];
580
-        foreach ($this->_columns as $column => $column_label) {
581
-            $column_array[ $column ] = $column_label;
582
-            if ($column === 'venue') {
583
-                $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
584
-            }
585
-        }
586
-        $this->_columns = $column_array;
587
-    }
511
+		if (
512
+			EE_Registry::instance()->CAP->current_user_can(
513
+				'ee_edit_event',
514
+				'espresso_events_edit',
515
+				$event->ID()
516
+			)
517
+		) {
518
+			$edit_query_args = array(
519
+				'action' => 'edit',
520
+				'post'   => $event->ID(),
521
+			);
522
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
523
+			$action_links[] = '<a href="' . $edit_link . '" class="ee-aria-tooltip button button--icon-only"'
524
+							  . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">'
525
+							  . '<span class="dashicons dashicons-calendar-alt"></span>'
526
+							  . '</a>';
527
+		}
528
+		if (
529
+			EE_Registry::instance()->CAP->current_user_can(
530
+				'ee_read_registrations',
531
+				'espresso_registrations_view_registration'
532
+			) && EE_Registry::instance()->CAP->current_user_can(
533
+				'ee_read_event',
534
+				'espresso_registrations_view_registration',
535
+				$event->ID()
536
+			)
537
+		) {
538
+			$attendees_query_args = array(
539
+				'action'   => 'default',
540
+				'event_id' => $event->ID(),
541
+			);
542
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
543
+			$action_links[] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip button button--icon-only"'
544
+							  . ' aria-label="' . esc_attr__('View Registrants', 'event_espresso') . '">'
545
+							  . '<span class="dashicons dashicons-groups"></span>'
546
+							  . '</a>';
547
+		}
548
+		$action_links = apply_filters(
549
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
550
+			$action_links,
551
+			$event
552
+		);
553
+		$content = $this->_action_string(
554
+			implode("\n\t", $action_links),
555
+			$event,
556
+			'div',
557
+			'event-overview-actions ee-list-table-actions'
558
+		);
559
+		return $this->columnContent('actions', $this->actionsModalMenu($content));
560
+	}
561
+
562
+
563
+	/**
564
+	 * Helper for adding columns conditionally
565
+	 *
566
+	 * @throws EE_Error
567
+	 * @throws InvalidArgumentException
568
+	 * @throws InvalidDataTypeException
569
+	 * @throws InvalidInterfaceException
570
+	 */
571
+	private function addConditionalColumns()
572
+	{
573
+		$event_category_count = EEM_Term::instance()->count(
574
+			[['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
575
+		);
576
+		if ($event_category_count === 0) {
577
+			return;
578
+		}
579
+		$column_array = [];
580
+		foreach ($this->_columns as $column => $column_label) {
581
+			$column_array[ $column ] = $column_label;
582
+			if ($column === 'venue') {
583
+				$column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
584
+			}
585
+		}
586
+		$this->_columns = $column_array;
587
+	}
588 588
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
             'start_date_time' => esc_html__('Event Start', 'event_espresso'),
56 56
             'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
57 57
             'attendees'       => '
58
-                <span class="show-on-mobile-view-only" aria-label="' . $approved_egistrations . '">
59
-                    ' . $approved_egistrations . '
58
+                <span class="show-on-mobile-view-only" aria-label="' . $approved_egistrations.'">
59
+                    ' . $approved_egistrations.'
60 60
                 </span>
61 61
                 <span class="dashicons dashicons-groups ee-icon-color-ee-green"></span>',
62 62
             'actions' => $this->actionsColumnHeader(),
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public function column_cb($item)
131 131
     {
132
-        if (! $item instanceof EE_Event) {
132
+        if ( ! $item instanceof EE_Event) {
133 133
             return '';
134 134
         }
135 135
         $this->_dtt = $item->primary_datetime(); // set this for use in other columns
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     {
152 152
         $content = $event->ID();
153 153
         $content .= '<span class="show-on-mobile-view-only">';
154
-        $content .= $this->column_name($event, false);;
154
+        $content .= $this->column_name($event, false); ;
155 155
         $content .= '</span>';
156 156
         return $this->columnContent('id', $content, 'end');
157 157
     }
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
         $actions = $this->_column_name_action_setup($event);
177 177
         $status = esc_attr($event->get_active_status());
178 178
         $pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
179
-        $status_dot = '<span class="ee-status-dot ee-status-bg--' . $status . '"></span>';
179
+        $status_dot = '<span class="ee-status-dot ee-status-bg--'.$status.'"></span>';
180 180
         $content = '<div class="ee-layout-row">';
181
-        $content .= '<a class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" aria-label="' .
182
-                    $pretty_status . '" href="' . $edit_link . '">' . $status_dot .
183
-                    $event->name() . '</a>';
181
+        $content .= '<a class="row-title ee-status-color--'.$status.' ee-aria-tooltip" aria-label="'.
182
+                    $pretty_status.'" href="'.$edit_link.'">'.$status_dot.
183
+                    $event->name().'</a>';
184 184
         $content .= '</div>';
185 185
         $content .= $this->row_actions($actions);
186 186
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     protected function _column_name_action_setup(EE_Event $event)
203 203
     {
204 204
         // todo: remove when attendees is active
205
-        if (! defined('REG_ADMIN_URL')) {
205
+        if ( ! defined('REG_ADMIN_URL')) {
206 206
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
207 207
         }
208 208
         $actions = array();
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
                 'post'   => $event->ID(),
222 222
             );
223 223
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
224
-            $actions['edit'] = '<a href="' . $edit_link . '" class="ee-aria-tooltip" '
225
-                               . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">'
224
+            $actions['edit'] = '<a href="'.$edit_link.'" class="ee-aria-tooltip" '
225
+                               . ' aria-label="'.esc_attr__('Edit Event', 'event_espresso').'">'
226 226
                                . esc_html__('Edit', 'event_espresso')
227 227
                                . '</a>';
228 228
         }
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
                 'event_id' => $event->ID(),
243 243
             );
244 244
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
245
-            $actions['attendees'] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip"'
246
-                                    . ' aria-label="' . esc_attr__('View Registrations', 'event_espresso') . '">'
245
+            $actions['attendees'] = '<a href="'.$attendees_link.'" class="ee-aria-tooltip"'
246
+                                    . ' aria-label="'.esc_attr__('View Registrations', 'event_espresso').'">'
247 247
                                     . esc_html__('Registrations', 'event_espresso')
248 248
                                     . '</a>';
249 249
         }
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
             );
297 297
         }
298 298
         $view_link = get_permalink($event->ID());
299
-        $actions['view'] = '<a href="' . $view_link . '" class="ee-aria-tooltip"'
300
-                           . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '">'
299
+        $actions['view'] = '<a href="'.$view_link.'" class="ee-aria-tooltip"'
300
+                           . ' aria-label="'.esc_attr__('View Event', 'event_espresso').'">'
301 301
                            . esc_html__('View', 'event_espresso')
302 302
                            . '</a>';
303 303
         if ($event->get('status') === 'trash') {
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
                     $event->ID()
309 309
                 )
310 310
             ) {
311
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" class="ee-aria-tooltip"'
312
-                                                 . ' aria-label="' . esc_attr__('Restore from Trash', 'event_espresso')
311
+                $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'" class="ee-aria-tooltip"'
312
+                                                 . ' aria-label="'.esc_attr__('Restore from Trash', 'event_espresso')
313 313
                                                  . '">'
314 314
                                                  . esc_html__('Restore from Trash', 'event_espresso')
315 315
                                                  . '</a>';
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
                     $event->ID()
322 322
                 )
323 323
             ) {
324
-                $actions['delete'] = '<a href="' . $delete_event_link . '" class="ee-aria-tooltip"'
325
-                                     . ' aria-label="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
324
+                $actions['delete'] = '<a href="'.$delete_event_link.'" class="ee-aria-tooltip"'
325
+                                     . ' aria-label="'.esc_attr__('Delete Permanently', 'event_espresso').'">'
326 326
                                      . esc_html__('Delete Permanently', 'event_espresso')
327 327
                                      . '</a>';
328 328
             }
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
                     $event->ID()
335 335
                 )
336 336
             ) {
337
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '" class="ee-aria-tooltip"'
338
-                                            . ' aria-label="' . esc_attr__('Trash Event', 'event_espresso') . '">'
337
+                $actions['move to trash'] = '<a href="'.$trash_event_link.'" class="ee-aria-tooltip"'
338
+                                            . ' aria-label="'.esc_attr__('Trash Event', 'event_espresso').'">'
339 339
                                             . esc_html__('Trash', 'event_espresso')
340 340
                                             . '</a>';
341 341
             }
@@ -362,8 +362,8 @@  discard block
 block discarded – undo
362 362
         );
363 363
         $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
364 364
         $content = '<div class="ee-layout-row">';
365
-        $content .= $gravatar . '  <a href="' . $filter_url . '" class="ee-aria-tooltip"'
366
-               . ' aria-label="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
365
+        $content .= $gravatar.'  <a href="'.$filter_url.'" class="ee-aria-tooltip"'
366
+               . ' aria-label="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">'
367 367
                . $event_author->display_name
368 368
                . '</a>';
369 369
         $content .= '</div>';
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
         $content = implode(
384 384
             ', ',
385 385
             array_map(
386
-                function (EE_Term $category) {
386
+                function(EE_Term $category) {
387 387
                     return $category->name();
388 388
                 },
389 389
                 $event_categories
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
                    'ee_read_registrations',
467 467
                    'espresso_registrations_view_registration'
468 468
                )
469
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
469
+            ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>'
470 470
             : $registered_attendees;
471 471
         return $this->columnContent('attendees', $content, 'center');
472 472
     }
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
     public function column_actions(EE_Event $event)
501 501
     {
502 502
         // todo: remove when attendees is active
503
-        if (! defined('REG_ADMIN_URL')) {
503
+        if ( ! defined('REG_ADMIN_URL')) {
504 504
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
505 505
         }
506 506
         $action_links = array();
507 507
         $view_link = get_permalink($event->ID());
508
-        $action_links[] = '<a href="' . $view_link . '" class="ee-aria-tooltip button button--icon-only"'
509
-                          . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">
508
+        $action_links[] = '<a href="'.$view_link.'" class="ee-aria-tooltip button button--icon-only"'
509
+                          . ' aria-label="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">
510 510
                           <span class="dashicons dashicons-search"></span></a>';
511 511
         if (
512 512
             EE_Registry::instance()->CAP->current_user_can(
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
                 'post'   => $event->ID(),
521 521
             );
522 522
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
523
-            $action_links[] = '<a href="' . $edit_link . '" class="ee-aria-tooltip button button--icon-only"'
524
-                              . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">'
523
+            $action_links[] = '<a href="'.$edit_link.'" class="ee-aria-tooltip button button--icon-only"'
524
+                              . ' aria-label="'.esc_attr__('Edit Event', 'event_espresso').'">'
525 525
                               . '<span class="dashicons dashicons-calendar-alt"></span>'
526 526
                               . '</a>';
527 527
         }
@@ -540,8 +540,8 @@  discard block
 block discarded – undo
540 540
                 'event_id' => $event->ID(),
541 541
             );
542 542
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
543
-            $action_links[] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip button button--icon-only"'
544
-                              . ' aria-label="' . esc_attr__('View Registrants', 'event_espresso') . '">'
543
+            $action_links[] = '<a href="'.$attendees_link.'" class="ee-aria-tooltip button button--icon-only"'
544
+                              . ' aria-label="'.esc_attr__('View Registrants', 'event_espresso').'">'
545 545
                               . '<span class="dashicons dashicons-groups"></span>'
546 546
                               . '</a>';
547 547
         }
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
         }
579 579
         $column_array = [];
580 580
         foreach ($this->_columns as $column => $column_label) {
581
-            $column_array[ $column ] = $column_label;
581
+            $column_array[$column] = $column_label;
582 582
             if ($column === 'venue') {
583 583
                 $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
584 584
             }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4557 added lines, -4557 removed lines patch added patch discarded remove patch
@@ -17,2661 +17,2661 @@  discard block
 block discarded – undo
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19 19
 
20
-    /**
21
-     * @type EE_Message_Resource_Manager $_message_resource_manager
22
-     */
23
-    protected $_message_resource_manager;
20
+	/**
21
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
22
+	 */
23
+	protected $_message_resource_manager;
24 24
 
25
-    /**
26
-     * @type string $_active_message_type_name
27
-     */
28
-    protected $_active_message_type_name = '';
29
-
30
-    /**
31
-     * @type EE_messenger $_active_messenger
32
-     */
33
-    protected $_active_messenger;
34
-
35
-    protected $_activate_state;
36
-
37
-    protected $_activate_meta_box_type;
38
-
39
-    protected $_current_message_meta_box;
40
-
41
-    protected $_current_message_meta_box_object;
42
-
43
-    protected $_context_switcher;
44
-
45
-    protected $_shortcodes           = [];
46
-
47
-    protected $_active_messengers    = [];
48
-
49
-    protected $_active_message_types = [];
50
-
51
-    /**
52
-     * @var EE_Message_Template_Group $_message_template_group
53
-     */
54
-    protected $_message_template_group;
55
-
56
-    protected $_m_mt_settings = [];
57
-
58
-
59
-    /**
60
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
61
-     * IF there is no group then it gets automatically set to the Default template pack.
62
-     *
63
-     * @since 4.5.0
64
-     *
65
-     * @var EE_Messages_Template_Pack
66
-     */
67
-    protected $_template_pack;
68
-
69
-
70
-    /**
71
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
72
-     * group is.  If there is no group then it automatically gets set to default.
73
-     *
74
-     * @since 4.5.0
75
-     *
76
-     * @var string
77
-     */
78
-    protected $_variation;
79
-
80
-
81
-    /**
82
-     * @param bool $routing
83
-     * @throws EE_Error
84
-     */
85
-    public function __construct($routing = true)
86
-    {
87
-        // make sure messages autoloader is running
88
-        EED_Messages::set_autoloaders();
89
-        parent::__construct($routing);
90
-    }
91
-
92
-
93
-    protected function _init_page_props()
94
-    {
95
-        $this->page_slug        = EE_MSG_PG_SLUG;
96
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
97
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
98
-        $this->_admin_base_path = EE_MSG_ADMIN;
99
-
100
-        $this->_activate_state = isset($this->_req_data['activate_state'])
101
-            ? (array) $this->_req_data['activate_state']
102
-            : [];
103
-
104
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
105
-        $this->_load_message_resource_manager();
106
-    }
107
-
108
-
109
-    /**
110
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
111
-     *
112
-     * @throws EE_Error
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws InvalidArgumentException
116
-     * @throws ReflectionException
117
-     */
118
-    protected function _load_message_resource_manager()
119
-    {
120
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
121
-    }
122
-
123
-
124
-    /**
125
-     * @return array
126
-     * @throws EE_Error
127
-     * @throws InvalidArgumentException
128
-     * @throws InvalidDataTypeException
129
-     * @throws InvalidInterfaceException
130
-     * @deprecated 4.9.9.rc.014
131
-     */
132
-    public function get_messengers_for_list_table()
133
-    {
134
-        EE_Error::doing_it_wrong(
135
-            __METHOD__,
136
-            sprintf(
137
-                esc_html__(
138
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
139
-                    'event_espresso'
140
-                ),
141
-                'Messages_Admin_Page::get_messengers_select_input()'
142
-            ),
143
-            '4.9.9.rc.014'
144
-        );
145
-
146
-        $m_values          = [];
147
-        $active_messengers = EEM_Message::instance()->get_all(['group_by' => 'MSG_messenger']);
148
-        // setup messengers for selects
149
-        $i = 1;
150
-        foreach ($active_messengers as $active_messenger) {
151
-            if ($active_messenger instanceof EE_Message) {
152
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
153
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
154
-                $i++;
155
-            }
156
-        }
157
-
158
-        return $m_values;
159
-    }
160
-
161
-
162
-    /**
163
-     * @return array
164
-     * @throws EE_Error
165
-     * @throws InvalidArgumentException
166
-     * @throws InvalidDataTypeException
167
-     * @throws InvalidInterfaceException
168
-     * @deprecated 4.9.9.rc.014
169
-     */
170
-    public function get_message_types_for_list_table()
171
-    {
172
-        EE_Error::doing_it_wrong(
173
-            __METHOD__,
174
-            sprintf(
175
-                esc_html__(
176
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
177
-                    'event_espresso'
178
-                ),
179
-                'Messages_Admin_Page::get_message_types_select_input()'
180
-            ),
181
-            '4.9.9.rc.014'
182
-        );
183
-
184
-        $mt_values       = [];
185
-        $active_messages = EEM_Message::instance()->get_all(['group_by' => 'MSG_message_type']);
186
-        $i               = 1;
187
-        foreach ($active_messages as $active_message) {
188
-            if ($active_message instanceof EE_Message) {
189
-                $mt_values[ $i ]['id']   = $active_message->message_type();
190
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
191
-                $i++;
192
-            }
193
-        }
194
-
195
-        return $mt_values;
196
-    }
197
-
198
-
199
-    /**
200
-     * @return array
201
-     * @throws EE_Error
202
-     * @throws InvalidArgumentException
203
-     * @throws InvalidDataTypeException
204
-     * @throws InvalidInterfaceException
205
-     * @deprecated 4.9.9.rc.014
206
-     */
207
-    public function get_contexts_for_message_types_for_list_table()
208
-    {
209
-        EE_Error::doing_it_wrong(
210
-            __METHOD__,
211
-            sprintf(
212
-                esc_html__(
213
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
214
-                    'event_espresso'
215
-                ),
216
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
217
-            ),
218
-            '4.9.9.rc.014'
219
-        );
220
-
221
-        $contexts                = [];
222
-        $active_message_contexts = EEM_Message::instance()->get_all(['group_by' => 'MSG_context']);
223
-        foreach ($active_message_contexts as $active_message) {
224
-            if ($active_message instanceof EE_Message) {
225
-                $message_type = $active_message->message_type_object();
226
-                if ($message_type instanceof EE_message_type) {
227
-                    $message_type_contexts = $message_type->get_contexts();
228
-                    foreach ($message_type_contexts as $context => $context_details) {
229
-                        $contexts[ $context ] = $context_details['label'];
230
-                    }
231
-                }
232
-            }
233
-        }
234
-
235
-        return $contexts;
236
-    }
237
-
238
-
239
-    /**
240
-     * Generate select input with provided messenger options array.
241
-     *
242
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
243
-     *                                 labels.
244
-     * @return string
245
-     * @throws EE_Error
246
-     */
247
-    public function get_messengers_select_input($messenger_options)
248
-    {
249
-        // if empty or just one value then just return an empty string
250
-        if (
251
-            empty($messenger_options)
252
-            || ! is_array($messenger_options)
253
-            || count($messenger_options) === 1
254
-        ) {
255
-            return '';
256
-        }
257
-        // merge in default
258
-        $messenger_options = array_merge(
259
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
260
-            $messenger_options
261
-        );
262
-        $input             = new EE_Select_Input(
263
-            $messenger_options,
264
-            [
265
-                'html_name'  => 'ee_messenger_filter_by',
266
-                'html_id'    => 'ee_messenger_filter_by',
267
-                'html_class' => 'wide',
268
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
269
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
270
-                    : 'none_selected',
271
-            ]
272
-        );
273
-
274
-        return $input->get_html_for_input();
275
-    }
276
-
277
-
278
-    /**
279
-     * Generate select input with provided message type options array.
280
-     *
281
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
282
-     *                                    message type labels
283
-     * @return string
284
-     * @throws EE_Error
285
-     */
286
-    public function get_message_types_select_input($message_type_options)
287
-    {
288
-        // if empty or count of options is 1 then just return an empty string
289
-        if (
290
-            empty($message_type_options)
291
-            || ! is_array($message_type_options)
292
-            || count($message_type_options) === 1
293
-        ) {
294
-            return '';
295
-        }
296
-        // merge in default
297
-        $message_type_options = array_merge(
298
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
299
-            $message_type_options
300
-        );
301
-        $input                = new EE_Select_Input(
302
-            $message_type_options,
303
-            [
304
-                'html_name'  => 'ee_message_type_filter_by',
305
-                'html_id'    => 'ee_message_type_filter_by',
306
-                'html_class' => 'wide',
307
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
308
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
309
-                    : 'none_selected',
310
-            ]
311
-        );
312
-
313
-        return $input->get_html_for_input();
314
-    }
315
-
316
-
317
-    /**
318
-     * Generate select input with provide message type contexts array.
319
-     *
320
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
321
-     *                               context label.
322
-     * @return string
323
-     * @throws EE_Error
324
-     */
325
-    public function get_contexts_for_message_types_select_input($context_options)
326
-    {
327
-        // if empty or count of options is one then just return empty string
328
-        if (
329
-            empty($context_options)
330
-            || ! is_array($context_options)
331
-            || count($context_options) === 1
332
-        ) {
333
-            return '';
334
-        }
335
-        // merge in default
336
-        $context_options = array_merge(
337
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
338
-            $context_options
339
-        );
340
-        $input           = new EE_Select_Input(
341
-            $context_options,
342
-            [
343
-                'html_name'  => 'ee_context_filter_by',
344
-                'html_id'    => 'ee_context_filter_by',
345
-                'html_class' => 'wide',
346
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
347
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
348
-                    : 'none_selected',
349
-            ]
350
-        );
351
-
352
-        return $input->get_html_for_input();
353
-    }
354
-
355
-
356
-    protected function _ajax_hooks()
357
-    {
358
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
359
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
360
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
361
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
362
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
363
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
364
-    }
365
-
366
-
367
-    protected function _define_page_props()
368
-    {
369
-        $this->_admin_page_title = $this->page_label;
370
-        $this->_labels           = [
371
-            'buttons'    => [
372
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
373
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
374
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
375
-            ],
376
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
377
-        ];
378
-    }
379
-
380
-
381
-    /**
382
-     *        an array for storing key => value pairs of request actions and their corresponding methods
383
-     *
384
-     * @access protected
385
-     * @return void
386
-     */
387
-    protected function _set_page_routes()
388
-    {
389
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
390
-            ? $this->_req_data['GRP_ID']
391
-            : 0;
392
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
393
-            ? $this->_req_data['id']
394
-            : $grp_id;
395
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
396
-            ? $this->_req_data['MSG_ID']
397
-            : 0;
398
-
399
-        $this->_page_routes = [
400
-            'default'                          => [
401
-                'func'       => '_message_queue_list_table',
402
-                'capability' => 'ee_read_global_messages',
403
-            ],
404
-            'global_mtps'                      => [
405
-                'func'       => '_ee_default_messages_overview_list_table',
406
-                'capability' => 'ee_read_global_messages',
407
-            ],
408
-            'custom_mtps'                      => [
409
-                'func'       => '_custom_mtps_preview',
410
-                'capability' => 'ee_read_messages',
411
-            ],
412
-            'add_new_message_template'         => [
413
-                'func'       => '_add_message_template',
414
-                'capability' => 'ee_edit_messages',
415
-                'noheader'   => true,
416
-            ],
417
-            'edit_message_template'            => [
418
-                'func'       => '_edit_message_template',
419
-                'capability' => 'ee_edit_message',
420
-                'obj_id'     => $grp_id,
421
-            ],
422
-            'preview_message'                  => [
423
-                'func'               => '_preview_message',
424
-                'capability'         => 'ee_read_message',
425
-                'obj_id'             => $grp_id,
426
-                'noheader'           => true,
427
-                'headers_sent_route' => 'display_preview_message',
428
-            ],
429
-            'display_preview_message'          => [
430
-                'func'       => '_display_preview_message',
431
-                'capability' => 'ee_read_message',
432
-                'obj_id'     => $grp_id,
433
-            ],
434
-            'insert_message_template'          => [
435
-                'func'       => '_insert_or_update_message_template',
436
-                'capability' => 'ee_edit_messages',
437
-                'args'       => ['new' => true],
438
-                'noheader'   => true,
439
-            ],
440
-            'update_message_template'          => [
441
-                'func'       => '_insert_or_update_message_template',
442
-                'capability' => 'ee_edit_message',
443
-                'obj_id'     => $grp_id,
444
-                'args'       => ['new' => false],
445
-                'noheader'   => true,
446
-            ],
447
-            'trash_message_template'           => [
448
-                'func'       => '_trash_or_restore_message_template',
449
-                'capability' => 'ee_delete_message',
450
-                'obj_id'     => $grp_id,
451
-                'args'       => ['trash' => true, 'all' => true],
452
-                'noheader'   => true,
453
-            ],
454
-            'trash_message_template_context'   => [
455
-                'func'       => '_trash_or_restore_message_template',
456
-                'capability' => 'ee_delete_message',
457
-                'obj_id'     => $grp_id,
458
-                'args'       => ['trash' => true],
459
-                'noheader'   => true,
460
-            ],
461
-            'restore_message_template'         => [
462
-                'func'       => '_trash_or_restore_message_template',
463
-                'capability' => 'ee_delete_message',
464
-                'obj_id'     => $grp_id,
465
-                'args'       => ['trash' => false, 'all' => true],
466
-                'noheader'   => true,
467
-            ],
468
-            'restore_message_template_context' => [
469
-                'func'       => '_trash_or_restore_message_template',
470
-                'capability' => 'ee_delete_message',
471
-                'obj_id'     => $grp_id,
472
-                'args'       => ['trash' => false],
473
-                'noheader'   => true,
474
-            ],
475
-            'delete_message_template'          => [
476
-                'func'       => '_delete_message_template',
477
-                'capability' => 'ee_delete_message',
478
-                'obj_id'     => $grp_id,
479
-                'noheader'   => true,
480
-            ],
481
-            'reset_to_default'                 => [
482
-                'func'       => '_reset_to_default_template',
483
-                'capability' => 'ee_edit_message',
484
-                'obj_id'     => $grp_id,
485
-                'noheader'   => true,
486
-            ],
487
-            'settings'                         => [
488
-                'func'       => '_settings',
489
-                'capability' => 'manage_options',
490
-            ],
491
-            'update_global_settings'           => [
492
-                'func'       => '_update_global_settings',
493
-                'capability' => 'manage_options',
494
-                'noheader'   => true,
495
-            ],
496
-            'generate_now'                     => [
497
-                'func'       => '_generate_now',
498
-                'capability' => 'ee_send_message',
499
-                'noheader'   => true,
500
-            ],
501
-            'generate_and_send_now'            => [
502
-                'func'       => '_generate_and_send_now',
503
-                'capability' => 'ee_send_message',
504
-                'noheader'   => true,
505
-            ],
506
-            'queue_for_resending'              => [
507
-                'func'       => '_queue_for_resending',
508
-                'capability' => 'ee_send_message',
509
-                'noheader'   => true,
510
-            ],
511
-            'send_now'                         => [
512
-                'func'       => '_send_now',
513
-                'capability' => 'ee_send_message',
514
-                'noheader'   => true,
515
-            ],
516
-            'delete_ee_message'                => [
517
-                'func'       => '_delete_ee_messages',
518
-                'capability' => 'ee_delete_messages',
519
-                'noheader'   => true,
520
-            ],
521
-            'delete_ee_messages'               => [
522
-                'func'       => '_delete_ee_messages',
523
-                'capability' => 'ee_delete_messages',
524
-                'noheader'   => true,
525
-                'obj_id'     => $msg_id,
526
-            ],
527
-        ];
528
-    }
529
-
530
-
531
-    protected function _set_page_config()
532
-    {
533
-        $this->_page_config = [
534
-            'default'                  => [
535
-                'nav'           => [
536
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
537
-                    'order' => 10,
538
-                ],
539
-                'list_table'    => 'EE_Message_List_Table',
540
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
541
-                'require_nonce' => false,
542
-            ],
543
-            'global_mtps'              => [
544
-                'nav'           => [
545
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
546
-                    'order' => 20,
547
-                ],
548
-                'list_table'    => 'Messages_Template_List_Table',
549
-                'help_tabs'     => [
550
-                    'messages_overview_help_tab'                                => [
551
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
552
-                        'filename' => 'messages_overview',
553
-                    ],
554
-                    'messages_overview_messages_table_column_headings_help_tab' => [
555
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
556
-                        'filename' => 'messages_overview_table_column_headings',
557
-                    ],
558
-                    'messages_overview_messages_filters_help_tab'               => [
559
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
560
-                        'filename' => 'messages_overview_filters',
561
-                    ],
562
-                    'messages_overview_messages_views_help_tab'                 => [
563
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
564
-                        'filename' => 'messages_overview_views',
565
-                    ],
566
-                    'message_overview_message_types_help_tab'                   => [
567
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
568
-                        'filename' => 'messages_overview_types',
569
-                    ],
570
-                    'messages_overview_messengers_help_tab'                     => [
571
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
572
-                        'filename' => 'messages_overview_messengers',
573
-                    ],
574
-                ],
575
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
576
-                // 'help_tour'     => array('Messages_Overview_Help_Tour'),
577
-                'require_nonce' => false,
578
-            ],
579
-            'custom_mtps'              => [
580
-                'nav'           => [
581
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
582
-                    'order' => 30,
583
-                ],
584
-                'help_tabs'     => [],
585
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
586
-                // 'help_tour'     => array(),
587
-                'require_nonce' => false,
588
-            ],
589
-            'add_new_message_template' => [
590
-                'nav'           => [
591
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
592
-                    'order'      => 5,
593
-                    'persistent' => false,
594
-                ],
595
-                'require_nonce' => false,
596
-            ],
597
-            'edit_message_template'    => [
598
-                'labels'        => [
599
-                    'buttons'    => [
600
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
601
-                    ],
602
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
603
-                ],
604
-                'nav'           => [
605
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
606
-                    'order'      => 5,
607
-                    'persistent' => false,
608
-                    'url'        => '',
609
-                ],
610
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
611
-                'has_metaboxes' => true,
612
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
613
-                // 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
614
-                'help_tabs'     => [
615
-                    'edit_message_template'            => [
616
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
617
-                        'callback' => 'edit_message_template_help_tab',
618
-                    ],
619
-                    'message_templates_help_tab'       => [
620
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
621
-                        'filename' => 'messages_templates',
622
-                    ],
623
-                    'message_template_shortcodes'      => [
624
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
625
-                        'callback' => 'message_template_shortcodes_help_tab',
626
-                    ],
627
-                    'message_preview_help_tab'         => [
628
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
629
-                        'filename' => 'messages_preview',
630
-                    ],
631
-                    'messages_overview_other_help_tab' => [
632
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
633
-                        'filename' => 'messages_overview_other',
634
-                    ],
635
-                ],
636
-                'require_nonce' => false,
637
-            ],
638
-            'display_preview_message'  => [
639
-                'nav'           => [
640
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
641
-                    'order'      => 5,
642
-                    'url'        => '',
643
-                    'persistent' => false,
644
-                ],
645
-                'help_tabs'     => [
646
-                    'preview_message' => [
647
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
648
-                        'callback' => 'preview_message_help_tab',
649
-                    ],
650
-                ],
651
-                'require_nonce' => false,
652
-            ],
653
-            'settings'                 => [
654
-                'nav'           => [
655
-                    'label' => esc_html__('Settings', 'event_espresso'),
656
-                    'order' => 40,
657
-                ],
658
-                'metaboxes'     => ['_messages_settings_metaboxes'],
659
-                'help_tabs'     => [
660
-                    'messages_settings_help_tab'               => [
661
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
662
-                        'filename' => 'messages_settings',
663
-                    ],
664
-                    'messages_settings_message_types_help_tab' => [
665
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
666
-                        'filename' => 'messages_settings_message_types',
667
-                    ],
668
-                    'messages_settings_messengers_help_tab'    => [
669
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
670
-                        'filename' => 'messages_settings_messengers',
671
-                    ],
672
-                ],
673
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
674
-                // 'help_tour'     => array('Messages_Settings_Help_Tour'),
675
-                'require_nonce' => false,
676
-            ],
677
-        ];
678
-    }
679
-
680
-
681
-    protected function _add_screen_options()
682
-    {
683
-        // todo
684
-    }
685
-
686
-
687
-    protected function _add_screen_options_global_mtps()
688
-    {
689
-        /**
690
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
691
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
692
-         */
693
-        $page_title              = $this->_admin_page_title;
694
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
695
-        $this->_per_page_screen_option();
696
-        $this->_admin_page_title = $page_title;
697
-    }
698
-
699
-
700
-    protected function _add_screen_options_default()
701
-    {
702
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
703
-        $this->_per_page_screen_option();
704
-    }
705
-
706
-
707
-    // none of the below group are currently used for Messages
708
-    protected function _add_feature_pointers()
709
-    {
710
-    }
711
-
712
-
713
-    public function admin_init()
714
-    {
715
-    }
716
-
717
-
718
-    public function admin_notices()
719
-    {
720
-    }
721
-
722
-
723
-    public function admin_footer_scripts()
724
-    {
725
-    }
726
-
727
-
728
-    public function messages_help_tab()
729
-    {
730
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
731
-    }
732
-
733
-
734
-    public function messengers_help_tab()
735
-    {
736
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
737
-    }
738
-
739
-
740
-    public function message_types_help_tab()
741
-    {
742
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
743
-    }
744
-
745
-
746
-    public function messages_overview_help_tab()
747
-    {
748
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
749
-    }
750
-
751
-
752
-    public function message_templates_help_tab()
753
-    {
754
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
755
-    }
756
-
757
-
758
-    public function edit_message_template_help_tab()
759
-    {
760
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
761
-                        . esc_attr__('Editor Title', 'event_espresso')
762
-                        . '" />';
763
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
764
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
765
-                        . '" />';
766
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
767
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
768
-                        . '" />';
769
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
770
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
771
-                        . '" />';
772
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
773
-                        . esc_attr__('Publish Metabox', 'event_espresso')
774
-                        . '" />';
775
-        EEH_Template::display_template(
776
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
777
-            $args
778
-        );
779
-    }
780
-
781
-
782
-    public function message_template_shortcodes_help_tab()
783
-    {
784
-        $this->_set_shortcodes();
785
-        $args['shortcodes'] = $this->_shortcodes;
786
-        EEH_Template::display_template(
787
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
788
-            $args
789
-        );
790
-    }
791
-
792
-
793
-    public function preview_message_help_tab()
794
-    {
795
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
796
-    }
797
-
798
-
799
-    public function settings_help_tab()
800
-    {
801
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
802
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
803
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
804
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
805
-        $args['img3'] = '<div class="switch">'
806
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
807
-                        . ' type="checkbox" checked="checked">'
808
-                        . '<label for="ee-on-off-toggle-on"></label>'
809
-                        . '</div>';
810
-        $args['img4'] = '<div class="switch">'
811
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
812
-                        . ' type="checkbox">'
813
-                        . '<label for="ee-on-off-toggle-on"></label>'
814
-                        . '</div>';
815
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
816
-    }
817
-
818
-
819
-    public function load_scripts_styles()
820
-    {
821
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
822
-        wp_enqueue_style('espresso_ee_msg');
823
-
824
-        wp_register_script(
825
-            'ee-messages-settings',
826
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
827
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
828
-            EVENT_ESPRESSO_VERSION,
829
-            true
830
-        );
831
-        wp_register_script(
832
-            'ee-msg-list-table-js',
833
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
834
-            ['ee-dialog'],
835
-            EVENT_ESPRESSO_VERSION
836
-        );
837
-    }
838
-
839
-
840
-    public function load_scripts_styles_default()
841
-    {
842
-        wp_enqueue_script('ee-msg-list-table-js');
843
-    }
844
-
845
-
846
-    public function wp_editor_css($mce_css)
847
-    {
848
-        // if we're on the edit_message_template route
849
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
850
-            $message_type_name = $this->_active_message_type_name;
851
-
852
-            // we're going to REPLACE the existing mce css
853
-            // we need to get the css file location from the active messenger
854
-            $mce_css = $this->_active_messenger->get_variation(
855
-                $this->_template_pack,
856
-                $message_type_name,
857
-                true,
858
-                'wpeditor',
859
-                $this->_variation
860
-            );
861
-        }
862
-
863
-        return $mce_css;
864
-    }
865
-
866
-
867
-    public function load_scripts_styles_edit_message_template()
868
-    {
869
-
870
-        $this->_set_shortcodes();
871
-
872
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
873
-            esc_html__(
874
-                '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.',
875
-                'event_espresso'
876
-            ),
877
-            $this->_message_template_group->messenger_obj()->label['singular'],
878
-            $this->_message_template_group->message_type_obj()->label['singular']
879
-        );
880
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
881
-            '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?',
882
-            'event_espresso'
883
-        );
884
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
885
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
886
-            'event_espresso'
887
-        );
888
-
889
-        wp_register_script(
890
-            'ee_msgs_edit_js',
891
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
892
-            ['jquery'],
893
-            EVENT_ESPRESSO_VERSION
894
-        );
895
-
896
-        wp_enqueue_script('ee_admin_js');
897
-        wp_enqueue_script('ee_msgs_edit_js');
898
-
899
-        // add in special css for tiny_mce
900
-        add_filter('mce_css', [$this, 'wp_editor_css']);
901
-    }
902
-
903
-
904
-    public function load_scripts_styles_display_preview_message()
905
-    {
906
-
907
-        $this->_set_message_template_group();
908
-
909
-        if (isset($this->_req_data['messenger'])) {
910
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
911
-                $this->_req_data['messenger']
912
-            );
913
-        }
914
-
915
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
916
-
917
-
918
-        wp_enqueue_style(
919
-            'espresso_preview_css',
920
-            $this->_active_messenger->get_variation(
921
-                $this->_template_pack,
922
-                $message_type_name,
923
-                true,
924
-                'preview',
925
-                $this->_variation
926
-            )
927
-        );
928
-    }
929
-
930
-
931
-    public function load_scripts_styles_settings()
932
-    {
933
-        wp_register_style(
934
-            'ee-message-settings',
935
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
936
-            [],
937
-            EVENT_ESPRESSO_VERSION
938
-        );
939
-        wp_enqueue_style('ee-text-links');
940
-        wp_enqueue_style('ee-message-settings');
941
-        wp_enqueue_script('ee-messages-settings');
942
-    }
943
-
944
-
945
-    /**
946
-     * set views array for List Table
947
-     */
948
-    public function _set_list_table_views_global_mtps()
949
-    {
950
-        $this->_views = [
951
-            'in_use' => [
952
-                'slug'  => 'in_use',
953
-                'label' => esc_html__('In Use', 'event_espresso'),
954
-                'count' => 0,
955
-            ],
956
-        ];
957
-    }
958
-
959
-
960
-    /**
961
-     * Set views array for the Custom Template List Table
962
-     */
963
-    public function _set_list_table_views_custom_mtps()
964
-    {
965
-        $this->_set_list_table_views_global_mtps();
966
-        $this->_views['in_use']['bulk_action'] = [
967
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
968
-        ];
969
-    }
970
-
971
-
972
-    /**
973
-     * set views array for message queue list table
974
-     *
975
-     * @throws InvalidDataTypeException
976
-     * @throws InvalidInterfaceException
977
-     * @throws InvalidArgumentException
978
-     * @throws EE_Error
979
-     * @throws ReflectionException
980
-     */
981
-    public function _set_list_table_views_default()
982
-    {
983
-        EE_Registry::instance()->load_helper('Template');
984
-
985
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
986
-            'ee_send_message',
987
-            'message_list_table_bulk_actions'
988
-        )
989
-            ? [
990
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
991
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
992
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
993
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
994
-            ]
995
-            : [];
996
-
997
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
998
-            'ee_delete_messages',
999
-            'message_list_table_bulk_actions'
1000
-        )
1001
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1002
-            : [];
1003
-
1004
-
1005
-        $this->_views = [
1006
-            'all' => [
1007
-                'slug'        => 'all',
1008
-                'label'       => esc_html__('All', 'event_espresso'),
1009
-                'count'       => 0,
1010
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1011
-            ],
1012
-        ];
1013
-
1014
-
1015
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
1016
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1017
-                continue;
1018
-            }
1019
-            $status_bulk_actions = $common_bulk_actions;
1020
-            // unset bulk actions not applying to status
1021
-            if (! empty($status_bulk_actions)) {
1022
-                switch ($status) {
1023
-                    case EEM_Message::status_idle:
1024
-                    case EEM_Message::status_resend:
1025
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1026
-                        break;
1027
-
1028
-                    case EEM_Message::status_failed:
1029
-                    case EEM_Message::status_debug_only:
1030
-                    case EEM_Message::status_messenger_executing:
1031
-                        $status_bulk_actions = [];
1032
-                        break;
1033
-
1034
-                    case EEM_Message::status_incomplete:
1035
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1036
-                        break;
1037
-
1038
-                    case EEM_Message::status_retry:
1039
-                    case EEM_Message::status_sent:
1040
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1041
-                        break;
1042
-                }
1043
-            }
1044
-
1045
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1046
-            if ($status === EEM_Message::status_messenger_executing) {
1047
-                continue;
1048
-            }
1049
-
1050
-            $this->_views[ strtolower($status) ] = [
1051
-                'slug'        => strtolower($status),
1052
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1053
-                'count'       => 0,
1054
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1055
-            ];
1056
-        }
1057
-    }
1058
-
1059
-
1060
-    protected function _ee_default_messages_overview_list_table()
1061
-    {
1062
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1063
-        $this->display_admin_list_table_page_with_no_sidebar();
1064
-    }
1065
-
1066
-
1067
-    /**
1068
-     * @throws ReflectionException
1069
-     * @throws EE_Error
1070
-     */
1071
-    protected function _message_queue_list_table()
1072
-    {
1073
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1074
-        $this->_template_args['per_column']        = 6;
1075
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1076
-        $message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1077
-        $this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1078
-        $this->display_admin_list_table_page_with_no_sidebar();
1079
-    }
1080
-
1081
-
1082
-    protected function _message_legend_items()
1083
-    {
1084
-
1085
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1086
-        $action_items       = [];
1087
-
1088
-        foreach ($action_css_classes as $action_item => $action_details) {
1089
-            if ($action_item === 'see_notifications_for') {
1090
-                continue;
1091
-            }
1092
-            $action_items[ $action_item ] = [
1093
-                'class' => $action_details['css_class'],
1094
-                'desc'  => $action_details['label'],
1095
-            ];
1096
-        }
1097
-
1098
-        /** @type array $status_items status legend setup */
1099
-        $status_items = [
1100
-            'sent_status'                => [
1101
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1102
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1103
-            ],
1104
-            'idle_status'                => [
1105
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1106
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1107
-            ],
1108
-            'failed_status'              => [
1109
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1110
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1111
-            ],
1112
-            'messenger_executing_status' => [
1113
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1114
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1115
-            ],
1116
-            'resend_status'              => [
1117
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1118
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1119
-            ],
1120
-            'incomplete_status'          => [
1121
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1122
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1123
-            ],
1124
-            'retry_status'               => [
1125
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1126
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1127
-            ],
1128
-        ];
1129
-        if (EEM_Message::debug()) {
1130
-            $status_items['debug_only_status'] = [
1131
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1132
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1133
-            ];
1134
-        }
1135
-
1136
-        return array_merge($action_items, $status_items);
1137
-    }
1138
-
1139
-
1140
-    protected function _custom_mtps_preview()
1141
-    {
1142
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1143
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1144
-                                                . ' alt="' . esc_attr__(
1145
-                                                    'Preview Custom Message Templates screenshot',
1146
-                                                    'event_espresso'
1147
-                                                ) . '" />';
1148
-        $this->_template_args['preview_text'] = '<strong>'
1149
-                                                . esc_html__(
1150
-                                                    '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.',
1151
-                                                    'event_espresso'
1152
-                                                )
1153
-                                                . '</strong>';
1154
-
1155
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1156
-    }
1157
-
1158
-
1159
-    /**
1160
-     * get_message_templates
1161
-     * This gets all the message templates for listing on the overview list.
1162
-     *
1163
-     * @access public
1164
-     * @param int    $perpage the amount of templates groups to show per page
1165
-     * @param string $type    the current _view we're getting templates for
1166
-     * @param bool   $count   return count?
1167
-     * @param bool   $all     disregard any paging info (get all data);
1168
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1169
-     * @return array
1170
-     * @throws EE_Error
1171
-     * @throws InvalidArgumentException
1172
-     * @throws InvalidDataTypeException
1173
-     * @throws InvalidInterfaceException
1174
-     */
1175
-    public function get_message_templates(
1176
-        $perpage = 10,
1177
-        $type = 'in_use',
1178
-        $count = false,
1179
-        $all = false,
1180
-        $global = true
1181
-    ) {
1182
-
1183
-        $MTP = EEM_Message_Template_Group::instance();
1184
-
1185
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1186
-        $orderby                    = $this->_req_data['orderby'];
1187
-
1188
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1189
-            ? $this->_req_data['order']
1190
-            : 'ASC';
1191
-
1192
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1193
-            ? $this->_req_data['paged']
1194
-            : 1;
1195
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1196
-            ? $this->_req_data['perpage']
1197
-            : $perpage;
1198
-
1199
-        $offset = ($current_page - 1) * $per_page;
1200
-        $limit  = $all ? null : [$offset, $per_page];
1201
-
1202
-
1203
-        // options will match what is in the _views array property
1204
-        switch ($type) {
1205
-            case 'in_use':
1206
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1207
-                break;
1208
-            default:
1209
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1210
-        }
1211
-
1212
-        return $templates;
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * filters etc might need a list of installed message_types
1218
-     *
1219
-     * @return array an array of message type objects
1220
-     */
1221
-    public function get_installed_message_types()
1222
-    {
1223
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1224
-        $installed               = [];
1225
-
1226
-        foreach ($installed_message_types as $message_type) {
1227
-            $installed[ $message_type->name ] = $message_type;
1228
-        }
1229
-
1230
-        return $installed;
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     * _add_message_template
1236
-     *
1237
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1238
-     *
1239
-     * @param string $message_type
1240
-     * @param string $messenger
1241
-     * @param string $GRP_ID
1242
-     *
1243
-     * @throws EE_error
1244
-     */
1245
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1246
-    {
1247
-        // set values override any request data
1248
-        $message_type = ! empty($message_type) ? $message_type : $this->request->getRequestParam('message_type');
1249
-        $messenger    = ! empty($messenger) ? $messenger : $this->request->getRequestParam('messenger');
1250
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1251
-
1252
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1253
-        if (empty($message_type) || empty($messenger)) {
1254
-            throw new EE_Error(
1255
-                esc_html__(
1256
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1257
-                    'event_espresso'
1258
-                )
1259
-            );
1260
-        }
1261
-
1262
-        // we need the GRP_ID for the template being used as the base for the new template
1263
-        if (empty($GRP_ID)) {
1264
-            throw new EE_Error(
1265
-                esc_html__(
1266
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1267
-                    'event_espresso'
1268
-                )
1269
-            );
1270
-        }
1271
-
1272
-        // let's just make sure the template gets generated!
1273
-
1274
-        // we need to reassign some variables for what the insert is expecting
1275
-        $this->_req_data['MTP_messenger']    = $messenger;
1276
-        $this->_req_data['MTP_message_type'] = $message_type;
1277
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1278
-        $this->_insert_or_update_message_template(true);
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * public wrapper for the _add_message_template method
1284
-     *
1285
-     * @param string $message_type     message type slug
1286
-     * @param string $messenger        messenger slug
1287
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1288
-     *                                 off of.
1289
-     * @throws EE_error
1290
-     */
1291
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1292
-    {
1293
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1294
-    }
1295
-
1296
-
1297
-    /**
1298
-     * _edit_message_template
1299
-     *
1300
-     * @access protected
1301
-     * @return void
1302
-     * @throws InvalidIdentifierException
1303
-     * @throws DomainException
1304
-     * @throws EE_Error
1305
-     * @throws InvalidArgumentException
1306
-     * @throws ReflectionException
1307
-     * @throws InvalidDataTypeException
1308
-     * @throws InvalidInterfaceException
1309
-     */
1310
-    protected function _edit_message_template()
1311
-    {
1312
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1313
-        $template_fields = '';
1314
-        $sidebar_fields  = '';
1315
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1316
-        // valid html in the templates.
1317
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1318
-
1319
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1320
-            ? absint($this->_req_data['id'])
1321
-            : false;
1322
-
1323
-        $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
1324
-            ? absint($this->_req_data['evt_id'])
1325
-            : false;
1326
-
1327
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1328
-        $message_template_group = $this->_message_template_group;
1329
-        $c_label                = $message_template_group->context_label();
1330
-        $c_config               = $message_template_group->contexts_config();
1331
-
1332
-        reset($c_config);
1333
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1334
-            ? strtolower($this->_req_data['context'])
1335
-            : key($c_config);
1336
-
1337
-
1338
-        if (empty($GRP_ID)) {
1339
-            $action                         = 'insert_message_template';
1340
-            $edit_message_template_form_url = add_query_arg(
1341
-                ['action' => $action, 'noheader' => true],
1342
-                EE_MSG_ADMIN_URL
1343
-            );
1344
-        } else {
1345
-            $action                         = 'update_message_template';
1346
-            $edit_message_template_form_url = add_query_arg(
1347
-                ['action' => $action, 'noheader' => true],
1348
-                EE_MSG_ADMIN_URL
1349
-            );
1350
-        }
1351
-
1352
-        // set active messenger for this view
1353
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1354
-            $message_template_group->messenger()
1355
-        );
1356
-        $this->_active_message_type_name = $message_template_group->message_type();
1357
-
1358
-
1359
-        // Do we have any validation errors?
1360
-        $validators = $this->_get_transient();
1361
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1362
-
1363
-
1364
-        // we need to assemble the title from Various details
1365
-        $context_label = sprintf(
1366
-            esc_html__('(%s %s)', 'event_espresso'),
1367
-            $c_config[ $context ]['label'],
1368
-            ucwords($c_label['label'])
1369
-        );
1370
-
1371
-        $title = sprintf(
1372
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1373
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1374
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1375
-            $context_label
1376
-        );
1377
-
1378
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1379
-        $this->_template_args['message_template'] = $message_template_group;
1380
-        $this->_template_args['is_extra_fields']  = false;
1381
-
1382
-
1383
-        // let's get EEH_MSG_Template so we can get template form fields
1384
-        $template_field_structure = EEH_MSG_Template::get_fields(
1385
-            $message_template_group->messenger(),
1386
-            $message_template_group->message_type()
1387
-        );
1388
-
1389
-        if (! $template_field_structure) {
1390
-            $template_field_structure = false;
1391
-            $template_fields          = esc_html__(
1392
-                'There was an error in assembling the fields for this display (you should see an error message)',
1393
-                'event_espresso'
1394
-            );
1395
-        }
1396
-
1397
-
1398
-        $message_templates = $message_template_group->context_templates();
1399
-
1400
-
1401
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1402
-        // will get handled in the "extra" array.
1403
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1404
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1405
-                unset($template_field_structure[ $context ][ $reference_field ]);
1406
-            }
1407
-        }
1408
-
1409
-        // let's loop through the template_field_structure and actually assemble the input fields!
1410
-        if (! empty($template_field_structure)) {
1411
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1412
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1413
-                // the extra array and reset them.
1414
-                if ($template_field === 'extra') {
1415
-                    $this->_template_args['is_extra_fields'] = true;
1416
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1417
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1418
-                        $content          = $message_template instanceof EE_Message_Template
1419
-                            ? $message_template->get('MTP_content')
1420
-                            : '';
1421
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1422
-                            // let's verify if we need this extra field via the shortcodes parameter.
1423
-                            $continue = false;
1424
-                            if (isset($extra_array['shortcodes_required'])) {
1425
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1426
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1427
-                                        $continue = true;
1428
-                                    }
1429
-                                }
1430
-                                if ($continue) {
1431
-                                    continue;
1432
-                                }
1433
-                            }
1434
-
1435
-                            $field_id                                  = $reference_field
1436
-                                                                         . '-'
1437
-                                                                         . $extra_field
1438
-                                                                         . '-content';
1439
-                            $template_form_fields[ $field_id ]         = $extra_array;
1440
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1441
-                                                                         . $reference_field
1442
-                                                                         . '][content]['
1443
-                                                                         . $extra_field . ']';
1444
-                            $css_class                                 = isset($extra_array['css_class'])
1445
-                                ? $extra_array['css_class']
1446
-                                : '';
1447
-
1448
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1449
-                                                                              && in_array($extra_field, $v_fields, true)
1450
-                                                                              && (
1451
-                                                                                  is_array($validators[ $extra_field ])
1452
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1453
-                                                                              )
1454
-                                ? 'validate-error ' . $css_class
1455
-                                : $css_class;
1456
-
1457
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1458
-                                                                          && isset($content[ $extra_field ])
1459
-                                ? $content[ $extra_field ]
1460
-                                : '';
1461
-
1462
-                            // do we have a validation error?  if we do then let's use that value instead
1463
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1464
-                                ? $validators[ $extra_field ]['value']
1465
-                                : $template_form_fields[ $field_id ]['value'];
1466
-
1467
-
1468
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1469
-
1470
-                            // shortcode selector
1471
-                            $field_name_to_use                                   = $extra_field === 'main'
1472
-                                ? 'content'
1473
-                                : $extra_field;
1474
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1475
-                                $field_name_to_use,
1476
-                                $field_id
1477
-                            );
1478
-
1479
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1480
-                                // we want to decode the entities
1481
-                                $template_form_fields[ $field_id ]['value'] =
1482
-                                    $template_form_fields[ $field_id ]['value'];
1483
-                            }
1484
-                        }
1485
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1486
-                        $templatefield_templatename_id = $reference_field . '-name';
1487
-
1488
-                        $template_form_fields[ $templatefield_MTP_id ] = [
1489
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1490
-                            'label'      => null,
1491
-                            'input'      => 'hidden',
1492
-                            'type'       => 'int',
1493
-                            'required'   => false,
1494
-                            'validation' => false,
1495
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1496
-                            'css_class'  => '',
1497
-                            'format'     => '%d',
1498
-                            'db-col'     => 'MTP_ID',
1499
-                        ];
1500
-
1501
-                        $template_form_fields[ $templatefield_templatename_id ] = [
1502
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1503
-                            'label'      => null,
1504
-                            'input'      => 'hidden',
1505
-                            'type'       => 'string',
1506
-                            'required'   => false,
1507
-                            'validation' => true,
1508
-                            'value'      => $reference_field,
1509
-                            'css_class'  => '',
1510
-                            'format'     => '%s',
1511
-                            'db-col'     => 'MTP_template_field',
1512
-                        ];
1513
-                    }
1514
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1515
-                } else {
1516
-                    $field_id                                   = $template_field . '-content';
1517
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1518
-                    $template_form_fields[ $field_id ]['name']  =
1519
-                        'MTP_template_fields[' . $template_field . '][content]';
1520
-                    $message_template                           =
1521
-                        isset($message_templates[ $context ][ $template_field ])
1522
-                            ? $message_templates[ $context ][ $template_field ]
1523
-                            : null;
1524
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1525
-                                                                  && is_array($message_templates[ $context ])
1526
-                                                                  && $message_template instanceof EE_Message_Template
1527
-                        ? $message_template->get('MTP_content')
1528
-                        : '';
1529
-
1530
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1531
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1532
-                        ? $validators[ $template_field ]['value']
1533
-                        : $template_form_fields[ $field_id ]['value'];
1534
-
1535
-
1536
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1537
-                    $css_class                                      = isset($field_setup_array['css_class'])
1538
-                        ? $field_setup_array['css_class']
1539
-                        : '';
1540
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1541
-                                                                      && in_array($template_field, $v_fields, true)
1542
-                                                                      && isset($validators[ $template_field ]['msg'])
1543
-                        ? 'validate-error ' . $css_class
1544
-                        : $css_class;
1545
-
1546
-                    // shortcode selector
1547
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1548
-                        $template_field,
1549
-                        $field_id
1550
-                    );
1551
-                }
1552
-
1553
-                // k took care of content field(s) now let's take care of others.
1554
-
1555
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1556
-                $templatefield_field_templatename_id = $template_field . '-name';
1557
-
1558
-                // foreach template field there are actually two form fields created
1559
-                $template_form_fields[ $templatefield_MTP_id ] = [
1560
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1561
-                    'label'      => null,
1562
-                    'input'      => 'hidden',
1563
-                    'type'       => 'int',
1564
-                    'required'   => false,
1565
-                    'validation' => true,
1566
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1567
-                    'css_class'  => '',
1568
-                    'format'     => '%d',
1569
-                    'db-col'     => 'MTP_ID',
1570
-                ];
1571
-
1572
-                $template_form_fields[ $templatefield_field_templatename_id ] = [
1573
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1574
-                    'label'      => null,
1575
-                    'input'      => 'hidden',
1576
-                    'type'       => 'string',
1577
-                    'required'   => false,
1578
-                    'validation' => true,
1579
-                    'value'      => $template_field,
1580
-                    'css_class'  => '',
1581
-                    'format'     => '%s',
1582
-                    'db-col'     => 'MTP_template_field',
1583
-                ];
1584
-            }
1585
-
1586
-            // add other fields
1587
-            $template_form_fields['ee-msg-current-context'] = [
1588
-                'name'       => 'MTP_context',
1589
-                'label'      => null,
1590
-                'input'      => 'hidden',
1591
-                'type'       => 'string',
1592
-                'required'   => false,
1593
-                'validation' => true,
1594
-                'value'      => $context,
1595
-                'css_class'  => '',
1596
-                'format'     => '%s',
1597
-                'db-col'     => 'MTP_context',
1598
-            ];
1599
-
1600
-            $template_form_fields['ee-msg-grp-id'] = [
1601
-                'name'       => 'GRP_ID',
1602
-                'label'      => null,
1603
-                'input'      => 'hidden',
1604
-                'type'       => 'int',
1605
-                'required'   => false,
1606
-                'validation' => true,
1607
-                'value'      => $GRP_ID,
1608
-                'css_class'  => '',
1609
-                'format'     => '%d',
1610
-                'db-col'     => 'GRP_ID',
1611
-            ];
1612
-
1613
-            $template_form_fields['ee-msg-messenger'] = [
1614
-                'name'       => 'MTP_messenger',
1615
-                'label'      => null,
1616
-                'input'      => 'hidden',
1617
-                'type'       => 'string',
1618
-                'required'   => false,
1619
-                'validation' => true,
1620
-                'value'      => $message_template_group->messenger(),
1621
-                'css_class'  => '',
1622
-                'format'     => '%s',
1623
-                'db-col'     => 'MTP_messenger',
1624
-            ];
1625
-
1626
-            $template_form_fields['ee-msg-message-type'] = [
1627
-                'name'       => 'MTP_message_type',
1628
-                'label'      => null,
1629
-                'input'      => 'hidden',
1630
-                'type'       => 'string',
1631
-                'required'   => false,
1632
-                'validation' => true,
1633
-                'value'      => $message_template_group->message_type(),
1634
-                'css_class'  => '',
1635
-                'format'     => '%s',
1636
-                'db-col'     => 'MTP_message_type',
1637
-            ];
1638
-
1639
-            $sidebar_form_fields['ee-msg-is-global'] = [
1640
-                'name'       => 'MTP_is_global',
1641
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1642
-                'input'      => 'hidden',
1643
-                'type'       => 'int',
1644
-                'required'   => false,
1645
-                'validation' => true,
1646
-                'value'      => $message_template_group->get('MTP_is_global'),
1647
-                'css_class'  => '',
1648
-                'format'     => '%d',
1649
-                'db-col'     => 'MTP_is_global',
1650
-            ];
1651
-
1652
-            $sidebar_form_fields['ee-msg-is-override'] = [
1653
-                'name'       => 'MTP_is_override',
1654
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1655
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1656
-                'type'       => 'int',
1657
-                'required'   => false,
1658
-                'validation' => true,
1659
-                'value'      => $message_template_group->get('MTP_is_override'),
1660
-                'css_class'  => '',
1661
-                'format'     => '%d',
1662
-                'db-col'     => 'MTP_is_override',
1663
-            ];
1664
-
1665
-            $sidebar_form_fields['ee-msg-is-active'] = [
1666
-                'name'       => 'MTP_is_active',
1667
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1668
-                'input'      => 'hidden',
1669
-                'type'       => 'int',
1670
-                'required'   => false,
1671
-                'validation' => true,
1672
-                'value'      => $message_template_group->is_active(),
1673
-                'css_class'  => '',
1674
-                'format'     => '%d',
1675
-                'db-col'     => 'MTP_is_active',
1676
-            ];
1677
-
1678
-            $sidebar_form_fields['ee-msg-deleted'] = [
1679
-                'name'       => 'MTP_deleted',
1680
-                'label'      => null,
1681
-                'input'      => 'hidden',
1682
-                'type'       => 'int',
1683
-                'required'   => false,
1684
-                'validation' => true,
1685
-                'value'      => $message_template_group->get('MTP_deleted'),
1686
-                'css_class'  => '',
1687
-                'format'     => '%d',
1688
-                'db-col'     => 'MTP_deleted',
1689
-            ];
1690
-            $sidebar_form_fields['ee-msg-author']  = [
1691
-                'name'       => 'MTP_user_id',
1692
-                'label'      => esc_html__('Author', 'event_espresso'),
1693
-                'input'      => 'hidden',
1694
-                'type'       => 'int',
1695
-                'required'   => false,
1696
-                'validation' => false,
1697
-                'value'      => $message_template_group->user(),
1698
-                'format'     => '%d',
1699
-                'db-col'     => 'MTP_user_id',
1700
-            ];
1701
-
1702
-            $sidebar_form_fields['ee-msg-route'] = [
1703
-                'name'  => 'action',
1704
-                'input' => 'hidden',
1705
-                'type'  => 'string',
1706
-                'value' => $action,
1707
-            ];
1708
-
1709
-            $sidebar_form_fields['ee-msg-id']        = [
1710
-                'name'  => 'id',
1711
-                'input' => 'hidden',
1712
-                'type'  => 'int',
1713
-                'value' => $GRP_ID,
1714
-            ];
1715
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1716
-                'name'  => $action . '_nonce',
1717
-                'input' => 'hidden',
1718
-                'type'  => 'string',
1719
-                'value' => wp_create_nonce($action . '_nonce'),
1720
-            ];
1721
-
1722
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1723
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1724
-                    'name'  => 'template_switch',
1725
-                    'input' => 'hidden',
1726
-                    'type'  => 'int',
1727
-                    'value' => 1,
1728
-                ];
1729
-            }
1730
-
1731
-
1732
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1733
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1734
-        } //end if ( !empty($template_field_structure) )
1735
-
1736
-        // set extra content for publish box
1737
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1738
-        $this->_set_publish_post_box_vars(
1739
-            'id',
1740
-            $GRP_ID,
1741
-            false,
1742
-            add_query_arg(
1743
-                ['action' => 'global_mtps'],
1744
-                $this->_admin_base_url
1745
-            )
1746
-        );
1747
-
1748
-        // add preview button
1749
-        $preview_url    = parent::add_query_args_and_nonce(
1750
-            [
1751
-                'message_type' => $message_template_group->message_type(),
1752
-                'messenger'    => $message_template_group->messenger(),
1753
-                'context'      => $context,
1754
-                'GRP_ID'       => $GRP_ID,
1755
-                'evt_id'       => $EVT_ID,
1756
-                'action'       => 'preview_message',
1757
-            ],
1758
-            $this->_admin_base_url
1759
-        );
1760
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1761
-                          . esc_html__('Preview', 'event_espresso')
1762
-                          . '</a>';
1763
-
1764
-
1765
-        // setup context switcher
1766
-        $context_switcher_args = [
1767
-            'page'    => 'espresso_messages',
1768
-            'action'  => 'edit_message_template',
1769
-            'id'      => $GRP_ID,
1770
-            'evt_id'  => $EVT_ID,
1771
-            'context' => $context,
1772
-            'extra'   => $preview_button,
1773
-        ];
1774
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1775
-
1776
-
1777
-        // main box
1778
-        $this->_template_args['template_fields']                         = $template_fields;
1779
-        $this->_template_args['sidebar_box_id']                          = 'details';
1780
-        $this->_template_args['action']                                  = $action;
1781
-        $this->_template_args['context']                                 = $context;
1782
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1783
-        $this->_template_args['learn_more_about_message_templates_link'] =
1784
-            $this->_learn_more_about_message_templates_link();
1785
-
1786
-
1787
-        $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1788
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1789
-            $message_template_group,
1790
-            $context,
1791
-            $context_label
1792
-        );
1793
-        $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1794
-        $this->_template_args['before_admin_page_content'] .= '</div>';
1795
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1796
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1797
-
1798
-        $this->_template_path = $this->_template_args['GRP_ID']
1799
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1800
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1801
-
1802
-        // send along EE_Message_Template_Group object for further template use.
1803
-        $this->_template_args['MTP'] = $message_template_group;
1804
-
1805
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1806
-            $this->_template_path,
1807
-            $this->_template_args,
1808
-            true
1809
-        );
1810
-
1811
-
1812
-        // finally, let's set the admin_page title
1813
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1814
-
1815
-
1816
-        // we need to take care of setting the shortcodes property for use elsewhere.
1817
-        $this->_set_shortcodes();
1818
-
1819
-
1820
-        // final template wrapper
1821
-        $this->display_admin_page_with_sidebar();
1822
-    }
1823
-
1824
-
1825
-    public function filter_tinymce_init($mceInit, $editor_id)
1826
-    {
1827
-        return $mceInit;
1828
-    }
1829
-
1830
-
1831
-    public function add_context_switcher()
1832
-    {
1833
-        return $this->_context_switcher;
1834
-    }
1835
-
1836
-
1837
-    /**
1838
-     * Adds the activation/deactivation toggle for the message template context.
1839
-     *
1840
-     * @param EE_Message_Template_Group $message_template_group
1841
-     * @param string                    $context
1842
-     * @param string                    $context_label
1843
-     * @return string
1844
-     * @throws DomainException
1845
-     * @throws EE_Error
1846
-     * @throws InvalidIdentifierException
1847
-     */
1848
-    protected function add_active_context_element(
1849
-        EE_Message_Template_Group $message_template_group,
1850
-        $context,
1851
-        $context_label
1852
-    ) {
1853
-        $template_args = [
1854
-            'context'                   => $context,
1855
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1856
-            'is_active'                 => $message_template_group->is_context_active($context),
1857
-            'on_off_action'             => $message_template_group->is_context_active($context)
1858
-                ? 'context-off'
1859
-                : 'context-on',
1860
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1861
-            'message_template_group_id' => $message_template_group->ID(),
1862
-        ];
1863
-        return EEH_Template::display_template(
1864
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1865
-            $template_args,
1866
-            true
1867
-        );
1868
-    }
1869
-
1870
-
1871
-    /**
1872
-     * Ajax callback for `toggle_context_template` ajax action.
1873
-     * Handles toggling the message context on or off.
1874
-     *
1875
-     * @throws EE_Error
1876
-     * @throws InvalidArgumentException
1877
-     * @throws InvalidDataTypeException
1878
-     * @throws InvalidIdentifierException
1879
-     * @throws InvalidInterfaceException
1880
-     */
1881
-    public function toggle_context_template()
1882
-    {
1883
-        $success = true;
1884
-        // check for required data
1885
-        if (
1886
-            ! isset(
1887
-                $this->_req_data['message_template_group_id'],
1888
-                $this->_req_data['context'],
1889
-                $this->_req_data['status']
1890
-            )
1891
-        ) {
1892
-            EE_Error::add_error(
1893
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1894
-                __FILE__,
1895
-                __FUNCTION__,
1896
-                __LINE__
1897
-            );
1898
-            $success = false;
1899
-        }
1900
-
1901
-        $nonce     = isset($this->_req_data['toggle_context_nonce'])
1902
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1903
-            : '';
1904
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1905
-        $this->_verify_nonce($nonce, $nonce_ref);
1906
-        $status = $this->_req_data['status'];
1907
-        if ($status !== 'off' && $status !== 'on') {
1908
-            EE_Error::add_error(
1909
-                sprintf(
1910
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1911
-                    $this->_req_data['status']
1912
-                ),
1913
-                __FILE__,
1914
-                __FUNCTION__,
1915
-                __LINE__
1916
-            );
1917
-            $success = false;
1918
-        }
1919
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1920
-            $this->_req_data['message_template_group_id']
1921
-        );
1922
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1923
-            EE_Error::add_error(
1924
-                sprintf(
1925
-                    esc_html__(
1926
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1927
-                        'event_espresso'
1928
-                    ),
1929
-                    $this->_req_data['message_template_group_id'],
1930
-                    'EE_Message_Template_Group'
1931
-                ),
1932
-                __FILE__,
1933
-                __FUNCTION__,
1934
-                __LINE__
1935
-            );
1936
-            $success = false;
1937
-        }
1938
-        if ($success) {
1939
-            $success = $status === 'off'
1940
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1941
-                : $message_template_group->activate_context($this->_req_data['context']);
1942
-        }
1943
-        $this->_template_args['success'] = $success;
1944
-        $this->_return_json();
1945
-    }
1946
-
1947
-
1948
-    public function _add_form_element_before()
1949
-    {
1950
-        return '<form method="post" action="'
1951
-               . $this->_template_args['edit_message_template_form_url']
1952
-               . '" id="ee-msg-edit-frm">';
1953
-    }
1954
-
1955
-
1956
-    public function _add_form_element_after()
1957
-    {
1958
-        return '</form>';
1959
-    }
1960
-
1961
-
1962
-    /**
1963
-     * This executes switching the template pack for a message template.
1964
-     *
1965
-     * @throws EE_Error
1966
-     * @throws InvalidDataTypeException
1967
-     * @throws InvalidInterfaceException
1968
-     * @throws InvalidArgumentException
1969
-     * @throws ReflectionException
1970
-     * @since 4.5.0
1971
-     */
1972
-    public function switch_template_pack()
1973
-    {
1974
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1975
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1976
-
1977
-        // verify we have needed values.
1978
-        if (empty($GRP_ID) || empty($template_pack)) {
1979
-            $this->_template_args['error'] = true;
1980
-            EE_Error::add_error(
1981
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1982
-                __FILE__,
1983
-                __FUNCTION__,
1984
-                __LINE__
1985
-            );
1986
-        } else {
1987
-            // get template, set the new template_pack and then reset to default
1988
-            /** @type EE_Message_Template_Group $message_template_group */
1989
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1990
-
1991
-            $message_template_group->set_template_pack_name($template_pack);
1992
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1993
-            $this->_req_data['mt']   = $message_template_group->message_type();
1994
-
1995
-            $query_args = $this->_reset_to_default_template();
1996
-
1997
-            if (empty($query_args['id'])) {
1998
-                EE_Error::add_error(
1999
-                    esc_html__(
2000
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2001
-                        'event_espresso'
2002
-                    ),
2003
-                    __FILE__,
2004
-                    __FUNCTION__,
2005
-                    __LINE__
2006
-                );
2007
-                $this->_template_args['error'] = true;
2008
-            } else {
2009
-                $template_label       = $message_template_group->get_template_pack()->label;
2010
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2011
-                EE_Error::add_success(
2012
-                    sprintf(
2013
-                        esc_html__(
2014
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2015
-                            'event_espresso'
2016
-                        ),
2017
-                        $template_label,
2018
-                        $template_pack_labels->template_pack
2019
-                    )
2020
-                );
2021
-                // generate the redirect url for js.
2022
-                $url                                          = self::add_query_args_and_nonce(
2023
-                    $query_args,
2024
-                    $this->_admin_base_url
2025
-                );
2026
-                $this->_template_args['data']['redirect_url'] = $url;
2027
-                $this->_template_args['success']              = true;
2028
-            }
2029
-
2030
-            $this->_return_json();
2031
-        }
2032
-    }
2033
-
2034
-
2035
-    /**
2036
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2037
-     * they want.
2038
-     *
2039
-     * @access protected
2040
-     * @return array|null
2041
-     * @throws EE_Error
2042
-     * @throws InvalidArgumentException
2043
-     * @throws InvalidDataTypeException
2044
-     * @throws InvalidInterfaceException
2045
-     */
2046
-    protected function _reset_to_default_template()
2047
-    {
2048
-
2049
-        $templates = [];
2050
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2051
-        // we need to make sure we've got the info we need.
2052
-        if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2053
-            EE_Error::add_error(
2054
-                esc_html__(
2055
-                    '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.',
2056
-                    'event_espresso'
2057
-                ),
2058
-                __FILE__,
2059
-                __FUNCTION__,
2060
-                __LINE__
2061
-            );
2062
-        }
2063
-
2064
-        // all templates will be reset to whatever the defaults are
2065
-        // for the global template matching the messenger and message type.
2066
-        $success = ! empty($GRP_ID) ? true : false;
2067
-
2068
-        if ($success) {
2069
-            // let's first determine if the incoming template is a global template,
2070
-            // if it isn't then we need to get the global template matching messenger and message type.
2071
-            // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2072
-
2073
-
2074
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2075
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2076
-
2077
-            if ($success) {
2078
-                // if successfully deleted, lets generate the new ones.
2079
-                // Note. We set GLOBAL to true, because resets on ANY template
2080
-                // will use the related global template defaults for regeneration.
2081
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2082
-                // HOWEVER, we DO keep the template pack and template variation set
2083
-                // for the current custom template when resetting.
2084
-                $templates = $this->_generate_new_templates(
2085
-                    $this->_req_data['msgr'],
2086
-                    $this->_req_data['mt'],
2087
-                    $GRP_ID,
2088
-                    true
2089
-                );
2090
-            }
2091
-        }
2092
-
2093
-        // any error messages?
2094
-        if (! $success) {
2095
-            EE_Error::add_error(
2096
-                esc_html__(
2097
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2098
-                    'event_espresso'
2099
-                ),
2100
-                __FILE__,
2101
-                __FUNCTION__,
2102
-                __LINE__
2103
-            );
2104
-        }
2105
-
2106
-        // all good, let's add a success message!
2107
-        if ($success && ! empty($templates)) {
2108
-            // the info for the template we generated is the first element in the returned array
2109
-            // $templates = $templates[0];
2110
-            EE_Error::overwrite_success();
2111
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2112
-        }
2113
-
2114
-
2115
-        $query_args = [
2116
-            'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2117
-            'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2118
-            'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2119
-        ];
2120
-
2121
-        // if called via ajax then we return query args otherwise redirect
2122
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2123
-            return $query_args;
2124
-        } else {
2125
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2126
-
2127
-            return null;
2128
-        }
2129
-    }
2130
-
2131
-
2132
-    /**
2133
-     * Retrieve and set the message preview for display.
2134
-     *
2135
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2136
-     * @return string
2137
-     * @throws ReflectionException
2138
-     * @throws EE_Error
2139
-     * @throws InvalidArgumentException
2140
-     * @throws InvalidDataTypeException
2141
-     * @throws InvalidInterfaceException
2142
-     */
2143
-    public function _preview_message($send = false)
2144
-    {
2145
-        // first make sure we've got the necessary parameters
2146
-        if (
2147
-            ! (
2148
-                $this->_req_data['message_type']
2149
-                && $this->_req_data['messenger']
2150
-                && $this->_req_data['GRP_ID']
2151
-            )
2152
-        ) {
2153
-            EE_Error::add_error(
2154
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2155
-                __FILE__,
2156
-                __FUNCTION__,
2157
-                __LINE__
2158
-            );
2159
-        }
2160
-
2161
-        // get the preview!
2162
-        $preview = EED_Messages::preview_message(
2163
-            $this->_req_data['message_type'],
2164
-            $this->_req_data['context'],
2165
-            $this->_req_data['messenger'],
2166
-            $send
2167
-        );
2168
-
2169
-        if ($send) {
2170
-            return $preview;
2171
-        }
2172
-
2173
-        // if we have an evt_id set on the request, use it.
2174
-        $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
2175
-            ? absint($this->_req_data['evt_id'])
2176
-            : false;
2177
-
2178
-        // let's add a button to go back to the edit view
2179
-        $query_args             = [
2180
-            'id'      => $this->_req_data['GRP_ID'],
2181
-            'evt_id'  => $EVT_ID,
2182
-            'context' => $this->_req_data['context'],
2183
-            'action'  => 'edit_message_template',
2184
-        ];
2185
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2186
-        $preview_button         = '<a href="'
2187
-                                  . $go_back_url
2188
-                                  . '" class="button--secondary messages-preview-go-back-button">'
2189
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2190
-                                  . '</a>';
2191
-        $message_types          = $this->get_installed_message_types();
2192
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
2193
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2194
-            ? ucwords($active_messenger->label['singular'])
2195
-            : esc_html__('Unknown Messenger', 'event_espresso');
2196
-        // let's provide a helpful title for context
2197
-        $preview_title = sprintf(
2198
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2199
-            $active_messenger_label,
2200
-            ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular'])
2201
-        );
2202
-        if (empty($preview)) {
2203
-            $this->noEventsErrorMessage();
2204
-        }
2205
-        // setup display of preview.
2206
-        $this->_admin_page_title                    = $preview_title;
2207
-        $this->_template_args['admin_page_title']   = $preview_title;
2208
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2209
-        $this->_template_args['data']['force_json'] = true;
2210
-
2211
-        return '';
2212
-    }
2213
-
2214
-
2215
-    /**
2216
-     * Used to set an error if there are no events available for generating a preview/test send.
2217
-     *
2218
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2219
-     */
2220
-    protected function noEventsErrorMessage($test_send = false)
2221
-    {
2222
-        $events_url = parent::add_query_args_and_nonce(
2223
-            [
2224
-                'action' => 'default',
2225
-                'page'   => 'espresso_events',
2226
-            ],
2227
-            admin_url('admin.php')
2228
-        );
2229
-        $message    = $test_send
2230
-            ? esc_html__(
2231
-                '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!',
2232
-                'event_espresso'
2233
-            )
2234
-            : esc_html__(
2235
-                '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!',
2236
-                'event_espresso'
2237
-            );
2238
-
2239
-        EE_Error::add_attention(
2240
-            sprintf(
2241
-                $message,
2242
-                "<a href='{$events_url}'>",
2243
-                '</a>'
2244
-            )
2245
-        );
2246
-    }
2247
-
2248
-
2249
-    /**
2250
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2251
-     * gets called automatically.
2252
-     *
2253
-     * @return string
2254
-     * @since 4.5.0
2255
-     *
2256
-     */
2257
-    protected function _display_preview_message()
2258
-    {
2259
-        $this->display_admin_page_with_no_sidebar();
2260
-    }
2261
-
2262
-
2263
-    /**
2264
-     * registers metaboxes that should show up on the "edit_message_template" page
2265
-     *
2266
-     * @access protected
2267
-     * @return void
2268
-     */
2269
-    protected function _register_edit_meta_boxes()
2270
-    {
2271
-        $this->addMetaBox(
2272
-            'mtp_valid_shortcodes',
2273
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2274
-            [$this, 'shortcode_meta_box'],
2275
-            $this->_current_screen->id,
2276
-            'side',
2277
-            'default'
2278
-        );
2279
-        $this->addMetaBox(
2280
-            'mtp_extra_actions',
2281
-            esc_html__('Extra Actions', 'event_espresso'),
2282
-            [$this, 'extra_actions_meta_box'],
2283
-            $this->_current_screen->id,
2284
-            'side',
2285
-            'high'
2286
-        );
2287
-        $this->addMetaBox(
2288
-            'mtp_templates',
2289
-            esc_html__('Template Styles', 'event_espresso'),
2290
-            [$this, 'template_pack_meta_box'],
2291
-            $this->_current_screen->id,
2292
-            'side',
2293
-            'high'
2294
-        );
2295
-    }
2296
-
2297
-
2298
-    /**
2299
-     * metabox content for all template pack and variation selection.
2300
-     *
2301
-     * @return string
2302
-     * @throws DomainException
2303
-     * @throws EE_Error
2304
-     * @throws InvalidArgumentException
2305
-     * @throws ReflectionException
2306
-     * @throws InvalidDataTypeException
2307
-     * @throws InvalidInterfaceException
2308
-     * @since 4.5.0
2309
-     */
2310
-    public function template_pack_meta_box()
2311
-    {
2312
-        $this->_set_message_template_group();
2313
-
2314
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2315
-
2316
-        $tp_select_values = [];
2317
-
2318
-        foreach ($tp_collection as $tp) {
2319
-            // only include template packs that support this messenger and message type!
2320
-            $supports = $tp->get_supports();
2321
-            if (
2322
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2323
-                || ! in_array(
2324
-                    $this->_message_template_group->message_type(),
2325
-                    $supports[ $this->_message_template_group->messenger() ],
2326
-                    true
2327
-                )
2328
-            ) {
2329
-                // not supported
2330
-                continue;
2331
-            }
2332
-
2333
-            $tp_select_values[] = [
2334
-                'text' => $tp->label,
2335
-                'id'   => $tp->dbref,
2336
-            ];
2337
-        }
2338
-
2339
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2340
-        // the default template pack.  This still allows for the odd template pack to override.
2341
-        if (empty($tp_select_values)) {
2342
-            $tp_select_values[] = [
2343
-                'text' => esc_html__('Default', 'event_espresso'),
2344
-                'id'   => 'default',
2345
-            ];
2346
-        }
2347
-
2348
-        // setup variation select values for the currently selected template.
2349
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2350
-            $this->_message_template_group->messenger(),
2351
-            $this->_message_template_group->message_type()
2352
-        );
2353
-        $variations_select_values = [];
2354
-        foreach ($variations as $variation => $label) {
2355
-            $variations_select_values[] = [
2356
-                'text' => $label,
2357
-                'id'   => $variation,
2358
-            ];
2359
-        }
2360
-
2361
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2362
-
2363
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2364
-            'MTP_template_pack',
2365
-            $tp_select_values,
2366
-            $this->_message_template_group->get_template_pack_name()
2367
-        );
2368
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2369
-            'MTP_template_variation',
2370
-            $variations_select_values,
2371
-            $this->_message_template_group->get_template_pack_variation()
2372
-        );
2373
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2374
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2375
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2376
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2377
-
2378
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2379
-
2380
-        EEH_Template::display_template($template, $template_args);
2381
-    }
2382
-
2383
-
2384
-    /**
2385
-     * This meta box holds any extra actions related to Message Templates
2386
-     * For now, this includes Resetting templates to defaults and sending a test email.
2387
-     *
2388
-     * @access  public
2389
-     * @return void
2390
-     * @throws EE_Error
2391
-     */
2392
-    public function extra_actions_meta_box()
2393
-    {
2394
-        $template_form_fields = [];
2395
-
2396
-        $extra_args = [
2397
-            'msgr'   => $this->_message_template_group->messenger(),
2398
-            'mt'     => $this->_message_template_group->message_type(),
2399
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2400
-        ];
2401
-        // first we need to see if there are any fields
2402
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2403
-
2404
-        if (! empty($fields)) {
2405
-            // yup there be fields
2406
-            foreach ($fields as $field => $config) {
2407
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2408
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2409
-                $default  = isset($config['default']) ? $config['default'] : '';
2410
-                $default  = isset($config['value']) ? $config['value'] : $default;
2411
-
2412
-                // if type is hidden and the value is empty
2413
-                // something may have gone wrong so let's correct with the defaults
2414
-                $fix                = $config['input'] === 'hidden'
2415
-                                      && isset($existing[ $field ])
2416
-                                      && empty($existing[ $field ])
2417
-                    ? $default
2418
-                    : '';
2419
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2420
-                    ? $existing[ $field ]
2421
-                    : $fix;
2422
-
2423
-                $template_form_fields[ $field_id ] = [
2424
-                    'name'       => 'test_settings_fld[' . $field . ']',
2425
-                    'label'      => $config['label'],
2426
-                    'input'      => $config['input'],
2427
-                    'type'       => $config['type'],
2428
-                    'required'   => $config['required'],
2429
-                    'validation' => $config['validation'],
2430
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2431
-                    'css_class'  => $config['css_class'],
2432
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2433
-                    'default'    => $default,
2434
-                    'format'     => $config['format'],
2435
-                ];
2436
-            }
2437
-        }
2438
-
2439
-        $test_settings_html = ! empty($template_form_fields)
2440
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2441
-            : '';
2442
-
2443
-        // print out $test_settings_fields
2444
-        if (! empty($test_settings_html)) {
2445
-            $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2446
-            $test_settings_html .= 'name="test_button" value="';
2447
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2448
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2449
-        }
2450
-
2451
-        // and button
2452
-        $test_settings_html .= '<p>';
2453
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2454
-        $test_settings_html .= '</p>';
2455
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2456
-        $test_settings_html .= $this->get_action_link_or_button(
2457
-            'reset_to_default',
2458
-            'reset',
2459
-            $extra_args,
2460
-            'button--primary reset-default-button'
2461
-        );
2462
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2463
-        echo $test_settings_html; // already escaped
2464
-    }
2465
-
2466
-
2467
-    /**
2468
-     * This returns the shortcode selector skeleton for a given context and field.
2469
-     *
2470
-     * @param string $field           The name of the field retrieving shortcodes for.
2471
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2472
-     * @return string
2473
-     * @throws DomainException
2474
-     * @throws EE_Error
2475
-     * @throws InvalidArgumentException
2476
-     * @throws ReflectionException
2477
-     * @throws InvalidDataTypeException
2478
-     * @throws InvalidInterfaceException
2479
-     * @since 4.9.rc.000
2480
-     */
2481
-    protected function _get_shortcode_selector($field, $linked_input_id)
2482
-    {
2483
-        $template_args = [
2484
-            'shortcodes'      => $this->_get_shortcodes([$field], true),
2485
-            'fieldname'       => $field,
2486
-            'linked_input_id' => $linked_input_id,
2487
-        ];
2488
-
2489
-        return EEH_Template::display_template(
2490
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2491
-            $template_args,
2492
-            true
2493
-        );
2494
-    }
2495
-
2496
-
2497
-    /**
2498
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2499
-     * page)
2500
-     *
2501
-     * @access public
2502
-     * @return void
2503
-     * @throws EE_Error
2504
-     * @throws InvalidArgumentException
2505
-     * @throws ReflectionException
2506
-     * @throws InvalidDataTypeException
2507
-     * @throws InvalidInterfaceException
2508
-     */
2509
-    public function shortcode_meta_box()
2510
-    {
2511
-        $shortcodes = $this->_get_shortcodes([], false);
2512
-        // just make sure the shortcodes property is set
2513
-        // $messenger = $this->_message_template_group->messenger_obj();
2514
-        // now let's set the content depending on the status of the shortcodes array
2515
-        if (empty($shortcodes)) {
2516
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2517
-            return;
2518
-        }
2519
-        ?>
25
+	/**
26
+	 * @type string $_active_message_type_name
27
+	 */
28
+	protected $_active_message_type_name = '';
29
+
30
+	/**
31
+	 * @type EE_messenger $_active_messenger
32
+	 */
33
+	protected $_active_messenger;
34
+
35
+	protected $_activate_state;
36
+
37
+	protected $_activate_meta_box_type;
38
+
39
+	protected $_current_message_meta_box;
40
+
41
+	protected $_current_message_meta_box_object;
42
+
43
+	protected $_context_switcher;
44
+
45
+	protected $_shortcodes           = [];
46
+
47
+	protected $_active_messengers    = [];
48
+
49
+	protected $_active_message_types = [];
50
+
51
+	/**
52
+	 * @var EE_Message_Template_Group $_message_template_group
53
+	 */
54
+	protected $_message_template_group;
55
+
56
+	protected $_m_mt_settings = [];
57
+
58
+
59
+	/**
60
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
61
+	 * IF there is no group then it gets automatically set to the Default template pack.
62
+	 *
63
+	 * @since 4.5.0
64
+	 *
65
+	 * @var EE_Messages_Template_Pack
66
+	 */
67
+	protected $_template_pack;
68
+
69
+
70
+	/**
71
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
72
+	 * group is.  If there is no group then it automatically gets set to default.
73
+	 *
74
+	 * @since 4.5.0
75
+	 *
76
+	 * @var string
77
+	 */
78
+	protected $_variation;
79
+
80
+
81
+	/**
82
+	 * @param bool $routing
83
+	 * @throws EE_Error
84
+	 */
85
+	public function __construct($routing = true)
86
+	{
87
+		// make sure messages autoloader is running
88
+		EED_Messages::set_autoloaders();
89
+		parent::__construct($routing);
90
+	}
91
+
92
+
93
+	protected function _init_page_props()
94
+	{
95
+		$this->page_slug        = EE_MSG_PG_SLUG;
96
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
97
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
98
+		$this->_admin_base_path = EE_MSG_ADMIN;
99
+
100
+		$this->_activate_state = isset($this->_req_data['activate_state'])
101
+			? (array) $this->_req_data['activate_state']
102
+			: [];
103
+
104
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
105
+		$this->_load_message_resource_manager();
106
+	}
107
+
108
+
109
+	/**
110
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
111
+	 *
112
+	 * @throws EE_Error
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws InvalidArgumentException
116
+	 * @throws ReflectionException
117
+	 */
118
+	protected function _load_message_resource_manager()
119
+	{
120
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return array
126
+	 * @throws EE_Error
127
+	 * @throws InvalidArgumentException
128
+	 * @throws InvalidDataTypeException
129
+	 * @throws InvalidInterfaceException
130
+	 * @deprecated 4.9.9.rc.014
131
+	 */
132
+	public function get_messengers_for_list_table()
133
+	{
134
+		EE_Error::doing_it_wrong(
135
+			__METHOD__,
136
+			sprintf(
137
+				esc_html__(
138
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
139
+					'event_espresso'
140
+				),
141
+				'Messages_Admin_Page::get_messengers_select_input()'
142
+			),
143
+			'4.9.9.rc.014'
144
+		);
145
+
146
+		$m_values          = [];
147
+		$active_messengers = EEM_Message::instance()->get_all(['group_by' => 'MSG_messenger']);
148
+		// setup messengers for selects
149
+		$i = 1;
150
+		foreach ($active_messengers as $active_messenger) {
151
+			if ($active_messenger instanceof EE_Message) {
152
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
153
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
154
+				$i++;
155
+			}
156
+		}
157
+
158
+		return $m_values;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @return array
164
+	 * @throws EE_Error
165
+	 * @throws InvalidArgumentException
166
+	 * @throws InvalidDataTypeException
167
+	 * @throws InvalidInterfaceException
168
+	 * @deprecated 4.9.9.rc.014
169
+	 */
170
+	public function get_message_types_for_list_table()
171
+	{
172
+		EE_Error::doing_it_wrong(
173
+			__METHOD__,
174
+			sprintf(
175
+				esc_html__(
176
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
177
+					'event_espresso'
178
+				),
179
+				'Messages_Admin_Page::get_message_types_select_input()'
180
+			),
181
+			'4.9.9.rc.014'
182
+		);
183
+
184
+		$mt_values       = [];
185
+		$active_messages = EEM_Message::instance()->get_all(['group_by' => 'MSG_message_type']);
186
+		$i               = 1;
187
+		foreach ($active_messages as $active_message) {
188
+			if ($active_message instanceof EE_Message) {
189
+				$mt_values[ $i ]['id']   = $active_message->message_type();
190
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
191
+				$i++;
192
+			}
193
+		}
194
+
195
+		return $mt_values;
196
+	}
197
+
198
+
199
+	/**
200
+	 * @return array
201
+	 * @throws EE_Error
202
+	 * @throws InvalidArgumentException
203
+	 * @throws InvalidDataTypeException
204
+	 * @throws InvalidInterfaceException
205
+	 * @deprecated 4.9.9.rc.014
206
+	 */
207
+	public function get_contexts_for_message_types_for_list_table()
208
+	{
209
+		EE_Error::doing_it_wrong(
210
+			__METHOD__,
211
+			sprintf(
212
+				esc_html__(
213
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
214
+					'event_espresso'
215
+				),
216
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
217
+			),
218
+			'4.9.9.rc.014'
219
+		);
220
+
221
+		$contexts                = [];
222
+		$active_message_contexts = EEM_Message::instance()->get_all(['group_by' => 'MSG_context']);
223
+		foreach ($active_message_contexts as $active_message) {
224
+			if ($active_message instanceof EE_Message) {
225
+				$message_type = $active_message->message_type_object();
226
+				if ($message_type instanceof EE_message_type) {
227
+					$message_type_contexts = $message_type->get_contexts();
228
+					foreach ($message_type_contexts as $context => $context_details) {
229
+						$contexts[ $context ] = $context_details['label'];
230
+					}
231
+				}
232
+			}
233
+		}
234
+
235
+		return $contexts;
236
+	}
237
+
238
+
239
+	/**
240
+	 * Generate select input with provided messenger options array.
241
+	 *
242
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
243
+	 *                                 labels.
244
+	 * @return string
245
+	 * @throws EE_Error
246
+	 */
247
+	public function get_messengers_select_input($messenger_options)
248
+	{
249
+		// if empty or just one value then just return an empty string
250
+		if (
251
+			empty($messenger_options)
252
+			|| ! is_array($messenger_options)
253
+			|| count($messenger_options) === 1
254
+		) {
255
+			return '';
256
+		}
257
+		// merge in default
258
+		$messenger_options = array_merge(
259
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
260
+			$messenger_options
261
+		);
262
+		$input             = new EE_Select_Input(
263
+			$messenger_options,
264
+			[
265
+				'html_name'  => 'ee_messenger_filter_by',
266
+				'html_id'    => 'ee_messenger_filter_by',
267
+				'html_class' => 'wide',
268
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
269
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
270
+					: 'none_selected',
271
+			]
272
+		);
273
+
274
+		return $input->get_html_for_input();
275
+	}
276
+
277
+
278
+	/**
279
+	 * Generate select input with provided message type options array.
280
+	 *
281
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
282
+	 *                                    message type labels
283
+	 * @return string
284
+	 * @throws EE_Error
285
+	 */
286
+	public function get_message_types_select_input($message_type_options)
287
+	{
288
+		// if empty or count of options is 1 then just return an empty string
289
+		if (
290
+			empty($message_type_options)
291
+			|| ! is_array($message_type_options)
292
+			|| count($message_type_options) === 1
293
+		) {
294
+			return '';
295
+		}
296
+		// merge in default
297
+		$message_type_options = array_merge(
298
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
299
+			$message_type_options
300
+		);
301
+		$input                = new EE_Select_Input(
302
+			$message_type_options,
303
+			[
304
+				'html_name'  => 'ee_message_type_filter_by',
305
+				'html_id'    => 'ee_message_type_filter_by',
306
+				'html_class' => 'wide',
307
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
308
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
309
+					: 'none_selected',
310
+			]
311
+		);
312
+
313
+		return $input->get_html_for_input();
314
+	}
315
+
316
+
317
+	/**
318
+	 * Generate select input with provide message type contexts array.
319
+	 *
320
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
321
+	 *                               context label.
322
+	 * @return string
323
+	 * @throws EE_Error
324
+	 */
325
+	public function get_contexts_for_message_types_select_input($context_options)
326
+	{
327
+		// if empty or count of options is one then just return empty string
328
+		if (
329
+			empty($context_options)
330
+			|| ! is_array($context_options)
331
+			|| count($context_options) === 1
332
+		) {
333
+			return '';
334
+		}
335
+		// merge in default
336
+		$context_options = array_merge(
337
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
338
+			$context_options
339
+		);
340
+		$input           = new EE_Select_Input(
341
+			$context_options,
342
+			[
343
+				'html_name'  => 'ee_context_filter_by',
344
+				'html_id'    => 'ee_context_filter_by',
345
+				'html_class' => 'wide',
346
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
347
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
348
+					: 'none_selected',
349
+			]
350
+		);
351
+
352
+		return $input->get_html_for_input();
353
+	}
354
+
355
+
356
+	protected function _ajax_hooks()
357
+	{
358
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
359
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
360
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
361
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
362
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
363
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
364
+	}
365
+
366
+
367
+	protected function _define_page_props()
368
+	{
369
+		$this->_admin_page_title = $this->page_label;
370
+		$this->_labels           = [
371
+			'buttons'    => [
372
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
373
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
374
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
375
+			],
376
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
377
+		];
378
+	}
379
+
380
+
381
+	/**
382
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
383
+	 *
384
+	 * @access protected
385
+	 * @return void
386
+	 */
387
+	protected function _set_page_routes()
388
+	{
389
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
390
+			? $this->_req_data['GRP_ID']
391
+			: 0;
392
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
393
+			? $this->_req_data['id']
394
+			: $grp_id;
395
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
396
+			? $this->_req_data['MSG_ID']
397
+			: 0;
398
+
399
+		$this->_page_routes = [
400
+			'default'                          => [
401
+				'func'       => '_message_queue_list_table',
402
+				'capability' => 'ee_read_global_messages',
403
+			],
404
+			'global_mtps'                      => [
405
+				'func'       => '_ee_default_messages_overview_list_table',
406
+				'capability' => 'ee_read_global_messages',
407
+			],
408
+			'custom_mtps'                      => [
409
+				'func'       => '_custom_mtps_preview',
410
+				'capability' => 'ee_read_messages',
411
+			],
412
+			'add_new_message_template'         => [
413
+				'func'       => '_add_message_template',
414
+				'capability' => 'ee_edit_messages',
415
+				'noheader'   => true,
416
+			],
417
+			'edit_message_template'            => [
418
+				'func'       => '_edit_message_template',
419
+				'capability' => 'ee_edit_message',
420
+				'obj_id'     => $grp_id,
421
+			],
422
+			'preview_message'                  => [
423
+				'func'               => '_preview_message',
424
+				'capability'         => 'ee_read_message',
425
+				'obj_id'             => $grp_id,
426
+				'noheader'           => true,
427
+				'headers_sent_route' => 'display_preview_message',
428
+			],
429
+			'display_preview_message'          => [
430
+				'func'       => '_display_preview_message',
431
+				'capability' => 'ee_read_message',
432
+				'obj_id'     => $grp_id,
433
+			],
434
+			'insert_message_template'          => [
435
+				'func'       => '_insert_or_update_message_template',
436
+				'capability' => 'ee_edit_messages',
437
+				'args'       => ['new' => true],
438
+				'noheader'   => true,
439
+			],
440
+			'update_message_template'          => [
441
+				'func'       => '_insert_or_update_message_template',
442
+				'capability' => 'ee_edit_message',
443
+				'obj_id'     => $grp_id,
444
+				'args'       => ['new' => false],
445
+				'noheader'   => true,
446
+			],
447
+			'trash_message_template'           => [
448
+				'func'       => '_trash_or_restore_message_template',
449
+				'capability' => 'ee_delete_message',
450
+				'obj_id'     => $grp_id,
451
+				'args'       => ['trash' => true, 'all' => true],
452
+				'noheader'   => true,
453
+			],
454
+			'trash_message_template_context'   => [
455
+				'func'       => '_trash_or_restore_message_template',
456
+				'capability' => 'ee_delete_message',
457
+				'obj_id'     => $grp_id,
458
+				'args'       => ['trash' => true],
459
+				'noheader'   => true,
460
+			],
461
+			'restore_message_template'         => [
462
+				'func'       => '_trash_or_restore_message_template',
463
+				'capability' => 'ee_delete_message',
464
+				'obj_id'     => $grp_id,
465
+				'args'       => ['trash' => false, 'all' => true],
466
+				'noheader'   => true,
467
+			],
468
+			'restore_message_template_context' => [
469
+				'func'       => '_trash_or_restore_message_template',
470
+				'capability' => 'ee_delete_message',
471
+				'obj_id'     => $grp_id,
472
+				'args'       => ['trash' => false],
473
+				'noheader'   => true,
474
+			],
475
+			'delete_message_template'          => [
476
+				'func'       => '_delete_message_template',
477
+				'capability' => 'ee_delete_message',
478
+				'obj_id'     => $grp_id,
479
+				'noheader'   => true,
480
+			],
481
+			'reset_to_default'                 => [
482
+				'func'       => '_reset_to_default_template',
483
+				'capability' => 'ee_edit_message',
484
+				'obj_id'     => $grp_id,
485
+				'noheader'   => true,
486
+			],
487
+			'settings'                         => [
488
+				'func'       => '_settings',
489
+				'capability' => 'manage_options',
490
+			],
491
+			'update_global_settings'           => [
492
+				'func'       => '_update_global_settings',
493
+				'capability' => 'manage_options',
494
+				'noheader'   => true,
495
+			],
496
+			'generate_now'                     => [
497
+				'func'       => '_generate_now',
498
+				'capability' => 'ee_send_message',
499
+				'noheader'   => true,
500
+			],
501
+			'generate_and_send_now'            => [
502
+				'func'       => '_generate_and_send_now',
503
+				'capability' => 'ee_send_message',
504
+				'noheader'   => true,
505
+			],
506
+			'queue_for_resending'              => [
507
+				'func'       => '_queue_for_resending',
508
+				'capability' => 'ee_send_message',
509
+				'noheader'   => true,
510
+			],
511
+			'send_now'                         => [
512
+				'func'       => '_send_now',
513
+				'capability' => 'ee_send_message',
514
+				'noheader'   => true,
515
+			],
516
+			'delete_ee_message'                => [
517
+				'func'       => '_delete_ee_messages',
518
+				'capability' => 'ee_delete_messages',
519
+				'noheader'   => true,
520
+			],
521
+			'delete_ee_messages'               => [
522
+				'func'       => '_delete_ee_messages',
523
+				'capability' => 'ee_delete_messages',
524
+				'noheader'   => true,
525
+				'obj_id'     => $msg_id,
526
+			],
527
+		];
528
+	}
529
+
530
+
531
+	protected function _set_page_config()
532
+	{
533
+		$this->_page_config = [
534
+			'default'                  => [
535
+				'nav'           => [
536
+					'label' => esc_html__('Message Activity', 'event_espresso'),
537
+					'order' => 10,
538
+				],
539
+				'list_table'    => 'EE_Message_List_Table',
540
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
541
+				'require_nonce' => false,
542
+			],
543
+			'global_mtps'              => [
544
+				'nav'           => [
545
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
546
+					'order' => 20,
547
+				],
548
+				'list_table'    => 'Messages_Template_List_Table',
549
+				'help_tabs'     => [
550
+					'messages_overview_help_tab'                                => [
551
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
552
+						'filename' => 'messages_overview',
553
+					],
554
+					'messages_overview_messages_table_column_headings_help_tab' => [
555
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
556
+						'filename' => 'messages_overview_table_column_headings',
557
+					],
558
+					'messages_overview_messages_filters_help_tab'               => [
559
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
560
+						'filename' => 'messages_overview_filters',
561
+					],
562
+					'messages_overview_messages_views_help_tab'                 => [
563
+						'title'    => esc_html__('Message Views', 'event_espresso'),
564
+						'filename' => 'messages_overview_views',
565
+					],
566
+					'message_overview_message_types_help_tab'                   => [
567
+						'title'    => esc_html__('Message Types', 'event_espresso'),
568
+						'filename' => 'messages_overview_types',
569
+					],
570
+					'messages_overview_messengers_help_tab'                     => [
571
+						'title'    => esc_html__('Messengers', 'event_espresso'),
572
+						'filename' => 'messages_overview_messengers',
573
+					],
574
+				],
575
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
576
+				// 'help_tour'     => array('Messages_Overview_Help_Tour'),
577
+				'require_nonce' => false,
578
+			],
579
+			'custom_mtps'              => [
580
+				'nav'           => [
581
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
582
+					'order' => 30,
583
+				],
584
+				'help_tabs'     => [],
585
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
586
+				// 'help_tour'     => array(),
587
+				'require_nonce' => false,
588
+			],
589
+			'add_new_message_template' => [
590
+				'nav'           => [
591
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
592
+					'order'      => 5,
593
+					'persistent' => false,
594
+				],
595
+				'require_nonce' => false,
596
+			],
597
+			'edit_message_template'    => [
598
+				'labels'        => [
599
+					'buttons'    => [
600
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
601
+					],
602
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
603
+				],
604
+				'nav'           => [
605
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
606
+					'order'      => 5,
607
+					'persistent' => false,
608
+					'url'        => '',
609
+				],
610
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
611
+				'has_metaboxes' => true,
612
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
613
+				// 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
614
+				'help_tabs'     => [
615
+					'edit_message_template'            => [
616
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
617
+						'callback' => 'edit_message_template_help_tab',
618
+					],
619
+					'message_templates_help_tab'       => [
620
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
621
+						'filename' => 'messages_templates',
622
+					],
623
+					'message_template_shortcodes'      => [
624
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
625
+						'callback' => 'message_template_shortcodes_help_tab',
626
+					],
627
+					'message_preview_help_tab'         => [
628
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
629
+						'filename' => 'messages_preview',
630
+					],
631
+					'messages_overview_other_help_tab' => [
632
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
633
+						'filename' => 'messages_overview_other',
634
+					],
635
+				],
636
+				'require_nonce' => false,
637
+			],
638
+			'display_preview_message'  => [
639
+				'nav'           => [
640
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
641
+					'order'      => 5,
642
+					'url'        => '',
643
+					'persistent' => false,
644
+				],
645
+				'help_tabs'     => [
646
+					'preview_message' => [
647
+						'title'    => esc_html__('About Previews', 'event_espresso'),
648
+						'callback' => 'preview_message_help_tab',
649
+					],
650
+				],
651
+				'require_nonce' => false,
652
+			],
653
+			'settings'                 => [
654
+				'nav'           => [
655
+					'label' => esc_html__('Settings', 'event_espresso'),
656
+					'order' => 40,
657
+				],
658
+				'metaboxes'     => ['_messages_settings_metaboxes'],
659
+				'help_tabs'     => [
660
+					'messages_settings_help_tab'               => [
661
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
662
+						'filename' => 'messages_settings',
663
+					],
664
+					'messages_settings_message_types_help_tab' => [
665
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
666
+						'filename' => 'messages_settings_message_types',
667
+					],
668
+					'messages_settings_messengers_help_tab'    => [
669
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
670
+						'filename' => 'messages_settings_messengers',
671
+					],
672
+				],
673
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
674
+				// 'help_tour'     => array('Messages_Settings_Help_Tour'),
675
+				'require_nonce' => false,
676
+			],
677
+		];
678
+	}
679
+
680
+
681
+	protected function _add_screen_options()
682
+	{
683
+		// todo
684
+	}
685
+
686
+
687
+	protected function _add_screen_options_global_mtps()
688
+	{
689
+		/**
690
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
691
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
692
+		 */
693
+		$page_title              = $this->_admin_page_title;
694
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
695
+		$this->_per_page_screen_option();
696
+		$this->_admin_page_title = $page_title;
697
+	}
698
+
699
+
700
+	protected function _add_screen_options_default()
701
+	{
702
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
703
+		$this->_per_page_screen_option();
704
+	}
705
+
706
+
707
+	// none of the below group are currently used for Messages
708
+	protected function _add_feature_pointers()
709
+	{
710
+	}
711
+
712
+
713
+	public function admin_init()
714
+	{
715
+	}
716
+
717
+
718
+	public function admin_notices()
719
+	{
720
+	}
721
+
722
+
723
+	public function admin_footer_scripts()
724
+	{
725
+	}
726
+
727
+
728
+	public function messages_help_tab()
729
+	{
730
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
731
+	}
732
+
733
+
734
+	public function messengers_help_tab()
735
+	{
736
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
737
+	}
738
+
739
+
740
+	public function message_types_help_tab()
741
+	{
742
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
743
+	}
744
+
745
+
746
+	public function messages_overview_help_tab()
747
+	{
748
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
749
+	}
750
+
751
+
752
+	public function message_templates_help_tab()
753
+	{
754
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
755
+	}
756
+
757
+
758
+	public function edit_message_template_help_tab()
759
+	{
760
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
761
+						. esc_attr__('Editor Title', 'event_espresso')
762
+						. '" />';
763
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
764
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
765
+						. '" />';
766
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
767
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
768
+						. '" />';
769
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
770
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
771
+						. '" />';
772
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
773
+						. esc_attr__('Publish Metabox', 'event_espresso')
774
+						. '" />';
775
+		EEH_Template::display_template(
776
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
777
+			$args
778
+		);
779
+	}
780
+
781
+
782
+	public function message_template_shortcodes_help_tab()
783
+	{
784
+		$this->_set_shortcodes();
785
+		$args['shortcodes'] = $this->_shortcodes;
786
+		EEH_Template::display_template(
787
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
788
+			$args
789
+		);
790
+	}
791
+
792
+
793
+	public function preview_message_help_tab()
794
+	{
795
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
796
+	}
797
+
798
+
799
+	public function settings_help_tab()
800
+	{
801
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
802
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
803
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
804
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
805
+		$args['img3'] = '<div class="switch">'
806
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
807
+						. ' type="checkbox" checked="checked">'
808
+						. '<label for="ee-on-off-toggle-on"></label>'
809
+						. '</div>';
810
+		$args['img4'] = '<div class="switch">'
811
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
812
+						. ' type="checkbox">'
813
+						. '<label for="ee-on-off-toggle-on"></label>'
814
+						. '</div>';
815
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
816
+	}
817
+
818
+
819
+	public function load_scripts_styles()
820
+	{
821
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
822
+		wp_enqueue_style('espresso_ee_msg');
823
+
824
+		wp_register_script(
825
+			'ee-messages-settings',
826
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
827
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
828
+			EVENT_ESPRESSO_VERSION,
829
+			true
830
+		);
831
+		wp_register_script(
832
+			'ee-msg-list-table-js',
833
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
834
+			['ee-dialog'],
835
+			EVENT_ESPRESSO_VERSION
836
+		);
837
+	}
838
+
839
+
840
+	public function load_scripts_styles_default()
841
+	{
842
+		wp_enqueue_script('ee-msg-list-table-js');
843
+	}
844
+
845
+
846
+	public function wp_editor_css($mce_css)
847
+	{
848
+		// if we're on the edit_message_template route
849
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
850
+			$message_type_name = $this->_active_message_type_name;
851
+
852
+			// we're going to REPLACE the existing mce css
853
+			// we need to get the css file location from the active messenger
854
+			$mce_css = $this->_active_messenger->get_variation(
855
+				$this->_template_pack,
856
+				$message_type_name,
857
+				true,
858
+				'wpeditor',
859
+				$this->_variation
860
+			);
861
+		}
862
+
863
+		return $mce_css;
864
+	}
865
+
866
+
867
+	public function load_scripts_styles_edit_message_template()
868
+	{
869
+
870
+		$this->_set_shortcodes();
871
+
872
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
873
+			esc_html__(
874
+				'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.',
875
+				'event_espresso'
876
+			),
877
+			$this->_message_template_group->messenger_obj()->label['singular'],
878
+			$this->_message_template_group->message_type_obj()->label['singular']
879
+		);
880
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
881
+			'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?',
882
+			'event_espresso'
883
+		);
884
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
885
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
886
+			'event_espresso'
887
+		);
888
+
889
+		wp_register_script(
890
+			'ee_msgs_edit_js',
891
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
892
+			['jquery'],
893
+			EVENT_ESPRESSO_VERSION
894
+		);
895
+
896
+		wp_enqueue_script('ee_admin_js');
897
+		wp_enqueue_script('ee_msgs_edit_js');
898
+
899
+		// add in special css for tiny_mce
900
+		add_filter('mce_css', [$this, 'wp_editor_css']);
901
+	}
902
+
903
+
904
+	public function load_scripts_styles_display_preview_message()
905
+	{
906
+
907
+		$this->_set_message_template_group();
908
+
909
+		if (isset($this->_req_data['messenger'])) {
910
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
911
+				$this->_req_data['messenger']
912
+			);
913
+		}
914
+
915
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
916
+
917
+
918
+		wp_enqueue_style(
919
+			'espresso_preview_css',
920
+			$this->_active_messenger->get_variation(
921
+				$this->_template_pack,
922
+				$message_type_name,
923
+				true,
924
+				'preview',
925
+				$this->_variation
926
+			)
927
+		);
928
+	}
929
+
930
+
931
+	public function load_scripts_styles_settings()
932
+	{
933
+		wp_register_style(
934
+			'ee-message-settings',
935
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
936
+			[],
937
+			EVENT_ESPRESSO_VERSION
938
+		);
939
+		wp_enqueue_style('ee-text-links');
940
+		wp_enqueue_style('ee-message-settings');
941
+		wp_enqueue_script('ee-messages-settings');
942
+	}
943
+
944
+
945
+	/**
946
+	 * set views array for List Table
947
+	 */
948
+	public function _set_list_table_views_global_mtps()
949
+	{
950
+		$this->_views = [
951
+			'in_use' => [
952
+				'slug'  => 'in_use',
953
+				'label' => esc_html__('In Use', 'event_espresso'),
954
+				'count' => 0,
955
+			],
956
+		];
957
+	}
958
+
959
+
960
+	/**
961
+	 * Set views array for the Custom Template List Table
962
+	 */
963
+	public function _set_list_table_views_custom_mtps()
964
+	{
965
+		$this->_set_list_table_views_global_mtps();
966
+		$this->_views['in_use']['bulk_action'] = [
967
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
968
+		];
969
+	}
970
+
971
+
972
+	/**
973
+	 * set views array for message queue list table
974
+	 *
975
+	 * @throws InvalidDataTypeException
976
+	 * @throws InvalidInterfaceException
977
+	 * @throws InvalidArgumentException
978
+	 * @throws EE_Error
979
+	 * @throws ReflectionException
980
+	 */
981
+	public function _set_list_table_views_default()
982
+	{
983
+		EE_Registry::instance()->load_helper('Template');
984
+
985
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
986
+			'ee_send_message',
987
+			'message_list_table_bulk_actions'
988
+		)
989
+			? [
990
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
991
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
992
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
993
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
994
+			]
995
+			: [];
996
+
997
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
998
+			'ee_delete_messages',
999
+			'message_list_table_bulk_actions'
1000
+		)
1001
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1002
+			: [];
1003
+
1004
+
1005
+		$this->_views = [
1006
+			'all' => [
1007
+				'slug'        => 'all',
1008
+				'label'       => esc_html__('All', 'event_espresso'),
1009
+				'count'       => 0,
1010
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1011
+			],
1012
+		];
1013
+
1014
+
1015
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
1016
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1017
+				continue;
1018
+			}
1019
+			$status_bulk_actions = $common_bulk_actions;
1020
+			// unset bulk actions not applying to status
1021
+			if (! empty($status_bulk_actions)) {
1022
+				switch ($status) {
1023
+					case EEM_Message::status_idle:
1024
+					case EEM_Message::status_resend:
1025
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1026
+						break;
1027
+
1028
+					case EEM_Message::status_failed:
1029
+					case EEM_Message::status_debug_only:
1030
+					case EEM_Message::status_messenger_executing:
1031
+						$status_bulk_actions = [];
1032
+						break;
1033
+
1034
+					case EEM_Message::status_incomplete:
1035
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1036
+						break;
1037
+
1038
+					case EEM_Message::status_retry:
1039
+					case EEM_Message::status_sent:
1040
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1041
+						break;
1042
+				}
1043
+			}
1044
+
1045
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1046
+			if ($status === EEM_Message::status_messenger_executing) {
1047
+				continue;
1048
+			}
1049
+
1050
+			$this->_views[ strtolower($status) ] = [
1051
+				'slug'        => strtolower($status),
1052
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1053
+				'count'       => 0,
1054
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1055
+			];
1056
+		}
1057
+	}
1058
+
1059
+
1060
+	protected function _ee_default_messages_overview_list_table()
1061
+	{
1062
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1063
+		$this->display_admin_list_table_page_with_no_sidebar();
1064
+	}
1065
+
1066
+
1067
+	/**
1068
+	 * @throws ReflectionException
1069
+	 * @throws EE_Error
1070
+	 */
1071
+	protected function _message_queue_list_table()
1072
+	{
1073
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1074
+		$this->_template_args['per_column']        = 6;
1075
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1076
+		$message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1077
+		$this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1078
+		$this->display_admin_list_table_page_with_no_sidebar();
1079
+	}
1080
+
1081
+
1082
+	protected function _message_legend_items()
1083
+	{
1084
+
1085
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1086
+		$action_items       = [];
1087
+
1088
+		foreach ($action_css_classes as $action_item => $action_details) {
1089
+			if ($action_item === 'see_notifications_for') {
1090
+				continue;
1091
+			}
1092
+			$action_items[ $action_item ] = [
1093
+				'class' => $action_details['css_class'],
1094
+				'desc'  => $action_details['label'],
1095
+			];
1096
+		}
1097
+
1098
+		/** @type array $status_items status legend setup */
1099
+		$status_items = [
1100
+			'sent_status'                => [
1101
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1102
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1103
+			],
1104
+			'idle_status'                => [
1105
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1106
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1107
+			],
1108
+			'failed_status'              => [
1109
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1110
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1111
+			],
1112
+			'messenger_executing_status' => [
1113
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1114
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1115
+			],
1116
+			'resend_status'              => [
1117
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1118
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1119
+			],
1120
+			'incomplete_status'          => [
1121
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1122
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1123
+			],
1124
+			'retry_status'               => [
1125
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1126
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1127
+			],
1128
+		];
1129
+		if (EEM_Message::debug()) {
1130
+			$status_items['debug_only_status'] = [
1131
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1132
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1133
+			];
1134
+		}
1135
+
1136
+		return array_merge($action_items, $status_items);
1137
+	}
1138
+
1139
+
1140
+	protected function _custom_mtps_preview()
1141
+	{
1142
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1143
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1144
+												. ' alt="' . esc_attr__(
1145
+													'Preview Custom Message Templates screenshot',
1146
+													'event_espresso'
1147
+												) . '" />';
1148
+		$this->_template_args['preview_text'] = '<strong>'
1149
+												. esc_html__(
1150
+													'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.',
1151
+													'event_espresso'
1152
+												)
1153
+												. '</strong>';
1154
+
1155
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1156
+	}
1157
+
1158
+
1159
+	/**
1160
+	 * get_message_templates
1161
+	 * This gets all the message templates for listing on the overview list.
1162
+	 *
1163
+	 * @access public
1164
+	 * @param int    $perpage the amount of templates groups to show per page
1165
+	 * @param string $type    the current _view we're getting templates for
1166
+	 * @param bool   $count   return count?
1167
+	 * @param bool   $all     disregard any paging info (get all data);
1168
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1169
+	 * @return array
1170
+	 * @throws EE_Error
1171
+	 * @throws InvalidArgumentException
1172
+	 * @throws InvalidDataTypeException
1173
+	 * @throws InvalidInterfaceException
1174
+	 */
1175
+	public function get_message_templates(
1176
+		$perpage = 10,
1177
+		$type = 'in_use',
1178
+		$count = false,
1179
+		$all = false,
1180
+		$global = true
1181
+	) {
1182
+
1183
+		$MTP = EEM_Message_Template_Group::instance();
1184
+
1185
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1186
+		$orderby                    = $this->_req_data['orderby'];
1187
+
1188
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1189
+			? $this->_req_data['order']
1190
+			: 'ASC';
1191
+
1192
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1193
+			? $this->_req_data['paged']
1194
+			: 1;
1195
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1196
+			? $this->_req_data['perpage']
1197
+			: $perpage;
1198
+
1199
+		$offset = ($current_page - 1) * $per_page;
1200
+		$limit  = $all ? null : [$offset, $per_page];
1201
+
1202
+
1203
+		// options will match what is in the _views array property
1204
+		switch ($type) {
1205
+			case 'in_use':
1206
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1207
+				break;
1208
+			default:
1209
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1210
+		}
1211
+
1212
+		return $templates;
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * filters etc might need a list of installed message_types
1218
+	 *
1219
+	 * @return array an array of message type objects
1220
+	 */
1221
+	public function get_installed_message_types()
1222
+	{
1223
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1224
+		$installed               = [];
1225
+
1226
+		foreach ($installed_message_types as $message_type) {
1227
+			$installed[ $message_type->name ] = $message_type;
1228
+		}
1229
+
1230
+		return $installed;
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 * _add_message_template
1236
+	 *
1237
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1238
+	 *
1239
+	 * @param string $message_type
1240
+	 * @param string $messenger
1241
+	 * @param string $GRP_ID
1242
+	 *
1243
+	 * @throws EE_error
1244
+	 */
1245
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1246
+	{
1247
+		// set values override any request data
1248
+		$message_type = ! empty($message_type) ? $message_type : $this->request->getRequestParam('message_type');
1249
+		$messenger    = ! empty($messenger) ? $messenger : $this->request->getRequestParam('messenger');
1250
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1251
+
1252
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1253
+		if (empty($message_type) || empty($messenger)) {
1254
+			throw new EE_Error(
1255
+				esc_html__(
1256
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1257
+					'event_espresso'
1258
+				)
1259
+			);
1260
+		}
1261
+
1262
+		// we need the GRP_ID for the template being used as the base for the new template
1263
+		if (empty($GRP_ID)) {
1264
+			throw new EE_Error(
1265
+				esc_html__(
1266
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1267
+					'event_espresso'
1268
+				)
1269
+			);
1270
+		}
1271
+
1272
+		// let's just make sure the template gets generated!
1273
+
1274
+		// we need to reassign some variables for what the insert is expecting
1275
+		$this->_req_data['MTP_messenger']    = $messenger;
1276
+		$this->_req_data['MTP_message_type'] = $message_type;
1277
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1278
+		$this->_insert_or_update_message_template(true);
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * public wrapper for the _add_message_template method
1284
+	 *
1285
+	 * @param string $message_type     message type slug
1286
+	 * @param string $messenger        messenger slug
1287
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1288
+	 *                                 off of.
1289
+	 * @throws EE_error
1290
+	 */
1291
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1292
+	{
1293
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1294
+	}
1295
+
1296
+
1297
+	/**
1298
+	 * _edit_message_template
1299
+	 *
1300
+	 * @access protected
1301
+	 * @return void
1302
+	 * @throws InvalidIdentifierException
1303
+	 * @throws DomainException
1304
+	 * @throws EE_Error
1305
+	 * @throws InvalidArgumentException
1306
+	 * @throws ReflectionException
1307
+	 * @throws InvalidDataTypeException
1308
+	 * @throws InvalidInterfaceException
1309
+	 */
1310
+	protected function _edit_message_template()
1311
+	{
1312
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1313
+		$template_fields = '';
1314
+		$sidebar_fields  = '';
1315
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1316
+		// valid html in the templates.
1317
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1318
+
1319
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1320
+			? absint($this->_req_data['id'])
1321
+			: false;
1322
+
1323
+		$EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
1324
+			? absint($this->_req_data['evt_id'])
1325
+			: false;
1326
+
1327
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1328
+		$message_template_group = $this->_message_template_group;
1329
+		$c_label                = $message_template_group->context_label();
1330
+		$c_config               = $message_template_group->contexts_config();
1331
+
1332
+		reset($c_config);
1333
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1334
+			? strtolower($this->_req_data['context'])
1335
+			: key($c_config);
1336
+
1337
+
1338
+		if (empty($GRP_ID)) {
1339
+			$action                         = 'insert_message_template';
1340
+			$edit_message_template_form_url = add_query_arg(
1341
+				['action' => $action, 'noheader' => true],
1342
+				EE_MSG_ADMIN_URL
1343
+			);
1344
+		} else {
1345
+			$action                         = 'update_message_template';
1346
+			$edit_message_template_form_url = add_query_arg(
1347
+				['action' => $action, 'noheader' => true],
1348
+				EE_MSG_ADMIN_URL
1349
+			);
1350
+		}
1351
+
1352
+		// set active messenger for this view
1353
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1354
+			$message_template_group->messenger()
1355
+		);
1356
+		$this->_active_message_type_name = $message_template_group->message_type();
1357
+
1358
+
1359
+		// Do we have any validation errors?
1360
+		$validators = $this->_get_transient();
1361
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1362
+
1363
+
1364
+		// we need to assemble the title from Various details
1365
+		$context_label = sprintf(
1366
+			esc_html__('(%s %s)', 'event_espresso'),
1367
+			$c_config[ $context ]['label'],
1368
+			ucwords($c_label['label'])
1369
+		);
1370
+
1371
+		$title = sprintf(
1372
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1373
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1374
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1375
+			$context_label
1376
+		);
1377
+
1378
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1379
+		$this->_template_args['message_template'] = $message_template_group;
1380
+		$this->_template_args['is_extra_fields']  = false;
1381
+
1382
+
1383
+		// let's get EEH_MSG_Template so we can get template form fields
1384
+		$template_field_structure = EEH_MSG_Template::get_fields(
1385
+			$message_template_group->messenger(),
1386
+			$message_template_group->message_type()
1387
+		);
1388
+
1389
+		if (! $template_field_structure) {
1390
+			$template_field_structure = false;
1391
+			$template_fields          = esc_html__(
1392
+				'There was an error in assembling the fields for this display (you should see an error message)',
1393
+				'event_espresso'
1394
+			);
1395
+		}
1396
+
1397
+
1398
+		$message_templates = $message_template_group->context_templates();
1399
+
1400
+
1401
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1402
+		// will get handled in the "extra" array.
1403
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1404
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1405
+				unset($template_field_structure[ $context ][ $reference_field ]);
1406
+			}
1407
+		}
1408
+
1409
+		// let's loop through the template_field_structure and actually assemble the input fields!
1410
+		if (! empty($template_field_structure)) {
1411
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1412
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1413
+				// the extra array and reset them.
1414
+				if ($template_field === 'extra') {
1415
+					$this->_template_args['is_extra_fields'] = true;
1416
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1417
+						$message_template = $message_templates[ $context ][ $reference_field ];
1418
+						$content          = $message_template instanceof EE_Message_Template
1419
+							? $message_template->get('MTP_content')
1420
+							: '';
1421
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1422
+							// let's verify if we need this extra field via the shortcodes parameter.
1423
+							$continue = false;
1424
+							if (isset($extra_array['shortcodes_required'])) {
1425
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1426
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1427
+										$continue = true;
1428
+									}
1429
+								}
1430
+								if ($continue) {
1431
+									continue;
1432
+								}
1433
+							}
1434
+
1435
+							$field_id                                  = $reference_field
1436
+																		 . '-'
1437
+																		 . $extra_field
1438
+																		 . '-content';
1439
+							$template_form_fields[ $field_id ]         = $extra_array;
1440
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1441
+																		 . $reference_field
1442
+																		 . '][content]['
1443
+																		 . $extra_field . ']';
1444
+							$css_class                                 = isset($extra_array['css_class'])
1445
+								? $extra_array['css_class']
1446
+								: '';
1447
+
1448
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1449
+																			  && in_array($extra_field, $v_fields, true)
1450
+																			  && (
1451
+																				  is_array($validators[ $extra_field ])
1452
+																				  && isset($validators[ $extra_field ]['msg'])
1453
+																			  )
1454
+								? 'validate-error ' . $css_class
1455
+								: $css_class;
1456
+
1457
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1458
+																		  && isset($content[ $extra_field ])
1459
+								? $content[ $extra_field ]
1460
+								: '';
1461
+
1462
+							// do we have a validation error?  if we do then let's use that value instead
1463
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1464
+								? $validators[ $extra_field ]['value']
1465
+								: $template_form_fields[ $field_id ]['value'];
1466
+
1467
+
1468
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1469
+
1470
+							// shortcode selector
1471
+							$field_name_to_use                                   = $extra_field === 'main'
1472
+								? 'content'
1473
+								: $extra_field;
1474
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1475
+								$field_name_to_use,
1476
+								$field_id
1477
+							);
1478
+
1479
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1480
+								// we want to decode the entities
1481
+								$template_form_fields[ $field_id ]['value'] =
1482
+									$template_form_fields[ $field_id ]['value'];
1483
+							}
1484
+						}
1485
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1486
+						$templatefield_templatename_id = $reference_field . '-name';
1487
+
1488
+						$template_form_fields[ $templatefield_MTP_id ] = [
1489
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1490
+							'label'      => null,
1491
+							'input'      => 'hidden',
1492
+							'type'       => 'int',
1493
+							'required'   => false,
1494
+							'validation' => false,
1495
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1496
+							'css_class'  => '',
1497
+							'format'     => '%d',
1498
+							'db-col'     => 'MTP_ID',
1499
+						];
1500
+
1501
+						$template_form_fields[ $templatefield_templatename_id ] = [
1502
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1503
+							'label'      => null,
1504
+							'input'      => 'hidden',
1505
+							'type'       => 'string',
1506
+							'required'   => false,
1507
+							'validation' => true,
1508
+							'value'      => $reference_field,
1509
+							'css_class'  => '',
1510
+							'format'     => '%s',
1511
+							'db-col'     => 'MTP_template_field',
1512
+						];
1513
+					}
1514
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1515
+				} else {
1516
+					$field_id                                   = $template_field . '-content';
1517
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1518
+					$template_form_fields[ $field_id ]['name']  =
1519
+						'MTP_template_fields[' . $template_field . '][content]';
1520
+					$message_template                           =
1521
+						isset($message_templates[ $context ][ $template_field ])
1522
+							? $message_templates[ $context ][ $template_field ]
1523
+							: null;
1524
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1525
+																  && is_array($message_templates[ $context ])
1526
+																  && $message_template instanceof EE_Message_Template
1527
+						? $message_template->get('MTP_content')
1528
+						: '';
1529
+
1530
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1531
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1532
+						? $validators[ $template_field ]['value']
1533
+						: $template_form_fields[ $field_id ]['value'];
1534
+
1535
+
1536
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1537
+					$css_class                                      = isset($field_setup_array['css_class'])
1538
+						? $field_setup_array['css_class']
1539
+						: '';
1540
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1541
+																	  && in_array($template_field, $v_fields, true)
1542
+																	  && isset($validators[ $template_field ]['msg'])
1543
+						? 'validate-error ' . $css_class
1544
+						: $css_class;
1545
+
1546
+					// shortcode selector
1547
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1548
+						$template_field,
1549
+						$field_id
1550
+					);
1551
+				}
1552
+
1553
+				// k took care of content field(s) now let's take care of others.
1554
+
1555
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1556
+				$templatefield_field_templatename_id = $template_field . '-name';
1557
+
1558
+				// foreach template field there are actually two form fields created
1559
+				$template_form_fields[ $templatefield_MTP_id ] = [
1560
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1561
+					'label'      => null,
1562
+					'input'      => 'hidden',
1563
+					'type'       => 'int',
1564
+					'required'   => false,
1565
+					'validation' => true,
1566
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1567
+					'css_class'  => '',
1568
+					'format'     => '%d',
1569
+					'db-col'     => 'MTP_ID',
1570
+				];
1571
+
1572
+				$template_form_fields[ $templatefield_field_templatename_id ] = [
1573
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1574
+					'label'      => null,
1575
+					'input'      => 'hidden',
1576
+					'type'       => 'string',
1577
+					'required'   => false,
1578
+					'validation' => true,
1579
+					'value'      => $template_field,
1580
+					'css_class'  => '',
1581
+					'format'     => '%s',
1582
+					'db-col'     => 'MTP_template_field',
1583
+				];
1584
+			}
1585
+
1586
+			// add other fields
1587
+			$template_form_fields['ee-msg-current-context'] = [
1588
+				'name'       => 'MTP_context',
1589
+				'label'      => null,
1590
+				'input'      => 'hidden',
1591
+				'type'       => 'string',
1592
+				'required'   => false,
1593
+				'validation' => true,
1594
+				'value'      => $context,
1595
+				'css_class'  => '',
1596
+				'format'     => '%s',
1597
+				'db-col'     => 'MTP_context',
1598
+			];
1599
+
1600
+			$template_form_fields['ee-msg-grp-id'] = [
1601
+				'name'       => 'GRP_ID',
1602
+				'label'      => null,
1603
+				'input'      => 'hidden',
1604
+				'type'       => 'int',
1605
+				'required'   => false,
1606
+				'validation' => true,
1607
+				'value'      => $GRP_ID,
1608
+				'css_class'  => '',
1609
+				'format'     => '%d',
1610
+				'db-col'     => 'GRP_ID',
1611
+			];
1612
+
1613
+			$template_form_fields['ee-msg-messenger'] = [
1614
+				'name'       => 'MTP_messenger',
1615
+				'label'      => null,
1616
+				'input'      => 'hidden',
1617
+				'type'       => 'string',
1618
+				'required'   => false,
1619
+				'validation' => true,
1620
+				'value'      => $message_template_group->messenger(),
1621
+				'css_class'  => '',
1622
+				'format'     => '%s',
1623
+				'db-col'     => 'MTP_messenger',
1624
+			];
1625
+
1626
+			$template_form_fields['ee-msg-message-type'] = [
1627
+				'name'       => 'MTP_message_type',
1628
+				'label'      => null,
1629
+				'input'      => 'hidden',
1630
+				'type'       => 'string',
1631
+				'required'   => false,
1632
+				'validation' => true,
1633
+				'value'      => $message_template_group->message_type(),
1634
+				'css_class'  => '',
1635
+				'format'     => '%s',
1636
+				'db-col'     => 'MTP_message_type',
1637
+			];
1638
+
1639
+			$sidebar_form_fields['ee-msg-is-global'] = [
1640
+				'name'       => 'MTP_is_global',
1641
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1642
+				'input'      => 'hidden',
1643
+				'type'       => 'int',
1644
+				'required'   => false,
1645
+				'validation' => true,
1646
+				'value'      => $message_template_group->get('MTP_is_global'),
1647
+				'css_class'  => '',
1648
+				'format'     => '%d',
1649
+				'db-col'     => 'MTP_is_global',
1650
+			];
1651
+
1652
+			$sidebar_form_fields['ee-msg-is-override'] = [
1653
+				'name'       => 'MTP_is_override',
1654
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1655
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1656
+				'type'       => 'int',
1657
+				'required'   => false,
1658
+				'validation' => true,
1659
+				'value'      => $message_template_group->get('MTP_is_override'),
1660
+				'css_class'  => '',
1661
+				'format'     => '%d',
1662
+				'db-col'     => 'MTP_is_override',
1663
+			];
1664
+
1665
+			$sidebar_form_fields['ee-msg-is-active'] = [
1666
+				'name'       => 'MTP_is_active',
1667
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1668
+				'input'      => 'hidden',
1669
+				'type'       => 'int',
1670
+				'required'   => false,
1671
+				'validation' => true,
1672
+				'value'      => $message_template_group->is_active(),
1673
+				'css_class'  => '',
1674
+				'format'     => '%d',
1675
+				'db-col'     => 'MTP_is_active',
1676
+			];
1677
+
1678
+			$sidebar_form_fields['ee-msg-deleted'] = [
1679
+				'name'       => 'MTP_deleted',
1680
+				'label'      => null,
1681
+				'input'      => 'hidden',
1682
+				'type'       => 'int',
1683
+				'required'   => false,
1684
+				'validation' => true,
1685
+				'value'      => $message_template_group->get('MTP_deleted'),
1686
+				'css_class'  => '',
1687
+				'format'     => '%d',
1688
+				'db-col'     => 'MTP_deleted',
1689
+			];
1690
+			$sidebar_form_fields['ee-msg-author']  = [
1691
+				'name'       => 'MTP_user_id',
1692
+				'label'      => esc_html__('Author', 'event_espresso'),
1693
+				'input'      => 'hidden',
1694
+				'type'       => 'int',
1695
+				'required'   => false,
1696
+				'validation' => false,
1697
+				'value'      => $message_template_group->user(),
1698
+				'format'     => '%d',
1699
+				'db-col'     => 'MTP_user_id',
1700
+			];
1701
+
1702
+			$sidebar_form_fields['ee-msg-route'] = [
1703
+				'name'  => 'action',
1704
+				'input' => 'hidden',
1705
+				'type'  => 'string',
1706
+				'value' => $action,
1707
+			];
1708
+
1709
+			$sidebar_form_fields['ee-msg-id']        = [
1710
+				'name'  => 'id',
1711
+				'input' => 'hidden',
1712
+				'type'  => 'int',
1713
+				'value' => $GRP_ID,
1714
+			];
1715
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1716
+				'name'  => $action . '_nonce',
1717
+				'input' => 'hidden',
1718
+				'type'  => 'string',
1719
+				'value' => wp_create_nonce($action . '_nonce'),
1720
+			];
1721
+
1722
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1723
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1724
+					'name'  => 'template_switch',
1725
+					'input' => 'hidden',
1726
+					'type'  => 'int',
1727
+					'value' => 1,
1728
+				];
1729
+			}
1730
+
1731
+
1732
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1733
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1734
+		} //end if ( !empty($template_field_structure) )
1735
+
1736
+		// set extra content for publish box
1737
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1738
+		$this->_set_publish_post_box_vars(
1739
+			'id',
1740
+			$GRP_ID,
1741
+			false,
1742
+			add_query_arg(
1743
+				['action' => 'global_mtps'],
1744
+				$this->_admin_base_url
1745
+			)
1746
+		);
1747
+
1748
+		// add preview button
1749
+		$preview_url    = parent::add_query_args_and_nonce(
1750
+			[
1751
+				'message_type' => $message_template_group->message_type(),
1752
+				'messenger'    => $message_template_group->messenger(),
1753
+				'context'      => $context,
1754
+				'GRP_ID'       => $GRP_ID,
1755
+				'evt_id'       => $EVT_ID,
1756
+				'action'       => 'preview_message',
1757
+			],
1758
+			$this->_admin_base_url
1759
+		);
1760
+		$preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1761
+						  . esc_html__('Preview', 'event_espresso')
1762
+						  . '</a>';
1763
+
1764
+
1765
+		// setup context switcher
1766
+		$context_switcher_args = [
1767
+			'page'    => 'espresso_messages',
1768
+			'action'  => 'edit_message_template',
1769
+			'id'      => $GRP_ID,
1770
+			'evt_id'  => $EVT_ID,
1771
+			'context' => $context,
1772
+			'extra'   => $preview_button,
1773
+		];
1774
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1775
+
1776
+
1777
+		// main box
1778
+		$this->_template_args['template_fields']                         = $template_fields;
1779
+		$this->_template_args['sidebar_box_id']                          = 'details';
1780
+		$this->_template_args['action']                                  = $action;
1781
+		$this->_template_args['context']                                 = $context;
1782
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1783
+		$this->_template_args['learn_more_about_message_templates_link'] =
1784
+			$this->_learn_more_about_message_templates_link();
1785
+
1786
+
1787
+		$this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1788
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1789
+			$message_template_group,
1790
+			$context,
1791
+			$context_label
1792
+		);
1793
+		$this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1794
+		$this->_template_args['before_admin_page_content'] .= '</div>';
1795
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1796
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1797
+
1798
+		$this->_template_path = $this->_template_args['GRP_ID']
1799
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1800
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1801
+
1802
+		// send along EE_Message_Template_Group object for further template use.
1803
+		$this->_template_args['MTP'] = $message_template_group;
1804
+
1805
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1806
+			$this->_template_path,
1807
+			$this->_template_args,
1808
+			true
1809
+		);
1810
+
1811
+
1812
+		// finally, let's set the admin_page title
1813
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1814
+
1815
+
1816
+		// we need to take care of setting the shortcodes property for use elsewhere.
1817
+		$this->_set_shortcodes();
1818
+
1819
+
1820
+		// final template wrapper
1821
+		$this->display_admin_page_with_sidebar();
1822
+	}
1823
+
1824
+
1825
+	public function filter_tinymce_init($mceInit, $editor_id)
1826
+	{
1827
+		return $mceInit;
1828
+	}
1829
+
1830
+
1831
+	public function add_context_switcher()
1832
+	{
1833
+		return $this->_context_switcher;
1834
+	}
1835
+
1836
+
1837
+	/**
1838
+	 * Adds the activation/deactivation toggle for the message template context.
1839
+	 *
1840
+	 * @param EE_Message_Template_Group $message_template_group
1841
+	 * @param string                    $context
1842
+	 * @param string                    $context_label
1843
+	 * @return string
1844
+	 * @throws DomainException
1845
+	 * @throws EE_Error
1846
+	 * @throws InvalidIdentifierException
1847
+	 */
1848
+	protected function add_active_context_element(
1849
+		EE_Message_Template_Group $message_template_group,
1850
+		$context,
1851
+		$context_label
1852
+	) {
1853
+		$template_args = [
1854
+			'context'                   => $context,
1855
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1856
+			'is_active'                 => $message_template_group->is_context_active($context),
1857
+			'on_off_action'             => $message_template_group->is_context_active($context)
1858
+				? 'context-off'
1859
+				: 'context-on',
1860
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1861
+			'message_template_group_id' => $message_template_group->ID(),
1862
+		];
1863
+		return EEH_Template::display_template(
1864
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1865
+			$template_args,
1866
+			true
1867
+		);
1868
+	}
1869
+
1870
+
1871
+	/**
1872
+	 * Ajax callback for `toggle_context_template` ajax action.
1873
+	 * Handles toggling the message context on or off.
1874
+	 *
1875
+	 * @throws EE_Error
1876
+	 * @throws InvalidArgumentException
1877
+	 * @throws InvalidDataTypeException
1878
+	 * @throws InvalidIdentifierException
1879
+	 * @throws InvalidInterfaceException
1880
+	 */
1881
+	public function toggle_context_template()
1882
+	{
1883
+		$success = true;
1884
+		// check for required data
1885
+		if (
1886
+			! isset(
1887
+				$this->_req_data['message_template_group_id'],
1888
+				$this->_req_data['context'],
1889
+				$this->_req_data['status']
1890
+			)
1891
+		) {
1892
+			EE_Error::add_error(
1893
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1894
+				__FILE__,
1895
+				__FUNCTION__,
1896
+				__LINE__
1897
+			);
1898
+			$success = false;
1899
+		}
1900
+
1901
+		$nonce     = isset($this->_req_data['toggle_context_nonce'])
1902
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1903
+			: '';
1904
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1905
+		$this->_verify_nonce($nonce, $nonce_ref);
1906
+		$status = $this->_req_data['status'];
1907
+		if ($status !== 'off' && $status !== 'on') {
1908
+			EE_Error::add_error(
1909
+				sprintf(
1910
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1911
+					$this->_req_data['status']
1912
+				),
1913
+				__FILE__,
1914
+				__FUNCTION__,
1915
+				__LINE__
1916
+			);
1917
+			$success = false;
1918
+		}
1919
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1920
+			$this->_req_data['message_template_group_id']
1921
+		);
1922
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1923
+			EE_Error::add_error(
1924
+				sprintf(
1925
+					esc_html__(
1926
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1927
+						'event_espresso'
1928
+					),
1929
+					$this->_req_data['message_template_group_id'],
1930
+					'EE_Message_Template_Group'
1931
+				),
1932
+				__FILE__,
1933
+				__FUNCTION__,
1934
+				__LINE__
1935
+			);
1936
+			$success = false;
1937
+		}
1938
+		if ($success) {
1939
+			$success = $status === 'off'
1940
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1941
+				: $message_template_group->activate_context($this->_req_data['context']);
1942
+		}
1943
+		$this->_template_args['success'] = $success;
1944
+		$this->_return_json();
1945
+	}
1946
+
1947
+
1948
+	public function _add_form_element_before()
1949
+	{
1950
+		return '<form method="post" action="'
1951
+			   . $this->_template_args['edit_message_template_form_url']
1952
+			   . '" id="ee-msg-edit-frm">';
1953
+	}
1954
+
1955
+
1956
+	public function _add_form_element_after()
1957
+	{
1958
+		return '</form>';
1959
+	}
1960
+
1961
+
1962
+	/**
1963
+	 * This executes switching the template pack for a message template.
1964
+	 *
1965
+	 * @throws EE_Error
1966
+	 * @throws InvalidDataTypeException
1967
+	 * @throws InvalidInterfaceException
1968
+	 * @throws InvalidArgumentException
1969
+	 * @throws ReflectionException
1970
+	 * @since 4.5.0
1971
+	 */
1972
+	public function switch_template_pack()
1973
+	{
1974
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1975
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1976
+
1977
+		// verify we have needed values.
1978
+		if (empty($GRP_ID) || empty($template_pack)) {
1979
+			$this->_template_args['error'] = true;
1980
+			EE_Error::add_error(
1981
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1982
+				__FILE__,
1983
+				__FUNCTION__,
1984
+				__LINE__
1985
+			);
1986
+		} else {
1987
+			// get template, set the new template_pack and then reset to default
1988
+			/** @type EE_Message_Template_Group $message_template_group */
1989
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1990
+
1991
+			$message_template_group->set_template_pack_name($template_pack);
1992
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1993
+			$this->_req_data['mt']   = $message_template_group->message_type();
1994
+
1995
+			$query_args = $this->_reset_to_default_template();
1996
+
1997
+			if (empty($query_args['id'])) {
1998
+				EE_Error::add_error(
1999
+					esc_html__(
2000
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2001
+						'event_espresso'
2002
+					),
2003
+					__FILE__,
2004
+					__FUNCTION__,
2005
+					__LINE__
2006
+				);
2007
+				$this->_template_args['error'] = true;
2008
+			} else {
2009
+				$template_label       = $message_template_group->get_template_pack()->label;
2010
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2011
+				EE_Error::add_success(
2012
+					sprintf(
2013
+						esc_html__(
2014
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2015
+							'event_espresso'
2016
+						),
2017
+						$template_label,
2018
+						$template_pack_labels->template_pack
2019
+					)
2020
+				);
2021
+				// generate the redirect url for js.
2022
+				$url                                          = self::add_query_args_and_nonce(
2023
+					$query_args,
2024
+					$this->_admin_base_url
2025
+				);
2026
+				$this->_template_args['data']['redirect_url'] = $url;
2027
+				$this->_template_args['success']              = true;
2028
+			}
2029
+
2030
+			$this->_return_json();
2031
+		}
2032
+	}
2033
+
2034
+
2035
+	/**
2036
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2037
+	 * they want.
2038
+	 *
2039
+	 * @access protected
2040
+	 * @return array|null
2041
+	 * @throws EE_Error
2042
+	 * @throws InvalidArgumentException
2043
+	 * @throws InvalidDataTypeException
2044
+	 * @throws InvalidInterfaceException
2045
+	 */
2046
+	protected function _reset_to_default_template()
2047
+	{
2048
+
2049
+		$templates = [];
2050
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2051
+		// we need to make sure we've got the info we need.
2052
+		if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2053
+			EE_Error::add_error(
2054
+				esc_html__(
2055
+					'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.',
2056
+					'event_espresso'
2057
+				),
2058
+				__FILE__,
2059
+				__FUNCTION__,
2060
+				__LINE__
2061
+			);
2062
+		}
2063
+
2064
+		// all templates will be reset to whatever the defaults are
2065
+		// for the global template matching the messenger and message type.
2066
+		$success = ! empty($GRP_ID) ? true : false;
2067
+
2068
+		if ($success) {
2069
+			// let's first determine if the incoming template is a global template,
2070
+			// if it isn't then we need to get the global template matching messenger and message type.
2071
+			// $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2072
+
2073
+
2074
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2075
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2076
+
2077
+			if ($success) {
2078
+				// if successfully deleted, lets generate the new ones.
2079
+				// Note. We set GLOBAL to true, because resets on ANY template
2080
+				// will use the related global template defaults for regeneration.
2081
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2082
+				// HOWEVER, we DO keep the template pack and template variation set
2083
+				// for the current custom template when resetting.
2084
+				$templates = $this->_generate_new_templates(
2085
+					$this->_req_data['msgr'],
2086
+					$this->_req_data['mt'],
2087
+					$GRP_ID,
2088
+					true
2089
+				);
2090
+			}
2091
+		}
2092
+
2093
+		// any error messages?
2094
+		if (! $success) {
2095
+			EE_Error::add_error(
2096
+				esc_html__(
2097
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2098
+					'event_espresso'
2099
+				),
2100
+				__FILE__,
2101
+				__FUNCTION__,
2102
+				__LINE__
2103
+			);
2104
+		}
2105
+
2106
+		// all good, let's add a success message!
2107
+		if ($success && ! empty($templates)) {
2108
+			// the info for the template we generated is the first element in the returned array
2109
+			// $templates = $templates[0];
2110
+			EE_Error::overwrite_success();
2111
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2112
+		}
2113
+
2114
+
2115
+		$query_args = [
2116
+			'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2117
+			'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2118
+			'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2119
+		];
2120
+
2121
+		// if called via ajax then we return query args otherwise redirect
2122
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2123
+			return $query_args;
2124
+		} else {
2125
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2126
+
2127
+			return null;
2128
+		}
2129
+	}
2130
+
2131
+
2132
+	/**
2133
+	 * Retrieve and set the message preview for display.
2134
+	 *
2135
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2136
+	 * @return string
2137
+	 * @throws ReflectionException
2138
+	 * @throws EE_Error
2139
+	 * @throws InvalidArgumentException
2140
+	 * @throws InvalidDataTypeException
2141
+	 * @throws InvalidInterfaceException
2142
+	 */
2143
+	public function _preview_message($send = false)
2144
+	{
2145
+		// first make sure we've got the necessary parameters
2146
+		if (
2147
+			! (
2148
+				$this->_req_data['message_type']
2149
+				&& $this->_req_data['messenger']
2150
+				&& $this->_req_data['GRP_ID']
2151
+			)
2152
+		) {
2153
+			EE_Error::add_error(
2154
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2155
+				__FILE__,
2156
+				__FUNCTION__,
2157
+				__LINE__
2158
+			);
2159
+		}
2160
+
2161
+		// get the preview!
2162
+		$preview = EED_Messages::preview_message(
2163
+			$this->_req_data['message_type'],
2164
+			$this->_req_data['context'],
2165
+			$this->_req_data['messenger'],
2166
+			$send
2167
+		);
2168
+
2169
+		if ($send) {
2170
+			return $preview;
2171
+		}
2172
+
2173
+		// if we have an evt_id set on the request, use it.
2174
+		$EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
2175
+			? absint($this->_req_data['evt_id'])
2176
+			: false;
2177
+
2178
+		// let's add a button to go back to the edit view
2179
+		$query_args             = [
2180
+			'id'      => $this->_req_data['GRP_ID'],
2181
+			'evt_id'  => $EVT_ID,
2182
+			'context' => $this->_req_data['context'],
2183
+			'action'  => 'edit_message_template',
2184
+		];
2185
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2186
+		$preview_button         = '<a href="'
2187
+								  . $go_back_url
2188
+								  . '" class="button--secondary messages-preview-go-back-button">'
2189
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2190
+								  . '</a>';
2191
+		$message_types          = $this->get_installed_message_types();
2192
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
2193
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2194
+			? ucwords($active_messenger->label['singular'])
2195
+			: esc_html__('Unknown Messenger', 'event_espresso');
2196
+		// let's provide a helpful title for context
2197
+		$preview_title = sprintf(
2198
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2199
+			$active_messenger_label,
2200
+			ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular'])
2201
+		);
2202
+		if (empty($preview)) {
2203
+			$this->noEventsErrorMessage();
2204
+		}
2205
+		// setup display of preview.
2206
+		$this->_admin_page_title                    = $preview_title;
2207
+		$this->_template_args['admin_page_title']   = $preview_title;
2208
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2209
+		$this->_template_args['data']['force_json'] = true;
2210
+
2211
+		return '';
2212
+	}
2213
+
2214
+
2215
+	/**
2216
+	 * Used to set an error if there are no events available for generating a preview/test send.
2217
+	 *
2218
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2219
+	 */
2220
+	protected function noEventsErrorMessage($test_send = false)
2221
+	{
2222
+		$events_url = parent::add_query_args_and_nonce(
2223
+			[
2224
+				'action' => 'default',
2225
+				'page'   => 'espresso_events',
2226
+			],
2227
+			admin_url('admin.php')
2228
+		);
2229
+		$message    = $test_send
2230
+			? esc_html__(
2231
+				'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!',
2232
+				'event_espresso'
2233
+			)
2234
+			: esc_html__(
2235
+				'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!',
2236
+				'event_espresso'
2237
+			);
2238
+
2239
+		EE_Error::add_attention(
2240
+			sprintf(
2241
+				$message,
2242
+				"<a href='{$events_url}'>",
2243
+				'</a>'
2244
+			)
2245
+		);
2246
+	}
2247
+
2248
+
2249
+	/**
2250
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2251
+	 * gets called automatically.
2252
+	 *
2253
+	 * @return string
2254
+	 * @since 4.5.0
2255
+	 *
2256
+	 */
2257
+	protected function _display_preview_message()
2258
+	{
2259
+		$this->display_admin_page_with_no_sidebar();
2260
+	}
2261
+
2262
+
2263
+	/**
2264
+	 * registers metaboxes that should show up on the "edit_message_template" page
2265
+	 *
2266
+	 * @access protected
2267
+	 * @return void
2268
+	 */
2269
+	protected function _register_edit_meta_boxes()
2270
+	{
2271
+		$this->addMetaBox(
2272
+			'mtp_valid_shortcodes',
2273
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2274
+			[$this, 'shortcode_meta_box'],
2275
+			$this->_current_screen->id,
2276
+			'side',
2277
+			'default'
2278
+		);
2279
+		$this->addMetaBox(
2280
+			'mtp_extra_actions',
2281
+			esc_html__('Extra Actions', 'event_espresso'),
2282
+			[$this, 'extra_actions_meta_box'],
2283
+			$this->_current_screen->id,
2284
+			'side',
2285
+			'high'
2286
+		);
2287
+		$this->addMetaBox(
2288
+			'mtp_templates',
2289
+			esc_html__('Template Styles', 'event_espresso'),
2290
+			[$this, 'template_pack_meta_box'],
2291
+			$this->_current_screen->id,
2292
+			'side',
2293
+			'high'
2294
+		);
2295
+	}
2296
+
2297
+
2298
+	/**
2299
+	 * metabox content for all template pack and variation selection.
2300
+	 *
2301
+	 * @return string
2302
+	 * @throws DomainException
2303
+	 * @throws EE_Error
2304
+	 * @throws InvalidArgumentException
2305
+	 * @throws ReflectionException
2306
+	 * @throws InvalidDataTypeException
2307
+	 * @throws InvalidInterfaceException
2308
+	 * @since 4.5.0
2309
+	 */
2310
+	public function template_pack_meta_box()
2311
+	{
2312
+		$this->_set_message_template_group();
2313
+
2314
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2315
+
2316
+		$tp_select_values = [];
2317
+
2318
+		foreach ($tp_collection as $tp) {
2319
+			// only include template packs that support this messenger and message type!
2320
+			$supports = $tp->get_supports();
2321
+			if (
2322
+				! isset($supports[ $this->_message_template_group->messenger() ])
2323
+				|| ! in_array(
2324
+					$this->_message_template_group->message_type(),
2325
+					$supports[ $this->_message_template_group->messenger() ],
2326
+					true
2327
+				)
2328
+			) {
2329
+				// not supported
2330
+				continue;
2331
+			}
2332
+
2333
+			$tp_select_values[] = [
2334
+				'text' => $tp->label,
2335
+				'id'   => $tp->dbref,
2336
+			];
2337
+		}
2338
+
2339
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2340
+		// the default template pack.  This still allows for the odd template pack to override.
2341
+		if (empty($tp_select_values)) {
2342
+			$tp_select_values[] = [
2343
+				'text' => esc_html__('Default', 'event_espresso'),
2344
+				'id'   => 'default',
2345
+			];
2346
+		}
2347
+
2348
+		// setup variation select values for the currently selected template.
2349
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2350
+			$this->_message_template_group->messenger(),
2351
+			$this->_message_template_group->message_type()
2352
+		);
2353
+		$variations_select_values = [];
2354
+		foreach ($variations as $variation => $label) {
2355
+			$variations_select_values[] = [
2356
+				'text' => $label,
2357
+				'id'   => $variation,
2358
+			];
2359
+		}
2360
+
2361
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2362
+
2363
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2364
+			'MTP_template_pack',
2365
+			$tp_select_values,
2366
+			$this->_message_template_group->get_template_pack_name()
2367
+		);
2368
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2369
+			'MTP_template_variation',
2370
+			$variations_select_values,
2371
+			$this->_message_template_group->get_template_pack_variation()
2372
+		);
2373
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2374
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2375
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2376
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2377
+
2378
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2379
+
2380
+		EEH_Template::display_template($template, $template_args);
2381
+	}
2382
+
2383
+
2384
+	/**
2385
+	 * This meta box holds any extra actions related to Message Templates
2386
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2387
+	 *
2388
+	 * @access  public
2389
+	 * @return void
2390
+	 * @throws EE_Error
2391
+	 */
2392
+	public function extra_actions_meta_box()
2393
+	{
2394
+		$template_form_fields = [];
2395
+
2396
+		$extra_args = [
2397
+			'msgr'   => $this->_message_template_group->messenger(),
2398
+			'mt'     => $this->_message_template_group->message_type(),
2399
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2400
+		];
2401
+		// first we need to see if there are any fields
2402
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2403
+
2404
+		if (! empty($fields)) {
2405
+			// yup there be fields
2406
+			foreach ($fields as $field => $config) {
2407
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2408
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2409
+				$default  = isset($config['default']) ? $config['default'] : '';
2410
+				$default  = isset($config['value']) ? $config['value'] : $default;
2411
+
2412
+				// if type is hidden and the value is empty
2413
+				// something may have gone wrong so let's correct with the defaults
2414
+				$fix                = $config['input'] === 'hidden'
2415
+									  && isset($existing[ $field ])
2416
+									  && empty($existing[ $field ])
2417
+					? $default
2418
+					: '';
2419
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2420
+					? $existing[ $field ]
2421
+					: $fix;
2422
+
2423
+				$template_form_fields[ $field_id ] = [
2424
+					'name'       => 'test_settings_fld[' . $field . ']',
2425
+					'label'      => $config['label'],
2426
+					'input'      => $config['input'],
2427
+					'type'       => $config['type'],
2428
+					'required'   => $config['required'],
2429
+					'validation' => $config['validation'],
2430
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2431
+					'css_class'  => $config['css_class'],
2432
+					'options'    => isset($config['options']) ? $config['options'] : [],
2433
+					'default'    => $default,
2434
+					'format'     => $config['format'],
2435
+				];
2436
+			}
2437
+		}
2438
+
2439
+		$test_settings_html = ! empty($template_form_fields)
2440
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2441
+			: '';
2442
+
2443
+		// print out $test_settings_fields
2444
+		if (! empty($test_settings_html)) {
2445
+			$test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2446
+			$test_settings_html .= 'name="test_button" value="';
2447
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2448
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2449
+		}
2450
+
2451
+		// and button
2452
+		$test_settings_html .= '<p>';
2453
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2454
+		$test_settings_html .= '</p>';
2455
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2456
+		$test_settings_html .= $this->get_action_link_or_button(
2457
+			'reset_to_default',
2458
+			'reset',
2459
+			$extra_args,
2460
+			'button--primary reset-default-button'
2461
+		);
2462
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2463
+		echo $test_settings_html; // already escaped
2464
+	}
2465
+
2466
+
2467
+	/**
2468
+	 * This returns the shortcode selector skeleton for a given context and field.
2469
+	 *
2470
+	 * @param string $field           The name of the field retrieving shortcodes for.
2471
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2472
+	 * @return string
2473
+	 * @throws DomainException
2474
+	 * @throws EE_Error
2475
+	 * @throws InvalidArgumentException
2476
+	 * @throws ReflectionException
2477
+	 * @throws InvalidDataTypeException
2478
+	 * @throws InvalidInterfaceException
2479
+	 * @since 4.9.rc.000
2480
+	 */
2481
+	protected function _get_shortcode_selector($field, $linked_input_id)
2482
+	{
2483
+		$template_args = [
2484
+			'shortcodes'      => $this->_get_shortcodes([$field], true),
2485
+			'fieldname'       => $field,
2486
+			'linked_input_id' => $linked_input_id,
2487
+		];
2488
+
2489
+		return EEH_Template::display_template(
2490
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2491
+			$template_args,
2492
+			true
2493
+		);
2494
+	}
2495
+
2496
+
2497
+	/**
2498
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2499
+	 * page)
2500
+	 *
2501
+	 * @access public
2502
+	 * @return void
2503
+	 * @throws EE_Error
2504
+	 * @throws InvalidArgumentException
2505
+	 * @throws ReflectionException
2506
+	 * @throws InvalidDataTypeException
2507
+	 * @throws InvalidInterfaceException
2508
+	 */
2509
+	public function shortcode_meta_box()
2510
+	{
2511
+		$shortcodes = $this->_get_shortcodes([], false);
2512
+		// just make sure the shortcodes property is set
2513
+		// $messenger = $this->_message_template_group->messenger_obj();
2514
+		// now let's set the content depending on the status of the shortcodes array
2515
+		if (empty($shortcodes)) {
2516
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2517
+			return;
2518
+		}
2519
+		?>
2520 2520
         <div style="float:right; margin-top:10px">
2521 2521
             <?php echo $this->_get_help_tab_link('message_template_shortcodes'); // already escaped ?>
2522 2522
         </div>
2523 2523
         <p class="small-text">
2524 2524
             <?php printf(
2525
-                esc_html__(
2526
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2527
-                    'event_espresso'
2528
-                ),
2529
-                '<span class="dashicons dashicons-menu"></span>'
2530
-            ); ?>
2525
+				esc_html__(
2526
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2527
+					'event_espresso'
2528
+				),
2529
+				'<span class="dashicons dashicons-menu"></span>'
2530
+			); ?>
2531 2531
         </p>
2532 2532
         <?php
2533
-    }
2534
-
2535
-
2536
-    /**
2537
-     * used to set the $_shortcodes property for when its needed elsewhere.
2538
-     *
2539
-     * @access protected
2540
-     * @return void
2541
-     * @throws EE_Error
2542
-     * @throws InvalidArgumentException
2543
-     * @throws ReflectionException
2544
-     * @throws InvalidDataTypeException
2545
-     * @throws InvalidInterfaceException
2546
-     */
2547
-    protected function _set_shortcodes()
2548
-    {
2549
-
2550
-        // no need to run this if the property is already set
2551
-        if (! empty($this->_shortcodes)) {
2552
-            return;
2553
-        }
2554
-
2555
-        $this->_shortcodes = $this->_get_shortcodes();
2556
-    }
2557
-
2558
-
2559
-    /**
2560
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2561
-     * property)
2562
-     *
2563
-     * @access  protected
2564
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2565
-     *                         for. Defaults to all (for the given context)
2566
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2567
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2568
-     *                         true just an array of shortcode/label pairs.
2569
-     * @throws EE_Error
2570
-     * @throws InvalidArgumentException
2571
-     * @throws ReflectionException
2572
-     * @throws InvalidDataTypeException
2573
-     * @throws InvalidInterfaceException
2574
-     */
2575
-    protected function _get_shortcodes($fields = [], $merged = true)
2576
-    {
2577
-        $this->_set_message_template_group();
2578
-
2579
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2580
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2581
-            ? absint($this->_req_data['id'])
2582
-            : false;
2583
-        $context = isset($this->_req_data['context'])
2584
-            ? $this->_req_data['context']
2585
-            : key($this->_message_template_group->contexts_config());
2586
-
2587
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : [];
2588
-    }
2589
-
2590
-
2591
-    /**
2592
-     * This sets the _message_template property (containing the called message_template object)
2593
-     *
2594
-     * @access protected
2595
-     * @return void
2596
-     * @throws EE_Error
2597
-     * @throws InvalidArgumentException
2598
-     * @throws ReflectionException
2599
-     * @throws InvalidDataTypeException
2600
-     * @throws InvalidInterfaceException
2601
-     */
2602
-    protected function _set_message_template_group()
2603
-    {
2604
-
2605
-        if (! empty($this->_message_template_group)) {
2606
-            return;
2607
-        } //get out if this is already set.
2608
-
2609
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2610
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2611
-
2612
-        // let's get the message templates
2613
-        $MTP = EEM_Message_Template_Group::instance();
2614
-
2615
-        if (empty($GRP_ID)) {
2616
-            $this->_message_template_group = $MTP->create_default_object();
2617
-        } else {
2618
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2619
-        }
2620
-
2621
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2622
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2623
-    }
2624
-
2625
-
2626
-    /**
2627
-     * sets up a context switcher for edit forms
2628
-     *
2629
-     * @access  protected
2630
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2631
-     * @param array                     $args                  various things the context switcher needs.
2632
-     * @throws EE_Error
2633
-     */
2634
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2635
-    {
2636
-        $context_details = $template_group_object->contexts_config();
2637
-        $context_label   = $template_group_object->context_label();
2638
-        ob_start();
2639
-        ?>
2533
+	}
2534
+
2535
+
2536
+	/**
2537
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2538
+	 *
2539
+	 * @access protected
2540
+	 * @return void
2541
+	 * @throws EE_Error
2542
+	 * @throws InvalidArgumentException
2543
+	 * @throws ReflectionException
2544
+	 * @throws InvalidDataTypeException
2545
+	 * @throws InvalidInterfaceException
2546
+	 */
2547
+	protected function _set_shortcodes()
2548
+	{
2549
+
2550
+		// no need to run this if the property is already set
2551
+		if (! empty($this->_shortcodes)) {
2552
+			return;
2553
+		}
2554
+
2555
+		$this->_shortcodes = $this->_get_shortcodes();
2556
+	}
2557
+
2558
+
2559
+	/**
2560
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2561
+	 * property)
2562
+	 *
2563
+	 * @access  protected
2564
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2565
+	 *                         for. Defaults to all (for the given context)
2566
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2567
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2568
+	 *                         true just an array of shortcode/label pairs.
2569
+	 * @throws EE_Error
2570
+	 * @throws InvalidArgumentException
2571
+	 * @throws ReflectionException
2572
+	 * @throws InvalidDataTypeException
2573
+	 * @throws InvalidInterfaceException
2574
+	 */
2575
+	protected function _get_shortcodes($fields = [], $merged = true)
2576
+	{
2577
+		$this->_set_message_template_group();
2578
+
2579
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2580
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2581
+			? absint($this->_req_data['id'])
2582
+			: false;
2583
+		$context = isset($this->_req_data['context'])
2584
+			? $this->_req_data['context']
2585
+			: key($this->_message_template_group->contexts_config());
2586
+
2587
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : [];
2588
+	}
2589
+
2590
+
2591
+	/**
2592
+	 * This sets the _message_template property (containing the called message_template object)
2593
+	 *
2594
+	 * @access protected
2595
+	 * @return void
2596
+	 * @throws EE_Error
2597
+	 * @throws InvalidArgumentException
2598
+	 * @throws ReflectionException
2599
+	 * @throws InvalidDataTypeException
2600
+	 * @throws InvalidInterfaceException
2601
+	 */
2602
+	protected function _set_message_template_group()
2603
+	{
2604
+
2605
+		if (! empty($this->_message_template_group)) {
2606
+			return;
2607
+		} //get out if this is already set.
2608
+
2609
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2610
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2611
+
2612
+		// let's get the message templates
2613
+		$MTP = EEM_Message_Template_Group::instance();
2614
+
2615
+		if (empty($GRP_ID)) {
2616
+			$this->_message_template_group = $MTP->create_default_object();
2617
+		} else {
2618
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2619
+		}
2620
+
2621
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2622
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2623
+	}
2624
+
2625
+
2626
+	/**
2627
+	 * sets up a context switcher for edit forms
2628
+	 *
2629
+	 * @access  protected
2630
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2631
+	 * @param array                     $args                  various things the context switcher needs.
2632
+	 * @throws EE_Error
2633
+	 */
2634
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2635
+	{
2636
+		$context_details = $template_group_object->contexts_config();
2637
+		$context_label   = $template_group_object->context_label();
2638
+		ob_start();
2639
+		?>
2640 2640
         <div class="ee-msg-switcher-container">
2641 2641
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2642 2642
                 <?php
2643
-                foreach ($args as $name => $value) {
2644
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2645
-                        continue;
2646
-                    }
2647
-                    ?>
2643
+				foreach ($args as $name => $value) {
2644
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2645
+						continue;
2646
+					}
2647
+					?>
2648 2648
                     <input type="hidden"
2649 2649
                            name="<?php echo esc_attr($name); ?>"
2650 2650
                            value="<?php echo esc_attr($value); ?>"
2651 2651
                     />
2652 2652
                     <?php
2653
-                }
2654
-                // setup nonce_url
2655
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2656
-                ?>
2653
+				}
2654
+				// setup nonce_url
2655
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2656
+				?>
2657 2657
                 <select name="context">
2658 2658
                     <?php
2659
-                    $context_templates = $template_group_object->context_templates();
2660
-                    if (is_array($context_templates)) :
2661
-                        foreach ($context_templates as $context => $template_fields) :
2662
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2663
-                            ?>
2659
+					$context_templates = $template_group_object->context_templates();
2660
+					if (is_array($context_templates)) :
2661
+						foreach ($context_templates as $context => $template_fields) :
2662
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2663
+							?>
2664 2664
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2665 2665
                                 <?php echo $context_details[ $context ]['label']; // already escaped
2666
-                                ?>
2666
+								?>
2667 2667
                             </option>
2668 2668
                         <?php endforeach;
2669
-                    endif; ?>
2669
+					endif; ?>
2670 2670
                 </select>
2671 2671
                 <?php $button_text = sprintf(
2672
-                    esc_html__('Switch %s', 'event_espresso'),
2673
-                    ucwords($context_label['label'])
2674
-                ); ?>
2672
+					esc_html__('Switch %s', 'event_espresso'),
2673
+					ucwords($context_label['label'])
2674
+				); ?>
2675 2675
                 <input class='button--secondary'
2676 2676
                        id="submit-msg-context-switcher-sbmt"
2677 2677
                        type="submit"
@@ -2679,1932 +2679,1932 @@  discard block
 block discarded – undo
2679 2679
                 />
2680 2680
             </form>
2681 2681
             <?php echo $args['extra']; // already escaped
2682
-            ?>
2682
+			?>
2683 2683
         </div> <!-- end .ee-msg-switcher-container -->
2684 2684
         <?php $this->_context_switcher = ob_get_clean();
2685
-    }
2686
-
2687
-
2688
-    /**
2689
-     * utility for sanitizing new values coming in.
2690
-     * Note: this is only used when updating a context.
2691
-     *
2692
-     * @access protected
2693
-     *
2694
-     * @param int $index This helps us know which template field to select from the request array.
2695
-     *
2696
-     * @return array
2697
-     */
2698
-    protected function _set_message_template_column_values($index)
2699
-    {
2700
-        if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2701
-            foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2702
-                $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2703
-            }
2704
-        }
2705
-
2706
-
2707
-        $set_column_values = [
2708
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2709
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2710
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2711
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2712
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2713
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2714
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2715
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2716
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2717
-                ? absint($this->_req_data['MTP_is_global'])
2718
-                : 0,
2719
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2720
-                ? absint($this->_req_data['MTP_is_override'])
2721
-                : 0,
2722
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2723
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active']),
2724
-        ];
2725
-
2726
-
2727
-        return $set_column_values;
2728
-    }
2729
-
2730
-
2731
-    protected function _insert_or_update_message_template($new = false)
2732
-    {
2733
-        $success = 0;
2734
-        $override = false;
2735
-
2736
-        // setup notices description
2737
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2738
-
2739
-        // need the message type and messenger objects to be able to use the labels for the notices
2740
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2741
-        $messenger_label  = $messenger_object instanceof EE_messenger
2742
-            ? ucwords($messenger_object->label['singular'])
2743
-            : '';
2744
-
2745
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2746
-            ? $this->_req_data['MTP_message_type']
2747
-            : '';
2748
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2749
-
2750
-        $message_type_label = $message_type_object instanceof EE_message_type
2751
-            ? ucwords($message_type_object->label['singular'])
2752
-            : '';
2753
-
2754
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2755
-            ? $this->_req_data['MTP_context']
2756
-            : '';
2757
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2758
-
2759
-        $item_desc   = $messenger_label && $message_type_label
2760
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2761
-            : '';
2762
-        $item_desc   .= 'Message Template';
2763
-        $query_args  = [];
2764
-        $edit_array  = [];
2765
-        $action_desc = '';
2766
-
2767
-        // if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2768
-        // user to edit.
2769
-        if ($new) {
2770
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2771
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2772
-                if (empty($edit_array)) {
2773
-                    $success = 0;
2774
-                } else {
2775
-                    $success    = 1;
2776
-                    $edit_array = $edit_array[0];
2777
-                    $query_args = [
2778
-                        'id'      => $edit_array['GRP_ID'],
2779
-                        'context' => $edit_array['MTP_context'],
2780
-                        'action'  => 'edit_message_template',
2781
-                    ];
2782
-                }
2783
-            }
2784
-            $action_desc = 'created';
2785
-        } else {
2786
-            $MTPG = EEM_Message_Template_Group::instance();
2787
-            $MTP  = EEM_Message_Template::instance();
2788
-
2789
-
2790
-            // run update for each template field in displayed context
2791
-            if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2792
-                EE_Error::add_error(
2793
-                    esc_html__(
2794
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2795
-                        'event_espresso'
2796
-                    ),
2797
-                    __FILE__,
2798
-                    __FUNCTION__,
2799
-                    __LINE__
2800
-                );
2801
-                $success = 0;
2802
-            } else {
2803
-                // first validate all fields!
2804
-                // this filter allows client code to add its own validation to the template fields as well.
2805
-                // returning an empty array means everything passed validation.
2806
-                // errors in validation should be represented in an array with the following shape:
2807
-                // array(
2808
-                //   'fieldname' => array(
2809
-                //          'msg' => 'error message'
2810
-                //          'value' => 'value for field producing error'
2811
-                // )
2812
-                $custom_validation = (array) apply_filters(
2813
-                    'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2814
-                    [],
2815
-                    $this->_req_data['MTP_template_fields'],
2816
-                    $context_slug,
2817
-                    $messenger_slug,
2818
-                    $message_type_slug
2819
-                );
2820
-
2821
-                $system_validation = $MTPG->validate(
2822
-                    $this->_req_data['MTP_template_fields'],
2823
-                    $context_slug,
2824
-                    $messenger_slug,
2825
-                    $message_type_slug
2826
-                );
2827
-
2828
-                $system_validation = ! is_array($system_validation) && $system_validation ? []
2829
-                    : $system_validation;
2830
-                $validates         = array_merge($custom_validation, $system_validation);
2831
-
2832
-                // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2833
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2834
-                //  WE need to make sure there is no actual error messages in validates.
2835
-                if (is_array($validates) && ! empty($validates)) {
2836
-                    // add the transient so when the form loads we know which fields to highlight
2837
-                    $this->_add_transient('edit_message_template', $validates);
2838
-
2839
-                    $success = 0;
2840
-
2841
-                    // setup notices
2842
-                    foreach ($validates as $field => $error) {
2843
-                        if (isset($error['msg'])) {
2844
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2845
-                        }
2846
-                    }
2847
-                } else {
2848
-                    $set_column_values = [];
2849
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2850
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2851
-
2852
-                        $where_cols_n_values = [
2853
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2854
-                        ];
2855
-                        // if they aren't allowed to use all JS, restrict them to just posty-y tags
2856
-                        if (! current_user_can('unfiltered_html')) {
2857
-                            if (is_array($set_column_values['MTP_content'])) {
2858
-                                foreach ($set_column_values['MTP_content'] as $key => $value) {
2859
-                                    // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2860
-                                    // only removes slashes from double-quotes, so attributes using single quotes always
2861
-                                    // appear invalid.) But currently the models expect slashed data, so after wp_kses
2862
-                                    // runs we need to re-slash the data. Sheesh. See
2863
-                                    // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2864
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2865
-                                        wp_kses(
2866
-                                            stripslashes($value),
2867
-                                            wp_kses_allowed_html('post')
2868
-                                        )
2869
-                                    );
2870
-                                }
2871
-                            } else {
2872
-                                $set_column_values['MTP_content'] = wp_kses(
2873
-                                    $set_column_values['MTP_content'],
2874
-                                    wp_kses_allowed_html('post')
2875
-                                );
2876
-                            }
2877
-                        }
2878
-                        $message_template_fields = [
2879
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2880
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2881
-                            'MTP_context'        => $set_column_values['MTP_context'],
2882
-                            'MTP_content'        => $set_column_values['MTP_content'],
2883
-                        ];
2884
-                        if ($updated = $MTP->update($message_template_fields, [$where_cols_n_values])) {
2885
-                            if ($updated === false) {
2886
-                                EE_Error::add_error(
2887
-                                    sprintf(
2888
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2889
-                                        $template_field
2890
-                                    ),
2891
-                                    __FILE__,
2892
-                                    __FUNCTION__,
2893
-                                    __LINE__
2894
-                                );
2895
-                            } else {
2896
-                                $success = 1;
2897
-                            }
2898
-                        } else {
2899
-                            // only do this logic if we don't have a MTP_ID for this field
2900
-                            if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2901
-                                // this has already been through the template field validator and sanitized, so it will be
2902
-                                // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2903
-                                // message template field in a messenger/message type and existing users don't have the
2904
-                                // default setup for it.
2905
-                                // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2906
-                                $updated = $MTP->insert($message_template_fields);
2907
-                                if (! $updated || is_wp_error($updated)) {
2908
-                                    EE_Error::add_error(
2909
-                                        sprintf(
2910
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2911
-                                            $template_field
2912
-                                        ),
2913
-                                        __FILE__,
2914
-                                        __FUNCTION__,
2915
-                                        __LINE__
2916
-                                    );
2917
-                                    $success = 0;
2918
-                                } else {
2919
-                                    $success = 1;
2920
-                                }
2921
-                            }
2922
-                        }
2923
-                        $action_desc = 'updated';
2924
-                    }
2925
-
2926
-                    // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2927
-                    $mtpg_fields = [
2928
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2929
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2930
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2931
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2932
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2933
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2934
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2935
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2936
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2937
-                            : '',
2938
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2939
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2940
-                            : '',
2941
-                    ];
2942
-
2943
-                    $mtpg_where = ['GRP_ID' => $set_column_values['GRP_ID']];
2944
-                    $updated    = $MTPG->update($mtpg_fields, [$mtpg_where]);
2945
-
2946
-                    if ($updated === false) {
2947
-                        EE_Error::add_error(
2948
-                            sprintf(
2949
-                                esc_html__(
2950
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2951
-                                    'event_espresso'
2952
-                                ),
2953
-                                $set_column_values['GRP_ID']
2954
-                            ),
2955
-                            __FILE__,
2956
-                            __FUNCTION__,
2957
-                            __LINE__
2958
-                        );
2959
-                    } else {
2960
-                        // k now we need to ensure the template_pack and template_variation fields are set.
2961
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2962
-                            ? $this->_req_data['MTP_template_pack']
2963
-                            : 'default';
2964
-
2965
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2966
-                            ? $this->_req_data['MTP_template_variation']
2967
-                            : 'default';
2968
-
2969
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2970
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2971
-                            $mtpg_obj->set_template_pack_name($template_pack);
2972
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2973
-                        }
2974
-                        $success = 1;
2975
-                    }
2976
-                }
2977
-            }
2978
-        }
2979
-
2980
-        // we return things differently if doing ajax
2981
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2982
-            $this->_template_args['success'] = $success;
2983
-            $this->_template_args['error']   = ! $success ? true : false;
2984
-            $this->_template_args['content'] = '';
2985
-            $this->_template_args['data']    = [
2986
-                'grpID'        => $edit_array['GRP_ID'],
2987
-                'templateName' => $edit_array['template_name'],
2988
-            ];
2989
-            if ($success) {
2990
-                EE_Error::overwrite_success();
2991
-                EE_Error::add_success(
2992
-                    esc_html__(
2993
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2994
-                        'event_espresso'
2995
-                    )
2996
-                );
2997
-            }
2998
-
2999
-            $this->_return_json();
3000
-        }
3001
-
3002
-
3003
-        // was a test send triggered?
3004
-        if (isset($this->_req_data['test_button'])) {
3005
-            EE_Error::overwrite_success();
3006
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
3007
-            $override = true;
3008
-        }
3009
-
3010
-        if (empty($query_args)) {
3011
-            $query_args = [
3012
-                'id'      => $this->_req_data['GRP_ID'],
3013
-                'context' => $context_slug,
3014
-                'action'  => 'edit_message_template',
3015
-            ];
3016
-        }
3017
-
3018
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
3019
-    }
3020
-
3021
-
3022
-    /**
3023
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3024
-     *
3025
-     * @param string $context      what context being tested
3026
-     * @param string $messenger    messenger being tested
3027
-     * @param string $message_type message type being tested
3028
-     * @throws EE_Error
3029
-     * @throws InvalidArgumentException
3030
-     * @throws InvalidDataTypeException
3031
-     * @throws InvalidInterfaceException
3032
-     */
3033
-    protected function _do_test_send($context, $messenger, $message_type)
3034
-    {
3035
-        // set things up for preview
3036
-        $this->_req_data['messenger']    = $messenger;
3037
-        $this->_req_data['message_type'] = $message_type;
3038
-        $this->_req_data['context']      = $context;
3039
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
3040
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
3041
-
3042
-        // let's save any existing fields that might be required by the messenger
3043
-        if (
3044
-            isset($this->_req_data['test_settings_fld'])
3045
-            && $active_messenger instanceof EE_messenger
3046
-            && apply_filters(
3047
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3048
-                true,
3049
-                $this->_req_data['test_settings_fld'],
3050
-                $active_messenger
3051
-            )
3052
-        ) {
3053
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
3054
-        }
3055
-
3056
-        /**
3057
-         * Use filter to add additional controls on whether message can send or not
3058
-         */
3059
-        if (
3060
-            apply_filters(
3061
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3062
-                true,
3063
-                $context,
3064
-                $this->_req_data,
3065
-                $messenger,
3066
-                $message_type
3067
-            )
3068
-        ) {
3069
-            if (EEM_Event::instance()->count() > 0) {
3070
-                $success = $this->_preview_message(true);
3071
-                if ($success) {
3072
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3073
-                } else {
3074
-                    EE_Error::add_error(
3075
-                        esc_html__('The test message was not sent', 'event_espresso'),
3076
-                        __FILE__,
3077
-                        __FUNCTION__,
3078
-                        __LINE__
3079
-                    );
3080
-                }
3081
-            } else {
3082
-                $this->noEventsErrorMessage(true);
3083
-            }
3084
-        }
3085
-    }
3086
-
3087
-
3088
-    /**
3089
-     * _generate_new_templates
3090
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3091
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3092
-     * for the event.
3093
-     *
3094
-     *
3095
-     * @param string $messenger      the messenger we are generating templates for
3096
-     * @param array  $message_types  array of message types that the templates are generated for.
3097
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3098
-     *                               indicate the message_template_group being used as the base.
3099
-     *
3100
-     * @param bool   $global
3101
-     *
3102
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3103
-     *                               encountering problems.
3104
-     * @throws EE_Error
3105
-     */
3106
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3107
-    {
3108
-
3109
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3110
-        // just don't generate any templates.
3111
-        if (empty($message_types)) {
3112
-            return true;
3113
-        }
3114
-
3115
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3116
-    }
3117
-
3118
-
3119
-    /**
3120
-     * [_trash_or_restore_message_template]
3121
-     *
3122
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3123
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3124
-     *                        an individual context (FALSE).
3125
-     * @return void
3126
-     * @throws EE_Error
3127
-     * @throws InvalidArgumentException
3128
-     * @throws InvalidDataTypeException
3129
-     * @throws InvalidInterfaceException
3130
-     */
3131
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3132
-    {
3133
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3134
-        $MTP = EEM_Message_Template_Group::instance();
3135
-
3136
-        $success = 1;
3137
-
3138
-        // incoming GRP_IDs
3139
-        if ($all) {
3140
-            // Checkboxes
3141
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3142
-                // if array has more than one element then success message should be plural.
3143
-                // todo: what about nonce?
3144
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3145
-
3146
-                // cycle through checkboxes
3147
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3148
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3149
-                    if (! $trashed_or_restored) {
3150
-                        $success = 0;
3151
-                    }
3152
-                }
3153
-            } else {
3154
-                // grab single GRP_ID and handle
3155
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3156
-                if (! empty($GRP_ID)) {
3157
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3158
-                    if (! $trashed_or_restored) {
3159
-                        $success = 0;
3160
-                    }
3161
-                } else {
3162
-                    $success = 0;
3163
-                }
3164
-            }
3165
-        }
3166
-
3167
-        $action_desc = $trash
3168
-            ? esc_html__('moved to the trash', 'event_espresso')
3169
-            : esc_html__('restored', 'event_espresso');
3170
-
3171
-        $action_desc =
3172
-            ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc;
3173
-
3174
-        $item_desc = $all ? _n(
3175
-            'Message Template Group',
3176
-            'Message Template Groups',
3177
-            $success,
3178
-            'event_espresso'
3179
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3180
-
3181
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n(
3182
-            'template',
3183
-            'templates',
3184
-            $success,
3185
-            'event_espresso'
3186
-        ) : $item_desc;
3187
-
3188
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3189
-    }
3190
-
3191
-
3192
-    /**
3193
-     * [_delete_message_template]
3194
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3195
-     *
3196
-     * @return void
3197
-     * @throws EE_Error
3198
-     * @throws InvalidArgumentException
3199
-     * @throws InvalidDataTypeException
3200
-     * @throws InvalidInterfaceException
3201
-     */
3202
-    protected function _delete_message_template()
3203
-    {
3204
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3205
-
3206
-        // checkboxes
3207
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3208
-            // if array has more than one element then success message should be plural
3209
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3210
-
3211
-            // cycle through bulk action checkboxes
3212
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3213
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3214
-            }
3215
-        } else {
3216
-            // grab single grp_id and delete
3217
-            $GRP_ID  = absint($this->_req_data['id']);
3218
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3219
-        }
3220
-
3221
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3222
-    }
3223
-
3224
-
3225
-    /**
3226
-     * helper for permanently deleting a mtP group and all related message_templates
3227
-     *
3228
-     * @param int  $GRP_ID        The group being deleted
3229
-     * @param bool $include_group whether to delete the Message Template Group as well.
3230
-     * @return bool boolean to indicate the success of the deletes or not.
3231
-     * @throws EE_Error
3232
-     * @throws InvalidArgumentException
3233
-     * @throws InvalidDataTypeException
3234
-     * @throws InvalidInterfaceException
3235
-     */
3236
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3237
-    {
3238
-        $success = 1;
3239
-        $MTPG    = EEM_Message_Template_Group::instance();
3240
-        // first let's GET this group
3241
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3242
-        // then delete permanently all the related Message Templates
3243
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3244
-
3245
-        if ($deleted === 0) {
3246
-            $success = 0;
3247
-        }
3248
-
3249
-        // now delete permanently this particular group
3250
-
3251
-        if ($include_group && ! $MTG->delete_permanently()) {
3252
-            $success = 0;
3253
-        }
3254
-
3255
-        return $success;
3256
-    }
3257
-
3258
-
3259
-    /**
3260
-     *    _learn_more_about_message_templates_link
3261
-     *
3262
-     * @access protected
3263
-     * @return string
3264
-     */
3265
-    protected function _learn_more_about_message_templates_link()
3266
-    {
3267
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3268
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3269
-               . '</a>';
3270
-    }
3271
-
3272
-
3273
-    /**
3274
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3275
-     * ajax and other routes.
3276
-     *
3277
-     * @return void
3278
-     * @throws DomainException
3279
-     */
3280
-    protected function _settings()
3281
-    {
3282
-
3283
-
3284
-        $this->_set_m_mt_settings();
3285
-
3286
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3287
-            ? $this->_req_data['selected_messenger']
3288
-            : 'email';
3289
-
3290
-        // let's setup the messenger tabs
3291
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3292
-            $this->_m_mt_settings['messenger_tabs'],
3293
-            'messenger_links',
3294
-            '|',
3295
-            $selected_messenger
3296
-        );
3297
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3298
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3299
-
3300
-        $this->display_admin_page_with_sidebar();
3301
-    }
3302
-
3303
-
3304
-    /**
3305
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3306
-     *
3307
-     * @access protected
3308
-     * @return void
3309
-     * @throws DomainException
3310
-     */
3311
-    protected function _set_m_mt_settings()
3312
-    {
3313
-        // first if this is already set then lets get out no need to regenerate data.
3314
-        if (! empty($this->_m_mt_settings)) {
3315
-            return;
3316
-        }
3317
-
3318
-        // get all installed messengers and message_types
3319
-        /** @type EE_messenger[] $messengers */
3320
-        $messengers = $this->_message_resource_manager->installed_messengers();
3321
-        /** @type EE_message_type[] $message_types */
3322
-        $message_types = $this->_message_resource_manager->installed_message_types();
3323
-
3324
-
3325
-        // assemble the array for the _tab_text_links helper
3326
-
3327
-        foreach ($messengers as $messenger) {
3328
-            $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3329
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3330
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3331
-                'label' => ucwords($messenger->label['singular']),
3332
-                'class' => $active ? "{$class} messenger-active" : $class,
3333
-                'href'  => $messenger->name,
3334
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3335
-                'slug'  => $messenger->name,
3336
-                'obj'   => $messenger,
3337
-                'icon' => $active
3338
-                    ? '<span class="dashicons dashicons-yes-alt"></span>'
3339
-                    : '<span class="dashicons dashicons-remove"></span>',
3340
-            ];
3341
-
3342
-
3343
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3344
-
3345
-            foreach ($message_types as $message_type) {
3346
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3347
-                // it shouldn't show in either the inactive OR active metabox.
3348
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3349
-                    continue;
3350
-                }
3351
-
3352
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3353
-                    $messenger->name,
3354
-                    $message_type->name
3355
-                )
3356
-                    ? 'active'
3357
-                    : 'inactive';
3358
-
3359
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3360
-                    'label'    => ucwords($message_type->label['singular']),
3361
-                    'class'    => 'message-type-' . $a_or_i,
3362
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3363
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3364
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3365
-                    'title'    => $a_or_i === 'active'
3366
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3367
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3368
-                    'content'  => $a_or_i === 'active'
3369
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3370
-                        : $this->_message_type_settings_content($message_type, $messenger),
3371
-                    'slug'     => $message_type->name,
3372
-                    'active'   => $a_or_i === 'active',
3373
-                    'obj'      => $message_type,
3374
-                ];
3375
-            }
3376
-        }
3377
-    }
3378
-
3379
-
3380
-    /**
3381
-     * This just prepares the content for the message type settings
3382
-     *
3383
-     * @param EE_message_type $message_type The message type object
3384
-     * @param EE_messenger    $messenger    The messenger object
3385
-     * @param boolean         $active       Whether the message type is active or not
3386
-     * @return string html output for the content
3387
-     * @throws DomainException
3388
-     */
3389
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3390
-    {
3391
-        // get message type fields
3392
-        $fields                                         = $message_type->get_admin_settings_fields();
3393
-        $settings_template_args['template_form_fields'] = '';
3394
-
3395
-        if (! empty($fields) && $active) {
3396
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3397
-            foreach ($fields as $fldname => $fldprops) {
3398
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3399
-                $template_form_field[ $field_id ] = [
3400
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3401
-                    'label'      => $fldprops['label'],
3402
-                    'input'      => $fldprops['field_type'],
3403
-                    'type'       => $fldprops['value_type'],
3404
-                    'required'   => $fldprops['required'],
3405
-                    'validation' => $fldprops['validation'],
3406
-                    'value'      => isset($existing_settings[ $fldname ])
3407
-                        ? $existing_settings[ $fldname ]
3408
-                        : $fldprops['default'],
3409
-                    'options'    => isset($fldprops['options'])
3410
-                        ? $fldprops['options']
3411
-                        : [],
3412
-                    'default'    => isset($existing_settings[ $fldname ])
3413
-                        ? $existing_settings[ $fldname ]
3414
-                        : $fldprops['default'],
3415
-                    'css_class'  => 'no-drag',
3416
-                    'format'     => $fldprops['format'],
3417
-                ];
3418
-            }
3419
-
3420
-
3421
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3422
-                ? $this->_generate_admin_form_fields(
3423
-                    $template_form_field,
3424
-                    'string',
3425
-                    'ee_mt_activate_form'
3426
-                )
3427
-                : '';
3428
-        }
3429
-
3430
-        $settings_template_args['description'] = $message_type->description;
3431
-        // we also need some hidden fields
3432
-        $hidden_fields = [
3433
-            'message_type_settings[messenger]' . $message_type->name   => [
3434
-                'type'  => 'hidden',
3435
-                'value' => $messenger->name,
3436
-            ],
3437
-            'message_type_settings[message_type]' . $message_type->name => [
3438
-                'type'  => 'hidden',
3439
-                'value' => $message_type->name,
3440
-            ],
3441
-            'type'   . $message_type->name                             => [
3442
-                'type'  => 'hidden',
3443
-                'value' => 'message_type',
3444
-            ],
3445
-        ];
3446
-
3447
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3448
-            $hidden_fields,
3449
-            'array'
3450
-        );
3451
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3452
-            ? ' hidden'
3453
-            : '';
3454
-
3455
-
3456
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3457
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
3458
-
3459
-        return $content;
3460
-    }
3461
-
3462
-
3463
-    /**
3464
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3465
-     *
3466
-     * @access protected
3467
-     * @return void
3468
-     * @throws DomainException
3469
-     */
3470
-    protected function _messages_settings_metaboxes()
3471
-    {
3472
-        $this->_set_m_mt_settings();
3473
-        $m_boxes         = $mt_boxes = [];
3474
-        $m_template_args = $mt_template_args = [];
3475
-
3476
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3477
-            ? $this->_req_data['selected_messenger']
3478
-            : 'email';
3479
-
3480
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3481
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3482
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3483
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3484
-                // messenger meta boxes
3485
-                $active                                   = $selected_messenger === $messenger;
3486
-                $active_mt_tabs                           = isset(
3487
-                    $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3488
-                )
3489
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3490
-                    : '';
3491
-                $m_boxes[ $messenger . '_a_box' ]         = sprintf(
3492
-                    esc_html__('%s Settings', 'event_espresso'),
3493
-                    $tab_array['label']
3494
-                );
3495
-                $m_template_args[ $messenger . '_a_box' ] = [
3496
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3497
-                    'inactive_message_types' => isset(
3498
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3499
-                    )
3500
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3501
-                        : '',
3502
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3503
-                    'hidden'                 => $active ? '' : ' hidden',
3504
-                    'hide_on_message'        => $hide_on_message,
3505
-                    'messenger'              => $messenger,
3506
-                    'active'                 => $active,
3507
-                ];
3508
-                // message type meta boxes
3509
-                // (which is really just the inactive container for each messenger
3510
-                // showing inactive message types for that messenger)
3511
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3512
-                $mt_template_args[ $messenger . '_i_box' ] = [
3513
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3514
-                    'inactive_message_types' => isset(
3515
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3516
-                    )
3517
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3518
-                        : '',
3519
-                    'hidden'                 => $active ? '' : ' hidden',
3520
-                    'hide_on_message'        => $hide_on_message,
3521
-                    'hide_off_message'       => $hide_off_message,
3522
-                    'messenger'              => $messenger,
3523
-                    'active'                 => $active,
3524
-                ];
3525
-            }
3526
-        }
3527
-
3528
-
3529
-        // register messenger metaboxes
3530
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3531
-        foreach ($m_boxes as $box => $label) {
3532
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3533
-            $msgr          = str_replace('_a_box', '', $box);
3534
-            $this->addMetaBox(
3535
-                'espresso_' . $msgr . '_settings',
3536
-                $label,
3537
-                function ($post, $metabox) {
3538
-                    EEH_Template::display_template(
3539
-                        $metabox['args']['template_path'],
3540
-                        $metabox['args']['template_args']
3541
-                    );
3542
-                },
3543
-                $this->_current_screen->id,
3544
-                'normal',
3545
-                'high',
3546
-                $callback_args
3547
-            );
3548
-        }
3549
-
3550
-        // register message type metaboxes
3551
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3552
-        foreach ($mt_boxes as $box => $label) {
3553
-            $callback_args = [
3554
-                'template_path' => $mt_template_path,
3555
-                'template_args' => $mt_template_args[ $box ],
3556
-            ];
3557
-            $mt            = str_replace('_i_box', '', $box);
3558
-            $this->addMetaBox(
3559
-                'espresso_' . $mt . '_inactive_mts',
3560
-                $label,
3561
-                function ($post, $metabox) {
3562
-                    EEH_Template::display_template(
3563
-                        $metabox['args']['template_path'],
3564
-                        $metabox['args']['template_args']
3565
-                    );
3566
-                },
3567
-                $this->_current_screen->id,
3568
-                'side',
3569
-                'high',
3570
-                $callback_args
3571
-            );
3572
-        }
3573
-
3574
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3575
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3576
-        if (is_main_site()) {
3577
-            $this->addMetaBox(
3578
-                'espresso_global_message_settings',
3579
-                esc_html__('Global Message Settings', 'event_espresso'),
3580
-                [$this, 'global_messages_settings_metabox_content'],
3581
-                $this->_current_screen->id,
3582
-                'normal',
3583
-                'low',
3584
-                []
3585
-            );
3586
-        }
3587
-    }
3588
-
3589
-
3590
-    /**
3591
-     *  This generates the content for the global messages settings metabox.
3592
-     *
3593
-     * @return void
3594
-     * @throws EE_Error
3595
-     * @throws InvalidArgumentException
3596
-     * @throws ReflectionException
3597
-     * @throws InvalidDataTypeException
3598
-     * @throws InvalidInterfaceException
3599
-     */
3600
-    public function global_messages_settings_metabox_content()
3601
-    {
3602
-        $form = $this->_generate_global_settings_form();
3603
-        // already escaped
3604
-        echo $form->form_open(
3605
-            $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3606
-            'POST'
3607
-        );
3608
-        echo $form->get_html();
3609
-        echo $form->form_close();
3610
-    }
3611
-
3612
-
3613
-    /**
3614
-     * This generates and returns the form object for the global messages settings.
3615
-     *
3616
-     * @return EE_Form_Section_Proper
3617
-     * @throws EE_Error
3618
-     * @throws InvalidArgumentException
3619
-     * @throws ReflectionException
3620
-     * @throws InvalidDataTypeException
3621
-     * @throws InvalidInterfaceException
3622
-     */
3623
-    protected function _generate_global_settings_form()
3624
-    {
3625
-        EE_Registry::instance()->load_helper('HTML');
3626
-        /** @var EE_Network_Core_Config $network_config */
3627
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3628
-
3629
-        return new EE_Form_Section_Proper(
3630
-            [
3631
-                'name'            => 'global_messages_settings',
3632
-                'html_id'         => 'global_messages_settings',
3633
-                'html_class'      => 'form-table',
3634
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3635
-                'subsections'     => apply_filters(
3636
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3637
-                    [
3638
-                        'do_messages_on_same_request' => new EE_Select_Input(
3639
-                            [
3640
-                                true  => esc_html__('On the same request', 'event_espresso'),
3641
-                                false => esc_html__('On a separate request', 'event_espresso'),
3642
-                            ],
3643
-                            [
3644
-                                'default'         => $network_config->do_messages_on_same_request,
3645
-                                'html_label_text' => esc_html__(
3646
-                                    'Generate and send all messages:',
3647
-                                    'event_espresso'
3648
-                                ),
3649
-                                'html_help_text'  => esc_html__(
3650
-                                    '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.',
3651
-                                    'event_espresso'
3652
-                                ),
3653
-                            ]
3654
-                        ),
3655
-                        'delete_threshold'            => new EE_Select_Input(
3656
-                            [
3657
-                                0  => esc_html__('Forever', 'event_espresso'),
3658
-                                3  => esc_html__('3 Months', 'event_espresso'),
3659
-                                6  => esc_html__('6 Months', 'event_espresso'),
3660
-                                9  => esc_html__('9 Months', 'event_espresso'),
3661
-                                12 => esc_html__('12 Months', 'event_espresso'),
3662
-                                24 => esc_html__('24 Months', 'event_espresso'),
3663
-                                36 => esc_html__('36 Months', 'event_espresso'),
3664
-                            ],
3665
-                            [
3666
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3667
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3668
-                                'html_help_text'  => esc_html__(
3669
-                                    'You can control how long a record of processed messages is kept via this option.',
3670
-                                    'event_espresso'
3671
-                                ),
3672
-                            ]
3673
-                        ),
3674
-                        'update_settings'             => new EE_Submit_Input(
3675
-                            [
3676
-                                'default'         => esc_html__('Update', 'event_espresso'),
3677
-                                'html_label_text' => '&nbsp',
3678
-                            ]
3679
-                        ),
3680
-                    ]
3681
-                ),
3682
-            ]
3683
-        );
3684
-    }
3685
-
3686
-
3687
-    /**
3688
-     * This handles updating the global settings set on the admin page.
3689
-     *
3690
-     * @throws EE_Error
3691
-     * @throws InvalidDataTypeException
3692
-     * @throws InvalidInterfaceException
3693
-     * @throws InvalidArgumentException
3694
-     * @throws ReflectionException
3695
-     */
3696
-    protected function _update_global_settings()
3697
-    {
3698
-        /** @var EE_Network_Core_Config $network_config */
3699
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3700
-        $messages_config = EE_Registry::instance()->CFG->messages;
3701
-        $form            = $this->_generate_global_settings_form();
3702
-        if ($form->was_submitted()) {
3703
-            $form->receive_form_submission();
3704
-            if ($form->is_valid()) {
3705
-                $valid_data = $form->valid_data();
3706
-                foreach ($valid_data as $property => $value) {
3707
-                    $setter = 'set_' . $property;
3708
-                    if (method_exists($network_config, $setter)) {
3709
-                        $network_config->{$setter}($value);
3710
-                    } elseif (
3711
-                        property_exists($network_config, $property)
3712
-                        && $network_config->{$property} !== $value
3713
-                    ) {
3714
-                        $network_config->{$property} = $value;
3715
-                    } elseif (
3716
-                        property_exists($messages_config, $property)
3717
-                        && $messages_config->{$property} !== $value
3718
-                    ) {
3719
-                        $messages_config->{$property} = $value;
3720
-                    }
3721
-                }
3722
-                // only update if the form submission was valid!
3723
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3724
-                EE_Registry::instance()->CFG->update_espresso_config();
3725
-                EE_Error::overwrite_success();
3726
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3727
-            }
3728
-        }
3729
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3730
-    }
3731
-
3732
-
3733
-    /**
3734
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3735
-     *
3736
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3737
-     * @return string html formatted tabs
3738
-     * @throws DomainException
3739
-     */
3740
-    protected function _get_mt_tabs($tab_array)
3741
-    {
3742
-        $tab_array = (array) $tab_array;
3743
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3744
-        $tabs      = '';
3745
-
3746
-        foreach ($tab_array as $tab) {
3747
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3748
-        }
3749
-
3750
-        return $tabs;
3751
-    }
3752
-
3753
-
3754
-    /**
3755
-     * This prepares the content of the messenger meta box admin settings
3756
-     *
3757
-     * @param EE_messenger $messenger The messenger we're setting up content for
3758
-     * @return string html formatted content
3759
-     * @throws DomainException
3760
-     */
3761
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3762
-    {
3763
-
3764
-        $fields                                         = $messenger->get_admin_settings_fields();
3765
-        $settings_template_args['template_form_fields'] = '';
3766
-
3767
-        // is $messenger active?
3768
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3769
-
3770
-
3771
-        if (! empty($fields)) {
3772
-            $existing_settings = $messenger->get_existing_admin_settings();
3773
-
3774
-            foreach ($fields as $fldname => $fldprops) {
3775
-                $field_id                         = $messenger->name . '-' . $fldname;
3776
-                $template_form_field[ $field_id ] = [
3777
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3778
-                    'label'      => $fldprops['label'],
3779
-                    'input'      => $fldprops['field_type'],
3780
-                    'type'       => $fldprops['value_type'],
3781
-                    'required'   => $fldprops['required'],
3782
-                    'validation' => $fldprops['validation'],
3783
-                    'value'      => isset($existing_settings[ $field_id ])
3784
-                        ? $existing_settings[ $field_id ]
3785
-                        : $fldprops['default'],
3786
-                    'css_class'  => '',
3787
-                    'format'     => $fldprops['format'],
3788
-                ];
3789
-            }
3790
-
3791
-
3792
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3793
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3794
-                : '';
3795
-        }
3796
-
3797
-        // we also need some hidden fields
3798
-        $settings_template_args['hidden_fields'] = [
3799
-            'messenger_settings[messenger]' . $messenger->name => [
3800
-                'type'  => 'hidden',
3801
-                'value' => $messenger->name,
3802
-            ],
3803
-            'type' . $messenger->name                          => [
3804
-                'type'  => 'hidden',
3805
-                'value' => 'messenger',
3806
-            ],
3807
-        ];
3808
-
3809
-        // make sure any active message types that are existing are included in the hidden fields
3810
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3811
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3812
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3813
-                    'type'  => 'hidden',
3814
-                    'value' => $mt,
3815
-                ];
3816
-            }
3817
-        }
3818
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3819
-            $settings_template_args['hidden_fields'],
3820
-            'array'
3821
-        );
3822
-        $active                                  =
3823
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3824
-
3825
-        $settings_template_args['messenger']           = $messenger->name;
3826
-        $settings_template_args['description']         = $messenger->description;
3827
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3828
-
3829
-
3830
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3831
-            $messenger->name
3832
-        )
3833
-            ? $settings_template_args['show_hide_edit_form']
3834
-            : ' hidden';
3835
-
3836
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3837
-            ? ' hidden'
3838
-            : $settings_template_args['show_hide_edit_form'];
3839
-
3840
-
3841
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3842
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3843
-        $settings_template_args['on_off_status'] = $active;
3844
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3845
-        return EEH_Template::display_template(
3846
-            $template,
3847
-            $settings_template_args,
3848
-            true
3849
-        );
3850
-    }
3851
-
3852
-
3853
-    /**
3854
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3855
-     *
3856
-     * @throws DomainException
3857
-     * @throws EE_Error
3858
-     * @throws InvalidDataTypeException
3859
-     * @throws InvalidInterfaceException
3860
-     * @throws InvalidArgumentException
3861
-     * @throws ReflectionException
3862
-     */
3863
-    public function activate_messenger_toggle()
3864
-    {
3865
-        $success = true;
3866
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3867
-        // let's check that we have required data
3868
-        if (! isset($this->_req_data['messenger'])) {
3869
-            EE_Error::add_error(
3870
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3871
-                __FILE__,
3872
-                __FUNCTION__,
3873
-                __LINE__
3874
-            );
3875
-            $success = false;
3876
-        }
3877
-
3878
-        // do a nonce check here since we're not arriving via a normal route
3879
-        $nonce     = isset($this->_req_data['activate_nonce'])
3880
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3881
-            : '';
3882
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3883
-
3884
-        $this->_verify_nonce($nonce, $nonce_ref);
3885
-
3886
-
3887
-        if (! isset($this->_req_data['status'])) {
3888
-            EE_Error::add_error(
3889
-                esc_html__(
3890
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3891
-                    'event_espresso'
3892
-                ),
3893
-                __FILE__,
3894
-                __FUNCTION__,
3895
-                __LINE__
3896
-            );
3897
-            $success = false;
3898
-        }
3899
-
3900
-        // do check to verify we have a valid status.
3901
-        $status = $this->_req_data['status'];
3902
-
3903
-        if ($status !== 'off' && $status !== 'on') {
3904
-            EE_Error::add_error(
3905
-                sprintf(
3906
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3907
-                    $this->_req_data['status']
3908
-                ),
3909
-                __FILE__,
3910
-                __FUNCTION__,
3911
-                __LINE__
3912
-            );
3913
-            $success = false;
3914
-        }
3915
-
3916
-        if ($success) {
3917
-            // made it here?  Stop dawdling then!!
3918
-            $success = $status === 'off'
3919
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3920
-                : $this->_activate_messenger($this->_req_data['messenger']);
3921
-        }
3922
-
3923
-        $this->_template_args['success'] = $success;
3924
-
3925
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
3926
-        $this->_return_json();
3927
-    }
3928
-
3929
-
3930
-    /**
3931
-     * used by ajax from the messages settings page to activate|deactivate a message type
3932
-     *
3933
-     * @throws DomainException
3934
-     * @throws EE_Error
3935
-     * @throws ReflectionException
3936
-     * @throws InvalidDataTypeException
3937
-     * @throws InvalidInterfaceException
3938
-     * @throws InvalidArgumentException
3939
-     */
3940
-    public function activate_mt_toggle()
3941
-    {
3942
-        $success = true;
3943
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3944
-
3945
-        // let's make sure we have the necessary data
3946
-        if (! isset($this->_req_data['message_type'])) {
3947
-            EE_Error::add_error(
3948
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3949
-                __FILE__,
3950
-                __FUNCTION__,
3951
-                __LINE__
3952
-            );
3953
-            $success = false;
3954
-        }
3955
-
3956
-        if (! isset($this->_req_data['messenger'])) {
3957
-            EE_Error::add_error(
3958
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3959
-                __FILE__,
3960
-                __FUNCTION__,
3961
-                __LINE__
3962
-            );
3963
-            $success = false;
3964
-        }
3965
-
3966
-        if (! isset($this->_req_data['status'])) {
3967
-            EE_Error::add_error(
3968
-                esc_html__(
3969
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3970
-                    'event_espresso'
3971
-                ),
3972
-                __FILE__,
3973
-                __FUNCTION__,
3974
-                __LINE__
3975
-            );
3976
-            $success = false;
3977
-        }
3978
-
3979
-
3980
-        // do check to verify we have a valid status.
3981
-        $status = $this->_req_data['status'];
3982
-
3983
-        if ($status !== 'activate' && $status !== 'deactivate') {
3984
-            EE_Error::add_error(
3985
-                sprintf(
3986
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3987
-                    $this->_req_data['status']
3988
-                ),
3989
-                __FILE__,
3990
-                __FUNCTION__,
3991
-                __LINE__
3992
-            );
3993
-            $success = false;
3994
-        }
3995
-
3996
-
3997
-        // do a nonce check here since we're not arriving via a normal route
3998
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3999
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
4000
-
4001
-        $this->_verify_nonce($nonce, $nonce_ref);
4002
-
4003
-        if ($success) {
4004
-            // made it here? um, what are you waiting for then?
4005
-            $success = $status === 'deactivate'
4006
-                ? $this->_deactivate_message_type_for_messenger(
4007
-                    $this->_req_data['messenger'],
4008
-                    $this->_req_data['message_type']
4009
-                )
4010
-                : $this->_activate_message_type_for_messenger(
4011
-                    $this->_req_data['messenger'],
4012
-                    $this->_req_data['message_type']
4013
-                );
4014
-        }
4015
-
4016
-        $this->_template_args['success'] = $success;
4017
-        $this->_return_json();
4018
-    }
4019
-
4020
-
4021
-    /**
4022
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4023
-     *
4024
-     * @param string $messenger_name The name of the messenger being activated
4025
-     * @return bool
4026
-     * @throws DomainException
4027
-     * @throws EE_Error
4028
-     * @throws InvalidArgumentException
4029
-     * @throws ReflectionException
4030
-     * @throws InvalidDataTypeException
4031
-     * @throws InvalidInterfaceException
4032
-     */
4033
-    protected function _activate_messenger($messenger_name)
4034
-    {
4035
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4036
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4037
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4038
-            ? $active_messenger->get_default_message_types()
4039
-            : [];
4040
-
4041
-        // ensure is active
4042
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4043
-
4044
-        // set response_data for reload
4045
-        foreach ($message_types_to_activate as $message_type_name) {
4046
-            /** @var EE_message_type $message_type */
4047
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4048
-            if (
4049
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4050
-                    $messenger_name,
4051
-                    $message_type_name
4052
-                )
4053
-                && $message_type instanceof EE_message_type
4054
-            ) {
4055
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4056
-                if ($message_type->get_admin_settings_fields()) {
4057
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4058
-                }
4059
-            }
4060
-        }
4061
-
4062
-        // add success message for activating messenger
4063
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4064
-    }
4065
-
4066
-
4067
-    /**
4068
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4069
-     *
4070
-     * @param string $messenger_name The name of the messenger being activated
4071
-     * @return bool
4072
-     * @throws DomainException
4073
-     * @throws EE_Error
4074
-     * @throws InvalidArgumentException
4075
-     * @throws ReflectionException
4076
-     * @throws InvalidDataTypeException
4077
-     * @throws InvalidInterfaceException
4078
-     */
4079
-    protected function _deactivate_messenger($messenger_name)
4080
-    {
4081
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4082
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4083
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4084
-
4085
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4086
-    }
4087
-
4088
-
4089
-    /**
4090
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4091
-     *
4092
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4093
-     * @param string $message_type_name The name of the message type being activated for the messenger
4094
-     * @return bool
4095
-     * @throws DomainException
4096
-     * @throws EE_Error
4097
-     * @throws InvalidArgumentException
4098
-     * @throws ReflectionException
4099
-     * @throws InvalidDataTypeException
4100
-     * @throws InvalidInterfaceException
4101
-     */
4102
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4103
-    {
4104
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4105
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4106
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4107
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4108
-
4109
-        // ensure is active
4110
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4111
-
4112
-        // set response for load
4113
-        if (
4114
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4115
-                $messenger_name,
4116
-                $message_type_name
4117
-            )
4118
-        ) {
4119
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4120
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4121
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4122
-            }
4123
-        }
4124
-
4125
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4126
-            $active_messenger,
4127
-            $message_type_to_activate
4128
-        );
4129
-    }
4130
-
4131
-
4132
-    /**
4133
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4134
-     *
4135
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4136
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4137
-     * @return bool
4138
-     * @throws DomainException
4139
-     * @throws EE_Error
4140
-     * @throws InvalidArgumentException
4141
-     * @throws ReflectionException
4142
-     * @throws InvalidDataTypeException
4143
-     * @throws InvalidInterfaceException
4144
-     */
4145
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4146
-    {
4147
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4148
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4149
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4150
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4151
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4152
-
4153
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4154
-            $active_messenger,
4155
-            $message_type_to_deactivate
4156
-        );
4157
-    }
4158
-
4159
-
4160
-    /**
4161
-     * This just initializes the defaults for activating messenger and message type responses.
4162
-     */
4163
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4164
-    {
4165
-        $this->_template_args['data']['active_mts'] = [];
4166
-        $this->_template_args['data']['mt_reload']  = [];
4167
-    }
4168
-
4169
-
4170
-    /**
4171
-     * Setup appropriate response for activating a messenger and/or message types
4172
-     *
4173
-     * @param EE_messenger         $messenger
4174
-     * @param EE_message_type|null $message_type
4175
-     * @return bool
4176
-     * @throws DomainException
4177
-     * @throws EE_Error
4178
-     * @throws InvalidArgumentException
4179
-     * @throws ReflectionException
4180
-     * @throws InvalidDataTypeException
4181
-     * @throws InvalidInterfaceException
4182
-     */
4183
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4184
-        $messenger,
4185
-        EE_Message_Type $message_type = null
4186
-    ) {
4187
-        // if $messenger isn't a valid messenger object then get out.
4188
-        if (! $messenger instanceof EE_Messenger) {
4189
-            EE_Error::add_error(
4190
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4191
-                __FILE__,
4192
-                __FUNCTION__,
4193
-                __LINE__
4194
-            );
4195
-
4196
-            return false;
4197
-        }
4198
-        // activated
4199
-        if ($this->_template_args['data']['active_mts']) {
4200
-            EE_Error::overwrite_success();
4201
-            // activated a message type with the messenger
4202
-            if ($message_type instanceof EE_message_type) {
4203
-                EE_Error::add_success(
4204
-                    sprintf(
4205
-                        esc_html__(
4206
-                            '%s message type has been successfully activated with the %s messenger',
4207
-                            'event_espresso'
4208
-                        ),
4209
-                        ucwords($message_type->label['singular']),
4210
-                        ucwords($messenger->label['singular'])
4211
-                    )
4212
-                );
4213
-
4214
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4215
-                if ($message_type->name === 'invoice') {
4216
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4217
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4218
-                    if ($pm instanceof EE_Payment_Method) {
4219
-                        EE_Error::add_attention(
4220
-                            esc_html__(
4221
-                                '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.',
4222
-                                'event_espresso'
4223
-                            )
4224
-                        );
4225
-                    }
4226
-                }
4227
-                // just toggles the entire messenger
4228
-            } else {
4229
-                EE_Error::add_success(
4230
-                    sprintf(
4231
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4232
-                        ucwords($messenger->label['singular'])
4233
-                    )
4234
-                );
4235
-            }
4236
-
4237
-            return true;
4238
-
4239
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4240
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4241
-            // in which case we just give a success message for the messenger being successfully activated.
4242
-        } else {
4243
-            if (! $messenger->get_default_message_types()) {
4244
-                // messenger doesn't have any default message types so still a success.
4245
-                EE_Error::add_success(
4246
-                    sprintf(
4247
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4248
-                        ucwords($messenger->label['singular'])
4249
-                    )
4250
-                );
4251
-
4252
-                return true;
4253
-            } else {
4254
-                EE_Error::add_error(
4255
-                    $message_type instanceof EE_message_type
4256
-                        ? sprintf(
4257
-                            esc_html__(
4258
-                                '%s message type was not successfully activated with the %s messenger',
4259
-                                'event_espresso'
4260
-                            ),
4261
-                            ucwords($message_type->label['singular']),
4262
-                            ucwords($messenger->label['singular'])
4263
-                        )
4264
-                        : sprintf(
4265
-                            esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4266
-                            ucwords($messenger->label['singular'])
4267
-                        ),
4268
-                    __FILE__,
4269
-                    __FUNCTION__,
4270
-                    __LINE__
4271
-                );
4272
-
4273
-                return false;
4274
-            }
4275
-        }
4276
-    }
4277
-
4278
-
4279
-    /**
4280
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4281
-     *
4282
-     * @param EE_messenger         $messenger
4283
-     * @param EE_message_type|null $message_type
4284
-     * @return bool
4285
-     * @throws DomainException
4286
-     * @throws EE_Error
4287
-     * @throws InvalidArgumentException
4288
-     * @throws ReflectionException
4289
-     * @throws InvalidDataTypeException
4290
-     * @throws InvalidInterfaceException
4291
-     */
4292
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4293
-        $messenger,
4294
-        EE_message_type $message_type = null
4295
-    ) {
4296
-        EE_Error::overwrite_success();
4297
-
4298
-        // if $messenger isn't a valid messenger object then get out.
4299
-        if (! $messenger instanceof EE_Messenger) {
4300
-            EE_Error::add_error(
4301
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4302
-                __FILE__,
4303
-                __FUNCTION__,
4304
-                __LINE__
4305
-            );
4306
-
4307
-            return false;
4308
-        }
4309
-
4310
-        if ($message_type instanceof EE_message_type) {
4311
-            $message_type_name = $message_type->name;
4312
-            EE_Error::add_success(
4313
-                sprintf(
4314
-                    esc_html__(
4315
-                        '%s message type has been successfully deactivated for the %s messenger.',
4316
-                        'event_espresso'
4317
-                    ),
4318
-                    ucwords($message_type->label['singular']),
4319
-                    ucwords($messenger->label['singular'])
4320
-                )
4321
-            );
4322
-        } else {
4323
-            $message_type_name = '';
4324
-            EE_Error::add_success(
4325
-                sprintf(
4326
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4327
-                    ucwords($messenger->label['singular'])
4328
-                )
4329
-            );
4330
-        }
4331
-
4332
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4333
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4334
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4335
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4336
-            if ($count_updated > 0) {
4337
-                $msg = $message_type_name === 'invoice'
4338
-                    ? esc_html__(
4339
-                        '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.',
4340
-                        'event_espresso'
4341
-                    )
4342
-                    : esc_html__(
4343
-                        '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.',
4344
-                        'event_espresso'
4345
-                    );
4346
-                EE_Error::add_attention($msg);
4347
-            }
4348
-        }
4349
-
4350
-        return true;
4351
-    }
4352
-
4353
-
4354
-    /**
4355
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4356
-     *
4357
-     * @throws DomainException
4358
-     */
4359
-    public function update_mt_form()
4360
-    {
4361
-        if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4362
-            EE_Error::add_error(
4363
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4364
-                __FILE__,
4365
-                __FUNCTION__,
4366
-                __LINE__
4367
-            );
4368
-            $this->_return_json();
4369
-        }
4370
-
4371
-        $message_types = $this->get_installed_message_types();
4372
-
4373
-        $message_type = $message_types[ $this->_req_data['message_type'] ];
4374
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4375
-
4376
-        $content                         = $this->_message_type_settings_content(
4377
-            $message_type,
4378
-            $messenger,
4379
-            true
4380
-        );
4381
-        $this->_template_args['success'] = true;
4382
-        $this->_template_args['content'] = $content;
4383
-        $this->_return_json();
4384
-    }
4385
-
4386
-
4387
-    /**
4388
-     * this handles saving the settings for a messenger or message type
4389
-     *
4390
-     */
4391
-    public function save_settings()
4392
-    {
4393
-        if (! isset($this->_req_data['type'])) {
4394
-            EE_Error::add_error(
4395
-                esc_html__(
4396
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4397
-                    'event_espresso'
4398
-                ),
4399
-                __FILE__,
4400
-                __FUNCTION__,
4401
-                __LINE__
4402
-            );
4403
-            $this->_template_args['error'] = true;
4404
-            $this->_return_json();
4405
-        }
4406
-
4407
-
4408
-        if ($this->_req_data['type'] === 'messenger') {
4409
-            // this should be an array.
4410
-            $settings  = $this->_req_data['messenger_settings'];
4411
-            $messenger = $settings['messenger'];
4412
-            // let's setup the settings data
4413
-            foreach ($settings as $key => $value) {
4414
-                switch ($key) {
4415
-                    case 'messenger':
4416
-                        unset($settings['messenger']);
4417
-                        break;
4418
-                    case 'message_types':
4419
-                        unset($settings['message_types']);
4420
-                        break;
4421
-                    default:
4422
-                        $settings[ $key ] = $value;
4423
-                        break;
4424
-                }
4425
-            }
4426
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4427
-        } elseif ($this->_req_data['type'] === 'message_type') {
4428
-            $settings     = $this->_req_data['message_type_settings'];
4429
-            $messenger    = $settings['messenger'];
4430
-            $message_type = $settings['message_type'];
4431
-
4432
-            foreach ($settings as $key => $value) {
4433
-                switch ($key) {
4434
-                    case 'messenger':
4435
-                        unset($settings['messenger']);
4436
-                        break;
4437
-                    case 'message_type':
4438
-                        unset($settings['message_type']);
4439
-                        break;
4440
-                    default:
4441
-                        $settings[ $key ] = $value;
4442
-                        break;
4443
-                }
4444
-            }
4445
-
4446
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4447
-        }
4448
-
4449
-        // okay we should have the data all setup.  Now we just update!
4450
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4451
-
4452
-        if ($success) {
4453
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4454
-        } else {
4455
-            EE_Error::add_error(
4456
-                esc_html__(
4457
-                    'Settings did not get updated',
4458
-                    'event_espresso'
4459
-                ),
4460
-                __FILE__,
4461
-                __FUNCTION__,
4462
-                __LINE__
4463
-            );
4464
-        }
4465
-
4466
-        $this->_template_args['success'] = $success;
4467
-        $this->_return_json();
4468
-    }
4469
-
4470
-
4471
-
4472
-
4473
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4474
-
4475
-
4476
-    /**
4477
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4478
-     * However, this does not send immediately, it just queues for sending.
4479
-     *
4480
-     * @throws EE_Error
4481
-     * @throws InvalidDataTypeException
4482
-     * @throws InvalidInterfaceException
4483
-     * @throws InvalidArgumentException
4484
-     * @throws ReflectionException
4485
-     * @since 4.9.0
4486
-     */
4487
-    protected function _generate_now()
4488
-    {
4489
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4490
-        $this->_redirect_after_action(false, '', '', [], true);
4491
-    }
4492
-
4493
-
4494
-    /**
4495
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4496
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4497
-     *
4498
-     * @throws EE_Error
4499
-     * @throws InvalidDataTypeException
4500
-     * @throws InvalidInterfaceException
4501
-     * @throws InvalidArgumentException
4502
-     * @throws ReflectionException
4503
-     * @since 4.9.0
4504
-     */
4505
-    protected function _generate_and_send_now()
4506
-    {
4507
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4508
-        $this->_redirect_after_action(false, '', '', [], true);
4509
-    }
4510
-
4511
-
4512
-    /**
4513
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4514
-     *
4515
-     * @throws EE_Error
4516
-     * @throws InvalidDataTypeException
4517
-     * @throws InvalidInterfaceException
4518
-     * @throws InvalidArgumentException
4519
-     * @throws ReflectionException
4520
-     * @since 4.9.0
4521
-     */
4522
-    protected function _queue_for_resending()
4523
-    {
4524
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4525
-        $this->_redirect_after_action(false, '', '', [], true);
4526
-    }
4527
-
4528
-
4529
-    /**
4530
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4531
-     *
4532
-     * @throws EE_Error
4533
-     * @throws InvalidDataTypeException
4534
-     * @throws InvalidInterfaceException
4535
-     * @throws InvalidArgumentException
4536
-     * @throws ReflectionException
4537
-     * @since 4.9.0
4538
-     */
4539
-    protected function _send_now()
4540
-    {
4541
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4542
-        $this->_redirect_after_action(false, '', '', [], true);
4543
-    }
4544
-
4545
-
4546
-    /**
4547
-     * Deletes EE_messages for IDs in the request.
4548
-     *
4549
-     * @throws EE_Error
4550
-     * @throws InvalidDataTypeException
4551
-     * @throws InvalidInterfaceException
4552
-     * @throws InvalidArgumentException
4553
-     * @since 4.9.0
4554
-     */
4555
-    protected function _delete_ee_messages()
4556
-    {
4557
-        $msg_ids       = $this->_get_msg_ids_from_request();
4558
-        $deleted_count = 0;
4559
-        foreach ($msg_ids as $msg_id) {
4560
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4561
-                $deleted_count++;
4562
-            }
4563
-        }
4564
-        if ($deleted_count) {
4565
-            EE_Error::add_success(
4566
-                esc_html(
4567
-                    _n(
4568
-                        'Message successfully deleted',
4569
-                        'Messages successfully deleted',
4570
-                        $deleted_count,
4571
-                        'event_espresso'
4572
-                    )
4573
-                )
4574
-            );
4575
-            $this->_redirect_after_action(
4576
-                false,
4577
-                '',
4578
-                '',
4579
-                [],
4580
-                true
4581
-            );
4582
-        } else {
4583
-            EE_Error::add_error(
4584
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4585
-                __FILE__,
4586
-                __FUNCTION__,
4587
-                __LINE__
4588
-            );
4589
-            $this->_redirect_after_action(false, '', '', [], true);
4590
-        }
4591
-    }
4592
-
4593
-
4594
-    /**
4595
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4596
-     *
4597
-     * @return array
4598
-     * @since 4.9.0
4599
-     */
4600
-    protected function _get_msg_ids_from_request()
4601
-    {
4602
-        if (! isset($this->_req_data['MSG_ID'])) {
4603
-            return [];
4604
-        }
4605
-
4606
-        return is_array($this->_req_data['MSG_ID'])
4607
-            ? array_keys($this->_req_data['MSG_ID'])
4608
-            : [$this->_req_data['MSG_ID']];
4609
-    }
2685
+	}
2686
+
2687
+
2688
+	/**
2689
+	 * utility for sanitizing new values coming in.
2690
+	 * Note: this is only used when updating a context.
2691
+	 *
2692
+	 * @access protected
2693
+	 *
2694
+	 * @param int $index This helps us know which template field to select from the request array.
2695
+	 *
2696
+	 * @return array
2697
+	 */
2698
+	protected function _set_message_template_column_values($index)
2699
+	{
2700
+		if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2701
+			foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2702
+				$this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2703
+			}
2704
+		}
2705
+
2706
+
2707
+		$set_column_values = [
2708
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2709
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2710
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2711
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2712
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2713
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2714
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2715
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2716
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2717
+				? absint($this->_req_data['MTP_is_global'])
2718
+				: 0,
2719
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2720
+				? absint($this->_req_data['MTP_is_override'])
2721
+				: 0,
2722
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2723
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active']),
2724
+		];
2725
+
2726
+
2727
+		return $set_column_values;
2728
+	}
2729
+
2730
+
2731
+	protected function _insert_or_update_message_template($new = false)
2732
+	{
2733
+		$success = 0;
2734
+		$override = false;
2735
+
2736
+		// setup notices description
2737
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2738
+
2739
+		// need the message type and messenger objects to be able to use the labels for the notices
2740
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2741
+		$messenger_label  = $messenger_object instanceof EE_messenger
2742
+			? ucwords($messenger_object->label['singular'])
2743
+			: '';
2744
+
2745
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type'])
2746
+			? $this->_req_data['MTP_message_type']
2747
+			: '';
2748
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2749
+
2750
+		$message_type_label = $message_type_object instanceof EE_message_type
2751
+			? ucwords($message_type_object->label['singular'])
2752
+			: '';
2753
+
2754
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2755
+			? $this->_req_data['MTP_context']
2756
+			: '';
2757
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2758
+
2759
+		$item_desc   = $messenger_label && $message_type_label
2760
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2761
+			: '';
2762
+		$item_desc   .= 'Message Template';
2763
+		$query_args  = [];
2764
+		$edit_array  = [];
2765
+		$action_desc = '';
2766
+
2767
+		// if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2768
+		// user to edit.
2769
+		if ($new) {
2770
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2771
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2772
+				if (empty($edit_array)) {
2773
+					$success = 0;
2774
+				} else {
2775
+					$success    = 1;
2776
+					$edit_array = $edit_array[0];
2777
+					$query_args = [
2778
+						'id'      => $edit_array['GRP_ID'],
2779
+						'context' => $edit_array['MTP_context'],
2780
+						'action'  => 'edit_message_template',
2781
+					];
2782
+				}
2783
+			}
2784
+			$action_desc = 'created';
2785
+		} else {
2786
+			$MTPG = EEM_Message_Template_Group::instance();
2787
+			$MTP  = EEM_Message_Template::instance();
2788
+
2789
+
2790
+			// run update for each template field in displayed context
2791
+			if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2792
+				EE_Error::add_error(
2793
+					esc_html__(
2794
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2795
+						'event_espresso'
2796
+					),
2797
+					__FILE__,
2798
+					__FUNCTION__,
2799
+					__LINE__
2800
+				);
2801
+				$success = 0;
2802
+			} else {
2803
+				// first validate all fields!
2804
+				// this filter allows client code to add its own validation to the template fields as well.
2805
+				// returning an empty array means everything passed validation.
2806
+				// errors in validation should be represented in an array with the following shape:
2807
+				// array(
2808
+				//   'fieldname' => array(
2809
+				//          'msg' => 'error message'
2810
+				//          'value' => 'value for field producing error'
2811
+				// )
2812
+				$custom_validation = (array) apply_filters(
2813
+					'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2814
+					[],
2815
+					$this->_req_data['MTP_template_fields'],
2816
+					$context_slug,
2817
+					$messenger_slug,
2818
+					$message_type_slug
2819
+				);
2820
+
2821
+				$system_validation = $MTPG->validate(
2822
+					$this->_req_data['MTP_template_fields'],
2823
+					$context_slug,
2824
+					$messenger_slug,
2825
+					$message_type_slug
2826
+				);
2827
+
2828
+				$system_validation = ! is_array($system_validation) && $system_validation ? []
2829
+					: $system_validation;
2830
+				$validates         = array_merge($custom_validation, $system_validation);
2831
+
2832
+				// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2833
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2834
+				//  WE need to make sure there is no actual error messages in validates.
2835
+				if (is_array($validates) && ! empty($validates)) {
2836
+					// add the transient so when the form loads we know which fields to highlight
2837
+					$this->_add_transient('edit_message_template', $validates);
2838
+
2839
+					$success = 0;
2840
+
2841
+					// setup notices
2842
+					foreach ($validates as $field => $error) {
2843
+						if (isset($error['msg'])) {
2844
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2845
+						}
2846
+					}
2847
+				} else {
2848
+					$set_column_values = [];
2849
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2850
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2851
+
2852
+						$where_cols_n_values = [
2853
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2854
+						];
2855
+						// if they aren't allowed to use all JS, restrict them to just posty-y tags
2856
+						if (! current_user_can('unfiltered_html')) {
2857
+							if (is_array($set_column_values['MTP_content'])) {
2858
+								foreach ($set_column_values['MTP_content'] as $key => $value) {
2859
+									// remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2860
+									// only removes slashes from double-quotes, so attributes using single quotes always
2861
+									// appear invalid.) But currently the models expect slashed data, so after wp_kses
2862
+									// runs we need to re-slash the data. Sheesh. See
2863
+									// https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2864
+									$set_column_values['MTP_content'][ $key ] = addslashes(
2865
+										wp_kses(
2866
+											stripslashes($value),
2867
+											wp_kses_allowed_html('post')
2868
+										)
2869
+									);
2870
+								}
2871
+							} else {
2872
+								$set_column_values['MTP_content'] = wp_kses(
2873
+									$set_column_values['MTP_content'],
2874
+									wp_kses_allowed_html('post')
2875
+								);
2876
+							}
2877
+						}
2878
+						$message_template_fields = [
2879
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2880
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2881
+							'MTP_context'        => $set_column_values['MTP_context'],
2882
+							'MTP_content'        => $set_column_values['MTP_content'],
2883
+						];
2884
+						if ($updated = $MTP->update($message_template_fields, [$where_cols_n_values])) {
2885
+							if ($updated === false) {
2886
+								EE_Error::add_error(
2887
+									sprintf(
2888
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2889
+										$template_field
2890
+									),
2891
+									__FILE__,
2892
+									__FUNCTION__,
2893
+									__LINE__
2894
+								);
2895
+							} else {
2896
+								$success = 1;
2897
+							}
2898
+						} else {
2899
+							// only do this logic if we don't have a MTP_ID for this field
2900
+							if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2901
+								// this has already been through the template field validator and sanitized, so it will be
2902
+								// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2903
+								// message template field in a messenger/message type and existing users don't have the
2904
+								// default setup for it.
2905
+								// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2906
+								$updated = $MTP->insert($message_template_fields);
2907
+								if (! $updated || is_wp_error($updated)) {
2908
+									EE_Error::add_error(
2909
+										sprintf(
2910
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2911
+											$template_field
2912
+										),
2913
+										__FILE__,
2914
+										__FUNCTION__,
2915
+										__LINE__
2916
+									);
2917
+									$success = 0;
2918
+								} else {
2919
+									$success = 1;
2920
+								}
2921
+							}
2922
+						}
2923
+						$action_desc = 'updated';
2924
+					}
2925
+
2926
+					// we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2927
+					$mtpg_fields = [
2928
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2929
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2930
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2931
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2932
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2933
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2934
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2935
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2936
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2937
+							: '',
2938
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2939
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2940
+							: '',
2941
+					];
2942
+
2943
+					$mtpg_where = ['GRP_ID' => $set_column_values['GRP_ID']];
2944
+					$updated    = $MTPG->update($mtpg_fields, [$mtpg_where]);
2945
+
2946
+					if ($updated === false) {
2947
+						EE_Error::add_error(
2948
+							sprintf(
2949
+								esc_html__(
2950
+									'The Message Template Group (%d) was NOT updated for some reason',
2951
+									'event_espresso'
2952
+								),
2953
+								$set_column_values['GRP_ID']
2954
+							),
2955
+							__FILE__,
2956
+							__FUNCTION__,
2957
+							__LINE__
2958
+						);
2959
+					} else {
2960
+						// k now we need to ensure the template_pack and template_variation fields are set.
2961
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2962
+							? $this->_req_data['MTP_template_pack']
2963
+							: 'default';
2964
+
2965
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2966
+							? $this->_req_data['MTP_template_variation']
2967
+							: 'default';
2968
+
2969
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2970
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2971
+							$mtpg_obj->set_template_pack_name($template_pack);
2972
+							$mtpg_obj->set_template_pack_variation($template_variation);
2973
+						}
2974
+						$success = 1;
2975
+					}
2976
+				}
2977
+			}
2978
+		}
2979
+
2980
+		// we return things differently if doing ajax
2981
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2982
+			$this->_template_args['success'] = $success;
2983
+			$this->_template_args['error']   = ! $success ? true : false;
2984
+			$this->_template_args['content'] = '';
2985
+			$this->_template_args['data']    = [
2986
+				'grpID'        => $edit_array['GRP_ID'],
2987
+				'templateName' => $edit_array['template_name'],
2988
+			];
2989
+			if ($success) {
2990
+				EE_Error::overwrite_success();
2991
+				EE_Error::add_success(
2992
+					esc_html__(
2993
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2994
+						'event_espresso'
2995
+					)
2996
+				);
2997
+			}
2998
+
2999
+			$this->_return_json();
3000
+		}
3001
+
3002
+
3003
+		// was a test send triggered?
3004
+		if (isset($this->_req_data['test_button'])) {
3005
+			EE_Error::overwrite_success();
3006
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
3007
+			$override = true;
3008
+		}
3009
+
3010
+		if (empty($query_args)) {
3011
+			$query_args = [
3012
+				'id'      => $this->_req_data['GRP_ID'],
3013
+				'context' => $context_slug,
3014
+				'action'  => 'edit_message_template',
3015
+			];
3016
+		}
3017
+
3018
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
3019
+	}
3020
+
3021
+
3022
+	/**
3023
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3024
+	 *
3025
+	 * @param string $context      what context being tested
3026
+	 * @param string $messenger    messenger being tested
3027
+	 * @param string $message_type message type being tested
3028
+	 * @throws EE_Error
3029
+	 * @throws InvalidArgumentException
3030
+	 * @throws InvalidDataTypeException
3031
+	 * @throws InvalidInterfaceException
3032
+	 */
3033
+	protected function _do_test_send($context, $messenger, $message_type)
3034
+	{
3035
+		// set things up for preview
3036
+		$this->_req_data['messenger']    = $messenger;
3037
+		$this->_req_data['message_type'] = $message_type;
3038
+		$this->_req_data['context']      = $context;
3039
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
3040
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
3041
+
3042
+		// let's save any existing fields that might be required by the messenger
3043
+		if (
3044
+			isset($this->_req_data['test_settings_fld'])
3045
+			&& $active_messenger instanceof EE_messenger
3046
+			&& apply_filters(
3047
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3048
+				true,
3049
+				$this->_req_data['test_settings_fld'],
3050
+				$active_messenger
3051
+			)
3052
+		) {
3053
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
3054
+		}
3055
+
3056
+		/**
3057
+		 * Use filter to add additional controls on whether message can send or not
3058
+		 */
3059
+		if (
3060
+			apply_filters(
3061
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3062
+				true,
3063
+				$context,
3064
+				$this->_req_data,
3065
+				$messenger,
3066
+				$message_type
3067
+			)
3068
+		) {
3069
+			if (EEM_Event::instance()->count() > 0) {
3070
+				$success = $this->_preview_message(true);
3071
+				if ($success) {
3072
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3073
+				} else {
3074
+					EE_Error::add_error(
3075
+						esc_html__('The test message was not sent', 'event_espresso'),
3076
+						__FILE__,
3077
+						__FUNCTION__,
3078
+						__LINE__
3079
+					);
3080
+				}
3081
+			} else {
3082
+				$this->noEventsErrorMessage(true);
3083
+			}
3084
+		}
3085
+	}
3086
+
3087
+
3088
+	/**
3089
+	 * _generate_new_templates
3090
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3091
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3092
+	 * for the event.
3093
+	 *
3094
+	 *
3095
+	 * @param string $messenger      the messenger we are generating templates for
3096
+	 * @param array  $message_types  array of message types that the templates are generated for.
3097
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3098
+	 *                               indicate the message_template_group being used as the base.
3099
+	 *
3100
+	 * @param bool   $global
3101
+	 *
3102
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3103
+	 *                               encountering problems.
3104
+	 * @throws EE_Error
3105
+	 */
3106
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3107
+	{
3108
+
3109
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3110
+		// just don't generate any templates.
3111
+		if (empty($message_types)) {
3112
+			return true;
3113
+		}
3114
+
3115
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3116
+	}
3117
+
3118
+
3119
+	/**
3120
+	 * [_trash_or_restore_message_template]
3121
+	 *
3122
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3123
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3124
+	 *                        an individual context (FALSE).
3125
+	 * @return void
3126
+	 * @throws EE_Error
3127
+	 * @throws InvalidArgumentException
3128
+	 * @throws InvalidDataTypeException
3129
+	 * @throws InvalidInterfaceException
3130
+	 */
3131
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3132
+	{
3133
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3134
+		$MTP = EEM_Message_Template_Group::instance();
3135
+
3136
+		$success = 1;
3137
+
3138
+		// incoming GRP_IDs
3139
+		if ($all) {
3140
+			// Checkboxes
3141
+			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3142
+				// if array has more than one element then success message should be plural.
3143
+				// todo: what about nonce?
3144
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3145
+
3146
+				// cycle through checkboxes
3147
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3148
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3149
+					if (! $trashed_or_restored) {
3150
+						$success = 0;
3151
+					}
3152
+				}
3153
+			} else {
3154
+				// grab single GRP_ID and handle
3155
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3156
+				if (! empty($GRP_ID)) {
3157
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3158
+					if (! $trashed_or_restored) {
3159
+						$success = 0;
3160
+					}
3161
+				} else {
3162
+					$success = 0;
3163
+				}
3164
+			}
3165
+		}
3166
+
3167
+		$action_desc = $trash
3168
+			? esc_html__('moved to the trash', 'event_espresso')
3169
+			: esc_html__('restored', 'event_espresso');
3170
+
3171
+		$action_desc =
3172
+			! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc;
3173
+
3174
+		$item_desc = $all ? _n(
3175
+			'Message Template Group',
3176
+			'Message Template Groups',
3177
+			$success,
3178
+			'event_espresso'
3179
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3180
+
3181
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n(
3182
+			'template',
3183
+			'templates',
3184
+			$success,
3185
+			'event_espresso'
3186
+		) : $item_desc;
3187
+
3188
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3189
+	}
3190
+
3191
+
3192
+	/**
3193
+	 * [_delete_message_template]
3194
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3195
+	 *
3196
+	 * @return void
3197
+	 * @throws EE_Error
3198
+	 * @throws InvalidArgumentException
3199
+	 * @throws InvalidDataTypeException
3200
+	 * @throws InvalidInterfaceException
3201
+	 */
3202
+	protected function _delete_message_template()
3203
+	{
3204
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3205
+
3206
+		// checkboxes
3207
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3208
+			// if array has more than one element then success message should be plural
3209
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3210
+
3211
+			// cycle through bulk action checkboxes
3212
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3213
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3214
+			}
3215
+		} else {
3216
+			// grab single grp_id and delete
3217
+			$GRP_ID  = absint($this->_req_data['id']);
3218
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3219
+		}
3220
+
3221
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3222
+	}
3223
+
3224
+
3225
+	/**
3226
+	 * helper for permanently deleting a mtP group and all related message_templates
3227
+	 *
3228
+	 * @param int  $GRP_ID        The group being deleted
3229
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3230
+	 * @return bool boolean to indicate the success of the deletes or not.
3231
+	 * @throws EE_Error
3232
+	 * @throws InvalidArgumentException
3233
+	 * @throws InvalidDataTypeException
3234
+	 * @throws InvalidInterfaceException
3235
+	 */
3236
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3237
+	{
3238
+		$success = 1;
3239
+		$MTPG    = EEM_Message_Template_Group::instance();
3240
+		// first let's GET this group
3241
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3242
+		// then delete permanently all the related Message Templates
3243
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3244
+
3245
+		if ($deleted === 0) {
3246
+			$success = 0;
3247
+		}
3248
+
3249
+		// now delete permanently this particular group
3250
+
3251
+		if ($include_group && ! $MTG->delete_permanently()) {
3252
+			$success = 0;
3253
+		}
3254
+
3255
+		return $success;
3256
+	}
3257
+
3258
+
3259
+	/**
3260
+	 *    _learn_more_about_message_templates_link
3261
+	 *
3262
+	 * @access protected
3263
+	 * @return string
3264
+	 */
3265
+	protected function _learn_more_about_message_templates_link()
3266
+	{
3267
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3268
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3269
+			   . '</a>';
3270
+	}
3271
+
3272
+
3273
+	/**
3274
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3275
+	 * ajax and other routes.
3276
+	 *
3277
+	 * @return void
3278
+	 * @throws DomainException
3279
+	 */
3280
+	protected function _settings()
3281
+	{
3282
+
3283
+
3284
+		$this->_set_m_mt_settings();
3285
+
3286
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3287
+			? $this->_req_data['selected_messenger']
3288
+			: 'email';
3289
+
3290
+		// let's setup the messenger tabs
3291
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3292
+			$this->_m_mt_settings['messenger_tabs'],
3293
+			'messenger_links',
3294
+			'|',
3295
+			$selected_messenger
3296
+		);
3297
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3298
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3299
+
3300
+		$this->display_admin_page_with_sidebar();
3301
+	}
3302
+
3303
+
3304
+	/**
3305
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3306
+	 *
3307
+	 * @access protected
3308
+	 * @return void
3309
+	 * @throws DomainException
3310
+	 */
3311
+	protected function _set_m_mt_settings()
3312
+	{
3313
+		// first if this is already set then lets get out no need to regenerate data.
3314
+		if (! empty($this->_m_mt_settings)) {
3315
+			return;
3316
+		}
3317
+
3318
+		// get all installed messengers and message_types
3319
+		/** @type EE_messenger[] $messengers */
3320
+		$messengers = $this->_message_resource_manager->installed_messengers();
3321
+		/** @type EE_message_type[] $message_types */
3322
+		$message_types = $this->_message_resource_manager->installed_message_types();
3323
+
3324
+
3325
+		// assemble the array for the _tab_text_links helper
3326
+
3327
+		foreach ($messengers as $messenger) {
3328
+			$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3329
+			$class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3330
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3331
+				'label' => ucwords($messenger->label['singular']),
3332
+				'class' => $active ? "{$class} messenger-active" : $class,
3333
+				'href'  => $messenger->name,
3334
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3335
+				'slug'  => $messenger->name,
3336
+				'obj'   => $messenger,
3337
+				'icon' => $active
3338
+					? '<span class="dashicons dashicons-yes-alt"></span>'
3339
+					: '<span class="dashicons dashicons-remove"></span>',
3340
+			];
3341
+
3342
+
3343
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3344
+
3345
+			foreach ($message_types as $message_type) {
3346
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3347
+				// it shouldn't show in either the inactive OR active metabox.
3348
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3349
+					continue;
3350
+				}
3351
+
3352
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3353
+					$messenger->name,
3354
+					$message_type->name
3355
+				)
3356
+					? 'active'
3357
+					: 'inactive';
3358
+
3359
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3360
+					'label'    => ucwords($message_type->label['singular']),
3361
+					'class'    => 'message-type-' . $a_or_i,
3362
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3363
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3364
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3365
+					'title'    => $a_or_i === 'active'
3366
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3367
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3368
+					'content'  => $a_or_i === 'active'
3369
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3370
+						: $this->_message_type_settings_content($message_type, $messenger),
3371
+					'slug'     => $message_type->name,
3372
+					'active'   => $a_or_i === 'active',
3373
+					'obj'      => $message_type,
3374
+				];
3375
+			}
3376
+		}
3377
+	}
3378
+
3379
+
3380
+	/**
3381
+	 * This just prepares the content for the message type settings
3382
+	 *
3383
+	 * @param EE_message_type $message_type The message type object
3384
+	 * @param EE_messenger    $messenger    The messenger object
3385
+	 * @param boolean         $active       Whether the message type is active or not
3386
+	 * @return string html output for the content
3387
+	 * @throws DomainException
3388
+	 */
3389
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3390
+	{
3391
+		// get message type fields
3392
+		$fields                                         = $message_type->get_admin_settings_fields();
3393
+		$settings_template_args['template_form_fields'] = '';
3394
+
3395
+		if (! empty($fields) && $active) {
3396
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3397
+			foreach ($fields as $fldname => $fldprops) {
3398
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3399
+				$template_form_field[ $field_id ] = [
3400
+					'name'       => 'message_type_settings[' . $fldname . ']',
3401
+					'label'      => $fldprops['label'],
3402
+					'input'      => $fldprops['field_type'],
3403
+					'type'       => $fldprops['value_type'],
3404
+					'required'   => $fldprops['required'],
3405
+					'validation' => $fldprops['validation'],
3406
+					'value'      => isset($existing_settings[ $fldname ])
3407
+						? $existing_settings[ $fldname ]
3408
+						: $fldprops['default'],
3409
+					'options'    => isset($fldprops['options'])
3410
+						? $fldprops['options']
3411
+						: [],
3412
+					'default'    => isset($existing_settings[ $fldname ])
3413
+						? $existing_settings[ $fldname ]
3414
+						: $fldprops['default'],
3415
+					'css_class'  => 'no-drag',
3416
+					'format'     => $fldprops['format'],
3417
+				];
3418
+			}
3419
+
3420
+
3421
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3422
+				? $this->_generate_admin_form_fields(
3423
+					$template_form_field,
3424
+					'string',
3425
+					'ee_mt_activate_form'
3426
+				)
3427
+				: '';
3428
+		}
3429
+
3430
+		$settings_template_args['description'] = $message_type->description;
3431
+		// we also need some hidden fields
3432
+		$hidden_fields = [
3433
+			'message_type_settings[messenger]' . $message_type->name   => [
3434
+				'type'  => 'hidden',
3435
+				'value' => $messenger->name,
3436
+			],
3437
+			'message_type_settings[message_type]' . $message_type->name => [
3438
+				'type'  => 'hidden',
3439
+				'value' => $message_type->name,
3440
+			],
3441
+			'type'   . $message_type->name                             => [
3442
+				'type'  => 'hidden',
3443
+				'value' => 'message_type',
3444
+			],
3445
+		];
3446
+
3447
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3448
+			$hidden_fields,
3449
+			'array'
3450
+		);
3451
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3452
+			? ' hidden'
3453
+			: '';
3454
+
3455
+
3456
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3457
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
3458
+
3459
+		return $content;
3460
+	}
3461
+
3462
+
3463
+	/**
3464
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3465
+	 *
3466
+	 * @access protected
3467
+	 * @return void
3468
+	 * @throws DomainException
3469
+	 */
3470
+	protected function _messages_settings_metaboxes()
3471
+	{
3472
+		$this->_set_m_mt_settings();
3473
+		$m_boxes         = $mt_boxes = [];
3474
+		$m_template_args = $mt_template_args = [];
3475
+
3476
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3477
+			? $this->_req_data['selected_messenger']
3478
+			: 'email';
3479
+
3480
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3481
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3482
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3483
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3484
+				// messenger meta boxes
3485
+				$active                                   = $selected_messenger === $messenger;
3486
+				$active_mt_tabs                           = isset(
3487
+					$this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3488
+				)
3489
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3490
+					: '';
3491
+				$m_boxes[ $messenger . '_a_box' ]         = sprintf(
3492
+					esc_html__('%s Settings', 'event_espresso'),
3493
+					$tab_array['label']
3494
+				);
3495
+				$m_template_args[ $messenger . '_a_box' ] = [
3496
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3497
+					'inactive_message_types' => isset(
3498
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3499
+					)
3500
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3501
+						: '',
3502
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3503
+					'hidden'                 => $active ? '' : ' hidden',
3504
+					'hide_on_message'        => $hide_on_message,
3505
+					'messenger'              => $messenger,
3506
+					'active'                 => $active,
3507
+				];
3508
+				// message type meta boxes
3509
+				// (which is really just the inactive container for each messenger
3510
+				// showing inactive message types for that messenger)
3511
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3512
+				$mt_template_args[ $messenger . '_i_box' ] = [
3513
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3514
+					'inactive_message_types' => isset(
3515
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3516
+					)
3517
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3518
+						: '',
3519
+					'hidden'                 => $active ? '' : ' hidden',
3520
+					'hide_on_message'        => $hide_on_message,
3521
+					'hide_off_message'       => $hide_off_message,
3522
+					'messenger'              => $messenger,
3523
+					'active'                 => $active,
3524
+				];
3525
+			}
3526
+		}
3527
+
3528
+
3529
+		// register messenger metaboxes
3530
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3531
+		foreach ($m_boxes as $box => $label) {
3532
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3533
+			$msgr          = str_replace('_a_box', '', $box);
3534
+			$this->addMetaBox(
3535
+				'espresso_' . $msgr . '_settings',
3536
+				$label,
3537
+				function ($post, $metabox) {
3538
+					EEH_Template::display_template(
3539
+						$metabox['args']['template_path'],
3540
+						$metabox['args']['template_args']
3541
+					);
3542
+				},
3543
+				$this->_current_screen->id,
3544
+				'normal',
3545
+				'high',
3546
+				$callback_args
3547
+			);
3548
+		}
3549
+
3550
+		// register message type metaboxes
3551
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3552
+		foreach ($mt_boxes as $box => $label) {
3553
+			$callback_args = [
3554
+				'template_path' => $mt_template_path,
3555
+				'template_args' => $mt_template_args[ $box ],
3556
+			];
3557
+			$mt            = str_replace('_i_box', '', $box);
3558
+			$this->addMetaBox(
3559
+				'espresso_' . $mt . '_inactive_mts',
3560
+				$label,
3561
+				function ($post, $metabox) {
3562
+					EEH_Template::display_template(
3563
+						$metabox['args']['template_path'],
3564
+						$metabox['args']['template_args']
3565
+					);
3566
+				},
3567
+				$this->_current_screen->id,
3568
+				'side',
3569
+				'high',
3570
+				$callback_args
3571
+			);
3572
+		}
3573
+
3574
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3575
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3576
+		if (is_main_site()) {
3577
+			$this->addMetaBox(
3578
+				'espresso_global_message_settings',
3579
+				esc_html__('Global Message Settings', 'event_espresso'),
3580
+				[$this, 'global_messages_settings_metabox_content'],
3581
+				$this->_current_screen->id,
3582
+				'normal',
3583
+				'low',
3584
+				[]
3585
+			);
3586
+		}
3587
+	}
3588
+
3589
+
3590
+	/**
3591
+	 *  This generates the content for the global messages settings metabox.
3592
+	 *
3593
+	 * @return void
3594
+	 * @throws EE_Error
3595
+	 * @throws InvalidArgumentException
3596
+	 * @throws ReflectionException
3597
+	 * @throws InvalidDataTypeException
3598
+	 * @throws InvalidInterfaceException
3599
+	 */
3600
+	public function global_messages_settings_metabox_content()
3601
+	{
3602
+		$form = $this->_generate_global_settings_form();
3603
+		// already escaped
3604
+		echo $form->form_open(
3605
+			$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3606
+			'POST'
3607
+		);
3608
+		echo $form->get_html();
3609
+		echo $form->form_close();
3610
+	}
3611
+
3612
+
3613
+	/**
3614
+	 * This generates and returns the form object for the global messages settings.
3615
+	 *
3616
+	 * @return EE_Form_Section_Proper
3617
+	 * @throws EE_Error
3618
+	 * @throws InvalidArgumentException
3619
+	 * @throws ReflectionException
3620
+	 * @throws InvalidDataTypeException
3621
+	 * @throws InvalidInterfaceException
3622
+	 */
3623
+	protected function _generate_global_settings_form()
3624
+	{
3625
+		EE_Registry::instance()->load_helper('HTML');
3626
+		/** @var EE_Network_Core_Config $network_config */
3627
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3628
+
3629
+		return new EE_Form_Section_Proper(
3630
+			[
3631
+				'name'            => 'global_messages_settings',
3632
+				'html_id'         => 'global_messages_settings',
3633
+				'html_class'      => 'form-table',
3634
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3635
+				'subsections'     => apply_filters(
3636
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3637
+					[
3638
+						'do_messages_on_same_request' => new EE_Select_Input(
3639
+							[
3640
+								true  => esc_html__('On the same request', 'event_espresso'),
3641
+								false => esc_html__('On a separate request', 'event_espresso'),
3642
+							],
3643
+							[
3644
+								'default'         => $network_config->do_messages_on_same_request,
3645
+								'html_label_text' => esc_html__(
3646
+									'Generate and send all messages:',
3647
+									'event_espresso'
3648
+								),
3649
+								'html_help_text'  => esc_html__(
3650
+									'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.',
3651
+									'event_espresso'
3652
+								),
3653
+							]
3654
+						),
3655
+						'delete_threshold'            => new EE_Select_Input(
3656
+							[
3657
+								0  => esc_html__('Forever', 'event_espresso'),
3658
+								3  => esc_html__('3 Months', 'event_espresso'),
3659
+								6  => esc_html__('6 Months', 'event_espresso'),
3660
+								9  => esc_html__('9 Months', 'event_espresso'),
3661
+								12 => esc_html__('12 Months', 'event_espresso'),
3662
+								24 => esc_html__('24 Months', 'event_espresso'),
3663
+								36 => esc_html__('36 Months', 'event_espresso'),
3664
+							],
3665
+							[
3666
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3667
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3668
+								'html_help_text'  => esc_html__(
3669
+									'You can control how long a record of processed messages is kept via this option.',
3670
+									'event_espresso'
3671
+								),
3672
+							]
3673
+						),
3674
+						'update_settings'             => new EE_Submit_Input(
3675
+							[
3676
+								'default'         => esc_html__('Update', 'event_espresso'),
3677
+								'html_label_text' => '&nbsp',
3678
+							]
3679
+						),
3680
+					]
3681
+				),
3682
+			]
3683
+		);
3684
+	}
3685
+
3686
+
3687
+	/**
3688
+	 * This handles updating the global settings set on the admin page.
3689
+	 *
3690
+	 * @throws EE_Error
3691
+	 * @throws InvalidDataTypeException
3692
+	 * @throws InvalidInterfaceException
3693
+	 * @throws InvalidArgumentException
3694
+	 * @throws ReflectionException
3695
+	 */
3696
+	protected function _update_global_settings()
3697
+	{
3698
+		/** @var EE_Network_Core_Config $network_config */
3699
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3700
+		$messages_config = EE_Registry::instance()->CFG->messages;
3701
+		$form            = $this->_generate_global_settings_form();
3702
+		if ($form->was_submitted()) {
3703
+			$form->receive_form_submission();
3704
+			if ($form->is_valid()) {
3705
+				$valid_data = $form->valid_data();
3706
+				foreach ($valid_data as $property => $value) {
3707
+					$setter = 'set_' . $property;
3708
+					if (method_exists($network_config, $setter)) {
3709
+						$network_config->{$setter}($value);
3710
+					} elseif (
3711
+						property_exists($network_config, $property)
3712
+						&& $network_config->{$property} !== $value
3713
+					) {
3714
+						$network_config->{$property} = $value;
3715
+					} elseif (
3716
+						property_exists($messages_config, $property)
3717
+						&& $messages_config->{$property} !== $value
3718
+					) {
3719
+						$messages_config->{$property} = $value;
3720
+					}
3721
+				}
3722
+				// only update if the form submission was valid!
3723
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3724
+				EE_Registry::instance()->CFG->update_espresso_config();
3725
+				EE_Error::overwrite_success();
3726
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3727
+			}
3728
+		}
3729
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3730
+	}
3731
+
3732
+
3733
+	/**
3734
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3735
+	 *
3736
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3737
+	 * @return string html formatted tabs
3738
+	 * @throws DomainException
3739
+	 */
3740
+	protected function _get_mt_tabs($tab_array)
3741
+	{
3742
+		$tab_array = (array) $tab_array;
3743
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3744
+		$tabs      = '';
3745
+
3746
+		foreach ($tab_array as $tab) {
3747
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3748
+		}
3749
+
3750
+		return $tabs;
3751
+	}
3752
+
3753
+
3754
+	/**
3755
+	 * This prepares the content of the messenger meta box admin settings
3756
+	 *
3757
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3758
+	 * @return string html formatted content
3759
+	 * @throws DomainException
3760
+	 */
3761
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3762
+	{
3763
+
3764
+		$fields                                         = $messenger->get_admin_settings_fields();
3765
+		$settings_template_args['template_form_fields'] = '';
3766
+
3767
+		// is $messenger active?
3768
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3769
+
3770
+
3771
+		if (! empty($fields)) {
3772
+			$existing_settings = $messenger->get_existing_admin_settings();
3773
+
3774
+			foreach ($fields as $fldname => $fldprops) {
3775
+				$field_id                         = $messenger->name . '-' . $fldname;
3776
+				$template_form_field[ $field_id ] = [
3777
+					'name'       => 'messenger_settings[' . $field_id . ']',
3778
+					'label'      => $fldprops['label'],
3779
+					'input'      => $fldprops['field_type'],
3780
+					'type'       => $fldprops['value_type'],
3781
+					'required'   => $fldprops['required'],
3782
+					'validation' => $fldprops['validation'],
3783
+					'value'      => isset($existing_settings[ $field_id ])
3784
+						? $existing_settings[ $field_id ]
3785
+						: $fldprops['default'],
3786
+					'css_class'  => '',
3787
+					'format'     => $fldprops['format'],
3788
+				];
3789
+			}
3790
+
3791
+
3792
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3793
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3794
+				: '';
3795
+		}
3796
+
3797
+		// we also need some hidden fields
3798
+		$settings_template_args['hidden_fields'] = [
3799
+			'messenger_settings[messenger]' . $messenger->name => [
3800
+				'type'  => 'hidden',
3801
+				'value' => $messenger->name,
3802
+			],
3803
+			'type' . $messenger->name                          => [
3804
+				'type'  => 'hidden',
3805
+				'value' => 'messenger',
3806
+			],
3807
+		];
3808
+
3809
+		// make sure any active message types that are existing are included in the hidden fields
3810
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3811
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3812
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3813
+					'type'  => 'hidden',
3814
+					'value' => $mt,
3815
+				];
3816
+			}
3817
+		}
3818
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3819
+			$settings_template_args['hidden_fields'],
3820
+			'array'
3821
+		);
3822
+		$active                                  =
3823
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3824
+
3825
+		$settings_template_args['messenger']           = $messenger->name;
3826
+		$settings_template_args['description']         = $messenger->description;
3827
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3828
+
3829
+
3830
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3831
+			$messenger->name
3832
+		)
3833
+			? $settings_template_args['show_hide_edit_form']
3834
+			: ' hidden';
3835
+
3836
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3837
+			? ' hidden'
3838
+			: $settings_template_args['show_hide_edit_form'];
3839
+
3840
+
3841
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3842
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3843
+		$settings_template_args['on_off_status'] = $active;
3844
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3845
+		return EEH_Template::display_template(
3846
+			$template,
3847
+			$settings_template_args,
3848
+			true
3849
+		);
3850
+	}
3851
+
3852
+
3853
+	/**
3854
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3855
+	 *
3856
+	 * @throws DomainException
3857
+	 * @throws EE_Error
3858
+	 * @throws InvalidDataTypeException
3859
+	 * @throws InvalidInterfaceException
3860
+	 * @throws InvalidArgumentException
3861
+	 * @throws ReflectionException
3862
+	 */
3863
+	public function activate_messenger_toggle()
3864
+	{
3865
+		$success = true;
3866
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3867
+		// let's check that we have required data
3868
+		if (! isset($this->_req_data['messenger'])) {
3869
+			EE_Error::add_error(
3870
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3871
+				__FILE__,
3872
+				__FUNCTION__,
3873
+				__LINE__
3874
+			);
3875
+			$success = false;
3876
+		}
3877
+
3878
+		// do a nonce check here since we're not arriving via a normal route
3879
+		$nonce     = isset($this->_req_data['activate_nonce'])
3880
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3881
+			: '';
3882
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3883
+
3884
+		$this->_verify_nonce($nonce, $nonce_ref);
3885
+
3886
+
3887
+		if (! isset($this->_req_data['status'])) {
3888
+			EE_Error::add_error(
3889
+				esc_html__(
3890
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3891
+					'event_espresso'
3892
+				),
3893
+				__FILE__,
3894
+				__FUNCTION__,
3895
+				__LINE__
3896
+			);
3897
+			$success = false;
3898
+		}
3899
+
3900
+		// do check to verify we have a valid status.
3901
+		$status = $this->_req_data['status'];
3902
+
3903
+		if ($status !== 'off' && $status !== 'on') {
3904
+			EE_Error::add_error(
3905
+				sprintf(
3906
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3907
+					$this->_req_data['status']
3908
+				),
3909
+				__FILE__,
3910
+				__FUNCTION__,
3911
+				__LINE__
3912
+			);
3913
+			$success = false;
3914
+		}
3915
+
3916
+		if ($success) {
3917
+			// made it here?  Stop dawdling then!!
3918
+			$success = $status === 'off'
3919
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3920
+				: $this->_activate_messenger($this->_req_data['messenger']);
3921
+		}
3922
+
3923
+		$this->_template_args['success'] = $success;
3924
+
3925
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
3926
+		$this->_return_json();
3927
+	}
3928
+
3929
+
3930
+	/**
3931
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3932
+	 *
3933
+	 * @throws DomainException
3934
+	 * @throws EE_Error
3935
+	 * @throws ReflectionException
3936
+	 * @throws InvalidDataTypeException
3937
+	 * @throws InvalidInterfaceException
3938
+	 * @throws InvalidArgumentException
3939
+	 */
3940
+	public function activate_mt_toggle()
3941
+	{
3942
+		$success = true;
3943
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3944
+
3945
+		// let's make sure we have the necessary data
3946
+		if (! isset($this->_req_data['message_type'])) {
3947
+			EE_Error::add_error(
3948
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3949
+				__FILE__,
3950
+				__FUNCTION__,
3951
+				__LINE__
3952
+			);
3953
+			$success = false;
3954
+		}
3955
+
3956
+		if (! isset($this->_req_data['messenger'])) {
3957
+			EE_Error::add_error(
3958
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3959
+				__FILE__,
3960
+				__FUNCTION__,
3961
+				__LINE__
3962
+			);
3963
+			$success = false;
3964
+		}
3965
+
3966
+		if (! isset($this->_req_data['status'])) {
3967
+			EE_Error::add_error(
3968
+				esc_html__(
3969
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3970
+					'event_espresso'
3971
+				),
3972
+				__FILE__,
3973
+				__FUNCTION__,
3974
+				__LINE__
3975
+			);
3976
+			$success = false;
3977
+		}
3978
+
3979
+
3980
+		// do check to verify we have a valid status.
3981
+		$status = $this->_req_data['status'];
3982
+
3983
+		if ($status !== 'activate' && $status !== 'deactivate') {
3984
+			EE_Error::add_error(
3985
+				sprintf(
3986
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3987
+					$this->_req_data['status']
3988
+				),
3989
+				__FILE__,
3990
+				__FUNCTION__,
3991
+				__LINE__
3992
+			);
3993
+			$success = false;
3994
+		}
3995
+
3996
+
3997
+		// do a nonce check here since we're not arriving via a normal route
3998
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3999
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
4000
+
4001
+		$this->_verify_nonce($nonce, $nonce_ref);
4002
+
4003
+		if ($success) {
4004
+			// made it here? um, what are you waiting for then?
4005
+			$success = $status === 'deactivate'
4006
+				? $this->_deactivate_message_type_for_messenger(
4007
+					$this->_req_data['messenger'],
4008
+					$this->_req_data['message_type']
4009
+				)
4010
+				: $this->_activate_message_type_for_messenger(
4011
+					$this->_req_data['messenger'],
4012
+					$this->_req_data['message_type']
4013
+				);
4014
+		}
4015
+
4016
+		$this->_template_args['success'] = $success;
4017
+		$this->_return_json();
4018
+	}
4019
+
4020
+
4021
+	/**
4022
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4023
+	 *
4024
+	 * @param string $messenger_name The name of the messenger being activated
4025
+	 * @return bool
4026
+	 * @throws DomainException
4027
+	 * @throws EE_Error
4028
+	 * @throws InvalidArgumentException
4029
+	 * @throws ReflectionException
4030
+	 * @throws InvalidDataTypeException
4031
+	 * @throws InvalidInterfaceException
4032
+	 */
4033
+	protected function _activate_messenger($messenger_name)
4034
+	{
4035
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4036
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4037
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4038
+			? $active_messenger->get_default_message_types()
4039
+			: [];
4040
+
4041
+		// ensure is active
4042
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4043
+
4044
+		// set response_data for reload
4045
+		foreach ($message_types_to_activate as $message_type_name) {
4046
+			/** @var EE_message_type $message_type */
4047
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4048
+			if (
4049
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4050
+					$messenger_name,
4051
+					$message_type_name
4052
+				)
4053
+				&& $message_type instanceof EE_message_type
4054
+			) {
4055
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4056
+				if ($message_type->get_admin_settings_fields()) {
4057
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4058
+				}
4059
+			}
4060
+		}
4061
+
4062
+		// add success message for activating messenger
4063
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4064
+	}
4065
+
4066
+
4067
+	/**
4068
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4069
+	 *
4070
+	 * @param string $messenger_name The name of the messenger being activated
4071
+	 * @return bool
4072
+	 * @throws DomainException
4073
+	 * @throws EE_Error
4074
+	 * @throws InvalidArgumentException
4075
+	 * @throws ReflectionException
4076
+	 * @throws InvalidDataTypeException
4077
+	 * @throws InvalidInterfaceException
4078
+	 */
4079
+	protected function _deactivate_messenger($messenger_name)
4080
+	{
4081
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4082
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4083
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4084
+
4085
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4086
+	}
4087
+
4088
+
4089
+	/**
4090
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4091
+	 *
4092
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4093
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4094
+	 * @return bool
4095
+	 * @throws DomainException
4096
+	 * @throws EE_Error
4097
+	 * @throws InvalidArgumentException
4098
+	 * @throws ReflectionException
4099
+	 * @throws InvalidDataTypeException
4100
+	 * @throws InvalidInterfaceException
4101
+	 */
4102
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4103
+	{
4104
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4105
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4106
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4107
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4108
+
4109
+		// ensure is active
4110
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4111
+
4112
+		// set response for load
4113
+		if (
4114
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4115
+				$messenger_name,
4116
+				$message_type_name
4117
+			)
4118
+		) {
4119
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4120
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4121
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4122
+			}
4123
+		}
4124
+
4125
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4126
+			$active_messenger,
4127
+			$message_type_to_activate
4128
+		);
4129
+	}
4130
+
4131
+
4132
+	/**
4133
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4134
+	 *
4135
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4136
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4137
+	 * @return bool
4138
+	 * @throws DomainException
4139
+	 * @throws EE_Error
4140
+	 * @throws InvalidArgumentException
4141
+	 * @throws ReflectionException
4142
+	 * @throws InvalidDataTypeException
4143
+	 * @throws InvalidInterfaceException
4144
+	 */
4145
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4146
+	{
4147
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4148
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4149
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4150
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4151
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4152
+
4153
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4154
+			$active_messenger,
4155
+			$message_type_to_deactivate
4156
+		);
4157
+	}
4158
+
4159
+
4160
+	/**
4161
+	 * This just initializes the defaults for activating messenger and message type responses.
4162
+	 */
4163
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4164
+	{
4165
+		$this->_template_args['data']['active_mts'] = [];
4166
+		$this->_template_args['data']['mt_reload']  = [];
4167
+	}
4168
+
4169
+
4170
+	/**
4171
+	 * Setup appropriate response for activating a messenger and/or message types
4172
+	 *
4173
+	 * @param EE_messenger         $messenger
4174
+	 * @param EE_message_type|null $message_type
4175
+	 * @return bool
4176
+	 * @throws DomainException
4177
+	 * @throws EE_Error
4178
+	 * @throws InvalidArgumentException
4179
+	 * @throws ReflectionException
4180
+	 * @throws InvalidDataTypeException
4181
+	 * @throws InvalidInterfaceException
4182
+	 */
4183
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4184
+		$messenger,
4185
+		EE_Message_Type $message_type = null
4186
+	) {
4187
+		// if $messenger isn't a valid messenger object then get out.
4188
+		if (! $messenger instanceof EE_Messenger) {
4189
+			EE_Error::add_error(
4190
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4191
+				__FILE__,
4192
+				__FUNCTION__,
4193
+				__LINE__
4194
+			);
4195
+
4196
+			return false;
4197
+		}
4198
+		// activated
4199
+		if ($this->_template_args['data']['active_mts']) {
4200
+			EE_Error::overwrite_success();
4201
+			// activated a message type with the messenger
4202
+			if ($message_type instanceof EE_message_type) {
4203
+				EE_Error::add_success(
4204
+					sprintf(
4205
+						esc_html__(
4206
+							'%s message type has been successfully activated with the %s messenger',
4207
+							'event_espresso'
4208
+						),
4209
+						ucwords($message_type->label['singular']),
4210
+						ucwords($messenger->label['singular'])
4211
+					)
4212
+				);
4213
+
4214
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4215
+				if ($message_type->name === 'invoice') {
4216
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4217
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4218
+					if ($pm instanceof EE_Payment_Method) {
4219
+						EE_Error::add_attention(
4220
+							esc_html__(
4221
+								'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.',
4222
+								'event_espresso'
4223
+							)
4224
+						);
4225
+					}
4226
+				}
4227
+				// just toggles the entire messenger
4228
+			} else {
4229
+				EE_Error::add_success(
4230
+					sprintf(
4231
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4232
+						ucwords($messenger->label['singular'])
4233
+					)
4234
+				);
4235
+			}
4236
+
4237
+			return true;
4238
+
4239
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4240
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4241
+			// in which case we just give a success message for the messenger being successfully activated.
4242
+		} else {
4243
+			if (! $messenger->get_default_message_types()) {
4244
+				// messenger doesn't have any default message types so still a success.
4245
+				EE_Error::add_success(
4246
+					sprintf(
4247
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4248
+						ucwords($messenger->label['singular'])
4249
+					)
4250
+				);
4251
+
4252
+				return true;
4253
+			} else {
4254
+				EE_Error::add_error(
4255
+					$message_type instanceof EE_message_type
4256
+						? sprintf(
4257
+							esc_html__(
4258
+								'%s message type was not successfully activated with the %s messenger',
4259
+								'event_espresso'
4260
+							),
4261
+							ucwords($message_type->label['singular']),
4262
+							ucwords($messenger->label['singular'])
4263
+						)
4264
+						: sprintf(
4265
+							esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4266
+							ucwords($messenger->label['singular'])
4267
+						),
4268
+					__FILE__,
4269
+					__FUNCTION__,
4270
+					__LINE__
4271
+				);
4272
+
4273
+				return false;
4274
+			}
4275
+		}
4276
+	}
4277
+
4278
+
4279
+	/**
4280
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4281
+	 *
4282
+	 * @param EE_messenger         $messenger
4283
+	 * @param EE_message_type|null $message_type
4284
+	 * @return bool
4285
+	 * @throws DomainException
4286
+	 * @throws EE_Error
4287
+	 * @throws InvalidArgumentException
4288
+	 * @throws ReflectionException
4289
+	 * @throws InvalidDataTypeException
4290
+	 * @throws InvalidInterfaceException
4291
+	 */
4292
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4293
+		$messenger,
4294
+		EE_message_type $message_type = null
4295
+	) {
4296
+		EE_Error::overwrite_success();
4297
+
4298
+		// if $messenger isn't a valid messenger object then get out.
4299
+		if (! $messenger instanceof EE_Messenger) {
4300
+			EE_Error::add_error(
4301
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4302
+				__FILE__,
4303
+				__FUNCTION__,
4304
+				__LINE__
4305
+			);
4306
+
4307
+			return false;
4308
+		}
4309
+
4310
+		if ($message_type instanceof EE_message_type) {
4311
+			$message_type_name = $message_type->name;
4312
+			EE_Error::add_success(
4313
+				sprintf(
4314
+					esc_html__(
4315
+						'%s message type has been successfully deactivated for the %s messenger.',
4316
+						'event_espresso'
4317
+					),
4318
+					ucwords($message_type->label['singular']),
4319
+					ucwords($messenger->label['singular'])
4320
+				)
4321
+			);
4322
+		} else {
4323
+			$message_type_name = '';
4324
+			EE_Error::add_success(
4325
+				sprintf(
4326
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4327
+					ucwords($messenger->label['singular'])
4328
+				)
4329
+			);
4330
+		}
4331
+
4332
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4333
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4334
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4335
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4336
+			if ($count_updated > 0) {
4337
+				$msg = $message_type_name === 'invoice'
4338
+					? esc_html__(
4339
+						'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.',
4340
+						'event_espresso'
4341
+					)
4342
+					: esc_html__(
4343
+						'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.',
4344
+						'event_espresso'
4345
+					);
4346
+				EE_Error::add_attention($msg);
4347
+			}
4348
+		}
4349
+
4350
+		return true;
4351
+	}
4352
+
4353
+
4354
+	/**
4355
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4356
+	 *
4357
+	 * @throws DomainException
4358
+	 */
4359
+	public function update_mt_form()
4360
+	{
4361
+		if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4362
+			EE_Error::add_error(
4363
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4364
+				__FILE__,
4365
+				__FUNCTION__,
4366
+				__LINE__
4367
+			);
4368
+			$this->_return_json();
4369
+		}
4370
+
4371
+		$message_types = $this->get_installed_message_types();
4372
+
4373
+		$message_type = $message_types[ $this->_req_data['message_type'] ];
4374
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4375
+
4376
+		$content                         = $this->_message_type_settings_content(
4377
+			$message_type,
4378
+			$messenger,
4379
+			true
4380
+		);
4381
+		$this->_template_args['success'] = true;
4382
+		$this->_template_args['content'] = $content;
4383
+		$this->_return_json();
4384
+	}
4385
+
4386
+
4387
+	/**
4388
+	 * this handles saving the settings for a messenger or message type
4389
+	 *
4390
+	 */
4391
+	public function save_settings()
4392
+	{
4393
+		if (! isset($this->_req_data['type'])) {
4394
+			EE_Error::add_error(
4395
+				esc_html__(
4396
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4397
+					'event_espresso'
4398
+				),
4399
+				__FILE__,
4400
+				__FUNCTION__,
4401
+				__LINE__
4402
+			);
4403
+			$this->_template_args['error'] = true;
4404
+			$this->_return_json();
4405
+		}
4406
+
4407
+
4408
+		if ($this->_req_data['type'] === 'messenger') {
4409
+			// this should be an array.
4410
+			$settings  = $this->_req_data['messenger_settings'];
4411
+			$messenger = $settings['messenger'];
4412
+			// let's setup the settings data
4413
+			foreach ($settings as $key => $value) {
4414
+				switch ($key) {
4415
+					case 'messenger':
4416
+						unset($settings['messenger']);
4417
+						break;
4418
+					case 'message_types':
4419
+						unset($settings['message_types']);
4420
+						break;
4421
+					default:
4422
+						$settings[ $key ] = $value;
4423
+						break;
4424
+				}
4425
+			}
4426
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4427
+		} elseif ($this->_req_data['type'] === 'message_type') {
4428
+			$settings     = $this->_req_data['message_type_settings'];
4429
+			$messenger    = $settings['messenger'];
4430
+			$message_type = $settings['message_type'];
4431
+
4432
+			foreach ($settings as $key => $value) {
4433
+				switch ($key) {
4434
+					case 'messenger':
4435
+						unset($settings['messenger']);
4436
+						break;
4437
+					case 'message_type':
4438
+						unset($settings['message_type']);
4439
+						break;
4440
+					default:
4441
+						$settings[ $key ] = $value;
4442
+						break;
4443
+				}
4444
+			}
4445
+
4446
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4447
+		}
4448
+
4449
+		// okay we should have the data all setup.  Now we just update!
4450
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4451
+
4452
+		if ($success) {
4453
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4454
+		} else {
4455
+			EE_Error::add_error(
4456
+				esc_html__(
4457
+					'Settings did not get updated',
4458
+					'event_espresso'
4459
+				),
4460
+				__FILE__,
4461
+				__FUNCTION__,
4462
+				__LINE__
4463
+			);
4464
+		}
4465
+
4466
+		$this->_template_args['success'] = $success;
4467
+		$this->_return_json();
4468
+	}
4469
+
4470
+
4471
+
4472
+
4473
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4474
+
4475
+
4476
+	/**
4477
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4478
+	 * However, this does not send immediately, it just queues for sending.
4479
+	 *
4480
+	 * @throws EE_Error
4481
+	 * @throws InvalidDataTypeException
4482
+	 * @throws InvalidInterfaceException
4483
+	 * @throws InvalidArgumentException
4484
+	 * @throws ReflectionException
4485
+	 * @since 4.9.0
4486
+	 */
4487
+	protected function _generate_now()
4488
+	{
4489
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4490
+		$this->_redirect_after_action(false, '', '', [], true);
4491
+	}
4492
+
4493
+
4494
+	/**
4495
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4496
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4497
+	 *
4498
+	 * @throws EE_Error
4499
+	 * @throws InvalidDataTypeException
4500
+	 * @throws InvalidInterfaceException
4501
+	 * @throws InvalidArgumentException
4502
+	 * @throws ReflectionException
4503
+	 * @since 4.9.0
4504
+	 */
4505
+	protected function _generate_and_send_now()
4506
+	{
4507
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4508
+		$this->_redirect_after_action(false, '', '', [], true);
4509
+	}
4510
+
4511
+
4512
+	/**
4513
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4514
+	 *
4515
+	 * @throws EE_Error
4516
+	 * @throws InvalidDataTypeException
4517
+	 * @throws InvalidInterfaceException
4518
+	 * @throws InvalidArgumentException
4519
+	 * @throws ReflectionException
4520
+	 * @since 4.9.0
4521
+	 */
4522
+	protected function _queue_for_resending()
4523
+	{
4524
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4525
+		$this->_redirect_after_action(false, '', '', [], true);
4526
+	}
4527
+
4528
+
4529
+	/**
4530
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4531
+	 *
4532
+	 * @throws EE_Error
4533
+	 * @throws InvalidDataTypeException
4534
+	 * @throws InvalidInterfaceException
4535
+	 * @throws InvalidArgumentException
4536
+	 * @throws ReflectionException
4537
+	 * @since 4.9.0
4538
+	 */
4539
+	protected function _send_now()
4540
+	{
4541
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4542
+		$this->_redirect_after_action(false, '', '', [], true);
4543
+	}
4544
+
4545
+
4546
+	/**
4547
+	 * Deletes EE_messages for IDs in the request.
4548
+	 *
4549
+	 * @throws EE_Error
4550
+	 * @throws InvalidDataTypeException
4551
+	 * @throws InvalidInterfaceException
4552
+	 * @throws InvalidArgumentException
4553
+	 * @since 4.9.0
4554
+	 */
4555
+	protected function _delete_ee_messages()
4556
+	{
4557
+		$msg_ids       = $this->_get_msg_ids_from_request();
4558
+		$deleted_count = 0;
4559
+		foreach ($msg_ids as $msg_id) {
4560
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4561
+				$deleted_count++;
4562
+			}
4563
+		}
4564
+		if ($deleted_count) {
4565
+			EE_Error::add_success(
4566
+				esc_html(
4567
+					_n(
4568
+						'Message successfully deleted',
4569
+						'Messages successfully deleted',
4570
+						$deleted_count,
4571
+						'event_espresso'
4572
+					)
4573
+				)
4574
+			);
4575
+			$this->_redirect_after_action(
4576
+				false,
4577
+				'',
4578
+				'',
4579
+				[],
4580
+				true
4581
+			);
4582
+		} else {
4583
+			EE_Error::add_error(
4584
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4585
+				__FILE__,
4586
+				__FUNCTION__,
4587
+				__LINE__
4588
+			);
4589
+			$this->_redirect_after_action(false, '', '', [], true);
4590
+		}
4591
+	}
4592
+
4593
+
4594
+	/**
4595
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4596
+	 *
4597
+	 * @return array
4598
+	 * @since 4.9.0
4599
+	 */
4600
+	protected function _get_msg_ids_from_request()
4601
+	{
4602
+		if (! isset($this->_req_data['MSG_ID'])) {
4603
+			return [];
4604
+		}
4605
+
4606
+		return is_array($this->_req_data['MSG_ID'])
4607
+			? array_keys($this->_req_data['MSG_ID'])
4608
+			: [$this->_req_data['MSG_ID']];
4609
+	}
4610 4610
 }
Please login to merge, or discard this patch.
Spacing   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
         $i = 1;
150 150
         foreach ($active_messengers as $active_messenger) {
151 151
             if ($active_messenger instanceof EE_Message) {
152
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
153
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
152
+                $m_values[$i]['id']   = $active_messenger->messenger();
153
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
154 154
                 $i++;
155 155
             }
156 156
         }
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
         $i               = 1;
187 187
         foreach ($active_messages as $active_message) {
188 188
             if ($active_message instanceof EE_Message) {
189
-                $mt_values[ $i ]['id']   = $active_message->message_type();
190
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
189
+                $mt_values[$i]['id']   = $active_message->message_type();
190
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
191 191
                 $i++;
192 192
             }
193 193
         }
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
                 if ($message_type instanceof EE_message_type) {
227 227
                     $message_type_contexts = $message_type->get_contexts();
228 228
                     foreach ($message_type_contexts as $context => $context_details) {
229
-                        $contexts[ $context ] = $context_details['label'];
229
+                        $contexts[$context] = $context_details['label'];
230 230
                     }
231 231
                 }
232 232
             }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
260 260
             $messenger_options
261 261
         );
262
-        $input             = new EE_Select_Input(
262
+        $input = new EE_Select_Input(
263 263
             $messenger_options,
264 264
             [
265 265
                 'html_name'  => 'ee_messenger_filter_by',
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
299 299
             $message_type_options
300 300
         );
301
-        $input                = new EE_Select_Input(
301
+        $input = new EE_Select_Input(
302 302
             $message_type_options,
303 303
             [
304 304
                 'html_name'  => 'ee_message_type_filter_by',
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
338 338
             $context_options
339 339
         );
340
-        $input           = new EE_Select_Input(
340
+        $input = new EE_Select_Input(
341 341
             $context_options,
342 342
             [
343 343
                 'html_name'  => 'ee_context_filter_by',
@@ -727,53 +727,53 @@  discard block
 block discarded – undo
727 727
 
728 728
     public function messages_help_tab()
729 729
     {
730
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
730
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
731 731
     }
732 732
 
733 733
 
734 734
     public function messengers_help_tab()
735 735
     {
736
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
736
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
737 737
     }
738 738
 
739 739
 
740 740
     public function message_types_help_tab()
741 741
     {
742
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
742
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
743 743
     }
744 744
 
745 745
 
746 746
     public function messages_overview_help_tab()
747 747
     {
748
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
748
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
749 749
     }
750 750
 
751 751
 
752 752
     public function message_templates_help_tab()
753 753
     {
754
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
754
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
755 755
     }
756 756
 
757 757
 
758 758
     public function edit_message_template_help_tab()
759 759
     {
760
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
760
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
761 761
                         . esc_attr__('Editor Title', 'event_espresso')
762 762
                         . '" />';
763
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
763
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
764 764
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
765 765
                         . '" />';
766
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
766
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
767 767
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
768 768
                         . '" />';
769
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
769
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
770 770
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
771 771
                         . '" />';
772
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
772
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
773 773
                         . esc_attr__('Publish Metabox', 'event_espresso')
774 774
                         . '" />';
775 775
         EEH_Template::display_template(
776
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
776
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
777 777
             $args
778 778
         );
779 779
     }
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
         $this->_set_shortcodes();
785 785
         $args['shortcodes'] = $this->_shortcodes;
786 786
         EEH_Template::display_template(
787
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
787
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
788 788
             $args
789 789
         );
790 790
     }
@@ -792,16 +792,16 @@  discard block
 block discarded – undo
792 792
 
793 793
     public function preview_message_help_tab()
794 794
     {
795
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
795
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
796 796
     }
797 797
 
798 798
 
799 799
     public function settings_help_tab()
800 800
     {
801
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
802
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
803
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
804
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
801
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
802
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
803
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
804
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
805 805
         $args['img3'] = '<div class="switch">'
806 806
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
807 807
                         . ' type="checkbox" checked="checked">'
@@ -812,25 +812,25 @@  discard block
 block discarded – undo
812 812
                         . ' type="checkbox">'
813 813
                         . '<label for="ee-on-off-toggle-on"></label>'
814 814
                         . '</div>';
815
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
815
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
816 816
     }
817 817
 
818 818
 
819 819
     public function load_scripts_styles()
820 820
     {
821
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
821
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
822 822
         wp_enqueue_style('espresso_ee_msg');
823 823
 
824 824
         wp_register_script(
825 825
             'ee-messages-settings',
826
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
826
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
827 827
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
828 828
             EVENT_ESPRESSO_VERSION,
829 829
             true
830 830
         );
831 831
         wp_register_script(
832 832
             'ee-msg-list-table-js',
833
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
833
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
834 834
             ['ee-dialog'],
835 835
             EVENT_ESPRESSO_VERSION
836 836
         );
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 
870 870
         $this->_set_shortcodes();
871 871
 
872
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
872
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
873 873
             esc_html__(
874 874
                 '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.',
875 875
                 'event_espresso'
@@ -881,14 +881,14 @@  discard block
 block discarded – undo
881 881
             '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?',
882 882
             'event_espresso'
883 883
         );
884
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
884
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
885 885
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
886 886
             'event_espresso'
887 887
         );
888 888
 
889 889
         wp_register_script(
890 890
             'ee_msgs_edit_js',
891
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
891
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
892 892
             ['jquery'],
893 893
             EVENT_ESPRESSO_VERSION
894 894
         );
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
     {
933 933
         wp_register_style(
934 934
             'ee-message-settings',
935
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
935
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
936 936
             [],
937 937
             EVENT_ESPRESSO_VERSION
938 938
         );
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
             }
1019 1019
             $status_bulk_actions = $common_bulk_actions;
1020 1020
             // unset bulk actions not applying to status
1021
-            if (! empty($status_bulk_actions)) {
1021
+            if ( ! empty($status_bulk_actions)) {
1022 1022
                 switch ($status) {
1023 1023
                     case EEM_Message::status_idle:
1024 1024
                     case EEM_Message::status_resend:
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
                 continue;
1048 1048
             }
1049 1049
 
1050
-            $this->_views[ strtolower($status) ] = [
1050
+            $this->_views[strtolower($status)] = [
1051 1051
                 'slug'        => strtolower($status),
1052 1052
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1053 1053
                 'count'       => 0,
@@ -1089,7 +1089,7 @@  discard block
 block discarded – undo
1089 1089
             if ($action_item === 'see_notifications_for') {
1090 1090
                 continue;
1091 1091
             }
1092
-            $action_items[ $action_item ] = [
1092
+            $action_items[$action_item] = [
1093 1093
                 'class' => $action_details['css_class'],
1094 1094
                 'desc'  => $action_details['label'],
1095 1095
             ];
@@ -1098,37 +1098,37 @@  discard block
 block discarded – undo
1098 1098
         /** @type array $status_items status legend setup */
1099 1099
         $status_items = [
1100 1100
             'sent_status'                => [
1101
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1101
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_sent,
1102 1102
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1103 1103
             ],
1104 1104
             'idle_status'                => [
1105
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1105
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_idle,
1106 1106
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1107 1107
             ],
1108 1108
             'failed_status'              => [
1109
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1109
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_failed,
1110 1110
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1111 1111
             ],
1112 1112
             'messenger_executing_status' => [
1113
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1113
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_messenger_executing,
1114 1114
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1115 1115
             ],
1116 1116
             'resend_status'              => [
1117
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1117
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_resend,
1118 1118
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1119 1119
             ],
1120 1120
             'incomplete_status'          => [
1121
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1121
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_incomplete,
1122 1122
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1123 1123
             ],
1124 1124
             'retry_status'               => [
1125
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1125
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_retry,
1126 1126
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1127 1127
             ],
1128 1128
         ];
1129 1129
         if (EEM_Message::debug()) {
1130 1130
             $status_items['debug_only_status'] = [
1131
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1131
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_debug_only,
1132 1132
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1133 1133
             ];
1134 1134
         }
@@ -1140,11 +1140,11 @@  discard block
 block discarded – undo
1140 1140
     protected function _custom_mtps_preview()
1141 1141
     {
1142 1142
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1143
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1144
-                                                . ' alt="' . esc_attr__(
1143
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1144
+                                                . ' alt="'.esc_attr__(
1145 1145
                                                     'Preview Custom Message Templates screenshot',
1146 1146
                                                     'event_espresso'
1147
-                                                ) . '" />';
1147
+                                                ).'" />';
1148 1148
         $this->_template_args['preview_text'] = '<strong>'
1149 1149
                                                 . esc_html__(
1150 1150
                                                     '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.',
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
         $installed               = [];
1225 1225
 
1226 1226
         foreach ($installed_message_types as $message_type) {
1227
-            $installed[ $message_type->name ] = $message_type;
1227
+            $installed[$message_type->name] = $message_type;
1228 1228
         }
1229 1229
 
1230 1230
         return $installed;
@@ -1364,7 +1364,7 @@  discard block
 block discarded – undo
1364 1364
         // we need to assemble the title from Various details
1365 1365
         $context_label = sprintf(
1366 1366
             esc_html__('(%s %s)', 'event_espresso'),
1367
-            $c_config[ $context ]['label'],
1367
+            $c_config[$context]['label'],
1368 1368
             ucwords($c_label['label'])
1369 1369
         );
1370 1370
 
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
             $message_template_group->message_type()
1387 1387
         );
1388 1388
 
1389
-        if (! $template_field_structure) {
1389
+        if ( ! $template_field_structure) {
1390 1390
             $template_field_structure = false;
1391 1391
             $template_fields          = esc_html__(
1392 1392
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1400,21 +1400,21 @@  discard block
 block discarded – undo
1400 1400
 
1401 1401
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1402 1402
         // will get handled in the "extra" array.
1403
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1404
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1405
-                unset($template_field_structure[ $context ][ $reference_field ]);
1403
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1404
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1405
+                unset($template_field_structure[$context][$reference_field]);
1406 1406
             }
1407 1407
         }
1408 1408
 
1409 1409
         // let's loop through the template_field_structure and actually assemble the input fields!
1410
-        if (! empty($template_field_structure)) {
1411
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1410
+        if ( ! empty($template_field_structure)) {
1411
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1412 1412
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1413 1413
                 // the extra array and reset them.
1414 1414
                 if ($template_field === 'extra') {
1415 1415
                     $this->_template_args['is_extra_fields'] = true;
1416 1416
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1417
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1417
+                        $message_template = $message_templates[$context][$reference_field];
1418 1418
                         $content          = $message_template instanceof EE_Message_Template
1419 1419
                             ? $message_template->get('MTP_content')
1420 1420
                             : '';
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
                             $continue = false;
1424 1424
                             if (isset($extra_array['shortcodes_required'])) {
1425 1425
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1426
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1426
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1427 1427
                                         $continue = true;
1428 1428
                                     }
1429 1429
                                 }
@@ -1432,61 +1432,61 @@  discard block
 block discarded – undo
1432 1432
                                 }
1433 1433
                             }
1434 1434
 
1435
-                            $field_id                                  = $reference_field
1435
+                            $field_id = $reference_field
1436 1436
                                                                          . '-'
1437 1437
                                                                          . $extra_field
1438 1438
                                                                          . '-content';
1439
-                            $template_form_fields[ $field_id ]         = $extra_array;
1440
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1439
+                            $template_form_fields[$field_id]         = $extra_array;
1440
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1441 1441
                                                                          . $reference_field
1442 1442
                                                                          . '][content]['
1443
-                                                                         . $extra_field . ']';
1444
-                            $css_class                                 = isset($extra_array['css_class'])
1443
+                                                                         . $extra_field.']';
1444
+                            $css_class = isset($extra_array['css_class'])
1445 1445
                                 ? $extra_array['css_class']
1446 1446
                                 : '';
1447 1447
 
1448
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1448
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1449 1449
                                                                               && in_array($extra_field, $v_fields, true)
1450 1450
                                                                               && (
1451
-                                                                                  is_array($validators[ $extra_field ])
1452
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1451
+                                                                                  is_array($validators[$extra_field])
1452
+                                                                                  && isset($validators[$extra_field]['msg'])
1453 1453
                                                                               )
1454
-                                ? 'validate-error ' . $css_class
1454
+                                ? 'validate-error '.$css_class
1455 1455
                                 : $css_class;
1456 1456
 
1457
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1458
-                                                                          && isset($content[ $extra_field ])
1459
-                                ? $content[ $extra_field ]
1457
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1458
+                                                                          && isset($content[$extra_field])
1459
+                                ? $content[$extra_field]
1460 1460
                                 : '';
1461 1461
 
1462 1462
                             // do we have a validation error?  if we do then let's use that value instead
1463
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1464
-                                ? $validators[ $extra_field ]['value']
1465
-                                : $template_form_fields[ $field_id ]['value'];
1463
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1464
+                                ? $validators[$extra_field]['value']
1465
+                                : $template_form_fields[$field_id]['value'];
1466 1466
 
1467 1467
 
1468
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1468
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1469 1469
 
1470 1470
                             // shortcode selector
1471 1471
                             $field_name_to_use                                   = $extra_field === 'main'
1472 1472
                                 ? 'content'
1473 1473
                                 : $extra_field;
1474
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1474
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1475 1475
                                 $field_name_to_use,
1476 1476
                                 $field_id
1477 1477
                             );
1478 1478
 
1479 1479
                             if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1480 1480
                                 // we want to decode the entities
1481
-                                $template_form_fields[ $field_id ]['value'] =
1482
-                                    $template_form_fields[ $field_id ]['value'];
1481
+                                $template_form_fields[$field_id]['value'] =
1482
+                                    $template_form_fields[$field_id]['value'];
1483 1483
                             }
1484 1484
                         }
1485
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1486
-                        $templatefield_templatename_id = $reference_field . '-name';
1485
+                        $templatefield_MTP_id          = $reference_field.'-MTP_ID';
1486
+                        $templatefield_templatename_id = $reference_field.'-name';
1487 1487
 
1488
-                        $template_form_fields[ $templatefield_MTP_id ] = [
1489
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1488
+                        $template_form_fields[$templatefield_MTP_id] = [
1489
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1490 1490
                             'label'      => null,
1491 1491
                             'input'      => 'hidden',
1492 1492
                             'type'       => 'int',
@@ -1498,8 +1498,8 @@  discard block
 block discarded – undo
1498 1498
                             'db-col'     => 'MTP_ID',
1499 1499
                         ];
1500 1500
 
1501
-                        $template_form_fields[ $templatefield_templatename_id ] = [
1502
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1501
+                        $template_form_fields[$templatefield_templatename_id] = [
1502
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1503 1503
                             'label'      => null,
1504 1504
                             'input'      => 'hidden',
1505 1505
                             'type'       => 'string',
@@ -1513,38 +1513,38 @@  discard block
 block discarded – undo
1513 1513
                     }
1514 1514
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1515 1515
                 } else {
1516
-                    $field_id                                   = $template_field . '-content';
1517
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1518
-                    $template_form_fields[ $field_id ]['name']  =
1519
-                        'MTP_template_fields[' . $template_field . '][content]';
1516
+                    $field_id                                   = $template_field.'-content';
1517
+                    $template_form_fields[$field_id]          = $field_setup_array;
1518
+                    $template_form_fields[$field_id]['name']  =
1519
+                        'MTP_template_fields['.$template_field.'][content]';
1520 1520
                     $message_template                           =
1521
-                        isset($message_templates[ $context ][ $template_field ])
1522
-                            ? $message_templates[ $context ][ $template_field ]
1521
+                        isset($message_templates[$context][$template_field])
1522
+                            ? $message_templates[$context][$template_field]
1523 1523
                             : null;
1524
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1525
-                                                                  && is_array($message_templates[ $context ])
1524
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1525
+                                                                  && is_array($message_templates[$context])
1526 1526
                                                                   && $message_template instanceof EE_Message_Template
1527 1527
                         ? $message_template->get('MTP_content')
1528 1528
                         : '';
1529 1529
 
1530 1530
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1531
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1532
-                        ? $validators[ $template_field ]['value']
1533
-                        : $template_form_fields[ $field_id ]['value'];
1531
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1532
+                        ? $validators[$template_field]['value']
1533
+                        : $template_form_fields[$field_id]['value'];
1534 1534
 
1535 1535
 
1536
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1536
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1537 1537
                     $css_class                                      = isset($field_setup_array['css_class'])
1538 1538
                         ? $field_setup_array['css_class']
1539 1539
                         : '';
1540
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1540
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1541 1541
                                                                       && in_array($template_field, $v_fields, true)
1542
-                                                                      && isset($validators[ $template_field ]['msg'])
1543
-                        ? 'validate-error ' . $css_class
1542
+                                                                      && isset($validators[$template_field]['msg'])
1543
+                        ? 'validate-error '.$css_class
1544 1544
                         : $css_class;
1545 1545
 
1546 1546
                     // shortcode selector
1547
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1547
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1548 1548
                         $template_field,
1549 1549
                         $field_id
1550 1550
                     );
@@ -1552,12 +1552,12 @@  discard block
 block discarded – undo
1552 1552
 
1553 1553
                 // k took care of content field(s) now let's take care of others.
1554 1554
 
1555
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1556
-                $templatefield_field_templatename_id = $template_field . '-name';
1555
+                $templatefield_MTP_id                = $template_field.'-MTP_ID';
1556
+                $templatefield_field_templatename_id = $template_field.'-name';
1557 1557
 
1558 1558
                 // foreach template field there are actually two form fields created
1559
-                $template_form_fields[ $templatefield_MTP_id ] = [
1560
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1559
+                $template_form_fields[$templatefield_MTP_id] = [
1560
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1561 1561
                     'label'      => null,
1562 1562
                     'input'      => 'hidden',
1563 1563
                     'type'       => 'int',
@@ -1569,8 +1569,8 @@  discard block
 block discarded – undo
1569 1569
                     'db-col'     => 'MTP_ID',
1570 1570
                 ];
1571 1571
 
1572
-                $template_form_fields[ $templatefield_field_templatename_id ] = [
1573
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1572
+                $template_form_fields[$templatefield_field_templatename_id] = [
1573
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1574 1574
                     'label'      => null,
1575 1575
                     'input'      => 'hidden',
1576 1576
                     'type'       => 'string',
@@ -1687,7 +1687,7 @@  discard block
 block discarded – undo
1687 1687
                 'format'     => '%d',
1688 1688
                 'db-col'     => 'MTP_deleted',
1689 1689
             ];
1690
-            $sidebar_form_fields['ee-msg-author']  = [
1690
+            $sidebar_form_fields['ee-msg-author'] = [
1691 1691
                 'name'       => 'MTP_user_id',
1692 1692
                 'label'      => esc_html__('Author', 'event_espresso'),
1693 1693
                 'input'      => 'hidden',
@@ -1706,17 +1706,17 @@  discard block
 block discarded – undo
1706 1706
                 'value' => $action,
1707 1707
             ];
1708 1708
 
1709
-            $sidebar_form_fields['ee-msg-id']        = [
1709
+            $sidebar_form_fields['ee-msg-id'] = [
1710 1710
                 'name'  => 'id',
1711 1711
                 'input' => 'hidden',
1712 1712
                 'type'  => 'int',
1713 1713
                 'value' => $GRP_ID,
1714 1714
             ];
1715 1715
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1716
-                'name'  => $action . '_nonce',
1716
+                'name'  => $action.'_nonce',
1717 1717
                 'input' => 'hidden',
1718 1718
                 'type'  => 'string',
1719
-                'value' => wp_create_nonce($action . '_nonce'),
1719
+                'value' => wp_create_nonce($action.'_nonce'),
1720 1720
             ];
1721 1721
 
1722 1722
             if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
         );
1747 1747
 
1748 1748
         // add preview button
1749
-        $preview_url    = parent::add_query_args_and_nonce(
1749
+        $preview_url = parent::add_query_args_and_nonce(
1750 1750
             [
1751 1751
                 'message_type' => $message_template_group->message_type(),
1752 1752
                 'messenger'    => $message_template_group->messenger(),
@@ -1757,7 +1757,7 @@  discard block
 block discarded – undo
1757 1757
             ],
1758 1758
             $this->_admin_base_url
1759 1759
         );
1760
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1760
+        $preview_button = '<a href="'.$preview_url.'" class="button--secondary messages-preview-button">'
1761 1761
                           . esc_html__('Preview', 'event_espresso')
1762 1762
                           . '</a>';
1763 1763
 
@@ -1793,11 +1793,11 @@  discard block
 block discarded – undo
1793 1793
         $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1794 1794
         $this->_template_args['before_admin_page_content'] .= '</div>';
1795 1795
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1796
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1796
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1797 1797
 
1798 1798
         $this->_template_path = $this->_template_args['GRP_ID']
1799 1799
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1800
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1800
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1801 1801
 
1802 1802
         // send along EE_Message_Template_Group object for further template use.
1803 1803
         $this->_template_args['MTP'] = $message_template_group;
@@ -1852,7 +1852,7 @@  discard block
 block discarded – undo
1852 1852
     ) {
1853 1853
         $template_args = [
1854 1854
             'context'                   => $context,
1855
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1855
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1856 1856
             'is_active'                 => $message_template_group->is_context_active($context),
1857 1857
             'on_off_action'             => $message_template_group->is_context_active($context)
1858 1858
                 ? 'context-off'
@@ -1861,7 +1861,7 @@  discard block
 block discarded – undo
1861 1861
             'message_template_group_id' => $message_template_group->ID(),
1862 1862
         ];
1863 1863
         return EEH_Template::display_template(
1864
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1864
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1865 1865
             $template_args,
1866 1866
             true
1867 1867
         );
@@ -1901,7 +1901,7 @@  discard block
 block discarded – undo
1901 1901
         $nonce     = isset($this->_req_data['toggle_context_nonce'])
1902 1902
             ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1903 1903
             : '';
1904
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1904
+        $nonce_ref = 'activate_'.$this->_req_data['context'].'_toggle_nonce';
1905 1905
         $this->_verify_nonce($nonce, $nonce_ref);
1906 1906
         $status = $this->_req_data['status'];
1907 1907
         if ($status !== 'off' && $status !== 'on') {
@@ -1919,7 +1919,7 @@  discard block
 block discarded – undo
1919 1919
         $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1920 1920
             $this->_req_data['message_template_group_id']
1921 1921
         );
1922
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1922
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1923 1923
             EE_Error::add_error(
1924 1924
                 sprintf(
1925 1925
                     esc_html__(
@@ -2019,7 +2019,7 @@  discard block
 block discarded – undo
2019 2019
                     )
2020 2020
                 );
2021 2021
                 // generate the redirect url for js.
2022
-                $url                                          = self::add_query_args_and_nonce(
2022
+                $url = self::add_query_args_and_nonce(
2023 2023
                     $query_args,
2024 2024
                     $this->_admin_base_url
2025 2025
                 );
@@ -2049,7 +2049,7 @@  discard block
 block discarded – undo
2049 2049
         $templates = [];
2050 2050
         $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2051 2051
         // we need to make sure we've got the info we need.
2052
-        if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2052
+        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2053 2053
             EE_Error::add_error(
2054 2054
                 esc_html__(
2055 2055
                     '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.',
@@ -2091,7 +2091,7 @@  discard block
 block discarded – undo
2091 2091
         }
2092 2092
 
2093 2093
         // any error messages?
2094
-        if (! $success) {
2094
+        if ( ! $success) {
2095 2095
             EE_Error::add_error(
2096 2096
                 esc_html__(
2097 2097
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
             : false;
2177 2177
 
2178 2178
         // let's add a button to go back to the edit view
2179
-        $query_args             = [
2179
+        $query_args = [
2180 2180
             'id'      => $this->_req_data['GRP_ID'],
2181 2181
             'evt_id'  => $EVT_ID,
2182 2182
             'context' => $this->_req_data['context'],
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
         $preview_title = sprintf(
2198 2198
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2199 2199
             $active_messenger_label,
2200
-            ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular'])
2200
+            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
2201 2201
         );
2202 2202
         if (empty($preview)) {
2203 2203
             $this->noEventsErrorMessage();
@@ -2205,7 +2205,7 @@  discard block
 block discarded – undo
2205 2205
         // setup display of preview.
2206 2206
         $this->_admin_page_title                    = $preview_title;
2207 2207
         $this->_template_args['admin_page_title']   = $preview_title;
2208
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2208
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2209 2209
         $this->_template_args['data']['force_json'] = true;
2210 2210
 
2211 2211
         return '';
@@ -2226,7 +2226,7 @@  discard block
 block discarded – undo
2226 2226
             ],
2227 2227
             admin_url('admin.php')
2228 2228
         );
2229
-        $message    = $test_send
2229
+        $message = $test_send
2230 2230
             ? esc_html__(
2231 2231
                 '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!',
2232 2232
                 'event_espresso'
@@ -2319,10 +2319,10 @@  discard block
 block discarded – undo
2319 2319
             // only include template packs that support this messenger and message type!
2320 2320
             $supports = $tp->get_supports();
2321 2321
             if (
2322
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2322
+                ! isset($supports[$this->_message_template_group->messenger()])
2323 2323
                 || ! in_array(
2324 2324
                     $this->_message_template_group->message_type(),
2325
-                    $supports[ $this->_message_template_group->messenger() ],
2325
+                    $supports[$this->_message_template_group->messenger()],
2326 2326
                     true
2327 2327
                 )
2328 2328
             ) {
@@ -2346,7 +2346,7 @@  discard block
 block discarded – undo
2346 2346
         }
2347 2347
 
2348 2348
         // setup variation select values for the currently selected template.
2349
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2349
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2350 2350
             $this->_message_template_group->messenger(),
2351 2351
             $this->_message_template_group->message_type()
2352 2352
         );
@@ -2360,12 +2360,12 @@  discard block
 block discarded – undo
2360 2360
 
2361 2361
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2362 2362
 
2363
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2363
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2364 2364
             'MTP_template_pack',
2365 2365
             $tp_select_values,
2366 2366
             $this->_message_template_group->get_template_pack_name()
2367 2367
         );
2368
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2368
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2369 2369
             'MTP_template_variation',
2370 2370
             $variations_select_values,
2371 2371
             $this->_message_template_group->get_template_pack_variation()
@@ -2375,7 +2375,7 @@  discard block
 block discarded – undo
2375 2375
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2376 2376
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2377 2377
 
2378
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2378
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2379 2379
 
2380 2380
         EEH_Template::display_template($template, $template_args);
2381 2381
     }
@@ -2401,33 +2401,33 @@  discard block
 block discarded – undo
2401 2401
         // first we need to see if there are any fields
2402 2402
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2403 2403
 
2404
-        if (! empty($fields)) {
2404
+        if ( ! empty($fields)) {
2405 2405
             // yup there be fields
2406 2406
             foreach ($fields as $field => $config) {
2407
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2407
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2408 2408
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2409 2409
                 $default  = isset($config['default']) ? $config['default'] : '';
2410 2410
                 $default  = isset($config['value']) ? $config['value'] : $default;
2411 2411
 
2412 2412
                 // if type is hidden and the value is empty
2413 2413
                 // something may have gone wrong so let's correct with the defaults
2414
-                $fix                = $config['input'] === 'hidden'
2415
-                                      && isset($existing[ $field ])
2416
-                                      && empty($existing[ $field ])
2414
+                $fix = $config['input'] === 'hidden'
2415
+                                      && isset($existing[$field])
2416
+                                      && empty($existing[$field])
2417 2417
                     ? $default
2418 2418
                     : '';
2419
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2420
-                    ? $existing[ $field ]
2419
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2420
+                    ? $existing[$field]
2421 2421
                     : $fix;
2422 2422
 
2423
-                $template_form_fields[ $field_id ] = [
2424
-                    'name'       => 'test_settings_fld[' . $field . ']',
2423
+                $template_form_fields[$field_id] = [
2424
+                    'name'       => 'test_settings_fld['.$field.']',
2425 2425
                     'label'      => $config['label'],
2426 2426
                     'input'      => $config['input'],
2427 2427
                     'type'       => $config['type'],
2428 2428
                     'required'   => $config['required'],
2429 2429
                     'validation' => $config['validation'],
2430
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2430
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2431 2431
                     'css_class'  => $config['css_class'],
2432 2432
                     'options'    => isset($config['options']) ? $config['options'] : [],
2433 2433
                     'default'    => $default,
@@ -2441,7 +2441,7 @@  discard block
 block discarded – undo
2441 2441
             : '';
2442 2442
 
2443 2443
         // print out $test_settings_fields
2444
-        if (! empty($test_settings_html)) {
2444
+        if ( ! empty($test_settings_html)) {
2445 2445
             $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2446 2446
             $test_settings_html .= 'name="test_button" value="';
2447 2447
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2487,7 +2487,7 @@  discard block
 block discarded – undo
2487 2487
         ];
2488 2488
 
2489 2489
         return EEH_Template::display_template(
2490
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2490
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2491 2491
             $template_args,
2492 2492
             true
2493 2493
         );
@@ -2513,7 +2513,7 @@  discard block
 block discarded – undo
2513 2513
         // $messenger = $this->_message_template_group->messenger_obj();
2514 2514
         // now let's set the content depending on the status of the shortcodes array
2515 2515
         if (empty($shortcodes)) {
2516
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2516
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2517 2517
             return;
2518 2518
         }
2519 2519
         ?>
@@ -2548,7 +2548,7 @@  discard block
 block discarded – undo
2548 2548
     {
2549 2549
 
2550 2550
         // no need to run this if the property is already set
2551
-        if (! empty($this->_shortcodes)) {
2551
+        if ( ! empty($this->_shortcodes)) {
2552 2552
             return;
2553 2553
         }
2554 2554
 
@@ -2602,7 +2602,7 @@  discard block
 block discarded – undo
2602 2602
     protected function _set_message_template_group()
2603 2603
     {
2604 2604
 
2605
-        if (! empty($this->_message_template_group)) {
2605
+        if ( ! empty($this->_message_template_group)) {
2606 2606
             return;
2607 2607
         } //get out if this is already set.
2608 2608
 
@@ -2652,7 +2652,7 @@  discard block
 block discarded – undo
2652 2652
                     <?php
2653 2653
                 }
2654 2654
                 // setup nonce_url
2655
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2655
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2656 2656
                 ?>
2657 2657
                 <select name="context">
2658 2658
                     <?php
@@ -2662,7 +2662,7 @@  discard block
 block discarded – undo
2662 2662
                             $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2663 2663
                             ?>
2664 2664
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2665
-                                <?php echo $context_details[ $context ]['label']; // already escaped
2665
+                                <?php echo $context_details[$context]['label']; // already escaped
2666 2666
                                 ?>
2667 2667
                             </option>
2668 2668
                         <?php endforeach;
@@ -2697,22 +2697,22 @@  discard block
 block discarded – undo
2697 2697
      */
2698 2698
     protected function _set_message_template_column_values($index)
2699 2699
     {
2700
-        if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2701
-            foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2702
-                $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2700
+        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2701
+            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2702
+                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2703 2703
             }
2704 2704
         }
2705 2705
 
2706 2706
 
2707 2707
         $set_column_values = [
2708
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2708
+            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2709 2709
             'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2710 2710
             'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2711 2711
             'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2712 2712
             'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2713
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2713
+            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2714 2714
             'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2715
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2715
+            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2716 2716
             'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2717 2717
                 ? absint($this->_req_data['MTP_is_global'])
2718 2718
                 : 0,
@@ -2756,10 +2756,10 @@  discard block
 block discarded – undo
2756 2756
             : '';
2757 2757
         $context      = ucwords(str_replace('_', ' ', $context_slug));
2758 2758
 
2759
-        $item_desc   = $messenger_label && $message_type_label
2760
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2759
+        $item_desc = $messenger_label && $message_type_label
2760
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
2761 2761
             : '';
2762
-        $item_desc   .= 'Message Template';
2762
+        $item_desc .= 'Message Template';
2763 2763
         $query_args  = [];
2764 2764
         $edit_array  = [];
2765 2765
         $action_desc = '';
@@ -2788,7 +2788,7 @@  discard block
 block discarded – undo
2788 2788
 
2789 2789
 
2790 2790
             // run update for each template field in displayed context
2791
-            if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2791
+            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2792 2792
                 EE_Error::add_error(
2793 2793
                     esc_html__(
2794 2794
                         'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
@@ -2850,10 +2850,10 @@  discard block
 block discarded – undo
2850 2850
                         $set_column_values = $this->_set_message_template_column_values($template_field);
2851 2851
 
2852 2852
                         $where_cols_n_values = [
2853
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2853
+                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'],
2854 2854
                         ];
2855 2855
                         // if they aren't allowed to use all JS, restrict them to just posty-y tags
2856
-                        if (! current_user_can('unfiltered_html')) {
2856
+                        if ( ! current_user_can('unfiltered_html')) {
2857 2857
                             if (is_array($set_column_values['MTP_content'])) {
2858 2858
                                 foreach ($set_column_values['MTP_content'] as $key => $value) {
2859 2859
                                     // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
@@ -2861,7 +2861,7 @@  discard block
 block discarded – undo
2861 2861
                                     // appear invalid.) But currently the models expect slashed data, so after wp_kses
2862 2862
                                     // runs we need to re-slash the data. Sheesh. See
2863 2863
                                     // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2864
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2864
+                                    $set_column_values['MTP_content'][$key] = addslashes(
2865 2865
                                         wp_kses(
2866 2866
                                             stripslashes($value),
2867 2867
                                             wp_kses_allowed_html('post')
@@ -2897,14 +2897,14 @@  discard block
 block discarded – undo
2897 2897
                             }
2898 2898
                         } else {
2899 2899
                             // only do this logic if we don't have a MTP_ID for this field
2900
-                            if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2900
+                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) {
2901 2901
                                 // this has already been through the template field validator and sanitized, so it will be
2902 2902
                                 // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2903 2903
                                 // message template field in a messenger/message type and existing users don't have the
2904 2904
                                 // default setup for it.
2905 2905
                                 // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2906 2906
                                 $updated = $MTP->insert($message_template_fields);
2907
-                                if (! $updated || is_wp_error($updated)) {
2907
+                                if ( ! $updated || is_wp_error($updated)) {
2908 2908
                                     EE_Error::add_error(
2909 2909
                                         sprintf(
2910 2910
                                             esc_html__('%s field could not be updated.', 'event_espresso'),
@@ -3138,7 +3138,7 @@  discard block
 block discarded – undo
3138 3138
         // incoming GRP_IDs
3139 3139
         if ($all) {
3140 3140
             // Checkboxes
3141
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3141
+            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3142 3142
                 // if array has more than one element then success message should be plural.
3143 3143
                 // todo: what about nonce?
3144 3144
                 $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
@@ -3146,16 +3146,16 @@  discard block
 block discarded – undo
3146 3146
                 // cycle through checkboxes
3147 3147
                 while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3148 3148
                     $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3149
-                    if (! $trashed_or_restored) {
3149
+                    if ( ! $trashed_or_restored) {
3150 3150
                         $success = 0;
3151 3151
                     }
3152 3152
                 }
3153 3153
             } else {
3154 3154
                 // grab single GRP_ID and handle
3155 3155
                 $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3156
-                if (! empty($GRP_ID)) {
3156
+                if ( ! empty($GRP_ID)) {
3157 3157
                     $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3158
-                    if (! $trashed_or_restored) {
3158
+                    if ( ! $trashed_or_restored) {
3159 3159
                         $success = 0;
3160 3160
                     }
3161 3161
                 } else {
@@ -3204,7 +3204,7 @@  discard block
 block discarded – undo
3204 3204
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3205 3205
 
3206 3206
         // checkboxes
3207
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3207
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3208 3208
             // if array has more than one element then success message should be plural
3209 3209
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3210 3210
 
@@ -3288,7 +3288,7 @@  discard block
 block discarded – undo
3288 3288
             : 'email';
3289 3289
 
3290 3290
         // let's setup the messenger tabs
3291
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links(
3291
+        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3292 3292
             $this->_m_mt_settings['messenger_tabs'],
3293 3293
             'messenger_links',
3294 3294
             '|',
@@ -3311,7 +3311,7 @@  discard block
 block discarded – undo
3311 3311
     protected function _set_m_mt_settings()
3312 3312
     {
3313 3313
         // first if this is already set then lets get out no need to regenerate data.
3314
-        if (! empty($this->_m_mt_settings)) {
3314
+        if ( ! empty($this->_m_mt_settings)) {
3315 3315
             return;
3316 3316
         }
3317 3317
 
@@ -3326,8 +3326,8 @@  discard block
 block discarded – undo
3326 3326
 
3327 3327
         foreach ($messengers as $messenger) {
3328 3328
             $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3329
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3330
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3329
+            $class = 'ee-messenger-'.sanitize_key($messenger->label['singular']);
3330
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3331 3331
                 'label' => ucwords($messenger->label['singular']),
3332 3332
                 'class' => $active ? "{$class} messenger-active" : $class,
3333 3333
                 'href'  => $messenger->name,
@@ -3345,7 +3345,7 @@  discard block
 block discarded – undo
3345 3345
             foreach ($message_types as $message_type) {
3346 3346
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3347 3347
                 // it shouldn't show in either the inactive OR active metabox.
3348
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3348
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3349 3349
                     continue;
3350 3350
                 }
3351 3351
 
@@ -3356,12 +3356,12 @@  discard block
 block discarded – undo
3356 3356
                     ? 'active'
3357 3357
                     : 'inactive';
3358 3358
 
3359
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3359
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3360 3360
                     'label'    => ucwords($message_type->label['singular']),
3361
-                    'class'    => 'message-type-' . $a_or_i,
3362
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3363
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3364
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3361
+                    'class'    => 'message-type-'.$a_or_i,
3362
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3363
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3364
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3365 3365
                     'title'    => $a_or_i === 'active'
3366 3366
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3367 3367
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3392,25 +3392,25 @@  discard block
 block discarded – undo
3392 3392
         $fields                                         = $message_type->get_admin_settings_fields();
3393 3393
         $settings_template_args['template_form_fields'] = '';
3394 3394
 
3395
-        if (! empty($fields) && $active) {
3395
+        if ( ! empty($fields) && $active) {
3396 3396
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3397 3397
             foreach ($fields as $fldname => $fldprops) {
3398
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3399
-                $template_form_field[ $field_id ] = [
3400
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3398
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3399
+                $template_form_field[$field_id] = [
3400
+                    'name'       => 'message_type_settings['.$fldname.']',
3401 3401
                     'label'      => $fldprops['label'],
3402 3402
                     'input'      => $fldprops['field_type'],
3403 3403
                     'type'       => $fldprops['value_type'],
3404 3404
                     'required'   => $fldprops['required'],
3405 3405
                     'validation' => $fldprops['validation'],
3406
-                    'value'      => isset($existing_settings[ $fldname ])
3407
-                        ? $existing_settings[ $fldname ]
3406
+                    'value'      => isset($existing_settings[$fldname])
3407
+                        ? $existing_settings[$fldname]
3408 3408
                         : $fldprops['default'],
3409 3409
                     'options'    => isset($fldprops['options'])
3410 3410
                         ? $fldprops['options']
3411 3411
                         : [],
3412
-                    'default'    => isset($existing_settings[ $fldname ])
3413
-                        ? $existing_settings[ $fldname ]
3412
+                    'default'    => isset($existing_settings[$fldname])
3413
+                        ? $existing_settings[$fldname]
3414 3414
                         : $fldprops['default'],
3415 3415
                     'css_class'  => 'no-drag',
3416 3416
                     'format'     => $fldprops['format'],
@@ -3430,15 +3430,15 @@  discard block
 block discarded – undo
3430 3430
         $settings_template_args['description'] = $message_type->description;
3431 3431
         // we also need some hidden fields
3432 3432
         $hidden_fields = [
3433
-            'message_type_settings[messenger]' . $message_type->name   => [
3433
+            'message_type_settings[messenger]'.$message_type->name   => [
3434 3434
                 'type'  => 'hidden',
3435 3435
                 'value' => $messenger->name,
3436 3436
             ],
3437
-            'message_type_settings[message_type]' . $message_type->name => [
3437
+            'message_type_settings[message_type]'.$message_type->name => [
3438 3438
                 'type'  => 'hidden',
3439 3439
                 'value' => $message_type->name,
3440 3440
             ],
3441
-            'type'   . $message_type->name                             => [
3441
+            'type'.$message_type->name                             => [
3442 3442
                 'type'  => 'hidden',
3443 3443
                 'value' => 'message_type',
3444 3444
             ],
@@ -3448,12 +3448,12 @@  discard block
 block discarded – undo
3448 3448
             $hidden_fields,
3449 3449
             'array'
3450 3450
         );
3451
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3451
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3452 3452
             ? ' hidden'
3453 3453
             : '';
3454 3454
 
3455 3455
 
3456
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3456
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3457 3457
         $content  = EEH_Template::display_template($template, $settings_template_args, true);
3458 3458
 
3459 3459
         return $content;
@@ -3484,20 +3484,20 @@  discard block
 block discarded – undo
3484 3484
                 // messenger meta boxes
3485 3485
                 $active                                   = $selected_messenger === $messenger;
3486 3486
                 $active_mt_tabs                           = isset(
3487
-                    $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3487
+                    $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3488 3488
                 )
3489
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3489
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3490 3490
                     : '';
3491
-                $m_boxes[ $messenger . '_a_box' ]         = sprintf(
3491
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3492 3492
                     esc_html__('%s Settings', 'event_espresso'),
3493 3493
                     $tab_array['label']
3494 3494
                 );
3495
-                $m_template_args[ $messenger . '_a_box' ] = [
3495
+                $m_template_args[$messenger.'_a_box'] = [
3496 3496
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3497 3497
                     'inactive_message_types' => isset(
3498
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3498
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3499 3499
                     )
3500
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3500
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3501 3501
                         : '',
3502 3502
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3503 3503
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3508,13 +3508,13 @@  discard block
 block discarded – undo
3508 3508
                 // message type meta boxes
3509 3509
                 // (which is really just the inactive container for each messenger
3510 3510
                 // showing inactive message types for that messenger)
3511
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3512
-                $mt_template_args[ $messenger . '_i_box' ] = [
3511
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3512
+                $mt_template_args[$messenger.'_i_box'] = [
3513 3513
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3514 3514
                     'inactive_message_types' => isset(
3515
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3515
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3516 3516
                     )
3517
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3517
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3518 3518
                         : '',
3519 3519
                     'hidden'                 => $active ? '' : ' hidden',
3520 3520
                     'hide_on_message'        => $hide_on_message,
@@ -3527,14 +3527,14 @@  discard block
 block discarded – undo
3527 3527
 
3528 3528
 
3529 3529
         // register messenger metaboxes
3530
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3530
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3531 3531
         foreach ($m_boxes as $box => $label) {
3532
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3532
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3533 3533
             $msgr          = str_replace('_a_box', '', $box);
3534 3534
             $this->addMetaBox(
3535
-                'espresso_' . $msgr . '_settings',
3535
+                'espresso_'.$msgr.'_settings',
3536 3536
                 $label,
3537
-                function ($post, $metabox) {
3537
+                function($post, $metabox) {
3538 3538
                     EEH_Template::display_template(
3539 3539
                         $metabox['args']['template_path'],
3540 3540
                         $metabox['args']['template_args']
@@ -3548,17 +3548,17 @@  discard block
 block discarded – undo
3548 3548
         }
3549 3549
 
3550 3550
         // register message type metaboxes
3551
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3551
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3552 3552
         foreach ($mt_boxes as $box => $label) {
3553 3553
             $callback_args = [
3554 3554
                 'template_path' => $mt_template_path,
3555
-                'template_args' => $mt_template_args[ $box ],
3555
+                'template_args' => $mt_template_args[$box],
3556 3556
             ];
3557
-            $mt            = str_replace('_i_box', '', $box);
3557
+            $mt = str_replace('_i_box', '', $box);
3558 3558
             $this->addMetaBox(
3559
-                'espresso_' . $mt . '_inactive_mts',
3559
+                'espresso_'.$mt.'_inactive_mts',
3560 3560
                 $label,
3561
-                function ($post, $metabox) {
3561
+                function($post, $metabox) {
3562 3562
                     EEH_Template::display_template(
3563 3563
                         $metabox['args']['template_path'],
3564 3564
                         $metabox['args']['template_args']
@@ -3704,7 +3704,7 @@  discard block
 block discarded – undo
3704 3704
             if ($form->is_valid()) {
3705 3705
                 $valid_data = $form->valid_data();
3706 3706
                 foreach ($valid_data as $property => $value) {
3707
-                    $setter = 'set_' . $property;
3707
+                    $setter = 'set_'.$property;
3708 3708
                     if (method_exists($network_config, $setter)) {
3709 3709
                         $network_config->{$setter}($value);
3710 3710
                     } elseif (
@@ -3740,7 +3740,7 @@  discard block
 block discarded – undo
3740 3740
     protected function _get_mt_tabs($tab_array)
3741 3741
     {
3742 3742
         $tab_array = (array) $tab_array;
3743
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3743
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3744 3744
         $tabs      = '';
3745 3745
 
3746 3746
         foreach ($tab_array as $tab) {
@@ -3768,20 +3768,20 @@  discard block
 block discarded – undo
3768 3768
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3769 3769
 
3770 3770
 
3771
-        if (! empty($fields)) {
3771
+        if ( ! empty($fields)) {
3772 3772
             $existing_settings = $messenger->get_existing_admin_settings();
3773 3773
 
3774 3774
             foreach ($fields as $fldname => $fldprops) {
3775
-                $field_id                         = $messenger->name . '-' . $fldname;
3776
-                $template_form_field[ $field_id ] = [
3777
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3775
+                $field_id                         = $messenger->name.'-'.$fldname;
3776
+                $template_form_field[$field_id] = [
3777
+                    'name'       => 'messenger_settings['.$field_id.']',
3778 3778
                     'label'      => $fldprops['label'],
3779 3779
                     'input'      => $fldprops['field_type'],
3780 3780
                     'type'       => $fldprops['value_type'],
3781 3781
                     'required'   => $fldprops['required'],
3782 3782
                     'validation' => $fldprops['validation'],
3783
-                    'value'      => isset($existing_settings[ $field_id ])
3784
-                        ? $existing_settings[ $field_id ]
3783
+                    'value'      => isset($existing_settings[$field_id])
3784
+                        ? $existing_settings[$field_id]
3785 3785
                         : $fldprops['default'],
3786 3786
                     'css_class'  => '',
3787 3787
                     'format'     => $fldprops['format'],
@@ -3796,20 +3796,20 @@  discard block
 block discarded – undo
3796 3796
 
3797 3797
         // we also need some hidden fields
3798 3798
         $settings_template_args['hidden_fields'] = [
3799
-            'messenger_settings[messenger]' . $messenger->name => [
3799
+            'messenger_settings[messenger]'.$messenger->name => [
3800 3800
                 'type'  => 'hidden',
3801 3801
                 'value' => $messenger->name,
3802 3802
             ],
3803
-            'type' . $messenger->name                          => [
3803
+            'type'.$messenger->name                          => [
3804 3804
                 'type'  => 'hidden',
3805 3805
                 'value' => 'messenger',
3806 3806
             ],
3807 3807
         ];
3808 3808
 
3809 3809
         // make sure any active message types that are existing are included in the hidden fields
3810
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3811
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3812
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3810
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3811
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3812
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3813 3813
                     'type'  => 'hidden',
3814 3814
                     'value' => $mt,
3815 3815
                 ];
@@ -3819,7 +3819,7 @@  discard block
 block discarded – undo
3819 3819
             $settings_template_args['hidden_fields'],
3820 3820
             'array'
3821 3821
         );
3822
-        $active                                  =
3822
+        $active =
3823 3823
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3824 3824
 
3825 3825
         $settings_template_args['messenger']           = $messenger->name;
@@ -3839,9 +3839,9 @@  discard block
 block discarded – undo
3839 3839
 
3840 3840
 
3841 3841
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3842
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3842
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3843 3843
         $settings_template_args['on_off_status'] = $active;
3844
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3844
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3845 3845
         return EEH_Template::display_template(
3846 3846
             $template,
3847 3847
             $settings_template_args,
@@ -3865,7 +3865,7 @@  discard block
 block discarded – undo
3865 3865
         $success = true;
3866 3866
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3867 3867
         // let's check that we have required data
3868
-        if (! isset($this->_req_data['messenger'])) {
3868
+        if ( ! isset($this->_req_data['messenger'])) {
3869 3869
             EE_Error::add_error(
3870 3870
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3871 3871
                 __FILE__,
@@ -3879,12 +3879,12 @@  discard block
 block discarded – undo
3879 3879
         $nonce     = isset($this->_req_data['activate_nonce'])
3880 3880
             ? sanitize_text_field($this->_req_data['activate_nonce'])
3881 3881
             : '';
3882
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3882
+        $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';
3883 3883
 
3884 3884
         $this->_verify_nonce($nonce, $nonce_ref);
3885 3885
 
3886 3886
 
3887
-        if (! isset($this->_req_data['status'])) {
3887
+        if ( ! isset($this->_req_data['status'])) {
3888 3888
             EE_Error::add_error(
3889 3889
                 esc_html__(
3890 3890
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3943,7 +3943,7 @@  discard block
 block discarded – undo
3943 3943
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3944 3944
 
3945 3945
         // let's make sure we have the necessary data
3946
-        if (! isset($this->_req_data['message_type'])) {
3946
+        if ( ! isset($this->_req_data['message_type'])) {
3947 3947
             EE_Error::add_error(
3948 3948
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3949 3949
                 __FILE__,
@@ -3953,7 +3953,7 @@  discard block
 block discarded – undo
3953 3953
             $success = false;
3954 3954
         }
3955 3955
 
3956
-        if (! isset($this->_req_data['messenger'])) {
3956
+        if ( ! isset($this->_req_data['messenger'])) {
3957 3957
             EE_Error::add_error(
3958 3958
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3959 3959
                 __FILE__,
@@ -3963,7 +3963,7 @@  discard block
 block discarded – undo
3963 3963
             $success = false;
3964 3964
         }
3965 3965
 
3966
-        if (! isset($this->_req_data['status'])) {
3966
+        if ( ! isset($this->_req_data['status'])) {
3967 3967
             EE_Error::add_error(
3968 3968
                 esc_html__(
3969 3969
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -3996,7 +3996,7 @@  discard block
 block discarded – undo
3996 3996
 
3997 3997
         // do a nonce check here since we're not arriving via a normal route
3998 3998
         $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3999
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3999
+        $nonce_ref = $this->_req_data['message_type'].'_nonce';
4000 4000
 
4001 4001
         $this->_verify_nonce($nonce, $nonce_ref);
4002 4002
 
@@ -4185,7 +4185,7 @@  discard block
 block discarded – undo
4185 4185
         EE_Message_Type $message_type = null
4186 4186
     ) {
4187 4187
         // if $messenger isn't a valid messenger object then get out.
4188
-        if (! $messenger instanceof EE_Messenger) {
4188
+        if ( ! $messenger instanceof EE_Messenger) {
4189 4189
             EE_Error::add_error(
4190 4190
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4191 4191
                 __FILE__,
@@ -4240,7 +4240,7 @@  discard block
 block discarded – undo
4240 4240
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4241 4241
             // in which case we just give a success message for the messenger being successfully activated.
4242 4242
         } else {
4243
-            if (! $messenger->get_default_message_types()) {
4243
+            if ( ! $messenger->get_default_message_types()) {
4244 4244
                 // messenger doesn't have any default message types so still a success.
4245 4245
                 EE_Error::add_success(
4246 4246
                     sprintf(
@@ -4296,7 +4296,7 @@  discard block
 block discarded – undo
4296 4296
         EE_Error::overwrite_success();
4297 4297
 
4298 4298
         // if $messenger isn't a valid messenger object then get out.
4299
-        if (! $messenger instanceof EE_Messenger) {
4299
+        if ( ! $messenger instanceof EE_Messenger) {
4300 4300
             EE_Error::add_error(
4301 4301
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4302 4302
                 __FILE__,
@@ -4358,7 +4358,7 @@  discard block
 block discarded – undo
4358 4358
      */
4359 4359
     public function update_mt_form()
4360 4360
     {
4361
-        if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4361
+        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4362 4362
             EE_Error::add_error(
4363 4363
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4364 4364
                 __FILE__,
@@ -4370,10 +4370,10 @@  discard block
 block discarded – undo
4370 4370
 
4371 4371
         $message_types = $this->get_installed_message_types();
4372 4372
 
4373
-        $message_type = $message_types[ $this->_req_data['message_type'] ];
4373
+        $message_type = $message_types[$this->_req_data['message_type']];
4374 4374
         $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4375 4375
 
4376
-        $content                         = $this->_message_type_settings_content(
4376
+        $content = $this->_message_type_settings_content(
4377 4377
             $message_type,
4378 4378
             $messenger,
4379 4379
             true
@@ -4390,7 +4390,7 @@  discard block
 block discarded – undo
4390 4390
      */
4391 4391
     public function save_settings()
4392 4392
     {
4393
-        if (! isset($this->_req_data['type'])) {
4393
+        if ( ! isset($this->_req_data['type'])) {
4394 4394
             EE_Error::add_error(
4395 4395
                 esc_html__(
4396 4396
                     'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
@@ -4419,7 +4419,7 @@  discard block
 block discarded – undo
4419 4419
                         unset($settings['message_types']);
4420 4420
                         break;
4421 4421
                     default:
4422
-                        $settings[ $key ] = $value;
4422
+                        $settings[$key] = $value;
4423 4423
                         break;
4424 4424
                 }
4425 4425
             }
@@ -4438,7 +4438,7 @@  discard block
 block discarded – undo
4438 4438
                         unset($settings['message_type']);
4439 4439
                         break;
4440 4440
                     default:
4441
-                        $settings[ $key ] = $value;
4441
+                        $settings[$key] = $value;
4442 4442
                         break;
4443 4443
                 }
4444 4444
             }
@@ -4599,7 +4599,7 @@  discard block
 block discarded – undo
4599 4599
      */
4600 4600
     protected function _get_msg_ids_from_request()
4601 4601
     {
4602
-        if (! isset($this->_req_data['MSG_ID'])) {
4602
+        if ( ! isset($this->_req_data['MSG_ID'])) {
4603 4603
             return [];
4604 4604
         }
4605 4605
 
Please login to merge, or discard this patch.