Completed
Branch master (87d3f3)
by
unknown
03:30
created
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 1 patch
Indentation   +646 added lines, -646 removed lines patch added patch discarded remove patch
@@ -16,255 +16,255 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class EE_Event_Registrations_List_Table extends EE_Admin_List_Table
18 18
 {
19
-    /**
20
-     * @var RequestInterface
21
-     */
22
-    protected $request;
23
-
24
-    /**
25
-     * @var Extend_Registrations_Admin_Page
26
-     */
27
-    protected $_admin_page;
28
-
29
-    /**
30
-     * This property will hold the related Datetimes on an event IF the event id is included in the request.
31
-     *
32
-     * @var DatetimesForEventCheckIn
33
-     */
34
-    protected $datetimes_for_event;
35
-
36
-    /**
37
-     * The DTT_ID if the current view has a specified datetime.
38
-     *
39
-     * @var int
40
-     */
41
-    protected $datetime_id = 0;
42
-
43
-    /**
44
-     * @var EE_Datetime
45
-     */
46
-    protected $datetime;
47
-
48
-    /**
49
-     * The event ID if one is specified in the request
50
-     *
51
-     * @var int
52
-     */
53
-    protected $event_id = 0;
54
-
55
-    /**
56
-     * @var EE_Event
57
-     */
58
-    protected $event;
59
-
60
-    /**
61
-     * @var DatetimesForEventCheckIn
62
-     */
63
-    protected $datetimes_for_current_row;
64
-
65
-    /**
66
-     * @var bool
67
-     */
68
-    protected $hide_expired;
69
-
70
-    /**
71
-     * @var bool
72
-     */
73
-    protected $hide_upcoming;
74
-
75
-    /**
76
-     * @var   array
77
-     * @since 4.10.31.p
78
-     */
79
-    protected $_status;
80
-
81
-
82
-    /**
83
-     * EE_Event_Registrations_List_Table constructor.
84
-     *
85
-     * @param Registrations_Admin_Page $admin_page
86
-     * @throws EE_Error
87
-     * @throws ReflectionException
88
-     */
89
-    public function __construct($admin_page)
90
-    {
91
-        $this->request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
92
-        $this->resolveRequestVars();
93
-        parent::__construct($admin_page);
94
-    }
95
-
96
-
97
-    /**
98
-     * @throws EE_Error
99
-     * @throws ReflectionException
100
-     * @since $VID:$
101
-     */
102
-    private function resolveRequestVars()
103
-    {
104
-        $this->event_id = $this->request->getRequestParam('event_id', 0, 'int');
105
-        $this->datetimes_for_event = DatetimesForEventCheckIn::fromEventID($this->event_id);
106
-        // if we're filtering for a specific event and it only has one datetime, then grab its ID
107
-        $datetime          = $this->datetimes_for_event->getOneDatetimeForEvent();
108
-        $this->datetime_id = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
109
-        // else check the request, but use the above as the default (and hope they match if BOTH exist, LOLZ)
110
-        $this->datetime_id = $this->request->getRequestParam(
111
-            'DTT_ID',
112
-            $this->datetime_id,
113
-            'int'
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * @throws EE_Error
120
-     */
121
-    protected function _setup_data()
122
-    {
123
-        $this->_data = $this->_view !== 'trash'
124
-            ? $this->_admin_page->get_event_attendees($this->_per_page)
125
-            : $this->_admin_page->get_event_attendees($this->_per_page, false, true);
126
-
127
-        $this->_all_data_count = $this->_view !== 'trash'
128
-            ? $this->_admin_page->get_event_attendees($this->_per_page, true)
129
-            : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
130
-    }
131
-
132
-
133
-    /**
134
-     * @throws ReflectionException
135
-     * @throws EE_Error
136
-     */
137
-    protected function _set_properties()
138
-    {
139
-        $return_url = $this->getReturnUrl();
140
-
141
-        $this->_wp_list_args = [
142
-            'singular' => esc_html__('registrant', 'event_espresso'),
143
-            'plural'   => esc_html__('registrants', 'event_espresso'),
144
-            'ajax'     => true,
145
-            'screen'   => $this->_admin_page->get_current_screen()->id,
146
-        ];
147
-        $columns             = [];
148
-
149
-        $this->_columns = [
150
-            '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
151
-            'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
152
-            'ATT_email'           => esc_html__('Email Address', 'event_espresso'),
153
-            'Event'               => esc_html__('Event', 'event_espresso'),
154
-            'PRC_name'            => esc_html__('TKT Option', 'event_espresso'),
155
-            '_REG_final_price'    => esc_html__('Price', 'event_espresso'),
156
-            'TXN_paid'            => esc_html__('Paid', 'event_espresso'),
157
-            'TXN_total'           => esc_html__('Total', 'event_espresso'),
158
-        ];
159
-        // Add/remove columns when an event has been selected
160
-        if (! empty($this->event_id)) {
161
-            // Render a checkbox column
162
-            $columns['cb']              = '<input type="checkbox" />';
163
-            $this->_has_checkbox_column = true;
164
-            // Remove the 'Event' column
165
-            unset($this->_columns['Event']);
166
-            $this->setBottomButtons();
167
-        }
168
-        $this->_columns        = array_merge($columns, $this->_columns);
169
-        $this->_primary_column = '_REG_att_checked_in';
170
-
171
-        $csv_report = RegistrationsCsvReportParams::getRequestParams(
172
-            $return_url,
173
-            $this->_req_data,
174
-            $this->event_id,
175
-            $this->datetime_id
176
-        );
177
-        if (! empty($csv_report)) {
178
-            $this->_bottom_buttons['csv_reg_report'] = $csv_report;
179
-        }
180
-
181
-        $this->_sortable_columns = [
182
-            /**
183
-             * Allows users to change the default sort if they wish.
184
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
185
-             *
186
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
187
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
188
-             * for a specific list table you can use the provided reference to this object instance.
189
-             */
190
-            'ATT_name' => [
191
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
192
-                true,
193
-                $this,
194
-            ]
195
-                ? ['ATT_lname' => true]
196
-                : ['ATT_fname' => true],
197
-            'Event'    => ['Event.EVT_name' => false],
198
-        ];
199
-        $this->_hidden_columns   = [];
200
-        $this->event              = EEM_Event::instance()->get_one_by_ID($this->event_id);
201
-        if ($this->event instanceof EE_Event) {
202
-            $this->datetimes_for_event = DatetimesForEventCheckIn::fromEvent($this->event);
203
-        }
204
-    }
205
-
206
-
207
-    /**
208
-     * @param EE_Registration $item
209
-     * @return string
210
-     */
211
-    protected function _get_row_class($item): string
212
-    {
213
-        $class = parent::_get_row_class($item);
214
-        if ($this->_has_checkbox_column) {
215
-            $class .= ' has-checkbox-column';
216
-        }
217
-        return $class;
218
-    }
219
-
220
-
221
-    /**
222
-     * @return array
223
-     * @throws EE_Error
224
-     * @throws ReflectionException
225
-     */
226
-    protected function _get_table_filters()
227
-    {
228
-        $filters = [];
229
-        $this->hide_expired = $this->request->getRequestParam('hide_expired', false, 'bool');
230
-        $this->hide_upcoming = $this->request->getRequestParam('hide_upcoming', false, 'bool');
231
-        $hide_expired_checked = $this->hide_expired ? 'checked' : '';
232
-        $hide_upcoming_checked = $this->hide_upcoming ? 'checked' : '';
233
-        // get datetimes for ALL active events (note possible capability restrictions)
234
-        $events   = $this->datetimes_for_event->getAllEvents();
235
-        $event_options[] = [
236
-            'id'   => 0,
237
-            'text' => esc_html__(' - select an event - ', 'event_espresso'),
238
-        ];
239
-        foreach ($events as $event) {
240
-            // any registrations for this event?
241
-            if (! $event instanceof EE_Event/* || ! $event->get_count_of_all_registrations()*/) {
242
-                continue;
243
-            }
244
-            $expired_class = $event->is_expired() ? 'ee-expired-event' : '';
245
-            $upcoming_class  = $event->is_upcoming() ? ' ee-upcoming-event' : '';
246
-
247
-            $event_options[] = [
248
-                'id'    => $event->ID(),
249
-                'text'  => apply_filters(
250
-                    'FHEE__EE_Event_Registrations___get_table_filters__event_name',
251
-                    $event->name(),
252
-                    $event
253
-                ),
254
-                'class' => $expired_class . $upcoming_class,
255
-            ];
256
-            if ($event->ID() === $this->event_id) {
257
-                $this->hide_expired = $expired_class === '' ? $this->hide_expired : false;
258
-                $hide_expired_checked  = $expired_class === '' ? $hide_expired_checked : '';
259
-                $this->hide_upcoming = $upcoming_class === '' ? $this->hide_upcoming : false;
260
-                $hide_upcoming_checked = $upcoming_class === '' ? $hide_upcoming_checked : '';
261
-            }
262
-        }
263
-
264
-        $select_class = $this->hide_expired ? 'ee-hide-expired-events' : '';
265
-        $select_class .= $this->hide_upcoming ? ' ee-hide-upcoming-events' : '';
266
-
267
-        $filters[] = '
19
+	/**
20
+	 * @var RequestInterface
21
+	 */
22
+	protected $request;
23
+
24
+	/**
25
+	 * @var Extend_Registrations_Admin_Page
26
+	 */
27
+	protected $_admin_page;
28
+
29
+	/**
30
+	 * This property will hold the related Datetimes on an event IF the event id is included in the request.
31
+	 *
32
+	 * @var DatetimesForEventCheckIn
33
+	 */
34
+	protected $datetimes_for_event;
35
+
36
+	/**
37
+	 * The DTT_ID if the current view has a specified datetime.
38
+	 *
39
+	 * @var int
40
+	 */
41
+	protected $datetime_id = 0;
42
+
43
+	/**
44
+	 * @var EE_Datetime
45
+	 */
46
+	protected $datetime;
47
+
48
+	/**
49
+	 * The event ID if one is specified in the request
50
+	 *
51
+	 * @var int
52
+	 */
53
+	protected $event_id = 0;
54
+
55
+	/**
56
+	 * @var EE_Event
57
+	 */
58
+	protected $event;
59
+
60
+	/**
61
+	 * @var DatetimesForEventCheckIn
62
+	 */
63
+	protected $datetimes_for_current_row;
64
+
65
+	/**
66
+	 * @var bool
67
+	 */
68
+	protected $hide_expired;
69
+
70
+	/**
71
+	 * @var bool
72
+	 */
73
+	protected $hide_upcoming;
74
+
75
+	/**
76
+	 * @var   array
77
+	 * @since 4.10.31.p
78
+	 */
79
+	protected $_status;
80
+
81
+
82
+	/**
83
+	 * EE_Event_Registrations_List_Table constructor.
84
+	 *
85
+	 * @param Registrations_Admin_Page $admin_page
86
+	 * @throws EE_Error
87
+	 * @throws ReflectionException
88
+	 */
89
+	public function __construct($admin_page)
90
+	{
91
+		$this->request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
92
+		$this->resolveRequestVars();
93
+		parent::__construct($admin_page);
94
+	}
95
+
96
+
97
+	/**
98
+	 * @throws EE_Error
99
+	 * @throws ReflectionException
100
+	 * @since $VID:$
101
+	 */
102
+	private function resolveRequestVars()
103
+	{
104
+		$this->event_id = $this->request->getRequestParam('event_id', 0, 'int');
105
+		$this->datetimes_for_event = DatetimesForEventCheckIn::fromEventID($this->event_id);
106
+		// if we're filtering for a specific event and it only has one datetime, then grab its ID
107
+		$datetime          = $this->datetimes_for_event->getOneDatetimeForEvent();
108
+		$this->datetime_id = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
109
+		// else check the request, but use the above as the default (and hope they match if BOTH exist, LOLZ)
110
+		$this->datetime_id = $this->request->getRequestParam(
111
+			'DTT_ID',
112
+			$this->datetime_id,
113
+			'int'
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @throws EE_Error
120
+	 */
121
+	protected function _setup_data()
122
+	{
123
+		$this->_data = $this->_view !== 'trash'
124
+			? $this->_admin_page->get_event_attendees($this->_per_page)
125
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
126
+
127
+		$this->_all_data_count = $this->_view !== 'trash'
128
+			? $this->_admin_page->get_event_attendees($this->_per_page, true)
129
+			: $this->_admin_page->get_event_attendees($this->_per_page, true, true);
130
+	}
131
+
132
+
133
+	/**
134
+	 * @throws ReflectionException
135
+	 * @throws EE_Error
136
+	 */
137
+	protected function _set_properties()
138
+	{
139
+		$return_url = $this->getReturnUrl();
140
+
141
+		$this->_wp_list_args = [
142
+			'singular' => esc_html__('registrant', 'event_espresso'),
143
+			'plural'   => esc_html__('registrants', 'event_espresso'),
144
+			'ajax'     => true,
145
+			'screen'   => $this->_admin_page->get_current_screen()->id,
146
+		];
147
+		$columns             = [];
148
+
149
+		$this->_columns = [
150
+			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
151
+			'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
152
+			'ATT_email'           => esc_html__('Email Address', 'event_espresso'),
153
+			'Event'               => esc_html__('Event', 'event_espresso'),
154
+			'PRC_name'            => esc_html__('TKT Option', 'event_espresso'),
155
+			'_REG_final_price'    => esc_html__('Price', 'event_espresso'),
156
+			'TXN_paid'            => esc_html__('Paid', 'event_espresso'),
157
+			'TXN_total'           => esc_html__('Total', 'event_espresso'),
158
+		];
159
+		// Add/remove columns when an event has been selected
160
+		if (! empty($this->event_id)) {
161
+			// Render a checkbox column
162
+			$columns['cb']              = '<input type="checkbox" />';
163
+			$this->_has_checkbox_column = true;
164
+			// Remove the 'Event' column
165
+			unset($this->_columns['Event']);
166
+			$this->setBottomButtons();
167
+		}
168
+		$this->_columns        = array_merge($columns, $this->_columns);
169
+		$this->_primary_column = '_REG_att_checked_in';
170
+
171
+		$csv_report = RegistrationsCsvReportParams::getRequestParams(
172
+			$return_url,
173
+			$this->_req_data,
174
+			$this->event_id,
175
+			$this->datetime_id
176
+		);
177
+		if (! empty($csv_report)) {
178
+			$this->_bottom_buttons['csv_reg_report'] = $csv_report;
179
+		}
180
+
181
+		$this->_sortable_columns = [
182
+			/**
183
+			 * Allows users to change the default sort if they wish.
184
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
185
+			 *
186
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
187
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
188
+			 * for a specific list table you can use the provided reference to this object instance.
189
+			 */
190
+			'ATT_name' => [
191
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
192
+				true,
193
+				$this,
194
+			]
195
+				? ['ATT_lname' => true]
196
+				: ['ATT_fname' => true],
197
+			'Event'    => ['Event.EVT_name' => false],
198
+		];
199
+		$this->_hidden_columns   = [];
200
+		$this->event              = EEM_Event::instance()->get_one_by_ID($this->event_id);
201
+		if ($this->event instanceof EE_Event) {
202
+			$this->datetimes_for_event = DatetimesForEventCheckIn::fromEvent($this->event);
203
+		}
204
+	}
205
+
206
+
207
+	/**
208
+	 * @param EE_Registration $item
209
+	 * @return string
210
+	 */
211
+	protected function _get_row_class($item): string
212
+	{
213
+		$class = parent::_get_row_class($item);
214
+		if ($this->_has_checkbox_column) {
215
+			$class .= ' has-checkbox-column';
216
+		}
217
+		return $class;
218
+	}
219
+
220
+
221
+	/**
222
+	 * @return array
223
+	 * @throws EE_Error
224
+	 * @throws ReflectionException
225
+	 */
226
+	protected function _get_table_filters()
227
+	{
228
+		$filters = [];
229
+		$this->hide_expired = $this->request->getRequestParam('hide_expired', false, 'bool');
230
+		$this->hide_upcoming = $this->request->getRequestParam('hide_upcoming', false, 'bool');
231
+		$hide_expired_checked = $this->hide_expired ? 'checked' : '';
232
+		$hide_upcoming_checked = $this->hide_upcoming ? 'checked' : '';
233
+		// get datetimes for ALL active events (note possible capability restrictions)
234
+		$events   = $this->datetimes_for_event->getAllEvents();
235
+		$event_options[] = [
236
+			'id'   => 0,
237
+			'text' => esc_html__(' - select an event - ', 'event_espresso'),
238
+		];
239
+		foreach ($events as $event) {
240
+			// any registrations for this event?
241
+			if (! $event instanceof EE_Event/* || ! $event->get_count_of_all_registrations()*/) {
242
+				continue;
243
+			}
244
+			$expired_class = $event->is_expired() ? 'ee-expired-event' : '';
245
+			$upcoming_class  = $event->is_upcoming() ? ' ee-upcoming-event' : '';
246
+
247
+			$event_options[] = [
248
+				'id'    => $event->ID(),
249
+				'text'  => apply_filters(
250
+					'FHEE__EE_Event_Registrations___get_table_filters__event_name',
251
+					$event->name(),
252
+					$event
253
+				),
254
+				'class' => $expired_class . $upcoming_class,
255
+			];
256
+			if ($event->ID() === $this->event_id) {
257
+				$this->hide_expired = $expired_class === '' ? $this->hide_expired : false;
258
+				$hide_expired_checked  = $expired_class === '' ? $hide_expired_checked : '';
259
+				$this->hide_upcoming = $upcoming_class === '' ? $this->hide_upcoming : false;
260
+				$hide_upcoming_checked = $upcoming_class === '' ? $hide_upcoming_checked : '';
261
+			}
262
+		}
263
+
264
+		$select_class = $this->hide_expired ? 'ee-hide-expired-events' : '';
265
+		$select_class .= $this->hide_upcoming ? ' ee-hide-upcoming-events' : '';
266
+
267
+		$filters[] = '
268 268
         <div class="ee-event-filter__wrapper">
269 269
             <label class="ee-event-filter-main-label">
270 270
                 ' . esc_html__('Check-in Status for', 'event_espresso') . '
@@ -273,439 +273,439 @@  discard block
 block discarded – undo
273 273
                 <span class="ee-event-selector">
274 274
                     <label for="event_id">' . esc_html__('Event', 'event_espresso') . '</label>
275 275
                     ' . EEH_Form_Fields::select_input(
276
-                        'event_id',
277
-                        $event_options,
278
-                        $this->event_id,
279
-                        '',
280
-                        $select_class
281
-                    ) . '
276
+						'event_id',
277
+						$event_options,
278
+						$this->event_id,
279
+						'',
280
+						$select_class
281
+					) . '
282 282
                 </span>';
283
-        // DTT datetimes filter
284
-        $datetimes_for_event = $this->datetimes_for_event->getAllDatetimesForEvent(
285
-            $hide_upcoming_checked === 'checked'
286
-        );
287
-        if (count($datetimes_for_event) > 1) {
288
-            $datetimes[0] = esc_html__(' - select a datetime - ', 'event_espresso');
289
-            foreach ($datetimes_for_event as $datetime) {
290
-                if ($datetime instanceof EE_Datetime) {
291
-                    $datetime_string = $datetime->name();
292
-                    $datetime_string = ! empty($datetime_string) ? $datetime_string . ': ' : '';
293
-                    $datetime_string .= $datetime->date_and_time_range();
294
-                    $datetime_string .= $datetime->is_active() ? ' ∗' : '';
295
-                    $datetime_string .= $datetime->is_expired() ? ' «' : '';
296
-                    $datetime_string .= $datetime->is_upcoming() ? ' »' : '';
297
-                    // now put it all together
298
-                    $datetimes[ $datetime->ID() ] = $datetime_string;
299
-                }
300
-            }
301
-            $filters[] = '
283
+		// DTT datetimes filter
284
+		$datetimes_for_event = $this->datetimes_for_event->getAllDatetimesForEvent(
285
+			$hide_upcoming_checked === 'checked'
286
+		);
287
+		if (count($datetimes_for_event) > 1) {
288
+			$datetimes[0] = esc_html__(' - select a datetime - ', 'event_espresso');
289
+			foreach ($datetimes_for_event as $datetime) {
290
+				if ($datetime instanceof EE_Datetime) {
291
+					$datetime_string = $datetime->name();
292
+					$datetime_string = ! empty($datetime_string) ? $datetime_string . ': ' : '';
293
+					$datetime_string .= $datetime->date_and_time_range();
294
+					$datetime_string .= $datetime->is_active() ? ' ∗' : '';
295
+					$datetime_string .= $datetime->is_expired() ? ' «' : '';
296
+					$datetime_string .= $datetime->is_upcoming() ? ' »' : '';
297
+					// now put it all together
298
+					$datetimes[ $datetime->ID() ] = $datetime_string;
299
+				}
300
+			}
301
+			$filters[] = '
302 302
                 <span class="ee-datetime-selector">
303 303
                     <label for="DTT_ID">' . esc_html__('Datetime', 'event_espresso') . '</label>
304 304
                     ' . EEH_Form_Fields::select_input(
305
-                        'DTT_ID',
306
-                        $datetimes,
307
-                        $this->datetime_id
308
-                    ) . '
305
+						'DTT_ID',
306
+						$datetimes,
307
+						$this->datetime_id
308
+					) . '
309 309
                 </span>';
310
-        }
311
-        $filters[] = '
310
+		}
311
+		$filters[] = '
312 312
                 <span class="ee-hide-upcoming-check">
313 313
                     <label for="js-ee-hide-upcoming-events">
314 314
                         <input type="checkbox" id="js-ee-hide-upcoming-events" name="hide_upcoming" '
315
-                         . $hide_upcoming_checked
316
-                         . '>
315
+						 . $hide_upcoming_checked
316
+						 . '>
317 317
                         '
318
-                         . esc_html__('Hide Upcoming Events', 'event_espresso')
319
-                         . '
318
+						 . esc_html__('Hide Upcoming Events', 'event_espresso')
319
+						 . '
320 320
                     </label>
321 321
                     <span class="ee-help-btn dashicons dashicons-editor-help ee-aria-tooltip" aria-label="'
322
-                         . esc_html__(
323
-                             'Will not display events with start dates in the future (ie: have not yet begun)',
324
-                             'event_espresso'
325
-                         )
326
-                         . '"></span>
322
+						 . esc_html__(
323
+							 'Will not display events with start dates in the future (ie: have not yet begun)',
324
+							 'event_espresso'
325
+						 )
326
+						 . '"></span>
327 327
                 </span>
328 328
                 <span class="ee-hide-expired-check">
329 329
                     <label for="js-ee-hide-expired-events">
330 330
                         <input type="checkbox" id="js-ee-hide-expired-events" name="hide_expired" '
331
-                         . $hide_expired_checked
332
-                         . '>
331
+						 . $hide_expired_checked
332
+						 . '>
333 333
                         '
334
-                         . esc_html__('Hide Expired Events', 'event_espresso')
335
-                         . '
334
+						 . esc_html__('Hide Expired Events', 'event_espresso')
335
+						 . '
336 336
                     </label>
337 337
                     <span class="ee-help-btn dashicons dashicons-editor-help ee-aria-tooltip" aria-label="'
338
-                         . esc_html__(
339
-                             'Will not display events with end dates in the past (ie: have already finished)',
340
-                             'event_espresso'
341
-                         )
342
-                         . '"></span>
338
+						 . esc_html__(
339
+							 'Will not display events with end dates in the past (ie: have already finished)',
340
+							 'event_espresso'
341
+						 )
342
+						 . '"></span>
343 343
                 </span>
344 344
             </div>
345 345
         </div>';
346
-        return $filters;
347
-    }
348
-
349
-
350
-    /**
351
-     * @throws EE_Error
352
-     * @throws ReflectionException
353
-     */
354
-    protected function _add_view_counts()
355
-    {
356
-        $this->_views['all']['count'] = $this->_get_total_event_attendees();
357
-    }
358
-
359
-
360
-    /**
361
-     * @return int
362
-     * @throws EE_Error
363
-     * @throws ReflectionException
364
-     */
365
-    protected function _get_total_event_attendees(): int
366
-    {
367
-        $query_params      = [];
368
-        if ($this->event_id) {
369
-            $query_params[0]['EVT_ID'] = $this->event_id;
370
-        }
371
-        // if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
372
-        if ($this->datetime_id) {
373
-            $query_params[0]['Ticket.Datetime.DTT_ID'] = $this->datetime_id;
374
-        }
375
-        $status_ids_array          = apply_filters(
376
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
377
-            [EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved]
378
-        );
379
-        $query_params[0]['STS_ID'] = ['IN', $status_ids_array];
380
-        return EEM_Registration::instance()->count($query_params);
381
-    }
382
-
383
-
384
-    /**
385
-     * @param EE_Registration $item
386
-     * @return string
387
-     * @throws EE_Error
388
-     * @throws ReflectionException
389
-     */
390
-    public function column_cb($item): string
391
-    {
392
-        return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
393
-    }
394
-
395
-
396
-    /**
397
-     * column_REG_att_checked_in
398
-     *
399
-     * @param EE_Registration $registration
400
-     * @return string
401
-     * @throws EE_Error
402
-     * @throws InvalidArgumentException
403
-     * @throws InvalidDataTypeException
404
-     * @throws InvalidInterfaceException
405
-     * @throws ReflectionException
406
-     */
407
-    public function column__REG_att_checked_in(EE_Registration $registration): string
408
-    {
409
-        // we need a local variable for the datetime for each row
410
-        // (so that we don't pollute state for the entire table)
411
-        // so let's try to get it from the registration's event
412
-        $DTT_ID = $this->datetime_id;
413
-        if (! $DTT_ID) {
414
-            $reg_ticket_datetimes = $registration->ticket()->datetimes();
415
-            if (count($reg_ticket_datetimes) === 1) {
416
-                $reg_ticket_datetime = reset($reg_ticket_datetimes);
417
-                $DTT_ID = $reg_ticket_datetime instanceof EE_Datetime ? $reg_ticket_datetime->ID() : 0;
418
-            }
419
-        }
420
-
421
-        if (! $DTT_ID) {
422
-            $this->datetimes_for_current_row = DatetimesForEventCheckIn::fromRegistration($registration);
423
-            $datetime = $this->datetimes_for_current_row->getOneDatetimeForEvent($DTT_ID);
424
-            $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
425
-        }
426
-
427
-        $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
428
-            $registration,
429
-            $DTT_ID
430
-        );
431
-
432
-        $aria_label = $checkin_status_dashicon->ariaLabel();
433
-        $dashicon_class = $checkin_status_dashicon->cssClasses();
434
-        $attributes = ' onClick="return false"';
435
-        $button_class = 'button button--secondary button--icon-only ee-aria-tooltip ee-aria-tooltip--big-box';
436
-
437
-        if (
438
-            $DTT_ID
439
-            && EE_Registry::instance()->CAP->current_user_can(
440
-                'ee_edit_checkin',
441
-                'espresso_registrations_toggle_checkin_status',
442
-                $registration->ID()
443
-            )
444
-        ) {
445
-            // overwrite the disabled attribute with data attributes for performing checkin
446
-            $attributes = 'data-_regid="' . $registration->ID() . '"';
447
-            $attributes .= ' data-dttid="' . $DTT_ID . '"';
448
-            $attributes .= ' data-nonce="' . wp_create_nonce('checkin_nonce') . '"';
449
-            $button_class .= ' clickable trigger-checkin';
450
-        }
451
-
452
-        $content = '
346
+		return $filters;
347
+	}
348
+
349
+
350
+	/**
351
+	 * @throws EE_Error
352
+	 * @throws ReflectionException
353
+	 */
354
+	protected function _add_view_counts()
355
+	{
356
+		$this->_views['all']['count'] = $this->_get_total_event_attendees();
357
+	}
358
+
359
+
360
+	/**
361
+	 * @return int
362
+	 * @throws EE_Error
363
+	 * @throws ReflectionException
364
+	 */
365
+	protected function _get_total_event_attendees(): int
366
+	{
367
+		$query_params      = [];
368
+		if ($this->event_id) {
369
+			$query_params[0]['EVT_ID'] = $this->event_id;
370
+		}
371
+		// if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
372
+		if ($this->datetime_id) {
373
+			$query_params[0]['Ticket.Datetime.DTT_ID'] = $this->datetime_id;
374
+		}
375
+		$status_ids_array          = apply_filters(
376
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
377
+			[EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved]
378
+		);
379
+		$query_params[0]['STS_ID'] = ['IN', $status_ids_array];
380
+		return EEM_Registration::instance()->count($query_params);
381
+	}
382
+
383
+
384
+	/**
385
+	 * @param EE_Registration $item
386
+	 * @return string
387
+	 * @throws EE_Error
388
+	 * @throws ReflectionException
389
+	 */
390
+	public function column_cb($item): string
391
+	{
392
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
393
+	}
394
+
395
+
396
+	/**
397
+	 * column_REG_att_checked_in
398
+	 *
399
+	 * @param EE_Registration $registration
400
+	 * @return string
401
+	 * @throws EE_Error
402
+	 * @throws InvalidArgumentException
403
+	 * @throws InvalidDataTypeException
404
+	 * @throws InvalidInterfaceException
405
+	 * @throws ReflectionException
406
+	 */
407
+	public function column__REG_att_checked_in(EE_Registration $registration): string
408
+	{
409
+		// we need a local variable for the datetime for each row
410
+		// (so that we don't pollute state for the entire table)
411
+		// so let's try to get it from the registration's event
412
+		$DTT_ID = $this->datetime_id;
413
+		if (! $DTT_ID) {
414
+			$reg_ticket_datetimes = $registration->ticket()->datetimes();
415
+			if (count($reg_ticket_datetimes) === 1) {
416
+				$reg_ticket_datetime = reset($reg_ticket_datetimes);
417
+				$DTT_ID = $reg_ticket_datetime instanceof EE_Datetime ? $reg_ticket_datetime->ID() : 0;
418
+			}
419
+		}
420
+
421
+		if (! $DTT_ID) {
422
+			$this->datetimes_for_current_row = DatetimesForEventCheckIn::fromRegistration($registration);
423
+			$datetime = $this->datetimes_for_current_row->getOneDatetimeForEvent($DTT_ID);
424
+			$DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
425
+		}
426
+
427
+		$checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
428
+			$registration,
429
+			$DTT_ID
430
+		);
431
+
432
+		$aria_label = $checkin_status_dashicon->ariaLabel();
433
+		$dashicon_class = $checkin_status_dashicon->cssClasses();
434
+		$attributes = ' onClick="return false"';
435
+		$button_class = 'button button--secondary button--icon-only ee-aria-tooltip ee-aria-tooltip--big-box';
436
+
437
+		if (
438
+			$DTT_ID
439
+			&& EE_Registry::instance()->CAP->current_user_can(
440
+				'ee_edit_checkin',
441
+				'espresso_registrations_toggle_checkin_status',
442
+				$registration->ID()
443
+			)
444
+		) {
445
+			// overwrite the disabled attribute with data attributes for performing checkin
446
+			$attributes = 'data-_regid="' . $registration->ID() . '"';
447
+			$attributes .= ' data-dttid="' . $DTT_ID . '"';
448
+			$attributes .= ' data-nonce="' . wp_create_nonce('checkin_nonce') . '"';
449
+			$button_class .= ' clickable trigger-checkin';
450
+		}
451
+
452
+		$content = '
453 453
         <button aria-label="' . $aria_label . '" class="' . $button_class . '" ' . $attributes . '>
454 454
             <span class="' . $dashicon_class . '" ></span>
455 455
         </button>
456 456
         <span class="show-on-mobile-view-only">' . $this->column_ATT_name($registration) . '</span>';
457
-        return $this->columnContent('_REG_att_checked_in', $content, 'center');
458
-    }
459
-
460
-
461
-    /**
462
-     * @param EE_Registration $registration
463
-     * @return string
464
-     * @throws EE_Error
465
-     * @throws ReflectionException
466
-     */
467
-    public function column_ATT_name(EE_Registration $registration): string
468
-    {
469
-        $attendee = $registration->attendee();
470
-        if (! $attendee instanceof EE_Attendee) {
471
-            return esc_html__('No contact record for this registration.', 'event_espresso');
472
-        }
473
-        // edit attendee link
474
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
475
-            ['action' => 'view_registration', '_REG_ID' => $registration->ID()],
476
-            REG_ADMIN_URL
477
-        );
478
-        $name_link    = '
457
+		return $this->columnContent('_REG_att_checked_in', $content, 'center');
458
+	}
459
+
460
+
461
+	/**
462
+	 * @param EE_Registration $registration
463
+	 * @return string
464
+	 * @throws EE_Error
465
+	 * @throws ReflectionException
466
+	 */
467
+	public function column_ATT_name(EE_Registration $registration): string
468
+	{
469
+		$attendee = $registration->attendee();
470
+		if (! $attendee instanceof EE_Attendee) {
471
+			return esc_html__('No contact record for this registration.', 'event_espresso');
472
+		}
473
+		// edit attendee link
474
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
475
+			['action' => 'view_registration', '_REG_ID' => $registration->ID()],
476
+			REG_ADMIN_URL
477
+		);
478
+		$name_link    = '
479 479
             <span class="ee-status-dot ee-status-bg--' . esc_attr($registration->status_ID()) . ' ee-aria-tooltip"
480 480
             aria-label="' . EEH_Template::pretty_status($registration->status_ID(), false, 'sentence') . '">
481 481
             </span>';
482
-        $name_link    .= EE_Registry::instance()->CAP->current_user_can(
483
-            'ee_edit_contacts',
484
-            'espresso_registrations_edit_attendee'
485
-        )
486
-            ? '<a class="ee-aria-tooltip" href="' . $edit_lnk_url . '" aria-label="' . esc_attr__(
487
-                'View Registration Details',
488
-                'event_espresso'
489
-            ) . '">'
490
-              . $registration->attendee()->full_name()
491
-              . '</a>'
492
-            : $registration->attendee()->full_name();
493
-        $name_link    .= $registration->count() === 1
494
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled gold-icon"></div></sup>	'
495
-            : '';
496
-        // add group details
497
-        $name_link .= '&nbsp;' . sprintf(
498
-            esc_html__('(%s of %s)', 'event_espresso'),
499
-            $registration->count(),
500
-            $registration->group_size()
501
-        );
502
-        // add regcode
503
-        $link      = EE_Admin_Page::add_query_args_and_nonce(
504
-            ['action' => 'view_registration', '_REG_ID' => $registration->ID()],
505
-            REG_ADMIN_URL
506
-        );
507
-        $name_link .= '<br>';
508
-        $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
509
-            'ee_read_registration',
510
-            'view_registration',
511
-            $registration->ID()
512
-        )
513
-            ? '<a class="ee-aria-tooltip" href="' . $link . '" aria-label="' . esc_attr__(
514
-                'View Registration Details',
515
-                'event_espresso'
516
-            ) . '">'
517
-              . $registration->reg_code()
518
-              . '</a>'
519
-            : $registration->reg_code();
520
-
521
-        $actions                 = [];
522
-        if (
523
-            $this->datetime_id
524
-            && EE_Registry::instance()->CAP->current_user_can(
525
-                'ee_read_checkins',
526
-                'espresso_registrations_registration_checkins'
527
-            )
528
-        ) {
529
-            $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
530
-                ['action' => 'registration_checkins', '_REG_ID' => $registration->ID(), 'DTT_ID' => $this->datetime_id],
531
-                REG_ADMIN_URL
532
-            );
533
-            // get the timestamps for this registration's checkins, related to the selected datetime
534
-            /** @var EE_Checkin[] $checkins */
535
-            $checkins = $registration->get_many_related('Checkin', [['DTT_ID' => $this->datetime_id]]);
536
-            if (! empty($checkins)) {
537
-                // get the last timestamp
538
-                $last_checkin = end($checkins);
539
-                // get timestamp string
540
-                $timestamp_string   = $last_checkin->get_datetime('CHK_timestamp');
541
-                $actions['checkin'] = '
482
+		$name_link    .= EE_Registry::instance()->CAP->current_user_can(
483
+			'ee_edit_contacts',
484
+			'espresso_registrations_edit_attendee'
485
+		)
486
+			? '<a class="ee-aria-tooltip" href="' . $edit_lnk_url . '" aria-label="' . esc_attr__(
487
+				'View Registration Details',
488
+				'event_espresso'
489
+			) . '">'
490
+			  . $registration->attendee()->full_name()
491
+			  . '</a>'
492
+			: $registration->attendee()->full_name();
493
+		$name_link    .= $registration->count() === 1
494
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled gold-icon"></div></sup>	'
495
+			: '';
496
+		// add group details
497
+		$name_link .= '&nbsp;' . sprintf(
498
+			esc_html__('(%s of %s)', 'event_espresso'),
499
+			$registration->count(),
500
+			$registration->group_size()
501
+		);
502
+		// add regcode
503
+		$link      = EE_Admin_Page::add_query_args_and_nonce(
504
+			['action' => 'view_registration', '_REG_ID' => $registration->ID()],
505
+			REG_ADMIN_URL
506
+		);
507
+		$name_link .= '<br>';
508
+		$name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
509
+			'ee_read_registration',
510
+			'view_registration',
511
+			$registration->ID()
512
+		)
513
+			? '<a class="ee-aria-tooltip" href="' . $link . '" aria-label="' . esc_attr__(
514
+				'View Registration Details',
515
+				'event_espresso'
516
+			) . '">'
517
+			  . $registration->reg_code()
518
+			  . '</a>'
519
+			: $registration->reg_code();
520
+
521
+		$actions                 = [];
522
+		if (
523
+			$this->datetime_id
524
+			&& EE_Registry::instance()->CAP->current_user_can(
525
+				'ee_read_checkins',
526
+				'espresso_registrations_registration_checkins'
527
+			)
528
+		) {
529
+			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
530
+				['action' => 'registration_checkins', '_REG_ID' => $registration->ID(), 'DTT_ID' => $this->datetime_id],
531
+				REG_ADMIN_URL
532
+			);
533
+			// get the timestamps for this registration's checkins, related to the selected datetime
534
+			/** @var EE_Checkin[] $checkins */
535
+			$checkins = $registration->get_many_related('Checkin', [['DTT_ID' => $this->datetime_id]]);
536
+			if (! empty($checkins)) {
537
+				// get the last timestamp
538
+				$last_checkin = end($checkins);
539
+				// get timestamp string
540
+				$timestamp_string   = $last_checkin->get_datetime('CHK_timestamp');
541
+				$actions['checkin'] = '
542 542
                     <a  class="ee-aria-tooltip"
543 543
                         href="' . $checkin_list_url . '"
544 544
                         aria-label="' . esc_attr__(
545
-                            'View this registrant\'s check-ins/checkouts for the datetime',
546
-                            'event_espresso'
547
-                        ) . '"
545
+							'View this registrant\'s check-ins/checkouts for the datetime',
546
+							'event_espresso'
547
+						) . '"
548 548
                     >
549 549
                         ' . $last_checkin->getCheckInText() . ': ' . $timestamp_string . '
550 550
                     </a>';
551
-            }
552
-        }
553
-        $content = (! empty($this->datetime_id) && ! empty($checkins))
554
-            ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
555
-            : $name_link;
556
-        return $this->columnContent('ATT_name', $content);
557
-    }
558
-
559
-
560
-    /**
561
-     * @param EE_Registration $registration
562
-     * @return string
563
-     * @throws EE_Error
564
-     * @throws EE_Error
565
-     * @throws ReflectionException
566
-     */
567
-    public function column_ATT_email(EE_Registration $registration): string
568
-    {
569
-        $attendee = $registration->attendee();
570
-        $content = $attendee instanceof EE_Attendee ? $attendee->email() : '';
571
-        return $this->columnContent('ATT_email', $content);
572
-    }
573
-
574
-
575
-    /**
576
-     * @param EE_Registration $registration
577
-     * @return string
578
-     * @throws EE_Error
579
-     * @throws ReflectionException
580
-     */
581
-    public function column_Event(EE_Registration $registration): string
582
-    {
583
-        try {
584
-            $event            = $this->event instanceof EE_Event ? $this->event : $registration->event();
585
-            $checkin_link_url = EE_Admin_Page::add_query_args_and_nonce(
586
-                ['action' => 'event_registrations', 'event_id' => $event->ID()],
587
-                REG_ADMIN_URL
588
-            );
589
-            $content      = EE_Registry::instance()->CAP->current_user_can(
590
-                'ee_read_checkins',
591
-                'espresso_registrations_registration_checkins'
592
-            ) ? '<a class="ee-aria-tooltip" href="' . $checkin_link_url . '" aria-label="'
593
-                . esc_attr__(
594
-                    'View Checkins for this Event',
595
-                    'event_espresso'
596
-                ) . '">' . $event->name() . '</a>' : $event->name();
597
-        } catch (EntityNotFoundException $e) {
598
-            $content = esc_html__('Unknown', 'event_espresso');
599
-        }
600
-        return $this->columnContent('Event', $content);
601
-    }
602
-
603
-
604
-    /**
605
-     * @param EE_Registration $registration
606
-     * @return string
607
-     * @throws EE_Error
608
-     * @throws ReflectionException
609
-     */
610
-    public function column_PRC_name(EE_Registration $registration): string
611
-    {
612
-        $content = $registration->ticket() instanceof EE_Ticket
613
-            ? $registration->ticket()->name()
614
-            : esc_html__(
615
-                "Unknown",
616
-                "event_espresso"
617
-            );
618
-        return $this->columnContent('PRC_name', $content);
619
-    }
620
-
621
-
622
-    /**
623
-     * column_REG_final_price
624
-     *
625
-     * @param EE_Registration $registration
626
-     * @return string
627
-     * @throws EE_Error
628
-     */
629
-    public function column__REG_final_price(EE_Registration $registration): string
630
-    {
631
-        return $this->columnContent('_REG_final_price', $registration->pretty_final_price(), 'end');
632
-    }
633
-
634
-
635
-    /**
636
-     * column_TXN_paid
637
-     *
638
-     * @param EE_Registration $registration
639
-     * @return string
640
-     * @throws EE_Error
641
-     * @throws ReflectionException
642
-     */
643
-    public function column_TXN_paid(EE_Registration $registration): string
644
-    {
645
-        $content = '';
646
-        if ($registration->count() === 1) {
647
-            if ($registration->transaction()->paid() >= $registration->transaction()->total()) {
648
-                return '<div class="dashicons dashicons-yes green-icon"></div>';
649
-            } else {
650
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
651
-                    ['action' => 'view_transaction', 'TXN_ID' => $registration->transaction_ID()],
652
-                    TXN_ADMIN_URL
653
-                );
654
-                $content = EE_Registry::instance()->CAP->current_user_can(
655
-                    'ee_read_transaction',
656
-                    'espresso_transactions_view_transaction'
657
-                ) ? '
551
+			}
552
+		}
553
+		$content = (! empty($this->datetime_id) && ! empty($checkins))
554
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
555
+			: $name_link;
556
+		return $this->columnContent('ATT_name', $content);
557
+	}
558
+
559
+
560
+	/**
561
+	 * @param EE_Registration $registration
562
+	 * @return string
563
+	 * @throws EE_Error
564
+	 * @throws EE_Error
565
+	 * @throws ReflectionException
566
+	 */
567
+	public function column_ATT_email(EE_Registration $registration): string
568
+	{
569
+		$attendee = $registration->attendee();
570
+		$content = $attendee instanceof EE_Attendee ? $attendee->email() : '';
571
+		return $this->columnContent('ATT_email', $content);
572
+	}
573
+
574
+
575
+	/**
576
+	 * @param EE_Registration $registration
577
+	 * @return string
578
+	 * @throws EE_Error
579
+	 * @throws ReflectionException
580
+	 */
581
+	public function column_Event(EE_Registration $registration): string
582
+	{
583
+		try {
584
+			$event            = $this->event instanceof EE_Event ? $this->event : $registration->event();
585
+			$checkin_link_url = EE_Admin_Page::add_query_args_and_nonce(
586
+				['action' => 'event_registrations', 'event_id' => $event->ID()],
587
+				REG_ADMIN_URL
588
+			);
589
+			$content      = EE_Registry::instance()->CAP->current_user_can(
590
+				'ee_read_checkins',
591
+				'espresso_registrations_registration_checkins'
592
+			) ? '<a class="ee-aria-tooltip" href="' . $checkin_link_url . '" aria-label="'
593
+				. esc_attr__(
594
+					'View Checkins for this Event',
595
+					'event_espresso'
596
+				) . '">' . $event->name() . '</a>' : $event->name();
597
+		} catch (EntityNotFoundException $e) {
598
+			$content = esc_html__('Unknown', 'event_espresso');
599
+		}
600
+		return $this->columnContent('Event', $content);
601
+	}
602
+
603
+
604
+	/**
605
+	 * @param EE_Registration $registration
606
+	 * @return string
607
+	 * @throws EE_Error
608
+	 * @throws ReflectionException
609
+	 */
610
+	public function column_PRC_name(EE_Registration $registration): string
611
+	{
612
+		$content = $registration->ticket() instanceof EE_Ticket
613
+			? $registration->ticket()->name()
614
+			: esc_html__(
615
+				"Unknown",
616
+				"event_espresso"
617
+			);
618
+		return $this->columnContent('PRC_name', $content);
619
+	}
620
+
621
+
622
+	/**
623
+	 * column_REG_final_price
624
+	 *
625
+	 * @param EE_Registration $registration
626
+	 * @return string
627
+	 * @throws EE_Error
628
+	 */
629
+	public function column__REG_final_price(EE_Registration $registration): string
630
+	{
631
+		return $this->columnContent('_REG_final_price', $registration->pretty_final_price(), 'end');
632
+	}
633
+
634
+
635
+	/**
636
+	 * column_TXN_paid
637
+	 *
638
+	 * @param EE_Registration $registration
639
+	 * @return string
640
+	 * @throws EE_Error
641
+	 * @throws ReflectionException
642
+	 */
643
+	public function column_TXN_paid(EE_Registration $registration): string
644
+	{
645
+		$content = '';
646
+		if ($registration->count() === 1) {
647
+			if ($registration->transaction()->paid() >= $registration->transaction()->total()) {
648
+				return '<div class="dashicons dashicons-yes green-icon"></div>';
649
+			} else {
650
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
651
+					['action' => 'view_transaction', 'TXN_ID' => $registration->transaction_ID()],
652
+					TXN_ADMIN_URL
653
+				);
654
+				$content = EE_Registry::instance()->CAP->current_user_can(
655
+					'ee_read_transaction',
656
+					'espresso_transactions_view_transaction'
657
+				) ? '
658 658
 				<a class="ee-aria-tooltip ee-status-color--'
659
-                    . $registration->transaction()->status_ID()
660
-                    . '" href="'
661
-                    . $view_txn_lnk_url
662
-                    . '"  aria-label="'
663
-                    . esc_attr__('View Transaction', 'event_espresso')
664
-                    . '">
659
+					. $registration->transaction()->status_ID()
660
+					. '" href="'
661
+					. $view_txn_lnk_url
662
+					. '"  aria-label="'
663
+					. esc_attr__('View Transaction', 'event_espresso')
664
+					. '">
665 665
 						'
666
-                    . $registration->transaction()->pretty_paid()
667
-                    . '
666
+					. $registration->transaction()->pretty_paid()
667
+					. '
668 668
 					</a>
669 669
 				' : $registration->transaction()->pretty_paid();
670
-            }
671
-        }
672
-        return $this->columnContent('TXN_paid', $content, 'end');
673
-    }
674
-
675
-
676
-    /**
677
-     *        column_TXN_total
678
-     *
679
-     * @param EE_Registration $registration
680
-     * @return string
681
-     * @throws EE_Error
682
-     * @throws ReflectionException
683
-     */
684
-    public function column_TXN_total(EE_Registration $registration): string
685
-    {
686
-        $content = '';
687
-        $txn = $registration->transaction();
688
-        $view_txn_url = add_query_arg(['action' => 'view_transaction', 'TXN_ID' => $txn->ID()], TXN_ADMIN_URL);
689
-        if ($registration->get('REG_count') === 1) {
690
-            $line_total_obj = $txn->total_line_item();
691
-            $txn_total      = $line_total_obj instanceof EE_Line_Item
692
-                ? $line_total_obj->get_pretty('LIN_total')
693
-                : esc_html__(
694
-                    'View Transaction',
695
-                    'event_espresso'
696
-                );
697
-            $content = EE_Registry::instance()->CAP->current_user_can(
698
-                'ee_read_transaction',
699
-                'espresso_transactions_view_transaction'
700
-            ) ? '<a class="ee-aria-tooltip" href="'
701
-                . $view_txn_url
702
-                . '" aria-label="'
703
-                . esc_attr__('View Transaction', 'event_espresso')
704
-                . '">'
705
-                . $txn_total
706
-                . '</a>'
707
-                : $txn_total;
708
-        }
709
-        return $this->columnContent('TXN_total', $content, 'end');
710
-    }
670
+			}
671
+		}
672
+		return $this->columnContent('TXN_paid', $content, 'end');
673
+	}
674
+
675
+
676
+	/**
677
+	 *        column_TXN_total
678
+	 *
679
+	 * @param EE_Registration $registration
680
+	 * @return string
681
+	 * @throws EE_Error
682
+	 * @throws ReflectionException
683
+	 */
684
+	public function column_TXN_total(EE_Registration $registration): string
685
+	{
686
+		$content = '';
687
+		$txn = $registration->transaction();
688
+		$view_txn_url = add_query_arg(['action' => 'view_transaction', 'TXN_ID' => $txn->ID()], TXN_ADMIN_URL);
689
+		if ($registration->get('REG_count') === 1) {
690
+			$line_total_obj = $txn->total_line_item();
691
+			$txn_total      = $line_total_obj instanceof EE_Line_Item
692
+				? $line_total_obj->get_pretty('LIN_total')
693
+				: esc_html__(
694
+					'View Transaction',
695
+					'event_espresso'
696
+				);
697
+			$content = EE_Registry::instance()->CAP->current_user_can(
698
+				'ee_read_transaction',
699
+				'espresso_transactions_view_transaction'
700
+			) ? '<a class="ee-aria-tooltip" href="'
701
+				. $view_txn_url
702
+				. '" aria-label="'
703
+				. esc_attr__('View Transaction', 'event_espresso')
704
+				. '">'
705
+				. $txn_total
706
+				. '</a>'
707
+				: $txn_total;
708
+		}
709
+		return $this->columnContent('TXN_total', $content, 'end');
710
+	}
711 711
 }
Please login to merge, or discard this patch.
registration_form/Registration_Form_Questions_Admin_List_Table.class.php 1 patch
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -15,223 +15,223 @@
 block discarded – undo
15 15
  */
16 16
 class Registration_Form_Questions_Admin_List_Table extends EE_Admin_List_Table
17 17
 {
18
-    /**
19
-     * @var Registration_Form_Admin_Page $_admin_page
20
-     */
21
-    protected $_admin_page;
22
-
23
-    /**
24
-     * @var RegFormListTableUserCapabilities
25
-     */
26
-    protected $caps_handler;
27
-
28
-
29
-    public function __construct($admin_page)
30
-    {
31
-        $this->caps_handler = new RegFormListTableUserCapabilities(EE_Registry::instance()->CAP);
32
-        parent::__construct($admin_page);
33
-
34
-        if (! defined('REG_ADMIN_URL')) {
35
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
36
-        }
37
-    }
38
-
39
-
40
-    /**
41
-     * @throws EE_Error
42
-     */
43
-    protected function _setup_data()
44
-    {
45
-        if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'trash') {
46
-            $this->_data = $this->_admin_page->get_trashed_questions($this->_per_page, $this->_current_page);
47
-        } else {
48
-            $this->_data = $this->_admin_page->get_questions($this->_per_page, $this->_current_page);
49
-        }
50
-        $this->_all_data_count = $this->_admin_page->get_questions($this->_per_page, $this->_current_page, true);
51
-    }
52
-
53
-
54
-    protected function _set_properties()
55
-    {
56
-        $this->_wp_list_args = [
57
-            'singular' => esc_html__('question', 'event_espresso'),
58
-            'plural'   => esc_html__('questions', 'event_espresso'),
59
-            'ajax'     => true, // for now,
60
-            'screen'   => $this->_admin_page->get_current_screen()->id,
61
-        ];
62
-
63
-        $this->_columns = [
64
-            'cb'           => '<input type="checkbox" />',
65
-            'id'           => esc_html__('ID', 'event_espresso'),
66
-            'display_text' => esc_html__('Question', 'event_espresso'),
67
-            'admin_label'  => esc_html__('Admin Label', 'event_espresso'),
68
-            'type'         => esc_html__('Type', 'event_espresso'),
69
-            'values'       => esc_html__('Values', 'event_espresso'),
70
-            'required'     => esc_html__('Req', 'event_espresso'),
71
-        ];
72
-
73
-        $this->_primary_column = 'id';
74
-
75
-        $this->_sortable_columns = [
76
-            'id'           => ['QST_ID' => false],
77
-            'display_text' => ['QST_display_text' => false],
78
-        ];
79
-
80
-        $this->_hidden_columns = [];
81
-    }
82
-
83
-
84
-    // not needed
85
-    protected function _get_table_filters()
86
-    {
87
-        return [];
88
-    }
89
-
90
-
91
-    /**
92
-     * @throws EE_Error
93
-     */
94
-    protected function _add_view_counts()
95
-    {
96
-        $this->_views['all']['count'] = $this->_admin_page->get_questions($this->_per_page, $this->_current_page, true);
97
-        if ($this->caps_handler->userCanTrashQuestions()) {
98
-            $this->_views['trash']['count'] = $this->_admin_page->get_trashed_questions(-1, $this->_current_page, true);
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * @param EE_Question $item
105
-     * @return string
106
-     * @throws EE_Error
107
-     * @throws ReflectionException
108
-     */
109
-    public function column_cb($item): string
110
-    {
111
-        $system_question      = $item->is_system_question();
112
-        $related_answer_count = $item->count_related('Answer');
113
-        $has_answers          = ! $system_question && $related_answer_count > 0 && $this->_view == 'trash';
114
-        $notice               = $has_answers
115
-            ? esc_html__(
116
-                'This question has answers attached to it from registrations that have the question.  It cannot be permanently deleted.',
117
-                'event_espresso'
118
-            )
119
-            : esc_html__('This question is a system question and cannot be trashed', 'event_espresso');
120
-
121
-        return $system_question || $has_answers
122
-            ? '
18
+	/**
19
+	 * @var Registration_Form_Admin_Page $_admin_page
20
+	 */
21
+	protected $_admin_page;
22
+
23
+	/**
24
+	 * @var RegFormListTableUserCapabilities
25
+	 */
26
+	protected $caps_handler;
27
+
28
+
29
+	public function __construct($admin_page)
30
+	{
31
+		$this->caps_handler = new RegFormListTableUserCapabilities(EE_Registry::instance()->CAP);
32
+		parent::__construct($admin_page);
33
+
34
+		if (! defined('REG_ADMIN_URL')) {
35
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
36
+		}
37
+	}
38
+
39
+
40
+	/**
41
+	 * @throws EE_Error
42
+	 */
43
+	protected function _setup_data()
44
+	{
45
+		if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'trash') {
46
+			$this->_data = $this->_admin_page->get_trashed_questions($this->_per_page, $this->_current_page);
47
+		} else {
48
+			$this->_data = $this->_admin_page->get_questions($this->_per_page, $this->_current_page);
49
+		}
50
+		$this->_all_data_count = $this->_admin_page->get_questions($this->_per_page, $this->_current_page, true);
51
+	}
52
+
53
+
54
+	protected function _set_properties()
55
+	{
56
+		$this->_wp_list_args = [
57
+			'singular' => esc_html__('question', 'event_espresso'),
58
+			'plural'   => esc_html__('questions', 'event_espresso'),
59
+			'ajax'     => true, // for now,
60
+			'screen'   => $this->_admin_page->get_current_screen()->id,
61
+		];
62
+
63
+		$this->_columns = [
64
+			'cb'           => '<input type="checkbox" />',
65
+			'id'           => esc_html__('ID', 'event_espresso'),
66
+			'display_text' => esc_html__('Question', 'event_espresso'),
67
+			'admin_label'  => esc_html__('Admin Label', 'event_espresso'),
68
+			'type'         => esc_html__('Type', 'event_espresso'),
69
+			'values'       => esc_html__('Values', 'event_espresso'),
70
+			'required'     => esc_html__('Req', 'event_espresso'),
71
+		];
72
+
73
+		$this->_primary_column = 'id';
74
+
75
+		$this->_sortable_columns = [
76
+			'id'           => ['QST_ID' => false],
77
+			'display_text' => ['QST_display_text' => false],
78
+		];
79
+
80
+		$this->_hidden_columns = [];
81
+	}
82
+
83
+
84
+	// not needed
85
+	protected function _get_table_filters()
86
+	{
87
+		return [];
88
+	}
89
+
90
+
91
+	/**
92
+	 * @throws EE_Error
93
+	 */
94
+	protected function _add_view_counts()
95
+	{
96
+		$this->_views['all']['count'] = $this->_admin_page->get_questions($this->_per_page, $this->_current_page, true);
97
+		if ($this->caps_handler->userCanTrashQuestions()) {
98
+			$this->_views['trash']['count'] = $this->_admin_page->get_trashed_questions(-1, $this->_current_page, true);
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param EE_Question $item
105
+	 * @return string
106
+	 * @throws EE_Error
107
+	 * @throws ReflectionException
108
+	 */
109
+	public function column_cb($item): string
110
+	{
111
+		$system_question      = $item->is_system_question();
112
+		$related_answer_count = $item->count_related('Answer');
113
+		$has_answers          = ! $system_question && $related_answer_count > 0 && $this->_view == 'trash';
114
+		$notice               = $has_answers
115
+			? esc_html__(
116
+				'This question has answers attached to it from registrations that have the question.  It cannot be permanently deleted.',
117
+				'event_espresso'
118
+			)
119
+			: esc_html__('This question is a system question and cannot be trashed', 'event_espresso');
120
+
121
+		return $system_question || $has_answers
122
+			? '
123 123
             <span class="dashicons dashicons-lock ee-locked-entity ee-aria-tooltip"
124 124
                     aria-label="' . $notice . '"></span>
125 125
             ' . sprintf('<input type="hidden" name="hdnchk[%1$d]" value="%1$d" />', $item->ID())
126
-            : sprintf('<input type="checkbox" class="QST_ID" name="checkbox[%1$d]" value="%1$d" />', $item->ID());
127
-    }
128
-
129
-
130
-    /**
131
-     * @param EE_Question $item
132
-     * @return string
133
-     * @throws EE_Error
134
-     * @throws ReflectionException
135
-     */
136
-    public function column_id(EE_Question $item): string
137
-    {
138
-        $content = '
126
+			: sprintf('<input type="checkbox" class="QST_ID" name="checkbox[%1$d]" value="%1$d" />', $item->ID());
127
+	}
128
+
129
+
130
+	/**
131
+	 * @param EE_Question $item
132
+	 * @return string
133
+	 * @throws EE_Error
134
+	 * @throws ReflectionException
135
+	 */
136
+	public function column_id(EE_Question $item): string
137
+	{
138
+		$content = '
139 139
             <span class="ee-entity-id">' . $item->ID() . '</span>
140 140
             <span class="show-on-mobile-view-only">
141 141
                 ' . $this->column_display_text($item, false) . '
142 142
             </span>';
143
-        return $this->columnContent('id', $content, 'end');
144
-    }
145
-
146
-
147
-    /**
148
-     * @param EE_Question $question
149
-     * @param bool        $prep_content
150
-     * @return string
151
-     * @throws EE_Error
152
-     * @throws ReflectionException
153
-     */
154
-    public function column_display_text(EE_Question $question, bool $prep_content = true): string
155
-    {
156
-        if ($this->caps_handler->userCanEditQuestion($question)) {
157
-            $content = $this->$this->getActionLink(
158
-                $this->getActionUrl($question, self::ACTION_EDIT),
159
-                $prep_content ? $question->display_text() : $question->admin_label(),
160
-                esc_attr__('Edit Question', 'event_espresso'),
161
-                'row-title'
162
-            );
163
-            $content .= $this->row_actions(
164
-                [
165
-                    'edit' => $this->getActionLink(
166
-                        $this->getActionUrl($question, self::ACTION_EDIT),
167
-                        esc_html__('Edit', 'event_espresso'),
168
-                        esc_attr__('Edit Question', 'event_espresso')
169
-                    ),
170
-                ]
171
-            );
172
-        } else {
173
-            $content = $question->display_text();
174
-        }
175
-
176
-        return $prep_content ? $this->columnContent('display_text', $content) : $content;
177
-    }
178
-
179
-
180
-    /**
181
-     * @param EE_Question $question
182
-     * @param string      $action
183
-     * @return string
184
-     * @throws EE_Error
185
-     * @throws ReflectionException
186
-     * @since $VID:$
187
-     */
188
-    protected function getActionUrl(EE_Question $question, string $action): string
189
-    {
190
-        if (! in_array($action, self::$actions)) {
191
-            throw new DomainException(esc_html__('Invalid Action', 'event_espresso'));
192
-        }
193
-        return EE_Admin_Page::add_query_args_and_nonce(
194
-            [
195
-                'action'   => $action === self::ACTION_DELETE ? "{$action}_questions" : "{$action}_question",
196
-                'QST_ID'   => $question->ID(),
197
-                'noheader' => $action !== self::ACTION_EDIT,
198
-            ],
199
-            EE_FORMS_ADMIN_URL
200
-        );
201
-    }
202
-
203
-
204
-    public function column_admin_label(EE_Question $item): string
205
-    {
206
-        return $this->columnContent('admin_label', $item->admin_label());
207
-    }
208
-
209
-
210
-    public function column_values(EE_Question $item): string
211
-    {
212
-        $optionNames = [];
213
-        $options     = $item->options();
214
-        if (empty($options)) {
215
-            $content = "N/A";
216
-        } else {
217
-            foreach ($options as $option) {
218
-                $optionNames[] = $option->value();
219
-            }
220
-            $content = implode(', ', $optionNames);
221
-        }
222
-        return $this->columnContent('values', $content);
223
-    }
224
-
225
-
226
-    public function column_type(EE_Question $item): string
227
-    {
228
-        return $this->columnContent('type', $item->type());
229
-    }
230
-
231
-
232
-    public function column_required(EE_Question $item): string
233
-    {
234
-        $content = $item->required() ? 'Yes' : '';
235
-        return $this->columnContent('required', $content);
236
-    }
143
+		return $this->columnContent('id', $content, 'end');
144
+	}
145
+
146
+
147
+	/**
148
+	 * @param EE_Question $question
149
+	 * @param bool        $prep_content
150
+	 * @return string
151
+	 * @throws EE_Error
152
+	 * @throws ReflectionException
153
+	 */
154
+	public function column_display_text(EE_Question $question, bool $prep_content = true): string
155
+	{
156
+		if ($this->caps_handler->userCanEditQuestion($question)) {
157
+			$content = $this->$this->getActionLink(
158
+				$this->getActionUrl($question, self::ACTION_EDIT),
159
+				$prep_content ? $question->display_text() : $question->admin_label(),
160
+				esc_attr__('Edit Question', 'event_espresso'),
161
+				'row-title'
162
+			);
163
+			$content .= $this->row_actions(
164
+				[
165
+					'edit' => $this->getActionLink(
166
+						$this->getActionUrl($question, self::ACTION_EDIT),
167
+						esc_html__('Edit', 'event_espresso'),
168
+						esc_attr__('Edit Question', 'event_espresso')
169
+					),
170
+				]
171
+			);
172
+		} else {
173
+			$content = $question->display_text();
174
+		}
175
+
176
+		return $prep_content ? $this->columnContent('display_text', $content) : $content;
177
+	}
178
+
179
+
180
+	/**
181
+	 * @param EE_Question $question
182
+	 * @param string      $action
183
+	 * @return string
184
+	 * @throws EE_Error
185
+	 * @throws ReflectionException
186
+	 * @since $VID:$
187
+	 */
188
+	protected function getActionUrl(EE_Question $question, string $action): string
189
+	{
190
+		if (! in_array($action, self::$actions)) {
191
+			throw new DomainException(esc_html__('Invalid Action', 'event_espresso'));
192
+		}
193
+		return EE_Admin_Page::add_query_args_and_nonce(
194
+			[
195
+				'action'   => $action === self::ACTION_DELETE ? "{$action}_questions" : "{$action}_question",
196
+				'QST_ID'   => $question->ID(),
197
+				'noheader' => $action !== self::ACTION_EDIT,
198
+			],
199
+			EE_FORMS_ADMIN_URL
200
+		);
201
+	}
202
+
203
+
204
+	public function column_admin_label(EE_Question $item): string
205
+	{
206
+		return $this->columnContent('admin_label', $item->admin_label());
207
+	}
208
+
209
+
210
+	public function column_values(EE_Question $item): string
211
+	{
212
+		$optionNames = [];
213
+		$options     = $item->options();
214
+		if (empty($options)) {
215
+			$content = "N/A";
216
+		} else {
217
+			foreach ($options as $option) {
218
+				$optionNames[] = $option->value();
219
+			}
220
+			$content = implode(', ', $optionNames);
221
+		}
222
+		return $this->columnContent('values', $content);
223
+	}
224
+
225
+
226
+	public function column_type(EE_Question $item): string
227
+	{
228
+		return $this->columnContent('type', $item->type());
229
+	}
230
+
231
+
232
+	public function column_required(EE_Question $item): string
233
+	{
234
+		$content = $item->required() ? 'Yes' : '';
235
+		return $this->columnContent('required', $content);
236
+	}
237 237
 }
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Attendee_Contact_List_Table.class.php 1 patch
Indentation   +386 added lines, -386 removed lines patch added patch discarded remove patch
@@ -12,412 +12,412 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Attendee_Contact_List_Table extends EE_Admin_List_Table
14 14
 {
15
-    /**
16
-     * @var Registrations_Admin_Page
17
-     */
18
-    protected $_admin_page;
19
-
20
-
21
-    /**
22
-     * Initial setup of data (called by parent).
23
-     *
24
-     * @throws EE_Error
25
-     */
26
-    protected function _setup_data()
27
-    {
28
-        $this->_data = $this->_view !== 'trash'
29
-            ? $this->_admin_page->get_attendees($this->_per_page)
30
-            : $this->_admin_page->get_attendees($this->_per_page, false, true);
31
-
32
-        $this->_all_data_count = $this->_view !== 'trash'
33
-            ? $this->_admin_page->get_attendees($this->_per_page, true)
34
-            : $this->_admin_page->get_attendees($this->_per_page, true, true);
35
-    }
36
-
37
-
38
-    /**
39
-     * Initial setup of properties.
40
-     */
41
-    protected function _set_properties()
42
-    {
43
-        $this->_wp_list_args = [
44
-            'singular' => esc_html__('attendee', 'event_espresso'),
45
-            'plural'   => esc_html__('attendees', 'event_espresso'),
46
-            'ajax'     => true,
47
-            'screen'   => $this->_admin_page->get_current_screen()->id,
48
-        ];
49
-
50
-        $this->_columns = [
51
-            'cb'                 => '<input type="checkbox" />', // Render a checkbox instead of text
52
-            'id'                 => esc_html__('ID', 'event_espresso'),
53
-            'ATT_fname'          => esc_html__('First Name', 'event_espresso'),
54
-            'ATT_lname'          => esc_html__('Last Name', 'event_espresso'),
55
-            'ATT_email'          => esc_html__('Email Address', 'event_espresso'),
56
-            'Registration_Count' => esc_html__('# Reg', 'event_espresso'),
57
-            'ATT_phone'          => esc_html__('Phone', 'event_espresso'),
58
-            'ATT_address'        => esc_html__('Address', 'event_espresso'),
59
-            'ATT_city'           => esc_html__('City', 'event_espresso'),
60
-            'STA_ID'             => esc_html__('State/Province', 'event_espresso'),
61
-            'CNT_ISO'            => esc_html__('Country', 'event_espresso'),
62
-        ];
63
-
64
-        $this->_sortable_columns = [
65
-            'id'                 => ['id' => false],
66
-            'ATT_lname'          => ['ATT_lname' => true], // true means its already sorted
67
-            'ATT_fname'          => ['ATT_fname' => false],
68
-            'ATT_email'          => ['ATT_email' => false],
69
-            'Registration_Count' => ['Registration_Count' => false],
70
-            'ATT_city'           => ['ATT_city' => false],
71
-            'STA_ID'             => ['STA_ID' => false],
72
-            'CNT_ISO'            => ['CNT_ISO' => false],
73
-        ];
74
-
75
-        $this->_hidden_columns = [
76
-            'ATT_phone',
77
-            'ATT_address',
78
-            'ATT_city',
79
-            'STA_ID',
80
-            'CNT_ISO',
81
-        ];
82
-    }
83
-
84
-
85
-    /**
86
-     * Initial setup of filters
87
-     *
88
-     * @return array
89
-     */
90
-    protected function _get_table_filters()
91
-    {
92
-        return [];
93
-    }
94
-
95
-
96
-    /**
97
-     * Initial setup of counts for views
98
-     *
99
-     * @throws InvalidArgumentException
100
-     * @throws InvalidDataTypeException
101
-     * @throws InvalidInterfaceException
102
-     * @throws EE_Error
103
-     * @throws EE_Error
104
-     */
105
-    protected function _add_view_counts()
106
-    {
107
-        $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true);
108
-        if (
109
-            EE_Registry::instance()->CAP->current_user_can(
110
-                'ee_delete_contacts',
111
-                'espresso_registrations_delete_registration'
112
-            )
113
-        ) {
114
-            $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true);
115
-        }
116
-    }
117
-
118
-
119
-    /**
120
-     * Get count of attendees.
121
-     *
122
-     * @return int
123
-     * @throws EE_Error
124
-     * @throws InvalidArgumentException
125
-     * @throws InvalidDataTypeException
126
-     * @throws InvalidInterfaceException
127
-     * @throws ReflectionException
128
-     */
129
-    protected function _get_attendees_count(): int
130
-    {
131
-        return EEM_Attendee::instance()->count();
132
-    }
133
-
134
-
135
-    /**
136
-     * Checkbox column
137
-     *
138
-     * @param EE_Attendee $item Unable to typehint this method because overrides parent.
139
-     * @return string
140
-     * @throws EE_Error
141
-     * @throws ReflectionException
142
-     */
143
-    public function column_cb($item): string
144
-    {
145
-        if (! $item instanceof EE_Attendee) {
146
-            return '';
147
-        }
148
-        return sprintf(
149
-            '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
150
-            $item->ID()
151
-        );
152
-    }
153
-
154
-
155
-    /**
156
-     * @param EE_Attendee|null $attendee
157
-     * @return string
158
-     * @throws EE_Error
159
-     * @throws ReflectionException
160
-     */
161
-    public function column_id(?EE_Attendee $attendee): string
162
-    {
163
-        $content = '
15
+	/**
16
+	 * @var Registrations_Admin_Page
17
+	 */
18
+	protected $_admin_page;
19
+
20
+
21
+	/**
22
+	 * Initial setup of data (called by parent).
23
+	 *
24
+	 * @throws EE_Error
25
+	 */
26
+	protected function _setup_data()
27
+	{
28
+		$this->_data = $this->_view !== 'trash'
29
+			? $this->_admin_page->get_attendees($this->_per_page)
30
+			: $this->_admin_page->get_attendees($this->_per_page, false, true);
31
+
32
+		$this->_all_data_count = $this->_view !== 'trash'
33
+			? $this->_admin_page->get_attendees($this->_per_page, true)
34
+			: $this->_admin_page->get_attendees($this->_per_page, true, true);
35
+	}
36
+
37
+
38
+	/**
39
+	 * Initial setup of properties.
40
+	 */
41
+	protected function _set_properties()
42
+	{
43
+		$this->_wp_list_args = [
44
+			'singular' => esc_html__('attendee', 'event_espresso'),
45
+			'plural'   => esc_html__('attendees', 'event_espresso'),
46
+			'ajax'     => true,
47
+			'screen'   => $this->_admin_page->get_current_screen()->id,
48
+		];
49
+
50
+		$this->_columns = [
51
+			'cb'                 => '<input type="checkbox" />', // Render a checkbox instead of text
52
+			'id'                 => esc_html__('ID', 'event_espresso'),
53
+			'ATT_fname'          => esc_html__('First Name', 'event_espresso'),
54
+			'ATT_lname'          => esc_html__('Last Name', 'event_espresso'),
55
+			'ATT_email'          => esc_html__('Email Address', 'event_espresso'),
56
+			'Registration_Count' => esc_html__('# Reg', 'event_espresso'),
57
+			'ATT_phone'          => esc_html__('Phone', 'event_espresso'),
58
+			'ATT_address'        => esc_html__('Address', 'event_espresso'),
59
+			'ATT_city'           => esc_html__('City', 'event_espresso'),
60
+			'STA_ID'             => esc_html__('State/Province', 'event_espresso'),
61
+			'CNT_ISO'            => esc_html__('Country', 'event_espresso'),
62
+		];
63
+
64
+		$this->_sortable_columns = [
65
+			'id'                 => ['id' => false],
66
+			'ATT_lname'          => ['ATT_lname' => true], // true means its already sorted
67
+			'ATT_fname'          => ['ATT_fname' => false],
68
+			'ATT_email'          => ['ATT_email' => false],
69
+			'Registration_Count' => ['Registration_Count' => false],
70
+			'ATT_city'           => ['ATT_city' => false],
71
+			'STA_ID'             => ['STA_ID' => false],
72
+			'CNT_ISO'            => ['CNT_ISO' => false],
73
+		];
74
+
75
+		$this->_hidden_columns = [
76
+			'ATT_phone',
77
+			'ATT_address',
78
+			'ATT_city',
79
+			'STA_ID',
80
+			'CNT_ISO',
81
+		];
82
+	}
83
+
84
+
85
+	/**
86
+	 * Initial setup of filters
87
+	 *
88
+	 * @return array
89
+	 */
90
+	protected function _get_table_filters()
91
+	{
92
+		return [];
93
+	}
94
+
95
+
96
+	/**
97
+	 * Initial setup of counts for views
98
+	 *
99
+	 * @throws InvalidArgumentException
100
+	 * @throws InvalidDataTypeException
101
+	 * @throws InvalidInterfaceException
102
+	 * @throws EE_Error
103
+	 * @throws EE_Error
104
+	 */
105
+	protected function _add_view_counts()
106
+	{
107
+		$this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true);
108
+		if (
109
+			EE_Registry::instance()->CAP->current_user_can(
110
+				'ee_delete_contacts',
111
+				'espresso_registrations_delete_registration'
112
+			)
113
+		) {
114
+			$this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true);
115
+		}
116
+	}
117
+
118
+
119
+	/**
120
+	 * Get count of attendees.
121
+	 *
122
+	 * @return int
123
+	 * @throws EE_Error
124
+	 * @throws InvalidArgumentException
125
+	 * @throws InvalidDataTypeException
126
+	 * @throws InvalidInterfaceException
127
+	 * @throws ReflectionException
128
+	 */
129
+	protected function _get_attendees_count(): int
130
+	{
131
+		return EEM_Attendee::instance()->count();
132
+	}
133
+
134
+
135
+	/**
136
+	 * Checkbox column
137
+	 *
138
+	 * @param EE_Attendee $item Unable to typehint this method because overrides parent.
139
+	 * @return string
140
+	 * @throws EE_Error
141
+	 * @throws ReflectionException
142
+	 */
143
+	public function column_cb($item): string
144
+	{
145
+		if (! $item instanceof EE_Attendee) {
146
+			return '';
147
+		}
148
+		return sprintf(
149
+			'<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
150
+			$item->ID()
151
+		);
152
+	}
153
+
154
+
155
+	/**
156
+	 * @param EE_Attendee|null $attendee
157
+	 * @return string
158
+	 * @throws EE_Error
159
+	 * @throws ReflectionException
160
+	 */
161
+	public function column_id(?EE_Attendee $attendee): string
162
+	{
163
+		$content = '
164 164
             <span class="ee-entity-id">' . $attendee->ID() . '</span>
165 165
             <span class="show-on-mobile-view-only">
166 166
                 ' . $this->editAttendeeLink($attendee->ID(), $attendee->full_name()) . '
167 167
             </span>';
168
-        return $this->columnContent('id', $content, 'end');
169
-    }
170
-
171
-
172
-    /**
173
-     * ATT_lname column
174
-     *
175
-     * @param EE_Attendee $attendee
176
-     * @return string
177
-     * @throws EE_Error
178
-     * @throws ReflectionException
179
-     */
180
-    public function column_ATT_lname(EE_Attendee $attendee): string
181
-    {
182
-        // edit attendee link
183
-        $content = $this->editAttendeeLink($attendee->ID(), $attendee->lname());
184
-        return $this->columnContent('ATT_lname', $content);
185
-    }
186
-
187
-
188
-    /**
189
-     * @param int    $ID
190
-     * @param string $attendee_name
191
-     * @return string
192
-     * @since   $VID:$
193
-     */
194
-    private function editAttendeeLink(int $ID, string $attendee_name): string
195
-    {
196
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
197
-            [
198
-                'action' => 'edit_attendee',
199
-                'post'   => $ID,
200
-            ],
201
-            REG_ADMIN_URL
202
-        );
203
-        return EE_Registry::instance()->CAP->current_user_can(
204
-            'ee_edit_contacts',
205
-            'espresso_registrations_edit_attendee'
206
-        )
207
-            ? '
168
+		return $this->columnContent('id', $content, 'end');
169
+	}
170
+
171
+
172
+	/**
173
+	 * ATT_lname column
174
+	 *
175
+	 * @param EE_Attendee $attendee
176
+	 * @return string
177
+	 * @throws EE_Error
178
+	 * @throws ReflectionException
179
+	 */
180
+	public function column_ATT_lname(EE_Attendee $attendee): string
181
+	{
182
+		// edit attendee link
183
+		$content = $this->editAttendeeLink($attendee->ID(), $attendee->lname());
184
+		return $this->columnContent('ATT_lname', $content);
185
+	}
186
+
187
+
188
+	/**
189
+	 * @param int    $ID
190
+	 * @param string $attendee_name
191
+	 * @return string
192
+	 * @since   $VID:$
193
+	 */
194
+	private function editAttendeeLink(int $ID, string $attendee_name): string
195
+	{
196
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
197
+			[
198
+				'action' => 'edit_attendee',
199
+				'post'   => $ID,
200
+			],
201
+			REG_ADMIN_URL
202
+		);
203
+		return EE_Registry::instance()->CAP->current_user_can(
204
+			'ee_edit_contacts',
205
+			'espresso_registrations_edit_attendee'
206
+		)
207
+			? '
208 208
             <a  href="' . $edit_lnk_url . '"
209 209
                 class="ee-aria-tooltip"
210 210
                 aria-label="' . esc_attr__('Edit Contact', 'event_espresso') . '"
211 211
             >
212 212
                 ' . $attendee_name . '
213 213
             </a>'
214
-            : $attendee_name;
215
-    }
216
-
217
-
218
-    /**
219
-     * ATT_fname column
220
-     *
221
-     * @param EE_Attendee $attendee
222
-     * @return string
223
-     * @throws InvalidArgumentException
224
-     * @throws InvalidDataTypeException
225
-     * @throws InvalidInterfaceException
226
-     * @throws EE_Error
227
-     * @throws ReflectionException
228
-     * @throws ReflectionException
229
-     * @throws ReflectionException
230
-     * @throws ReflectionException
231
-     */
232
-    public function column_ATT_fname(EE_Attendee $attendee): string
233
-    {
234
-        // Build row actions
235
-        $actions = [];
236
-        // edit attendee link
237
-        if (
238
-            EE_Registry::instance()->CAP->current_user_can(
239
-                'ee_edit_contacts',
240
-                'espresso_registrations_edit_attendee'
241
-            )
242
-        ) {
243
-            $actions['edit'] = $this->editAttendeeLink(
244
-                $attendee->ID(),
245
-                esc_html__('Edit Contact', 'event_espresso')
246
-            );
247
-        }
248
-
249
-        if ($this->_view === 'in_use') {
250
-            // trash attendee link
251
-            if (
252
-                EE_Registry::instance()->CAP->current_user_can(
253
-                    'ee_delete_contacts',
254
-                    'espresso_registrations_trash_attendees'
255
-                )
256
-            ) {
257
-                $trash_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
258
-                    [
259
-                        'action' => 'trash_attendee',
260
-                        'ATT_ID' => $attendee->ID(),
261
-                    ],
262
-                    REG_ADMIN_URL
263
-                );
264
-                $actions['trash'] = '
214
+			: $attendee_name;
215
+	}
216
+
217
+
218
+	/**
219
+	 * ATT_fname column
220
+	 *
221
+	 * @param EE_Attendee $attendee
222
+	 * @return string
223
+	 * @throws InvalidArgumentException
224
+	 * @throws InvalidDataTypeException
225
+	 * @throws InvalidInterfaceException
226
+	 * @throws EE_Error
227
+	 * @throws ReflectionException
228
+	 * @throws ReflectionException
229
+	 * @throws ReflectionException
230
+	 * @throws ReflectionException
231
+	 */
232
+	public function column_ATT_fname(EE_Attendee $attendee): string
233
+	{
234
+		// Build row actions
235
+		$actions = [];
236
+		// edit attendee link
237
+		if (
238
+			EE_Registry::instance()->CAP->current_user_can(
239
+				'ee_edit_contacts',
240
+				'espresso_registrations_edit_attendee'
241
+			)
242
+		) {
243
+			$actions['edit'] = $this->editAttendeeLink(
244
+				$attendee->ID(),
245
+				esc_html__('Edit Contact', 'event_espresso')
246
+			);
247
+		}
248
+
249
+		if ($this->_view === 'in_use') {
250
+			// trash attendee link
251
+			if (
252
+				EE_Registry::instance()->CAP->current_user_can(
253
+					'ee_delete_contacts',
254
+					'espresso_registrations_trash_attendees'
255
+				)
256
+			) {
257
+				$trash_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
258
+					[
259
+						'action' => 'trash_attendee',
260
+						'ATT_ID' => $attendee->ID(),
261
+					],
262
+					REG_ADMIN_URL
263
+				);
264
+				$actions['trash'] = '
265 265
                     <a  href="' . $trash_lnk_url . '"
266 266
                         class="ee-aria-tooltip"
267 267
                         aria-label="' . esc_attr__('Move Contact to Trash', 'event_espresso') . '"
268 268
                     >
269 269
                         ' . esc_html__('Trash', 'event_espresso') . '
270 270
                     </a>';
271
-            }
272
-        } else {
273
-            if (
274
-                EE_Registry::instance()->CAP->current_user_can(
275
-                    'ee_delete_contacts',
276
-                    'espresso_registrations_restore_attendees'
277
-                )
278
-            ) {
279
-                // restore attendee link
280
-                $restore_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
281
-                    [
282
-                        'action' => 'restore_attendees',
283
-                        'ATT_ID' => $attendee->ID(),
284
-                    ],
285
-                    REG_ADMIN_URL
286
-                );
287
-                $actions['restore'] = '
271
+			}
272
+		} else {
273
+			if (
274
+				EE_Registry::instance()->CAP->current_user_can(
275
+					'ee_delete_contacts',
276
+					'espresso_registrations_restore_attendees'
277
+				)
278
+			) {
279
+				// restore attendee link
280
+				$restore_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
281
+					[
282
+						'action' => 'restore_attendees',
283
+						'ATT_ID' => $attendee->ID(),
284
+					],
285
+					REG_ADMIN_URL
286
+				);
287
+				$actions['restore'] = '
288 288
                     <a  href="' . $restore_lnk_url . '"
289 289
                         class="ee-aria-tooltip"
290 290
                         aria-label="' . esc_attr__('Restore Contact', 'event_espresso') . '"
291 291
                     >
292 292
                         ' . esc_html__('Restore', 'event_espresso') . '
293 293
                     </a>';
294
-            }
295
-        }
296
-
297
-        $name_link    = $this->editAttendeeLink($attendee->ID(), $attendee->fname());
298
-
299
-        // Return the name contents
300
-        $content = sprintf('%1$s %2$s', $name_link, $this->row_actions($actions));
301
-        return $this->columnContent('ATT_fname', $content);
302
-    }
303
-
304
-
305
-    /**
306
-     * Email Column
307
-     *
308
-     * @param EE_Attendee $attendee
309
-     * @return string
310
-     * @throws EE_Error
311
-     */
312
-    public function column_ATT_email(EE_Attendee $attendee): string
313
-    {
314
-        $content = '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
315
-        return $this->columnContent('ATT_email', $content);
316
-    }
317
-
318
-
319
-    /**
320
-     * Column displaying count of registrations attached to Attendee.
321
-     *
322
-     * @param EE_Attendee $attendee
323
-     * @return string
324
-     * @throws EE_Error
325
-     * @throws ReflectionException
326
-     */
327
-    public function column_Registration_Count(EE_Attendee $attendee): string
328
-    {
329
-        $link = EEH_URL::add_query_args_and_nonce(
330
-            [
331
-                'action' => 'default',
332
-                'ATT_ID' => $attendee->ID(),
333
-            ],
334
-            REG_ADMIN_URL
335
-        );
336
-        $content = '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
337
-        return $this->columnContent('Registration_Count', $content, 'end');
338
-    }
339
-
340
-
341
-    /**
342
-     * ATT_address column
343
-     *
344
-     * @param EE_Attendee $attendee
345
-     * @return string
346
-     * @throws EE_Error
347
-     */
348
-    public function column_ATT_address(EE_Attendee $attendee): string
349
-    {
350
-        return $this->columnContent('ATT_address', $attendee->address());
351
-    }
352
-
353
-
354
-    /**
355
-     * ATT_city column
356
-     *
357
-     * @param EE_Attendee $attendee
358
-     * @return string
359
-     * @throws EE_Error
360
-     */
361
-    public function column_ATT_city(EE_Attendee $attendee): string
362
-    {
363
-        return $this->columnContent('ATT_city', $attendee->city());
364
-    }
365
-
366
-
367
-    /**
368
-     * State Column
369
-     *
370
-     * @param EE_Attendee $attendee
371
-     * @return string
372
-     * @throws EE_Error
373
-     * @throws InvalidArgumentException
374
-     * @throws InvalidDataTypeException
375
-     * @throws InvalidInterfaceException
376
-     * @throws ReflectionException
377
-     */
378
-    public function column_STA_ID(EE_Attendee $attendee): string
379
-    {
380
-        $states = EEM_State::instance()->get_all_states();
381
-        $state  = isset($states[ $attendee->state_ID() ])
382
-            ? $states[ $attendee->state_ID() ]->get('STA_name')
383
-            : $attendee->state_ID();
384
-        $content = ! is_numeric($state) ? $state : '';
385
-        return $this->columnContent('STA_ID', $content);
386
-    }
387
-
388
-
389
-    /**
390
-     * Country Column
391
-     *
392
-     * @param EE_Attendee $attendee
393
-     * @return string
394
-     * @throws EE_Error
395
-     * @throws InvalidArgumentException
396
-     * @throws InvalidDataTypeException
397
-     * @throws InvalidInterfaceException
398
-     * @throws ReflectionException
399
-     * @throws ReflectionException
400
-     */
401
-    public function column_CNT_ISO(EE_Attendee $attendee): string
402
-    {
403
-        $countries = EEM_Country::instance()->get_all_countries();
404
-        $country   = isset($countries[ $attendee->country_ID() ])
405
-            ? $countries[ $attendee->country_ID() ]->get('CNT_name')
406
-            : $attendee->country_ID();
407
-        $content = ! is_numeric($country) ? $country : '';
408
-        return $this->columnContent('CNT_ISO', $content);
409
-    }
410
-
411
-
412
-    /**
413
-     * Phone Number column
414
-     *
415
-     * @param EE_Attendee $attendee
416
-     * @return string
417
-     * @throws EE_Error
418
-     */
419
-    public function column_ATT_phone(EE_Attendee $attendee): string
420
-    {
421
-        return $this->columnContent('ATT_phone', $attendee->phone());
422
-    }
294
+			}
295
+		}
296
+
297
+		$name_link    = $this->editAttendeeLink($attendee->ID(), $attendee->fname());
298
+
299
+		// Return the name contents
300
+		$content = sprintf('%1$s %2$s', $name_link, $this->row_actions($actions));
301
+		return $this->columnContent('ATT_fname', $content);
302
+	}
303
+
304
+
305
+	/**
306
+	 * Email Column
307
+	 *
308
+	 * @param EE_Attendee $attendee
309
+	 * @return string
310
+	 * @throws EE_Error
311
+	 */
312
+	public function column_ATT_email(EE_Attendee $attendee): string
313
+	{
314
+		$content = '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
315
+		return $this->columnContent('ATT_email', $content);
316
+	}
317
+
318
+
319
+	/**
320
+	 * Column displaying count of registrations attached to Attendee.
321
+	 *
322
+	 * @param EE_Attendee $attendee
323
+	 * @return string
324
+	 * @throws EE_Error
325
+	 * @throws ReflectionException
326
+	 */
327
+	public function column_Registration_Count(EE_Attendee $attendee): string
328
+	{
329
+		$link = EEH_URL::add_query_args_and_nonce(
330
+			[
331
+				'action' => 'default',
332
+				'ATT_ID' => $attendee->ID(),
333
+			],
334
+			REG_ADMIN_URL
335
+		);
336
+		$content = '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
337
+		return $this->columnContent('Registration_Count', $content, 'end');
338
+	}
339
+
340
+
341
+	/**
342
+	 * ATT_address column
343
+	 *
344
+	 * @param EE_Attendee $attendee
345
+	 * @return string
346
+	 * @throws EE_Error
347
+	 */
348
+	public function column_ATT_address(EE_Attendee $attendee): string
349
+	{
350
+		return $this->columnContent('ATT_address', $attendee->address());
351
+	}
352
+
353
+
354
+	/**
355
+	 * ATT_city column
356
+	 *
357
+	 * @param EE_Attendee $attendee
358
+	 * @return string
359
+	 * @throws EE_Error
360
+	 */
361
+	public function column_ATT_city(EE_Attendee $attendee): string
362
+	{
363
+		return $this->columnContent('ATT_city', $attendee->city());
364
+	}
365
+
366
+
367
+	/**
368
+	 * State Column
369
+	 *
370
+	 * @param EE_Attendee $attendee
371
+	 * @return string
372
+	 * @throws EE_Error
373
+	 * @throws InvalidArgumentException
374
+	 * @throws InvalidDataTypeException
375
+	 * @throws InvalidInterfaceException
376
+	 * @throws ReflectionException
377
+	 */
378
+	public function column_STA_ID(EE_Attendee $attendee): string
379
+	{
380
+		$states = EEM_State::instance()->get_all_states();
381
+		$state  = isset($states[ $attendee->state_ID() ])
382
+			? $states[ $attendee->state_ID() ]->get('STA_name')
383
+			: $attendee->state_ID();
384
+		$content = ! is_numeric($state) ? $state : '';
385
+		return $this->columnContent('STA_ID', $content);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Country Column
391
+	 *
392
+	 * @param EE_Attendee $attendee
393
+	 * @return string
394
+	 * @throws EE_Error
395
+	 * @throws InvalidArgumentException
396
+	 * @throws InvalidDataTypeException
397
+	 * @throws InvalidInterfaceException
398
+	 * @throws ReflectionException
399
+	 * @throws ReflectionException
400
+	 */
401
+	public function column_CNT_ISO(EE_Attendee $attendee): string
402
+	{
403
+		$countries = EEM_Country::instance()->get_all_countries();
404
+		$country   = isset($countries[ $attendee->country_ID() ])
405
+			? $countries[ $attendee->country_ID() ]->get('CNT_name')
406
+			: $attendee->country_ID();
407
+		$content = ! is_numeric($country) ? $country : '';
408
+		return $this->columnContent('CNT_ISO', $content);
409
+	}
410
+
411
+
412
+	/**
413
+	 * Phone Number column
414
+	 *
415
+	 * @param EE_Attendee $attendee
416
+	 * @return string
417
+	 * @throws EE_Error
418
+	 */
419
+	public function column_ATT_phone(EE_Attendee $attendee): string
420
+	{
421
+		return $this->columnContent('ATT_phone', $attendee->phone());
422
+	}
423 423
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_List_Table.core.php 1 patch
Indentation   +946 added lines, -946 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\request\sanitizers\AllowedTags;
6 6
 
7 7
 if (! class_exists('WP_List_Table')) {
8
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
8
+	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9 9
 }
10 10
 
11 11
 
@@ -23,928 +23,928 @@  discard block
 block discarded – undo
23 23
  */
24 24
 abstract class EE_Admin_List_Table extends WP_List_Table
25 25
 {
26
-    const ACTION_COPY    = 'duplicate';
27
-
28
-    const ACTION_DELETE  = 'delete';
29
-
30
-    const ACTION_EDIT    = 'edit';
31
-
32
-    const ACTION_RESTORE = 'restore';
33
-
34
-    const ACTION_TRASH   = 'trash';
35
-
36
-    protected static $actions = [
37
-        self::ACTION_COPY,
38
-        self::ACTION_DELETE,
39
-        self::ACTION_EDIT,
40
-        self::ACTION_RESTORE,
41
-        self::ACTION_TRASH,
42
-    ];
43
-
44
-    /**
45
-     * holds the data that will be processed for the table
46
-     *
47
-     * @var array $_data
48
-     */
49
-    protected $_data;
50
-
51
-
52
-    /**
53
-     * This holds the value of all the data available for the given view (for all pages).
54
-     *
55
-     * @var int $_all_data_count
56
-     */
57
-    protected $_all_data_count;
58
-
59
-
60
-    /**
61
-     * Will contain the count of trashed items for the view label.
62
-     *
63
-     * @var int $_trashed_count
64
-     */
65
-    protected $_trashed_count;
66
-
67
-
68
-    /**
69
-     * This is what will be referenced as the slug for the current screen
70
-     *
71
-     * @var string $_screen
72
-     */
73
-    protected $_screen;
74
-
75
-
76
-    /**
77
-     * this is the EE_Admin_Page object
78
-     *
79
-     * @var EE_Admin_Page $_admin_page
80
-     */
81
-    protected $_admin_page;
82
-
83
-
84
-    /**
85
-     * The current view
86
-     *
87
-     * @var string $_view
88
-     */
89
-    protected $_view;
90
-
91
-
92
-    /**
93
-     * array of possible views for this table
94
-     *
95
-     * @var array $_views
96
-     */
97
-    protected $_views;
98
-
99
-
100
-    /**
101
-     * An array of key => value pairs containing information about the current table
102
-     * array(
103
-     *        'plural' => 'plural label',
104
-     *        'singular' => 'singular label',
105
-     *        'ajax' => false, //whether to use ajax or not
106
-     *        'screen' => null, //string used to reference what screen this is
107
-     *        (WP_List_table converts to screen object)
108
-     * )
109
-     *
110
-     * @var array $_wp_list_args
111
-     */
112
-    protected $_wp_list_args;
113
-
114
-    /**
115
-     * an array of column names
116
-     * array(
117
-     *    'internal-name' => 'Title'
118
-     * )
119
-     *
120
-     * @var array $_columns
121
-     */
122
-    protected $_columns;
123
-
124
-    /**
125
-     * An array of sortable columns
126
-     * array(
127
-     *    'internal-name' => 'orderby' //or
128
-     *    'internal-name' => array( 'orderby', true )
129
-     * )
130
-     *
131
-     * @var array $_sortable_columns
132
-     */
133
-    protected $_sortable_columns;
134
-
135
-    /**
136
-     * callback method used to perform AJAX row reordering
137
-     *
138
-     * @var string $_ajax_sorting_callback
139
-     */
140
-    protected $_ajax_sorting_callback;
141
-
142
-    /**
143
-     * An array of hidden columns (if needed)
144
-     * array('internal-name', 'internal-name')
145
-     *
146
-     * @var array $_hidden_columns
147
-     */
148
-    protected $_hidden_columns;
149
-
150
-    /**
151
-     * holds the per_page value
152
-     *
153
-     * @var int $_per_page
154
-     */
155
-    protected $_per_page;
156
-
157
-    /**
158
-     * holds what page number is currently being viewed
159
-     *
160
-     * @var int $_current_page
161
-     */
162
-    protected $_current_page;
163
-
164
-    /**
165
-     * the reference string for the nonce_action
166
-     *
167
-     * @var string $_nonce_action_ref
168
-     */
169
-    protected $_nonce_action_ref;
170
-
171
-    /**
172
-     * property to hold incoming request data (as set by the admin_page_core)
173
-     *
174
-     * @var array $_req_data
175
-     */
176
-    protected $_req_data;
177
-
178
-
179
-    /**
180
-     * yes / no array for admin form fields
181
-     *
182
-     * @var array $_yes_no
183
-     */
184
-    protected $_yes_no = [];
185
-
186
-    /**
187
-     * Array describing buttons that should appear at the bottom of the page
188
-     * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
189
-     * and the values are another array with the following keys
190
-     * array(
191
-     *    'route' => 'page_route',
192
-     *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
193
-     * )
194
-     *
195
-     * @var array $_bottom_buttons
196
-     */
197
-    protected $_bottom_buttons = [];
198
-
199
-
200
-    /**
201
-     * Used to indicate what should be the primary column for the list table.
202
-     * If not present then falls back to what WP calculates
203
-     * as the primary column.
204
-     *
205
-     * @type string $_primary_column
206
-     */
207
-    protected $_primary_column = '';
208
-
209
-
210
-    /**
211
-     * Used to indicate whether the table has a checkbox column or not.
212
-     *
213
-     * @type bool $_has_checkbox_column
214
-     */
215
-    protected $_has_checkbox_column = false;
216
-
217
-    /**
218
-     * @var AdminListTableFilters|null
219
-     */
220
-    protected ?AdminListTableFilters $admin_list_table_filters = null;
221
-
222
-
223
-    /**
224
-     * @param EE_Admin_Page              $admin_page we use this for obtaining everything we need in the list table
225
-     * @param AdminListTableFilters|null $filters    to display list table filters
226
-     */
227
-    public function __construct(EE_Admin_Page $admin_page, ?AdminListTableFilters $filters = null)
228
-    {
229
-        $this->_admin_page   = $admin_page;
230
-        $this->_req_data     = $this->_admin_page->get_request_data();
231
-        $this->_view         = $this->_admin_page->get_view();
232
-        $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
233
-        $this->_current_page = $this->get_pagenum();
234
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
235
-        $this->_yes_no       = [
236
-            esc_html__('No', 'event_espresso'),
237
-            esc_html__('Yes', 'event_espresso')
238
-        ];
239
-
240
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page');
241
-
242
-        $this->admin_list_table_filters = $filters instanceof AdminListTableFilters
243
-            ? $filters
244
-            : LoaderFactory::getShared(AdminListTableFilters::class);
245
-
246
-        $this->_setup_data();
247
-        $this->_add_view_counts();
248
-
249
-        $this->_nonce_action_ref = $this->_view;
250
-
251
-        $this->_set_properties();
252
-
253
-        // set primary column
254
-        add_filter('list_table_primary_column', [$this, 'set_primary_column']);
255
-
256
-        // set parent defaults
257
-        parent::__construct($this->_wp_list_args);
258
-
259
-        $this->prepare_items();
260
-    }
261
-
262
-
263
-    /**
264
-     * _setup_data
265
-     * this method is used to setup the $_data, $_all_data_count, and _per_page properties
266
-     *
267
-     * @return void
268
-     * @uses $this->_admin_page
269
-     */
270
-    abstract protected function _setup_data();
271
-
272
-
273
-    /**
274
-     * set the properties that this class needs to be able to execute wp_list_table properly
275
-     * properties set:
276
-     * _wp_list_args = what the arguments required for the parent _wp_list_table.
277
-     * _columns = set the columns in an array.
278
-     * _sortable_columns = columns that are sortable (array).
279
-     * _hidden_columns = columns that are hidden (array)
280
-     * _default_orderby = the default orderby for sorting.
281
-     *
282
-     * @abstract
283
-     * @access protected
284
-     * @return void
285
-     */
286
-    abstract protected function _set_properties();
287
-
288
-
289
-    /**
290
-     * _get_table_filters
291
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
292
-     * gets shown in the table.
293
-     *
294
-     * @abstract
295
-     * @access protected
296
-     * @return string[]
297
-     */
298
-    abstract protected function _get_table_filters();
299
-
300
-
301
-    /**
302
-     * this is a method that child class will do to add counts to the views array so when views are displayed the
303
-     * counts of the views is accurate.
304
-     *
305
-     * @abstract
306
-     * @access protected
307
-     * @return void
308
-     */
309
-    abstract protected function _add_view_counts();
310
-
311
-
312
-    /**
313
-     * _get_hidden_fields
314
-     * returns a html string of hidden fields so if any table filters are used the current view will be respected.
315
-     *
316
-     * @return string
317
-     */
318
-    protected function _get_hidden_fields()
319
-    {
320
-        $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
321
-        $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
322
-        // if action is STILL empty, then we set it to default
323
-        $action = empty($action) ? 'default' : $action;
324
-        $field  = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n";
325
-        $field  .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n";
326
-        $field  .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n";
327
-
328
-        $bulk_actions = $this->_get_bulk_actions();
329
-        foreach ($bulk_actions as $bulk_action => $label) {
330
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
331
-                      . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
332
-        }
333
-
334
-        return $field;
335
-    }
336
-
337
-
338
-    /**
339
-     * _set_column_info
340
-     * we're using this to set the column headers property.
341
-     *
342
-     * @access protected
343
-     * @return void
344
-     */
345
-    protected function _set_column_info()
346
-    {
347
-        $columns   = $this->get_columns();
348
-        $hidden    = $this->get_hidden_columns();
349
-        $_sortable = $this->get_sortable_columns();
350
-
351
-        /**
352
-         * Dynamic hook allowing for adding sortable columns in this list table.
353
-         * Note that $this->screen->id is in the format
354
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
355
-         * table it is: event-espresso_page_espresso_messages.
356
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
357
-         * hook prefix ("event-espresso") will be different.
358
-         *
359
-         * @var array
360
-         */
361
-        $_sortable = apply_filters(
362
-            "FHEE_manage_{$this->screen->id}_sortable_columns",
363
-            $_sortable,
364
-            $this->_screen,
365
-            $this
366
-        );
367
-
368
-        $sortable = [];
369
-        foreach ($_sortable as $id => $data) {
370
-            if (empty($data)) {
371
-                continue;
372
-            }
373
-            // fix for offset errors with WP_List_Table default get_columninfo()
374
-            if (is_array($data)) {
375
-                $_data[0] = key($data);
376
-                $_data[1] = isset($data[1]) ? $data[1] : false;
377
-            } else {
378
-                $_data[0] = $data;
379
-            }
380
-
381
-            $data = (array) $data;
382
-
383
-            if (! isset($data[1])) {
384
-                $_data[1] = false;
385
-            }
386
-
387
-            $sortable[ $id ] = $_data;
388
-        }
389
-        $primary               = $this->get_primary_column_name();
390
-        $this->_column_headers = [$columns, $hidden, $sortable, $primary];
391
-    }
392
-
393
-
394
-    /**
395
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
396
-     *
397
-     * @return string
398
-     */
399
-    protected function get_primary_column_name()
400
-    {
401
-        foreach (class_parents($this) as $parent) {
402
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
403
-                return parent::get_primary_column_name();
404
-            }
405
-        }
406
-        return $this->_primary_column;
407
-    }
408
-
409
-
410
-    /**
411
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
412
-     *
413
-     * @param EE_Base_Class $item
414
-     * @param string        $column_name
415
-     * @param string        $primary
416
-     * @return string
417
-     */
418
-    protected function handle_row_actions($item, $column_name, $primary)
419
-    {
420
-        foreach (class_parents($this) as $parent) {
421
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
422
-                return parent::handle_row_actions($item, $column_name, $primary);
423
-            }
424
-        }
425
-        return '';
426
-    }
427
-
428
-
429
-    /**
430
-     * _get_bulk_actions
431
-     * This is a wrapper called by WP_List_Table::get_bulk_actions()
432
-     *
433
-     * @access protected
434
-     * @return array bulk_actions
435
-     */
436
-    protected function _get_bulk_actions(): array
437
-    {
438
-        $actions = [];
439
-        // the _views property should have the bulk_actions, so let's go through and extract them into a properly
440
-        // formatted array for the wp_list_table();
441
-        foreach ($this->_views as $view => $args) {
442
-            if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
443
-                // each bulk action will correspond with a admin page route, so we can check whatever the capability is
444
-                // for that page route and skip adding the bulk action if no access for the current logged in user.
445
-                foreach ($args['bulk_action'] as $route => $label) {
446
-                    if ($this->_admin_page->check_user_access($route, true)) {
447
-                        $actions[ $route ] = $label;
448
-                    }
449
-                }
450
-            }
451
-        }
452
-        return $actions;
453
-    }
454
-
455
-
456
-    /**
457
-     * Generate the table navigation above or below the table.
458
-     * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
459
-     *
460
-     * @throws EE_Error
461
-     * @since 4.9.44.rc.001
462
-     */
463
-    public function display_tablenav($which)
464
-    {
465
-        if ('top' === $which) {
466
-            wp_nonce_field('bulk-' . $this->_args['plural']);
467
-        }
468
-        ?>
26
+	const ACTION_COPY    = 'duplicate';
27
+
28
+	const ACTION_DELETE  = 'delete';
29
+
30
+	const ACTION_EDIT    = 'edit';
31
+
32
+	const ACTION_RESTORE = 'restore';
33
+
34
+	const ACTION_TRASH   = 'trash';
35
+
36
+	protected static $actions = [
37
+		self::ACTION_COPY,
38
+		self::ACTION_DELETE,
39
+		self::ACTION_EDIT,
40
+		self::ACTION_RESTORE,
41
+		self::ACTION_TRASH,
42
+	];
43
+
44
+	/**
45
+	 * holds the data that will be processed for the table
46
+	 *
47
+	 * @var array $_data
48
+	 */
49
+	protected $_data;
50
+
51
+
52
+	/**
53
+	 * This holds the value of all the data available for the given view (for all pages).
54
+	 *
55
+	 * @var int $_all_data_count
56
+	 */
57
+	protected $_all_data_count;
58
+
59
+
60
+	/**
61
+	 * Will contain the count of trashed items for the view label.
62
+	 *
63
+	 * @var int $_trashed_count
64
+	 */
65
+	protected $_trashed_count;
66
+
67
+
68
+	/**
69
+	 * This is what will be referenced as the slug for the current screen
70
+	 *
71
+	 * @var string $_screen
72
+	 */
73
+	protected $_screen;
74
+
75
+
76
+	/**
77
+	 * this is the EE_Admin_Page object
78
+	 *
79
+	 * @var EE_Admin_Page $_admin_page
80
+	 */
81
+	protected $_admin_page;
82
+
83
+
84
+	/**
85
+	 * The current view
86
+	 *
87
+	 * @var string $_view
88
+	 */
89
+	protected $_view;
90
+
91
+
92
+	/**
93
+	 * array of possible views for this table
94
+	 *
95
+	 * @var array $_views
96
+	 */
97
+	protected $_views;
98
+
99
+
100
+	/**
101
+	 * An array of key => value pairs containing information about the current table
102
+	 * array(
103
+	 *        'plural' => 'plural label',
104
+	 *        'singular' => 'singular label',
105
+	 *        'ajax' => false, //whether to use ajax or not
106
+	 *        'screen' => null, //string used to reference what screen this is
107
+	 *        (WP_List_table converts to screen object)
108
+	 * )
109
+	 *
110
+	 * @var array $_wp_list_args
111
+	 */
112
+	protected $_wp_list_args;
113
+
114
+	/**
115
+	 * an array of column names
116
+	 * array(
117
+	 *    'internal-name' => 'Title'
118
+	 * )
119
+	 *
120
+	 * @var array $_columns
121
+	 */
122
+	protected $_columns;
123
+
124
+	/**
125
+	 * An array of sortable columns
126
+	 * array(
127
+	 *    'internal-name' => 'orderby' //or
128
+	 *    'internal-name' => array( 'orderby', true )
129
+	 * )
130
+	 *
131
+	 * @var array $_sortable_columns
132
+	 */
133
+	protected $_sortable_columns;
134
+
135
+	/**
136
+	 * callback method used to perform AJAX row reordering
137
+	 *
138
+	 * @var string $_ajax_sorting_callback
139
+	 */
140
+	protected $_ajax_sorting_callback;
141
+
142
+	/**
143
+	 * An array of hidden columns (if needed)
144
+	 * array('internal-name', 'internal-name')
145
+	 *
146
+	 * @var array $_hidden_columns
147
+	 */
148
+	protected $_hidden_columns;
149
+
150
+	/**
151
+	 * holds the per_page value
152
+	 *
153
+	 * @var int $_per_page
154
+	 */
155
+	protected $_per_page;
156
+
157
+	/**
158
+	 * holds what page number is currently being viewed
159
+	 *
160
+	 * @var int $_current_page
161
+	 */
162
+	protected $_current_page;
163
+
164
+	/**
165
+	 * the reference string for the nonce_action
166
+	 *
167
+	 * @var string $_nonce_action_ref
168
+	 */
169
+	protected $_nonce_action_ref;
170
+
171
+	/**
172
+	 * property to hold incoming request data (as set by the admin_page_core)
173
+	 *
174
+	 * @var array $_req_data
175
+	 */
176
+	protected $_req_data;
177
+
178
+
179
+	/**
180
+	 * yes / no array for admin form fields
181
+	 *
182
+	 * @var array $_yes_no
183
+	 */
184
+	protected $_yes_no = [];
185
+
186
+	/**
187
+	 * Array describing buttons that should appear at the bottom of the page
188
+	 * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
189
+	 * and the values are another array with the following keys
190
+	 * array(
191
+	 *    'route' => 'page_route',
192
+	 *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
193
+	 * )
194
+	 *
195
+	 * @var array $_bottom_buttons
196
+	 */
197
+	protected $_bottom_buttons = [];
198
+
199
+
200
+	/**
201
+	 * Used to indicate what should be the primary column for the list table.
202
+	 * If not present then falls back to what WP calculates
203
+	 * as the primary column.
204
+	 *
205
+	 * @type string $_primary_column
206
+	 */
207
+	protected $_primary_column = '';
208
+
209
+
210
+	/**
211
+	 * Used to indicate whether the table has a checkbox column or not.
212
+	 *
213
+	 * @type bool $_has_checkbox_column
214
+	 */
215
+	protected $_has_checkbox_column = false;
216
+
217
+	/**
218
+	 * @var AdminListTableFilters|null
219
+	 */
220
+	protected ?AdminListTableFilters $admin_list_table_filters = null;
221
+
222
+
223
+	/**
224
+	 * @param EE_Admin_Page              $admin_page we use this for obtaining everything we need in the list table
225
+	 * @param AdminListTableFilters|null $filters    to display list table filters
226
+	 */
227
+	public function __construct(EE_Admin_Page $admin_page, ?AdminListTableFilters $filters = null)
228
+	{
229
+		$this->_admin_page   = $admin_page;
230
+		$this->_req_data     = $this->_admin_page->get_request_data();
231
+		$this->_view         = $this->_admin_page->get_view();
232
+		$this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
233
+		$this->_current_page = $this->get_pagenum();
234
+		$this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
235
+		$this->_yes_no       = [
236
+			esc_html__('No', 'event_espresso'),
237
+			esc_html__('Yes', 'event_espresso')
238
+		];
239
+
240
+		$this->_per_page = $this->get_items_per_page($this->_screen . '_per_page');
241
+
242
+		$this->admin_list_table_filters = $filters instanceof AdminListTableFilters
243
+			? $filters
244
+			: LoaderFactory::getShared(AdminListTableFilters::class);
245
+
246
+		$this->_setup_data();
247
+		$this->_add_view_counts();
248
+
249
+		$this->_nonce_action_ref = $this->_view;
250
+
251
+		$this->_set_properties();
252
+
253
+		// set primary column
254
+		add_filter('list_table_primary_column', [$this, 'set_primary_column']);
255
+
256
+		// set parent defaults
257
+		parent::__construct($this->_wp_list_args);
258
+
259
+		$this->prepare_items();
260
+	}
261
+
262
+
263
+	/**
264
+	 * _setup_data
265
+	 * this method is used to setup the $_data, $_all_data_count, and _per_page properties
266
+	 *
267
+	 * @return void
268
+	 * @uses $this->_admin_page
269
+	 */
270
+	abstract protected function _setup_data();
271
+
272
+
273
+	/**
274
+	 * set the properties that this class needs to be able to execute wp_list_table properly
275
+	 * properties set:
276
+	 * _wp_list_args = what the arguments required for the parent _wp_list_table.
277
+	 * _columns = set the columns in an array.
278
+	 * _sortable_columns = columns that are sortable (array).
279
+	 * _hidden_columns = columns that are hidden (array)
280
+	 * _default_orderby = the default orderby for sorting.
281
+	 *
282
+	 * @abstract
283
+	 * @access protected
284
+	 * @return void
285
+	 */
286
+	abstract protected function _set_properties();
287
+
288
+
289
+	/**
290
+	 * _get_table_filters
291
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
292
+	 * gets shown in the table.
293
+	 *
294
+	 * @abstract
295
+	 * @access protected
296
+	 * @return string[]
297
+	 */
298
+	abstract protected function _get_table_filters();
299
+
300
+
301
+	/**
302
+	 * this is a method that child class will do to add counts to the views array so when views are displayed the
303
+	 * counts of the views is accurate.
304
+	 *
305
+	 * @abstract
306
+	 * @access protected
307
+	 * @return void
308
+	 */
309
+	abstract protected function _add_view_counts();
310
+
311
+
312
+	/**
313
+	 * _get_hidden_fields
314
+	 * returns a html string of hidden fields so if any table filters are used the current view will be respected.
315
+	 *
316
+	 * @return string
317
+	 */
318
+	protected function _get_hidden_fields()
319
+	{
320
+		$action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
321
+		$action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
322
+		// if action is STILL empty, then we set it to default
323
+		$action = empty($action) ? 'default' : $action;
324
+		$field  = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n";
325
+		$field  .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n";
326
+		$field  .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n";
327
+
328
+		$bulk_actions = $this->_get_bulk_actions();
329
+		foreach ($bulk_actions as $bulk_action => $label) {
330
+			$field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
331
+					  . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
332
+		}
333
+
334
+		return $field;
335
+	}
336
+
337
+
338
+	/**
339
+	 * _set_column_info
340
+	 * we're using this to set the column headers property.
341
+	 *
342
+	 * @access protected
343
+	 * @return void
344
+	 */
345
+	protected function _set_column_info()
346
+	{
347
+		$columns   = $this->get_columns();
348
+		$hidden    = $this->get_hidden_columns();
349
+		$_sortable = $this->get_sortable_columns();
350
+
351
+		/**
352
+		 * Dynamic hook allowing for adding sortable columns in this list table.
353
+		 * Note that $this->screen->id is in the format
354
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
355
+		 * table it is: event-espresso_page_espresso_messages.
356
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
357
+		 * hook prefix ("event-espresso") will be different.
358
+		 *
359
+		 * @var array
360
+		 */
361
+		$_sortable = apply_filters(
362
+			"FHEE_manage_{$this->screen->id}_sortable_columns",
363
+			$_sortable,
364
+			$this->_screen,
365
+			$this
366
+		);
367
+
368
+		$sortable = [];
369
+		foreach ($_sortable as $id => $data) {
370
+			if (empty($data)) {
371
+				continue;
372
+			}
373
+			// fix for offset errors with WP_List_Table default get_columninfo()
374
+			if (is_array($data)) {
375
+				$_data[0] = key($data);
376
+				$_data[1] = isset($data[1]) ? $data[1] : false;
377
+			} else {
378
+				$_data[0] = $data;
379
+			}
380
+
381
+			$data = (array) $data;
382
+
383
+			if (! isset($data[1])) {
384
+				$_data[1] = false;
385
+			}
386
+
387
+			$sortable[ $id ] = $_data;
388
+		}
389
+		$primary               = $this->get_primary_column_name();
390
+		$this->_column_headers = [$columns, $hidden, $sortable, $primary];
391
+	}
392
+
393
+
394
+	/**
395
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
396
+	 *
397
+	 * @return string
398
+	 */
399
+	protected function get_primary_column_name()
400
+	{
401
+		foreach (class_parents($this) as $parent) {
402
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
403
+				return parent::get_primary_column_name();
404
+			}
405
+		}
406
+		return $this->_primary_column;
407
+	}
408
+
409
+
410
+	/**
411
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
412
+	 *
413
+	 * @param EE_Base_Class $item
414
+	 * @param string        $column_name
415
+	 * @param string        $primary
416
+	 * @return string
417
+	 */
418
+	protected function handle_row_actions($item, $column_name, $primary)
419
+	{
420
+		foreach (class_parents($this) as $parent) {
421
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
422
+				return parent::handle_row_actions($item, $column_name, $primary);
423
+			}
424
+		}
425
+		return '';
426
+	}
427
+
428
+
429
+	/**
430
+	 * _get_bulk_actions
431
+	 * This is a wrapper called by WP_List_Table::get_bulk_actions()
432
+	 *
433
+	 * @access protected
434
+	 * @return array bulk_actions
435
+	 */
436
+	protected function _get_bulk_actions(): array
437
+	{
438
+		$actions = [];
439
+		// the _views property should have the bulk_actions, so let's go through and extract them into a properly
440
+		// formatted array for the wp_list_table();
441
+		foreach ($this->_views as $view => $args) {
442
+			if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
443
+				// each bulk action will correspond with a admin page route, so we can check whatever the capability is
444
+				// for that page route and skip adding the bulk action if no access for the current logged in user.
445
+				foreach ($args['bulk_action'] as $route => $label) {
446
+					if ($this->_admin_page->check_user_access($route, true)) {
447
+						$actions[ $route ] = $label;
448
+					}
449
+				}
450
+			}
451
+		}
452
+		return $actions;
453
+	}
454
+
455
+
456
+	/**
457
+	 * Generate the table navigation above or below the table.
458
+	 * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
459
+	 *
460
+	 * @throws EE_Error
461
+	 * @since 4.9.44.rc.001
462
+	 */
463
+	public function display_tablenav($which)
464
+	{
465
+		if ('top' === $which) {
466
+			wp_nonce_field('bulk-' . $this->_args['plural']);
467
+		}
468
+		?>
469 469
         <div class="tablenav <?php echo esc_attr($which); ?>">
470 470
             <?php if ($this->_get_bulk_actions()) { ?>
471 471
                 <div class="alignleft actions bulkactions">
472 472
                     <?php $this->bulk_actions(); ?>
473 473
                 </div>
474 474
             <?php }
475
-            $this->extra_tablenav($which);
476
-            $this->pagination($which);
477
-            ?>
475
+			$this->extra_tablenav($which);
476
+			$this->pagination($which);
477
+			?>
478 478
 
479 479
             <br class="clear" />
480 480
         </div>
481 481
         <?php
482
-    }
483
-
484
-
485
-    /**
486
-     * _filters
487
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
488
-     * button.
489
-     *
490
-     * @access private
491
-     * @return void  echos html showing filters
492
-     */
493
-    private function _filters(): void
494
-    {
495
-        $classname = get_class($this);
496
-        $filters   = apply_filters(
497
-            "FHEE__{$classname}__filters",
498
-            $this->_get_table_filters(),
499
-            $this,
500
-            $this->_screen
501
-        );
502
-
503
-        if (empty($filters)) {
504
-            return;
505
-        }
506
-
507
-        $this->admin_list_table_filters->filters(
508
-            $filters,
509
-            $this->get_admin_page()->get_current_page_view_url()
510
-        );
511
-    }
512
-
513
-
514
-    /**
515
-     * Callback for 'list_table_primary_column' WordPress filter
516
-     * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
517
-     * column when class is instantiated.
518
-     *
519
-     * @param string $column_name
520
-     * @return string
521
-     * @see WP_List_Table::get_primary_column_name
522
-     */
523
-    public function set_primary_column($column_name)
524
-    {
525
-        return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
526
-    }
527
-
528
-
529
-    /**
530
-     *
531
-     */
532
-    public function prepare_items()
533
-    {
534
-        $this->_set_column_info();
535
-        $this->process_bulk_action();
536
-
537
-        $this->items = $this->_data;
538
-        $this->set_pagination_args(
539
-            [
540
-                'total_items' => $this->_all_data_count,
541
-                'per_page'    => $this->_per_page,
542
-                'total_pages' => (int) ceil($this->_all_data_count / $this->_per_page),
543
-            ]
544
-        );
545
-    }
546
-
547
-
548
-    /**
549
-     * @param object|array $item
550
-     * @return string html content for the column
551
-     */
552
-    protected function column_cb($item)
553
-    {
554
-        return '';
555
-    }
556
-
557
-
558
-    /**
559
-     * This column is the default for when there is no defined column method for a registered column.
560
-     * This can be overridden by child classes, but allows for hooking in for custom columns.
561
-     *
562
-     * @param EE_Base_Class $item
563
-     * @param string        $column_name The column being called.
564
-     * @return string html content for the column
565
-     */
566
-    public function column_default($item, $column_name)
567
-    {
568
-        /**
569
-         * Dynamic hook allowing for adding additional column content in this list table.
570
-         * Note that $this->screen->id is in the format
571
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
572
-         * table it is: event-espresso_page_espresso_messages.
573
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
574
-         * hook prefix ("event-espresso") will be different.
575
-         */
576
-        ob_start();
577
-        do_action(
578
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
579
-            $item,
580
-            $this->_screen
581
-        );
582
-        $content = ob_get_clean();
583
-        return $column_name === 'actions' ? $this->actionsModalMenu($content) : $content;
584
-    }
585
-
586
-
587
-    /**
588
-     * Get a list of columns. The format is:
589
-     * 'internal-name' => 'Title'
590
-     *
591
-     * @return array
592
-     * @since  3.1.0
593
-     * @access public
594
-     * @abstract
595
-     */
596
-    public function get_columns()
597
-    {
598
-        /**
599
-         * Dynamic hook allowing for adding additional columns in this list table.
600
-         * Note that $this->screen->id is in the format
601
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
602
-         * table it is: event-espresso_page_espresso_messages.
603
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
604
-         * hook prefix ("event-espresso") will be different.
605
-         *
606
-         * @var array
607
-         */
608
-        return apply_filters("FHEE_manage_{$this->screen->id}_columns", $this->_columns, $this->_screen, $this);
609
-    }
610
-
611
-
612
-    /**
613
-     * Get an associative array ( id => link ) with the list
614
-     * of views available on this table.
615
-     *
616
-     * @return array
617
-     * @since  3.1.0
618
-     * @access protected
619
-     */
620
-    public function get_views()
621
-    {
622
-        return $this->_views;
623
-    }
624
-
625
-
626
-    /**
627
-     * Generate the views html.
628
-     */
629
-    public function display_views()
630
-    {
631
-        $views           = $this->get_views();
632
-        $assembled_views = [];
633
-
634
-        if (empty($views)) {
635
-            return;
636
-        }
637
-        echo "<ul class='subsubsub'>\n";
638
-        foreach ($views as $view) {
639
-            $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
640
-            if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
641
-                $filter = "<li";
642
-                $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : '';
643
-                $filter .= ">";
644
-                $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>';
645
-                $filter .= '<span class="count">(' . $count . ')</span>';
646
-                $filter .= '</li>';
647
-                $assembled_views[ $view['slug'] ] = $filter;
648
-            }
649
-        }
650
-
651
-        echo ! empty($assembled_views)
652
-            ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views)
653
-            : '';
654
-        echo "</ul>";
655
-    }
656
-
657
-
658
-    /**
659
-     * Generates content for a single row of the table
660
-     *
661
-     * @param EE_Base_Class $item The current item
662
-     * @since  4.1
663
-     * @access public
664
-     */
665
-    public function single_row($item)
666
-    {
667
-        $row_class = $this->_get_row_class($item);
668
-        echo '<tr class="' . esc_attr($row_class) . '">';
669
-        $this->single_row_columns($item); // already escaped
670
-        echo '</tr>';
671
-    }
672
-
673
-
674
-    /**
675
-     * This simply sets up the row class for the table rows.
676
-     * Allows for easier overriding of child methods for setting up sorting.
677
-     *
678
-     * @param EE_Base_Class $item the current item
679
-     * @return string
680
-     */
681
-    protected function _get_row_class($item)
682
-    {
683
-        static $row_class = '';
684
-        $row_class = ($row_class === '' ? 'alternate' : '');
685
-
686
-        $new_row_class = $row_class;
687
-
688
-        if (! empty($this->_ajax_sorting_callback)) {
689
-            $new_row_class .= ' rowsortable';
690
-        }
691
-
692
-        return $new_row_class;
693
-    }
694
-
695
-
696
-    /**
697
-     * @return array
698
-     */
699
-    public function get_sortable_columns()
700
-    {
701
-        return (array) $this->_sortable_columns;
702
-    }
703
-
704
-
705
-    /**
706
-     * @return string
707
-     */
708
-    public function get_ajax_sorting_callback()
709
-    {
710
-        return $this->_ajax_sorting_callback;
711
-    }
712
-
713
-
714
-    /**
715
-     * @return array
716
-     */
717
-    public function get_hidden_columns()
718
-    {
719
-        $user_id     = get_current_user_id();
720
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
721
-        if (empty($has_default) && ! empty($this->_hidden_columns)) {
722
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
723
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
724
-        }
725
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
726
-        return (array) get_user_option($ref, $user_id);
727
-    }
728
-
729
-
730
-    /**
731
-     * Generates the columns for a single row of the table.
732
-     * Overridden from wp_list_table so as to allow us to filter the column content for a given
733
-     * column.
734
-     *
735
-     * @param EE_Base_Class $item The current item
736
-     * @since 3.1.0
737
-     */
738
-    public function single_row_columns($item)
739
-    {
740
-        [$columns, $hidden, $sortable, $primary] = $this->get_column_info();
741
-
742
-        foreach ($columns as $column_name => $column_display_name) {
743
-
744
-            /**
745
-             * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
746
-             * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
747
-             */
748
-            $hidden_class = in_array($column_name, $hidden) ? ' hidden' : '';
749
-
750
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
751
-            if ($primary === $column_name) {
752
-                $classes .= ' has-row-actions column-primary';
753
-            }
754
-
755
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
756
-
757
-            $class = 'class="' . esc_attr($classes) . '"';
758
-
759
-            $attributes = "{$class}{$data}";
760
-
761
-            if ($column_name === 'cb') {
762
-                echo '<th scope="row" class="check-column">';
763
-                echo apply_filters(
764
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
765
-                    $this->column_cb($item), // already escaped
766
-                    $item,
767
-                    $this
768
-                );
769
-                echo '</th>';
770
-            } elseif (method_exists($this, "column_$column_name")) {
771
-                echo "<td $attributes>"; // already escaped
772
-                echo apply_filters(
773
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
774
-                    call_user_func([$this, "column_$column_name"], $item),
775
-                    $item,
776
-                    $this
777
-                );
778
-                echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
779
-                echo "</td>";
780
-            } else {
781
-                echo "<td $attributes>"; // already escaped
782
-                echo apply_filters(
783
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
784
-                    $this->column_default($item, $column_name),
785
-                    $item,
786
-                    $column_name,
787
-                    $this
788
-                );
789
-                echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
790
-                echo "</td>";
791
-            }
792
-        }
793
-    }
794
-
795
-
796
-    /**
797
-     * Extra controls to be displayed between bulk actions and pagination
798
-     *
799
-     * @access public
800
-     * @param string $which
801
-     * @throws EE_Error
802
-     */
803
-    public function extra_tablenav($which)
804
-    {
805
-        if ($which === 'top') {
806
-            $this->_filters();
807
-            echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags());
808
-        } else {
809
-            echo '<div class="list-table-bottom-buttons alignleft actions">';
810
-            foreach ($this->_bottom_buttons as $type => $action) {
811
-                $route         = $action['route'] ?? '';
812
-                $extra_request = $action['extra_request'] ?? '';
813
-                $btn_class     = $action['btn_class'] ?? 'button button--secondary';
814
-                // already escaped
815
-                echo wp_kses($this->_admin_page->get_action_link_or_button(
816
-                    $route,
817
-                    $type,
818
-                    $extra_request,
819
-                    $btn_class
820
-                ), AllowedTags::getWithFormTags());
821
-            }
822
-            do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
823
-            echo '</div>';
824
-        }
825
-    }
826
-
827
-
828
-    /**
829
-     * Get an associative array ( option_name => option_title ) with the list
830
-     * of bulk actions available on this table.
831
-     *
832
-     * @return array
833
-     * @since  3.1.0
834
-     * @access protected
835
-     */
836
-    public function get_bulk_actions()
837
-    {
838
-        return (array) $this->_get_bulk_actions();
839
-    }
840
-
841
-
842
-    /**
843
-     * Processing bulk actions.
844
-     */
845
-    public function process_bulk_action()
846
-    {
847
-        // this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
848
-        // reference in case there is a case where it gets used.
849
-    }
850
-
851
-
852
-    /**
853
-     * returns the EE admin page this list table is associated with
854
-     *
855
-     * @return EE_Admin_Page
856
-     */
857
-    public function get_admin_page()
858
-    {
859
-        return $this->_admin_page;
860
-    }
861
-
862
-
863
-    /**
864
-     * A "helper" function for all children to provide an html string of
865
-     * actions to output in their content.  It is preferable for child classes
866
-     * to use this method for generating their actions content so that it's
867
-     * filterable by plugins
868
-     *
869
-     * @param string        $action_container           what are the html container
870
-     *                                                  elements for this actions string?
871
-     * @param string        $action_class               What class is for the container
872
-     *                                                  element.
873
-     * @param string        $action_items               The contents for the action items
874
-     *                                                  container.  This is filtered before
875
-     *                                                  returned.
876
-     * @param string        $action_id                  What id (optional) is used for the
877
-     *                                                  container element.
878
-     * @param EE_Base_Class $item                       The object for the column displaying
879
-     *                                                  the actions.
880
-     * @return string The assembled action elements container.
881
-     */
882
-    protected function _action_string(
883
-        $action_items,
884
-        $item,
885
-        $action_container = 'ul',
886
-        $action_class = '',
887
-        $action_id = ''
888
-    ) {
889
-        $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : '';
890
-        $action_id    = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : '';
891
-        $open_tag     = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
892
-        $close_tag    = ! empty($action_container) ? '</' . $action_container . '>' : '';
893
-        try {
894
-            $content = apply_filters(
895
-                'FHEE__EE_Admin_List_Table___action_string__action_items',
896
-                $action_items,
897
-                $item,
898
-                $this
899
-            );
900
-        } catch (Exception $e) {
901
-            if (WP_DEBUG) {
902
-                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
903
-            }
904
-            $content = $action_items;
905
-        }
906
-        return "{$open_tag}{$content}{$close_tag}";
907
-    }
908
-
909
-
910
-    /**
911
-     * @return string
912
-     */
913
-    protected function getReturnUrl()
914
-    {
915
-        $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST');
916
-        $uri  = $this->_admin_page->get_request()->getServerParam('REQUEST_URI');
917
-        return urlencode(esc_url_raw("//{$host}{$uri}"));
918
-    }
919
-
920
-
921
-    /**
922
-     * @param string $id
923
-     * @param string $content
924
-     * @param string $align     start (default), center, end
925
-     * @return string
926
-     * @since   $VID:$
927
-     */
928
-    protected function columnContent($id, $content, $align = 'start')
929
-    {
930
-        if (! isset($this->_columns[ $id ])) {
931
-            throw new DomainException('missing column id');
932
-        }
933
-        $heading = $id !== 'cb' ? $this->_columns[ $id ] : '';
934
-        $align = in_array($align, ['start', 'center', 'end']) ? $align : 'start';
935
-        $align = "ee-responsive-table-cell--{$align}";
936
-
937
-        $html = "<div class='ee-responsive-table-cell ee-responsive-table-cell--column-{$id} {$align} ee-layout-row'>";
938
-        $html .= "<div class='ee-responsive-table-cell__heading'>{$heading}</div>";
939
-        $html .= "<div class='ee-responsive-table-cell__content ee-layout-row'>{$content}</div>";
940
-        $html .= "</div>";
941
-        return $html;
942
-    }
943
-
944
-
945
-    protected function actionsModalMenu($actions): string
946
-    {
947
-        return '
482
+	}
483
+
484
+
485
+	/**
486
+	 * _filters
487
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
488
+	 * button.
489
+	 *
490
+	 * @access private
491
+	 * @return void  echos html showing filters
492
+	 */
493
+	private function _filters(): void
494
+	{
495
+		$classname = get_class($this);
496
+		$filters   = apply_filters(
497
+			"FHEE__{$classname}__filters",
498
+			$this->_get_table_filters(),
499
+			$this,
500
+			$this->_screen
501
+		);
502
+
503
+		if (empty($filters)) {
504
+			return;
505
+		}
506
+
507
+		$this->admin_list_table_filters->filters(
508
+			$filters,
509
+			$this->get_admin_page()->get_current_page_view_url()
510
+		);
511
+	}
512
+
513
+
514
+	/**
515
+	 * Callback for 'list_table_primary_column' WordPress filter
516
+	 * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
517
+	 * column when class is instantiated.
518
+	 *
519
+	 * @param string $column_name
520
+	 * @return string
521
+	 * @see WP_List_Table::get_primary_column_name
522
+	 */
523
+	public function set_primary_column($column_name)
524
+	{
525
+		return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
526
+	}
527
+
528
+
529
+	/**
530
+	 *
531
+	 */
532
+	public function prepare_items()
533
+	{
534
+		$this->_set_column_info();
535
+		$this->process_bulk_action();
536
+
537
+		$this->items = $this->_data;
538
+		$this->set_pagination_args(
539
+			[
540
+				'total_items' => $this->_all_data_count,
541
+				'per_page'    => $this->_per_page,
542
+				'total_pages' => (int) ceil($this->_all_data_count / $this->_per_page),
543
+			]
544
+		);
545
+	}
546
+
547
+
548
+	/**
549
+	 * @param object|array $item
550
+	 * @return string html content for the column
551
+	 */
552
+	protected function column_cb($item)
553
+	{
554
+		return '';
555
+	}
556
+
557
+
558
+	/**
559
+	 * This column is the default for when there is no defined column method for a registered column.
560
+	 * This can be overridden by child classes, but allows for hooking in for custom columns.
561
+	 *
562
+	 * @param EE_Base_Class $item
563
+	 * @param string        $column_name The column being called.
564
+	 * @return string html content for the column
565
+	 */
566
+	public function column_default($item, $column_name)
567
+	{
568
+		/**
569
+		 * Dynamic hook allowing for adding additional column content in this list table.
570
+		 * Note that $this->screen->id is in the format
571
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
572
+		 * table it is: event-espresso_page_espresso_messages.
573
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
574
+		 * hook prefix ("event-espresso") will be different.
575
+		 */
576
+		ob_start();
577
+		do_action(
578
+			'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
579
+			$item,
580
+			$this->_screen
581
+		);
582
+		$content = ob_get_clean();
583
+		return $column_name === 'actions' ? $this->actionsModalMenu($content) : $content;
584
+	}
585
+
586
+
587
+	/**
588
+	 * Get a list of columns. The format is:
589
+	 * 'internal-name' => 'Title'
590
+	 *
591
+	 * @return array
592
+	 * @since  3.1.0
593
+	 * @access public
594
+	 * @abstract
595
+	 */
596
+	public function get_columns()
597
+	{
598
+		/**
599
+		 * Dynamic hook allowing for adding additional columns in this list table.
600
+		 * Note that $this->screen->id is in the format
601
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
602
+		 * table it is: event-espresso_page_espresso_messages.
603
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
604
+		 * hook prefix ("event-espresso") will be different.
605
+		 *
606
+		 * @var array
607
+		 */
608
+		return apply_filters("FHEE_manage_{$this->screen->id}_columns", $this->_columns, $this->_screen, $this);
609
+	}
610
+
611
+
612
+	/**
613
+	 * Get an associative array ( id => link ) with the list
614
+	 * of views available on this table.
615
+	 *
616
+	 * @return array
617
+	 * @since  3.1.0
618
+	 * @access protected
619
+	 */
620
+	public function get_views()
621
+	{
622
+		return $this->_views;
623
+	}
624
+
625
+
626
+	/**
627
+	 * Generate the views html.
628
+	 */
629
+	public function display_views()
630
+	{
631
+		$views           = $this->get_views();
632
+		$assembled_views = [];
633
+
634
+		if (empty($views)) {
635
+			return;
636
+		}
637
+		echo "<ul class='subsubsub'>\n";
638
+		foreach ($views as $view) {
639
+			$count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
640
+			if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
641
+				$filter = "<li";
642
+				$filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : '';
643
+				$filter .= ">";
644
+				$filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>';
645
+				$filter .= '<span class="count">(' . $count . ')</span>';
646
+				$filter .= '</li>';
647
+				$assembled_views[ $view['slug'] ] = $filter;
648
+			}
649
+		}
650
+
651
+		echo ! empty($assembled_views)
652
+			? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views)
653
+			: '';
654
+		echo "</ul>";
655
+	}
656
+
657
+
658
+	/**
659
+	 * Generates content for a single row of the table
660
+	 *
661
+	 * @param EE_Base_Class $item The current item
662
+	 * @since  4.1
663
+	 * @access public
664
+	 */
665
+	public function single_row($item)
666
+	{
667
+		$row_class = $this->_get_row_class($item);
668
+		echo '<tr class="' . esc_attr($row_class) . '">';
669
+		$this->single_row_columns($item); // already escaped
670
+		echo '</tr>';
671
+	}
672
+
673
+
674
+	/**
675
+	 * This simply sets up the row class for the table rows.
676
+	 * Allows for easier overriding of child methods for setting up sorting.
677
+	 *
678
+	 * @param EE_Base_Class $item the current item
679
+	 * @return string
680
+	 */
681
+	protected function _get_row_class($item)
682
+	{
683
+		static $row_class = '';
684
+		$row_class = ($row_class === '' ? 'alternate' : '');
685
+
686
+		$new_row_class = $row_class;
687
+
688
+		if (! empty($this->_ajax_sorting_callback)) {
689
+			$new_row_class .= ' rowsortable';
690
+		}
691
+
692
+		return $new_row_class;
693
+	}
694
+
695
+
696
+	/**
697
+	 * @return array
698
+	 */
699
+	public function get_sortable_columns()
700
+	{
701
+		return (array) $this->_sortable_columns;
702
+	}
703
+
704
+
705
+	/**
706
+	 * @return string
707
+	 */
708
+	public function get_ajax_sorting_callback()
709
+	{
710
+		return $this->_ajax_sorting_callback;
711
+	}
712
+
713
+
714
+	/**
715
+	 * @return array
716
+	 */
717
+	public function get_hidden_columns()
718
+	{
719
+		$user_id     = get_current_user_id();
720
+		$has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
721
+		if (empty($has_default) && ! empty($this->_hidden_columns)) {
722
+			update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
723
+			update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
724
+		}
725
+		$ref = 'manage' . $this->screen->id . 'columnshidden';
726
+		return (array) get_user_option($ref, $user_id);
727
+	}
728
+
729
+
730
+	/**
731
+	 * Generates the columns for a single row of the table.
732
+	 * Overridden from wp_list_table so as to allow us to filter the column content for a given
733
+	 * column.
734
+	 *
735
+	 * @param EE_Base_Class $item The current item
736
+	 * @since 3.1.0
737
+	 */
738
+	public function single_row_columns($item)
739
+	{
740
+		[$columns, $hidden, $sortable, $primary] = $this->get_column_info();
741
+
742
+		foreach ($columns as $column_name => $column_display_name) {
743
+
744
+			/**
745
+			 * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
746
+			 * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
747
+			 */
748
+			$hidden_class = in_array($column_name, $hidden) ? ' hidden' : '';
749
+
750
+			$classes = $column_name . ' column-' . $column_name . $hidden_class;
751
+			if ($primary === $column_name) {
752
+				$classes .= ' has-row-actions column-primary';
753
+			}
754
+
755
+			$data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
756
+
757
+			$class = 'class="' . esc_attr($classes) . '"';
758
+
759
+			$attributes = "{$class}{$data}";
760
+
761
+			if ($column_name === 'cb') {
762
+				echo '<th scope="row" class="check-column">';
763
+				echo apply_filters(
764
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
765
+					$this->column_cb($item), // already escaped
766
+					$item,
767
+					$this
768
+				);
769
+				echo '</th>';
770
+			} elseif (method_exists($this, "column_$column_name")) {
771
+				echo "<td $attributes>"; // already escaped
772
+				echo apply_filters(
773
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
774
+					call_user_func([$this, "column_$column_name"], $item),
775
+					$item,
776
+					$this
777
+				);
778
+				echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
779
+				echo "</td>";
780
+			} else {
781
+				echo "<td $attributes>"; // already escaped
782
+				echo apply_filters(
783
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
784
+					$this->column_default($item, $column_name),
785
+					$item,
786
+					$column_name,
787
+					$this
788
+				);
789
+				echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
790
+				echo "</td>";
791
+			}
792
+		}
793
+	}
794
+
795
+
796
+	/**
797
+	 * Extra controls to be displayed between bulk actions and pagination
798
+	 *
799
+	 * @access public
800
+	 * @param string $which
801
+	 * @throws EE_Error
802
+	 */
803
+	public function extra_tablenav($which)
804
+	{
805
+		if ($which === 'top') {
806
+			$this->_filters();
807
+			echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags());
808
+		} else {
809
+			echo '<div class="list-table-bottom-buttons alignleft actions">';
810
+			foreach ($this->_bottom_buttons as $type => $action) {
811
+				$route         = $action['route'] ?? '';
812
+				$extra_request = $action['extra_request'] ?? '';
813
+				$btn_class     = $action['btn_class'] ?? 'button button--secondary';
814
+				// already escaped
815
+				echo wp_kses($this->_admin_page->get_action_link_or_button(
816
+					$route,
817
+					$type,
818
+					$extra_request,
819
+					$btn_class
820
+				), AllowedTags::getWithFormTags());
821
+			}
822
+			do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
823
+			echo '</div>';
824
+		}
825
+	}
826
+
827
+
828
+	/**
829
+	 * Get an associative array ( option_name => option_title ) with the list
830
+	 * of bulk actions available on this table.
831
+	 *
832
+	 * @return array
833
+	 * @since  3.1.0
834
+	 * @access protected
835
+	 */
836
+	public function get_bulk_actions()
837
+	{
838
+		return (array) $this->_get_bulk_actions();
839
+	}
840
+
841
+
842
+	/**
843
+	 * Processing bulk actions.
844
+	 */
845
+	public function process_bulk_action()
846
+	{
847
+		// this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
848
+		// reference in case there is a case where it gets used.
849
+	}
850
+
851
+
852
+	/**
853
+	 * returns the EE admin page this list table is associated with
854
+	 *
855
+	 * @return EE_Admin_Page
856
+	 */
857
+	public function get_admin_page()
858
+	{
859
+		return $this->_admin_page;
860
+	}
861
+
862
+
863
+	/**
864
+	 * A "helper" function for all children to provide an html string of
865
+	 * actions to output in their content.  It is preferable for child classes
866
+	 * to use this method for generating their actions content so that it's
867
+	 * filterable by plugins
868
+	 *
869
+	 * @param string        $action_container           what are the html container
870
+	 *                                                  elements for this actions string?
871
+	 * @param string        $action_class               What class is for the container
872
+	 *                                                  element.
873
+	 * @param string        $action_items               The contents for the action items
874
+	 *                                                  container.  This is filtered before
875
+	 *                                                  returned.
876
+	 * @param string        $action_id                  What id (optional) is used for the
877
+	 *                                                  container element.
878
+	 * @param EE_Base_Class $item                       The object for the column displaying
879
+	 *                                                  the actions.
880
+	 * @return string The assembled action elements container.
881
+	 */
882
+	protected function _action_string(
883
+		$action_items,
884
+		$item,
885
+		$action_container = 'ul',
886
+		$action_class = '',
887
+		$action_id = ''
888
+	) {
889
+		$action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : '';
890
+		$action_id    = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : '';
891
+		$open_tag     = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
892
+		$close_tag    = ! empty($action_container) ? '</' . $action_container . '>' : '';
893
+		try {
894
+			$content = apply_filters(
895
+				'FHEE__EE_Admin_List_Table___action_string__action_items',
896
+				$action_items,
897
+				$item,
898
+				$this
899
+			);
900
+		} catch (Exception $e) {
901
+			if (WP_DEBUG) {
902
+				EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
903
+			}
904
+			$content = $action_items;
905
+		}
906
+		return "{$open_tag}{$content}{$close_tag}";
907
+	}
908
+
909
+
910
+	/**
911
+	 * @return string
912
+	 */
913
+	protected function getReturnUrl()
914
+	{
915
+		$host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST');
916
+		$uri  = $this->_admin_page->get_request()->getServerParam('REQUEST_URI');
917
+		return urlencode(esc_url_raw("//{$host}{$uri}"));
918
+	}
919
+
920
+
921
+	/**
922
+	 * @param string $id
923
+	 * @param string $content
924
+	 * @param string $align     start (default), center, end
925
+	 * @return string
926
+	 * @since   $VID:$
927
+	 */
928
+	protected function columnContent($id, $content, $align = 'start')
929
+	{
930
+		if (! isset($this->_columns[ $id ])) {
931
+			throw new DomainException('missing column id');
932
+		}
933
+		$heading = $id !== 'cb' ? $this->_columns[ $id ] : '';
934
+		$align = in_array($align, ['start', 'center', 'end']) ? $align : 'start';
935
+		$align = "ee-responsive-table-cell--{$align}";
936
+
937
+		$html = "<div class='ee-responsive-table-cell ee-responsive-table-cell--column-{$id} {$align} ee-layout-row'>";
938
+		$html .= "<div class='ee-responsive-table-cell__heading'>{$heading}</div>";
939
+		$html .= "<div class='ee-responsive-table-cell__content ee-layout-row'>{$content}</div>";
940
+		$html .= "</div>";
941
+		return $html;
942
+	}
943
+
944
+
945
+	protected function actionsModalMenu($actions): string
946
+	{
947
+		return '
948 948
         <div class="ee-modal-menu">
949 949
             <button class="ee-modal-menu__button button button--secondary button--icon-only ee-aria-tooltip"
950 950
                     aria-label="' . esc_attr__('list table actions menu', 'event_espresso') . '"
@@ -956,43 +956,43 @@  discard block
 block discarded – undo
956 956
                 ' . $actions . '
957 957
             </div>
958 958
         </div>';
959
-    }
959
+	}
960 960
 
961 961
 
962
-    public function actionsColumnHeader(): string
963
-    {
964
-        return '
962
+	public function actionsColumnHeader(): string
963
+	{
964
+		return '
965 965
             <span class="ee-actions-column-header-wrap">
966 966
                 <span class="dashicons dashicons-screenoptions"></span>
967 967
                 <span class="ee-actions-column-header">' . esc_html__('Actions', 'event_espresso') . '</span>
968 968
             </span>';
969
-    }
970
-
971
-
972
-    protected function getActionLink(string $url, string $display_text, string $label, $class = ''): string
973
-    {
974
-        $class = ! empty($class) ? "{$class} ee-list-table-action" : 'ee-list-table-action';
975
-        $class = ! empty($label) ? "{$class} ee-aria-tooltip" : $class;
976
-        $label = ! empty($label) ? " aria-label='{$label}'" : '';
977
-        return "<a href='{$url}' class='{$class}'{$label}>{$display_text}</a>";
978
-    }
979
-
980
-    /**
981
-     * Override the search box method of WP List Table to include a reset button
982
-     *
983
-     * @param string $text     The 'submit' button label.
984
-     * @param string $input_id ID attribute value for the search input field.
985
-     */
986
-    public function search_box($text, $input_id)
987
-    {
988
-        if (empty($_REQUEST['s']) && ! $this->has_items()) {
989
-            return;
990
-        }
991
-
992
-        $this->admin_list_table_filters->searchBox(
993
-            $text,
994
-            $input_id,
995
-            $this->get_admin_page()->get_current_page_view_url()
996
-        );
997
-    }
969
+	}
970
+
971
+
972
+	protected function getActionLink(string $url, string $display_text, string $label, $class = ''): string
973
+	{
974
+		$class = ! empty($class) ? "{$class} ee-list-table-action" : 'ee-list-table-action';
975
+		$class = ! empty($label) ? "{$class} ee-aria-tooltip" : $class;
976
+		$label = ! empty($label) ? " aria-label='{$label}'" : '';
977
+		return "<a href='{$url}' class='{$class}'{$label}>{$display_text}</a>";
978
+	}
979
+
980
+	/**
981
+	 * Override the search box method of WP List Table to include a reset button
982
+	 *
983
+	 * @param string $text     The 'submit' button label.
984
+	 * @param string $input_id ID attribute value for the search input field.
985
+	 */
986
+	public function search_box($text, $input_id)
987
+	{
988
+		if (empty($_REQUEST['s']) && ! $this->has_items()) {
989
+			return;
990
+		}
991
+
992
+		$this->admin_list_table_filters->searchBox(
993
+			$text,
994
+			$input_id,
995
+			$this->get_admin_page()->get_current_page_view_url()
996
+		);
997
+	}
998 998
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4262 added lines, -4262 removed lines patch added patch discarded remove patch
@@ -24,4350 +24,4350 @@
 block discarded – undo
24 24
  */
25 25
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
26 26
 {
27
-    /**
28
-     * @var EE_Admin_Config
29
-     */
30
-    protected $admin_config;
27
+	/**
28
+	 * @var EE_Admin_Config
29
+	 */
30
+	protected $admin_config;
31 31
 
32
-    /**
33
-     * @var LoaderInterface
34
-     */
35
-    protected $loader;
32
+	/**
33
+	 * @var LoaderInterface
34
+	 */
35
+	protected $loader;
36 36
 
37
-    /**
38
-     * @var RequestInterface
39
-     */
40
-    protected $request;
37
+	/**
38
+	 * @var RequestInterface
39
+	 */
40
+	protected $request;
41 41
 
42
-    // set in _init_page_props()
43
-    public $page_slug;
42
+	// set in _init_page_props()
43
+	public $page_slug;
44 44
 
45
-    public $page_label;
45
+	public $page_label;
46 46
 
47
-    public $page_folder;
47
+	public $page_folder;
48 48
 
49
-    // set in define_page_props()
50
-    protected $_admin_base_url;
49
+	// set in define_page_props()
50
+	protected $_admin_base_url;
51 51
 
52
-    protected $_admin_base_path;
52
+	protected $_admin_base_path;
53 53
 
54
-    protected $_admin_page_title;
54
+	protected $_admin_page_title;
55 55
 
56
-    protected $_labels;
56
+	protected $_labels;
57 57
 
58 58
 
59
-    // set early within EE_Admin_Init
60
-    protected $_wp_page_slug;
59
+	// set early within EE_Admin_Init
60
+	protected $_wp_page_slug;
61 61
 
62
-    // nav tabs
63
-    protected $_nav_tabs;
62
+	// nav tabs
63
+	protected $_nav_tabs;
64 64
 
65
-    protected $_default_nav_tab_name;
65
+	protected $_default_nav_tab_name;
66 66
 
67 67
 
68
-    // template variables (used by templates)
69
-    protected $_template_path;
68
+	// template variables (used by templates)
69
+	protected $_template_path;
70 70
 
71
-    protected $_column_template_path;
71
+	protected $_column_template_path;
72 72
 
73
-    /**
74
-     * @var array $_template_args
75
-     */
76
-    protected $_template_args = [];
73
+	/**
74
+	 * @var array $_template_args
75
+	 */
76
+	protected $_template_args = [];
77 77
 
78
-    /**
79
-     * this will hold the list table object for a given view.
80
-     *
81
-     * @var EE_Admin_List_Table $_list_table_object
82
-     */
83
-    protected $_list_table_object;
78
+	/**
79
+	 * this will hold the list table object for a given view.
80
+	 *
81
+	 * @var EE_Admin_List_Table $_list_table_object
82
+	 */
83
+	protected $_list_table_object;
84 84
 
85
-    // boolean
86
-    protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
85
+	// boolean
86
+	protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
87 87
 
88
-    protected $_routing;
88
+	protected $_routing;
89 89
 
90
-    // list table args
91
-    protected $_view;
90
+	// list table args
91
+	protected $_view;
92 92
 
93
-    protected $_views;
93
+	protected $_views;
94 94
 
95 95
 
96
-    // action => method pairs used for routing incoming requests
97
-    protected $_page_routes;
96
+	// action => method pairs used for routing incoming requests
97
+	protected $_page_routes;
98 98
 
99
-    /**
100
-     * @var array $_page_config
101
-     */
102
-    protected $_page_config;
99
+	/**
100
+	 * @var array $_page_config
101
+	 */
102
+	protected $_page_config;
103 103
 
104
-    /**
105
-     * the current page route and route config
106
-     *
107
-     * @var array|string|null $_route
108
-     */
109
-    protected $_route;
104
+	/**
105
+	 * the current page route and route config
106
+	 *
107
+	 * @var array|string|null $_route
108
+	 */
109
+	protected $_route;
110 110
 
111
-    /**
112
-     * @var string $_cpt_route
113
-     */
114
-    protected $_cpt_route;
111
+	/**
112
+	 * @var string $_cpt_route
113
+	 */
114
+	protected $_cpt_route;
115 115
 
116
-    /**
117
-     * @var array $_route_config
118
-     */
119
-    protected $_route_config;
116
+	/**
117
+	 * @var array $_route_config
118
+	 */
119
+	protected $_route_config;
120 120
 
121
-    /**
122
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
123
-     * actions.
124
-     *
125
-     * @since 4.6.x
126
-     * @var array.
127
-     */
128
-    protected $_default_route_query_args;
121
+	/**
122
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
123
+	 * actions.
124
+	 *
125
+	 * @since 4.6.x
126
+	 * @var array.
127
+	 */
128
+	protected $_default_route_query_args;
129 129
 
130
-    // set via request page and action args.
131
-    protected $_current_page;
130
+	// set via request page and action args.
131
+	protected $_current_page;
132 132
 
133
-    protected $_current_view;
133
+	protected $_current_view;
134 134
 
135
-    protected $_current_page_view_url;
135
+	protected $_current_page_view_url;
136 136
 
137
-    /**
138
-     * unprocessed value for the 'action' request param (default '')
139
-     *
140
-     * @var string
141
-     */
142
-    protected $raw_req_action = '';
137
+	/**
138
+	 * unprocessed value for the 'action' request param (default '')
139
+	 *
140
+	 * @var string
141
+	 */
142
+	protected $raw_req_action = '';
143 143
 
144
-    /**
145
-     * unprocessed value for the 'page' request param (default '')
146
-     *
147
-     * @var string
148
-     */
149
-    protected $raw_req_page = '';
150
-
151
-    /**
152
-     * sanitized request action (and nonce)
153
-     *
154
-     * @var string
155
-     */
156
-    protected $_req_action = '';
157
-
158
-    /**
159
-     * sanitized request action nonce
160
-     *
161
-     * @var string
162
-     */
163
-    protected $_req_nonce = '';
164
-
165
-    /**
166
-     * @var string
167
-     */
168
-    protected $_search_btn_label = '';
169
-
170
-    /**
171
-     * @var string
172
-     */
173
-    protected $_search_box_callback = '';
174
-
175
-    /**
176
-     * @var WP_Screen
177
-     */
178
-    protected $_current_screen;
179
-
180
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
181
-    protected $_hook_obj;
182
-
183
-    // for holding incoming request data
184
-    protected $_req_data = [];
185
-
186
-    // yes / no array for admin form fields
187
-    protected $_yes_no_values = [];
188
-
189
-    // some default things shared by all child classes
190
-    protected $_default_espresso_metaboxes = [
191
-        '_espresso_news_post_box',
192
-        '_espresso_links_post_box',
193
-        '_espresso_ratings_request',
194
-        '_espresso_sponsors_post_box',
195
-    ];
196
-
197
-    /**
198
-     * @var EE_Registry
199
-     */
200
-    protected $EE;
201
-
202
-
203
-    /**
204
-     * This is just a property that flags whether the given route is a caffeinated route or not.
205
-     *
206
-     * @var boolean
207
-     */
208
-    protected $_is_caf = false;
209
-
210
-    /**
211
-     * whether or not initializePage() has run
212
-     *
213
-     * @var boolean
214
-     */
215
-    protected $initialized = false;
216
-
217
-    /**
218
-     * @var FeatureFlags
219
-     */
220
-    protected $feature;
221
-
222
-
223
-    /**
224
-     * @var string
225
-     */
226
-    protected $class_name;
227
-
228
-    /**
229
-     * if the current class is an admin page extension, like: Extend_Events_Admin_Page,
230
-     * then this would be the parent classname: Events_Admin_Page
231
-     *
232
-     * @var string
233
-     */
234
-    protected $base_class_name;
235
-
236
-    /**
237
-     * @var array
238
-     * @since $VID:$
239
-     */
240
-    private $publish_post_meta_box_hidden_fields = [];
241
-
242
-
243
-    /**
244
-     * @Constructor
245
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
246
-     * @throws InvalidArgumentException
247
-     * @throws InvalidDataTypeException
248
-     * @throws InvalidInterfaceException
249
-     * @throws ReflectionException
250
-     */
251
-    public function __construct($routing = true)
252
-    {
253
-        $this->loader       = LoaderFactory::getLoader();
254
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
255
-        $this->feature      = $this->loader->getShared(FeatureFlags::class);
256
-        $this->request      = $this->loader->getShared(RequestInterface::class);
257
-        // routing enabled?
258
-        $this->_routing = $routing;
259
-
260
-        $this->class_name      = get_class($this);
261
-        $this->base_class_name = strpos($this->class_name, 'Extend_') === 0
262
-            ? str_replace('Extend_', '', $this->class_name)
263
-            : '';
264
-
265
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
266
-            $this->_is_caf = true;
267
-        }
268
-        $this->_yes_no_values = [
269
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
270
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
271
-        ];
272
-        // set the _req_data property.
273
-        $this->_req_data = $this->request->requestParams();
274
-    }
275
-
276
-
277
-    /**
278
-     * @return EE_Admin_Config
279
-     */
280
-    public function adminConfig(): EE_Admin_Config
281
-    {
282
-        return $this->admin_config;
283
-    }
284
-
285
-
286
-    /**
287
-     * @return FeatureFlags
288
-     */
289
-    public function feature(): FeatureFlags
290
-    {
291
-        return $this->feature;
292
-    }
293
-
294
-
295
-    /**
296
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
297
-     * for child classes that needed to set properties prior to these methods getting called,
298
-     * but also needed the parent class to have its construction completed as well.
299
-     * Bottom line is that constructors should ONLY be used for setting initial properties
300
-     * and any complex initialization logic should only run after instantiation is complete.
301
-     *
302
-     * This method gets called immediately after construction from within
303
-     *      EE_Admin_Page_Init::_initialize_admin_page()
304
-     *
305
-     * @throws EE_Error
306
-     * @throws InvalidArgumentException
307
-     * @throws InvalidDataTypeException
308
-     * @throws InvalidInterfaceException
309
-     * @throws ReflectionException
310
-     * @since $VID:$
311
-     */
312
-    public function initializePage()
313
-    {
314
-        if ($this->initialized) {
315
-            return;
316
-        }
317
-        // set initial page props (child method)
318
-        $this->_init_page_props();
319
-        // set global defaults
320
-        $this->_set_defaults();
321
-        // set early because incoming requests could be ajax related and we need to register those hooks.
322
-        $this->_global_ajax_hooks();
323
-        $this->_ajax_hooks();
324
-        // other_page_hooks have to be early too.
325
-        $this->_do_other_page_hooks();
326
-        // set up page dependencies
327
-        $this->_before_page_setup();
328
-        $this->_page_setup();
329
-        $this->initialized = true;
330
-    }
331
-
332
-
333
-    /**
334
-     * _init_page_props
335
-     * Child classes use to set at least the following properties:
336
-     * $page_slug.
337
-     * $page_label.
338
-     *
339
-     * @abstract
340
-     * @return void
341
-     */
342
-    abstract protected function _init_page_props();
343
-
344
-
345
-    /**
346
-     * _ajax_hooks
347
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
348
-     * Note: within the ajax callback methods.
349
-     *
350
-     * @abstract
351
-     * @return void
352
-     */
353
-    abstract protected function _ajax_hooks();
354
-
355
-
356
-    /**
357
-     * _define_page_props
358
-     * child classes define page properties in here.  Must include at least:
359
-     * $_admin_base_url = base_url for all admin pages
360
-     * $_admin_page_title = default admin_page_title for admin pages
361
-     * $_labels = array of default labels for various automatically generated elements:
362
-     *    array(
363
-     *        'buttons' => array(
364
-     *            'add' => esc_html__('label for add new button'),
365
-     *            'edit' => esc_html__('label for edit button'),
366
-     *            'delete' => esc_html__('label for delete button')
367
-     *            )
368
-     *        )
369
-     *
370
-     * @abstract
371
-     * @return void
372
-     */
373
-    abstract protected function _define_page_props();
374
-
375
-
376
-    /**
377
-     * _set_page_routes
378
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
379
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
380
-     * have a 'default' route. Here's the format
381
-     * $this->_page_routes = array(
382
-     *        'default' => array(
383
-     *            'func' => '_default_method_handling_route',
384
-     *            'args' => array('array','of','args'),
385
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
386
-     *            ajax request, backend processing)
387
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
388
-     *            headers route after.  The string you enter here should match the defined route reference for a
389
-     *            headers sent route.
390
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
391
-     *            this route.
392
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
393
-     *            checks).
394
-     *        ),
395
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
396
-     *        handling method.
397
-     *        )
398
-     * )
399
-     *
400
-     * @abstract
401
-     * @return void
402
-     */
403
-    abstract protected function _set_page_routes();
404
-
405
-
406
-    /**
407
-     * _set_page_config
408
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
409
-     * array corresponds to the page_route for the loaded page. Format:
410
-     * $this->_page_config = array(
411
-     *        'default' => array(
412
-     *            'labels' => array(
413
-     *                'buttons' => array(
414
-     *                    'add' => esc_html__('label for adding item'),
415
-     *                    'edit' => esc_html__('label for editing item'),
416
-     *                    'delete' => esc_html__('label for deleting item')
417
-     *                ),
418
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
419
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
420
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
421
-     *            _define_page_props() method
422
-     *            'nav' => array(
423
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
424
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
425
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
426
-     *                'order' => 10, //required to indicate tab position.
427
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
428
-     *                displayed then add this parameter.
429
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
430
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
431
-     *            metaboxes set for eventespresso admin pages.
432
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
433
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
434
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
435
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
436
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
437
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
438
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
439
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
440
-     *            want to display.
441
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
442
-     *                'tab_id' => array(
443
-     *                    'title' => 'tab_title',
444
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
445
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
446
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
447
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
448
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
449
-     *                    attempt to use the callback which should match the name of a method in the class
450
-     *                    ),
451
-     *                'tab2_id' => array(
452
-     *                    'title' => 'tab2 title',
453
-     *                    'filename' => 'file_name_2'
454
-     *                    'callback' => 'callback_method_for_content',
455
-     *                 ),
456
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
457
-     *            help tab area on an admin page. @return void
458
-     *
459
-     * @abstract
460
-     */
461
-    abstract protected function _set_page_config();
462
-
463
-
464
-    /**
465
-     * _add_screen_options
466
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
467
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
468
-     * to a particular view.
469
-     *
470
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
471
-     *         see also WP_Screen object documents...
472
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
473
-     * @abstract
474
-     * @return void
475
-     */
476
-    abstract protected function _add_screen_options();
477
-
478
-
479
-    /**
480
-     * _add_feature_pointers
481
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
482
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
483
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
484
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
485
-     * extended) also see:
486
-     *
487
-     * @link   http://eamann.com/tech/wordpress-portland/
488
-     * @abstract
489
-     * @return void
490
-     */
491
-    abstract protected function _add_feature_pointers();
492
-
493
-
494
-    /**
495
-     * load_scripts_styles
496
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
497
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
498
-     * scripts/styles per view by putting them in a dynamic function in this format
499
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
500
-     *
501
-     * @abstract
502
-     * @return void
503
-     */
504
-    abstract public function load_scripts_styles();
505
-
506
-
507
-    /**
508
-     * admin_init
509
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
510
-     * all pages/views loaded by child class.
511
-     *
512
-     * @abstract
513
-     * @return void
514
-     */
515
-    abstract public function admin_init();
516
-
517
-
518
-    /**
519
-     * admin_notices
520
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
521
-     * all pages/views loaded by child class.
522
-     *
523
-     * @abstract
524
-     * @return void
525
-     */
526
-    abstract public function admin_notices();
527
-
528
-
529
-    /**
530
-     * admin_footer_scripts
531
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
532
-     * will apply to all pages/views loaded by child class.
533
-     *
534
-     * @return void
535
-     */
536
-    abstract public function admin_footer_scripts();
537
-
538
-
539
-    /**
540
-     * admin_footer
541
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
542
-     * apply to all pages/views loaded by child class.
543
-     *
544
-     * @return void
545
-     */
546
-    public function admin_footer()
547
-    {
548
-    }
549
-
550
-
551
-    /**
552
-     * _global_ajax_hooks
553
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
554
-     * Note: within the ajax callback methods.
555
-     *
556
-     * @abstract
557
-     * @return void
558
-     */
559
-    protected function _global_ajax_hooks()
560
-    {
561
-        // for lazy loading of metabox content
562
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
563
-
564
-        add_action(
565
-            'wp_ajax_espresso_hide_status_change_notice',
566
-            [$this, 'hideStatusChangeNotice']
567
-        );
568
-        add_action(
569
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
570
-            [$this, 'hideStatusChangeNotice']
571
-        );
572
-    }
573
-
574
-
575
-    public function ajax_metabox_content()
576
-    {
577
-        $content_id  = $this->request->getRequestParam('contentid', '');
578
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
579
-        EE_Admin_Page::cached_rss_display($content_id, $content_url);
580
-        wp_die();
581
-    }
582
-
583
-
584
-    public function hideStatusChangeNotice()
585
-    {
586
-        $response = [];
587
-        try {
588
-            /** @var StatusChangeNotice $status_change_notice */
589
-            $status_change_notice = $this->loader->getShared(
590
-                'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
591
-            );
592
-            $response['success']  = $status_change_notice->dismiss() > -1;
593
-        } catch (Exception $exception) {
594
-            $response['errors'] = $exception->getMessage();
595
-        }
596
-        echo wp_json_encode($response);
597
-        exit();
598
-    }
599
-
600
-
601
-    /**
602
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
603
-     *
604
-     * @return void
605
-     */
606
-    protected function _before_page_setup()
607
-    {
608
-        // default is to do nothing
609
-    }
610
-
611
-
612
-    /**
613
-     * Makes sure any things that need to be loaded early get handled.
614
-     * We also escape early here if the page requested doesn't match the object.
615
-     *
616
-     * @final
617
-     * @return void
618
-     * @throws EE_Error
619
-     * @throws InvalidArgumentException
620
-     * @throws ReflectionException
621
-     * @throws InvalidDataTypeException
622
-     * @throws InvalidInterfaceException
623
-     */
624
-    final protected function _page_setup()
625
-    {
626
-        // requires?
627
-        // admin_init stuff - global - we're setting this REALLY early
628
-        // so if EE_Admin pages have to hook into other WP pages they can.
629
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
630
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
631
-        // next verify if we need to load anything...
632
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
633
-        $this->_current_page = $this->request->getRequestParam('current_page', $this->_current_page, 'key');
634
-        $this->page_folder   = strtolower(
635
-            str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name)
636
-        );
637
-        global $ee_menu_slugs;
638
-        $ee_menu_slugs = (array) $ee_menu_slugs;
639
-        if (
640
-            ! $this->request->isAjax()
641
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
642
-        ) {
643
-            return;
644
-        }
645
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
646
-        // we need to copy the action from the second to the first
647
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
648
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
649
-        $action     = $action !== '-1' ? $action : $action2;
650
-        $req_action = $action !== '-1' ? $action : 'default';
651
-
652
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
653
-        // then let's use the route as the action.
654
-        // This covers cases where we're coming in from a list table that isn't on the default route.
655
-        $route             = $this->request->getRequestParam('route');
656
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
657
-            ? $route
658
-            : $req_action;
659
-
660
-        $this->_current_view = $this->_req_action;
661
-        $this->_req_nonce    = $this->_req_action . '_nonce';
662
-        $this->_define_page_props();
663
-        $this->_current_page_view_url = add_query_arg(
664
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
665
-            $this->_admin_base_url
666
-        );
667
-        // set page configs
668
-        $this->_set_page_routes();
669
-        $this->_set_page_config();
670
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
671
-        if ($this->request->requestParamIsSet('wp_referer')) {
672
-            $wp_referer = $this->request->getRequestParam('wp_referer');
673
-            if ($wp_referer) {
674
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
675
-            }
676
-        }
677
-        // for CPT and other extended functionality.
678
-        // If there is an _extend_page_config_for_cpt
679
-        // then let's run that to modify all the various page configuration arrays.
680
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
681
-            $this->_extend_page_config_for_cpt();
682
-        }
683
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
684
-        $this->_page_routes = apply_filters(
685
-            'FHEE__' . $this->class_name . '__page_setup__page_routes',
686
-            $this->_page_routes,
687
-            $this
688
-        );
689
-        $this->_page_config = apply_filters(
690
-            'FHEE__' . $this->class_name . '__page_setup__page_config',
691
-            $this->_page_config,
692
-            $this
693
-        );
694
-        if ($this->base_class_name !== '') {
695
-            $this->_page_routes = apply_filters(
696
-                'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
697
-                $this->_page_routes,
698
-                $this
699
-            );
700
-            $this->_page_config = apply_filters(
701
-                'FHEE__' . $this->base_class_name . '__page_setup__page_config',
702
-                $this->_page_config,
703
-                $this
704
-            );
705
-        }
706
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
707
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
708
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
709
-            add_action(
710
-                'AHEE__EE_Admin_Page__route_admin_request',
711
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
712
-                10,
713
-                2
714
-            );
715
-        }
716
-        // next route only if routing enabled
717
-        if ($this->_routing && ! $this->request->isAjax()) {
718
-            $this->_verify_routes();
719
-            // next let's just check user_access and kill if no access
720
-            $this->check_user_access();
721
-            if ($this->_is_UI_request) {
722
-                // admin_init stuff - global, all views for this page class, specific view
723
-                add_action('admin_init', [$this, 'admin_init'], 10);
724
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
725
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
726
-                }
727
-            } else {
728
-                // hijack regular WP loading and route admin request immediately
729
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
730
-                $this->route_admin_request();
731
-            }
732
-        }
733
-    }
734
-
735
-
736
-    /**
737
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
738
-     *
739
-     * @return void
740
-     * @throws EE_Error
741
-     */
742
-    private function _do_other_page_hooks()
743
-    {
744
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
745
-        foreach ($registered_pages as $page) {
746
-            // now let's setup the file name and class that should be present
747
-            $classname = str_replace('.class.php', '', $page);
748
-            // autoloaders should take care of loading file
749
-            if (! class_exists($classname)) {
750
-                $error_msg[] = sprintf(
751
-                    esc_html__(
752
-                        'Something went wrong with loading the %s admin hooks page.',
753
-                        'event_espresso'
754
-                    ),
755
-                    $page
756
-                );
757
-                $error_msg[] = $error_msg[0]
758
-                               . "\r\n"
759
-                               . sprintf(
760
-                                   esc_html__(
761
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
762
-                                       'event_espresso'
763
-                                   ),
764
-                                   $page,
765
-                                   '<br />',
766
-                                   '<strong>' . $classname . '</strong>'
767
-                               );
768
-                throw new EE_Error(implode('||', $error_msg));
769
-            }
770
-            // notice we are passing the instance of this class to the hook object.
771
-            $this->loader->getShared($classname, [$this]);
772
-        }
773
-    }
774
-
775
-
776
-    /**
777
-     * @throws ReflectionException
778
-     * @throws EE_Error
779
-     */
780
-    public function load_page_dependencies()
781
-    {
782
-        try {
783
-            $this->_load_page_dependencies();
784
-        } catch (EE_Error $e) {
785
-            $e->get_error();
786
-        }
787
-    }
788
-
789
-
790
-    /**
791
-     * load_page_dependencies
792
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
793
-     *
794
-     * @return void
795
-     * @throws DomainException
796
-     * @throws EE_Error
797
-     * @throws InvalidArgumentException
798
-     * @throws InvalidDataTypeException
799
-     * @throws InvalidInterfaceException
800
-     * @throws ReflectionException
801
-     */
802
-    protected function _load_page_dependencies()
803
-    {
804
-        // let's set the current_screen and screen options to override what WP set
805
-        $this->_current_screen = get_current_screen();
806
-        // load admin_notices - global, page class, and view specific
807
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
808
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
809
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
810
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
811
-        }
812
-        // load network admin_notices - global, page class, and view specific
813
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
814
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
815
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
816
-        }
817
-        // this will save any per_page screen options if they are present
818
-        $this->_set_per_page_screen_options();
819
-        // setup list table properties
820
-        $this->_set_list_table();
821
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
822
-        // However in some cases the metaboxes will need to be added within a route handling callback.
823
-        add_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99);
824
-        // hack because promos admin was loading the edited promotion object in the metaboxes callback
825
-        // which should NOT be generated on non-UI requests like POST updates/inserts
826
-        if (
827
-            $this->class_name === 'Promotions_Admin_Page'
828
-            && ($this->_req_action === 'edit' || $this->_req_action === 'create_new')
829
-        ) {
830
-            $this->addRegisteredMetaBoxes();
831
-        }
832
-        $this->_add_screen_columns();
833
-        // add screen options - global, page child class, and view specific
834
-        $this->_add_global_screen_options();
835
-        $this->_add_screen_options();
836
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
837
-        if (method_exists($this, $add_screen_options)) {
838
-            $this->{$add_screen_options}();
839
-        }
840
-        // add help tab(s) - set via page_config and qtips.
841
-        $this->_add_help_tabs();
842
-        $this->_add_qtips();
843
-        // add feature_pointers - global, page child class, and view specific
844
-        $this->_add_feature_pointers();
845
-        $this->_add_global_feature_pointers();
846
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
847
-        if (method_exists($this, $add_feature_pointer)) {
848
-            $this->{$add_feature_pointer}();
849
-        }
850
-        // enqueue scripts/styles - global, page class, and view specific
851
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
852
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
853
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
854
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
855
-        }
856
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
857
-        // admin_print_footer_scripts - global, page child class, and view specific.
858
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
859
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
860
-        // is a good use case. Notice the late priority we're giving these
861
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
862
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
863
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
864
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
865
-        }
866
-        // admin footer scripts
867
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
868
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
869
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
870
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
871
-        }
872
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
873
-        // targeted hook
874
-        do_action(
875
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
876
-        );
877
-    }
878
-
879
-
880
-    /**
881
-     * _set_defaults
882
-     * This sets some global defaults for class properties.
883
-     */
884
-    private function _set_defaults()
885
-    {
886
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
887
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
888
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
889
-        $this->_page_config          = $this->_default_route_query_args = [];
890
-        $this->_default_nav_tab_name = 'overview';
891
-        // init template args
892
-        $this->set_template_args(
893
-            [
894
-                'admin_page_header'  => '',
895
-                'admin_page_content' => '',
896
-                'post_body_content'  => '',
897
-                'before_list_table'  => '',
898
-                'after_list_table'   => '',
899
-            ]
900
-        );
901
-    }
902
-
903
-
904
-    /**
905
-     * route_admin_request
906
-     *
907
-     * @return void
908
-     * @throws InvalidArgumentException
909
-     * @throws InvalidInterfaceException
910
-     * @throws InvalidDataTypeException
911
-     * @throws EE_Error
912
-     * @throws ReflectionException
913
-     * @see    _route_admin_request()
914
-     */
915
-    public function route_admin_request()
916
-    {
917
-        try {
918
-            $this->_route_admin_request();
919
-        } catch (EE_Error $e) {
920
-            $e->get_error();
921
-        }
922
-    }
923
-
924
-
925
-    public function set_wp_page_slug($wp_page_slug)
926
-    {
927
-        $this->_wp_page_slug = $wp_page_slug;
928
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
929
-        if (is_network_admin()) {
930
-            $this->_wp_page_slug .= '-network';
931
-        }
932
-    }
933
-
934
-
935
-    /**
936
-     * _verify_routes
937
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
938
-     * we know if we need to drop out.
939
-     *
940
-     * @return bool
941
-     * @throws EE_Error
942
-     */
943
-    protected function _verify_routes()
944
-    {
945
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
946
-        if (! $this->_current_page && ! $this->request->isAjax()) {
947
-            return false;
948
-        }
949
-        $this->_route = false;
950
-        // check that the page_routes array is not empty
951
-        if (empty($this->_page_routes)) {
952
-            // user error msg
953
-            $error_msg = sprintf(
954
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
955
-                $this->_admin_page_title
956
-            );
957
-            // developer error msg
958
-            $error_msg .= '||' . $error_msg
959
-                          . esc_html__(
960
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
961
-                              'event_espresso'
962
-                          );
963
-            throw new EE_Error($error_msg);
964
-        }
965
-        // and that the requested page route exists
966
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
967
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
968
-            $this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
969
-        } else {
970
-            // user error msg
971
-            $error_msg = sprintf(
972
-                esc_html__(
973
-                    'The requested page route does not exist for the %s admin page.',
974
-                    'event_espresso'
975
-                ),
976
-                $this->_admin_page_title
977
-            );
978
-            // developer error msg
979
-            $error_msg .= '||' . $error_msg
980
-                          . sprintf(
981
-                              esc_html__(
982
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
983
-                                  'event_espresso'
984
-                              ),
985
-                              $this->_req_action
986
-                          );
987
-            throw new EE_Error($error_msg);
988
-        }
989
-        // and that a default route exists
990
-        if (! array_key_exists('default', $this->_page_routes)) {
991
-            // user error msg
992
-            $error_msg = sprintf(
993
-                esc_html__(
994
-                    'A default page route has not been set for the % admin page.',
995
-                    'event_espresso'
996
-                ),
997
-                $this->_admin_page_title
998
-            );
999
-            // developer error msg
1000
-            $error_msg .= '||' . $error_msg
1001
-                          . esc_html__(
1002
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
1003
-                              'event_espresso'
1004
-                          );
1005
-            throw new EE_Error($error_msg);
1006
-        }
1007
-
1008
-        // first lets' catch if the UI request has EVER been set.
1009
-        if ($this->_is_UI_request === null) {
1010
-            // lets set if this is a UI request or not.
1011
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
1012
-            // wait a minute... we might have a noheader in the route array
1013
-            $this->_is_UI_request = ! (
1014
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
1015
-            )
1016
-                ? $this->_is_UI_request
1017
-                : false;
1018
-        }
1019
-        $this->_set_current_labels();
1020
-        return true;
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
1026
-     *
1027
-     * @param string $route the route name we're verifying
1028
-     * @return bool we'll throw an exception if this isn't a valid route.
1029
-     * @throws EE_Error
1030
-     */
1031
-    protected function _verify_route($route)
1032
-    {
1033
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
1034
-            return true;
1035
-        }
1036
-        // user error msg
1037
-        $error_msg = sprintf(
1038
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
1039
-            $this->_admin_page_title
1040
-        );
1041
-        // developer error msg
1042
-        $error_msg .= '||' . $error_msg
1043
-                      . sprintf(
1044
-                          esc_html__(
1045
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
1046
-                              'event_espresso'
1047
-                          ),
1048
-                          $route
1049
-                      );
1050
-        throw new EE_Error($error_msg);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * perform nonce verification
1056
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1057
-     * using this method (and save retyping!)
1058
-     *
1059
-     * @param string $nonce     The nonce sent
1060
-     * @param string $nonce_ref The nonce reference string (name0)
1061
-     * @return void
1062
-     * @throws EE_Error
1063
-     * @throws InvalidArgumentException
1064
-     * @throws InvalidDataTypeException
1065
-     * @throws InvalidInterfaceException
1066
-     */
1067
-    protected function _verify_nonce($nonce, $nonce_ref)
1068
-    {
1069
-        // verify nonce against expected value
1070
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1071
-            // these are not the droids you are looking for !!!
1072
-            $msg = sprintf(
1073
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
1074
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1075
-                '</a>'
1076
-            );
1077
-            if (WP_DEBUG) {
1078
-                $msg .= "\n  ";
1079
-                $msg .= sprintf(
1080
-                    esc_html__(
1081
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1082
-                        'event_espresso'
1083
-                    ),
1084
-                    __CLASS__
1085
-                );
1086
-            }
1087
-            if (! $this->request->isAjax()) {
1088
-                wp_die($msg);
1089
-            }
1090
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1091
-            $this->_return_json();
1092
-        }
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * _route_admin_request()
1098
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1099
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1100
-     * in the page routes and then will try to load the corresponding method.
1101
-     *
1102
-     * @return void
1103
-     * @throws EE_Error
1104
-     * @throws InvalidArgumentException
1105
-     * @throws InvalidDataTypeException
1106
-     * @throws InvalidInterfaceException
1107
-     * @throws ReflectionException
1108
-     */
1109
-    protected function _route_admin_request()
1110
-    {
1111
-        if (! $this->_is_UI_request) {
1112
-            $this->_verify_routes();
1113
-        }
1114
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1115
-        if ($this->_req_action !== 'default' && $nonce_check) {
1116
-            // set nonce from post data
1117
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
1118
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1119
-        }
1120
-        // set the nav_tabs array but ONLY if this is  UI_request
1121
-        if ($this->_is_UI_request) {
1122
-            $this->_set_nav_tabs();
1123
-        }
1124
-        // grab callback function
1125
-        $func = is_array($this->_route) && isset($this->_route['func'])
1126
-            ? $this->_route['func']
1127
-            : $this->_route;
1128
-        // check if callback has args
1129
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1130
-        // action right before calling route
1131
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1132
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1133
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1134
-        }
1135
-        // strip _wp_http_referer from the server REQUEST_URI
1136
-        // else it grows in length on every submission due to recursion,
1137
-        // ultimately causing a "Request-URI Too Large" error
1138
-        $this->request->unSetRequestParam('_wp_http_referer');
1139
-        $this->request->unSetServerParam('_wp_http_referer');
1140
-        $cleaner_request_uri = remove_query_arg(
1141
-            '_wp_http_referer',
1142
-            wp_unslash($this->request->getServerParam('REQUEST_URI'))
1143
-        );
1144
-        $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri, true);
1145
-        $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri, true);
1146
-        $route_callback = [];
1147
-        if (! empty($func)) {
1148
-            if (is_array($func)) {
1149
-                $route_callback = $func;
1150
-            } elseif (is_string($func)) {
1151
-                if (strpos($func, '::') !== false) {
1152
-                    $route_callback = explode('::', $func);
1153
-                } elseif (method_exists($this, $func)) {
1154
-                    $route_callback = [$this, $func];
1155
-                } else {
1156
-                    $route_callback = $func;
1157
-                }
1158
-            }
1159
-            [$class, $method] = $route_callback;
1160
-            // is it neither a class method NOR a standalone function?
1161
-            if (! is_callable($route_callback)) {
1162
-                // user error msg
1163
-                $error_msg = esc_html__(
1164
-                    'An error occurred. The  requested page route could not be found.',
1165
-                    'event_espresso'
1166
-                );
1167
-                // developer error msg
1168
-                $error_msg .= '||';
1169
-                $error_msg .= sprintf(
1170
-                    esc_html__(
1171
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1172
-                        'event_espresso'
1173
-                    ),
1174
-                    $method
1175
-                );
1176
-                throw new DomainException($error_msg);
1177
-            }
1178
-            if ($class !== $this && ! in_array($this, $args)) {
1179
-                // send along this admin page object for access by addons.
1180
-                $args['admin_page'] = $this;
1181
-            }
1182
-
1183
-            try {
1184
-                call_user_func_array($route_callback, $args);
1185
-            } catch (Throwable $throwable) {
1186
-                $arg_keys = array_keys($args);
1187
-                $nice_args = [];
1188
-                foreach ($args as $key => $arg) {
1189
-                    $nice_args[ $key ] = is_object($arg) ? get_class($arg) : $arg_keys[ $key ];
1190
-                }
1191
-                new ExceptionStackTraceDisplay(
1192
-                        new RuntimeException(
1193
-                            sprintf(
1194
-                                esc_html__(
1195
-                                    'Page route "%1$s" with the supplied arguments (%2$s) threw the following exception: %3$s',
1196
-                                    'event_espresso'
1197
-                                ),
1198
-                                $method,
1199
-                                implode(', ', $nice_args),
1200
-                                $throwable->getMessage()
1201
-                            ),
1202
-                            $throwable->getCode(),
1203
-                            $throwable
1204
-                        )
1205
-                );
1206
-            }
1207
-        }
1208
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1209
-        // then we need to reset the routing properties to the new route.
1210
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1211
-        if (
1212
-            $this->_is_UI_request === false
1213
-            && is_array($this->_route)
1214
-            && ! empty($this->_route['headers_sent_route'])
1215
-        ) {
1216
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1217
-        }
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * This method just allows the resetting of page properties in the case where a no headers
1223
-     * route redirects to a headers route in its route config.
1224
-     *
1225
-     * @param string $new_route New (non header) route to redirect to.
1226
-     * @return   void
1227
-     * @throws ReflectionException
1228
-     * @throws InvalidArgumentException
1229
-     * @throws InvalidInterfaceException
1230
-     * @throws InvalidDataTypeException
1231
-     * @throws EE_Error
1232
-     * @since   4.3.0
1233
-     */
1234
-    protected function _reset_routing_properties($new_route)
1235
-    {
1236
-        $this->_is_UI_request = true;
1237
-        // now we set the current route to whatever the headers_sent_route is set at
1238
-        $this->request->setRequestParam('action', $new_route);
1239
-        // rerun page setup
1240
-        $this->_page_setup();
1241
-    }
1242
-
1243
-
1244
-    /**
1245
-     * _add_query_arg
1246
-     * adds nonce to array of arguments then calls WP add_query_arg function
1247
-     *(internally just uses EEH_URL's function with the same name)
1248
-     *
1249
-     * @param array  $args
1250
-     * @param string $url
1251
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1252
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1253
-     *                                        Example usage: If the current page is:
1254
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1255
-     *                                        &action=default&event_id=20&month_range=March%202015
1256
-     *                                        &_wpnonce=5467821
1257
-     *                                        and you call:
1258
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1259
-     *                                        array(
1260
-     *                                        'action' => 'resend_something',
1261
-     *                                        'page=>espresso_registrations'
1262
-     *                                        ),
1263
-     *                                        $some_url,
1264
-     *                                        true
1265
-     *                                        );
1266
-     *                                        It will produce a url in this structure:
1267
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1268
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1269
-     *                                        month_range]=March%202015
1270
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1271
-     * @param int    $context
1272
-     * @return string
1273
-     */
1274
-    public static function add_query_args_and_nonce(
1275
-        $args = [],
1276
-        $url = '',
1277
-        $sticky = false,
1278
-        $exclude_nonce = false,
1279
-        int $context = EEH_URL::CONTEXT_NONE
1280
-    ) {
1281
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1282
-        if ($sticky) {
1283
-            /** @var RequestInterface $request */
1284
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1285
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1286
-            $request->unSetServerParam('_wp_http_referer', true);
1287
-            foreach ($request->requestParams() as $key => $value) {
1288
-                // do not add nonces
1289
-                if (strpos($key, 'nonce') !== false) {
1290
-                    continue;
1291
-                }
1292
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1293
-            }
1294
-        }
1295
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce, $context);
1296
-    }
1297
-
1298
-
1299
-    /**
1300
-     * This returns a generated link that will load the related help tab.
1301
-     *
1302
-     * @param string $help_tab_id the id for the connected help tab
1303
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1304
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1305
-     * @return string              generated link
1306
-     * @uses EEH_Template::get_help_tab_link()
1307
-     */
1308
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1309
-    {
1310
-        return EEH_Template::get_help_tab_link(
1311
-            $help_tab_id,
1312
-            $this->page_slug,
1313
-            $this->_req_action,
1314
-            $icon_style,
1315
-            $help_text
1316
-        );
1317
-    }
1318
-
1319
-
1320
-    /**
1321
-     * _add_help_tabs
1322
-     * Note child classes define their help tabs within the page_config array.
1323
-     *
1324
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1325
-     * @return void
1326
-     * @throws DomainException
1327
-     * @throws EE_Error
1328
-     * @throws ReflectionException
1329
-     */
1330
-    protected function _add_help_tabs()
1331
-    {
1332
-        if (isset($this->_page_config[ $this->_req_action ])) {
1333
-            $config = $this->_page_config[ $this->_req_action ];
1334
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1335
-            if (is_array($config) && isset($config['help_sidebar'])) {
1336
-                // check that the callback given is valid
1337
-                if (! method_exists($this, $config['help_sidebar'])) {
1338
-                    throw new EE_Error(
1339
-                        sprintf(
1340
-                            esc_html__(
1341
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1342
-                                'event_espresso'
1343
-                            ),
1344
-                            $config['help_sidebar'],
1345
-                            $this->class_name
1346
-                        )
1347
-                    );
1348
-                }
1349
-                $content = apply_filters(
1350
-                    'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1351
-                    $this->{$config['help_sidebar']}()
1352
-                );
1353
-                $this->_current_screen->set_help_sidebar($content);
1354
-            }
1355
-            if (! isset($config['help_tabs'])) {
1356
-                return;
1357
-            } //no help tabs for this route
1358
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1359
-                // we're here so there ARE help tabs!
1360
-                // make sure we've got what we need
1361
-                if (! isset($cfg['title'])) {
1362
-                    throw new EE_Error(
1363
-                        esc_html__(
1364
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1365
-                            'event_espresso'
1366
-                        )
1367
-                    );
1368
-                }
1369
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1370
-                    throw new EE_Error(
1371
-                        esc_html__(
1372
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1373
-                            'event_espresso'
1374
-                        )
1375
-                    );
1376
-                }
1377
-                // first priority goes to content.
1378
-                if (! empty($cfg['content'])) {
1379
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1380
-                    // second priority goes to filename
1381
-                } elseif (! empty($cfg['filename'])) {
1382
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1383
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1384
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1385
-                                                             . basename($this->_get_dir())
1386
-                                                             . '/help_tabs/'
1387
-                                                             . $cfg['filename']
1388
-                                                             . '.help_tab.php' : $file_path;
1389
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1390
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1391
-                        EE_Error::add_error(
1392
-                            sprintf(
1393
-                                esc_html__(
1394
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1395
-                                    'event_espresso'
1396
-                                ),
1397
-                                $tab_id,
1398
-                                key($config),
1399
-                                $file_path
1400
-                            ),
1401
-                            __FILE__,
1402
-                            __FUNCTION__,
1403
-                            __LINE__
1404
-                        );
1405
-                        return;
1406
-                    }
1407
-                    $template_args['admin_page_obj'] = $this;
1408
-                    $content                         = EEH_Template::display_template(
1409
-                        $file_path,
1410
-                        $template_args,
1411
-                        true
1412
-                    );
1413
-                } else {
1414
-                    $content = '';
1415
-                }
1416
-                // check if callback is valid
1417
-                if (
1418
-                    empty($content)
1419
-                    && (
1420
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1421
-                    )
1422
-                ) {
1423
-                    EE_Error::add_error(
1424
-                        sprintf(
1425
-                            esc_html__(
1426
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1427
-                                'event_espresso'
1428
-                            ),
1429
-                            $cfg['title']
1430
-                        ),
1431
-                        __FILE__,
1432
-                        __FUNCTION__,
1433
-                        __LINE__
1434
-                    );
1435
-                    return;
1436
-                }
1437
-                // setup config array for help tab method
1438
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1439
-                $_ht = [
1440
-                    'id'       => $id,
1441
-                    'title'    => $cfg['title'],
1442
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1443
-                    'content'  => $content,
1444
-                ];
1445
-                $this->_current_screen->add_help_tab($_ht);
1446
-            }
1447
-        }
1448
-    }
1449
-
1450
-
1451
-    /**
1452
-     * This simply sets up any qtips that have been defined in the page config
1453
-     *
1454
-     * @return void
1455
-     * @throws ReflectionException
1456
-     * @throws EE_Error
1457
-     */
1458
-    protected function _add_qtips()
1459
-    {
1460
-        if (isset($this->_route_config['qtips'])) {
1461
-            $qtips = (array) $this->_route_config['qtips'];
1462
-            // load qtip loader
1463
-            $path = [
1464
-                $this->_get_dir() . '/qtips/',
1465
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1466
-            ];
1467
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1468
-        }
1469
-    }
1470
-
1471
-
1472
-    /**
1473
-     * _set_nav_tabs
1474
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1475
-     * wish to add additional tabs or modify accordingly.
1476
-     *
1477
-     * @return void
1478
-     * @throws InvalidArgumentException
1479
-     * @throws InvalidInterfaceException
1480
-     * @throws InvalidDataTypeException
1481
-     */
1482
-    protected function _set_nav_tabs()
1483
-    {
1484
-        $i        = 0;
1485
-        $only_tab = count($this->_page_config) < 2;
1486
-        foreach ($this->_page_config as $slug => $config) {
1487
-            if (! is_array($config) || empty($config['nav'])) {
1488
-                continue;
1489
-            }
1490
-            // no nav tab for this config
1491
-            // check for persistent flag
1492
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1493
-                // nav tab is only to appear when route requested.
1494
-                continue;
1495
-            }
1496
-            if (! $this->check_user_access($slug, true)) {
1497
-                // no nav tab because current user does not have access.
1498
-                continue;
1499
-            }
1500
-            $css_class = $config['css_class'] ?? '';
1501
-            $css_class .= $only_tab ? ' ee-only-tab' : '';
1502
-            $css_class .= " ee-nav-tab__$slug";
1503
-
1504
-            $this->_nav_tabs[ $slug ] = [
1505
-                'url'       => $config['nav']['url'] ?? EE_Admin_Page::add_query_args_and_nonce(
1506
-                        ['action' => $slug],
1507
-                        $this->_admin_base_url
1508
-                    ),
1509
-                'link_text' => $this->navTabLabel($config['nav'], $slug),
1510
-                'css_class' => $this->_req_action === $slug ? $css_class . ' nav-tab-active' : $css_class,
1511
-                'order'     => $config['nav']['order'] ?? $i,
1512
-            ];
1513
-            $i++;
1514
-        }
1515
-        // if $this->_nav_tabs is empty then lets set the default
1516
-        if (empty($this->_nav_tabs)) {
1517
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1518
-                'url'       => $this->_admin_base_url,
1519
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1520
-                'css_class' => 'nav-tab-active',
1521
-                'order'     => 10,
1522
-            ];
1523
-        }
1524
-        // now let's sort the tabs according to order
1525
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1526
-    }
1527
-
1528
-
1529
-    private function navTabLabel(array $nav_tab, string $slug): string
1530
-    {
1531
-        $label = $nav_tab['label'] ?? ucwords(str_replace('_', ' ', $slug));
1532
-        $icon  = $nav_tab['icon'] ?? null;
1533
-        $icon  = $icon ? '<span class="dashicons ' . $icon . '"></span>' : '';
1534
-        return '
144
+	/**
145
+	 * unprocessed value for the 'page' request param (default '')
146
+	 *
147
+	 * @var string
148
+	 */
149
+	protected $raw_req_page = '';
150
+
151
+	/**
152
+	 * sanitized request action (and nonce)
153
+	 *
154
+	 * @var string
155
+	 */
156
+	protected $_req_action = '';
157
+
158
+	/**
159
+	 * sanitized request action nonce
160
+	 *
161
+	 * @var string
162
+	 */
163
+	protected $_req_nonce = '';
164
+
165
+	/**
166
+	 * @var string
167
+	 */
168
+	protected $_search_btn_label = '';
169
+
170
+	/**
171
+	 * @var string
172
+	 */
173
+	protected $_search_box_callback = '';
174
+
175
+	/**
176
+	 * @var WP_Screen
177
+	 */
178
+	protected $_current_screen;
179
+
180
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
181
+	protected $_hook_obj;
182
+
183
+	// for holding incoming request data
184
+	protected $_req_data = [];
185
+
186
+	// yes / no array for admin form fields
187
+	protected $_yes_no_values = [];
188
+
189
+	// some default things shared by all child classes
190
+	protected $_default_espresso_metaboxes = [
191
+		'_espresso_news_post_box',
192
+		'_espresso_links_post_box',
193
+		'_espresso_ratings_request',
194
+		'_espresso_sponsors_post_box',
195
+	];
196
+
197
+	/**
198
+	 * @var EE_Registry
199
+	 */
200
+	protected $EE;
201
+
202
+
203
+	/**
204
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
205
+	 *
206
+	 * @var boolean
207
+	 */
208
+	protected $_is_caf = false;
209
+
210
+	/**
211
+	 * whether or not initializePage() has run
212
+	 *
213
+	 * @var boolean
214
+	 */
215
+	protected $initialized = false;
216
+
217
+	/**
218
+	 * @var FeatureFlags
219
+	 */
220
+	protected $feature;
221
+
222
+
223
+	/**
224
+	 * @var string
225
+	 */
226
+	protected $class_name;
227
+
228
+	/**
229
+	 * if the current class is an admin page extension, like: Extend_Events_Admin_Page,
230
+	 * then this would be the parent classname: Events_Admin_Page
231
+	 *
232
+	 * @var string
233
+	 */
234
+	protected $base_class_name;
235
+
236
+	/**
237
+	 * @var array
238
+	 * @since $VID:$
239
+	 */
240
+	private $publish_post_meta_box_hidden_fields = [];
241
+
242
+
243
+	/**
244
+	 * @Constructor
245
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
246
+	 * @throws InvalidArgumentException
247
+	 * @throws InvalidDataTypeException
248
+	 * @throws InvalidInterfaceException
249
+	 * @throws ReflectionException
250
+	 */
251
+	public function __construct($routing = true)
252
+	{
253
+		$this->loader       = LoaderFactory::getLoader();
254
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
255
+		$this->feature      = $this->loader->getShared(FeatureFlags::class);
256
+		$this->request      = $this->loader->getShared(RequestInterface::class);
257
+		// routing enabled?
258
+		$this->_routing = $routing;
259
+
260
+		$this->class_name      = get_class($this);
261
+		$this->base_class_name = strpos($this->class_name, 'Extend_') === 0
262
+			? str_replace('Extend_', '', $this->class_name)
263
+			: '';
264
+
265
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
266
+			$this->_is_caf = true;
267
+		}
268
+		$this->_yes_no_values = [
269
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
270
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
271
+		];
272
+		// set the _req_data property.
273
+		$this->_req_data = $this->request->requestParams();
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return EE_Admin_Config
279
+	 */
280
+	public function adminConfig(): EE_Admin_Config
281
+	{
282
+		return $this->admin_config;
283
+	}
284
+
285
+
286
+	/**
287
+	 * @return FeatureFlags
288
+	 */
289
+	public function feature(): FeatureFlags
290
+	{
291
+		return $this->feature;
292
+	}
293
+
294
+
295
+	/**
296
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
297
+	 * for child classes that needed to set properties prior to these methods getting called,
298
+	 * but also needed the parent class to have its construction completed as well.
299
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
300
+	 * and any complex initialization logic should only run after instantiation is complete.
301
+	 *
302
+	 * This method gets called immediately after construction from within
303
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
304
+	 *
305
+	 * @throws EE_Error
306
+	 * @throws InvalidArgumentException
307
+	 * @throws InvalidDataTypeException
308
+	 * @throws InvalidInterfaceException
309
+	 * @throws ReflectionException
310
+	 * @since $VID:$
311
+	 */
312
+	public function initializePage()
313
+	{
314
+		if ($this->initialized) {
315
+			return;
316
+		}
317
+		// set initial page props (child method)
318
+		$this->_init_page_props();
319
+		// set global defaults
320
+		$this->_set_defaults();
321
+		// set early because incoming requests could be ajax related and we need to register those hooks.
322
+		$this->_global_ajax_hooks();
323
+		$this->_ajax_hooks();
324
+		// other_page_hooks have to be early too.
325
+		$this->_do_other_page_hooks();
326
+		// set up page dependencies
327
+		$this->_before_page_setup();
328
+		$this->_page_setup();
329
+		$this->initialized = true;
330
+	}
331
+
332
+
333
+	/**
334
+	 * _init_page_props
335
+	 * Child classes use to set at least the following properties:
336
+	 * $page_slug.
337
+	 * $page_label.
338
+	 *
339
+	 * @abstract
340
+	 * @return void
341
+	 */
342
+	abstract protected function _init_page_props();
343
+
344
+
345
+	/**
346
+	 * _ajax_hooks
347
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
348
+	 * Note: within the ajax callback methods.
349
+	 *
350
+	 * @abstract
351
+	 * @return void
352
+	 */
353
+	abstract protected function _ajax_hooks();
354
+
355
+
356
+	/**
357
+	 * _define_page_props
358
+	 * child classes define page properties in here.  Must include at least:
359
+	 * $_admin_base_url = base_url for all admin pages
360
+	 * $_admin_page_title = default admin_page_title for admin pages
361
+	 * $_labels = array of default labels for various automatically generated elements:
362
+	 *    array(
363
+	 *        'buttons' => array(
364
+	 *            'add' => esc_html__('label for add new button'),
365
+	 *            'edit' => esc_html__('label for edit button'),
366
+	 *            'delete' => esc_html__('label for delete button')
367
+	 *            )
368
+	 *        )
369
+	 *
370
+	 * @abstract
371
+	 * @return void
372
+	 */
373
+	abstract protected function _define_page_props();
374
+
375
+
376
+	/**
377
+	 * _set_page_routes
378
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
379
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
380
+	 * have a 'default' route. Here's the format
381
+	 * $this->_page_routes = array(
382
+	 *        'default' => array(
383
+	 *            'func' => '_default_method_handling_route',
384
+	 *            'args' => array('array','of','args'),
385
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
386
+	 *            ajax request, backend processing)
387
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
388
+	 *            headers route after.  The string you enter here should match the defined route reference for a
389
+	 *            headers sent route.
390
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
391
+	 *            this route.
392
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
393
+	 *            checks).
394
+	 *        ),
395
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
396
+	 *        handling method.
397
+	 *        )
398
+	 * )
399
+	 *
400
+	 * @abstract
401
+	 * @return void
402
+	 */
403
+	abstract protected function _set_page_routes();
404
+
405
+
406
+	/**
407
+	 * _set_page_config
408
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
409
+	 * array corresponds to the page_route for the loaded page. Format:
410
+	 * $this->_page_config = array(
411
+	 *        'default' => array(
412
+	 *            'labels' => array(
413
+	 *                'buttons' => array(
414
+	 *                    'add' => esc_html__('label for adding item'),
415
+	 *                    'edit' => esc_html__('label for editing item'),
416
+	 *                    'delete' => esc_html__('label for deleting item')
417
+	 *                ),
418
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
419
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
420
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
421
+	 *            _define_page_props() method
422
+	 *            'nav' => array(
423
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
424
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
425
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
426
+	 *                'order' => 10, //required to indicate tab position.
427
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
428
+	 *                displayed then add this parameter.
429
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
430
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
431
+	 *            metaboxes set for eventespresso admin pages.
432
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
433
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
434
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
435
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
436
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
437
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
438
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
439
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
440
+	 *            want to display.
441
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
442
+	 *                'tab_id' => array(
443
+	 *                    'title' => 'tab_title',
444
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
445
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
446
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
447
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
448
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
449
+	 *                    attempt to use the callback which should match the name of a method in the class
450
+	 *                    ),
451
+	 *                'tab2_id' => array(
452
+	 *                    'title' => 'tab2 title',
453
+	 *                    'filename' => 'file_name_2'
454
+	 *                    'callback' => 'callback_method_for_content',
455
+	 *                 ),
456
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
457
+	 *            help tab area on an admin page. @return void
458
+	 *
459
+	 * @abstract
460
+	 */
461
+	abstract protected function _set_page_config();
462
+
463
+
464
+	/**
465
+	 * _add_screen_options
466
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
467
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
468
+	 * to a particular view.
469
+	 *
470
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
471
+	 *         see also WP_Screen object documents...
472
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
473
+	 * @abstract
474
+	 * @return void
475
+	 */
476
+	abstract protected function _add_screen_options();
477
+
478
+
479
+	/**
480
+	 * _add_feature_pointers
481
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
482
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
483
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
484
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
485
+	 * extended) also see:
486
+	 *
487
+	 * @link   http://eamann.com/tech/wordpress-portland/
488
+	 * @abstract
489
+	 * @return void
490
+	 */
491
+	abstract protected function _add_feature_pointers();
492
+
493
+
494
+	/**
495
+	 * load_scripts_styles
496
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
497
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
498
+	 * scripts/styles per view by putting them in a dynamic function in this format
499
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
500
+	 *
501
+	 * @abstract
502
+	 * @return void
503
+	 */
504
+	abstract public function load_scripts_styles();
505
+
506
+
507
+	/**
508
+	 * admin_init
509
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
510
+	 * all pages/views loaded by child class.
511
+	 *
512
+	 * @abstract
513
+	 * @return void
514
+	 */
515
+	abstract public function admin_init();
516
+
517
+
518
+	/**
519
+	 * admin_notices
520
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
521
+	 * all pages/views loaded by child class.
522
+	 *
523
+	 * @abstract
524
+	 * @return void
525
+	 */
526
+	abstract public function admin_notices();
527
+
528
+
529
+	/**
530
+	 * admin_footer_scripts
531
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
532
+	 * will apply to all pages/views loaded by child class.
533
+	 *
534
+	 * @return void
535
+	 */
536
+	abstract public function admin_footer_scripts();
537
+
538
+
539
+	/**
540
+	 * admin_footer
541
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
542
+	 * apply to all pages/views loaded by child class.
543
+	 *
544
+	 * @return void
545
+	 */
546
+	public function admin_footer()
547
+	{
548
+	}
549
+
550
+
551
+	/**
552
+	 * _global_ajax_hooks
553
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
554
+	 * Note: within the ajax callback methods.
555
+	 *
556
+	 * @abstract
557
+	 * @return void
558
+	 */
559
+	protected function _global_ajax_hooks()
560
+	{
561
+		// for lazy loading of metabox content
562
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
563
+
564
+		add_action(
565
+			'wp_ajax_espresso_hide_status_change_notice',
566
+			[$this, 'hideStatusChangeNotice']
567
+		);
568
+		add_action(
569
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
570
+			[$this, 'hideStatusChangeNotice']
571
+		);
572
+	}
573
+
574
+
575
+	public function ajax_metabox_content()
576
+	{
577
+		$content_id  = $this->request->getRequestParam('contentid', '');
578
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
579
+		EE_Admin_Page::cached_rss_display($content_id, $content_url);
580
+		wp_die();
581
+	}
582
+
583
+
584
+	public function hideStatusChangeNotice()
585
+	{
586
+		$response = [];
587
+		try {
588
+			/** @var StatusChangeNotice $status_change_notice */
589
+			$status_change_notice = $this->loader->getShared(
590
+				'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
591
+			);
592
+			$response['success']  = $status_change_notice->dismiss() > -1;
593
+		} catch (Exception $exception) {
594
+			$response['errors'] = $exception->getMessage();
595
+		}
596
+		echo wp_json_encode($response);
597
+		exit();
598
+	}
599
+
600
+
601
+	/**
602
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
603
+	 *
604
+	 * @return void
605
+	 */
606
+	protected function _before_page_setup()
607
+	{
608
+		// default is to do nothing
609
+	}
610
+
611
+
612
+	/**
613
+	 * Makes sure any things that need to be loaded early get handled.
614
+	 * We also escape early here if the page requested doesn't match the object.
615
+	 *
616
+	 * @final
617
+	 * @return void
618
+	 * @throws EE_Error
619
+	 * @throws InvalidArgumentException
620
+	 * @throws ReflectionException
621
+	 * @throws InvalidDataTypeException
622
+	 * @throws InvalidInterfaceException
623
+	 */
624
+	final protected function _page_setup()
625
+	{
626
+		// requires?
627
+		// admin_init stuff - global - we're setting this REALLY early
628
+		// so if EE_Admin pages have to hook into other WP pages they can.
629
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
630
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
631
+		// next verify if we need to load anything...
632
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
633
+		$this->_current_page = $this->request->getRequestParam('current_page', $this->_current_page, 'key');
634
+		$this->page_folder   = strtolower(
635
+			str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name)
636
+		);
637
+		global $ee_menu_slugs;
638
+		$ee_menu_slugs = (array) $ee_menu_slugs;
639
+		if (
640
+			! $this->request->isAjax()
641
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
642
+		) {
643
+			return;
644
+		}
645
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
646
+		// we need to copy the action from the second to the first
647
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
648
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
649
+		$action     = $action !== '-1' ? $action : $action2;
650
+		$req_action = $action !== '-1' ? $action : 'default';
651
+
652
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
653
+		// then let's use the route as the action.
654
+		// This covers cases where we're coming in from a list table that isn't on the default route.
655
+		$route             = $this->request->getRequestParam('route');
656
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
657
+			? $route
658
+			: $req_action;
659
+
660
+		$this->_current_view = $this->_req_action;
661
+		$this->_req_nonce    = $this->_req_action . '_nonce';
662
+		$this->_define_page_props();
663
+		$this->_current_page_view_url = add_query_arg(
664
+			['page' => $this->_current_page, 'action' => $this->_current_view],
665
+			$this->_admin_base_url
666
+		);
667
+		// set page configs
668
+		$this->_set_page_routes();
669
+		$this->_set_page_config();
670
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
671
+		if ($this->request->requestParamIsSet('wp_referer')) {
672
+			$wp_referer = $this->request->getRequestParam('wp_referer');
673
+			if ($wp_referer) {
674
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
675
+			}
676
+		}
677
+		// for CPT and other extended functionality.
678
+		// If there is an _extend_page_config_for_cpt
679
+		// then let's run that to modify all the various page configuration arrays.
680
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
681
+			$this->_extend_page_config_for_cpt();
682
+		}
683
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
684
+		$this->_page_routes = apply_filters(
685
+			'FHEE__' . $this->class_name . '__page_setup__page_routes',
686
+			$this->_page_routes,
687
+			$this
688
+		);
689
+		$this->_page_config = apply_filters(
690
+			'FHEE__' . $this->class_name . '__page_setup__page_config',
691
+			$this->_page_config,
692
+			$this
693
+		);
694
+		if ($this->base_class_name !== '') {
695
+			$this->_page_routes = apply_filters(
696
+				'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
697
+				$this->_page_routes,
698
+				$this
699
+			);
700
+			$this->_page_config = apply_filters(
701
+				'FHEE__' . $this->base_class_name . '__page_setup__page_config',
702
+				$this->_page_config,
703
+				$this
704
+			);
705
+		}
706
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
707
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
708
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
709
+			add_action(
710
+				'AHEE__EE_Admin_Page__route_admin_request',
711
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
712
+				10,
713
+				2
714
+			);
715
+		}
716
+		// next route only if routing enabled
717
+		if ($this->_routing && ! $this->request->isAjax()) {
718
+			$this->_verify_routes();
719
+			// next let's just check user_access and kill if no access
720
+			$this->check_user_access();
721
+			if ($this->_is_UI_request) {
722
+				// admin_init stuff - global, all views for this page class, specific view
723
+				add_action('admin_init', [$this, 'admin_init'], 10);
724
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
725
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
726
+				}
727
+			} else {
728
+				// hijack regular WP loading and route admin request immediately
729
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
730
+				$this->route_admin_request();
731
+			}
732
+		}
733
+	}
734
+
735
+
736
+	/**
737
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
738
+	 *
739
+	 * @return void
740
+	 * @throws EE_Error
741
+	 */
742
+	private function _do_other_page_hooks()
743
+	{
744
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
745
+		foreach ($registered_pages as $page) {
746
+			// now let's setup the file name and class that should be present
747
+			$classname = str_replace('.class.php', '', $page);
748
+			// autoloaders should take care of loading file
749
+			if (! class_exists($classname)) {
750
+				$error_msg[] = sprintf(
751
+					esc_html__(
752
+						'Something went wrong with loading the %s admin hooks page.',
753
+						'event_espresso'
754
+					),
755
+					$page
756
+				);
757
+				$error_msg[] = $error_msg[0]
758
+							   . "\r\n"
759
+							   . sprintf(
760
+								   esc_html__(
761
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
762
+									   'event_espresso'
763
+								   ),
764
+								   $page,
765
+								   '<br />',
766
+								   '<strong>' . $classname . '</strong>'
767
+							   );
768
+				throw new EE_Error(implode('||', $error_msg));
769
+			}
770
+			// notice we are passing the instance of this class to the hook object.
771
+			$this->loader->getShared($classname, [$this]);
772
+		}
773
+	}
774
+
775
+
776
+	/**
777
+	 * @throws ReflectionException
778
+	 * @throws EE_Error
779
+	 */
780
+	public function load_page_dependencies()
781
+	{
782
+		try {
783
+			$this->_load_page_dependencies();
784
+		} catch (EE_Error $e) {
785
+			$e->get_error();
786
+		}
787
+	}
788
+
789
+
790
+	/**
791
+	 * load_page_dependencies
792
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
793
+	 *
794
+	 * @return void
795
+	 * @throws DomainException
796
+	 * @throws EE_Error
797
+	 * @throws InvalidArgumentException
798
+	 * @throws InvalidDataTypeException
799
+	 * @throws InvalidInterfaceException
800
+	 * @throws ReflectionException
801
+	 */
802
+	protected function _load_page_dependencies()
803
+	{
804
+		// let's set the current_screen and screen options to override what WP set
805
+		$this->_current_screen = get_current_screen();
806
+		// load admin_notices - global, page class, and view specific
807
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
808
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
809
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
810
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
811
+		}
812
+		// load network admin_notices - global, page class, and view specific
813
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
814
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
815
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
816
+		}
817
+		// this will save any per_page screen options if they are present
818
+		$this->_set_per_page_screen_options();
819
+		// setup list table properties
820
+		$this->_set_list_table();
821
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
822
+		// However in some cases the metaboxes will need to be added within a route handling callback.
823
+		add_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99);
824
+		// hack because promos admin was loading the edited promotion object in the metaboxes callback
825
+		// which should NOT be generated on non-UI requests like POST updates/inserts
826
+		if (
827
+			$this->class_name === 'Promotions_Admin_Page'
828
+			&& ($this->_req_action === 'edit' || $this->_req_action === 'create_new')
829
+		) {
830
+			$this->addRegisteredMetaBoxes();
831
+		}
832
+		$this->_add_screen_columns();
833
+		// add screen options - global, page child class, and view specific
834
+		$this->_add_global_screen_options();
835
+		$this->_add_screen_options();
836
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
837
+		if (method_exists($this, $add_screen_options)) {
838
+			$this->{$add_screen_options}();
839
+		}
840
+		// add help tab(s) - set via page_config and qtips.
841
+		$this->_add_help_tabs();
842
+		$this->_add_qtips();
843
+		// add feature_pointers - global, page child class, and view specific
844
+		$this->_add_feature_pointers();
845
+		$this->_add_global_feature_pointers();
846
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
847
+		if (method_exists($this, $add_feature_pointer)) {
848
+			$this->{$add_feature_pointer}();
849
+		}
850
+		// enqueue scripts/styles - global, page class, and view specific
851
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
852
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
853
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
854
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
855
+		}
856
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
857
+		// admin_print_footer_scripts - global, page child class, and view specific.
858
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
859
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
860
+		// is a good use case. Notice the late priority we're giving these
861
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
862
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
863
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
864
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
865
+		}
866
+		// admin footer scripts
867
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
868
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
869
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
870
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
871
+		}
872
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
873
+		// targeted hook
874
+		do_action(
875
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
876
+		);
877
+	}
878
+
879
+
880
+	/**
881
+	 * _set_defaults
882
+	 * This sets some global defaults for class properties.
883
+	 */
884
+	private function _set_defaults()
885
+	{
886
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
887
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
888
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
889
+		$this->_page_config          = $this->_default_route_query_args = [];
890
+		$this->_default_nav_tab_name = 'overview';
891
+		// init template args
892
+		$this->set_template_args(
893
+			[
894
+				'admin_page_header'  => '',
895
+				'admin_page_content' => '',
896
+				'post_body_content'  => '',
897
+				'before_list_table'  => '',
898
+				'after_list_table'   => '',
899
+			]
900
+		);
901
+	}
902
+
903
+
904
+	/**
905
+	 * route_admin_request
906
+	 *
907
+	 * @return void
908
+	 * @throws InvalidArgumentException
909
+	 * @throws InvalidInterfaceException
910
+	 * @throws InvalidDataTypeException
911
+	 * @throws EE_Error
912
+	 * @throws ReflectionException
913
+	 * @see    _route_admin_request()
914
+	 */
915
+	public function route_admin_request()
916
+	{
917
+		try {
918
+			$this->_route_admin_request();
919
+		} catch (EE_Error $e) {
920
+			$e->get_error();
921
+		}
922
+	}
923
+
924
+
925
+	public function set_wp_page_slug($wp_page_slug)
926
+	{
927
+		$this->_wp_page_slug = $wp_page_slug;
928
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
929
+		if (is_network_admin()) {
930
+			$this->_wp_page_slug .= '-network';
931
+		}
932
+	}
933
+
934
+
935
+	/**
936
+	 * _verify_routes
937
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
938
+	 * we know if we need to drop out.
939
+	 *
940
+	 * @return bool
941
+	 * @throws EE_Error
942
+	 */
943
+	protected function _verify_routes()
944
+	{
945
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
946
+		if (! $this->_current_page && ! $this->request->isAjax()) {
947
+			return false;
948
+		}
949
+		$this->_route = false;
950
+		// check that the page_routes array is not empty
951
+		if (empty($this->_page_routes)) {
952
+			// user error msg
953
+			$error_msg = sprintf(
954
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
955
+				$this->_admin_page_title
956
+			);
957
+			// developer error msg
958
+			$error_msg .= '||' . $error_msg
959
+						  . esc_html__(
960
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
961
+							  'event_espresso'
962
+						  );
963
+			throw new EE_Error($error_msg);
964
+		}
965
+		// and that the requested page route exists
966
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
967
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
968
+			$this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
969
+		} else {
970
+			// user error msg
971
+			$error_msg = sprintf(
972
+				esc_html__(
973
+					'The requested page route does not exist for the %s admin page.',
974
+					'event_espresso'
975
+				),
976
+				$this->_admin_page_title
977
+			);
978
+			// developer error msg
979
+			$error_msg .= '||' . $error_msg
980
+						  . sprintf(
981
+							  esc_html__(
982
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
983
+								  'event_espresso'
984
+							  ),
985
+							  $this->_req_action
986
+						  );
987
+			throw new EE_Error($error_msg);
988
+		}
989
+		// and that a default route exists
990
+		if (! array_key_exists('default', $this->_page_routes)) {
991
+			// user error msg
992
+			$error_msg = sprintf(
993
+				esc_html__(
994
+					'A default page route has not been set for the % admin page.',
995
+					'event_espresso'
996
+				),
997
+				$this->_admin_page_title
998
+			);
999
+			// developer error msg
1000
+			$error_msg .= '||' . $error_msg
1001
+						  . esc_html__(
1002
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
1003
+							  'event_espresso'
1004
+						  );
1005
+			throw new EE_Error($error_msg);
1006
+		}
1007
+
1008
+		// first lets' catch if the UI request has EVER been set.
1009
+		if ($this->_is_UI_request === null) {
1010
+			// lets set if this is a UI request or not.
1011
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
1012
+			// wait a minute... we might have a noheader in the route array
1013
+			$this->_is_UI_request = ! (
1014
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
1015
+			)
1016
+				? $this->_is_UI_request
1017
+				: false;
1018
+		}
1019
+		$this->_set_current_labels();
1020
+		return true;
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
1026
+	 *
1027
+	 * @param string $route the route name we're verifying
1028
+	 * @return bool we'll throw an exception if this isn't a valid route.
1029
+	 * @throws EE_Error
1030
+	 */
1031
+	protected function _verify_route($route)
1032
+	{
1033
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
1034
+			return true;
1035
+		}
1036
+		// user error msg
1037
+		$error_msg = sprintf(
1038
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
1039
+			$this->_admin_page_title
1040
+		);
1041
+		// developer error msg
1042
+		$error_msg .= '||' . $error_msg
1043
+					  . sprintf(
1044
+						  esc_html__(
1045
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
1046
+							  'event_espresso'
1047
+						  ),
1048
+						  $route
1049
+					  );
1050
+		throw new EE_Error($error_msg);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * perform nonce verification
1056
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1057
+	 * using this method (and save retyping!)
1058
+	 *
1059
+	 * @param string $nonce     The nonce sent
1060
+	 * @param string $nonce_ref The nonce reference string (name0)
1061
+	 * @return void
1062
+	 * @throws EE_Error
1063
+	 * @throws InvalidArgumentException
1064
+	 * @throws InvalidDataTypeException
1065
+	 * @throws InvalidInterfaceException
1066
+	 */
1067
+	protected function _verify_nonce($nonce, $nonce_ref)
1068
+	{
1069
+		// verify nonce against expected value
1070
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
1071
+			// these are not the droids you are looking for !!!
1072
+			$msg = sprintf(
1073
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
1074
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1075
+				'</a>'
1076
+			);
1077
+			if (WP_DEBUG) {
1078
+				$msg .= "\n  ";
1079
+				$msg .= sprintf(
1080
+					esc_html__(
1081
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1082
+						'event_espresso'
1083
+					),
1084
+					__CLASS__
1085
+				);
1086
+			}
1087
+			if (! $this->request->isAjax()) {
1088
+				wp_die($msg);
1089
+			}
1090
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1091
+			$this->_return_json();
1092
+		}
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * _route_admin_request()
1098
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1099
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1100
+	 * in the page routes and then will try to load the corresponding method.
1101
+	 *
1102
+	 * @return void
1103
+	 * @throws EE_Error
1104
+	 * @throws InvalidArgumentException
1105
+	 * @throws InvalidDataTypeException
1106
+	 * @throws InvalidInterfaceException
1107
+	 * @throws ReflectionException
1108
+	 */
1109
+	protected function _route_admin_request()
1110
+	{
1111
+		if (! $this->_is_UI_request) {
1112
+			$this->_verify_routes();
1113
+		}
1114
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1115
+		if ($this->_req_action !== 'default' && $nonce_check) {
1116
+			// set nonce from post data
1117
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
1118
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1119
+		}
1120
+		// set the nav_tabs array but ONLY if this is  UI_request
1121
+		if ($this->_is_UI_request) {
1122
+			$this->_set_nav_tabs();
1123
+		}
1124
+		// grab callback function
1125
+		$func = is_array($this->_route) && isset($this->_route['func'])
1126
+			? $this->_route['func']
1127
+			: $this->_route;
1128
+		// check if callback has args
1129
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1130
+		// action right before calling route
1131
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1132
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1133
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1134
+		}
1135
+		// strip _wp_http_referer from the server REQUEST_URI
1136
+		// else it grows in length on every submission due to recursion,
1137
+		// ultimately causing a "Request-URI Too Large" error
1138
+		$this->request->unSetRequestParam('_wp_http_referer');
1139
+		$this->request->unSetServerParam('_wp_http_referer');
1140
+		$cleaner_request_uri = remove_query_arg(
1141
+			'_wp_http_referer',
1142
+			wp_unslash($this->request->getServerParam('REQUEST_URI'))
1143
+		);
1144
+		$this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri, true);
1145
+		$this->request->setServerParam('REQUEST_URI', $cleaner_request_uri, true);
1146
+		$route_callback = [];
1147
+		if (! empty($func)) {
1148
+			if (is_array($func)) {
1149
+				$route_callback = $func;
1150
+			} elseif (is_string($func)) {
1151
+				if (strpos($func, '::') !== false) {
1152
+					$route_callback = explode('::', $func);
1153
+				} elseif (method_exists($this, $func)) {
1154
+					$route_callback = [$this, $func];
1155
+				} else {
1156
+					$route_callback = $func;
1157
+				}
1158
+			}
1159
+			[$class, $method] = $route_callback;
1160
+			// is it neither a class method NOR a standalone function?
1161
+			if (! is_callable($route_callback)) {
1162
+				// user error msg
1163
+				$error_msg = esc_html__(
1164
+					'An error occurred. The  requested page route could not be found.',
1165
+					'event_espresso'
1166
+				);
1167
+				// developer error msg
1168
+				$error_msg .= '||';
1169
+				$error_msg .= sprintf(
1170
+					esc_html__(
1171
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1172
+						'event_espresso'
1173
+					),
1174
+					$method
1175
+				);
1176
+				throw new DomainException($error_msg);
1177
+			}
1178
+			if ($class !== $this && ! in_array($this, $args)) {
1179
+				// send along this admin page object for access by addons.
1180
+				$args['admin_page'] = $this;
1181
+			}
1182
+
1183
+			try {
1184
+				call_user_func_array($route_callback, $args);
1185
+			} catch (Throwable $throwable) {
1186
+				$arg_keys = array_keys($args);
1187
+				$nice_args = [];
1188
+				foreach ($args as $key => $arg) {
1189
+					$nice_args[ $key ] = is_object($arg) ? get_class($arg) : $arg_keys[ $key ];
1190
+				}
1191
+				new ExceptionStackTraceDisplay(
1192
+						new RuntimeException(
1193
+							sprintf(
1194
+								esc_html__(
1195
+									'Page route "%1$s" with the supplied arguments (%2$s) threw the following exception: %3$s',
1196
+									'event_espresso'
1197
+								),
1198
+								$method,
1199
+								implode(', ', $nice_args),
1200
+								$throwable->getMessage()
1201
+							),
1202
+							$throwable->getCode(),
1203
+							$throwable
1204
+						)
1205
+				);
1206
+			}
1207
+		}
1208
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1209
+		// then we need to reset the routing properties to the new route.
1210
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1211
+		if (
1212
+			$this->_is_UI_request === false
1213
+			&& is_array($this->_route)
1214
+			&& ! empty($this->_route['headers_sent_route'])
1215
+		) {
1216
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1217
+		}
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * This method just allows the resetting of page properties in the case where a no headers
1223
+	 * route redirects to a headers route in its route config.
1224
+	 *
1225
+	 * @param string $new_route New (non header) route to redirect to.
1226
+	 * @return   void
1227
+	 * @throws ReflectionException
1228
+	 * @throws InvalidArgumentException
1229
+	 * @throws InvalidInterfaceException
1230
+	 * @throws InvalidDataTypeException
1231
+	 * @throws EE_Error
1232
+	 * @since   4.3.0
1233
+	 */
1234
+	protected function _reset_routing_properties($new_route)
1235
+	{
1236
+		$this->_is_UI_request = true;
1237
+		// now we set the current route to whatever the headers_sent_route is set at
1238
+		$this->request->setRequestParam('action', $new_route);
1239
+		// rerun page setup
1240
+		$this->_page_setup();
1241
+	}
1242
+
1243
+
1244
+	/**
1245
+	 * _add_query_arg
1246
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1247
+	 *(internally just uses EEH_URL's function with the same name)
1248
+	 *
1249
+	 * @param array  $args
1250
+	 * @param string $url
1251
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1252
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1253
+	 *                                        Example usage: If the current page is:
1254
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1255
+	 *                                        &action=default&event_id=20&month_range=March%202015
1256
+	 *                                        &_wpnonce=5467821
1257
+	 *                                        and you call:
1258
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1259
+	 *                                        array(
1260
+	 *                                        'action' => 'resend_something',
1261
+	 *                                        'page=>espresso_registrations'
1262
+	 *                                        ),
1263
+	 *                                        $some_url,
1264
+	 *                                        true
1265
+	 *                                        );
1266
+	 *                                        It will produce a url in this structure:
1267
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1268
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1269
+	 *                                        month_range]=March%202015
1270
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1271
+	 * @param int    $context
1272
+	 * @return string
1273
+	 */
1274
+	public static function add_query_args_and_nonce(
1275
+		$args = [],
1276
+		$url = '',
1277
+		$sticky = false,
1278
+		$exclude_nonce = false,
1279
+		int $context = EEH_URL::CONTEXT_NONE
1280
+	) {
1281
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1282
+		if ($sticky) {
1283
+			/** @var RequestInterface $request */
1284
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1285
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1286
+			$request->unSetServerParam('_wp_http_referer', true);
1287
+			foreach ($request->requestParams() as $key => $value) {
1288
+				// do not add nonces
1289
+				if (strpos($key, 'nonce') !== false) {
1290
+					continue;
1291
+				}
1292
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1293
+			}
1294
+		}
1295
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce, $context);
1296
+	}
1297
+
1298
+
1299
+	/**
1300
+	 * This returns a generated link that will load the related help tab.
1301
+	 *
1302
+	 * @param string $help_tab_id the id for the connected help tab
1303
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1304
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1305
+	 * @return string              generated link
1306
+	 * @uses EEH_Template::get_help_tab_link()
1307
+	 */
1308
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1309
+	{
1310
+		return EEH_Template::get_help_tab_link(
1311
+			$help_tab_id,
1312
+			$this->page_slug,
1313
+			$this->_req_action,
1314
+			$icon_style,
1315
+			$help_text
1316
+		);
1317
+	}
1318
+
1319
+
1320
+	/**
1321
+	 * _add_help_tabs
1322
+	 * Note child classes define their help tabs within the page_config array.
1323
+	 *
1324
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1325
+	 * @return void
1326
+	 * @throws DomainException
1327
+	 * @throws EE_Error
1328
+	 * @throws ReflectionException
1329
+	 */
1330
+	protected function _add_help_tabs()
1331
+	{
1332
+		if (isset($this->_page_config[ $this->_req_action ])) {
1333
+			$config = $this->_page_config[ $this->_req_action ];
1334
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1335
+			if (is_array($config) && isset($config['help_sidebar'])) {
1336
+				// check that the callback given is valid
1337
+				if (! method_exists($this, $config['help_sidebar'])) {
1338
+					throw new EE_Error(
1339
+						sprintf(
1340
+							esc_html__(
1341
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1342
+								'event_espresso'
1343
+							),
1344
+							$config['help_sidebar'],
1345
+							$this->class_name
1346
+						)
1347
+					);
1348
+				}
1349
+				$content = apply_filters(
1350
+					'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1351
+					$this->{$config['help_sidebar']}()
1352
+				);
1353
+				$this->_current_screen->set_help_sidebar($content);
1354
+			}
1355
+			if (! isset($config['help_tabs'])) {
1356
+				return;
1357
+			} //no help tabs for this route
1358
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1359
+				// we're here so there ARE help tabs!
1360
+				// make sure we've got what we need
1361
+				if (! isset($cfg['title'])) {
1362
+					throw new EE_Error(
1363
+						esc_html__(
1364
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1365
+							'event_espresso'
1366
+						)
1367
+					);
1368
+				}
1369
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1370
+					throw new EE_Error(
1371
+						esc_html__(
1372
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1373
+							'event_espresso'
1374
+						)
1375
+					);
1376
+				}
1377
+				// first priority goes to content.
1378
+				if (! empty($cfg['content'])) {
1379
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1380
+					// second priority goes to filename
1381
+				} elseif (! empty($cfg['filename'])) {
1382
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1383
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1384
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1385
+															 . basename($this->_get_dir())
1386
+															 . '/help_tabs/'
1387
+															 . $cfg['filename']
1388
+															 . '.help_tab.php' : $file_path;
1389
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1390
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1391
+						EE_Error::add_error(
1392
+							sprintf(
1393
+								esc_html__(
1394
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1395
+									'event_espresso'
1396
+								),
1397
+								$tab_id,
1398
+								key($config),
1399
+								$file_path
1400
+							),
1401
+							__FILE__,
1402
+							__FUNCTION__,
1403
+							__LINE__
1404
+						);
1405
+						return;
1406
+					}
1407
+					$template_args['admin_page_obj'] = $this;
1408
+					$content                         = EEH_Template::display_template(
1409
+						$file_path,
1410
+						$template_args,
1411
+						true
1412
+					);
1413
+				} else {
1414
+					$content = '';
1415
+				}
1416
+				// check if callback is valid
1417
+				if (
1418
+					empty($content)
1419
+					&& (
1420
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1421
+					)
1422
+				) {
1423
+					EE_Error::add_error(
1424
+						sprintf(
1425
+							esc_html__(
1426
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1427
+								'event_espresso'
1428
+							),
1429
+							$cfg['title']
1430
+						),
1431
+						__FILE__,
1432
+						__FUNCTION__,
1433
+						__LINE__
1434
+					);
1435
+					return;
1436
+				}
1437
+				// setup config array for help tab method
1438
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1439
+				$_ht = [
1440
+					'id'       => $id,
1441
+					'title'    => $cfg['title'],
1442
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1443
+					'content'  => $content,
1444
+				];
1445
+				$this->_current_screen->add_help_tab($_ht);
1446
+			}
1447
+		}
1448
+	}
1449
+
1450
+
1451
+	/**
1452
+	 * This simply sets up any qtips that have been defined in the page config
1453
+	 *
1454
+	 * @return void
1455
+	 * @throws ReflectionException
1456
+	 * @throws EE_Error
1457
+	 */
1458
+	protected function _add_qtips()
1459
+	{
1460
+		if (isset($this->_route_config['qtips'])) {
1461
+			$qtips = (array) $this->_route_config['qtips'];
1462
+			// load qtip loader
1463
+			$path = [
1464
+				$this->_get_dir() . '/qtips/',
1465
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1466
+			];
1467
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1468
+		}
1469
+	}
1470
+
1471
+
1472
+	/**
1473
+	 * _set_nav_tabs
1474
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1475
+	 * wish to add additional tabs or modify accordingly.
1476
+	 *
1477
+	 * @return void
1478
+	 * @throws InvalidArgumentException
1479
+	 * @throws InvalidInterfaceException
1480
+	 * @throws InvalidDataTypeException
1481
+	 */
1482
+	protected function _set_nav_tabs()
1483
+	{
1484
+		$i        = 0;
1485
+		$only_tab = count($this->_page_config) < 2;
1486
+		foreach ($this->_page_config as $slug => $config) {
1487
+			if (! is_array($config) || empty($config['nav'])) {
1488
+				continue;
1489
+			}
1490
+			// no nav tab for this config
1491
+			// check for persistent flag
1492
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1493
+				// nav tab is only to appear when route requested.
1494
+				continue;
1495
+			}
1496
+			if (! $this->check_user_access($slug, true)) {
1497
+				// no nav tab because current user does not have access.
1498
+				continue;
1499
+			}
1500
+			$css_class = $config['css_class'] ?? '';
1501
+			$css_class .= $only_tab ? ' ee-only-tab' : '';
1502
+			$css_class .= " ee-nav-tab__$slug";
1503
+
1504
+			$this->_nav_tabs[ $slug ] = [
1505
+				'url'       => $config['nav']['url'] ?? EE_Admin_Page::add_query_args_and_nonce(
1506
+						['action' => $slug],
1507
+						$this->_admin_base_url
1508
+					),
1509
+				'link_text' => $this->navTabLabel($config['nav'], $slug),
1510
+				'css_class' => $this->_req_action === $slug ? $css_class . ' nav-tab-active' : $css_class,
1511
+				'order'     => $config['nav']['order'] ?? $i,
1512
+			];
1513
+			$i++;
1514
+		}
1515
+		// if $this->_nav_tabs is empty then lets set the default
1516
+		if (empty($this->_nav_tabs)) {
1517
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1518
+				'url'       => $this->_admin_base_url,
1519
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1520
+				'css_class' => 'nav-tab-active',
1521
+				'order'     => 10,
1522
+			];
1523
+		}
1524
+		// now let's sort the tabs according to order
1525
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1526
+	}
1527
+
1528
+
1529
+	private function navTabLabel(array $nav_tab, string $slug): string
1530
+	{
1531
+		$label = $nav_tab['label'] ?? ucwords(str_replace('_', ' ', $slug));
1532
+		$icon  = $nav_tab['icon'] ?? null;
1533
+		$icon  = $icon ? '<span class="dashicons ' . $icon . '"></span>' : '';
1534
+		return '
1535 1535
             <span class="ee-admin-screen-tab__label">
1536 1536
                 ' . $icon . '
1537 1537
                 <span class="ee-nav-label__text">' . $label . '</span>
1538 1538
             </span>';
1539
-    }
1540
-
1541
-
1542
-    /**
1543
-     * _set_current_labels
1544
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1545
-     * property array
1546
-     *
1547
-     * @return void
1548
-     */
1549
-    private function _set_current_labels()
1550
-    {
1551
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1552
-            foreach ($this->_route_config['labels'] as $label => $text) {
1553
-                if (is_array($text)) {
1554
-                    foreach ($text as $sublabel => $subtext) {
1555
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1556
-                    }
1557
-                } else {
1558
-                    $this->_labels[ $label ] = $text;
1559
-                }
1560
-            }
1561
-        }
1562
-    }
1563
-
1564
-
1565
-    /**
1566
-     *        verifies user access for this admin page
1567
-     *
1568
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1569
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1570
-     *                               return false if verify fail.
1571
-     * @return bool
1572
-     * @throws InvalidArgumentException
1573
-     * @throws InvalidDataTypeException
1574
-     * @throws InvalidInterfaceException
1575
-     */
1576
-    public function check_user_access($route_to_check = '', $verify_only = false)
1577
-    {
1578
-        $route_to_check = ! empty($route_to_check) ? $route_to_check : $this->_req_action;
1579
-        $capability     = ! empty($route_to_check)
1580
-                          && isset($this->_page_routes[ $route_to_check ])
1581
-                          && is_array($this->_page_routes[ $route_to_check ])
1582
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1583
-            ? $this->_page_routes[ $route_to_check ]['capability']
1584
-            : null;
1585
-
1586
-        if (empty($capability) && empty($route_to_check)) {
1587
-            $capability = ! empty($this->_route['capability']) ? $this->_route['capability'] : 'manage_options';
1588
-        } else {
1589
-            $capability = empty($capability) ? 'manage_options' : $capability;
1590
-        }
1591
-
1592
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1593
-
1594
-        if (
1595
-            ! $this->request->isAjax()
1596
-            && (
1597
-                ! function_exists('is_admin')
1598
-                || ! EE_Registry::instance()->CAP->current_user_can(
1599
-                    $capability,
1600
-                    "{$this->page_slug}_$route_to_check",
1601
-                    $id
1602
-                )
1603
-            )
1604
-        ) {
1605
-            if ($verify_only) {
1606
-                return false;
1607
-            }
1608
-            if (is_user_logged_in()) {
1609
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1610
-            }
1611
-            return false;
1612
-        }
1613
-        return true;
1614
-    }
1615
-
1616
-
1617
-    /**
1618
-     * @param string                 $box_id
1619
-     * @param string                 $title
1620
-     * @param callable|string|null   $callback
1621
-     * @param string|array|WP_Screen $screen
1622
-     * @param string                 $context
1623
-     * @param string                 $priority
1624
-     * @param array|null             $callback_args
1625
-     */
1626
-    protected function addMetaBox(
1627
-        string $box_id,
1628
-        string $title,
1629
-        $callback,
1630
-        $screen,
1631
-        string $context = 'normal',
1632
-        string $priority = 'default',
1633
-        ?array $callback_args = null
1634
-    ) {
1635
-        if (! (is_callable($callback) || ! function_exists($callback))) {
1636
-            return;
1637
-        }
1638
-
1639
-        add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1640
-        add_filter(
1641
-            "postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1642
-            function ($classes) {
1643
-                $classes[] = 'ee-admin-container';
1644
-                return $classes;
1645
-            }
1646
-        );
1647
-    }
1648
-
1649
-
1650
-    /**
1651
-     * admin_init_global
1652
-     * This runs all the code that we want executed within the WP admin_init hook.
1653
-     * This method executes for ALL EE Admin pages.
1654
-     *
1655
-     * @return void
1656
-     */
1657
-    public function admin_init_global()
1658
-    {
1659
-    }
1660
-
1661
-
1662
-    /**
1663
-     * wp_loaded_global
1664
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1665
-     * EE_Admin page and will execute on every EE Admin Page load
1666
-     *
1667
-     * @return void
1668
-     */
1669
-    public function wp_loaded()
1670
-    {
1671
-    }
1672
-
1673
-
1674
-    /**
1675
-     * admin_notices
1676
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1677
-     * ALL EE_Admin pages.
1678
-     *
1679
-     * @return void
1680
-     */
1681
-    public function admin_notices_global()
1682
-    {
1683
-        $this->_display_no_javascript_warning();
1684
-        $this->_display_espresso_notices();
1685
-    }
1686
-
1687
-
1688
-    public function network_admin_notices_global()
1689
-    {
1690
-        $this->_display_no_javascript_warning();
1691
-        $this->_display_espresso_notices();
1692
-    }
1693
-
1694
-
1695
-    /**
1696
-     * admin_footer_scripts_global
1697
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1698
-     * will apply on ALL EE_Admin pages.
1699
-     *
1700
-     * @return void
1701
-     */
1702
-    public function admin_footer_scripts_global()
1703
-    {
1704
-        $this->_add_admin_page_ajax_loading_img();
1705
-        $this->_add_admin_page_overlay();
1706
-        // if metaboxes are present we need to add the nonce field
1707
-        if (
1708
-            isset($this->_route_config['metaboxes'])
1709
-            || isset($this->_route_config['list_table'])
1710
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1711
-        ) {
1712
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1713
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1714
-        }
1715
-    }
1716
-
1717
-
1718
-    /**
1719
-     * admin_footer_global
1720
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1721
-     * This particular method will apply on ALL EE_Admin Pages.
1722
-     *
1723
-     * @return void
1724
-     */
1725
-    public function admin_footer_global()
1726
-    {
1727
-        // dialog container for dialog helper
1728
-        echo '
1539
+	}
1540
+
1541
+
1542
+	/**
1543
+	 * _set_current_labels
1544
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1545
+	 * property array
1546
+	 *
1547
+	 * @return void
1548
+	 */
1549
+	private function _set_current_labels()
1550
+	{
1551
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1552
+			foreach ($this->_route_config['labels'] as $label => $text) {
1553
+				if (is_array($text)) {
1554
+					foreach ($text as $sublabel => $subtext) {
1555
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1556
+					}
1557
+				} else {
1558
+					$this->_labels[ $label ] = $text;
1559
+				}
1560
+			}
1561
+		}
1562
+	}
1563
+
1564
+
1565
+	/**
1566
+	 *        verifies user access for this admin page
1567
+	 *
1568
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1569
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1570
+	 *                               return false if verify fail.
1571
+	 * @return bool
1572
+	 * @throws InvalidArgumentException
1573
+	 * @throws InvalidDataTypeException
1574
+	 * @throws InvalidInterfaceException
1575
+	 */
1576
+	public function check_user_access($route_to_check = '', $verify_only = false)
1577
+	{
1578
+		$route_to_check = ! empty($route_to_check) ? $route_to_check : $this->_req_action;
1579
+		$capability     = ! empty($route_to_check)
1580
+						  && isset($this->_page_routes[ $route_to_check ])
1581
+						  && is_array($this->_page_routes[ $route_to_check ])
1582
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1583
+			? $this->_page_routes[ $route_to_check ]['capability']
1584
+			: null;
1585
+
1586
+		if (empty($capability) && empty($route_to_check)) {
1587
+			$capability = ! empty($this->_route['capability']) ? $this->_route['capability'] : 'manage_options';
1588
+		} else {
1589
+			$capability = empty($capability) ? 'manage_options' : $capability;
1590
+		}
1591
+
1592
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1593
+
1594
+		if (
1595
+			! $this->request->isAjax()
1596
+			&& (
1597
+				! function_exists('is_admin')
1598
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1599
+					$capability,
1600
+					"{$this->page_slug}_$route_to_check",
1601
+					$id
1602
+				)
1603
+			)
1604
+		) {
1605
+			if ($verify_only) {
1606
+				return false;
1607
+			}
1608
+			if (is_user_logged_in()) {
1609
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1610
+			}
1611
+			return false;
1612
+		}
1613
+		return true;
1614
+	}
1615
+
1616
+
1617
+	/**
1618
+	 * @param string                 $box_id
1619
+	 * @param string                 $title
1620
+	 * @param callable|string|null   $callback
1621
+	 * @param string|array|WP_Screen $screen
1622
+	 * @param string                 $context
1623
+	 * @param string                 $priority
1624
+	 * @param array|null             $callback_args
1625
+	 */
1626
+	protected function addMetaBox(
1627
+		string $box_id,
1628
+		string $title,
1629
+		$callback,
1630
+		$screen,
1631
+		string $context = 'normal',
1632
+		string $priority = 'default',
1633
+		?array $callback_args = null
1634
+	) {
1635
+		if (! (is_callable($callback) || ! function_exists($callback))) {
1636
+			return;
1637
+		}
1638
+
1639
+		add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1640
+		add_filter(
1641
+			"postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1642
+			function ($classes) {
1643
+				$classes[] = 'ee-admin-container';
1644
+				return $classes;
1645
+			}
1646
+		);
1647
+	}
1648
+
1649
+
1650
+	/**
1651
+	 * admin_init_global
1652
+	 * This runs all the code that we want executed within the WP admin_init hook.
1653
+	 * This method executes for ALL EE Admin pages.
1654
+	 *
1655
+	 * @return void
1656
+	 */
1657
+	public function admin_init_global()
1658
+	{
1659
+	}
1660
+
1661
+
1662
+	/**
1663
+	 * wp_loaded_global
1664
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1665
+	 * EE_Admin page and will execute on every EE Admin Page load
1666
+	 *
1667
+	 * @return void
1668
+	 */
1669
+	public function wp_loaded()
1670
+	{
1671
+	}
1672
+
1673
+
1674
+	/**
1675
+	 * admin_notices
1676
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1677
+	 * ALL EE_Admin pages.
1678
+	 *
1679
+	 * @return void
1680
+	 */
1681
+	public function admin_notices_global()
1682
+	{
1683
+		$this->_display_no_javascript_warning();
1684
+		$this->_display_espresso_notices();
1685
+	}
1686
+
1687
+
1688
+	public function network_admin_notices_global()
1689
+	{
1690
+		$this->_display_no_javascript_warning();
1691
+		$this->_display_espresso_notices();
1692
+	}
1693
+
1694
+
1695
+	/**
1696
+	 * admin_footer_scripts_global
1697
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1698
+	 * will apply on ALL EE_Admin pages.
1699
+	 *
1700
+	 * @return void
1701
+	 */
1702
+	public function admin_footer_scripts_global()
1703
+	{
1704
+		$this->_add_admin_page_ajax_loading_img();
1705
+		$this->_add_admin_page_overlay();
1706
+		// if metaboxes are present we need to add the nonce field
1707
+		if (
1708
+			isset($this->_route_config['metaboxes'])
1709
+			|| isset($this->_route_config['list_table'])
1710
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1711
+		) {
1712
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1713
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1714
+		}
1715
+	}
1716
+
1717
+
1718
+	/**
1719
+	 * admin_footer_global
1720
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1721
+	 * This particular method will apply on ALL EE_Admin Pages.
1722
+	 *
1723
+	 * @return void
1724
+	 */
1725
+	public function admin_footer_global()
1726
+	{
1727
+		// dialog container for dialog helper
1728
+		echo '
1729 1729
         <div class="ee-admin-dialog-container auto-hide hidden">
1730 1730
             <div class="ee-notices"></div>
1731 1731
             <div class="ee-admin-dialog-container-inner-content"></div>
1732 1732
         </div>
1733 1733
         ';
1734 1734
 
1735
-        // current set timezone for timezone js
1736
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1737
-    }
1738
-
1739
-
1740
-    /**
1741
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1742
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1743
-     * help popups then in your templates or your content you set "triggers" for the content using the
1744
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1745
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1746
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1747
-     * for the
1748
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1749
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1750
-     *    'help_trigger_id' => array(
1751
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1752
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1753
-     *    )
1754
-     * );
1755
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1756
-     *
1757
-     * @param array $help_array
1758
-     * @param bool  $display
1759
-     * @return string content
1760
-     * @throws DomainException
1761
-     * @throws EE_Error
1762
-     */
1763
-    protected function _set_help_popup_content($help_array = [], $display = false)
1764
-    {
1765
-        $content    = '';
1766
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1767
-        // loop through the array and setup content
1768
-        foreach ($help_array as $trigger => $help) {
1769
-            // make sure the array is setup properly
1770
-            if (! isset($help['title'], $help['content'])) {
1771
-                throw new EE_Error(
1772
-                    esc_html__(
1773
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1774
-                        'event_espresso'
1775
-                    )
1776
-                );
1777
-            }
1778
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1779
-            $template_args = [
1780
-                'help_popup_id'      => $trigger,
1781
-                'help_popup_title'   => $help['title'],
1782
-                'help_popup_content' => $help['content'],
1783
-            ];
1784
-            $content       .= EEH_Template::display_template(
1785
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1786
-                $template_args,
1787
-                true
1788
-            );
1789
-        }
1790
-        if ($display) {
1791
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1792
-            return '';
1793
-        }
1794
-        return $content;
1795
-    }
1796
-
1797
-
1798
-    /**
1799
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1800
-     *
1801
-     * @return array properly formatted array for help popup content
1802
-     * @throws EE_Error
1803
-     */
1804
-    private function _get_help_content()
1805
-    {
1806
-        // what is the method we're looking for?
1807
-        $method_name = '_help_popup_content_' . $this->_req_action;
1808
-        // if method doesn't exist let's get out.
1809
-        if (! method_exists($this, $method_name)) {
1810
-            return [];
1811
-        }
1812
-        // k we're good to go let's retrieve the help array
1813
-        $help_array = $this->{$method_name}();
1814
-        // make sure we've got an array!
1815
-        if (! is_array($help_array)) {
1816
-            throw new EE_Error(
1817
-                esc_html__(
1818
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1819
-                    'event_espresso'
1820
-                )
1821
-            );
1822
-        }
1823
-        return $help_array;
1824
-    }
1825
-
1826
-
1827
-    /**
1828
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1829
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1830
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1831
-     *
1832
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1833
-     * @param boolean $display    if false then we return the trigger string
1834
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1835
-     * @return string
1836
-     * @throws DomainException
1837
-     * @throws EE_Error
1838
-     */
1839
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1840
-    {
1841
-        if ($this->request->isAjax()) {
1842
-            return '';
1843
-        }
1844
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1845
-        $help_array   = $this->_get_help_content();
1846
-        $help_content = '';
1847
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1848
-            $help_array[ $trigger_id ] = [
1849
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1850
-                'content' => esc_html__(
1851
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1852
-                    'event_espresso'
1853
-                ),
1854
-            ];
1855
-            $help_content              = $this->_set_help_popup_content($help_array);
1856
-        }
1857
-        // let's setup the trigger
1858
-        $content = '<a class="ee-dialog" href="?height='
1859
-                   . esc_attr($dimensions[0])
1860
-                   . '&width='
1861
-                   . esc_attr($dimensions[1])
1862
-                   . '&inlineId='
1863
-                   . esc_attr($trigger_id)
1864
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1865
-        $content .= $help_content;
1866
-        if ($display) {
1867
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1868
-            return '';
1869
-        }
1870
-        return $content;
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     * _add_global_screen_options
1876
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1877
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1878
-     *
1879
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1880
-     *         see also WP_Screen object documents...
1881
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1882
-     * @abstract
1883
-     * @return void
1884
-     */
1885
-    private function _add_global_screen_options()
1886
-    {
1887
-    }
1888
-
1889
-
1890
-    /**
1891
-     * _add_global_feature_pointers
1892
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1893
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1894
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1895
-     *
1896
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1897
-     *         extended) also see:
1898
-     * @link   http://eamann.com/tech/wordpress-portland/
1899
-     * @abstract
1900
-     * @return void
1901
-     */
1902
-    private function _add_global_feature_pointers()
1903
-    {
1904
-    }
1905
-
1906
-
1907
-    /**
1908
-     * load_global_scripts_styles
1909
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1910
-     *
1911
-     * @return void
1912
-     */
1913
-    public function load_global_scripts_styles()
1914
-    {
1915
-        // add debugging styles
1916
-        if (WP_DEBUG) {
1917
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1918
-        }
1919
-        // taking care of metaboxes
1920
-        if (
1921
-            empty($this->_cpt_route)
1922
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1923
-        ) {
1924
-            wp_enqueue_script('dashboard');
1925
-        }
1926
-
1927
-        wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH);
1928
-        wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
1929
-        // LOCALIZED DATA
1930
-        // localize script for ajax lazy loading
1931
-        wp_localize_script(
1932
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1933
-            'eeLazyLoadingContainers',
1934
-            apply_filters(
1935
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1936
-                ['espresso_news_post_box_content']
1937
-            )
1938
-        );
1939
-        StatusChangeNotice::loadAssets();
1940
-
1941
-        add_filter(
1942
-            'admin_body_class',
1943
-            function ($classes) {
1944
-                if (strpos($classes, 'espresso-admin') === false) {
1945
-                    $classes .= ' espresso-admin';
1946
-                }
1947
-                return $classes;
1948
-            }
1949
-        );
1950
-    }
1951
-
1952
-
1953
-    /**
1954
-     *        admin_footer_scripts_eei18n_js_strings
1955
-     *
1956
-     * @return        void
1957
-     */
1958
-    public function admin_footer_scripts_eei18n_js_strings()
1959
-    {
1960
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1961
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1962
-            __(
1963
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1964
-                'event_espresso'
1965
-            )
1966
-        );
1967
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1968
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1969
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1970
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1971
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1972
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1973
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1974
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1975
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1976
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1977
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1978
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1979
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1980
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1981
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1982
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1983
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1984
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1985
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1986
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1987
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1988
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1989
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1990
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1991
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1992
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1993
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1994
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1995
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1996
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1997
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1998
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1999
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
2000
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
2001
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
2002
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
2003
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
2004
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
2005
-    }
2006
-
2007
-
2008
-    /**
2009
-     *        load enhanced xdebug styles for ppl with failing eyesight
2010
-     *
2011
-     * @return        void
2012
-     */
2013
-    public function add_xdebug_style()
2014
-    {
2015
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2016
-    }
2017
-
2018
-
2019
-    /************************/
2020
-    /** LIST TABLE METHODS **/
2021
-    /************************/
2022
-    /**
2023
-     * this sets up the list table if the current view requires it.
2024
-     *
2025
-     * @return void
2026
-     * @throws EE_Error
2027
-     * @throws InvalidArgumentException
2028
-     * @throws InvalidDataTypeException
2029
-     * @throws InvalidInterfaceException
2030
-     */
2031
-    protected function _set_list_table()
2032
-    {
2033
-        // first is this a list_table view?
2034
-        if (! isset($this->_route_config['list_table'])) {
2035
-            return;
2036
-        } //not a list_table view so get out.
2037
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2038
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2039
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2040
-            // user error msg
2041
-            $error_msg = esc_html__(
2042
-                'An error occurred. The requested list table views could not be found.',
2043
-                'event_espresso'
2044
-            );
2045
-            // developer error msg
2046
-            $error_msg .= '||'
2047
-                          . sprintf(
2048
-                              esc_html__(
2049
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2050
-                                  'event_espresso'
2051
-                              ),
2052
-                              $this->_req_action,
2053
-                              $list_table_view
2054
-                          );
2055
-            throw new EE_Error($error_msg);
2056
-        }
2057
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2058
-        $this->_views = apply_filters(
2059
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2060
-            $this->_views
2061
-        );
2062
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2063
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2064
-        $this->_set_list_table_view();
2065
-        $this->_set_list_table_object();
2066
-    }
2067
-
2068
-
2069
-    /**
2070
-     * set current view for List Table
2071
-     *
2072
-     * @return void
2073
-     */
2074
-    protected function _set_list_table_view()
2075
-    {
2076
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2077
-        $status      = $this->request->getRequestParam('status', null, 'key');
2078
-        $this->_view = $status && array_key_exists($status, $this->_views)
2079
-            ? $status
2080
-            : $this->_view;
2081
-    }
2082
-
2083
-
2084
-    /**
2085
-     * _set_list_table_object
2086
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2087
-     *
2088
-     * @throws InvalidInterfaceException
2089
-     * @throws InvalidArgumentException
2090
-     * @throws InvalidDataTypeException
2091
-     * @throws EE_Error
2092
-     * @throws InvalidInterfaceException
2093
-     */
2094
-    protected function _set_list_table_object()
2095
-    {
2096
-        if (isset($this->_route_config['list_table'])) {
2097
-            if (! class_exists($this->_route_config['list_table'])) {
2098
-                throw new EE_Error(
2099
-                    sprintf(
2100
-                        esc_html__(
2101
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2102
-                            'event_espresso'
2103
-                        ),
2104
-                        $this->_route_config['list_table'],
2105
-                        $this->class_name
2106
-                    )
2107
-                );
2108
-            }
2109
-            $this->_list_table_object = $this->loader->getShared(
2110
-                $this->_route_config['list_table'],
2111
-                [
2112
-                    $this,
2113
-                    LoaderFactory::getShared(AdminListTableFilters::class)
2114
-                ]
2115
-            );
2116
-        }
2117
-    }
2118
-
2119
-
2120
-    /**
2121
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2122
-     *
2123
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2124
-     *                                                    urls.  The array should be indexed by the view it is being
2125
-     *                                                    added to.
2126
-     * @return array
2127
-     */
2128
-    public function get_list_table_view_RLs($extra_query_args = [])
2129
-    {
2130
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2131
-        if (empty($this->_views)) {
2132
-            $this->_views = [];
2133
-        }
2134
-        // cycle thru views
2135
-        foreach ($this->_views as $key => $view) {
2136
-            $query_args = [];
2137
-            // check for current view
2138
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2139
-            $query_args['action']                        = $this->_req_action;
2140
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2141
-            $query_args['status']                        = $view['slug'];
2142
-            // merge any other arguments sent in.
2143
-            if (isset($extra_query_args[ $view['slug'] ])) {
2144
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2145
-                    $query_args[] = $extra_query_arg;
2146
-                }
2147
-            }
2148
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2149
-        }
2150
-        return $this->_views;
2151
-    }
2152
-
2153
-
2154
-    /**
2155
-     * _entries_per_page_dropdown
2156
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2157
-     *
2158
-     * @param int $max_entries total number of rows in the table
2159
-     * @return string
2160
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2161
-     *                         WP does it.
2162
-     */
2163
-    protected function _entries_per_page_dropdown($max_entries = 0)
2164
-    {
2165
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2166
-        $values   = [10, 25, 50, 100];
2167
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2168
-        if ($max_entries) {
2169
-            $values[] = $max_entries;
2170
-            sort($values);
2171
-        }
2172
-        $entries_per_page_dropdown = '
1735
+		// current set timezone for timezone js
1736
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1737
+	}
1738
+
1739
+
1740
+	/**
1741
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1742
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1743
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1744
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1745
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1746
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1747
+	 * for the
1748
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1749
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1750
+	 *    'help_trigger_id' => array(
1751
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1752
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1753
+	 *    )
1754
+	 * );
1755
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1756
+	 *
1757
+	 * @param array $help_array
1758
+	 * @param bool  $display
1759
+	 * @return string content
1760
+	 * @throws DomainException
1761
+	 * @throws EE_Error
1762
+	 */
1763
+	protected function _set_help_popup_content($help_array = [], $display = false)
1764
+	{
1765
+		$content    = '';
1766
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1767
+		// loop through the array and setup content
1768
+		foreach ($help_array as $trigger => $help) {
1769
+			// make sure the array is setup properly
1770
+			if (! isset($help['title'], $help['content'])) {
1771
+				throw new EE_Error(
1772
+					esc_html__(
1773
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1774
+						'event_espresso'
1775
+					)
1776
+				);
1777
+			}
1778
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1779
+			$template_args = [
1780
+				'help_popup_id'      => $trigger,
1781
+				'help_popup_title'   => $help['title'],
1782
+				'help_popup_content' => $help['content'],
1783
+			];
1784
+			$content       .= EEH_Template::display_template(
1785
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1786
+				$template_args,
1787
+				true
1788
+			);
1789
+		}
1790
+		if ($display) {
1791
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1792
+			return '';
1793
+		}
1794
+		return $content;
1795
+	}
1796
+
1797
+
1798
+	/**
1799
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1800
+	 *
1801
+	 * @return array properly formatted array for help popup content
1802
+	 * @throws EE_Error
1803
+	 */
1804
+	private function _get_help_content()
1805
+	{
1806
+		// what is the method we're looking for?
1807
+		$method_name = '_help_popup_content_' . $this->_req_action;
1808
+		// if method doesn't exist let's get out.
1809
+		if (! method_exists($this, $method_name)) {
1810
+			return [];
1811
+		}
1812
+		// k we're good to go let's retrieve the help array
1813
+		$help_array = $this->{$method_name}();
1814
+		// make sure we've got an array!
1815
+		if (! is_array($help_array)) {
1816
+			throw new EE_Error(
1817
+				esc_html__(
1818
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1819
+					'event_espresso'
1820
+				)
1821
+			);
1822
+		}
1823
+		return $help_array;
1824
+	}
1825
+
1826
+
1827
+	/**
1828
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1829
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1830
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1831
+	 *
1832
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1833
+	 * @param boolean $display    if false then we return the trigger string
1834
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1835
+	 * @return string
1836
+	 * @throws DomainException
1837
+	 * @throws EE_Error
1838
+	 */
1839
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1840
+	{
1841
+		if ($this->request->isAjax()) {
1842
+			return '';
1843
+		}
1844
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1845
+		$help_array   = $this->_get_help_content();
1846
+		$help_content = '';
1847
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1848
+			$help_array[ $trigger_id ] = [
1849
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1850
+				'content' => esc_html__(
1851
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1852
+					'event_espresso'
1853
+				),
1854
+			];
1855
+			$help_content              = $this->_set_help_popup_content($help_array);
1856
+		}
1857
+		// let's setup the trigger
1858
+		$content = '<a class="ee-dialog" href="?height='
1859
+				   . esc_attr($dimensions[0])
1860
+				   . '&width='
1861
+				   . esc_attr($dimensions[1])
1862
+				   . '&inlineId='
1863
+				   . esc_attr($trigger_id)
1864
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1865
+		$content .= $help_content;
1866
+		if ($display) {
1867
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1868
+			return '';
1869
+		}
1870
+		return $content;
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 * _add_global_screen_options
1876
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1877
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1878
+	 *
1879
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1880
+	 *         see also WP_Screen object documents...
1881
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1882
+	 * @abstract
1883
+	 * @return void
1884
+	 */
1885
+	private function _add_global_screen_options()
1886
+	{
1887
+	}
1888
+
1889
+
1890
+	/**
1891
+	 * _add_global_feature_pointers
1892
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1893
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1894
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1895
+	 *
1896
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1897
+	 *         extended) also see:
1898
+	 * @link   http://eamann.com/tech/wordpress-portland/
1899
+	 * @abstract
1900
+	 * @return void
1901
+	 */
1902
+	private function _add_global_feature_pointers()
1903
+	{
1904
+	}
1905
+
1906
+
1907
+	/**
1908
+	 * load_global_scripts_styles
1909
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1910
+	 *
1911
+	 * @return void
1912
+	 */
1913
+	public function load_global_scripts_styles()
1914
+	{
1915
+		// add debugging styles
1916
+		if (WP_DEBUG) {
1917
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1918
+		}
1919
+		// taking care of metaboxes
1920
+		if (
1921
+			empty($this->_cpt_route)
1922
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1923
+		) {
1924
+			wp_enqueue_script('dashboard');
1925
+		}
1926
+
1927
+		wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH);
1928
+		wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
1929
+		// LOCALIZED DATA
1930
+		// localize script for ajax lazy loading
1931
+		wp_localize_script(
1932
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1933
+			'eeLazyLoadingContainers',
1934
+			apply_filters(
1935
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1936
+				['espresso_news_post_box_content']
1937
+			)
1938
+		);
1939
+		StatusChangeNotice::loadAssets();
1940
+
1941
+		add_filter(
1942
+			'admin_body_class',
1943
+			function ($classes) {
1944
+				if (strpos($classes, 'espresso-admin') === false) {
1945
+					$classes .= ' espresso-admin';
1946
+				}
1947
+				return $classes;
1948
+			}
1949
+		);
1950
+	}
1951
+
1952
+
1953
+	/**
1954
+	 *        admin_footer_scripts_eei18n_js_strings
1955
+	 *
1956
+	 * @return        void
1957
+	 */
1958
+	public function admin_footer_scripts_eei18n_js_strings()
1959
+	{
1960
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1961
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1962
+			__(
1963
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1964
+				'event_espresso'
1965
+			)
1966
+		);
1967
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1968
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1969
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1970
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1971
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1972
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1973
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1974
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1975
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1976
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1977
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1978
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1979
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1980
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1981
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1982
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1983
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1984
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1985
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1986
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1987
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1988
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1989
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1990
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1991
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1992
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1993
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1994
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1995
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1996
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1997
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1998
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1999
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
2000
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
2001
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
2002
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
2003
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
2004
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
2005
+	}
2006
+
2007
+
2008
+	/**
2009
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2010
+	 *
2011
+	 * @return        void
2012
+	 */
2013
+	public function add_xdebug_style()
2014
+	{
2015
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2016
+	}
2017
+
2018
+
2019
+	/************************/
2020
+	/** LIST TABLE METHODS **/
2021
+	/************************/
2022
+	/**
2023
+	 * this sets up the list table if the current view requires it.
2024
+	 *
2025
+	 * @return void
2026
+	 * @throws EE_Error
2027
+	 * @throws InvalidArgumentException
2028
+	 * @throws InvalidDataTypeException
2029
+	 * @throws InvalidInterfaceException
2030
+	 */
2031
+	protected function _set_list_table()
2032
+	{
2033
+		// first is this a list_table view?
2034
+		if (! isset($this->_route_config['list_table'])) {
2035
+			return;
2036
+		} //not a list_table view so get out.
2037
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2038
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2039
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2040
+			// user error msg
2041
+			$error_msg = esc_html__(
2042
+				'An error occurred. The requested list table views could not be found.',
2043
+				'event_espresso'
2044
+			);
2045
+			// developer error msg
2046
+			$error_msg .= '||'
2047
+						  . sprintf(
2048
+							  esc_html__(
2049
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2050
+								  'event_espresso'
2051
+							  ),
2052
+							  $this->_req_action,
2053
+							  $list_table_view
2054
+						  );
2055
+			throw new EE_Error($error_msg);
2056
+		}
2057
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2058
+		$this->_views = apply_filters(
2059
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2060
+			$this->_views
2061
+		);
2062
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2063
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2064
+		$this->_set_list_table_view();
2065
+		$this->_set_list_table_object();
2066
+	}
2067
+
2068
+
2069
+	/**
2070
+	 * set current view for List Table
2071
+	 *
2072
+	 * @return void
2073
+	 */
2074
+	protected function _set_list_table_view()
2075
+	{
2076
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2077
+		$status      = $this->request->getRequestParam('status', null, 'key');
2078
+		$this->_view = $status && array_key_exists($status, $this->_views)
2079
+			? $status
2080
+			: $this->_view;
2081
+	}
2082
+
2083
+
2084
+	/**
2085
+	 * _set_list_table_object
2086
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2087
+	 *
2088
+	 * @throws InvalidInterfaceException
2089
+	 * @throws InvalidArgumentException
2090
+	 * @throws InvalidDataTypeException
2091
+	 * @throws EE_Error
2092
+	 * @throws InvalidInterfaceException
2093
+	 */
2094
+	protected function _set_list_table_object()
2095
+	{
2096
+		if (isset($this->_route_config['list_table'])) {
2097
+			if (! class_exists($this->_route_config['list_table'])) {
2098
+				throw new EE_Error(
2099
+					sprintf(
2100
+						esc_html__(
2101
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2102
+							'event_espresso'
2103
+						),
2104
+						$this->_route_config['list_table'],
2105
+						$this->class_name
2106
+					)
2107
+				);
2108
+			}
2109
+			$this->_list_table_object = $this->loader->getShared(
2110
+				$this->_route_config['list_table'],
2111
+				[
2112
+					$this,
2113
+					LoaderFactory::getShared(AdminListTableFilters::class)
2114
+				]
2115
+			);
2116
+		}
2117
+	}
2118
+
2119
+
2120
+	/**
2121
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2122
+	 *
2123
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2124
+	 *                                                    urls.  The array should be indexed by the view it is being
2125
+	 *                                                    added to.
2126
+	 * @return array
2127
+	 */
2128
+	public function get_list_table_view_RLs($extra_query_args = [])
2129
+	{
2130
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2131
+		if (empty($this->_views)) {
2132
+			$this->_views = [];
2133
+		}
2134
+		// cycle thru views
2135
+		foreach ($this->_views as $key => $view) {
2136
+			$query_args = [];
2137
+			// check for current view
2138
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2139
+			$query_args['action']                        = $this->_req_action;
2140
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2141
+			$query_args['status']                        = $view['slug'];
2142
+			// merge any other arguments sent in.
2143
+			if (isset($extra_query_args[ $view['slug'] ])) {
2144
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2145
+					$query_args[] = $extra_query_arg;
2146
+				}
2147
+			}
2148
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2149
+		}
2150
+		return $this->_views;
2151
+	}
2152
+
2153
+
2154
+	/**
2155
+	 * _entries_per_page_dropdown
2156
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2157
+	 *
2158
+	 * @param int $max_entries total number of rows in the table
2159
+	 * @return string
2160
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2161
+	 *                         WP does it.
2162
+	 */
2163
+	protected function _entries_per_page_dropdown($max_entries = 0)
2164
+	{
2165
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2166
+		$values   = [10, 25, 50, 100];
2167
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2168
+		if ($max_entries) {
2169
+			$values[] = $max_entries;
2170
+			sort($values);
2171
+		}
2172
+		$entries_per_page_dropdown = '
2173 2173
 			<div id="entries-per-page-dv" class="alignleft actions">
2174 2174
 				<label class="hide-if-no-js">
2175 2175
 					Show
2176 2176
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2177
-        foreach ($values as $value) {
2178
-            if ($value < $max_entries) {
2179
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2180
-                $entries_per_page_dropdown .= '
2177
+		foreach ($values as $value) {
2178
+			if ($value < $max_entries) {
2179
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2180
+				$entries_per_page_dropdown .= '
2181 2181
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2182
-            }
2183
-        }
2184
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2185
-        $entries_per_page_dropdown .= '
2182
+			}
2183
+		}
2184
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2185
+		$entries_per_page_dropdown .= '
2186 2186
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2187
-        $entries_per_page_dropdown .= '
2187
+		$entries_per_page_dropdown .= '
2188 2188
 					</select>
2189 2189
 					entries
2190 2190
 				</label>
2191 2191
 				<input id="entries-per-page-btn" class="button button--secondary" type="submit" value="Go" >
2192 2192
 			</div>
2193 2193
 		';
2194
-        return $entries_per_page_dropdown;
2195
-    }
2196
-
2197
-
2198
-    /**
2199
-     *        _set_search_attributes
2200
-     *
2201
-     * @return        void
2202
-     */
2203
-    public function _set_search_attributes()
2204
-    {
2205
-        $this->_template_args['search']['btn_label'] = sprintf(
2206
-            esc_html__('Search %s', 'event_espresso'),
2207
-            empty($this->_search_btn_label) ? $this->page_label
2208
-                : $this->_search_btn_label
2209
-        );
2210
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2211
-    }
2212
-
2213
-
2214
-
2215
-    /*** END LIST TABLE METHODS **/
2216
-
2217
-    /**
2218
-     * @return void
2219
-     * @throws EE_Error
2220
-     */
2221
-    public function addRegisteredMetaBoxes()
2222
-    {
2223
-        remove_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99);
2224
-        $this->_add_registered_meta_boxes();
2225
-    }
2226
-
2227
-
2228
-    /**
2229
-     * _add_registered_metaboxes
2230
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2231
-     *
2232
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2233
-     * @return void
2234
-     * @throws EE_Error
2235
-     */
2236
-    private function _add_registered_meta_boxes()
2237
-    {
2238
-        // we only add meta boxes if the page_route calls for it
2239
-        if (
2240
-            is_array($this->_route_config)
2241
-            && isset($this->_route_config['metaboxes'])
2242
-            && is_array($this->_route_config['metaboxes'])
2243
-        ) {
2244
-            // this simply loops through the callbacks provided
2245
-            // and checks if there is a corresponding callback registered by the child
2246
-            // if there is then we go ahead and process the metabox loader.
2247
-            foreach ($this->_route_config['metaboxes'] as $key => $metabox_callback) {
2248
-                // first check for Closures
2249
-                if ($metabox_callback instanceof Closure) {
2250
-                    $result = $metabox_callback();
2251
-                } elseif (is_callable($metabox_callback)) {
2252
-                    $result = call_user_func($metabox_callback);
2253
-                } elseif (method_exists($this, $metabox_callback)) {
2254
-                    $result = $this->{$metabox_callback}();
2255
-                } else {
2256
-                    $result = false;
2257
-                }
2258
-                if ($result === false) {
2259
-                    // user error msg
2260
-                    $error_msg = esc_html__(
2261
-                        'An error occurred. The  requested metabox could not be found.',
2262
-                        'event_espresso'
2263
-                    );
2264
-                    // developer error msg
2265
-                    $error_msg .= '||'
2266
-                                  . sprintf(
2267
-                                      esc_html__(
2268
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2269
-                                          'event_espresso'
2270
-                                      ),
2271
-                                      $metabox_callback
2272
-                                  );
2273
-                    throw new EE_Error($error_msg);
2274
-                }
2275
-                unset($this->_route_config['metaboxes'][ $key ]);
2276
-            }
2277
-        }
2278
-    }
2279
-
2280
-
2281
-    /**
2282
-     * _add_screen_columns
2283
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2284
-     * the dynamic column template and we'll setup the column options for the page.
2285
-     *
2286
-     * @return void
2287
-     */
2288
-    private function _add_screen_columns()
2289
-    {
2290
-        if (
2291
-            is_array($this->_route_config)
2292
-            && isset($this->_route_config['columns'])
2293
-            && is_array($this->_route_config['columns'])
2294
-            && count($this->_route_config['columns']) === 2
2295
-        ) {
2296
-            add_screen_option(
2297
-                'layout_columns',
2298
-                [
2299
-                    'max'     => (int) $this->_route_config['columns'][0],
2300
-                    'default' => (int) $this->_route_config['columns'][1],
2301
-                ]
2302
-            );
2303
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2304
-            $screen_id                                           = $this->_current_screen->id;
2305
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2306
-            $total_columns                                       = ! empty($screen_columns)
2307
-                ? $screen_columns
2308
-                : $this->_route_config['columns'][1];
2309
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2310
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2311
-            $this->_template_args['screen']                      = $this->_current_screen;
2312
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2313
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2314
-            // finally if we don't have has_metaboxes set in the route config
2315
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2316
-            $this->_route_config['has_metaboxes'] = true;
2317
-        }
2318
-    }
2319
-
2320
-
2321
-
2322
-    /** GLOBALLY AVAILABLE METABOXES **/
2323
-
2324
-
2325
-    /**
2326
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2327
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2328
-     * these get loaded on.
2329
-     */
2330
-    private function _espresso_news_post_box()
2331
-    {
2332
-        $news_box_title = apply_filters(
2333
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2334
-            esc_html__('New @ Event Espresso', 'event_espresso')
2335
-        );
2336
-        $this->addMetaBox(
2337
-            'espresso_news_post_box',
2338
-            $news_box_title,
2339
-            [
2340
-                $this,
2341
-                'espresso_news_post_box',
2342
-            ],
2343
-            $this->_wp_page_slug,
2344
-            'side',
2345
-            'low'
2346
-        );
2347
-    }
2348
-
2349
-
2350
-    /**
2351
-     * Code for setting up espresso ratings request metabox.
2352
-     */
2353
-    protected function _espresso_ratings_request()
2354
-    {
2355
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2356
-            return;
2357
-        }
2358
-        $ratings_box_title = apply_filters(
2359
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2360
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2361
-        );
2362
-        $this->addMetaBox(
2363
-            'espresso_ratings_request',
2364
-            $ratings_box_title,
2365
-            [
2366
-                $this,
2367
-                'espresso_ratings_request',
2368
-            ],
2369
-            $this->_wp_page_slug,
2370
-            'side'
2371
-        );
2372
-    }
2373
-
2374
-
2375
-    /**
2376
-     * Code for setting up espresso ratings request metabox content.
2377
-     *
2378
-     * @throws DomainException
2379
-     */
2380
-    public function espresso_ratings_request()
2381
-    {
2382
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2383
-    }
2384
-
2385
-
2386
-    public static function cached_rss_display($rss_id, $url)
2387
-    {
2388
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2389
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2390
-                     . '</p><p class="hide-if-js">'
2391
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2392
-                     . '</p>';
2393
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2394
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2395
-        $post      = '</div>' . "\n";
2396
-        $cache_key = 'ee_rss_' . md5($rss_id);
2397
-        $output    = get_transient($cache_key);
2398
-        if ($output !== false) {
2399
-            echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2400
-            return true;
2401
-        }
2402
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2403
-            echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2404
-            return false;
2405
-        }
2406
-        ob_start();
2407
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2408
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2409
-        return true;
2410
-    }
2411
-
2412
-
2413
-    public function espresso_news_post_box()
2414
-    {
2415
-        ?>
2194
+		return $entries_per_page_dropdown;
2195
+	}
2196
+
2197
+
2198
+	/**
2199
+	 *        _set_search_attributes
2200
+	 *
2201
+	 * @return        void
2202
+	 */
2203
+	public function _set_search_attributes()
2204
+	{
2205
+		$this->_template_args['search']['btn_label'] = sprintf(
2206
+			esc_html__('Search %s', 'event_espresso'),
2207
+			empty($this->_search_btn_label) ? $this->page_label
2208
+				: $this->_search_btn_label
2209
+		);
2210
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2211
+	}
2212
+
2213
+
2214
+
2215
+	/*** END LIST TABLE METHODS **/
2216
+
2217
+	/**
2218
+	 * @return void
2219
+	 * @throws EE_Error
2220
+	 */
2221
+	public function addRegisteredMetaBoxes()
2222
+	{
2223
+		remove_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99);
2224
+		$this->_add_registered_meta_boxes();
2225
+	}
2226
+
2227
+
2228
+	/**
2229
+	 * _add_registered_metaboxes
2230
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2231
+	 *
2232
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2233
+	 * @return void
2234
+	 * @throws EE_Error
2235
+	 */
2236
+	private function _add_registered_meta_boxes()
2237
+	{
2238
+		// we only add meta boxes if the page_route calls for it
2239
+		if (
2240
+			is_array($this->_route_config)
2241
+			&& isset($this->_route_config['metaboxes'])
2242
+			&& is_array($this->_route_config['metaboxes'])
2243
+		) {
2244
+			// this simply loops through the callbacks provided
2245
+			// and checks if there is a corresponding callback registered by the child
2246
+			// if there is then we go ahead and process the metabox loader.
2247
+			foreach ($this->_route_config['metaboxes'] as $key => $metabox_callback) {
2248
+				// first check for Closures
2249
+				if ($metabox_callback instanceof Closure) {
2250
+					$result = $metabox_callback();
2251
+				} elseif (is_callable($metabox_callback)) {
2252
+					$result = call_user_func($metabox_callback);
2253
+				} elseif (method_exists($this, $metabox_callback)) {
2254
+					$result = $this->{$metabox_callback}();
2255
+				} else {
2256
+					$result = false;
2257
+				}
2258
+				if ($result === false) {
2259
+					// user error msg
2260
+					$error_msg = esc_html__(
2261
+						'An error occurred. The  requested metabox could not be found.',
2262
+						'event_espresso'
2263
+					);
2264
+					// developer error msg
2265
+					$error_msg .= '||'
2266
+								  . sprintf(
2267
+									  esc_html__(
2268
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2269
+										  'event_espresso'
2270
+									  ),
2271
+									  $metabox_callback
2272
+								  );
2273
+					throw new EE_Error($error_msg);
2274
+				}
2275
+				unset($this->_route_config['metaboxes'][ $key ]);
2276
+			}
2277
+		}
2278
+	}
2279
+
2280
+
2281
+	/**
2282
+	 * _add_screen_columns
2283
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2284
+	 * the dynamic column template and we'll setup the column options for the page.
2285
+	 *
2286
+	 * @return void
2287
+	 */
2288
+	private function _add_screen_columns()
2289
+	{
2290
+		if (
2291
+			is_array($this->_route_config)
2292
+			&& isset($this->_route_config['columns'])
2293
+			&& is_array($this->_route_config['columns'])
2294
+			&& count($this->_route_config['columns']) === 2
2295
+		) {
2296
+			add_screen_option(
2297
+				'layout_columns',
2298
+				[
2299
+					'max'     => (int) $this->_route_config['columns'][0],
2300
+					'default' => (int) $this->_route_config['columns'][1],
2301
+				]
2302
+			);
2303
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2304
+			$screen_id                                           = $this->_current_screen->id;
2305
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2306
+			$total_columns                                       = ! empty($screen_columns)
2307
+				? $screen_columns
2308
+				: $this->_route_config['columns'][1];
2309
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2310
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2311
+			$this->_template_args['screen']                      = $this->_current_screen;
2312
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2313
+																   . 'admin_details_metabox_column_wrapper.template.php';
2314
+			// finally if we don't have has_metaboxes set in the route config
2315
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2316
+			$this->_route_config['has_metaboxes'] = true;
2317
+		}
2318
+	}
2319
+
2320
+
2321
+
2322
+	/** GLOBALLY AVAILABLE METABOXES **/
2323
+
2324
+
2325
+	/**
2326
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2327
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2328
+	 * these get loaded on.
2329
+	 */
2330
+	private function _espresso_news_post_box()
2331
+	{
2332
+		$news_box_title = apply_filters(
2333
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2334
+			esc_html__('New @ Event Espresso', 'event_espresso')
2335
+		);
2336
+		$this->addMetaBox(
2337
+			'espresso_news_post_box',
2338
+			$news_box_title,
2339
+			[
2340
+				$this,
2341
+				'espresso_news_post_box',
2342
+			],
2343
+			$this->_wp_page_slug,
2344
+			'side',
2345
+			'low'
2346
+		);
2347
+	}
2348
+
2349
+
2350
+	/**
2351
+	 * Code for setting up espresso ratings request metabox.
2352
+	 */
2353
+	protected function _espresso_ratings_request()
2354
+	{
2355
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2356
+			return;
2357
+		}
2358
+		$ratings_box_title = apply_filters(
2359
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2360
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2361
+		);
2362
+		$this->addMetaBox(
2363
+			'espresso_ratings_request',
2364
+			$ratings_box_title,
2365
+			[
2366
+				$this,
2367
+				'espresso_ratings_request',
2368
+			],
2369
+			$this->_wp_page_slug,
2370
+			'side'
2371
+		);
2372
+	}
2373
+
2374
+
2375
+	/**
2376
+	 * Code for setting up espresso ratings request metabox content.
2377
+	 *
2378
+	 * @throws DomainException
2379
+	 */
2380
+	public function espresso_ratings_request()
2381
+	{
2382
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2383
+	}
2384
+
2385
+
2386
+	public static function cached_rss_display($rss_id, $url)
2387
+	{
2388
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2389
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2390
+					 . '</p><p class="hide-if-js">'
2391
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2392
+					 . '</p>';
2393
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2394
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2395
+		$post      = '</div>' . "\n";
2396
+		$cache_key = 'ee_rss_' . md5($rss_id);
2397
+		$output    = get_transient($cache_key);
2398
+		if ($output !== false) {
2399
+			echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2400
+			return true;
2401
+		}
2402
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2403
+			echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2404
+			return false;
2405
+		}
2406
+		ob_start();
2407
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2408
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2409
+		return true;
2410
+	}
2411
+
2412
+
2413
+	public function espresso_news_post_box()
2414
+	{
2415
+		?>
2416 2416
         <div class="padding">
2417 2417
             <div id="espresso_news_post_box_content" class="infolinks">
2418 2418
                 <?php
2419
-                // Get RSS Feed(s)
2420
-                EE_Admin_Page::cached_rss_display(
2421
-                    'espresso_news_post_box_content',
2422
-                    esc_url_raw(
2423
-                        apply_filters(
2424
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2425
-                            'https://eventespresso.com/feed/'
2426
-                        )
2427
-                    )
2428
-                );
2429
-                ?>
2419
+				// Get RSS Feed(s)
2420
+				EE_Admin_Page::cached_rss_display(
2421
+					'espresso_news_post_box_content',
2422
+					esc_url_raw(
2423
+						apply_filters(
2424
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2425
+							'https://eventespresso.com/feed/'
2426
+						)
2427
+					)
2428
+				);
2429
+				?>
2430 2430
             </div>
2431 2431
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2432 2432
         </div>
2433 2433
         <?php
2434
-    }
2435
-
2436
-
2437
-    private function _espresso_links_post_box()
2438
-    {
2439
-        // Hiding until we actually have content to put in here...
2440
-        // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2441
-    }
2442
-
2443
-
2444
-    public function espresso_links_post_box()
2445
-    {
2446
-        // Hiding until we actually have content to put in here...
2447
-        // EEH_Template::display_template(
2448
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2449
-        // );
2450
-    }
2451
-
2452
-
2453
-    protected function _espresso_sponsors_post_box()
2454
-    {
2455
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2456
-            $this->addMetaBox(
2457
-                'espresso_sponsors_post_box',
2458
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2459
-                [$this, 'espresso_sponsors_post_box'],
2460
-                $this->_wp_page_slug,
2461
-                'side'
2462
-            );
2463
-        }
2464
-    }
2465
-
2466
-
2467
-    public function espresso_sponsors_post_box()
2468
-    {
2469
-        EEH_Template::display_template(
2470
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2471
-        );
2472
-    }
2473
-
2474
-
2475
-    /**
2476
-     * if there is [ 'label' => [ 'publishbox' => 'some title' ]]
2477
-     * present in the _page_config array, then we'll use that for the metabox label.
2478
-     * Otherwise we'll just use publish
2479
-     * (publishbox itself could be an array of labels indexed by routes)
2480
-     *
2481
-     * @return string
2482
-     * @since   $VID:$
2483
-     */
2484
-    protected function getPublishBoxTitle(): string
2485
-    {
2486
-        $publish_box_title = esc_html__('Publish', 'event_espresso');
2487
-        if (! empty($this->_labels['publishbox'])) {
2488
-            if (is_array($this->_labels['publishbox'])) {
2489
-                $publish_box_title = $this->_labels['publishbox'][ $this->_req_action ] ?? $publish_box_title;
2490
-            } else {
2491
-                $publish_box_title = $this->_labels['publishbox'];
2492
-            }
2493
-        }
2494
-        return apply_filters(
2495
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2496
-            $publish_box_title,
2497
-            $this->_req_action,
2498
-            $this
2499
-        );
2500
-    }
2501
-
2502
-
2503
-    /**
2504
-     * @throws EE_Error
2505
-     */
2506
-    private function _publish_post_box()
2507
-    {
2508
-        $title = $this->getPublishBoxTitle();
2509
-        if (empty($this->_template_args['save_buttons'])) {
2510
-            $this->_set_publish_post_box_vars(
2511
-                sanitize_key($title),
2512
-                "espresso_{$this->page_slug}_editor_overview",
2513
-                '',
2514
-                '',
2515
-                true
2516
-            );
2517
-        } else {
2518
-            $this->addPublishPostMetaBoxHiddenFields(
2519
-                sanitize_key($title),
2520
-                ['type' => 'hidden', 'value' => "espresso_{$this->page_slug}_editor_overview"]
2521
-            );
2522
-        }
2523
-        $this->addMetaBox(
2524
-            "espresso_{$this->page_slug}_editor_overview",
2525
-            $title,
2526
-            [$this, 'editor_overview'],
2527
-            $this->_current_screen->id,
2528
-            'side',
2529
-            'high'
2530
-        );
2531
-    }
2532
-
2533
-
2534
-    public function editor_overview()
2535
-    {
2536
-        /**
2537
-         * @var string $publish_box_extra_content
2538
-         * @var string $publish_hidden_fields
2539
-         * @var string $publish_delete_link
2540
-         * @var string $save_buttons
2541
-         */
2542
-        // if we have extra content set let's add it in if not make sure its empty
2543
-        $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2544
-        echo EEH_Template::display_template(
2545
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2546
-            $this->_template_args,
2547
-            true
2548
-        );
2549
-    }
2550
-
2551
-
2552
-    /** end of globally available metaboxes section **/
2553
-
2554
-
2555
-    /**
2556
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2557
-     * Note: currently there is no validation for this.  However, if you want the delete button, the
2558
-     * save, and save and close buttons to work properly, then you will want to include a
2559
-     * values for the name and id arguments.
2560
-     *
2561
-     * @param string|null $name                     key used for the action ID (i.e. event_id)
2562
-     * @param int|string  $id                       id attached to the item published
2563
-     * @param string|null $delete                   page route callback for the delete action
2564
-     * @param string|null $save_close_redirect_URL  custom URL to redirect to after Save & Close has been completed
2565
-     * @param boolean     $both_btns                whether to display BOTH the "Save & Close" and "Save" buttons
2566
-     *                                              or just the "Save" button
2567
-     * @throws EE_Error
2568
-     * @throws InvalidArgumentException
2569
-     * @throws InvalidDataTypeException
2570
-     * @throws InvalidInterfaceException
2571
-     * @todo  Add in validation for name/id arguments.
2572
-     */
2573
-    protected function _set_publish_post_box_vars(
2574
-        ?string $name = '',
2575
-        $id = 0,
2576
-        ?string $delete = '',
2577
-        ?string $save_close_redirect_URL = '',
2578
-        bool $both_btns = true
2579
-    ) {
2580
-        // if Save & Close, use a custom redirect URL or default to the main page?
2581
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2582
-            ? $save_close_redirect_URL
2583
-            : $this->_admin_base_url;
2584
-        // create the Save & Close and Save buttons
2585
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2586
-        // if we have extra content set let's add it in if not make sure its empty
2587
-        $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2588
-        if ($delete && ! empty($id) && empty($this->_template_args['publish_delete_link'])) {
2589
-            // make sure we have a default if just true is sent.
2590
-            $delete      = ! empty($delete) ? $delete : 'delete';
2591
-            $this->_template_args['publish_delete_link'] = $this->get_action_link_or_button(
2592
-                $delete,
2593
-                $delete,
2594
-                [$name => $id],
2595
-                'submitdelete deletion button button--outline button--caution'
2596
-            );
2597
-        }
2598
-        if (! isset($this->_template_args['publish_delete_link'])) {
2599
-            $this->_template_args['publish_delete_link'] = '';
2600
-        }
2601
-        if (! empty($name) && ! empty($id)) {
2602
-            $this->addPublishPostMetaBoxHiddenFields($name, ['type' => 'hidden', 'value' => $id]);
2603
-        }
2604
-        $hidden_fields = $this->_generate_admin_form_fields($this->publish_post_meta_box_hidden_fields, 'array');
2605
-        // add hidden fields
2606
-        $this->_template_args['publish_hidden_fields'] = $this->_template_args['publish_hidden_fields'] ?? '';
2607
-        foreach ($hidden_fields as $hidden_field) {
2608
-            $this->_template_args['publish_hidden_fields'] .= $hidden_field['field'] ?? '';
2609
-        }
2610
-    }
2611
-
2612
-
2613
-    /**
2614
-     * @param string|null $name
2615
-     * @param int|string  $id
2616
-     * @param string|null $delete
2617
-     * @param string|null $save_close_redirect_URL
2618
-     * @param bool        $both_btns
2619
-     * @throws EE_Error
2620
-     */
2621
-    public function set_publish_post_box_vars(
2622
-        ?string $name = '',
2623
-        $id = 0,
2624
-        ?string $delete = '',
2625
-        ?string $save_close_redirect_URL = '',
2626
-        bool $both_btns = false
2627
-    ) {
2628
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2629
-    }
2630
-
2631
-
2632
-    protected function addPublishPostMetaBoxHiddenFields(string $field_name, array $field_attributes)
2633
-    {
2634
-        $this->publish_post_meta_box_hidden_fields[ $field_name ] = $field_attributes;
2635
-    }
2636
-
2637
-
2638
-    /**
2639
-     * displays an error message to ppl who have javascript disabled
2640
-     *
2641
-     * @return void
2642
-     */
2643
-    private function _display_no_javascript_warning()
2644
-    {
2645
-        ?>
2434
+	}
2435
+
2436
+
2437
+	private function _espresso_links_post_box()
2438
+	{
2439
+		// Hiding until we actually have content to put in here...
2440
+		// $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2441
+	}
2442
+
2443
+
2444
+	public function espresso_links_post_box()
2445
+	{
2446
+		// Hiding until we actually have content to put in here...
2447
+		// EEH_Template::display_template(
2448
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2449
+		// );
2450
+	}
2451
+
2452
+
2453
+	protected function _espresso_sponsors_post_box()
2454
+	{
2455
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2456
+			$this->addMetaBox(
2457
+				'espresso_sponsors_post_box',
2458
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2459
+				[$this, 'espresso_sponsors_post_box'],
2460
+				$this->_wp_page_slug,
2461
+				'side'
2462
+			);
2463
+		}
2464
+	}
2465
+
2466
+
2467
+	public function espresso_sponsors_post_box()
2468
+	{
2469
+		EEH_Template::display_template(
2470
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2471
+		);
2472
+	}
2473
+
2474
+
2475
+	/**
2476
+	 * if there is [ 'label' => [ 'publishbox' => 'some title' ]]
2477
+	 * present in the _page_config array, then we'll use that for the metabox label.
2478
+	 * Otherwise we'll just use publish
2479
+	 * (publishbox itself could be an array of labels indexed by routes)
2480
+	 *
2481
+	 * @return string
2482
+	 * @since   $VID:$
2483
+	 */
2484
+	protected function getPublishBoxTitle(): string
2485
+	{
2486
+		$publish_box_title = esc_html__('Publish', 'event_espresso');
2487
+		if (! empty($this->_labels['publishbox'])) {
2488
+			if (is_array($this->_labels['publishbox'])) {
2489
+				$publish_box_title = $this->_labels['publishbox'][ $this->_req_action ] ?? $publish_box_title;
2490
+			} else {
2491
+				$publish_box_title = $this->_labels['publishbox'];
2492
+			}
2493
+		}
2494
+		return apply_filters(
2495
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2496
+			$publish_box_title,
2497
+			$this->_req_action,
2498
+			$this
2499
+		);
2500
+	}
2501
+
2502
+
2503
+	/**
2504
+	 * @throws EE_Error
2505
+	 */
2506
+	private function _publish_post_box()
2507
+	{
2508
+		$title = $this->getPublishBoxTitle();
2509
+		if (empty($this->_template_args['save_buttons'])) {
2510
+			$this->_set_publish_post_box_vars(
2511
+				sanitize_key($title),
2512
+				"espresso_{$this->page_slug}_editor_overview",
2513
+				'',
2514
+				'',
2515
+				true
2516
+			);
2517
+		} else {
2518
+			$this->addPublishPostMetaBoxHiddenFields(
2519
+				sanitize_key($title),
2520
+				['type' => 'hidden', 'value' => "espresso_{$this->page_slug}_editor_overview"]
2521
+			);
2522
+		}
2523
+		$this->addMetaBox(
2524
+			"espresso_{$this->page_slug}_editor_overview",
2525
+			$title,
2526
+			[$this, 'editor_overview'],
2527
+			$this->_current_screen->id,
2528
+			'side',
2529
+			'high'
2530
+		);
2531
+	}
2532
+
2533
+
2534
+	public function editor_overview()
2535
+	{
2536
+		/**
2537
+		 * @var string $publish_box_extra_content
2538
+		 * @var string $publish_hidden_fields
2539
+		 * @var string $publish_delete_link
2540
+		 * @var string $save_buttons
2541
+		 */
2542
+		// if we have extra content set let's add it in if not make sure its empty
2543
+		$this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2544
+		echo EEH_Template::display_template(
2545
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2546
+			$this->_template_args,
2547
+			true
2548
+		);
2549
+	}
2550
+
2551
+
2552
+	/** end of globally available metaboxes section **/
2553
+
2554
+
2555
+	/**
2556
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2557
+	 * Note: currently there is no validation for this.  However, if you want the delete button, the
2558
+	 * save, and save and close buttons to work properly, then you will want to include a
2559
+	 * values for the name and id arguments.
2560
+	 *
2561
+	 * @param string|null $name                     key used for the action ID (i.e. event_id)
2562
+	 * @param int|string  $id                       id attached to the item published
2563
+	 * @param string|null $delete                   page route callback for the delete action
2564
+	 * @param string|null $save_close_redirect_URL  custom URL to redirect to after Save & Close has been completed
2565
+	 * @param boolean     $both_btns                whether to display BOTH the "Save & Close" and "Save" buttons
2566
+	 *                                              or just the "Save" button
2567
+	 * @throws EE_Error
2568
+	 * @throws InvalidArgumentException
2569
+	 * @throws InvalidDataTypeException
2570
+	 * @throws InvalidInterfaceException
2571
+	 * @todo  Add in validation for name/id arguments.
2572
+	 */
2573
+	protected function _set_publish_post_box_vars(
2574
+		?string $name = '',
2575
+		$id = 0,
2576
+		?string $delete = '',
2577
+		?string $save_close_redirect_URL = '',
2578
+		bool $both_btns = true
2579
+	) {
2580
+		// if Save & Close, use a custom redirect URL or default to the main page?
2581
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2582
+			? $save_close_redirect_URL
2583
+			: $this->_admin_base_url;
2584
+		// create the Save & Close and Save buttons
2585
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2586
+		// if we have extra content set let's add it in if not make sure its empty
2587
+		$this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2588
+		if ($delete && ! empty($id) && empty($this->_template_args['publish_delete_link'])) {
2589
+			// make sure we have a default if just true is sent.
2590
+			$delete      = ! empty($delete) ? $delete : 'delete';
2591
+			$this->_template_args['publish_delete_link'] = $this->get_action_link_or_button(
2592
+				$delete,
2593
+				$delete,
2594
+				[$name => $id],
2595
+				'submitdelete deletion button button--outline button--caution'
2596
+			);
2597
+		}
2598
+		if (! isset($this->_template_args['publish_delete_link'])) {
2599
+			$this->_template_args['publish_delete_link'] = '';
2600
+		}
2601
+		if (! empty($name) && ! empty($id)) {
2602
+			$this->addPublishPostMetaBoxHiddenFields($name, ['type' => 'hidden', 'value' => $id]);
2603
+		}
2604
+		$hidden_fields = $this->_generate_admin_form_fields($this->publish_post_meta_box_hidden_fields, 'array');
2605
+		// add hidden fields
2606
+		$this->_template_args['publish_hidden_fields'] = $this->_template_args['publish_hidden_fields'] ?? '';
2607
+		foreach ($hidden_fields as $hidden_field) {
2608
+			$this->_template_args['publish_hidden_fields'] .= $hidden_field['field'] ?? '';
2609
+		}
2610
+	}
2611
+
2612
+
2613
+	/**
2614
+	 * @param string|null $name
2615
+	 * @param int|string  $id
2616
+	 * @param string|null $delete
2617
+	 * @param string|null $save_close_redirect_URL
2618
+	 * @param bool        $both_btns
2619
+	 * @throws EE_Error
2620
+	 */
2621
+	public function set_publish_post_box_vars(
2622
+		?string $name = '',
2623
+		$id = 0,
2624
+		?string $delete = '',
2625
+		?string $save_close_redirect_URL = '',
2626
+		bool $both_btns = false
2627
+	) {
2628
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2629
+	}
2630
+
2631
+
2632
+	protected function addPublishPostMetaBoxHiddenFields(string $field_name, array $field_attributes)
2633
+	{
2634
+		$this->publish_post_meta_box_hidden_fields[ $field_name ] = $field_attributes;
2635
+	}
2636
+
2637
+
2638
+	/**
2639
+	 * displays an error message to ppl who have javascript disabled
2640
+	 *
2641
+	 * @return void
2642
+	 */
2643
+	private function _display_no_javascript_warning()
2644
+	{
2645
+		?>
2646 2646
         <noscript>
2647 2647
             <div id="no-js-message" class="error">
2648 2648
                 <p style="font-size:1.3em;">
2649 2649
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2650 2650
                     <?php esc_html_e(
2651
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2652
-                        'event_espresso'
2653
-                    ); ?>
2651
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2652
+						'event_espresso'
2653
+					); ?>
2654 2654
                 </p>
2655 2655
             </div>
2656 2656
         </noscript>
2657 2657
         <?php
2658
-    }
2659
-
2660
-
2661
-    /**
2662
-     * displays espresso success and/or error notices
2663
-     *
2664
-     * @return void
2665
-     */
2666
-    protected function _display_espresso_notices()
2667
-    {
2668
-        $notices = $this->_get_transient(true);
2669
-        echo stripslashes($notices);
2670
-    }
2671
-
2672
-
2673
-    /**
2674
-     * spinny things pacify the masses
2675
-     *
2676
-     * @return void
2677
-     */
2678
-    protected function _add_admin_page_ajax_loading_img()
2679
-    {
2680
-        ?>
2658
+	}
2659
+
2660
+
2661
+	/**
2662
+	 * displays espresso success and/or error notices
2663
+	 *
2664
+	 * @return void
2665
+	 */
2666
+	protected function _display_espresso_notices()
2667
+	{
2668
+		$notices = $this->_get_transient(true);
2669
+		echo stripslashes($notices);
2670
+	}
2671
+
2672
+
2673
+	/**
2674
+	 * spinny things pacify the masses
2675
+	 *
2676
+	 * @return void
2677
+	 */
2678
+	protected function _add_admin_page_ajax_loading_img()
2679
+	{
2680
+		?>
2681 2681
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2682 2682
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2683
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2683
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2684 2684
         </div>
2685 2685
         <?php
2686
-    }
2686
+	}
2687 2687
 
2688 2688
 
2689
-    /**
2690
-     * add admin page overlay for modal boxes
2691
-     *
2692
-     * @return void
2693
-     */
2694
-    protected function _add_admin_page_overlay()
2695
-    {
2696
-        ?>
2689
+	/**
2690
+	 * add admin page overlay for modal boxes
2691
+	 *
2692
+	 * @return void
2693
+	 */
2694
+	protected function _add_admin_page_overlay()
2695
+	{
2696
+		?>
2697 2697
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2698 2698
         <?php
2699
-    }
2700
-
2701
-
2702
-    /**
2703
-     * facade for $this->addMetaBox()
2704
-     *
2705
-     * @param string  $action        where the metabox gets displayed
2706
-     * @param string  $title         Title of Metabox (output in metabox header)
2707
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2708
-     *                               instead of the one created in here.
2709
-     * @param array   $callback_args an array of args supplied for the metabox
2710
-     * @param string  $column        what metabox column
2711
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2712
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2713
-     *                               created but just set our own callback for wp's add_meta_box.
2714
-     * @throws DomainException
2715
-     */
2716
-    public function _add_admin_page_meta_box(
2717
-        $action,
2718
-        $title,
2719
-        $callback,
2720
-        $callback_args,
2721
-        $column = 'normal',
2722
-        $priority = 'high',
2723
-        $create_func = true
2724
-    ) {
2725
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2726
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2727
-        if (empty($callback_args) && $create_func) {
2728
-            $callback_args = [
2729
-                'template_path' => $this->_template_path,
2730
-                'template_args' => $this->_template_args,
2731
-            ];
2732
-        }
2733
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2734
-        $call_back_func = $create_func
2735
-            ? static function ($post, $metabox) {
2736
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2737
-                echo EEH_Template::display_template(
2738
-                    $metabox['args']['template_path'],
2739
-                    $metabox['args']['template_args'],
2740
-                    true
2741
-                );
2742
-            }
2743
-            : $callback;
2744
-        $this->addMetaBox(
2745
-            str_replace('_', '-', $action) . '-mbox',
2746
-            $title,
2747
-            $call_back_func,
2748
-            $this->_wp_page_slug,
2749
-            $column,
2750
-            $priority,
2751
-            $callback_args
2752
-        );
2753
-    }
2754
-
2755
-
2756
-    /**
2757
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2758
-     *
2759
-     * @throws DomainException
2760
-     * @throws EE_Error
2761
-     * @throws InvalidArgumentException
2762
-     * @throws InvalidDataTypeException
2763
-     * @throws InvalidInterfaceException
2764
-     */
2765
-    public function display_admin_page_with_metabox_columns()
2766
-    {
2767
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2768
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2769
-            $this->_column_template_path,
2770
-            $this->_template_args,
2771
-            true
2772
-        );
2773
-        // the final wrapper
2774
-        $this->admin_page_wrapper();
2775
-    }
2776
-
2777
-
2778
-    /**
2779
-     * generates  HTML wrapper for an admin details page
2780
-     *
2781
-     * @return void
2782
-     * @throws DomainException
2783
-     * @throws EE_Error
2784
-     * @throws InvalidArgumentException
2785
-     * @throws InvalidDataTypeException
2786
-     * @throws InvalidInterfaceException
2787
-     */
2788
-    public function display_admin_page_with_sidebar()
2789
-    {
2790
-        $this->_display_admin_page(true);
2791
-    }
2792
-
2793
-
2794
-    /**
2795
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2796
-     *
2797
-     * @return void
2798
-     * @throws DomainException
2799
-     * @throws EE_Error
2800
-     * @throws InvalidArgumentException
2801
-     * @throws InvalidDataTypeException
2802
-     * @throws InvalidInterfaceException
2803
-     */
2804
-    public function display_admin_page_with_no_sidebar()
2805
-    {
2806
-        $this->_display_admin_page();
2807
-    }
2808
-
2809
-
2810
-    /**
2811
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2812
-     *
2813
-     * @return void
2814
-     * @throws DomainException
2815
-     * @throws EE_Error
2816
-     * @throws InvalidArgumentException
2817
-     * @throws InvalidDataTypeException
2818
-     * @throws InvalidInterfaceException
2819
-     */
2820
-    public function display_about_admin_page()
2821
-    {
2822
-        $this->_display_admin_page(false, true);
2823
-    }
2824
-
2825
-
2826
-    /**
2827
-     * display_admin_page
2828
-     * contains the code for actually displaying an admin page
2829
-     *
2830
-     * @param boolean $sidebar true with sidebar, false without
2831
-     * @param boolean $about   use the about admin wrapper instead of the default.
2832
-     * @return void
2833
-     * @throws DomainException
2834
-     * @throws EE_Error
2835
-     * @throws InvalidArgumentException
2836
-     * @throws InvalidDataTypeException
2837
-     * @throws InvalidInterfaceException
2838
-     */
2839
-    private function _display_admin_page($sidebar = false, $about = false)
2840
-    {
2841
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2842
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2843
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2844
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2845
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2846
-
2847
-        $post_body_content = $this->_template_args['before_admin_page_content'] ?? '';
2848
-
2849
-        $this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status'
2850
-                                                  && $this->_req_action !== 'data_reset'
2851
-                                                  && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages'
2852
-                                                  && strpos($post_body_content, 'wp-list-table') === false;
2853
-
2854
-        $this->_template_args['current_page']                 = $this->_wp_page_slug;
2855
-        $this->_template_args['admin_page_wrapper_div_id']    = $this->_cpt_route
2856
-            ? 'poststuff'
2857
-            : 'espresso-default-admin';
2858
-        $this->_template_args['admin_page_wrapper_div_class'] = str_replace(
2859
-                                                                    'event-espresso_page_espresso_',
2860
-                                                                    '',
2861
-                                                                    $this->_wp_page_slug
2862
-                                                                ) . ' ' . $this->_req_action . '-route';
2863
-
2864
-        $template_path = $sidebar
2865
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2866
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2867
-        if ($this->request->isAjax()) {
2868
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2869
-        }
2870
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2871
-
2872
-        $this->_template_args['post_body_content']         = $this->_template_args['admin_page_content'] ?? '';
2873
-        $this->_template_args['before_admin_page_content'] = $post_body_content;
2874
-        $this->_template_args['after_admin_page_content']  = $this->_template_args['after_admin_page_content'] ?? '';
2875
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2876
-            $template_path,
2877
-            $this->_template_args,
2878
-            true
2879
-        );
2880
-        // the final template wrapper
2881
-        $this->admin_page_wrapper($about);
2882
-    }
2883
-
2884
-
2885
-    /**
2886
-     * This is used to display caf preview pages.
2887
-     *
2888
-     * @param string $utm_campaign_source what is the key used for google analytics link
2889
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2890
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2891
-     * @return void
2892
-     * @throws DomainException
2893
-     * @throws EE_Error
2894
-     * @throws InvalidArgumentException
2895
-     * @throws InvalidDataTypeException
2896
-     * @throws InvalidInterfaceException
2897
-     * @since 4.3.2
2898
-     */
2899
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2900
-    {
2901
-        // let's generate a default preview action button if there isn't one already present.
2902
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2903
-            'Upgrade to Event Espresso 4 Right Now',
2904
-            'event_espresso'
2905
-        );
2906
-        $buy_now_url                                   = add_query_arg(
2907
-            [
2908
-                'ee_ver'       => 'ee4',
2909
-                'utm_source'   => 'ee4_plugin_admin',
2910
-                'utm_medium'   => 'link',
2911
-                'utm_campaign' => $utm_campaign_source,
2912
-                'utm_content'  => 'buy_now_button',
2913
-            ],
2914
-            'https://eventespresso.com/pricing/'
2915
-        );
2916
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2917
-            ? $this->get_action_link_or_button(
2918
-                '',
2919
-                'buy_now',
2920
-                [],
2921
-                'button button--primary button--big',
2922
-                esc_url_raw($buy_now_url),
2923
-                true
2924
-            )
2925
-            : $this->_template_args['preview_action_button'];
2926
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2927
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2928
-            $this->_template_args,
2929
-            true
2930
-        );
2931
-        $this->_display_admin_page($display_sidebar);
2932
-    }
2933
-
2934
-
2935
-    /**
2936
-     * display_admin_list_table_page_with_sidebar
2937
-     * generates HTML wrapper for an admin_page with list_table
2938
-     *
2939
-     * @return void
2940
-     * @throws DomainException
2941
-     * @throws EE_Error
2942
-     * @throws InvalidArgumentException
2943
-     * @throws InvalidDataTypeException
2944
-     * @throws InvalidInterfaceException
2945
-     */
2946
-    public function display_admin_list_table_page_with_sidebar()
2947
-    {
2948
-        $this->_display_admin_list_table_page(true);
2949
-    }
2950
-
2951
-
2952
-    /**
2953
-     * display_admin_list_table_page_with_no_sidebar
2954
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2955
-     *
2956
-     * @return void
2957
-     * @throws DomainException
2958
-     * @throws EE_Error
2959
-     * @throws InvalidArgumentException
2960
-     * @throws InvalidDataTypeException
2961
-     * @throws InvalidInterfaceException
2962
-     */
2963
-    public function display_admin_list_table_page_with_no_sidebar()
2964
-    {
2965
-        $this->_display_admin_list_table_page();
2966
-    }
2967
-
2968
-
2969
-    /**
2970
-     * generates html wrapper for an admin_list_table page
2971
-     *
2972
-     * @param boolean $sidebar whether to display with sidebar or not.
2973
-     * @return void
2974
-     * @throws DomainException
2975
-     * @throws EE_Error
2976
-     * @throws InvalidArgumentException
2977
-     * @throws InvalidDataTypeException
2978
-     * @throws InvalidInterfaceException
2979
-     */
2980
-    private function _display_admin_list_table_page($sidebar = false)
2981
-    {
2982
-        // setup search attributes
2983
-        $this->_set_search_attributes();
2984
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2985
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2986
-        $this->_template_args['table_url']        = $this->request->isAjax()
2987
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2988
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2989
-        $this->_template_args['list_table']       = $this->_list_table_object;
2990
-        $this->_template_args['current_route']    = $this->_req_action;
2991
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2992
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2993
-        if (! empty($ajax_sorting_callback)) {
2994
-            $sortable_list_table_form_fields = wp_nonce_field(
2995
-                $ajax_sorting_callback . '_nonce',
2996
-                $ajax_sorting_callback . '_nonce',
2997
-                false,
2998
-                false
2999
-            );
3000
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3001
-                                                . $this->page_slug
3002
-                                                . '" />';
3003
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3004
-                                                . $ajax_sorting_callback
3005
-                                                . '" />';
3006
-        } else {
3007
-            $sortable_list_table_form_fields = '';
3008
-        }
3009
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3010
-
3011
-        $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
3012
-
3013
-        $nonce_ref          = $this->_req_action . '_nonce';
3014
-        $hidden_form_fields .= '
2699
+	}
2700
+
2701
+
2702
+	/**
2703
+	 * facade for $this->addMetaBox()
2704
+	 *
2705
+	 * @param string  $action        where the metabox gets displayed
2706
+	 * @param string  $title         Title of Metabox (output in metabox header)
2707
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2708
+	 *                               instead of the one created in here.
2709
+	 * @param array   $callback_args an array of args supplied for the metabox
2710
+	 * @param string  $column        what metabox column
2711
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2712
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2713
+	 *                               created but just set our own callback for wp's add_meta_box.
2714
+	 * @throws DomainException
2715
+	 */
2716
+	public function _add_admin_page_meta_box(
2717
+		$action,
2718
+		$title,
2719
+		$callback,
2720
+		$callback_args,
2721
+		$column = 'normal',
2722
+		$priority = 'high',
2723
+		$create_func = true
2724
+	) {
2725
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2726
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2727
+		if (empty($callback_args) && $create_func) {
2728
+			$callback_args = [
2729
+				'template_path' => $this->_template_path,
2730
+				'template_args' => $this->_template_args,
2731
+			];
2732
+		}
2733
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2734
+		$call_back_func = $create_func
2735
+			? static function ($post, $metabox) {
2736
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2737
+				echo EEH_Template::display_template(
2738
+					$metabox['args']['template_path'],
2739
+					$metabox['args']['template_args'],
2740
+					true
2741
+				);
2742
+			}
2743
+			: $callback;
2744
+		$this->addMetaBox(
2745
+			str_replace('_', '-', $action) . '-mbox',
2746
+			$title,
2747
+			$call_back_func,
2748
+			$this->_wp_page_slug,
2749
+			$column,
2750
+			$priority,
2751
+			$callback_args
2752
+		);
2753
+	}
2754
+
2755
+
2756
+	/**
2757
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2758
+	 *
2759
+	 * @throws DomainException
2760
+	 * @throws EE_Error
2761
+	 * @throws InvalidArgumentException
2762
+	 * @throws InvalidDataTypeException
2763
+	 * @throws InvalidInterfaceException
2764
+	 */
2765
+	public function display_admin_page_with_metabox_columns()
2766
+	{
2767
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2768
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2769
+			$this->_column_template_path,
2770
+			$this->_template_args,
2771
+			true
2772
+		);
2773
+		// the final wrapper
2774
+		$this->admin_page_wrapper();
2775
+	}
2776
+
2777
+
2778
+	/**
2779
+	 * generates  HTML wrapper for an admin details page
2780
+	 *
2781
+	 * @return void
2782
+	 * @throws DomainException
2783
+	 * @throws EE_Error
2784
+	 * @throws InvalidArgumentException
2785
+	 * @throws InvalidDataTypeException
2786
+	 * @throws InvalidInterfaceException
2787
+	 */
2788
+	public function display_admin_page_with_sidebar()
2789
+	{
2790
+		$this->_display_admin_page(true);
2791
+	}
2792
+
2793
+
2794
+	/**
2795
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2796
+	 *
2797
+	 * @return void
2798
+	 * @throws DomainException
2799
+	 * @throws EE_Error
2800
+	 * @throws InvalidArgumentException
2801
+	 * @throws InvalidDataTypeException
2802
+	 * @throws InvalidInterfaceException
2803
+	 */
2804
+	public function display_admin_page_with_no_sidebar()
2805
+	{
2806
+		$this->_display_admin_page();
2807
+	}
2808
+
2809
+
2810
+	/**
2811
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2812
+	 *
2813
+	 * @return void
2814
+	 * @throws DomainException
2815
+	 * @throws EE_Error
2816
+	 * @throws InvalidArgumentException
2817
+	 * @throws InvalidDataTypeException
2818
+	 * @throws InvalidInterfaceException
2819
+	 */
2820
+	public function display_about_admin_page()
2821
+	{
2822
+		$this->_display_admin_page(false, true);
2823
+	}
2824
+
2825
+
2826
+	/**
2827
+	 * display_admin_page
2828
+	 * contains the code for actually displaying an admin page
2829
+	 *
2830
+	 * @param boolean $sidebar true with sidebar, false without
2831
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2832
+	 * @return void
2833
+	 * @throws DomainException
2834
+	 * @throws EE_Error
2835
+	 * @throws InvalidArgumentException
2836
+	 * @throws InvalidDataTypeException
2837
+	 * @throws InvalidInterfaceException
2838
+	 */
2839
+	private function _display_admin_page($sidebar = false, $about = false)
2840
+	{
2841
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2842
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2843
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2844
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2845
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2846
+
2847
+		$post_body_content = $this->_template_args['before_admin_page_content'] ?? '';
2848
+
2849
+		$this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status'
2850
+												  && $this->_req_action !== 'data_reset'
2851
+												  && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages'
2852
+												  && strpos($post_body_content, 'wp-list-table') === false;
2853
+
2854
+		$this->_template_args['current_page']                 = $this->_wp_page_slug;
2855
+		$this->_template_args['admin_page_wrapper_div_id']    = $this->_cpt_route
2856
+			? 'poststuff'
2857
+			: 'espresso-default-admin';
2858
+		$this->_template_args['admin_page_wrapper_div_class'] = str_replace(
2859
+																	'event-espresso_page_espresso_',
2860
+																	'',
2861
+																	$this->_wp_page_slug
2862
+																) . ' ' . $this->_req_action . '-route';
2863
+
2864
+		$template_path = $sidebar
2865
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2866
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2867
+		if ($this->request->isAjax()) {
2868
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2869
+		}
2870
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2871
+
2872
+		$this->_template_args['post_body_content']         = $this->_template_args['admin_page_content'] ?? '';
2873
+		$this->_template_args['before_admin_page_content'] = $post_body_content;
2874
+		$this->_template_args['after_admin_page_content']  = $this->_template_args['after_admin_page_content'] ?? '';
2875
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2876
+			$template_path,
2877
+			$this->_template_args,
2878
+			true
2879
+		);
2880
+		// the final template wrapper
2881
+		$this->admin_page_wrapper($about);
2882
+	}
2883
+
2884
+
2885
+	/**
2886
+	 * This is used to display caf preview pages.
2887
+	 *
2888
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2889
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2890
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2891
+	 * @return void
2892
+	 * @throws DomainException
2893
+	 * @throws EE_Error
2894
+	 * @throws InvalidArgumentException
2895
+	 * @throws InvalidDataTypeException
2896
+	 * @throws InvalidInterfaceException
2897
+	 * @since 4.3.2
2898
+	 */
2899
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2900
+	{
2901
+		// let's generate a default preview action button if there isn't one already present.
2902
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2903
+			'Upgrade to Event Espresso 4 Right Now',
2904
+			'event_espresso'
2905
+		);
2906
+		$buy_now_url                                   = add_query_arg(
2907
+			[
2908
+				'ee_ver'       => 'ee4',
2909
+				'utm_source'   => 'ee4_plugin_admin',
2910
+				'utm_medium'   => 'link',
2911
+				'utm_campaign' => $utm_campaign_source,
2912
+				'utm_content'  => 'buy_now_button',
2913
+			],
2914
+			'https://eventespresso.com/pricing/'
2915
+		);
2916
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2917
+			? $this->get_action_link_or_button(
2918
+				'',
2919
+				'buy_now',
2920
+				[],
2921
+				'button button--primary button--big',
2922
+				esc_url_raw($buy_now_url),
2923
+				true
2924
+			)
2925
+			: $this->_template_args['preview_action_button'];
2926
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2927
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2928
+			$this->_template_args,
2929
+			true
2930
+		);
2931
+		$this->_display_admin_page($display_sidebar);
2932
+	}
2933
+
2934
+
2935
+	/**
2936
+	 * display_admin_list_table_page_with_sidebar
2937
+	 * generates HTML wrapper for an admin_page with list_table
2938
+	 *
2939
+	 * @return void
2940
+	 * @throws DomainException
2941
+	 * @throws EE_Error
2942
+	 * @throws InvalidArgumentException
2943
+	 * @throws InvalidDataTypeException
2944
+	 * @throws InvalidInterfaceException
2945
+	 */
2946
+	public function display_admin_list_table_page_with_sidebar()
2947
+	{
2948
+		$this->_display_admin_list_table_page(true);
2949
+	}
2950
+
2951
+
2952
+	/**
2953
+	 * display_admin_list_table_page_with_no_sidebar
2954
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2955
+	 *
2956
+	 * @return void
2957
+	 * @throws DomainException
2958
+	 * @throws EE_Error
2959
+	 * @throws InvalidArgumentException
2960
+	 * @throws InvalidDataTypeException
2961
+	 * @throws InvalidInterfaceException
2962
+	 */
2963
+	public function display_admin_list_table_page_with_no_sidebar()
2964
+	{
2965
+		$this->_display_admin_list_table_page();
2966
+	}
2967
+
2968
+
2969
+	/**
2970
+	 * generates html wrapper for an admin_list_table page
2971
+	 *
2972
+	 * @param boolean $sidebar whether to display with sidebar or not.
2973
+	 * @return void
2974
+	 * @throws DomainException
2975
+	 * @throws EE_Error
2976
+	 * @throws InvalidArgumentException
2977
+	 * @throws InvalidDataTypeException
2978
+	 * @throws InvalidInterfaceException
2979
+	 */
2980
+	private function _display_admin_list_table_page($sidebar = false)
2981
+	{
2982
+		// setup search attributes
2983
+		$this->_set_search_attributes();
2984
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2985
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2986
+		$this->_template_args['table_url']        = $this->request->isAjax()
2987
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2988
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2989
+		$this->_template_args['list_table']       = $this->_list_table_object;
2990
+		$this->_template_args['current_route']    = $this->_req_action;
2991
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2992
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2993
+		if (! empty($ajax_sorting_callback)) {
2994
+			$sortable_list_table_form_fields = wp_nonce_field(
2995
+				$ajax_sorting_callback . '_nonce',
2996
+				$ajax_sorting_callback . '_nonce',
2997
+				false,
2998
+				false
2999
+			);
3000
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3001
+												. $this->page_slug
3002
+												. '" />';
3003
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3004
+												. $ajax_sorting_callback
3005
+												. '" />';
3006
+		} else {
3007
+			$sortable_list_table_form_fields = '';
3008
+		}
3009
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3010
+
3011
+		$hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
3012
+
3013
+		$nonce_ref          = $this->_req_action . '_nonce';
3014
+		$hidden_form_fields .= '
3015 3015
             <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
3016 3016
 
3017
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3018
-        // display message about search results?
3019
-        $search                                    = $this->request->getRequestParam('s');
3020
-        $this->_template_args['before_list_table'] .= ! empty($search)
3021
-            ? '<p class="ee-search-results">' . sprintf(
3022
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3023
-                trim($search, '%')
3024
-            ) . '</p>'
3025
-            : '';
3026
-        // filter before_list_table template arg
3027
-        $this->_template_args['before_list_table'] = apply_filters(
3028
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3029
-            $this->_template_args['before_list_table'],
3030
-            $this->page_slug,
3031
-            $this->request->requestParams(),
3032
-            $this->_req_action
3033
-        );
3034
-        // convert to array and filter again
3035
-        // arrays are easier to inject new items in a specific location,
3036
-        // but would not be backwards compatible, so we have to add a new filter
3037
-        $this->_template_args['before_list_table'] = implode(
3038
-            " \n",
3039
-            (array) apply_filters(
3040
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3041
-                (array) $this->_template_args['before_list_table'],
3042
-                $this->page_slug,
3043
-                $this->request->requestParams(),
3044
-                $this->_req_action
3045
-            )
3046
-        );
3047
-        // filter after_list_table template arg
3048
-        $this->_template_args['after_list_table'] = apply_filters(
3049
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3050
-            $this->_template_args['after_list_table'],
3051
-            $this->page_slug,
3052
-            $this->request->requestParams(),
3053
-            $this->_req_action
3054
-        );
3055
-        // convert to array and filter again
3056
-        // arrays are easier to inject new items in a specific location,
3057
-        // but would not be backwards compatible, so we have to add a new filter
3058
-        $this->_template_args['after_list_table']   = implode(
3059
-            " \n",
3060
-            (array) apply_filters(
3061
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3062
-                (array) $this->_template_args['after_list_table'],
3063
-                $this->page_slug,
3064
-                $this->request->requestParams(),
3065
-                $this->_req_action
3066
-            )
3067
-        );
3068
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3069
-            $template_path,
3070
-            $this->_template_args,
3071
-            true
3072
-        );
3073
-        // the final template wrapper
3074
-        if ($sidebar) {
3075
-            $this->display_admin_page_with_sidebar();
3076
-        } else {
3077
-            $this->display_admin_page_with_no_sidebar();
3078
-        }
3079
-    }
3080
-
3081
-
3082
-    /**
3083
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3084
-     * html string for the legend.
3085
-     * $items are expected in an array in the following format:
3086
-     * $legend_items = array(
3087
-     *        'item_id' => array(
3088
-     *            'icon' => 'http://url_to_icon_being_described.png',
3089
-     *            'desc' => esc_html__('localized description of item');
3090
-     *        )
3091
-     * );
3092
-     *
3093
-     * @param array $items see above for format of array
3094
-     * @return string html string of legend
3095
-     * @throws DomainException
3096
-     */
3097
-    protected function _display_legend($items)
3098
-    {
3099
-        $this->_template_args['items'] = apply_filters(
3100
-            'FHEE__EE_Admin_Page___display_legend__items',
3101
-            (array) $items,
3102
-            $this
3103
-        );
3104
-        /** @var StatusChangeNotice $status_change_notice */
3105
-        $status_change_notice                         = $this->loader->getShared(
3106
-            'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
3107
-        );
3108
-        $this->_template_args['status_change_notice'] = $status_change_notice->display(
3109
-            '__admin-legend',
3110
-            $this->page_slug
3111
-        );
3112
-        return EEH_Template::display_template(
3113
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3114
-            $this->_template_args,
3115
-            true
3116
-        );
3117
-    }
3118
-
3119
-
3120
-    /**
3121
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3122
-     * The returned json object is created from an array in the following format:
3123
-     * array(
3124
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3125
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3126
-     *  'notices' => '', // - contains any EE_Error formatted notices
3127
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3128
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3129
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3130
-     *  that might be included in here)
3131
-     * )
3132
-     * The json object is populated by whatever is set in the $_template_args property.
3133
-     *
3134
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3135
-     *                                 instead of displayed.
3136
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3137
-     * @return void
3138
-     * @throws EE_Error
3139
-     * @throws InvalidArgumentException
3140
-     * @throws InvalidDataTypeException
3141
-     * @throws InvalidInterfaceException
3142
-     */
3143
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
3144
-    {
3145
-        // make sure any EE_Error notices have been handled.
3146
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3147
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3148
-        unset($this->_template_args['data']);
3149
-        $json = [
3150
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3151
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3152
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3153
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3154
-            'notices'   => EE_Error::get_notices(),
3155
-            'content'   => isset($this->_template_args['admin_page_content'])
3156
-                ? $this->_template_args['admin_page_content'] : '',
3157
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3158
-            'isEEajax'  => true
3159
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3160
-        ];
3161
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3162
-        if (null === error_get_last() || ! headers_sent()) {
3163
-            header('Content-Type: application/json; charset=UTF-8');
3164
-        }
3165
-        echo wp_json_encode($json);
3166
-        exit();
3167
-    }
3168
-
3169
-
3170
-    /**
3171
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3172
-     *
3173
-     * @return void
3174
-     * @throws EE_Error
3175
-     * @throws InvalidArgumentException
3176
-     * @throws InvalidDataTypeException
3177
-     * @throws InvalidInterfaceException
3178
-     */
3179
-    public function return_json()
3180
-    {
3181
-        if ($this->request->isAjax()) {
3182
-            $this->_return_json();
3183
-        } else {
3184
-            throw new EE_Error(
3185
-                sprintf(
3186
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3187
-                    __FUNCTION__
3188
-                )
3189
-            );
3190
-        }
3191
-    }
3192
-
3193
-
3194
-    /**
3195
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3196
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3197
-     *
3198
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3199
-     */
3200
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3201
-    {
3202
-        $this->_hook_obj = $hook_obj;
3203
-    }
3204
-
3205
-
3206
-    /**
3207
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3208
-     *
3209
-     * @param boolean $about whether to use the special about page wrapper or default.
3210
-     * @return void
3211
-     * @throws DomainException
3212
-     * @throws EE_Error
3213
-     * @throws InvalidArgumentException
3214
-     * @throws InvalidDataTypeException
3215
-     * @throws InvalidInterfaceException
3216
-     */
3217
-    public function admin_page_wrapper($about = false)
3218
-    {
3219
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3220
-        $this->_nav_tabs                          = $this->_get_main_nav_tabs();
3221
-        $this->_template_args['nav_tabs']         = $this->_nav_tabs;
3222
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
3223
-
3224
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3225
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3226
-            $this->_template_args['before_admin_page_content'] ?? ''
3227
-        );
3228
-
3229
-        $this->_template_args['after_admin_page_content'] = apply_filters(
3230
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3231
-            $this->_template_args['after_admin_page_content'] ?? ''
3232
-        );
3233
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3234
-
3235
-        if ($this->request->isAjax()) {
3236
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3237
-            // $template_path,
3238
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3239
-                $this->_template_args,
3240
-                true
3241
-            );
3242
-            $this->_return_json();
3243
-        }
3244
-        // load settings page wrapper template
3245
-        $template_path = $about
3246
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3247
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3248
-
3249
-        EEH_Template::display_template($template_path, $this->_template_args);
3250
-    }
3251
-
3252
-
3253
-    /**
3254
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3255
-     *
3256
-     * @return string html
3257
-     * @throws EE_Error
3258
-     */
3259
-    protected function _get_main_nav_tabs()
3260
-    {
3261
-        // let's generate the html using the EEH_Tabbed_Content helper.
3262
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3263
-        // (rather than setting in the page_routes array)
3264
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs, $this->page_slug);
3265
-    }
3266
-
3267
-
3268
-    /**
3269
-     *        sort nav tabs
3270
-     *
3271
-     * @param $a
3272
-     * @param $b
3273
-     * @return int
3274
-     */
3275
-    private function _sort_nav_tabs($a, $b)
3276
-    {
3277
-        if ($a['order'] === $b['order']) {
3278
-            return 0;
3279
-        }
3280
-        return ($a['order'] < $b['order']) ? -1 : 1;
3281
-    }
3282
-
3283
-
3284
-    /**
3285
-     * generates HTML for the forms used on admin pages
3286
-     *
3287
-     * @param array  $input_vars - array of input field details
3288
-     * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3289
-     * @param bool   $id
3290
-     * @return array|string
3291
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3292
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3293
-     */
3294
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3295
-    {
3296
-        return $generator === 'string'
3297
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3298
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3299
-    }
3300
-
3301
-
3302
-    /**
3303
-     * generates the "Save" and "Save & Close" buttons for edit forms
3304
-     *
3305
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3306
-     *                                   Close" button.
3307
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3308
-     *                                   'Save', [1] => 'save & close')
3309
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3310
-     *                                   via the "name" value in the button).  We can also use this to just dump
3311
-     *                                   default actions by submitting some other value.
3312
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3313
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3314
-     *                                   close (normal form handling).
3315
-     */
3316
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3317
-    {
3318
-        // make sure $text and $actions are in an array
3319
-        $text          = (array) $text;
3320
-        $actions       = (array) $actions;
3321
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3322
-        $button_text   = ! empty($text)
3323
-            ? $text
3324
-            : [
3325
-                esc_html__('Save', 'event_espresso'),
3326
-                esc_html__('Save and Close', 'event_espresso'),
3327
-            ];
3328
-        $default_names = ['save', 'save_and_close'];
3329
-        $buttons       = '';
3330
-        foreach ($button_text as $key => $button) {
3331
-            $ref     = $default_names[ $key ];
3332
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3333
-            $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3334
-                        . 'value="' . $button . '" name="' . $name . '" '
3335
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3336
-            if (! $both) {
3337
-                break;
3338
-            }
3339
-        }
3340
-        // add in a hidden index for the current page (so save and close redirects properly)
3341
-        $buttons                              .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3342
-                                                 . $referrer_url
3343
-                                                 . '" />';
3344
-        $this->_template_args['save_buttons'] = $buttons;
3345
-    }
3346
-
3347
-
3348
-    /**
3349
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3350
-     *
3351
-     * @param string $route
3352
-     * @param array  $additional_hidden_fields
3353
-     * @see   $this->_set_add_edit_form_tags() for details on params
3354
-     * @since 4.6.0
3355
-     */
3356
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3357
-    {
3358
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3359
-    }
3360
-
3361
-
3362
-    /**
3363
-     * set form open and close tags on add/edit pages.
3364
-     *
3365
-     * @param string $route                    the route you want the form to direct to
3366
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3367
-     * @return void
3368
-     */
3369
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3370
-    {
3371
-        if (empty($route)) {
3372
-            $user_msg = esc_html__(
3373
-                'An error occurred. No action was set for this page\'s form.',
3374
-                'event_espresso'
3375
-            );
3376
-            $dev_msg  = $user_msg . "\n"
3377
-                        . sprintf(
3378
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3379
-                            __FUNCTION__,
3380
-                            __CLASS__
3381
-                        );
3382
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3383
-        }
3384
-        // open form
3385
-        $action                                            = $this->_admin_base_url;
3386
-        $this->_template_args['before_admin_page_content'] = "
3017
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3018
+		// display message about search results?
3019
+		$search                                    = $this->request->getRequestParam('s');
3020
+		$this->_template_args['before_list_table'] .= ! empty($search)
3021
+			? '<p class="ee-search-results">' . sprintf(
3022
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3023
+				trim($search, '%')
3024
+			) . '</p>'
3025
+			: '';
3026
+		// filter before_list_table template arg
3027
+		$this->_template_args['before_list_table'] = apply_filters(
3028
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3029
+			$this->_template_args['before_list_table'],
3030
+			$this->page_slug,
3031
+			$this->request->requestParams(),
3032
+			$this->_req_action
3033
+		);
3034
+		// convert to array and filter again
3035
+		// arrays are easier to inject new items in a specific location,
3036
+		// but would not be backwards compatible, so we have to add a new filter
3037
+		$this->_template_args['before_list_table'] = implode(
3038
+			" \n",
3039
+			(array) apply_filters(
3040
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3041
+				(array) $this->_template_args['before_list_table'],
3042
+				$this->page_slug,
3043
+				$this->request->requestParams(),
3044
+				$this->_req_action
3045
+			)
3046
+		);
3047
+		// filter after_list_table template arg
3048
+		$this->_template_args['after_list_table'] = apply_filters(
3049
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3050
+			$this->_template_args['after_list_table'],
3051
+			$this->page_slug,
3052
+			$this->request->requestParams(),
3053
+			$this->_req_action
3054
+		);
3055
+		// convert to array and filter again
3056
+		// arrays are easier to inject new items in a specific location,
3057
+		// but would not be backwards compatible, so we have to add a new filter
3058
+		$this->_template_args['after_list_table']   = implode(
3059
+			" \n",
3060
+			(array) apply_filters(
3061
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3062
+				(array) $this->_template_args['after_list_table'],
3063
+				$this->page_slug,
3064
+				$this->request->requestParams(),
3065
+				$this->_req_action
3066
+			)
3067
+		);
3068
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3069
+			$template_path,
3070
+			$this->_template_args,
3071
+			true
3072
+		);
3073
+		// the final template wrapper
3074
+		if ($sidebar) {
3075
+			$this->display_admin_page_with_sidebar();
3076
+		} else {
3077
+			$this->display_admin_page_with_no_sidebar();
3078
+		}
3079
+	}
3080
+
3081
+
3082
+	/**
3083
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3084
+	 * html string for the legend.
3085
+	 * $items are expected in an array in the following format:
3086
+	 * $legend_items = array(
3087
+	 *        'item_id' => array(
3088
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3089
+	 *            'desc' => esc_html__('localized description of item');
3090
+	 *        )
3091
+	 * );
3092
+	 *
3093
+	 * @param array $items see above for format of array
3094
+	 * @return string html string of legend
3095
+	 * @throws DomainException
3096
+	 */
3097
+	protected function _display_legend($items)
3098
+	{
3099
+		$this->_template_args['items'] = apply_filters(
3100
+			'FHEE__EE_Admin_Page___display_legend__items',
3101
+			(array) $items,
3102
+			$this
3103
+		);
3104
+		/** @var StatusChangeNotice $status_change_notice */
3105
+		$status_change_notice                         = $this->loader->getShared(
3106
+			'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
3107
+		);
3108
+		$this->_template_args['status_change_notice'] = $status_change_notice->display(
3109
+			'__admin-legend',
3110
+			$this->page_slug
3111
+		);
3112
+		return EEH_Template::display_template(
3113
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3114
+			$this->_template_args,
3115
+			true
3116
+		);
3117
+	}
3118
+
3119
+
3120
+	/**
3121
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3122
+	 * The returned json object is created from an array in the following format:
3123
+	 * array(
3124
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3125
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3126
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3127
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3128
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3129
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3130
+	 *  that might be included in here)
3131
+	 * )
3132
+	 * The json object is populated by whatever is set in the $_template_args property.
3133
+	 *
3134
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3135
+	 *                                 instead of displayed.
3136
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3137
+	 * @return void
3138
+	 * @throws EE_Error
3139
+	 * @throws InvalidArgumentException
3140
+	 * @throws InvalidDataTypeException
3141
+	 * @throws InvalidInterfaceException
3142
+	 */
3143
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
3144
+	{
3145
+		// make sure any EE_Error notices have been handled.
3146
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3147
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3148
+		unset($this->_template_args['data']);
3149
+		$json = [
3150
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3151
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3152
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3153
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3154
+			'notices'   => EE_Error::get_notices(),
3155
+			'content'   => isset($this->_template_args['admin_page_content'])
3156
+				? $this->_template_args['admin_page_content'] : '',
3157
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3158
+			'isEEajax'  => true
3159
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3160
+		];
3161
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3162
+		if (null === error_get_last() || ! headers_sent()) {
3163
+			header('Content-Type: application/json; charset=UTF-8');
3164
+		}
3165
+		echo wp_json_encode($json);
3166
+		exit();
3167
+	}
3168
+
3169
+
3170
+	/**
3171
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3172
+	 *
3173
+	 * @return void
3174
+	 * @throws EE_Error
3175
+	 * @throws InvalidArgumentException
3176
+	 * @throws InvalidDataTypeException
3177
+	 * @throws InvalidInterfaceException
3178
+	 */
3179
+	public function return_json()
3180
+	{
3181
+		if ($this->request->isAjax()) {
3182
+			$this->_return_json();
3183
+		} else {
3184
+			throw new EE_Error(
3185
+				sprintf(
3186
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3187
+					__FUNCTION__
3188
+				)
3189
+			);
3190
+		}
3191
+	}
3192
+
3193
+
3194
+	/**
3195
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3196
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3197
+	 *
3198
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3199
+	 */
3200
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3201
+	{
3202
+		$this->_hook_obj = $hook_obj;
3203
+	}
3204
+
3205
+
3206
+	/**
3207
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3208
+	 *
3209
+	 * @param boolean $about whether to use the special about page wrapper or default.
3210
+	 * @return void
3211
+	 * @throws DomainException
3212
+	 * @throws EE_Error
3213
+	 * @throws InvalidArgumentException
3214
+	 * @throws InvalidDataTypeException
3215
+	 * @throws InvalidInterfaceException
3216
+	 */
3217
+	public function admin_page_wrapper($about = false)
3218
+	{
3219
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3220
+		$this->_nav_tabs                          = $this->_get_main_nav_tabs();
3221
+		$this->_template_args['nav_tabs']         = $this->_nav_tabs;
3222
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
3223
+
3224
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3225
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3226
+			$this->_template_args['before_admin_page_content'] ?? ''
3227
+		);
3228
+
3229
+		$this->_template_args['after_admin_page_content'] = apply_filters(
3230
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3231
+			$this->_template_args['after_admin_page_content'] ?? ''
3232
+		);
3233
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3234
+
3235
+		if ($this->request->isAjax()) {
3236
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3237
+			// $template_path,
3238
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3239
+				$this->_template_args,
3240
+				true
3241
+			);
3242
+			$this->_return_json();
3243
+		}
3244
+		// load settings page wrapper template
3245
+		$template_path = $about
3246
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3247
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3248
+
3249
+		EEH_Template::display_template($template_path, $this->_template_args);
3250
+	}
3251
+
3252
+
3253
+	/**
3254
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3255
+	 *
3256
+	 * @return string html
3257
+	 * @throws EE_Error
3258
+	 */
3259
+	protected function _get_main_nav_tabs()
3260
+	{
3261
+		// let's generate the html using the EEH_Tabbed_Content helper.
3262
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3263
+		// (rather than setting in the page_routes array)
3264
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs, $this->page_slug);
3265
+	}
3266
+
3267
+
3268
+	/**
3269
+	 *        sort nav tabs
3270
+	 *
3271
+	 * @param $a
3272
+	 * @param $b
3273
+	 * @return int
3274
+	 */
3275
+	private function _sort_nav_tabs($a, $b)
3276
+	{
3277
+		if ($a['order'] === $b['order']) {
3278
+			return 0;
3279
+		}
3280
+		return ($a['order'] < $b['order']) ? -1 : 1;
3281
+	}
3282
+
3283
+
3284
+	/**
3285
+	 * generates HTML for the forms used on admin pages
3286
+	 *
3287
+	 * @param array  $input_vars - array of input field details
3288
+	 * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3289
+	 * @param bool   $id
3290
+	 * @return array|string
3291
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3292
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3293
+	 */
3294
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3295
+	{
3296
+		return $generator === 'string'
3297
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3298
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3299
+	}
3300
+
3301
+
3302
+	/**
3303
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3304
+	 *
3305
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3306
+	 *                                   Close" button.
3307
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3308
+	 *                                   'Save', [1] => 'save & close')
3309
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3310
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3311
+	 *                                   default actions by submitting some other value.
3312
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3313
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3314
+	 *                                   close (normal form handling).
3315
+	 */
3316
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3317
+	{
3318
+		// make sure $text and $actions are in an array
3319
+		$text          = (array) $text;
3320
+		$actions       = (array) $actions;
3321
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3322
+		$button_text   = ! empty($text)
3323
+			? $text
3324
+			: [
3325
+				esc_html__('Save', 'event_espresso'),
3326
+				esc_html__('Save and Close', 'event_espresso'),
3327
+			];
3328
+		$default_names = ['save', 'save_and_close'];
3329
+		$buttons       = '';
3330
+		foreach ($button_text as $key => $button) {
3331
+			$ref     = $default_names[ $key ];
3332
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3333
+			$buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3334
+						. 'value="' . $button . '" name="' . $name . '" '
3335
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3336
+			if (! $both) {
3337
+				break;
3338
+			}
3339
+		}
3340
+		// add in a hidden index for the current page (so save and close redirects properly)
3341
+		$buttons                              .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3342
+												 . $referrer_url
3343
+												 . '" />';
3344
+		$this->_template_args['save_buttons'] = $buttons;
3345
+	}
3346
+
3347
+
3348
+	/**
3349
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3350
+	 *
3351
+	 * @param string $route
3352
+	 * @param array  $additional_hidden_fields
3353
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3354
+	 * @since 4.6.0
3355
+	 */
3356
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3357
+	{
3358
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3359
+	}
3360
+
3361
+
3362
+	/**
3363
+	 * set form open and close tags on add/edit pages.
3364
+	 *
3365
+	 * @param string $route                    the route you want the form to direct to
3366
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3367
+	 * @return void
3368
+	 */
3369
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3370
+	{
3371
+		if (empty($route)) {
3372
+			$user_msg = esc_html__(
3373
+				'An error occurred. No action was set for this page\'s form.',
3374
+				'event_espresso'
3375
+			);
3376
+			$dev_msg  = $user_msg . "\n"
3377
+						. sprintf(
3378
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3379
+							__FUNCTION__,
3380
+							__CLASS__
3381
+						);
3382
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3383
+		}
3384
+		// open form
3385
+		$action                                            = $this->_admin_base_url;
3386
+		$this->_template_args['before_admin_page_content'] = "
3387 3387
             <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' >
3388 3388
             ";
3389
-        // add nonce
3390
-        $nonce                                             =
3391
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3392
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3393
-        // add REQUIRED form action
3394
-        $hidden_fields = [
3395
-            'action' => ['type' => 'hidden', 'value' => $route],
3396
-        ];
3397
-        // merge arrays
3398
-        $hidden_fields = is_array($additional_hidden_fields)
3399
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3400
-            : $hidden_fields;
3401
-        // generate form fields
3402
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3403
-        // add fields to form
3404
-        foreach ((array) $form_fields as $form_field) {
3405
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3406
-        }
3407
-        // close form
3408
-        $this->_template_args['after_admin_page_content'] = '</form>';
3409
-    }
3410
-
3411
-
3412
-    /**
3413
-     * Public Wrapper for _redirect_after_action() method since its
3414
-     * discovered it would be useful for external code to have access.
3415
-     *
3416
-     * @param bool   $success
3417
-     * @param string $what
3418
-     * @param string $action_desc
3419
-     * @param array  $query_args
3420
-     * @param bool   $override_overwrite
3421
-     * @throws EE_Error
3422
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3423
-     * @since 4.5.0
3424
-     */
3425
-    public function redirect_after_action(
3426
-        $success = false,
3427
-        $what = 'item',
3428
-        $action_desc = 'processed',
3429
-        $query_args = [],
3430
-        $override_overwrite = false
3431
-    ) {
3432
-        $this->_redirect_after_action(
3433
-            $success,
3434
-            $what,
3435
-            $action_desc,
3436
-            $query_args,
3437
-            $override_overwrite
3438
-        );
3439
-    }
3440
-
3441
-
3442
-    /**
3443
-     * Helper method for merging existing request data with the returned redirect url.
3444
-     *
3445
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3446
-     * filters are still applied.
3447
-     *
3448
-     * @param array $new_route_data
3449
-     * @return array
3450
-     */
3451
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3452
-    {
3453
-        foreach ($this->request->requestParams() as $ref => $value) {
3454
-            // unset nonces
3455
-            if (strpos($ref, 'nonce') !== false) {
3456
-                $this->request->unSetRequestParam($ref);
3457
-                continue;
3458
-            }
3459
-            // urlencode values.
3460
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3461
-            $this->request->setRequestParam($ref, $value);
3462
-        }
3463
-        return array_merge($this->request->requestParams(), $new_route_data);
3464
-    }
3465
-
3466
-
3467
-    /**
3468
-     * @param int|float|string $success            - whether success was for two or more records, or just one, or none
3469
-     * @param string           $what               - what the action was performed on
3470
-     * @param string           $action_desc        - what was done ie: updated, deleted, etc
3471
-     * @param array            $query_args         - an array of query_args to be added to the URL to redirect to
3472
-     * @param BOOL             $override_overwrite - by default all EE_Error::success messages are overwritten,
3473
-     *                                             this allows you to override this so that they show.
3474
-     * @return void
3475
-     * @throws EE_Error
3476
-     * @throws InvalidArgumentException
3477
-     * @throws InvalidDataTypeException
3478
-     * @throws InvalidInterfaceException
3479
-     */
3480
-    protected function _redirect_after_action(
3481
-        $success = 0,
3482
-        string $what = 'item',
3483
-        string $action_desc = 'processed',
3484
-        array $query_args = [],
3485
-        bool $override_overwrite = false
3486
-    ) {
3487
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3488
-        $notices = EE_Error::get_notices(false);
3489
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3490
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3491
-            EE_Error::overwrite_success();
3492
-        }
3493
-        if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3494
-            // how many records affected ? more than one record ? or just one ?
3495
-            EE_Error::add_success(
3496
-                sprintf(
3497
-                    esc_html(
3498
-                        _n(
3499
-                            'The "%1$s" has been successfully %2$s.',
3500
-                            'The "%1$s" have been successfully %2$s.',
3501
-                            $success,
3502
-                            'event_espresso'
3503
-                        )
3504
-                    ),
3505
-                    $what,
3506
-                    $action_desc
3507
-                ),
3508
-                __FILE__,
3509
-                __FUNCTION__,
3510
-                __LINE__
3511
-            );
3512
-        }
3513
-        // check that $query_args isn't something crazy
3514
-        if (! is_array($query_args)) {
3515
-            $query_args = [];
3516
-        }
3517
-        /**
3518
-         * Allow injecting actions before the query_args are modified for possible different
3519
-         * redirections on save and close actions
3520
-         *
3521
-         * @param array $query_args       The original query_args array coming into the
3522
-         *                                method.
3523
-         * @since 4.2.0
3524
-         */
3525
-        do_action(
3526
-            "AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3527
-            $query_args
3528
-        );
3529
-        // set redirect url.
3530
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3531
-        // otherwise we go with whatever is set as the _admin_base_url
3532
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3533
-        // calculate where we're going (if we have a "save and close" button pushed)
3534
-        if (
3535
-            $this->request->requestParamIsSet('save_and_close')
3536
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3537
-        ) {
3538
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3539
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3540
-            // regenerate query args array from referrer URL
3541
-            parse_str($parsed_url['query'], $query_args);
3542
-            // correct page and action will be in the query args now
3543
-            $redirect_url = admin_url('admin.php');
3544
-        }
3545
-        // merge any default query_args set in _default_route_query_args property
3546
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3547
-            $args_to_merge = [];
3548
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3549
-                // is there a wp_referer array in our _default_route_query_args property?
3550
-                if ($query_param === 'wp_referer') {
3551
-                    $query_value = (array) $query_value;
3552
-                    foreach ($query_value as $reference => $value) {
3553
-                        if (strpos($reference, 'nonce') !== false) {
3554
-                            continue;
3555
-                        }
3556
-                        // finally we will override any arguments in the referer with
3557
-                        // what might be set on the _default_route_query_args array.
3558
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3559
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3560
-                        } else {
3561
-                            $args_to_merge[ $reference ] = urlencode($value);
3562
-                        }
3563
-                    }
3564
-                    continue;
3565
-                }
3566
-                $args_to_merge[ $query_param ] = $query_value;
3567
-            }
3568
-            // now let's merge these arguments but override with what was specifically sent in to the
3569
-            // redirect.
3570
-            $query_args = array_merge($args_to_merge, $query_args);
3571
-        }
3572
-        $this->_process_notices($query_args);
3573
-        // generate redirect url
3574
-        // if redirecting to anything other than the main page, add a nonce
3575
-        if (isset($query_args['action'])) {
3576
-            // manually generate wp_nonce and merge that with the query vars
3577
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3578
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3579
-        }
3580
-        // we're adding some hooks and filters in here for processing any things just before redirects
3581
-        // (example: an admin page has done an insert or update and we want to run something after that).
3582
-        do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3583
-        $redirect_url = apply_filters(
3584
-            'FHEE_redirect_' . $this->class_name . $this->_req_action,
3585
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3586
-            $query_args
3587
-        );
3588
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3589
-        if ($this->request->isAjax()) {
3590
-            $default_data                    = [
3591
-                'close'        => true,
3592
-                'redirect_url' => $redirect_url,
3593
-                'where'        => 'main',
3594
-                'what'         => 'append',
3595
-            ];
3596
-            $this->_template_args['success'] = $success;
3597
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3598
-                $default_data,
3599
-                $this->_template_args['data']
3600
-            ) : $default_data;
3601
-            $this->_return_json();
3602
-        }
3603
-        wp_safe_redirect($redirect_url);
3604
-        exit();
3605
-    }
3606
-
3607
-
3608
-    /**
3609
-     * process any notices before redirecting (or returning ajax request)
3610
-     * This method sets the $this->_template_args['notices'] attribute;
3611
-     *
3612
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3613
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3614
-     *                                  page_routes haven't been defined yet.
3615
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3616
-     *                                  still save a transient for the notice.
3617
-     * @return void
3618
-     * @throws EE_Error
3619
-     * @throws InvalidArgumentException
3620
-     * @throws InvalidDataTypeException
3621
-     * @throws InvalidInterfaceException
3622
-     */
3623
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3624
-    {
3625
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3626
-        if ($this->request->isAjax()) {
3627
-            $notices = EE_Error::get_notices(false);
3628
-            if (empty($this->_template_args['success'])) {
3629
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3630
-            }
3631
-            if (empty($this->_template_args['errors'])) {
3632
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3633
-            }
3634
-            if (empty($this->_template_args['attention'])) {
3635
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3636
-            }
3637
-        }
3638
-        $this->_template_args['notices'] = EE_Error::get_notices();
3639
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3640
-        if (! $this->request->isAjax() || $sticky_notices) {
3641
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3642
-            $this->_add_transient(
3643
-                $route,
3644
-                $this->_template_args['notices'],
3645
-                true,
3646
-                $skip_route_verify
3647
-            );
3648
-        }
3649
-    }
3650
-
3651
-
3652
-    /**
3653
-     * get_action_link_or_button
3654
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3655
-     *
3656
-     * @param string $action        use this to indicate which action the url is generated with.
3657
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3658
-     *                              property.
3659
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3660
-     * @param string $class         Use this to give the class for the button. Defaults to 'button--primary'
3661
-     * @param string $base_url      If this is not provided
3662
-     *                              the _admin_base_url will be used as the default for the button base_url.
3663
-     *                              Otherwise this value will be used.
3664
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3665
-     * @return string
3666
-     * @throws InvalidArgumentException
3667
-     * @throws InvalidInterfaceException
3668
-     * @throws InvalidDataTypeException
3669
-     * @throws EE_Error
3670
-     */
3671
-    public function get_action_link_or_button(
3672
-        $action,
3673
-        $type = 'add',
3674
-        $extra_request = [],
3675
-        $class = 'button button--primary',
3676
-        $base_url = '',
3677
-        $exclude_nonce = false
3678
-    ) {
3679
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3680
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3681
-            throw new EE_Error(
3682
-                sprintf(
3683
-                    esc_html__(
3684
-                        'There is no page route for given action for the button.  This action was given: %s',
3685
-                        'event_espresso'
3686
-                    ),
3687
-                    $action
3688
-                )
3689
-            );
3690
-        }
3691
-        if (! isset($this->_labels['buttons'][ $type ])) {
3692
-            throw new EE_Error(
3693
-                sprintf(
3694
-                    esc_html__(
3695
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3696
-                        'event_espresso'
3697
-                    ),
3698
-                    $type
3699
-                )
3700
-            );
3701
-        }
3702
-        // finally check user access for this button.
3703
-        $has_access = $this->check_user_access($action, true);
3704
-        if (! $has_access) {
3705
-            return '';
3706
-        }
3707
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3708
-        $query_args = [
3709
-            'action' => $action,
3710
-        ];
3711
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3712
-        if (! empty($extra_request)) {
3713
-            $query_args = array_merge($extra_request, $query_args);
3714
-        }
3715
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3716
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3717
-    }
3718
-
3719
-
3720
-    /**
3721
-     * _per_page_screen_option
3722
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3723
-     *
3724
-     * @return void
3725
-     * @throws InvalidArgumentException
3726
-     * @throws InvalidInterfaceException
3727
-     * @throws InvalidDataTypeException
3728
-     */
3729
-    protected function _per_page_screen_option()
3730
-    {
3731
-        $option = 'per_page';
3732
-        $args   = [
3733
-            'label'   => apply_filters(
3734
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3735
-                $this->_admin_page_title,
3736
-                $this
3737
-            ),
3738
-            'default' => (int) apply_filters(
3739
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3740
-                20
3741
-            ),
3742
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3743
-        ];
3744
-        // ONLY add the screen option if the user has access to it.
3745
-        if ($this->check_user_access($this->_current_view, true)) {
3746
-            add_screen_option($option, $args);
3747
-        }
3748
-    }
3749
-
3750
-
3751
-    /**
3752
-     * set_per_page_screen_option
3753
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3754
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3755
-     * admin_menu.
3756
-     *
3757
-     * @return void
3758
-     */
3759
-    private function _set_per_page_screen_options()
3760
-    {
3761
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3762
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3763
-            if (! $user = wp_get_current_user()) {
3764
-                return;
3765
-            }
3766
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3767
-            if (! $option) {
3768
-                return;
3769
-            }
3770
-            $value      = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3771
-            $map_option = $option;
3772
-            $option     = str_replace('-', '_', $option);
3773
-            switch ($map_option) {
3774
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3775
-                    $max_value = apply_filters(
3776
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3777
-                        999,
3778
-                        $this->_current_page,
3779
-                        $this->_current_view
3780
-                    );
3781
-                    if ($value < 1) {
3782
-                        return;
3783
-                    }
3784
-                    $value = min($value, $max_value);
3785
-                    break;
3786
-                default:
3787
-                    $value = apply_filters(
3788
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3789
-                        false,
3790
-                        $option,
3791
-                        $value
3792
-                    );
3793
-                    if (false === $value) {
3794
-                        return;
3795
-                    }
3796
-                    break;
3797
-            }
3798
-            update_user_meta($user->ID, $option, $value);
3799
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3800
-            exit;
3801
-        }
3802
-    }
3803
-
3804
-
3805
-    /**
3806
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3807
-     *
3808
-     * @param array $data array that will be assigned to template args.
3809
-     */
3810
-    public function set_template_args($data)
3811
-    {
3812
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3813
-    }
3814
-
3815
-
3816
-    /**
3817
-     * This makes available the WP transient system for temporarily moving data between routes
3818
-     *
3819
-     * @param string $route             the route that should receive the transient
3820
-     * @param array  $data              the data that gets sent
3821
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3822
-     *                                  normal route transient.
3823
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3824
-     *                                  when we are adding a transient before page_routes have been defined.
3825
-     * @return void
3826
-     * @throws EE_Error
3827
-     */
3828
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3829
-    {
3830
-        $user_id = get_current_user_id();
3831
-        if (! $skip_route_verify) {
3832
-            $this->_verify_route($route);
3833
-        }
3834
-        // now let's set the string for what kind of transient we're setting
3835
-        $transient = $notices
3836
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3837
-            : 'rte_tx_' . $route . '_' . $user_id;
3838
-        $data      = $notices ? ['notices' => $data] : $data;
3839
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3840
-        $existing = is_multisite() && is_network_admin()
3841
-            ? get_site_transient($transient)
3842
-            : get_transient($transient);
3843
-        if ($existing) {
3844
-            $data = array_merge((array) $data, (array) $existing);
3845
-        }
3846
-        if (is_multisite() && is_network_admin()) {
3847
-            set_site_transient($transient, $data, 8);
3848
-        } else {
3849
-            set_transient($transient, $data, 8);
3850
-        }
3851
-    }
3852
-
3853
-
3854
-    /**
3855
-     * this retrieves the temporary transient that has been set for moving data between routes.
3856
-     *
3857
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3858
-     * @param string $route
3859
-     * @return mixed data
3860
-     */
3861
-    protected function _get_transient($notices = false, $route = '')
3862
-    {
3863
-        $user_id   = get_current_user_id();
3864
-        $route     = ! $route ? $this->_req_action : $route;
3865
-        $transient = $notices
3866
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3867
-            : 'rte_tx_' . $route . '_' . $user_id;
3868
-        $data      = is_multisite() && is_network_admin()
3869
-            ? get_site_transient($transient)
3870
-            : get_transient($transient);
3871
-        // delete transient after retrieval (just in case it hasn't expired);
3872
-        if (is_multisite() && is_network_admin()) {
3873
-            delete_site_transient($transient);
3874
-        } else {
3875
-            delete_transient($transient);
3876
-        }
3877
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3878
-    }
3879
-
3880
-
3881
-    /**
3882
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3883
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3884
-     * default route callback on the EE_Admin page you want it run.)
3885
-     *
3886
-     * @return void
3887
-     */
3888
-    protected function _transient_garbage_collection()
3889
-    {
3890
-        global $wpdb;
3891
-        // retrieve all existing transients
3892
-        $query =
3893
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3894
-        if ($results = $wpdb->get_results($query)) {
3895
-            foreach ($results as $result) {
3896
-                $transient = str_replace('_transient_', '', $result->option_name);
3897
-                get_transient($transient);
3898
-                if (is_multisite() && is_network_admin()) {
3899
-                    get_site_transient($transient);
3900
-                }
3901
-            }
3902
-        }
3903
-    }
3904
-
3905
-
3906
-    /**
3907
-     * get_view
3908
-     *
3909
-     * @return string content of _view property
3910
-     */
3911
-    public function get_view()
3912
-    {
3913
-        return $this->_view;
3914
-    }
3915
-
3916
-
3917
-    /**
3918
-     * getter for the protected $_views property
3919
-     *
3920
-     * @return array
3921
-     */
3922
-    public function get_views()
3923
-    {
3924
-        return $this->_views;
3925
-    }
3926
-
3927
-
3928
-    /**
3929
-     * get_current_page
3930
-     *
3931
-     * @return string _current_page property value
3932
-     */
3933
-    public function get_current_page()
3934
-    {
3935
-        return $this->_current_page;
3936
-    }
3937
-
3938
-
3939
-    /**
3940
-     * get_current_view
3941
-     *
3942
-     * @return string _current_view property value
3943
-     */
3944
-    public function get_current_view()
3945
-    {
3946
-        return $this->_current_view;
3947
-    }
3948
-
3949
-
3950
-    /**
3951
-     * get_current_screen
3952
-     *
3953
-     * @return object The current WP_Screen object
3954
-     */
3955
-    public function get_current_screen()
3956
-    {
3957
-        return $this->_current_screen;
3958
-    }
3959
-
3960
-
3961
-    /**
3962
-     * get_current_page_view_url
3963
-     *
3964
-     * @return string This returns the url for the current_page_view.
3965
-     */
3966
-    public function get_current_page_view_url()
3967
-    {
3968
-        return $this->_current_page_view_url;
3969
-    }
3970
-
3971
-
3972
-    /**
3973
-     * just returns the Request
3974
-     *
3975
-     * @return RequestInterface
3976
-     */
3977
-    public function get_request()
3978
-    {
3979
-        return $this->request;
3980
-    }
3981
-
3982
-
3983
-    /**
3984
-     * just returns the _req_data property
3985
-     *
3986
-     * @return array
3987
-     */
3988
-    public function get_request_data()
3989
-    {
3990
-        return $this->request->requestParams();
3991
-    }
3992
-
3993
-
3994
-    /**
3995
-     * returns the _req_data protected property
3996
-     *
3997
-     * @return string
3998
-     */
3999
-    public function get_req_action()
4000
-    {
4001
-        return $this->_req_action;
4002
-    }
4003
-
4004
-
4005
-    /**
4006
-     * @return bool  value of $_is_caf property
4007
-     */
4008
-    public function is_caf()
4009
-    {
4010
-        return $this->_is_caf;
4011
-    }
4012
-
4013
-
4014
-    /**
4015
-     * @return mixed
4016
-     */
4017
-    public function default_espresso_metaboxes()
4018
-    {
4019
-        return $this->_default_espresso_metaboxes;
4020
-    }
4021
-
4022
-
4023
-    /**
4024
-     * @return mixed
4025
-     */
4026
-    public function admin_base_url()
4027
-    {
4028
-        return $this->_admin_base_url;
4029
-    }
4030
-
4031
-
4032
-    /**
4033
-     * @return mixed
4034
-     */
4035
-    public function wp_page_slug()
4036
-    {
4037
-        return $this->_wp_page_slug;
4038
-    }
4039
-
4040
-
4041
-    /**
4042
-     * updates  espresso configuration settings
4043
-     *
4044
-     * @param string                   $tab
4045
-     * @param EE_Config_Base|EE_Config $config
4046
-     * @param string                   $file file where error occurred
4047
-     * @param string                   $func function  where error occurred
4048
-     * @param string                   $line line no where error occurred
4049
-     * @return boolean
4050
-     */
4051
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4052
-    {
4053
-        // remove any options that are NOT going to be saved with the config settings.
4054
-        if (isset($config->core->ee_ueip_optin)) {
4055
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4056
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4057
-            update_option('ee_ueip_has_notified', true);
4058
-        }
4059
-        // and save it (note we're also doing the network save here)
4060
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
4061
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4062
-        if ($config_saved && $net_saved) {
4063
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4064
-            return true;
4065
-        }
4066
-        EE_Error::add_error(
4067
-            sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab),
4068
-            $file,
4069
-            $func,
4070
-            $line
4071
-        );
4072
-        return false;
4073
-    }
4074
-
4075
-
4076
-    /**
4077
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4078
-     *
4079
-     * @return array
4080
-     */
4081
-    public function get_yes_no_values()
4082
-    {
4083
-        return $this->_yes_no_values;
4084
-    }
4085
-
4086
-
4087
-    /**
4088
-     * @return string
4089
-     * @throws ReflectionException
4090
-     * @since $VID:$
4091
-     */
4092
-    protected function _get_dir()
4093
-    {
4094
-        $reflector = new ReflectionClass($this->class_name);
4095
-        return dirname($reflector->getFileName());
4096
-    }
4097
-
4098
-
4099
-    /**
4100
-     * A helper for getting a "next link".
4101
-     *
4102
-     * @param string $url   The url to link to
4103
-     * @param string $class The class to use.
4104
-     * @return string
4105
-     */
4106
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4107
-    {
4108
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4109
-    }
4110
-
4111
-
4112
-    /**
4113
-     * A helper for getting a "previous link".
4114
-     *
4115
-     * @param string $url   The url to link to
4116
-     * @param string $class The class to use.
4117
-     * @return string
4118
-     */
4119
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4120
-    {
4121
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4122
-    }
4123
-
4124
-
4125
-
4126
-
4127
-
4128
-
4129
-
4130
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4131
-
4132
-
4133
-    /**
4134
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4135
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4136
-     * _req_data array.
4137
-     *
4138
-     * @return bool success/fail
4139
-     * @throws EE_Error
4140
-     * @throws InvalidArgumentException
4141
-     * @throws ReflectionException
4142
-     * @throws InvalidDataTypeException
4143
-     * @throws InvalidInterfaceException
4144
-     */
4145
-    protected function _process_resend_registration()
4146
-    {
4147
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4148
-        do_action(
4149
-            'AHEE__EE_Admin_Page___process_resend_registration',
4150
-            $this->_template_args['success'],
4151
-            $this->request->requestParams()
4152
-        );
4153
-        return $this->_template_args['success'];
4154
-    }
4155
-
4156
-
4157
-    /**
4158
-     * This automatically processes any payment message notifications when manual payment has been applied.
4159
-     *
4160
-     * @param EE_Payment $payment
4161
-     * @return bool success/fail
4162
-     */
4163
-    protected function _process_payment_notification(EE_Payment $payment)
4164
-    {
4165
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4166
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4167
-        $this->_template_args['success'] = apply_filters(
4168
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4169
-            false,
4170
-            $payment
4171
-        );
4172
-        return $this->_template_args['success'];
4173
-    }
4174
-
4175
-
4176
-    /**
4177
-     * @param EEM_Base      $entity_model
4178
-     * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4179
-     * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4180
-     * @param string        $delete_column  name of the field that denotes whether entity is trashed
4181
-     * @param callable|null $callback       called after entity is trashed, restored, or deleted
4182
-     * @return int|float
4183
-     * @throws EE_Error
4184
-     */
4185
-    protected function trashRestoreDeleteEntities(
4186
-        EEM_Base $entity_model,
4187
-        $entity_PK_name,
4188
-        $action = EE_Admin_List_Table::ACTION_DELETE,
4189
-        $delete_column = '',
4190
-        callable $callback = null
4191
-    ) {
4192
-        $entity_PK      = $entity_model->get_primary_key_field();
4193
-        $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4194
-        $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4195
-        // grab ID if deleting a single entity
4196
-        if ($this->request->requestParamIsSet($entity_PK_name)) {
4197
-            $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4198
-            return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4199
-        }
4200
-        // or grab checkbox array if bulk deleting
4201
-        $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4202
-        if (empty($checkboxes)) {
4203
-            return 0;
4204
-        }
4205
-        $success = 0;
4206
-        $IDs     = array_keys($checkboxes);
4207
-        // cycle thru bulk action checkboxes
4208
-        foreach ($IDs as $ID) {
4209
-            // increment $success
4210
-            if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4211
-                $success++;
4212
-            }
4213
-        }
4214
-        $count = (int) count($checkboxes);
4215
-        // if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4216
-        // otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4217
-        return $success === $count ? $count : $success / $count;
4218
-    }
4219
-
4220
-
4221
-    /**
4222
-     * @param EE_Primary_Key_Field_Base $entity_PK
4223
-     * @return string
4224
-     * @throws EE_Error
4225
-     * @since   4.10.30.p
4226
-     */
4227
-    private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK)
4228
-    {
4229
-        $entity_PK_type = $entity_PK->getSchemaType();
4230
-        switch ($entity_PK_type) {
4231
-            case 'boolean':
4232
-                return 'bool';
4233
-            case 'integer':
4234
-                return 'int';
4235
-            case 'number':
4236
-                return 'float';
4237
-            case 'string':
4238
-                return 'string';
4239
-        }
4240
-        throw new RuntimeException(
4241
-            sprintf(
4242
-                esc_html__(
4243
-                    '"%1$s" is an invalid schema type for the %2$s primary key.',
4244
-                    'event_espresso'
4245
-                ),
4246
-                $entity_PK_type,
4247
-                $entity_PK->get_name()
4248
-            )
4249
-        );
4250
-    }
4251
-
4252
-
4253
-    /**
4254
-     * @param EEM_Base      $entity_model
4255
-     * @param int|string    $entity_ID
4256
-     * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4257
-     * @param string        $delete_column name of the field that denotes whether entity is trashed
4258
-     * @param callable|null $callback      called after entity is trashed, restored, or deleted
4259
-     * @return bool
4260
-     */
4261
-    protected function trashRestoreDeleteEntity(
4262
-        EEM_Base $entity_model,
4263
-        $entity_ID,
4264
-        string $action,
4265
-        string $delete_column,
4266
-        ?callable $callback = null
4267
-    ): bool {
4268
-        $entity_ID = absint($entity_ID);
4269
-        if (! $entity_ID) {
4270
-            $this->trashRestoreDeleteError($action, $entity_model);
4271
-        }
4272
-        $result = 0;
4273
-        try {
4274
-            $entity = $entity_model->get_one_by_ID($entity_ID);
4275
-            if (! $entity instanceof EE_Base_Class) {
4276
-                throw new DomainException(
4277
-                    sprintf(
4278
-                        esc_html__(
4279
-                            'Missing or invalid %1$s entity with ID of "%2$s" returned from db.',
4280
-                            'event_espresso'
4281
-                        ),
4282
-                        str_replace('EEM_', '', $entity_model->get_this_model_name()),
4283
-                        $entity_ID
4284
-                    )
4285
-                );
4286
-            }
4287
-            switch ($action) {
4288
-                case EE_Admin_List_Table::ACTION_DELETE:
4289
-                    $result = (bool) $entity->delete_permanently();
4290
-                    break;
4291
-                case EE_Admin_List_Table::ACTION_RESTORE:
4292
-                    $result = $entity->delete_or_restore(false);
4293
-                    break;
4294
-                case EE_Admin_List_Table::ACTION_TRASH:
4295
-                    $result = $entity->delete_or_restore();
4296
-                    break;
4297
-            }
4298
-        } catch (Exception $exception) {
4299
-            $this->trashRestoreDeleteError($action, $entity_model, $exception);
4300
-        }
4301
-        if (is_callable($callback)) {
4302
-            call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4303
-        }
4304
-        return $result;
4305
-    }
4306
-
4307
-
4308
-    /**
4309
-     * @param EEM_Base $entity_model
4310
-     * @param string   $delete_column
4311
-     * @since 4.10.30.p
4312
-     */
4313
-    private function validateDeleteColumn(EEM_Base $entity_model, $delete_column)
4314
-    {
4315
-        if (empty($delete_column)) {
4316
-            throw new DomainException(
4317
-                sprintf(
4318
-                    esc_html__(
4319
-                        'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4320
-                        'event_espresso'
4321
-                    ),
4322
-                    $entity_model->get_this_model_name()
4323
-                )
4324
-            );
4325
-        }
4326
-        if (! $entity_model->has_field($delete_column)) {
4327
-            throw new DomainException(
4328
-                sprintf(
4329
-                    esc_html__(
4330
-                        'The %1$s field does not exist on the %2$s model.',
4331
-                        'event_espresso'
4332
-                    ),
4333
-                    $delete_column,
4334
-                    $entity_model->get_this_model_name()
4335
-                )
4336
-            );
4337
-        }
4338
-    }
4339
-
4340
-
4341
-    /**
4342
-     * @param EEM_Base       $entity_model
4343
-     * @param Exception|null $exception
4344
-     * @param string         $action
4345
-     * @since 4.10.30.p
4346
-     */
4347
-    private function trashRestoreDeleteError($action, EEM_Base $entity_model, Exception $exception = null)
4348
-    {
4349
-        if ($exception instanceof Exception) {
4350
-            throw new RuntimeException(
4351
-                sprintf(
4352
-                    esc_html__(
4353
-                        'Could not %1$s the %2$s because the following error occurred: %3$s',
4354
-                        'event_espresso'
4355
-                    ),
4356
-                    $action,
4357
-                    $entity_model->get_this_model_name(),
4358
-                    $exception->getMessage()
4359
-                )
4360
-            );
4361
-        }
4362
-        throw new RuntimeException(
4363
-            sprintf(
4364
-                esc_html__(
4365
-                    'Could not %1$s the %2$s because an invalid ID was received.',
4366
-                    'event_espresso'
4367
-                ),
4368
-                $action,
4369
-                $entity_model->get_this_model_name()
4370
-            )
4371
-        );
4372
-    }
3389
+		// add nonce
3390
+		$nonce                                             =
3391
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3392
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3393
+		// add REQUIRED form action
3394
+		$hidden_fields = [
3395
+			'action' => ['type' => 'hidden', 'value' => $route],
3396
+		];
3397
+		// merge arrays
3398
+		$hidden_fields = is_array($additional_hidden_fields)
3399
+			? array_merge($hidden_fields, $additional_hidden_fields)
3400
+			: $hidden_fields;
3401
+		// generate form fields
3402
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3403
+		// add fields to form
3404
+		foreach ((array) $form_fields as $form_field) {
3405
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3406
+		}
3407
+		// close form
3408
+		$this->_template_args['after_admin_page_content'] = '</form>';
3409
+	}
3410
+
3411
+
3412
+	/**
3413
+	 * Public Wrapper for _redirect_after_action() method since its
3414
+	 * discovered it would be useful for external code to have access.
3415
+	 *
3416
+	 * @param bool   $success
3417
+	 * @param string $what
3418
+	 * @param string $action_desc
3419
+	 * @param array  $query_args
3420
+	 * @param bool   $override_overwrite
3421
+	 * @throws EE_Error
3422
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3423
+	 * @since 4.5.0
3424
+	 */
3425
+	public function redirect_after_action(
3426
+		$success = false,
3427
+		$what = 'item',
3428
+		$action_desc = 'processed',
3429
+		$query_args = [],
3430
+		$override_overwrite = false
3431
+	) {
3432
+		$this->_redirect_after_action(
3433
+			$success,
3434
+			$what,
3435
+			$action_desc,
3436
+			$query_args,
3437
+			$override_overwrite
3438
+		);
3439
+	}
3440
+
3441
+
3442
+	/**
3443
+	 * Helper method for merging existing request data with the returned redirect url.
3444
+	 *
3445
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3446
+	 * filters are still applied.
3447
+	 *
3448
+	 * @param array $new_route_data
3449
+	 * @return array
3450
+	 */
3451
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3452
+	{
3453
+		foreach ($this->request->requestParams() as $ref => $value) {
3454
+			// unset nonces
3455
+			if (strpos($ref, 'nonce') !== false) {
3456
+				$this->request->unSetRequestParam($ref);
3457
+				continue;
3458
+			}
3459
+			// urlencode values.
3460
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3461
+			$this->request->setRequestParam($ref, $value);
3462
+		}
3463
+		return array_merge($this->request->requestParams(), $new_route_data);
3464
+	}
3465
+
3466
+
3467
+	/**
3468
+	 * @param int|float|string $success            - whether success was for two or more records, or just one, or none
3469
+	 * @param string           $what               - what the action was performed on
3470
+	 * @param string           $action_desc        - what was done ie: updated, deleted, etc
3471
+	 * @param array            $query_args         - an array of query_args to be added to the URL to redirect to
3472
+	 * @param BOOL             $override_overwrite - by default all EE_Error::success messages are overwritten,
3473
+	 *                                             this allows you to override this so that they show.
3474
+	 * @return void
3475
+	 * @throws EE_Error
3476
+	 * @throws InvalidArgumentException
3477
+	 * @throws InvalidDataTypeException
3478
+	 * @throws InvalidInterfaceException
3479
+	 */
3480
+	protected function _redirect_after_action(
3481
+		$success = 0,
3482
+		string $what = 'item',
3483
+		string $action_desc = 'processed',
3484
+		array $query_args = [],
3485
+		bool $override_overwrite = false
3486
+	) {
3487
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3488
+		$notices = EE_Error::get_notices(false);
3489
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3490
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3491
+			EE_Error::overwrite_success();
3492
+		}
3493
+		if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3494
+			// how many records affected ? more than one record ? or just one ?
3495
+			EE_Error::add_success(
3496
+				sprintf(
3497
+					esc_html(
3498
+						_n(
3499
+							'The "%1$s" has been successfully %2$s.',
3500
+							'The "%1$s" have been successfully %2$s.',
3501
+							$success,
3502
+							'event_espresso'
3503
+						)
3504
+					),
3505
+					$what,
3506
+					$action_desc
3507
+				),
3508
+				__FILE__,
3509
+				__FUNCTION__,
3510
+				__LINE__
3511
+			);
3512
+		}
3513
+		// check that $query_args isn't something crazy
3514
+		if (! is_array($query_args)) {
3515
+			$query_args = [];
3516
+		}
3517
+		/**
3518
+		 * Allow injecting actions before the query_args are modified for possible different
3519
+		 * redirections on save and close actions
3520
+		 *
3521
+		 * @param array $query_args       The original query_args array coming into the
3522
+		 *                                method.
3523
+		 * @since 4.2.0
3524
+		 */
3525
+		do_action(
3526
+			"AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3527
+			$query_args
3528
+		);
3529
+		// set redirect url.
3530
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3531
+		// otherwise we go with whatever is set as the _admin_base_url
3532
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3533
+		// calculate where we're going (if we have a "save and close" button pushed)
3534
+		if (
3535
+			$this->request->requestParamIsSet('save_and_close')
3536
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3537
+		) {
3538
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3539
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3540
+			// regenerate query args array from referrer URL
3541
+			parse_str($parsed_url['query'], $query_args);
3542
+			// correct page and action will be in the query args now
3543
+			$redirect_url = admin_url('admin.php');
3544
+		}
3545
+		// merge any default query_args set in _default_route_query_args property
3546
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3547
+			$args_to_merge = [];
3548
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3549
+				// is there a wp_referer array in our _default_route_query_args property?
3550
+				if ($query_param === 'wp_referer') {
3551
+					$query_value = (array) $query_value;
3552
+					foreach ($query_value as $reference => $value) {
3553
+						if (strpos($reference, 'nonce') !== false) {
3554
+							continue;
3555
+						}
3556
+						// finally we will override any arguments in the referer with
3557
+						// what might be set on the _default_route_query_args array.
3558
+						if (isset($this->_default_route_query_args[ $reference ])) {
3559
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3560
+						} else {
3561
+							$args_to_merge[ $reference ] = urlencode($value);
3562
+						}
3563
+					}
3564
+					continue;
3565
+				}
3566
+				$args_to_merge[ $query_param ] = $query_value;
3567
+			}
3568
+			// now let's merge these arguments but override with what was specifically sent in to the
3569
+			// redirect.
3570
+			$query_args = array_merge($args_to_merge, $query_args);
3571
+		}
3572
+		$this->_process_notices($query_args);
3573
+		// generate redirect url
3574
+		// if redirecting to anything other than the main page, add a nonce
3575
+		if (isset($query_args['action'])) {
3576
+			// manually generate wp_nonce and merge that with the query vars
3577
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3578
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3579
+		}
3580
+		// we're adding some hooks and filters in here for processing any things just before redirects
3581
+		// (example: an admin page has done an insert or update and we want to run something after that).
3582
+		do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3583
+		$redirect_url = apply_filters(
3584
+			'FHEE_redirect_' . $this->class_name . $this->_req_action,
3585
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3586
+			$query_args
3587
+		);
3588
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3589
+		if ($this->request->isAjax()) {
3590
+			$default_data                    = [
3591
+				'close'        => true,
3592
+				'redirect_url' => $redirect_url,
3593
+				'where'        => 'main',
3594
+				'what'         => 'append',
3595
+			];
3596
+			$this->_template_args['success'] = $success;
3597
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3598
+				$default_data,
3599
+				$this->_template_args['data']
3600
+			) : $default_data;
3601
+			$this->_return_json();
3602
+		}
3603
+		wp_safe_redirect($redirect_url);
3604
+		exit();
3605
+	}
3606
+
3607
+
3608
+	/**
3609
+	 * process any notices before redirecting (or returning ajax request)
3610
+	 * This method sets the $this->_template_args['notices'] attribute;
3611
+	 *
3612
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3613
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3614
+	 *                                  page_routes haven't been defined yet.
3615
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3616
+	 *                                  still save a transient for the notice.
3617
+	 * @return void
3618
+	 * @throws EE_Error
3619
+	 * @throws InvalidArgumentException
3620
+	 * @throws InvalidDataTypeException
3621
+	 * @throws InvalidInterfaceException
3622
+	 */
3623
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3624
+	{
3625
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3626
+		if ($this->request->isAjax()) {
3627
+			$notices = EE_Error::get_notices(false);
3628
+			if (empty($this->_template_args['success'])) {
3629
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3630
+			}
3631
+			if (empty($this->_template_args['errors'])) {
3632
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3633
+			}
3634
+			if (empty($this->_template_args['attention'])) {
3635
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3636
+			}
3637
+		}
3638
+		$this->_template_args['notices'] = EE_Error::get_notices();
3639
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3640
+		if (! $this->request->isAjax() || $sticky_notices) {
3641
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3642
+			$this->_add_transient(
3643
+				$route,
3644
+				$this->_template_args['notices'],
3645
+				true,
3646
+				$skip_route_verify
3647
+			);
3648
+		}
3649
+	}
3650
+
3651
+
3652
+	/**
3653
+	 * get_action_link_or_button
3654
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3655
+	 *
3656
+	 * @param string $action        use this to indicate which action the url is generated with.
3657
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3658
+	 *                              property.
3659
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3660
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button--primary'
3661
+	 * @param string $base_url      If this is not provided
3662
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3663
+	 *                              Otherwise this value will be used.
3664
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3665
+	 * @return string
3666
+	 * @throws InvalidArgumentException
3667
+	 * @throws InvalidInterfaceException
3668
+	 * @throws InvalidDataTypeException
3669
+	 * @throws EE_Error
3670
+	 */
3671
+	public function get_action_link_or_button(
3672
+		$action,
3673
+		$type = 'add',
3674
+		$extra_request = [],
3675
+		$class = 'button button--primary',
3676
+		$base_url = '',
3677
+		$exclude_nonce = false
3678
+	) {
3679
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3680
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3681
+			throw new EE_Error(
3682
+				sprintf(
3683
+					esc_html__(
3684
+						'There is no page route for given action for the button.  This action was given: %s',
3685
+						'event_espresso'
3686
+					),
3687
+					$action
3688
+				)
3689
+			);
3690
+		}
3691
+		if (! isset($this->_labels['buttons'][ $type ])) {
3692
+			throw new EE_Error(
3693
+				sprintf(
3694
+					esc_html__(
3695
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3696
+						'event_espresso'
3697
+					),
3698
+					$type
3699
+				)
3700
+			);
3701
+		}
3702
+		// finally check user access for this button.
3703
+		$has_access = $this->check_user_access($action, true);
3704
+		if (! $has_access) {
3705
+			return '';
3706
+		}
3707
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3708
+		$query_args = [
3709
+			'action' => $action,
3710
+		];
3711
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3712
+		if (! empty($extra_request)) {
3713
+			$query_args = array_merge($extra_request, $query_args);
3714
+		}
3715
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3716
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3717
+	}
3718
+
3719
+
3720
+	/**
3721
+	 * _per_page_screen_option
3722
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3723
+	 *
3724
+	 * @return void
3725
+	 * @throws InvalidArgumentException
3726
+	 * @throws InvalidInterfaceException
3727
+	 * @throws InvalidDataTypeException
3728
+	 */
3729
+	protected function _per_page_screen_option()
3730
+	{
3731
+		$option = 'per_page';
3732
+		$args   = [
3733
+			'label'   => apply_filters(
3734
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3735
+				$this->_admin_page_title,
3736
+				$this
3737
+			),
3738
+			'default' => (int) apply_filters(
3739
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3740
+				20
3741
+			),
3742
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3743
+		];
3744
+		// ONLY add the screen option if the user has access to it.
3745
+		if ($this->check_user_access($this->_current_view, true)) {
3746
+			add_screen_option($option, $args);
3747
+		}
3748
+	}
3749
+
3750
+
3751
+	/**
3752
+	 * set_per_page_screen_option
3753
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3754
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3755
+	 * admin_menu.
3756
+	 *
3757
+	 * @return void
3758
+	 */
3759
+	private function _set_per_page_screen_options()
3760
+	{
3761
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3762
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3763
+			if (! $user = wp_get_current_user()) {
3764
+				return;
3765
+			}
3766
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3767
+			if (! $option) {
3768
+				return;
3769
+			}
3770
+			$value      = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3771
+			$map_option = $option;
3772
+			$option     = str_replace('-', '_', $option);
3773
+			switch ($map_option) {
3774
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3775
+					$max_value = apply_filters(
3776
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3777
+						999,
3778
+						$this->_current_page,
3779
+						$this->_current_view
3780
+					);
3781
+					if ($value < 1) {
3782
+						return;
3783
+					}
3784
+					$value = min($value, $max_value);
3785
+					break;
3786
+				default:
3787
+					$value = apply_filters(
3788
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3789
+						false,
3790
+						$option,
3791
+						$value
3792
+					);
3793
+					if (false === $value) {
3794
+						return;
3795
+					}
3796
+					break;
3797
+			}
3798
+			update_user_meta($user->ID, $option, $value);
3799
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3800
+			exit;
3801
+		}
3802
+	}
3803
+
3804
+
3805
+	/**
3806
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3807
+	 *
3808
+	 * @param array $data array that will be assigned to template args.
3809
+	 */
3810
+	public function set_template_args($data)
3811
+	{
3812
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3813
+	}
3814
+
3815
+
3816
+	/**
3817
+	 * This makes available the WP transient system for temporarily moving data between routes
3818
+	 *
3819
+	 * @param string $route             the route that should receive the transient
3820
+	 * @param array  $data              the data that gets sent
3821
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3822
+	 *                                  normal route transient.
3823
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3824
+	 *                                  when we are adding a transient before page_routes have been defined.
3825
+	 * @return void
3826
+	 * @throws EE_Error
3827
+	 */
3828
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3829
+	{
3830
+		$user_id = get_current_user_id();
3831
+		if (! $skip_route_verify) {
3832
+			$this->_verify_route($route);
3833
+		}
3834
+		// now let's set the string for what kind of transient we're setting
3835
+		$transient = $notices
3836
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3837
+			: 'rte_tx_' . $route . '_' . $user_id;
3838
+		$data      = $notices ? ['notices' => $data] : $data;
3839
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3840
+		$existing = is_multisite() && is_network_admin()
3841
+			? get_site_transient($transient)
3842
+			: get_transient($transient);
3843
+		if ($existing) {
3844
+			$data = array_merge((array) $data, (array) $existing);
3845
+		}
3846
+		if (is_multisite() && is_network_admin()) {
3847
+			set_site_transient($transient, $data, 8);
3848
+		} else {
3849
+			set_transient($transient, $data, 8);
3850
+		}
3851
+	}
3852
+
3853
+
3854
+	/**
3855
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3856
+	 *
3857
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3858
+	 * @param string $route
3859
+	 * @return mixed data
3860
+	 */
3861
+	protected function _get_transient($notices = false, $route = '')
3862
+	{
3863
+		$user_id   = get_current_user_id();
3864
+		$route     = ! $route ? $this->_req_action : $route;
3865
+		$transient = $notices
3866
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3867
+			: 'rte_tx_' . $route . '_' . $user_id;
3868
+		$data      = is_multisite() && is_network_admin()
3869
+			? get_site_transient($transient)
3870
+			: get_transient($transient);
3871
+		// delete transient after retrieval (just in case it hasn't expired);
3872
+		if (is_multisite() && is_network_admin()) {
3873
+			delete_site_transient($transient);
3874
+		} else {
3875
+			delete_transient($transient);
3876
+		}
3877
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3878
+	}
3879
+
3880
+
3881
+	/**
3882
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3883
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3884
+	 * default route callback on the EE_Admin page you want it run.)
3885
+	 *
3886
+	 * @return void
3887
+	 */
3888
+	protected function _transient_garbage_collection()
3889
+	{
3890
+		global $wpdb;
3891
+		// retrieve all existing transients
3892
+		$query =
3893
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3894
+		if ($results = $wpdb->get_results($query)) {
3895
+			foreach ($results as $result) {
3896
+				$transient = str_replace('_transient_', '', $result->option_name);
3897
+				get_transient($transient);
3898
+				if (is_multisite() && is_network_admin()) {
3899
+					get_site_transient($transient);
3900
+				}
3901
+			}
3902
+		}
3903
+	}
3904
+
3905
+
3906
+	/**
3907
+	 * get_view
3908
+	 *
3909
+	 * @return string content of _view property
3910
+	 */
3911
+	public function get_view()
3912
+	{
3913
+		return $this->_view;
3914
+	}
3915
+
3916
+
3917
+	/**
3918
+	 * getter for the protected $_views property
3919
+	 *
3920
+	 * @return array
3921
+	 */
3922
+	public function get_views()
3923
+	{
3924
+		return $this->_views;
3925
+	}
3926
+
3927
+
3928
+	/**
3929
+	 * get_current_page
3930
+	 *
3931
+	 * @return string _current_page property value
3932
+	 */
3933
+	public function get_current_page()
3934
+	{
3935
+		return $this->_current_page;
3936
+	}
3937
+
3938
+
3939
+	/**
3940
+	 * get_current_view
3941
+	 *
3942
+	 * @return string _current_view property value
3943
+	 */
3944
+	public function get_current_view()
3945
+	{
3946
+		return $this->_current_view;
3947
+	}
3948
+
3949
+
3950
+	/**
3951
+	 * get_current_screen
3952
+	 *
3953
+	 * @return object The current WP_Screen object
3954
+	 */
3955
+	public function get_current_screen()
3956
+	{
3957
+		return $this->_current_screen;
3958
+	}
3959
+
3960
+
3961
+	/**
3962
+	 * get_current_page_view_url
3963
+	 *
3964
+	 * @return string This returns the url for the current_page_view.
3965
+	 */
3966
+	public function get_current_page_view_url()
3967
+	{
3968
+		return $this->_current_page_view_url;
3969
+	}
3970
+
3971
+
3972
+	/**
3973
+	 * just returns the Request
3974
+	 *
3975
+	 * @return RequestInterface
3976
+	 */
3977
+	public function get_request()
3978
+	{
3979
+		return $this->request;
3980
+	}
3981
+
3982
+
3983
+	/**
3984
+	 * just returns the _req_data property
3985
+	 *
3986
+	 * @return array
3987
+	 */
3988
+	public function get_request_data()
3989
+	{
3990
+		return $this->request->requestParams();
3991
+	}
3992
+
3993
+
3994
+	/**
3995
+	 * returns the _req_data protected property
3996
+	 *
3997
+	 * @return string
3998
+	 */
3999
+	public function get_req_action()
4000
+	{
4001
+		return $this->_req_action;
4002
+	}
4003
+
4004
+
4005
+	/**
4006
+	 * @return bool  value of $_is_caf property
4007
+	 */
4008
+	public function is_caf()
4009
+	{
4010
+		return $this->_is_caf;
4011
+	}
4012
+
4013
+
4014
+	/**
4015
+	 * @return mixed
4016
+	 */
4017
+	public function default_espresso_metaboxes()
4018
+	{
4019
+		return $this->_default_espresso_metaboxes;
4020
+	}
4021
+
4022
+
4023
+	/**
4024
+	 * @return mixed
4025
+	 */
4026
+	public function admin_base_url()
4027
+	{
4028
+		return $this->_admin_base_url;
4029
+	}
4030
+
4031
+
4032
+	/**
4033
+	 * @return mixed
4034
+	 */
4035
+	public function wp_page_slug()
4036
+	{
4037
+		return $this->_wp_page_slug;
4038
+	}
4039
+
4040
+
4041
+	/**
4042
+	 * updates  espresso configuration settings
4043
+	 *
4044
+	 * @param string                   $tab
4045
+	 * @param EE_Config_Base|EE_Config $config
4046
+	 * @param string                   $file file where error occurred
4047
+	 * @param string                   $func function  where error occurred
4048
+	 * @param string                   $line line no where error occurred
4049
+	 * @return boolean
4050
+	 */
4051
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4052
+	{
4053
+		// remove any options that are NOT going to be saved with the config settings.
4054
+		if (isset($config->core->ee_ueip_optin)) {
4055
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4056
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4057
+			update_option('ee_ueip_has_notified', true);
4058
+		}
4059
+		// and save it (note we're also doing the network save here)
4060
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
4061
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4062
+		if ($config_saved && $net_saved) {
4063
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4064
+			return true;
4065
+		}
4066
+		EE_Error::add_error(
4067
+			sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab),
4068
+			$file,
4069
+			$func,
4070
+			$line
4071
+		);
4072
+		return false;
4073
+	}
4074
+
4075
+
4076
+	/**
4077
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4078
+	 *
4079
+	 * @return array
4080
+	 */
4081
+	public function get_yes_no_values()
4082
+	{
4083
+		return $this->_yes_no_values;
4084
+	}
4085
+
4086
+
4087
+	/**
4088
+	 * @return string
4089
+	 * @throws ReflectionException
4090
+	 * @since $VID:$
4091
+	 */
4092
+	protected function _get_dir()
4093
+	{
4094
+		$reflector = new ReflectionClass($this->class_name);
4095
+		return dirname($reflector->getFileName());
4096
+	}
4097
+
4098
+
4099
+	/**
4100
+	 * A helper for getting a "next link".
4101
+	 *
4102
+	 * @param string $url   The url to link to
4103
+	 * @param string $class The class to use.
4104
+	 * @return string
4105
+	 */
4106
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4107
+	{
4108
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4109
+	}
4110
+
4111
+
4112
+	/**
4113
+	 * A helper for getting a "previous link".
4114
+	 *
4115
+	 * @param string $url   The url to link to
4116
+	 * @param string $class The class to use.
4117
+	 * @return string
4118
+	 */
4119
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4120
+	{
4121
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4122
+	}
4123
+
4124
+
4125
+
4126
+
4127
+
4128
+
4129
+
4130
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4131
+
4132
+
4133
+	/**
4134
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4135
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4136
+	 * _req_data array.
4137
+	 *
4138
+	 * @return bool success/fail
4139
+	 * @throws EE_Error
4140
+	 * @throws InvalidArgumentException
4141
+	 * @throws ReflectionException
4142
+	 * @throws InvalidDataTypeException
4143
+	 * @throws InvalidInterfaceException
4144
+	 */
4145
+	protected function _process_resend_registration()
4146
+	{
4147
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4148
+		do_action(
4149
+			'AHEE__EE_Admin_Page___process_resend_registration',
4150
+			$this->_template_args['success'],
4151
+			$this->request->requestParams()
4152
+		);
4153
+		return $this->_template_args['success'];
4154
+	}
4155
+
4156
+
4157
+	/**
4158
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4159
+	 *
4160
+	 * @param EE_Payment $payment
4161
+	 * @return bool success/fail
4162
+	 */
4163
+	protected function _process_payment_notification(EE_Payment $payment)
4164
+	{
4165
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4166
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4167
+		$this->_template_args['success'] = apply_filters(
4168
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4169
+			false,
4170
+			$payment
4171
+		);
4172
+		return $this->_template_args['success'];
4173
+	}
4174
+
4175
+
4176
+	/**
4177
+	 * @param EEM_Base      $entity_model
4178
+	 * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4179
+	 * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4180
+	 * @param string        $delete_column  name of the field that denotes whether entity is trashed
4181
+	 * @param callable|null $callback       called after entity is trashed, restored, or deleted
4182
+	 * @return int|float
4183
+	 * @throws EE_Error
4184
+	 */
4185
+	protected function trashRestoreDeleteEntities(
4186
+		EEM_Base $entity_model,
4187
+		$entity_PK_name,
4188
+		$action = EE_Admin_List_Table::ACTION_DELETE,
4189
+		$delete_column = '',
4190
+		callable $callback = null
4191
+	) {
4192
+		$entity_PK      = $entity_model->get_primary_key_field();
4193
+		$entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4194
+		$entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4195
+		// grab ID if deleting a single entity
4196
+		if ($this->request->requestParamIsSet($entity_PK_name)) {
4197
+			$ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4198
+			return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4199
+		}
4200
+		// or grab checkbox array if bulk deleting
4201
+		$checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4202
+		if (empty($checkboxes)) {
4203
+			return 0;
4204
+		}
4205
+		$success = 0;
4206
+		$IDs     = array_keys($checkboxes);
4207
+		// cycle thru bulk action checkboxes
4208
+		foreach ($IDs as $ID) {
4209
+			// increment $success
4210
+			if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4211
+				$success++;
4212
+			}
4213
+		}
4214
+		$count = (int) count($checkboxes);
4215
+		// if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4216
+		// otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4217
+		return $success === $count ? $count : $success / $count;
4218
+	}
4219
+
4220
+
4221
+	/**
4222
+	 * @param EE_Primary_Key_Field_Base $entity_PK
4223
+	 * @return string
4224
+	 * @throws EE_Error
4225
+	 * @since   4.10.30.p
4226
+	 */
4227
+	private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK)
4228
+	{
4229
+		$entity_PK_type = $entity_PK->getSchemaType();
4230
+		switch ($entity_PK_type) {
4231
+			case 'boolean':
4232
+				return 'bool';
4233
+			case 'integer':
4234
+				return 'int';
4235
+			case 'number':
4236
+				return 'float';
4237
+			case 'string':
4238
+				return 'string';
4239
+		}
4240
+		throw new RuntimeException(
4241
+			sprintf(
4242
+				esc_html__(
4243
+					'"%1$s" is an invalid schema type for the %2$s primary key.',
4244
+					'event_espresso'
4245
+				),
4246
+				$entity_PK_type,
4247
+				$entity_PK->get_name()
4248
+			)
4249
+		);
4250
+	}
4251
+
4252
+
4253
+	/**
4254
+	 * @param EEM_Base      $entity_model
4255
+	 * @param int|string    $entity_ID
4256
+	 * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4257
+	 * @param string        $delete_column name of the field that denotes whether entity is trashed
4258
+	 * @param callable|null $callback      called after entity is trashed, restored, or deleted
4259
+	 * @return bool
4260
+	 */
4261
+	protected function trashRestoreDeleteEntity(
4262
+		EEM_Base $entity_model,
4263
+		$entity_ID,
4264
+		string $action,
4265
+		string $delete_column,
4266
+		?callable $callback = null
4267
+	): bool {
4268
+		$entity_ID = absint($entity_ID);
4269
+		if (! $entity_ID) {
4270
+			$this->trashRestoreDeleteError($action, $entity_model);
4271
+		}
4272
+		$result = 0;
4273
+		try {
4274
+			$entity = $entity_model->get_one_by_ID($entity_ID);
4275
+			if (! $entity instanceof EE_Base_Class) {
4276
+				throw new DomainException(
4277
+					sprintf(
4278
+						esc_html__(
4279
+							'Missing or invalid %1$s entity with ID of "%2$s" returned from db.',
4280
+							'event_espresso'
4281
+						),
4282
+						str_replace('EEM_', '', $entity_model->get_this_model_name()),
4283
+						$entity_ID
4284
+					)
4285
+				);
4286
+			}
4287
+			switch ($action) {
4288
+				case EE_Admin_List_Table::ACTION_DELETE:
4289
+					$result = (bool) $entity->delete_permanently();
4290
+					break;
4291
+				case EE_Admin_List_Table::ACTION_RESTORE:
4292
+					$result = $entity->delete_or_restore(false);
4293
+					break;
4294
+				case EE_Admin_List_Table::ACTION_TRASH:
4295
+					$result = $entity->delete_or_restore();
4296
+					break;
4297
+			}
4298
+		} catch (Exception $exception) {
4299
+			$this->trashRestoreDeleteError($action, $entity_model, $exception);
4300
+		}
4301
+		if (is_callable($callback)) {
4302
+			call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4303
+		}
4304
+		return $result;
4305
+	}
4306
+
4307
+
4308
+	/**
4309
+	 * @param EEM_Base $entity_model
4310
+	 * @param string   $delete_column
4311
+	 * @since 4.10.30.p
4312
+	 */
4313
+	private function validateDeleteColumn(EEM_Base $entity_model, $delete_column)
4314
+	{
4315
+		if (empty($delete_column)) {
4316
+			throw new DomainException(
4317
+				sprintf(
4318
+					esc_html__(
4319
+						'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4320
+						'event_espresso'
4321
+					),
4322
+					$entity_model->get_this_model_name()
4323
+				)
4324
+			);
4325
+		}
4326
+		if (! $entity_model->has_field($delete_column)) {
4327
+			throw new DomainException(
4328
+				sprintf(
4329
+					esc_html__(
4330
+						'The %1$s field does not exist on the %2$s model.',
4331
+						'event_espresso'
4332
+					),
4333
+					$delete_column,
4334
+					$entity_model->get_this_model_name()
4335
+				)
4336
+			);
4337
+		}
4338
+	}
4339
+
4340
+
4341
+	/**
4342
+	 * @param EEM_Base       $entity_model
4343
+	 * @param Exception|null $exception
4344
+	 * @param string         $action
4345
+	 * @since 4.10.30.p
4346
+	 */
4347
+	private function trashRestoreDeleteError($action, EEM_Base $entity_model, Exception $exception = null)
4348
+	{
4349
+		if ($exception instanceof Exception) {
4350
+			throw new RuntimeException(
4351
+				sprintf(
4352
+					esc_html__(
4353
+						'Could not %1$s the %2$s because the following error occurred: %3$s',
4354
+						'event_espresso'
4355
+					),
4356
+					$action,
4357
+					$entity_model->get_this_model_name(),
4358
+					$exception->getMessage()
4359
+				)
4360
+			);
4361
+		}
4362
+		throw new RuntimeException(
4363
+			sprintf(
4364
+				esc_html__(
4365
+					'Could not %1$s the %2$s because an invalid ID was received.',
4366
+					'event_espresso'
4367
+				),
4368
+				$action,
4369
+				$entity_model->get_this_model_name()
4370
+			)
4371
+		);
4372
+	}
4373 4373
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/admin/EspressoLegacyAdmin.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -17,125 +17,125 @@
 block discarded – undo
17 17
  */
18 18
 class EspressoLegacyAdmin extends AdminRoute
19 19
 {
20
-    /**
21
-     * @var LegacyAccountingAssetManager $asset_manager
22
-     */
23
-    protected $asset_manager;
20
+	/**
21
+	 * @var LegacyAccountingAssetManager $asset_manager
22
+	 */
23
+	protected $asset_manager;
24 24
 
25 25
 
26
-    /**
27
-     * returns true if the current request matches this route
28
-     *
29
-     * @return bool
30
-     * @since   $VID:$
31
-     */
32
-    public function matchesCurrentRequest(): bool
33
-    {
34
-        global $pagenow;
35
-        return ($pagenow === 'admin.php' || $pagenow === 'admin-ajax.php') && parent::matchesCurrentRequest();
36
-    }
26
+	/**
27
+	 * returns true if the current request matches this route
28
+	 *
29
+	 * @return bool
30
+	 * @since   $VID:$
31
+	 */
32
+	public function matchesCurrentRequest(): bool
33
+	{
34
+		global $pagenow;
35
+		return ($pagenow === 'admin.php' || $pagenow === 'admin-ajax.php') && parent::matchesCurrentRequest();
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @since $VID:$
41
-     */
42
-    protected function registerDependencies()
43
-    {
44
-        $asset_manger_dependencies = [
45
-            'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
46
-            'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object,
47
-            'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
48
-        ];
49
-        $this->dependency_map->registerDependencies(JqueryAssetManager::class, $asset_manger_dependencies);
50
-        $this->dependency_map->registerDependencies(EspressoLegacyAdminAssetManager::class, $asset_manger_dependencies);
51
-        $this->dependency_map->registerDependencies(
52
-            LegacyAccountingAssetManager::class,
53
-            ['EE_Currency_Config' => EE_Dependency_Map::load_from_cache] + $asset_manger_dependencies
54
-        );
55
-        $this->dependency_map->registerDependencies(
56
-            'EE_Admin_Transactions_List_Table',
57
-            [
58
-                null,
59
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
60
-            ]
61
-        );
62
-        $this->dependency_map->registerDependencies(
63
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
64
-            ['EE_Registration_Config' => EE_Dependency_Map::load_from_cache]
65
-        );
66
-        $this->dependency_map->registerDependencies(
67
-            'EventEspresso\admin_pages\general_settings\OrganizationSettings',
68
-            [
69
-                'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
70
-                'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
71
-                'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
72
-                'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
73
-                'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
74
-            ]
75
-        );
76
-        $this->dependency_map->registerDependencies(
77
-            'EventEspresso\core\services\address\CountrySubRegionDao',
78
-            [
79
-                'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
80
-                'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
81
-            ]
82
-        );
83
-        $this->dependency_map->registerDependencies(
84
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
85
-            [
86
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
87
-                'EEM_Registration'                            => EE_Dependency_Map::load_from_cache,
88
-                null,
89
-            ]
90
-        );
91
-        $this->dependency_map->registerDependencies(
92
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
93
-            [
94
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
95
-                'EEM_Attendee'                                => EE_Dependency_Map::load_from_cache,
96
-            ]
97
-        );
98
-        $this->dependency_map->registerDependencies(
99
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
100
-            [
101
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
102
-                'EEM_Datetime'                                => EE_Dependency_Map::load_from_cache,
103
-            ]
104
-        );
105
-        $this->dependency_map->registerDependencies(
106
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
107
-            [
108
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
109
-                'EEM_Event'                                   => EE_Dependency_Map::load_from_cache,
110
-            ]
111
-        );
112
-        $this->dependency_map->registerDependencies(
113
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
114
-            [
115
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
116
-                'EEM_Ticket'                                  => EE_Dependency_Map::load_from_cache,
117
-            ]
118
-        );
119
-        $this->dependency_map->registerDependencies(
120
-            'EventEspresso\core\services\admin\AdminListTableFilters',
121
-            [
122
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
123
-            ]
124
-        );
125
-    }
39
+	/**
40
+	 * @since $VID:$
41
+	 */
42
+	protected function registerDependencies()
43
+	{
44
+		$asset_manger_dependencies = [
45
+			'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
46
+			'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object,
47
+			'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
48
+		];
49
+		$this->dependency_map->registerDependencies(JqueryAssetManager::class, $asset_manger_dependencies);
50
+		$this->dependency_map->registerDependencies(EspressoLegacyAdminAssetManager::class, $asset_manger_dependencies);
51
+		$this->dependency_map->registerDependencies(
52
+			LegacyAccountingAssetManager::class,
53
+			['EE_Currency_Config' => EE_Dependency_Map::load_from_cache] + $asset_manger_dependencies
54
+		);
55
+		$this->dependency_map->registerDependencies(
56
+			'EE_Admin_Transactions_List_Table',
57
+			[
58
+				null,
59
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
60
+			]
61
+		);
62
+		$this->dependency_map->registerDependencies(
63
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
64
+			['EE_Registration_Config' => EE_Dependency_Map::load_from_cache]
65
+		);
66
+		$this->dependency_map->registerDependencies(
67
+			'EventEspresso\admin_pages\general_settings\OrganizationSettings',
68
+			[
69
+				'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
70
+				'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
71
+				'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
72
+				'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
73
+				'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
74
+			]
75
+		);
76
+		$this->dependency_map->registerDependencies(
77
+			'EventEspresso\core\services\address\CountrySubRegionDao',
78
+			[
79
+				'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
80
+				'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
81
+			]
82
+		);
83
+		$this->dependency_map->registerDependencies(
84
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
85
+			[
86
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
87
+				'EEM_Registration'                            => EE_Dependency_Map::load_from_cache,
88
+				null,
89
+			]
90
+		);
91
+		$this->dependency_map->registerDependencies(
92
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
93
+			[
94
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
95
+				'EEM_Attendee'                                => EE_Dependency_Map::load_from_cache,
96
+			]
97
+		);
98
+		$this->dependency_map->registerDependencies(
99
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
100
+			[
101
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
102
+				'EEM_Datetime'                                => EE_Dependency_Map::load_from_cache,
103
+			]
104
+		);
105
+		$this->dependency_map->registerDependencies(
106
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
107
+			[
108
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
109
+				'EEM_Event'                                   => EE_Dependency_Map::load_from_cache,
110
+			]
111
+		);
112
+		$this->dependency_map->registerDependencies(
113
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
114
+			[
115
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
116
+				'EEM_Ticket'                                  => EE_Dependency_Map::load_from_cache,
117
+			]
118
+		);
119
+		$this->dependency_map->registerDependencies(
120
+			'EventEspresso\core\services\admin\AdminListTableFilters',
121
+			[
122
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
123
+			]
124
+		);
125
+	}
126 126
 
127 127
 
128
-    /**
129
-     * implements logic required to run during request
130
-     *
131
-     * @return bool
132
-     * @since   $VID:$
133
-     */
134
-    protected function requestHandler(): bool
135
-    {
136
-        $this->loader->getShared(JqueryAssetManager::class);
137
-        $this->loader->getShared(EspressoLegacyAdminAssetManager::class);
138
-        $this->loader->getShared(LegacyAccountingAssetManager::class);
139
-        return true;
140
-    }
128
+	/**
129
+	 * implements logic required to run during request
130
+	 *
131
+	 * @return bool
132
+	 * @since   $VID:$
133
+	 */
134
+	protected function requestHandler(): bool
135
+	{
136
+		$this->loader->getShared(JqueryAssetManager::class);
137
+		$this->loader->getShared(EspressoLegacyAdminAssetManager::class);
138
+		$this->loader->getShared(LegacyAccountingAssetManager::class);
139
+		return true;
140
+	}
141 141
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/admin/EspressoEventsAdmin.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -14,36 +14,36 @@
 block discarded – undo
14 14
  */
15 15
 class EspressoEventsAdmin extends AdminRoute
16 16
 {
17
-    /**
18
-     * returns true if the current request matches this route
19
-     *
20
-     * @return bool
21
-     * @since   $VID:$
22
-     */
23
-    public function matchesCurrentRequest(): bool
24
-    {
25
-        global $pagenow;
26
-        return parent::matchesCurrentRequest()
27
-               && $pagenow
28
-               && $pagenow === 'admin.php'
29
-               && $this->request->getRequestParam('page') === 'espresso_events';
30
-    }
17
+	/**
18
+	 * returns true if the current request matches this route
19
+	 *
20
+	 * @return bool
21
+	 * @since   $VID:$
22
+	 */
23
+	public function matchesCurrentRequest(): bool
24
+	{
25
+		global $pagenow;
26
+		return parent::matchesCurrentRequest()
27
+			   && $pagenow
28
+			   && $pagenow === 'admin.php'
29
+			   && $this->request->getRequestParam('page') === 'espresso_events';
30
+	}
31 31
 
32 32
 
33
-    /**
34
-     * @since $VID:$
35
-     */
36
-    protected function registerDependencies()
37
-    {
38
-        $this->dependency_map->registerDependencies(
39
-            'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection',
40
-            AdminRoute::getDefaultDependencies()
41
-        );
42
-        $this->dependency_map->registerDependencies(
43
-            'EventEspresso\core\services\admin\AdminListTableFilters',
44
-            [
45
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
46
-            ]
47
-        );
48
-    }
33
+	/**
34
+	 * @since $VID:$
35
+	 */
36
+	protected function registerDependencies()
37
+	{
38
+		$this->dependency_map->registerDependencies(
39
+			'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection',
40
+			AdminRoute::getDefaultDependencies()
41
+		);
42
+		$this->dependency_map->registerDependencies(
43
+			'EventEspresso\core\services\admin\AdminListTableFilters',
44
+			[
45
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
46
+			]
47
+		);
48
+	}
49 49
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2956 added lines, -2956 removed lines patch added patch discarded remove patch
@@ -18,2963 +18,2963 @@
 block discarded – undo
18 18
  */
19 19
 class Events_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21
-    /**
22
-     * This will hold the event object for event_details screen.
21
+	/**
22
+	 * This will hold the event object for event_details screen.
23
+	 *
24
+	 * @var EE_Event $_event
25
+	 */
26
+	protected $_event;
27
+
28
+
29
+	/**
30
+	 * This will hold the category object for category_details screen.
31
+	 *
32
+	 * @var stdClass $_category
33
+	 */
34
+	protected $_category;
35
+
36
+
37
+	/**
38
+	 * This will hold the event model instance
39
+	 *
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+
45
+	/**
46
+	 * @var EE_Event
47
+	 */
48
+	protected $_cpt_model_obj = false;
49
+
50
+
51
+	/**
52
+	 * @var NodeGroupDao
53
+	 */
54
+	protected $model_obj_node_group_persister;
55
+
56
+	/**
57
+	 * @var AdvancedEditorAdminFormSection
58
+	 */
59
+	protected $advanced_editor_admin_form;
60
+
61
+
62
+	/**
63
+	 * Initialize page props for this admin page group.
64
+	 */
65
+	protected function _init_page_props()
66
+	{
67
+		$this->page_slug        = EVENTS_PG_SLUG;
68
+		$this->page_label       = EVENTS_LABEL;
69
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
70
+		$this->_admin_base_path = EVENTS_ADMIN;
71
+		$this->_cpt_model_names = [
72
+			'create_new' => 'EEM_Event',
73
+			'edit'       => 'EEM_Event',
74
+		];
75
+		$this->_cpt_edit_routes = [
76
+			'espresso_events' => 'edit',
77
+		];
78
+		add_action(
79
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
80
+			[$this, 'verify_event_edit'],
81
+			10,
82
+			2
83
+		);
84
+	}
85
+
86
+
87
+	/**
88
+	 * Sets the ajax hooks used for this admin page group.
89
+	 */
90
+	protected function _ajax_hooks()
91
+	{
92
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
93
+	}
94
+
95
+
96
+	/**
97
+	 * Sets the page properties for this admin page group.
98
+	 */
99
+	protected function _define_page_props()
100
+	{
101
+		$event_id = $this->request->getRequestParam('post', 0, DataType::INT);
102
+		if ($event_id) {
103
+			$event_post = get_post($event_id);
104
+		}
105
+
106
+		$this->_admin_page_title = EVENTS_LABEL;
107
+		$this->_labels           = [
108
+			'buttons'      => [
109
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
110
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
111
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
112
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
113
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
114
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
115
+			],
116
+			'editor_title' => [
117
+				'espresso_events' => isset($event_post) && $event_post instanceof WP_Post
118
+					? $event_post->post_title
119
+					: esc_html__('Edit Event', 'event_espresso'),
120
+			],
121
+			'publishbox'   => [
122
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
123
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
124
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
125
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
126
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
127
+			],
128
+		];
129
+	}
130
+
131
+
132
+	/**
133
+	 * Sets the page routes property for this admin page group.
134
+	 */
135
+	protected function _set_page_routes()
136
+	{
137
+		// load formatter helper
138
+		// load field generator helper
139
+		// is there a evt_id in the request?
140
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT);
141
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, DataType::INT);
142
+
143
+		$this->_page_routes = [
144
+			'default'                       => [
145
+				'func'       => [$this, '_events_overview_list_table'],
146
+				'capability' => 'ee_read_events',
147
+			],
148
+			'create_new'                    => [
149
+				'func'       => [$this, '_create_new_cpt_item'],
150
+				'capability' => 'ee_edit_events',
151
+			],
152
+			'edit'                          => [
153
+				'func'       => [$this, '_edit_cpt_item'],
154
+				'capability' => 'ee_edit_event',
155
+				'obj_id'     => $EVT_ID,
156
+			],
157
+			'copy_event'                    => [
158
+				'func'       => [$this, '_copy_events'],
159
+				'capability' => 'ee_edit_event',
160
+				'obj_id'     => $EVT_ID,
161
+				'noheader'   => true,
162
+			],
163
+			'trash_event'                   => [
164
+				'func'       => [$this, '_trash_or_restore_event'],
165
+				'args'       => ['event_status' => 'trash'],
166
+				'capability' => 'ee_delete_event',
167
+				'obj_id'     => $EVT_ID,
168
+				'noheader'   => true,
169
+			],
170
+			'trash_events'                  => [
171
+				'func'       => [$this, '_trash_or_restore_events'],
172
+				'args'       => ['event_status' => 'trash'],
173
+				'capability' => 'ee_delete_events',
174
+				'noheader'   => true,
175
+			],
176
+			'restore_event'                 => [
177
+				'func'       => [$this, '_trash_or_restore_event'],
178
+				'args'       => ['event_status' => 'draft'],
179
+				'capability' => 'ee_delete_event',
180
+				'obj_id'     => $EVT_ID,
181
+				'noheader'   => true,
182
+			],
183
+			'restore_events'                => [
184
+				'func'       => [$this, '_trash_or_restore_events'],
185
+				'args'       => ['event_status' => 'draft'],
186
+				'capability' => 'ee_delete_events',
187
+				'noheader'   => true,
188
+			],
189
+			'delete_event'                  => [
190
+				'func'       => [$this, '_delete_event'],
191
+				'capability' => 'ee_delete_event',
192
+				'obj_id'     => $EVT_ID,
193
+				'noheader'   => true,
194
+			],
195
+			'delete_events'                 => [
196
+				'func'       => [$this, '_delete_events'],
197
+				'capability' => 'ee_delete_events',
198
+				'noheader'   => true,
199
+			],
200
+			'view_report'                   => [
201
+				'func'       => [$this, '_view_report'],
202
+				'capability' => 'ee_edit_events',
203
+			],
204
+			'default_event_settings'        => [
205
+				'func'       => [$this, '_default_event_settings'],
206
+				'capability' => 'manage_options',
207
+			],
208
+			'update_default_event_settings' => [
209
+				'func'       => [$this, '_update_default_event_settings'],
210
+				'capability' => 'manage_options',
211
+				'noheader'   => true,
212
+			],
213
+			'template_settings'             => [
214
+				'func'       => [$this, '_template_settings'],
215
+				'capability' => 'manage_options',
216
+			],
217
+			// event category tab related
218
+			'add_category'                  => [
219
+				'func'       => [$this, '_category_details'],
220
+				'capability' => 'ee_edit_event_category',
221
+				'args'       => ['view' => 'add'],
222
+			],
223
+			'edit_category'                 => [
224
+				'func'       => [$this, '_category_details'],
225
+				'capability' => 'ee_edit_event_category',
226
+				'args'       => ['view' => 'edit'],
227
+			],
228
+			'delete_categories'             => [
229
+				'func'       => [$this, '_delete_categories'],
230
+				'capability' => 'ee_delete_event_category',
231
+				'noheader'   => true,
232
+			],
233
+			'delete_category'               => [
234
+				'func'       => [$this, '_delete_categories'],
235
+				'capability' => 'ee_delete_event_category',
236
+				'noheader'   => true,
237
+			],
238
+			'insert_category'               => [
239
+				'func'       => [$this, '_insert_or_update_category'],
240
+				'args'       => ['new_category' => true],
241
+				'capability' => 'ee_edit_event_category',
242
+				'noheader'   => true,
243
+			],
244
+			'update_category'               => [
245
+				'func'       => [$this, '_insert_or_update_category'],
246
+				'args'       => ['new_category' => false],
247
+				'capability' => 'ee_edit_event_category',
248
+				'noheader'   => true,
249
+			],
250
+			'category_list'                 => [
251
+				'func'       => [$this, '_category_list_table'],
252
+				'capability' => 'ee_manage_event_categories',
253
+			],
254
+			'preview_deletion'              => [
255
+				'func'       => [$this, 'previewDeletion'],
256
+				'capability' => 'ee_delete_events',
257
+			],
258
+			'confirm_deletion'              => [
259
+				'func'       => [$this, 'confirmDeletion'],
260
+				'capability' => 'ee_delete_events',
261
+				'noheader'   => true,
262
+			],
263
+		];
264
+	}
265
+
266
+
267
+	/**
268
+	 * Set the _page_config property for this admin page group.
269
+	 */
270
+	protected function _set_page_config()
271
+	{
272
+		$post_id            = $this->request->getRequestParam('post', 0, DataType::INT);
273
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
274
+		$this->_page_config = [
275
+			'default'                => [
276
+				'nav'           => [
277
+					'label' => esc_html__('Overview', 'event_espresso'),
278
+					'icon'  => 'dashicons-list-view',
279
+					'order' => 10,
280
+				],
281
+				'list_table'    => 'Events_Admin_List_Table',
282
+				'help_tabs'     => [
283
+					'events_overview_help_tab'                       => [
284
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
285
+						'filename' => 'events_overview',
286
+					],
287
+					'events_overview_table_column_headings_help_tab' => [
288
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
289
+						'filename' => 'events_overview_table_column_headings',
290
+					],
291
+					'events_overview_filters_help_tab'               => [
292
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
293
+						'filename' => 'events_overview_filters',
294
+					],
295
+					'events_overview_view_help_tab'                  => [
296
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
297
+						'filename' => 'events_overview_views',
298
+					],
299
+					'events_overview_other_help_tab'                 => [
300
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
301
+						'filename' => 'events_overview_other',
302
+					],
303
+				],
304
+				'require_nonce' => false,
305
+			],
306
+			'create_new'             => [
307
+				'nav'           => [
308
+					'label'      => esc_html__('Add New Event', 'event_espresso'),
309
+					'icon'       => 'dashicons-plus-alt',
310
+					'order'      => 15,
311
+					'persistent' => false,
312
+				],
313
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
314
+				'help_tabs'     => [
315
+					'event_editor_help_tab'                            => [
316
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
317
+						'filename' => 'event_editor',
318
+					],
319
+					'event_editor_title_richtexteditor_help_tab'       => [
320
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
321
+						'filename' => 'event_editor_title_richtexteditor',
322
+					],
323
+					'event_editor_venue_details_help_tab'              => [
324
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
325
+						'filename' => 'event_editor_venue_details',
326
+					],
327
+					'event_editor_event_datetimes_help_tab'            => [
328
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
329
+						'filename' => 'event_editor_event_datetimes',
330
+					],
331
+					'event_editor_event_tickets_help_tab'              => [
332
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
333
+						'filename' => 'event_editor_event_tickets',
334
+					],
335
+					'event_editor_event_registration_options_help_tab' => [
336
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
337
+						'filename' => 'event_editor_event_registration_options',
338
+					],
339
+					'event_editor_tags_categories_help_tab'            => [
340
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
341
+						'filename' => 'event_editor_tags_categories',
342
+					],
343
+					'event_editor_questions_registrants_help_tab'      => [
344
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
345
+						'filename' => 'event_editor_questions_registrants',
346
+					],
347
+					'event_editor_save_new_event_help_tab'             => [
348
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
349
+						'filename' => 'event_editor_save_new_event',
350
+					],
351
+					'event_editor_other_help_tab'                      => [
352
+						'title'    => esc_html__('Event Other', 'event_espresso'),
353
+						'filename' => 'event_editor_other',
354
+					],
355
+				],
356
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
357
+				'require_nonce' => false,
358
+			],
359
+			'edit'                   => [
360
+				'nav'           => [
361
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
362
+					'icon'       => 'dashicons-edit',
363
+					'order'      => 15,
364
+					'persistent' => false,
365
+					'url'        => $post_id
366
+						? EE_Admin_Page::add_query_args_and_nonce(
367
+							['post' => $post_id, 'action' => 'edit'],
368
+							$this->_current_page_view_url
369
+						)
370
+						: $this->_admin_base_url,
371
+				],
372
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
373
+				'help_tabs'     => [
374
+					'event_editor_help_tab'                            => [
375
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
376
+						'filename' => 'event_editor',
377
+					],
378
+					'event_editor_title_richtexteditor_help_tab'       => [
379
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
380
+						'filename' => 'event_editor_title_richtexteditor',
381
+					],
382
+					'event_editor_venue_details_help_tab'              => [
383
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
384
+						'filename' => 'event_editor_venue_details',
385
+					],
386
+					'event_editor_event_datetimes_help_tab'            => [
387
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
388
+						'filename' => 'event_editor_event_datetimes',
389
+					],
390
+					'event_editor_event_tickets_help_tab'              => [
391
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
392
+						'filename' => 'event_editor_event_tickets',
393
+					],
394
+					'event_editor_event_registration_options_help_tab' => [
395
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
396
+						'filename' => 'event_editor_event_registration_options',
397
+					],
398
+					'event_editor_tags_categories_help_tab'            => [
399
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
400
+						'filename' => 'event_editor_tags_categories',
401
+					],
402
+					'event_editor_questions_registrants_help_tab'      => [
403
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
404
+						'filename' => 'event_editor_questions_registrants',
405
+					],
406
+					'event_editor_save_new_event_help_tab'             => [
407
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
408
+						'filename' => 'event_editor_save_new_event',
409
+					],
410
+					'event_editor_other_help_tab'                      => [
411
+						'title'    => esc_html__('Event Other', 'event_espresso'),
412
+						'filename' => 'event_editor_other',
413
+					],
414
+				],
415
+				'require_nonce' => false,
416
+			],
417
+			'default_event_settings' => [
418
+				'nav'           => [
419
+					'label' => esc_html__('Default Settings', 'event_espresso'),
420
+					'icon'  => 'dashicons-admin-generic',
421
+					'order' => 40,
422
+				],
423
+				'metaboxes'     => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes),
424
+				'labels'        => [
425
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
426
+				],
427
+				'help_tabs'     => [
428
+					'default_settings_help_tab'        => [
429
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
430
+						'filename' => 'events_default_settings',
431
+					],
432
+					'default_settings_status_help_tab' => [
433
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
434
+						'filename' => 'events_default_settings_status',
435
+					],
436
+					'default_maximum_tickets_help_tab' => [
437
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
438
+						'filename' => 'events_default_settings_max_tickets',
439
+					],
440
+				],
441
+				'require_nonce' => false,
442
+			],
443
+			// template settings
444
+			'template_settings'      => [
445
+				'nav'           => [
446
+					'label' => esc_html__('Templates', 'event_espresso'),
447
+					'icon'  => 'dashicons-layout',
448
+					'order' => 30,
449
+				],
450
+				'metaboxes'     => $this->_default_espresso_metaboxes,
451
+				'help_tabs'     => [
452
+					'general_settings_templates_help_tab' => [
453
+						'title'    => esc_html__('Templates', 'event_espresso'),
454
+						'filename' => 'general_settings_templates',
455
+					],
456
+				],
457
+				'require_nonce' => false,
458
+			],
459
+			// event category stuff
460
+			'add_category'           => [
461
+				'nav'           => [
462
+					'label'      => esc_html__('Add Category', 'event_espresso'),
463
+					'icon'       => 'dashicons-plus-alt',
464
+					'order'      => 25,
465
+					'persistent' => false,
466
+				],
467
+				'help_tabs'     => [
468
+					'add_category_help_tab' => [
469
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
470
+						'filename' => 'events_add_category',
471
+					],
472
+				],
473
+				'metaboxes'     => ['_publish_post_box'],
474
+				'require_nonce' => false,
475
+			],
476
+			'edit_category'          => [
477
+				'nav'           => [
478
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
479
+					'icon'       => 'dashicons-edit',
480
+					'order'      => 25,
481
+					'persistent' => false,
482
+					'url'        => $EVT_CAT_ID
483
+						? add_query_arg(
484
+							['EVT_CAT_ID' => $EVT_CAT_ID],
485
+							$this->_current_page_view_url
486
+						)
487
+						: $this->_admin_base_url,
488
+				],
489
+				'help_tabs'     => [
490
+					'edit_category_help_tab' => [
491
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
492
+						'filename' => 'events_edit_category',
493
+					],
494
+				],
495
+				'metaboxes'     => ['_publish_post_box'],
496
+				'require_nonce' => false,
497
+			],
498
+			'category_list'          => [
499
+				'nav'           => [
500
+					'label' => esc_html__('Categories', 'event_espresso'),
501
+					'icon'  => 'dashicons-networking',
502
+					'order' => 20,
503
+				],
504
+				'list_table'    => 'Event_Categories_Admin_List_Table',
505
+				'help_tabs'     => [
506
+					'events_categories_help_tab'                       => [
507
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
508
+						'filename' => 'events_categories',
509
+					],
510
+					'events_categories_table_column_headings_help_tab' => [
511
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
512
+						'filename' => 'events_categories_table_column_headings',
513
+					],
514
+					'events_categories_view_help_tab'                  => [
515
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
516
+						'filename' => 'events_categories_views',
517
+					],
518
+					'events_categories_other_help_tab'                 => [
519
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
520
+						'filename' => 'events_categories_other',
521
+					],
522
+				],
523
+				'metaboxes'     => $this->_default_espresso_metaboxes,
524
+				'require_nonce' => false,
525
+			],
526
+			'preview_deletion'       => [
527
+				'nav'           => [
528
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
529
+					'icon'       => 'dashicons-remove',
530
+					'order'      => 15,
531
+					'persistent' => false,
532
+					'url'        => '',
533
+				],
534
+				'require_nonce' => false,
535
+			],
536
+		];
537
+	}
538
+
539
+
540
+	/**
541
+	 * Used to register any global screen options if necessary for every route in this admin page group.
542
+	 */
543
+	protected function _add_screen_options()
544
+	{
545
+	}
546
+
547
+
548
+	/**
549
+	 * Implementing the screen options for the 'default' route.
550
+	 *
551
+	 * @throws InvalidArgumentException
552
+	 * @throws InvalidDataTypeException
553
+	 * @throws InvalidInterfaceException
554
+	 */
555
+	protected function _add_screen_options_default()
556
+	{
557
+		$this->_per_page_screen_option();
558
+	}
559
+
560
+
561
+	/**
562
+	 * Implementing screen options for the category list route.
563
+	 *
564
+	 * @throws InvalidArgumentException
565
+	 * @throws InvalidDataTypeException
566
+	 * @throws InvalidInterfaceException
567
+	 */
568
+	protected function _add_screen_options_category_list()
569
+	{
570
+		$page_title              = $this->_admin_page_title;
571
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
572
+		$this->_per_page_screen_option();
573
+		$this->_admin_page_title = $page_title;
574
+	}
575
+
576
+
577
+	/**
578
+	 * Used to register any global feature pointers for the admin page group.
579
+	 */
580
+	protected function _add_feature_pointers()
581
+	{
582
+	}
583
+
584
+
585
+	/**
586
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
587
+	 */
588
+	public function load_scripts_styles()
589
+	{
590
+		wp_register_style(
591
+			'events-admin-css',
592
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
593
+			[],
594
+			EVENT_ESPRESSO_VERSION
595
+		);
596
+		wp_register_style(
597
+			'ee-cat-admin',
598
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
599
+			[],
600
+			EVENT_ESPRESSO_VERSION
601
+		);
602
+		wp_enqueue_style('events-admin-css');
603
+		wp_enqueue_style('ee-cat-admin');
604
+		// scripts
605
+		wp_register_script(
606
+			'event_editor_js',
607
+			EVENTS_ASSETS_URL . 'event_editor.js',
608
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
609
+			EVENT_ESPRESSO_VERSION,
610
+			true
611
+		);
612
+	}
613
+
614
+
615
+	/**
616
+	 * Enqueuing scripts and styles specific to this view
617
+	 */
618
+	public function load_scripts_styles_create_new()
619
+	{
620
+		$this->load_scripts_styles_edit();
621
+	}
622
+
623
+
624
+	/**
625
+	 * Enqueuing scripts and styles specific to this view
626
+	 */
627
+	public function load_scripts_styles_edit()
628
+	{
629
+		// styles
630
+		wp_enqueue_style('espresso-ui-theme');
631
+		wp_register_style(
632
+			'event-editor-css',
633
+			EVENTS_ASSETS_URL . 'event-editor.css',
634
+			['ee-admin-css'],
635
+			EVENT_ESPRESSO_VERSION
636
+		);
637
+		wp_enqueue_style('event-editor-css');
638
+		// scripts
639
+		if (! $this->admin_config->useAdvancedEditor()) {
640
+			wp_register_script(
641
+				'event-datetime-metabox',
642
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
643
+				['event_editor_js', 'ee-datepicker'],
644
+				EVENT_ESPRESSO_VERSION
645
+			);
646
+			wp_enqueue_script('event-datetime-metabox');
647
+		}
648
+	}
649
+
650
+
651
+	/**
652
+	 * Populating the _views property for the category list table view.
653
+	 */
654
+	protected function _set_list_table_views_category_list()
655
+	{
656
+		$this->_views = [
657
+			'all' => [
658
+				'slug'        => 'all',
659
+				'label'       => esc_html__('All', 'event_espresso'),
660
+				'count'       => 0,
661
+				'bulk_action' => [
662
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
663
+				],
664
+			],
665
+		];
666
+	}
667
+
668
+
669
+	/**
670
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
671
+	 */
672
+	public function admin_init()
673
+	{
674
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
675
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
676
+			'event_espresso'
677
+		);
678
+	}
679
+
680
+
681
+	/**
682
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
683
+	 * group.
684
+	 */
685
+	public function admin_notices()
686
+	{
687
+	}
688
+
689
+
690
+	/**
691
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
692
+	 * this admin page group.
693
+	 */
694
+	public function admin_footer_scripts()
695
+	{
696
+	}
697
+
698
+
699
+	/**
700
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
701
+	 * warning (via EE_Error::add_error());
702
+	 *
703
+	 * @param EE_Event|null $event Event object
704
+	 * @param string        $req_type
705
+	 * @return void
706
+	 * @throws EE_Error
707
+	 * @throws ReflectionException
708
+	 */
709
+	public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '')
710
+	{
711
+		// don't need to do this when processing
712
+		if (! empty($req_type)) {
713
+			return;
714
+		}
715
+		// no event?
716
+		if (! $event instanceof EE_Event) {
717
+			$event = $this->_cpt_model_obj;
718
+		}
719
+		// STILL no event?
720
+		if (! $event instanceof EE_Event) {
721
+			return;
722
+		}
723
+		// don't need to keep calling this
724
+		remove_action(
725
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
726
+			[$this, 'verify_event_edit']
727
+		);
728
+		$orig_status = $event->status();
729
+		// first check if event is active.
730
+		if (
731
+			$orig_status === EEM_Event::cancelled
732
+			|| $orig_status === EEM_Event::postponed
733
+			|| $event->is_expired()
734
+			|| $event->is_inactive()
735
+		) {
736
+			return;
737
+		}
738
+		// made it here so it IS active... next check that any of the tickets are sold.
739
+		if ($event->is_sold_out(true)) {
740
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
741
+				EE_Error::add_attention(
742
+					sprintf(
743
+						esc_html__(
744
+							'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.',
745
+							'event_espresso'
746
+						),
747
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
748
+					)
749
+				);
750
+			}
751
+			return;
752
+		}
753
+		if ($orig_status === EEM_Event::sold_out) {
754
+			EE_Error::add_attention(
755
+				sprintf(
756
+					esc_html__(
757
+						'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.',
758
+						'event_espresso'
759
+					),
760
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
761
+				)
762
+			);
763
+		}
764
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
765
+		if (! $event->tickets_on_sale()) {
766
+			return;
767
+		}
768
+		// made it here so show warning
769
+		$this->_edit_event_warning();
770
+	}
771
+
772
+
773
+	/**
774
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
775
+	 * When needed, hook this into a EE_Error::add_error() notice.
776
+	 *
777
+	 * @access protected
778
+	 * @return void
779
+	 */
780
+	protected function _edit_event_warning()
781
+	{
782
+		// we don't want to add warnings during these requests
783
+		if ($this->request->getRequestParam('action') === 'editpost') {
784
+			return;
785
+		}
786
+		EE_Error::add_attention(
787
+			sprintf(
788
+				esc_html__(
789
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
790
+					'event_espresso'
791
+				),
792
+				'<a class="espresso-help-tab-lnk ee-help-tab-link">',
793
+				'</a>'
794
+			)
795
+		);
796
+	}
797
+
798
+
799
+	/**
800
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
801
+	 * Otherwise, do the normal logic
802
+	 *
803
+	 * @return void
804
+	 * @throws EE_Error
805
+	 * @throws InvalidArgumentException
806
+	 * @throws InvalidDataTypeException
807
+	 * @throws InvalidInterfaceException
808
+	 * @throws ReflectionException
809
+	 */
810
+	protected function _create_new_cpt_item()
811
+	{
812
+		$has_timezone_string = get_option('timezone_string');
813
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
814
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
815
+			EE_Error::add_attention(
816
+				sprintf(
817
+					esc_html__(
818
+						'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',
819
+						'event_espresso'
820
+					),
821
+					'<br>',
822
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
823
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
824
+					. '</select>',
825
+					'<button class="button button--secondary timezone-submit">',
826
+					'</button><span class="spinner"></span>'
827
+				),
828
+				__FILE__,
829
+				__FUNCTION__,
830
+				__LINE__
831
+			);
832
+		}
833
+		parent::_create_new_cpt_item();
834
+	}
835
+
836
+
837
+	/**
838
+	 * Sets the _views property for the default route in this admin page group.
839
+	 */
840
+	protected function _set_list_table_views_default()
841
+	{
842
+		$this->_views = [
843
+			'all'   => [
844
+				'slug'        => 'all',
845
+				'label'       => esc_html__('View All Events', 'event_espresso'),
846
+				'count'       => 0,
847
+				'bulk_action' => [
848
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
849
+				],
850
+			],
851
+			'draft' => [
852
+				'slug'        => 'draft',
853
+				'label'       => esc_html__('Draft', 'event_espresso'),
854
+				'count'       => 0,
855
+				'bulk_action' => [
856
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
857
+				],
858
+			],
859
+		];
860
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
861
+			$this->_views['trash'] = [
862
+				'slug'        => 'trash',
863
+				'label'       => esc_html__('Trash', 'event_espresso'),
864
+				'count'       => 0,
865
+				'bulk_action' => [
866
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
867
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
868
+				],
869
+			];
870
+		}
871
+	}
872
+
873
+
874
+	/**
875
+	 * Provides the legend item array for the default list table view.
876
+	 *
877
+	 * @return array
878
+	 * @throws EE_Error
879
+	 * @throws EE_Error
880
+	 */
881
+	protected function _event_legend_items(): array
882
+	{
883
+		$items    = [
884
+			'view_details'   => [
885
+				'class' => 'dashicons dashicons-visibility',
886
+				'desc'  => esc_html__('View Event', 'event_espresso'),
887
+			],
888
+			'edit_event'     => [
889
+				'class' => 'dashicons dashicons-calendar-alt',
890
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
891
+			],
892
+			'view_attendees' => [
893
+				'class' => 'dashicons dashicons-groups',
894
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
895
+			],
896
+		];
897
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
898
+		$statuses = [
899
+			'sold_out_status'  => [
900
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
901
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
902
+			],
903
+			'active_status'    => [
904
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
905
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
906
+			],
907
+			'upcoming_status'  => [
908
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
909
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
910
+			],
911
+			'postponed_status' => [
912
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
913
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
914
+			],
915
+			'cancelled_status' => [
916
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
917
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
918
+			],
919
+			'expired_status'   => [
920
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
921
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
922
+			],
923
+			'inactive_status'  => [
924
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
925
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
926
+			],
927
+		];
928
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
929
+		return array_merge($items, $statuses);
930
+	}
931
+
932
+
933
+	/**
934
+	 * @return EEM_Event
935
+	 * @throws EE_Error
936
+	 * @throws InvalidArgumentException
937
+	 * @throws InvalidDataTypeException
938
+	 * @throws InvalidInterfaceException
939
+	 * @throws ReflectionException
940
+	 */
941
+	private function _event_model(): EEM_Event
942
+	{
943
+		if (! $this->_event_model instanceof EEM_Event) {
944
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
945
+		}
946
+		return $this->_event_model;
947
+	}
948
+
949
+
950
+	/**
951
+	 * Adds extra buttons to the WP CPT permalink field row.
952
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
953
+	 *
954
+	 * @param string      $return    the current html
955
+	 * @param int         $id        the post id for the page
956
+	 * @param string|null $new_title What the title is
957
+	 * @param string|null $new_slug  what the slug is
958
+	 * @return string            The new html string for the permalink area
959
+	 * @deprecated $VID:$
960
+	 * @see TicketSelectorShortcodeButton::addButton
961
+	 */
962
+	public function extra_permalink_field_buttons(
963
+		string $return,
964
+		int $id,
965
+		?string $new_title,
966
+		?string $new_slug
967
+	): string {
968
+		return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug);
969
+	}
970
+
971
+
972
+	/**
973
+	 * _events_overview_list_table
974
+	 * This contains the logic for showing the events_overview list
975
+	 *
976
+	 * @access protected
977
+	 * @return void
978
+	 * @throws DomainException
979
+	 * @throws EE_Error
980
+	 * @throws InvalidArgumentException
981
+	 * @throws InvalidDataTypeException
982
+	 * @throws InvalidInterfaceException
983
+	 */
984
+	protected function _events_overview_list_table()
985
+	{
986
+		$after_list_table = [];
987
+		$links_html       = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
988
+		$links_html       .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
989
+		$links_html       .= EEH_HTML::div(
990
+			EEH_Template::get_button_or_link(
991
+				get_post_type_archive_link('espresso_events'),
992
+				esc_html__('View Event Archive Page', 'event_espresso'),
993
+				'button button--small button--secondary'
994
+			),
995
+			'',
996
+			'ee-admin-button-row ee-admin-button-row--align-start'
997
+		);
998
+		$links_html       .= EEH_HTML::divx();
999
+
1000
+		$after_list_table['view_event_list_button'] = $links_html;
1001
+
1002
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
1003
+		$this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
1004
+			'create_new',
1005
+			'add',
1006
+			[],
1007
+			'add-new-h2'
1008
+		);
1009
+
1010
+		$this->_template_args['after_list_table'] = array_merge(
1011
+			(array) $this->_template_args['after_list_table'],
1012
+			$after_list_table
1013
+		);
1014
+		$this->display_admin_list_table_page_with_no_sidebar();
1015
+	}
1016
+
1017
+
1018
+	/**
1019
+	 * this allows for extra misc actions in the default WP publish box
1020
+	 *
1021
+	 * @return void
1022
+	 * @throws DomainException
1023
+	 * @throws EE_Error
1024
+	 * @throws InvalidArgumentException
1025
+	 * @throws InvalidDataTypeException
1026
+	 * @throws InvalidInterfaceException
1027
+	 * @throws ReflectionException
1028
+	 */
1029
+	public function extra_misc_actions_publish_box()
1030
+	{
1031
+		$this->_generate_publish_box_extra_content();
1032
+	}
1033
+
1034
+
1035
+	/**
1036
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1037
+	 * saved.
1038
+	 * Typically you would use this to save any additional data.
1039
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1040
+	 * ALSO very important.  When a post transitions from scheduled to published,
1041
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1042
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1043
+	 *
1044
+	 * @access protected
1045
+	 * @abstract
1046
+	 * @param string  $post_id The ID of the cpt that was saved (so you can link relationally)
1047
+	 * @param WP_Post $post    The post object of the cpt that was saved.
1048
+	 * @return void
1049
+	 * @throws EE_Error
1050
+	 * @throws InvalidArgumentException
1051
+	 * @throws InvalidDataTypeException
1052
+	 * @throws InvalidInterfaceException
1053
+	 * @throws ReflectionException
1054
+	 */
1055
+	protected function _insert_update_cpt_item($post_id, $post)
1056
+	{
1057
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1058
+			// get out we're not processing an event save.
1059
+			return;
1060
+		}
1061
+		$event_values = [
1062
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, DataType::BOOL),
1063
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, DataType::BOOL),
1064
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1065
+		];
1066
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1067
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1068
+			$event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1069
+				'display_ticket_selector',
1070
+				false,
1071
+				'bool'
1072
+			);
1073
+			$event_values['EVT_additional_limit']            = min(
1074
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1075
+				$this->request->getRequestParam(
1076
+					'additional_limit',
1077
+					EEM_Event::get_default_additional_limit(),
1078
+					'int'
1079
+				)
1080
+			);
1081
+			$event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1082
+				'EVT_default_registration_status',
1083
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1084
+			);
1085
+
1086
+			$event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1087
+			$event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1088
+			$event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, DataType::BOOL);
1089
+		} elseif ($post instanceof WP_Post) {
1090
+			$event_values['EVT_name'] = $post->post_title;
1091
+			$event_values['EVT_desc'] = $post->post_content;
1092
+		}
1093
+		// update event
1094
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1095
+		// get event_object for other metaboxes...
1096
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1097
+		// i have to setup where conditions to override the filters in the model
1098
+		// that filter out auto-draft and inherit statuses so we GET the inherit id!
1099
+		/** @var EE_Event $event */
1100
+		$event = $this->_event_model()->get_one(
1101
+			[
1102
+				[
1103
+					$this->_event_model()->primary_key_name() => $post_id,
1104
+					'OR'                                      => [
1105
+						'status'   => $post->post_status,
1106
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1107
+						// but the returned object here has a status of "publish", so use the original post status as well
1108
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1109
+					],
1110
+				],
1111
+			]
1112
+		);
1113
+
1114
+		// the following are default callbacks for event attachment updates
1115
+		// that can be overridden by caffeinated functionality and/or addons.
1116
+		$event_update_callbacks = [];
1117
+		if (! $this->admin_config->useAdvancedEditor()) {
1118
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1119
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1120
+		}
1121
+		$event_update_callbacks = apply_filters(
1122
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1123
+			$event_update_callbacks
1124
+		);
1125
+
1126
+		$att_success = true;
1127
+		foreach ($event_update_callbacks as $e_callback) {
1128
+			$_success = is_callable($e_callback)
1129
+				? $e_callback($event, $this->request->requestParams())
1130
+				: false;
1131
+			// if ANY of these updates fail then we want the appropriate global error message
1132
+			$att_success = $_success !== false ? $att_success : false;
1133
+		}
1134
+		// any errors?
1135
+		if ($success && $att_success === false) {
1136
+			EE_Error::add_error(
1137
+				esc_html__(
1138
+					'Event Details saved successfully but something went wrong with saving attachments.',
1139
+					'event_espresso'
1140
+				),
1141
+				__FILE__,
1142
+				__FUNCTION__,
1143
+				__LINE__
1144
+			);
1145
+		} elseif ($success === false) {
1146
+			EE_Error::add_error(
1147
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1148
+				__FILE__,
1149
+				__FUNCTION__,
1150
+				__LINE__
1151
+			);
1152
+		}
1153
+	}
1154
+
1155
+
1156
+	/**
1157
+	 * @param int $post_id
1158
+	 * @param int $revision_id
1159
+	 * @throws EE_Error
1160
+	 * @throws EE_Error
1161
+	 * @throws ReflectionException
1162
+	 * @see parent::restore_item()
1163
+	 */
1164
+	protected function _restore_cpt_item(int $post_id, int $revision_id)
1165
+	{
1166
+		// copy existing event meta to new post
1167
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1168
+		if ($post_evt instanceof EE_Event) {
1169
+			// meta revision restore
1170
+			$post_evt->restore_revision($revision_id);
1171
+			// related objs restore
1172
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1173
+		}
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * Attach the venue to the Event
1179
+	 *
1180
+	 * @param EE_Event $event Event Object to add the venue to
1181
+	 * @param array    $data  The request data from the form
1182
+	 * @return bool           Success or fail.
1183
+	 * @throws EE_Error
1184
+	 * @throws ReflectionException
1185
+	 */
1186
+	protected function _default_venue_update(EE_Event $event, array $data): bool
1187
+	{
1188
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1189
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1190
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1191
+		// very important.  If we don't have a venue name...
1192
+		// then we'll get out because not necessary to create empty venue
1193
+		if (empty($data['venue_title'])) {
1194
+			return false;
1195
+		}
1196
+		$venue_array = [
1197
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1198
+			'VNU_name'            => $data['venue_title'],
1199
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1200
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1201
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1202
+				? $data['venue_short_description']
1203
+				: null,
1204
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1205
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1206
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1207
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1208
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1209
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1210
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1211
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1212
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1213
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1214
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1215
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1216
+			'status'              => 'publish',
1217
+		];
1218
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1219
+		if (! empty($venue_id)) {
1220
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1221
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1222
+			// we've gotta make sure that the venue is always attached to a revision..
1223
+			// add_relation_to should take care of making sure that the relation is already present.
1224
+			$event->_add_relation_to($venue_id, 'Venue');
1225
+			return $rows_affected > 0;
1226
+		}
1227
+		// we insert the venue
1228
+		$venue_id = $venue_model->insert($venue_array);
1229
+		$event->_add_relation_to($venue_id, 'Venue');
1230
+		return ! empty($venue_id);
1231
+		// when we have the ancestor come in it's already been handled by the revision save.
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1237
+	 *
1238
+	 * @param EE_Event $event The Event object we're attaching data to
1239
+	 * @param array    $data  The request data from the form
1240
+	 * @return array
1241
+	 * @throws EE_Error
1242
+	 * @throws ReflectionException
1243
+	 * @throws Exception
1244
+	 */
1245
+	protected function _default_tickets_update(EE_Event $event, array $data): array
1246
+	{
1247
+		if ($this->admin_config->useAdvancedEditor()) {
1248
+			return [];
1249
+		}
1250
+		$datetime       = null;
1251
+		$saved_tickets  = [];
1252
+		$event_timezone = $event->get_timezone();
1253
+		$date_formats   = ['Y-m-d', 'h:i a'];
1254
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1255
+			// trim all values to ensure any excess whitespace is removed.
1256
+			$datetime_data                = array_map('trim', $datetime_data);
1257
+			$datetime_data['DTT_EVT_end'] =
1258
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1259
+					? $datetime_data['DTT_EVT_end']
1260
+					: $datetime_data['DTT_EVT_start'];
1261
+			$datetime_values              = [
1262
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1263
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1264
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1265
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1266
+				'DTT_order'     => $row,
1267
+			];
1268
+			// if we have an id then let's get existing object first and then set the new values.
1269
+			//  Otherwise we instantiate a new object for save.
1270
+			if (! empty($datetime_data['DTT_ID'])) {
1271
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1272
+				if (! $datetime instanceof EE_Datetime) {
1273
+					throw new RuntimeException(
1274
+						sprintf(
1275
+							esc_html__(
1276
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1277
+								'event_espresso'
1278
+							),
1279
+							$datetime_data['DTT_ID']
1280
+						)
1281
+					);
1282
+				}
1283
+				$datetime->set_date_format($date_formats[0]);
1284
+				$datetime->set_time_format($date_formats[1]);
1285
+				foreach ($datetime_values as $field => $value) {
1286
+					$datetime->set($field, $value);
1287
+				}
1288
+			} else {
1289
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1290
+			}
1291
+			if (! $datetime instanceof EE_Datetime) {
1292
+				throw new RuntimeException(
1293
+					sprintf(
1294
+						esc_html__(
1295
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1296
+							'event_espresso'
1297
+						),
1298
+						print_r($datetime_values, true)
1299
+					)
1300
+				);
1301
+			}
1302
+			// before going any further make sure our dates are setup correctly
1303
+			// so that the end date is always equal or greater than the start date.
1304
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1305
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1306
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1307
+			}
1308
+			$datetime->save();
1309
+			$event->_add_relation_to($datetime, 'Datetime');
1310
+		}
1311
+		// no datetimes get deleted so we don't do any of that logic here.
1312
+		// update tickets next
1313
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1314
+
1315
+		// set up some default start and end dates in case those are not present in the incoming data
1316
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1317
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1318
+		// use the start date of the first datetime for the end date
1319
+		$first_datetime   = $event->first_datetime();
1320
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1321
+
1322
+		// now process the incoming data
1323
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1324
+			$update_prices = false;
1325
+			$ticket_price  = $data['edit_prices'][ $row ][1]['PRC_amount'] ?? 0;
1326
+			// trim inputs to ensure any excess whitespace is removed.
1327
+			$ticket_data   = array_map('trim', $ticket_data);
1328
+			$ticket_values = [
1329
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1330
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1331
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1332
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1333
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1334
+					? $ticket_data['TKT_start_date']
1335
+					: $default_start_date,
1336
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1337
+					? $ticket_data['TKT_end_date']
1338
+					: $default_end_date,
1339
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1340
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1341
+					? $ticket_data['TKT_qty']
1342
+					: EE_INF,
1343
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1344
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1345
+					? $ticket_data['TKT_uses']
1346
+					: EE_INF,
1347
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1348
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1349
+				'TKT_order'       => $ticket_data['TKT_order'] ?? $row,
1350
+				'TKT_price'       => $ticket_price,
1351
+				'TKT_row'         => $row,
1352
+			];
1353
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1354
+			// which means in turn that the prices will become new prices as well.
1355
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1356
+				$ticket_values['TKT_ID']         = 0;
1357
+				$ticket_values['TKT_is_default'] = 0;
1358
+				$update_prices                   = true;
1359
+			}
1360
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1361
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1362
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1363
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1364
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1365
+			if (! empty($ticket_data['TKT_ID'])) {
1366
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1367
+				if (! $existing_ticket instanceof EE_Ticket) {
1368
+					throw new RuntimeException(
1369
+						sprintf(
1370
+							esc_html__(
1371
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1372
+								'event_espresso'
1373
+							),
1374
+							$ticket_data['TKT_ID']
1375
+						)
1376
+					);
1377
+				}
1378
+				$ticket_sold = $existing_ticket->count_related(
1379
+					'Registration',
1380
+					[
1381
+							[
1382
+								'STS_ID' => [
1383
+									'NOT IN',
1384
+									[EEM_Registration::status_id_incomplete],
1385
+								],
1386
+							],
1387
+						]
1388
+				) > 0;
1389
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1390
+				// if they are different then we create a new ticket (if $ticket_sold)
1391
+				// if they aren't different then we go ahead and modify existing ticket.
1392
+				$create_new_ticket = $ticket_sold
1393
+									 && $ticket_price !== $existing_ticket->price()
1394
+									 && ! $existing_ticket->deleted();
1395
+				$existing_ticket->set_date_format($date_formats[0]);
1396
+				$existing_ticket->set_time_format($date_formats[1]);
1397
+				// set new values
1398
+				foreach ($ticket_values as $field => $value) {
1399
+					if ($field == 'TKT_qty') {
1400
+						$existing_ticket->set_qty($value);
1401
+					} elseif ($field == 'TKT_price') {
1402
+						$existing_ticket->set('TKT_price', $ticket_price);
1403
+					} else {
1404
+						$existing_ticket->set($field, $value);
1405
+					}
1406
+				}
1407
+				$ticket = $existing_ticket;
1408
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1409
+				//  Otherwise we have to create a new ticket.
1410
+				if ($create_new_ticket) {
1411
+					// archive the old ticket first
1412
+					$existing_ticket->set('TKT_deleted', 1);
1413
+					$existing_ticket->save();
1414
+					// make sure this ticket is still recorded in our $saved_tickets
1415
+					// so we don't run it through the regular trash routine.
1416
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1417
+					// create new ticket that's a copy of the existing except,
1418
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1419
+					$new_ticket = clone $existing_ticket;
1420
+					$new_ticket->set('TKT_ID', 0);
1421
+					$new_ticket->set('TKT_deleted', 0);
1422
+					$new_ticket->set('TKT_sold', 0);
1423
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1424
+					$update_prices = true;
1425
+					$ticket        = $new_ticket;
1426
+				}
1427
+			} else {
1428
+				// no TKT_id so a new ticket
1429
+				$ticket_values['TKT_price'] = $ticket_price;
1430
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1431
+				$update_prices              = true;
1432
+			}
1433
+			if (! $ticket instanceof EE_Ticket) {
1434
+				throw new RuntimeException(
1435
+					sprintf(
1436
+						esc_html__(
1437
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1438
+							'event_espresso'
1439
+						),
1440
+						print_r($ticket_values, true)
1441
+					)
1442
+				);
1443
+			}
1444
+			// cap ticket qty by datetime reg limits
1445
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1446
+			// update ticket.
1447
+			$ticket->save();
1448
+			// before going any further make sure our dates are setup correctly
1449
+			// so that the end date is always equal or greater than the start date.
1450
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1451
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1452
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1453
+				$ticket->save();
1454
+			}
1455
+			// initially let's add the ticket to the datetime
1456
+			$datetime->_add_relation_to($ticket, 'Ticket');
1457
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1458
+			// add prices to ticket
1459
+			$prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1460
+				? $data['edit_prices'][ $row ]
1461
+				: [];
1462
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1463
+		}
1464
+		// however now we need to handle permanently deleting tickets via the ui.
1465
+		// Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1466
+		// However, it does allow for deleting tickets that have no tickets sold,
1467
+		// in which case we want to get rid of permanently because there is no need to save in db.
1468
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1469
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1470
+		foreach ($tickets_removed as $id) {
1471
+			$id = absint($id);
1472
+			// get the ticket for this id
1473
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1474
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1475
+				continue;
1476
+			}
1477
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1478
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1479
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1480
+			foreach ($related_datetimes as $related_datetime) {
1481
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1482
+			}
1483
+			// need to do the same for prices (except these prices can also be deleted because again,
1484
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1485
+			$ticket_to_remove->delete_related_permanently('Price');
1486
+			// finally let's delete this ticket
1487
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1488
+			$ticket_to_remove->delete_permanently();
1489
+		}
1490
+		return [$datetime, $saved_tickets];
1491
+	}
1492
+
1493
+
1494
+	/**
1495
+	 * This attaches a list of given prices to a ticket.
1496
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1497
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1498
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1499
+	 *
1500
+	 * @access  private
1501
+	 * @param array     $prices_data Array of prices from the form.
1502
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1503
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1504
+	 * @return  void
1505
+	 * @throws EE_Error
1506
+	 * @throws ReflectionException
1507
+	 */
1508
+	private function _add_prices_to_ticket(array $prices_data, EE_Ticket $ticket, bool $new_prices = false)
1509
+	{
1510
+		$timezone = $ticket->get_timezone();
1511
+		foreach ($prices_data as $row => $price_data) {
1512
+			$price_values = [
1513
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1514
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1515
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1516
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1517
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1518
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1519
+				'PRC_order'      => $row,
1520
+			];
1521
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1522
+				$price_values['PRC_ID'] = 0;
1523
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1524
+			} else {
1525
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1526
+				// update this price with new values
1527
+				foreach ($price_values as $field => $new_price) {
1528
+					$price->set($field, $new_price);
1529
+				}
1530
+			}
1531
+			if (! $price instanceof EE_Price) {
1532
+				throw new RuntimeException(
1533
+					sprintf(
1534
+						esc_html__(
1535
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1536
+							'event_espresso'
1537
+						),
1538
+						print_r($price_values, true)
1539
+					)
1540
+				);
1541
+			}
1542
+			$price->save();
1543
+			$ticket->_add_relation_to($price, 'Price');
1544
+		}
1545
+	}
1546
+
1547
+
1548
+	/**
1549
+	 * Add in our autosave ajax handlers
1550
+	 *
1551
+	 */
1552
+	protected function _ee_autosave_create_new()
1553
+	{
1554
+	}
1555
+
1556
+
1557
+	/**
1558
+	 * More autosave handlers.
1559
+	 */
1560
+	protected function _ee_autosave_edit()
1561
+	{
1562
+	}
1563
+
1564
+
1565
+	/**
1566
+	 * @throws EE_Error
1567
+	 * @throws ReflectionException
1568
+	 */
1569
+	private function _generate_publish_box_extra_content()
1570
+	{
1571
+		// load formatter helper
1572
+		// args for getting related registrations
1573
+		$approved_query_args        = [
1574
+			[
1575
+				'REG_deleted' => 0,
1576
+				'STS_ID'      => EEM_Registration::status_id_approved,
1577
+			],
1578
+		];
1579
+		$not_approved_query_args    = [
1580
+			[
1581
+				'REG_deleted' => 0,
1582
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1583
+			],
1584
+		];
1585
+		$pending_payment_query_args = [
1586
+			[
1587
+				'REG_deleted' => 0,
1588
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1589
+			],
1590
+		];
1591
+		// publish box
1592
+		$publish_box_extra_args = [
1593
+			'view_approved_reg_url'        => add_query_arg(
1594
+				[
1595
+					'action'      => 'default',
1596
+					'event_id'    => $this->_cpt_model_obj->ID(),
1597
+					'_reg_status' => EEM_Registration::status_id_approved,
1598
+					'use_filters' => true,
1599
+				],
1600
+				REG_ADMIN_URL
1601
+			),
1602
+			'view_not_approved_reg_url'    => add_query_arg(
1603
+				[
1604
+					'action'      => 'default',
1605
+					'event_id'    => $this->_cpt_model_obj->ID(),
1606
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1607
+					'use_filters' => true,
1608
+				],
1609
+				REG_ADMIN_URL
1610
+			),
1611
+			'view_pending_payment_reg_url' => add_query_arg(
1612
+				[
1613
+					'action'      => 'default',
1614
+					'event_id'    => $this->_cpt_model_obj->ID(),
1615
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1616
+					'use_filters' => true,
1617
+				],
1618
+				REG_ADMIN_URL
1619
+			),
1620
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1621
+				'Registration',
1622
+				$approved_query_args
1623
+			),
1624
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1625
+				'Registration',
1626
+				$not_approved_query_args
1627
+			),
1628
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1629
+				'Registration',
1630
+				$pending_payment_query_args
1631
+			),
1632
+			'misc_pub_section_class'       => apply_filters(
1633
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1634
+				'misc-pub-section'
1635
+			),
1636
+		];
1637
+		ob_start();
1638
+		do_action(
1639
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1640
+			$this->_cpt_model_obj
1641
+		);
1642
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1643
+		// load template
1644
+		EEH_Template::display_template(
1645
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1646
+			$publish_box_extra_args
1647
+		);
1648
+	}
1649
+
1650
+
1651
+	/**
1652
+	 * @return EE_Event
1653
+	 */
1654
+	public function get_event_object()
1655
+	{
1656
+		return $this->_cpt_model_obj;
1657
+	}
1658
+
1659
+
1660
+
1661
+
1662
+	/** METABOXES * */
1663
+	/**
1664
+	 * _register_event_editor_meta_boxes
1665
+	 * add all metaboxes related to the event_editor
1666
+	 *
1667
+	 * @return void
1668
+	 * @throws EE_Error
1669
+	 * @throws ReflectionException
1670
+	 */
1671
+	protected function _register_event_editor_meta_boxes()
1672
+	{
1673
+		$this->verify_cpt_object();
1674
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1675
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1676
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1677
+			$this->addMetaBox(
1678
+				'espresso_event_editor_event_options',
1679
+				esc_html__('Event Registration Options', 'event_espresso'),
1680
+				[$this, 'registration_options_meta_box'],
1681
+				$this->page_slug,
1682
+				'side'
1683
+			);
1684
+		}
1685
+		if (! $use_advanced_editor) {
1686
+			$this->addMetaBox(
1687
+				'espresso_event_editor_tickets',
1688
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1689
+				[$this, 'ticket_metabox'],
1690
+				$this->page_slug,
1691
+				'normal',
1692
+				'high'
1693
+			);
1694
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1695
+			add_action(
1696
+				'add_meta_boxes_espresso_events',
1697
+				function () {
1698
+					global $current_screen;
1699
+					remove_meta_box('authordiv', $current_screen, 'normal');
1700
+				},
1701
+				99
1702
+			);
1703
+		}
1704
+		// NOTE: if you're looking for other metaboxes in here,
1705
+		// where a metabox has a related management page in the admin
1706
+		// you will find it setup in the related management page's "_Hooks" file.
1707
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1708
+	}
1709
+
1710
+
1711
+	/**
1712
+	 * @throws DomainException
1713
+	 * @throws EE_Error
1714
+	 * @throws ReflectionException
1715
+	 */
1716
+	public function ticket_metabox()
1717
+	{
1718
+		$existing_datetime_ids = $existing_ticket_ids = [];
1719
+		// defaults for template args
1720
+		$template_args = [
1721
+			'ticket_rows'       => '',
1722
+			'total_ticket_rows' => 1,
1723
+			'trash_icon'        => 'dashicons dashicons-lock',
1724
+			'disabled'          => '',
1725
+		];
1726
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1727
+		/**
1728
+		 * 1. Start with retrieving Datetimes
1729
+		 * 2. Fore each datetime get related tickets
1730
+		 * 3. For each ticket get related prices
1731
+		 */
1732
+		/** @var EEM_Datetime $datetime_model */
1733
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1734
+		/** @var EEM_Ticket $datetime_model */
1735
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1736
+		$times        = $datetime_model->get_all_event_dates($event_id);
1737
+		/** @type EE_Datetime $first_datetime */
1738
+		$first_datetime = reset($times);
1739
+		// do we get related tickets?
1740
+		if (
1741
+			$first_datetime instanceof EE_Datetime
1742
+			&& $first_datetime->ID() !== 0
1743
+		) {
1744
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1745
+			$template_args['time']   = $first_datetime;
1746
+			$related_tickets         = $first_datetime->tickets(
1747
+				[
1748
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1749
+					'default_where_conditions' => 'none',
1750
+				]
1751
+			);
1752
+			if (! empty($related_tickets)) {
1753
+				$template_args['total_ticket_rows'] = count($related_tickets);
1754
+				$row                                = 0;
1755
+				foreach ($related_tickets as $ticket) {
1756
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1757
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1758
+					$row++;
1759
+				}
1760
+			} else {
1761
+				$template_args['total_ticket_rows'] = 1;
1762
+				/** @type EE_Ticket $ticket */
1763
+				$ticket                       = $ticket_model->create_default_object();
1764
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1765
+			}
1766
+		} else {
1767
+			$template_args['time'] = $times[0];
1768
+			/** @type EE_Ticket[] $tickets */
1769
+			$tickets                      = $ticket_model->get_all_default_tickets();
1770
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1771
+			// NOTE: we're just sending the first default row
1772
+			// (decaf can't manage default tickets so this should be sufficient);
1773
+		}
1774
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1775
+			'event_editor_event_datetimes_help_tab'
1776
+		);
1777
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1778
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1779
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1780
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1781
+			$ticket_model->create_default_object(),
1782
+			true
1783
+		);
1784
+		$template                                  = apply_filters(
1785
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1786
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1787
+		);
1788
+		EEH_Template::display_template($template, $template_args);
1789
+	}
1790
+
1791
+
1792
+	/**
1793
+	 * Setup an individual ticket form for the decaf event editor page
1794
+	 *
1795
+	 * @access private
1796
+	 * @param EE_Ticket $ticket   the ticket object
1797
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1798
+	 * @param int       $row
1799
+	 * @return string generated html for the ticket row.
1800
+	 * @throws EE_Error
1801
+	 * @throws ReflectionException
1802
+	 */
1803
+	private function _get_ticket_row(EE_Ticket $ticket, bool $skeleton = false, int $row = 0): string
1804
+	{
1805
+		$template_args = [
1806
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1807
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1808
+				: '',
1809
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1810
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1811
+			'TKT_name'            => $ticket->get('TKT_name'),
1812
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1813
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1814
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1815
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1816
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1817
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1818
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1819
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1820
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1821
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1822
+				: ' disabled=disabled',
1823
+		];
1824
+		$price         = $ticket->ID() !== 0
1825
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1826
+			: null;
1827
+		$price         = $price instanceof EE_Price
1828
+			? $price
1829
+			: EEM_Price::instance()->create_default_object();
1830
+		$price_args    = [
1831
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1832
+			'PRC_amount'            => $price->get('PRC_amount'),
1833
+			'PRT_ID'                => $price->get('PRT_ID'),
1834
+			'PRC_ID'                => $price->get('PRC_ID'),
1835
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1836
+		];
1837
+		// make sure we have default start and end dates if skeleton
1838
+		// handle rows that should NOT be empty
1839
+		if (empty($template_args['TKT_start_date'])) {
1840
+			// if empty then the start date will be now.
1841
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1842
+		}
1843
+		if (empty($template_args['TKT_end_date'])) {
1844
+			// get the earliest datetime (if present);
1845
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1846
+				? $this->_cpt_model_obj->get_first_related(
1847
+					'Datetime',
1848
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1849
+				)
1850
+				: null;
1851
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1852
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1853
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1854
+		}
1855
+		$template_args = array_merge($template_args, $price_args);
1856
+		$template      = apply_filters(
1857
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1858
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1859
+			$ticket
1860
+		);
1861
+		return EEH_Template::display_template($template, $template_args, true);
1862
+	}
1863
+
1864
+
1865
+	/**
1866
+	 * @throws EE_Error
1867
+	 * @throws ReflectionException
1868
+	 */
1869
+	public function registration_options_meta_box()
1870
+	{
1871
+		$yes_no_values             = [
1872
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1873
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1874
+		];
1875
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1876
+			[
1877
+				EEM_Registration::status_id_cancelled,
1878
+				EEM_Registration::status_id_declined,
1879
+				EEM_Registration::status_id_incomplete,
1880
+			],
1881
+			true
1882
+		);
1883
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1884
+		$template_args['_event']                          = $this->_cpt_model_obj;
1885
+		$template_args['event']                           = $this->_cpt_model_obj;
1886
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1887
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1888
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1889
+			'default_reg_status',
1890
+			$default_reg_status_values,
1891
+			$this->_cpt_model_obj->default_registration_status()
1892
+		);
1893
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1894
+			'display_desc',
1895
+			$yes_no_values,
1896
+			$this->_cpt_model_obj->display_description()
1897
+		);
1898
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1899
+			'display_ticket_selector',
1900
+			$yes_no_values,
1901
+			$this->_cpt_model_obj->display_ticket_selector(),
1902
+			'',
1903
+			'',
1904
+			false
1905
+		);
1906
+		$template_args['additional_registration_options'] = apply_filters(
1907
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1908
+			'',
1909
+			$template_args,
1910
+			$yes_no_values,
1911
+			$default_reg_status_values
1912
+		);
1913
+		EEH_Template::display_template(
1914
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1915
+			$template_args
1916
+		);
1917
+	}
1918
+
1919
+
1920
+	/**
1921
+	 * _get_events()
1922
+	 * This method simply returns all the events (for the given _view and paging)
1923
+	 *
1924
+	 * @access public
1925
+	 * @param int  $per_page     count of items per page (20 default);
1926
+	 * @param int  $current_page what is the current page being viewed.
1927
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1928
+	 *                           If FALSE then we return an array of event objects
1929
+	 *                           that match the given _view and paging parameters.
1930
+	 * @return array|int         an array of event objects or a count of them.
1931
+	 * @throws Exception
1932
+	 */
1933
+	public function get_events(int $per_page = 10, int $current_page = 1, bool $count = false)
1934
+	{
1935
+		$EEM_Event   = $this->_event_model();
1936
+		$offset      = ($current_page - 1) * $per_page;
1937
+		$limit       = $count ? null : $offset . ',' . $per_page;
1938
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1939
+		$order       = $this->request->getRequestParam('order', 'DESC');
1940
+		$month_range = $this->request->getRequestParam('month_range');
1941
+		if ($month_range) {
1942
+			$pieces = explode(' ', $month_range, 3);
1943
+			// simulate the FIRST day of the month, that fixes issues for months like February
1944
+			// where PHP doesn't know what to assume for date.
1945
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1946
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1947
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1948
+		}
1949
+		$where  = [];
1950
+		$status = $this->request->getRequestParam('status');
1951
+		// determine what post_status our condition will have for the query.
1952
+		switch ($status) {
1953
+			case 'month':
1954
+			case 'today':
1955
+			case null:
1956
+			case 'all':
1957
+				break;
1958
+			case 'draft':
1959
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1960
+				break;
1961
+			default:
1962
+				$where['status'] = $status;
1963
+		}
1964
+		// categories? The default for all categories is -1
1965
+		$category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INT);
1966
+		if ($category !== -1) {
1967
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1968
+			$where['Term_Taxonomy.term_id']  = $category;
1969
+		}
1970
+		// date where conditions
1971
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1972
+		if ($month_range) {
1973
+			$DateTime = new DateTime(
1974
+				$year_r . '-' . $month_r . '-01 00:00:00',
1975
+				new DateTimeZone('UTC')
1976
+			);
1977
+			$start    = $DateTime->getTimestamp();
1978
+			// set the datetime to be the end of the month
1979
+			$DateTime->setDate(
1980
+				$year_r,
1981
+				$month_r,
1982
+				$DateTime->format('t')
1983
+			)->setTime(23, 59, 59);
1984
+			$end                             = $DateTime->getTimestamp();
1985
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
+		} elseif ($status === 'today') {
1987
+			$DateTime                        =
1988
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1989
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1990
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1991
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1992
+		} elseif ($status === 'month') {
1993
+			$now                             = date('Y-m-01');
1994
+			$DateTime                        =
1995
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1996
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1997
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1998
+														->setTime(23, 59, 59)
1999
+														->format(implode(' ', $start_formats));
2000
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2001
+		}
2002
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2003
+			$where['EVT_wp_user'] = get_current_user_id();
2004
+		} else {
2005
+			if (! isset($where['status'])) {
2006
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
2007
+					$where['OR'] = [
2008
+						'status*restrict_private' => ['!=', 'private'],
2009
+						'AND'                     => [
2010
+							'status*inclusive' => ['=', 'private'],
2011
+							'EVT_wp_user'      => get_current_user_id(),
2012
+						],
2013
+					];
2014
+				}
2015
+			}
2016
+		}
2017
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, DataType::INT);
2018
+		if (
2019
+			$wp_user
2020
+			&& $wp_user !== get_current_user_id()
2021
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2022
+		) {
2023
+			$where['EVT_wp_user'] = $wp_user;
2024
+		}
2025
+		// search query handling
2026
+		$search_term = $this->request->getRequestParam('s');
2027
+		if ($search_term) {
2028
+			$search_term = '%' . $search_term . '%';
2029
+			$where['OR'] = [
2030
+				'EVT_name'       => ['LIKE', $search_term],
2031
+				'EVT_desc'       => ['LIKE', $search_term],
2032
+				'EVT_short_desc' => ['LIKE', $search_term],
2033
+			];
2034
+		}
2035
+		// filter events by venue.
2036
+		$venue = $this->request->getRequestParam('venue', 0, DataType::INT);
2037
+		if ($venue) {
2038
+			$where['Venue.VNU_ID'] = $venue;
2039
+		}
2040
+		$request_params = $this->request->requestParams();
2041
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2042
+		$query_params   = apply_filters(
2043
+			'FHEE__Events_Admin_Page__get_events__query_params',
2044
+			[
2045
+				$where,
2046
+				'limit'    => $limit,
2047
+				'order_by' => $orderby,
2048
+				'order'    => $order,
2049
+				'group_by' => 'EVT_ID',
2050
+			],
2051
+			$request_params
2052
+		);
2053
+
2054
+		// let's first check if we have special requests coming in.
2055
+		$active_status = $this->request->getRequestParam('active_status');
2056
+		if ($active_status) {
2057
+			switch ($active_status) {
2058
+				case 'upcoming':
2059
+					return $EEM_Event->get_upcoming_events($query_params, $count);
2060
+				case 'expired':
2061
+					return $EEM_Event->get_expired_events($query_params, $count);
2062
+				case 'active':
2063
+					return $EEM_Event->get_active_events($query_params, $count);
2064
+				case 'inactive':
2065
+					return $EEM_Event->get_inactive_events($query_params, $count);
2066
+			}
2067
+		}
2068
+
2069
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2070
+	}
2071
+
2072
+
2073
+	/**
2074
+	 * handling for WordPress CPT actions (trash, restore, delete)
2075
+	 *
2076
+	 * @param string $post_id
2077
+	 * @throws EE_Error
2078
+	 * @throws ReflectionException
2079
+	 */
2080
+	public function trash_cpt_item($post_id)
2081
+	{
2082
+		$this->request->setRequestParam('EVT_ID', $post_id);
2083
+		$this->_trash_or_restore_event('trash', false);
2084
+	}
2085
+
2086
+
2087
+	/**
2088
+	 * @param string $post_id
2089
+	 * @throws EE_Error
2090
+	 * @throws ReflectionException
2091
+	 */
2092
+	public function restore_cpt_item($post_id)
2093
+	{
2094
+		$this->request->setRequestParam('EVT_ID', $post_id);
2095
+		$this->_trash_or_restore_event('draft', false);
2096
+	}
2097
+
2098
+
2099
+	/**
2100
+	 * @param string $post_id
2101
+	 * @throws EE_Error
2102
+	 * @throws EE_Error
2103
+	 */
2104
+	public function delete_cpt_item($post_id)
2105
+	{
2106
+		throw new EE_Error(
2107
+			esc_html__(
2108
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2109
+				'event_espresso'
2110
+			)
2111
+		);
2112
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2113
+		// $this->_delete_event();
2114
+	}
2115
+
2116
+
2117
+	/**
2118
+	 * _trash_or_restore_event
2119
+	 *
2120
+	 * @access protected
2121
+	 * @param string $event_status
2122
+	 * @param bool   $redirect_after
2123
+	 * @throws EE_Error
2124
+	 * @throws EE_Error
2125
+	 * @throws ReflectionException
2126
+	 */
2127
+	protected function _trash_or_restore_event(string $event_status = 'trash', bool $redirect_after = true)
2128
+	{
2129
+		// determine the event id and set to array.
2130
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT);
2131
+		// loop thru events
2132
+		if ($EVT_ID) {
2133
+			// clean status
2134
+			$event_status = sanitize_key($event_status);
2135
+			// grab status
2136
+			if (! empty($event_status)) {
2137
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2138
+			} else {
2139
+				$success = false;
2140
+				$msg     = esc_html__(
2141
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2142
+					'event_espresso'
2143
+				);
2144
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2145
+			}
2146
+		} else {
2147
+			$success = false;
2148
+			$msg     = esc_html__(
2149
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2150
+				'event_espresso'
2151
+			);
2152
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2153
+		}
2154
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2155
+		if ($redirect_after) {
2156
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2157
+		}
2158
+	}
2159
+
2160
+
2161
+	/**
2162
+	 * _trash_or_restore_events
2163
+	 *
2164
+	 * @access protected
2165
+	 * @param string $event_status
2166
+	 * @return void
2167
+	 * @throws EE_Error
2168
+	 * @throws EE_Error
2169
+	 * @throws ReflectionException
2170
+	 */
2171
+	protected function _trash_or_restore_events(string $event_status = 'trash')
2172
+	{
2173
+		// clean status
2174
+		$event_status = sanitize_key($event_status);
2175
+		// grab status
2176
+		if (! empty($event_status)) {
2177
+			$success = true;
2178
+			// determine the event id and set to array.
2179
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2180
+			// loop thru events
2181
+			foreach ($EVT_IDs as $EVT_ID) {
2182
+				if ($EVT_ID = absint($EVT_ID)) {
2183
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2184
+					$success = $results !== false ? $success : false;
2185
+				} else {
2186
+					$msg = sprintf(
2187
+						esc_html__(
2188
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2189
+							'event_espresso'
2190
+						),
2191
+						$EVT_ID
2192
+					);
2193
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2194
+					$success = false;
2195
+				}
2196
+			}
2197
+		} else {
2198
+			$success = false;
2199
+			$msg     = esc_html__(
2200
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2201
+				'event_espresso'
2202
+			);
2203
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2204
+		}
2205
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2206
+		$success = $success ? 2 : false;
2207
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2208
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2209
+	}
2210
+
2211
+
2212
+	/**
2213
+	 * @param int    $EVT_ID
2214
+	 * @param string $event_status
2215
+	 * @return bool
2216
+	 * @throws EE_Error
2217
+	 * @throws ReflectionException
2218
+	 */
2219
+	private function _change_event_status(int $EVT_ID = 0, string $event_status = ''): bool
2220
+	{
2221
+		// grab event id
2222
+		if (! $EVT_ID) {
2223
+			$msg = esc_html__(
2224
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2225
+				'event_espresso'
2226
+			);
2227
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2228
+			return false;
2229
+		}
2230
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2231
+		// clean status
2232
+		$event_status = sanitize_key($event_status);
2233
+		// grab status
2234
+		if (empty($event_status)) {
2235
+			$msg = esc_html__(
2236
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2237
+				'event_espresso'
2238
+			);
2239
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2240
+			return false;
2241
+		}
2242
+		// was event trashed or restored ?
2243
+		switch ($event_status) {
2244
+			case 'draft':
2245
+				$action = 'restored from the trash';
2246
+				$hook   = 'AHEE_event_restored_from_trash';
2247
+				break;
2248
+			case 'trash':
2249
+				$action = 'moved to the trash';
2250
+				$hook   = 'AHEE_event_moved_to_trash';
2251
+				break;
2252
+			default:
2253
+				$action = 'updated';
2254
+				$hook   = false;
2255
+		}
2256
+		// use class to change status
2257
+		$this->_cpt_model_obj->set_status($event_status);
2258
+		$success = $this->_cpt_model_obj->save();
2259
+		if (! $success) {
2260
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2261
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2262
+			return false;
2263
+		}
2264
+		if ($hook) {
2265
+			do_action($hook);
2266
+			// fake the action hook in EE_Soft_Delete_Base_Class::delete_or_restore()
2267
+			// because events side step that and it otherwise won't get called
2268
+			do_action(
2269
+				'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after',
2270
+				$this->_cpt_model_obj,
2271
+				$hook === 'AHEE_event_moved_to_trash',
2272
+				$success
2273
+			);
2274
+		}
2275
+		return true;
2276
+	}
2277
+
2278
+
2279
+	/**
2280
+	 * @param array $event_ids
2281
+	 * @return array
2282
+	 * @since   4.10.23.p
2283
+	 */
2284
+	private function cleanEventIds(array $event_ids): array
2285
+	{
2286
+		return array_map('absint', $event_ids);
2287
+	}
2288
+
2289
+
2290
+	/**
2291
+	 * @return array
2292
+	 * @since   4.10.23.p
2293
+	 */
2294
+	private function getEventIdsFromRequest(): array
2295
+	{
2296
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2297
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2298
+		} else {
2299
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2300
+		}
2301
+	}
2302
+
2303
+
2304
+	/**
2305
+	 * @param bool $preview_delete
2306
+	 * @throws EE_Error
2307
+	 * @throws ReflectionException
2308
+	 */
2309
+	protected function _delete_event(bool $preview_delete = true)
2310
+	{
2311
+		$this->_delete_events($preview_delete);
2312
+	}
2313
+
2314
+
2315
+	/**
2316
+	 * Gets the tree traversal batch persister.
2317
+	 *
2318
+	 * @return NodeGroupDao
2319
+	 * @throws InvalidArgumentException
2320
+	 * @throws InvalidDataTypeException
2321
+	 * @throws InvalidInterfaceException
2322
+	 * @since 4.10.12.p
2323
+	 */
2324
+	protected function getModelObjNodeGroupPersister(): NodeGroupDao
2325
+	{
2326
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2327
+			$this->model_obj_node_group_persister =
2328
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2329
+		}
2330
+		return $this->model_obj_node_group_persister;
2331
+	}
2332
+
2333
+
2334
+	/**
2335
+	 * @param bool $preview_delete
2336
+	 * @return void
2337
+	 * @throws EE_Error
2338
+	 * @throws ReflectionException
2339
+	 */
2340
+	protected function _delete_events(bool $preview_delete = true)
2341
+	{
2342
+		$event_ids = $this->getEventIdsFromRequest();
2343
+		if ($preview_delete) {
2344
+			$this->generateDeletionPreview($event_ids);
2345
+		} else {
2346
+			foreach ($event_ids as $event_id) {
2347
+				$event = EEM_Event::instance()->get_one_by_ID($event_id);
2348
+				if ($event instanceof EE_Event) {
2349
+					$event->delete_permanently();
2350
+				}
2351
+			}
2352
+		}
2353
+	}
2354
+
2355
+
2356
+	/**
2357
+	 * @param array $event_ids
2358
+	 */
2359
+	protected function generateDeletionPreview(array $event_ids)
2360
+	{
2361
+		$event_ids = $this->cleanEventIds($event_ids);
2362
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2363
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2364
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2365
+			[
2366
+				'action'            => 'preview_deletion',
2367
+				'deletion_job_code' => $deletion_job_code,
2368
+			],
2369
+			$this->_admin_base_url
2370
+		);
2371
+		EEH_URL::safeRedirectAndExit(
2372
+			EE_Admin_Page::add_query_args_and_nonce(
2373
+				[
2374
+					'page'              => EED_Batch::PAGE_SLUG,
2375
+					'batch'             => EED_Batch::batch_job,
2376
+					'EVT_IDs'           => $event_ids,
2377
+					'deletion_job_code' => $deletion_job_code,
2378
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2379
+					'return_url'        => urlencode($return_url),
2380
+				],
2381
+				admin_url()
2382
+			)
2383
+		);
2384
+	}
2385
+
2386
+
2387
+	/**
2388
+	 * Checks for a POST submission
2389
+	 *
2390
+	 * @since 4.10.12.p
2391
+	 */
2392
+	protected function confirmDeletion()
2393
+	{
2394
+		$deletion_redirect_logic = $this->getLoader()->getShared(
2395
+			'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'
2396
+		);
2397
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2398
+	}
2399
+
2400
+
2401
+	/**
2402
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2403
+	 *
2404
+	 * @throws EE_Error
2405
+	 * @since 4.10.12.p
2406
+	 */
2407
+	protected function previewDeletion()
2408
+	{
2409
+		$preview_deletion_logic = $this->getLoader()->getShared(
2410
+			'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'
2411
+		);
2412
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2413
+		$this->display_admin_page_with_no_sidebar();
2414
+	}
2415
+
2416
+
2417
+	/**
2418
+	 * get total number of events
2419
+	 *
2420
+	 * @access public
2421
+	 * @return int
2422
+	 * @throws EE_Error
2423
+	 * @throws EE_Error
2424
+	 * @throws ReflectionException
2425
+	 */
2426
+	public function total_events(): int
2427
+	{
2428
+		return EEM_Event::instance()->count(
2429
+			['caps' => 'read_admin'],
2430
+			'EVT_ID',
2431
+			true
2432
+		);
2433
+	}
2434
+
2435
+
2436
+	/**
2437
+	 * get total number of draft events
2438
+	 *
2439
+	 * @access public
2440
+	 * @return int
2441
+	 * @throws EE_Error
2442
+	 * @throws EE_Error
2443
+	 * @throws ReflectionException
2444
+	 */
2445
+	public function total_events_draft(): int
2446
+	{
2447
+		return EEM_Event::instance()->count(
2448
+			[
2449
+				['status' => ['IN', ['draft', 'auto-draft']]],
2450
+				'caps' => 'read_admin',
2451
+			],
2452
+			'EVT_ID',
2453
+			true
2454
+		);
2455
+	}
2456
+
2457
+
2458
+	/**
2459
+	 * get total number of trashed events
2460
+	 *
2461
+	 * @access public
2462
+	 * @return int
2463
+	 * @throws EE_Error
2464
+	 * @throws EE_Error
2465
+	 * @throws ReflectionException
2466
+	 */
2467
+	public function total_trashed_events(): int
2468
+	{
2469
+		return EEM_Event::instance()->count(
2470
+			[
2471
+				['status' => 'trash'],
2472
+				'caps' => 'read_admin',
2473
+			],
2474
+			'EVT_ID',
2475
+			true
2476
+		);
2477
+	}
2478
+
2479
+
2480
+	/**
2481
+	 *    _default_event_settings
2482
+	 *    This generates the Default Settings Tab
2483
+	 *
2484
+	 * @return void
2485
+	 * @throws DomainException
2486
+	 * @throws EE_Error
2487
+	 * @throws InvalidArgumentException
2488
+	 * @throws InvalidDataTypeException
2489
+	 * @throws InvalidInterfaceException
2490
+	 */
2491
+	protected function _default_event_settings()
2492
+	{
2493
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2494
+		$this->_set_publish_post_box_vars();
2495
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
2496
+			$this->_default_event_settings_form()->get_html(),
2497
+			'',
2498
+			'padding'
2499
+		);
2500
+		$this->display_admin_page_with_sidebar();
2501
+	}
2502
+
2503
+
2504
+	/**
2505
+	 * Return the form for event settings.
2506
+	 *
2507
+	 * @return EE_Form_Section_Proper
2508
+	 * @throws EE_Error
2509
+	 */
2510
+	protected function _default_event_settings_form(): EE_Form_Section_Proper
2511
+	{
2512
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2513
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2514
+		// exclude
2515
+			[
2516
+				EEM_Registration::status_id_cancelled,
2517
+				EEM_Registration::status_id_declined,
2518
+				EEM_Registration::status_id_incomplete,
2519
+				EEM_Registration::status_id_wait_list,
2520
+			],
2521
+			true
2522
+		);
2523
+		// setup Advanced Editor ???
2524
+		if (
2525
+			$this->raw_req_action === 'default_event_settings'
2526
+			|| $this->raw_req_action === 'update_default_event_settings'
2527
+		) {
2528
+			$this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2529
+		}
2530
+		return new EE_Form_Section_Proper(
2531
+			[
2532
+				'name'            => 'update_default_event_settings',
2533
+				'html_id'         => 'update_default_event_settings',
2534
+				'html_class'      => 'form-table',
2535
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2536
+				'subsections'     => apply_filters(
2537
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2538
+					[
2539
+						'defaults_section_header' => new EE_Form_Section_HTML(
2540
+							EEH_HTML::h2(
2541
+								esc_html__('Default Settings', 'event_espresso'),
2542
+								'',
2543
+								'ee-admin-settings-hdr'
2544
+							)
2545
+						),
2546
+						'default_reg_status'      => new EE_Select_Input(
2547
+							$registration_stati_for_selection,
2548
+							[
2549
+								'default'         => isset($registration_config->default_STS_ID)
2550
+													 && array_key_exists(
2551
+														 $registration_config->default_STS_ID,
2552
+														 $registration_stati_for_selection
2553
+													 )
2554
+									? sanitize_text_field($registration_config->default_STS_ID)
2555
+									: EEM_Registration::status_id_pending_payment,
2556
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2557
+													 . EEH_Template::get_help_tab_link(
2558
+														 'default_settings_status_help_tab'
2559
+													 ),
2560
+								'html_help_text'  => esc_html__(
2561
+									'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.',
2562
+									'event_espresso'
2563
+								),
2564
+							]
2565
+						),
2566
+						'default_max_tickets'     => new EE_Integer_Input(
2567
+							[
2568
+								'default'         => $registration_config->default_maximum_number_of_tickets
2569
+													 ?? EEM_Event::get_default_additional_limit(),
2570
+								'html_label_text' => esc_html__(
2571
+									'Default Maximum Tickets Allowed Per Order:',
2572
+									'event_espresso'
2573
+								)
2574
+													 . EEH_Template::get_help_tab_link(
2575
+														 'default_maximum_tickets_help_tab"'
2576
+													 ),
2577
+								'html_help_text'  => esc_html__(
2578
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2579
+									'event_espresso'
2580
+								),
2581
+							]
2582
+						),
2583
+					]
2584
+				),
2585
+			]
2586
+		);
2587
+	}
2588
+
2589
+
2590
+	/**
2591
+	 * @return void
2592
+	 * @throws EE_Error
2593
+	 * @throws InvalidArgumentException
2594
+	 * @throws InvalidDataTypeException
2595
+	 * @throws InvalidInterfaceException
2596
+	 */
2597
+	protected function _update_default_event_settings()
2598
+	{
2599
+		$form = $this->_default_event_settings_form();
2600
+		if ($form->was_submitted()) {
2601
+			$form->receive_form_submission();
2602
+			if ($form->is_valid()) {
2603
+				$registration_config = EE_Registry::instance()->CFG->registration;
2604
+				$valid_data          = $form->valid_data();
2605
+				if (isset($valid_data['default_reg_status'])) {
2606
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2607
+				}
2608
+				if (isset($valid_data['default_max_tickets'])) {
2609
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2610
+				}
2611
+				do_action(
2612
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2613
+					$valid_data,
2614
+					EE_Registry::instance()->CFG,
2615
+					$this
2616
+				);
2617
+				// update because data was valid!
2618
+				EE_Registry::instance()->CFG->update_espresso_config();
2619
+				EE_Error::overwrite_success();
2620
+				EE_Error::add_success(
2621
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2622
+				);
2623
+			}
2624
+		}
2625
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2626
+	}
2627
+
2628
+
2629
+	/*************        Templates        *************
23 2630
      *
24
-     * @var EE_Event $_event
25
-     */
26
-    protected $_event;
27
-
28
-
29
-    /**
30
-     * This will hold the category object for category_details screen.
31
-     *
32
-     * @var stdClass $_category
33
-     */
34
-    protected $_category;
35
-
36
-
37
-    /**
38
-     * This will hold the event model instance
39
-     *
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-
45
-    /**
46
-     * @var EE_Event
47
-     */
48
-    protected $_cpt_model_obj = false;
49
-
50
-
51
-    /**
52
-     * @var NodeGroupDao
53
-     */
54
-    protected $model_obj_node_group_persister;
55
-
56
-    /**
57
-     * @var AdvancedEditorAdminFormSection
58
-     */
59
-    protected $advanced_editor_admin_form;
60
-
61
-
62
-    /**
63
-     * Initialize page props for this admin page group.
64
-     */
65
-    protected function _init_page_props()
66
-    {
67
-        $this->page_slug        = EVENTS_PG_SLUG;
68
-        $this->page_label       = EVENTS_LABEL;
69
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
70
-        $this->_admin_base_path = EVENTS_ADMIN;
71
-        $this->_cpt_model_names = [
72
-            'create_new' => 'EEM_Event',
73
-            'edit'       => 'EEM_Event',
74
-        ];
75
-        $this->_cpt_edit_routes = [
76
-            'espresso_events' => 'edit',
77
-        ];
78
-        add_action(
79
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
80
-            [$this, 'verify_event_edit'],
81
-            10,
82
-            2
83
-        );
84
-    }
85
-
86
-
87
-    /**
88
-     * Sets the ajax hooks used for this admin page group.
89
-     */
90
-    protected function _ajax_hooks()
91
-    {
92
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
93
-    }
94
-
95
-
96
-    /**
97
-     * Sets the page properties for this admin page group.
98
-     */
99
-    protected function _define_page_props()
100
-    {
101
-        $event_id = $this->request->getRequestParam('post', 0, DataType::INT);
102
-        if ($event_id) {
103
-            $event_post = get_post($event_id);
104
-        }
105
-
106
-        $this->_admin_page_title = EVENTS_LABEL;
107
-        $this->_labels           = [
108
-            'buttons'      => [
109
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
110
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
111
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
112
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
113
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
114
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
115
-            ],
116
-            'editor_title' => [
117
-                'espresso_events' => isset($event_post) && $event_post instanceof WP_Post
118
-                    ? $event_post->post_title
119
-                    : esc_html__('Edit Event', 'event_espresso'),
120
-            ],
121
-            'publishbox'   => [
122
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
123
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
124
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
125
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
126
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
127
-            ],
128
-        ];
129
-    }
130
-
131
-
132
-    /**
133
-     * Sets the page routes property for this admin page group.
134
-     */
135
-    protected function _set_page_routes()
136
-    {
137
-        // load formatter helper
138
-        // load field generator helper
139
-        // is there a evt_id in the request?
140
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT);
141
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, DataType::INT);
142
-
143
-        $this->_page_routes = [
144
-            'default'                       => [
145
-                'func'       => [$this, '_events_overview_list_table'],
146
-                'capability' => 'ee_read_events',
147
-            ],
148
-            'create_new'                    => [
149
-                'func'       => [$this, '_create_new_cpt_item'],
150
-                'capability' => 'ee_edit_events',
151
-            ],
152
-            'edit'                          => [
153
-                'func'       => [$this, '_edit_cpt_item'],
154
-                'capability' => 'ee_edit_event',
155
-                'obj_id'     => $EVT_ID,
156
-            ],
157
-            'copy_event'                    => [
158
-                'func'       => [$this, '_copy_events'],
159
-                'capability' => 'ee_edit_event',
160
-                'obj_id'     => $EVT_ID,
161
-                'noheader'   => true,
162
-            ],
163
-            'trash_event'                   => [
164
-                'func'       => [$this, '_trash_or_restore_event'],
165
-                'args'       => ['event_status' => 'trash'],
166
-                'capability' => 'ee_delete_event',
167
-                'obj_id'     => $EVT_ID,
168
-                'noheader'   => true,
169
-            ],
170
-            'trash_events'                  => [
171
-                'func'       => [$this, '_trash_or_restore_events'],
172
-                'args'       => ['event_status' => 'trash'],
173
-                'capability' => 'ee_delete_events',
174
-                'noheader'   => true,
175
-            ],
176
-            'restore_event'                 => [
177
-                'func'       => [$this, '_trash_or_restore_event'],
178
-                'args'       => ['event_status' => 'draft'],
179
-                'capability' => 'ee_delete_event',
180
-                'obj_id'     => $EVT_ID,
181
-                'noheader'   => true,
182
-            ],
183
-            'restore_events'                => [
184
-                'func'       => [$this, '_trash_or_restore_events'],
185
-                'args'       => ['event_status' => 'draft'],
186
-                'capability' => 'ee_delete_events',
187
-                'noheader'   => true,
188
-            ],
189
-            'delete_event'                  => [
190
-                'func'       => [$this, '_delete_event'],
191
-                'capability' => 'ee_delete_event',
192
-                'obj_id'     => $EVT_ID,
193
-                'noheader'   => true,
194
-            ],
195
-            'delete_events'                 => [
196
-                'func'       => [$this, '_delete_events'],
197
-                'capability' => 'ee_delete_events',
198
-                'noheader'   => true,
199
-            ],
200
-            'view_report'                   => [
201
-                'func'       => [$this, '_view_report'],
202
-                'capability' => 'ee_edit_events',
203
-            ],
204
-            'default_event_settings'        => [
205
-                'func'       => [$this, '_default_event_settings'],
206
-                'capability' => 'manage_options',
207
-            ],
208
-            'update_default_event_settings' => [
209
-                'func'       => [$this, '_update_default_event_settings'],
210
-                'capability' => 'manage_options',
211
-                'noheader'   => true,
212
-            ],
213
-            'template_settings'             => [
214
-                'func'       => [$this, '_template_settings'],
215
-                'capability' => 'manage_options',
216
-            ],
217
-            // event category tab related
218
-            'add_category'                  => [
219
-                'func'       => [$this, '_category_details'],
220
-                'capability' => 'ee_edit_event_category',
221
-                'args'       => ['view' => 'add'],
222
-            ],
223
-            'edit_category'                 => [
224
-                'func'       => [$this, '_category_details'],
225
-                'capability' => 'ee_edit_event_category',
226
-                'args'       => ['view' => 'edit'],
227
-            ],
228
-            'delete_categories'             => [
229
-                'func'       => [$this, '_delete_categories'],
230
-                'capability' => 'ee_delete_event_category',
231
-                'noheader'   => true,
232
-            ],
233
-            'delete_category'               => [
234
-                'func'       => [$this, '_delete_categories'],
235
-                'capability' => 'ee_delete_event_category',
236
-                'noheader'   => true,
237
-            ],
238
-            'insert_category'               => [
239
-                'func'       => [$this, '_insert_or_update_category'],
240
-                'args'       => ['new_category' => true],
241
-                'capability' => 'ee_edit_event_category',
242
-                'noheader'   => true,
243
-            ],
244
-            'update_category'               => [
245
-                'func'       => [$this, '_insert_or_update_category'],
246
-                'args'       => ['new_category' => false],
247
-                'capability' => 'ee_edit_event_category',
248
-                'noheader'   => true,
249
-            ],
250
-            'category_list'                 => [
251
-                'func'       => [$this, '_category_list_table'],
252
-                'capability' => 'ee_manage_event_categories',
253
-            ],
254
-            'preview_deletion'              => [
255
-                'func'       => [$this, 'previewDeletion'],
256
-                'capability' => 'ee_delete_events',
257
-            ],
258
-            'confirm_deletion'              => [
259
-                'func'       => [$this, 'confirmDeletion'],
260
-                'capability' => 'ee_delete_events',
261
-                'noheader'   => true,
262
-            ],
263
-        ];
264
-    }
265
-
266
-
267
-    /**
268
-     * Set the _page_config property for this admin page group.
269
-     */
270
-    protected function _set_page_config()
271
-    {
272
-        $post_id            = $this->request->getRequestParam('post', 0, DataType::INT);
273
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
274
-        $this->_page_config = [
275
-            'default'                => [
276
-                'nav'           => [
277
-                    'label' => esc_html__('Overview', 'event_espresso'),
278
-                    'icon'  => 'dashicons-list-view',
279
-                    'order' => 10,
280
-                ],
281
-                'list_table'    => 'Events_Admin_List_Table',
282
-                'help_tabs'     => [
283
-                    'events_overview_help_tab'                       => [
284
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
285
-                        'filename' => 'events_overview',
286
-                    ],
287
-                    'events_overview_table_column_headings_help_tab' => [
288
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
289
-                        'filename' => 'events_overview_table_column_headings',
290
-                    ],
291
-                    'events_overview_filters_help_tab'               => [
292
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
293
-                        'filename' => 'events_overview_filters',
294
-                    ],
295
-                    'events_overview_view_help_tab'                  => [
296
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
297
-                        'filename' => 'events_overview_views',
298
-                    ],
299
-                    'events_overview_other_help_tab'                 => [
300
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
301
-                        'filename' => 'events_overview_other',
302
-                    ],
303
-                ],
304
-                'require_nonce' => false,
305
-            ],
306
-            'create_new'             => [
307
-                'nav'           => [
308
-                    'label'      => esc_html__('Add New Event', 'event_espresso'),
309
-                    'icon'       => 'dashicons-plus-alt',
310
-                    'order'      => 15,
311
-                    'persistent' => false,
312
-                ],
313
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
314
-                'help_tabs'     => [
315
-                    'event_editor_help_tab'                            => [
316
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
317
-                        'filename' => 'event_editor',
318
-                    ],
319
-                    'event_editor_title_richtexteditor_help_tab'       => [
320
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
321
-                        'filename' => 'event_editor_title_richtexteditor',
322
-                    ],
323
-                    'event_editor_venue_details_help_tab'              => [
324
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
325
-                        'filename' => 'event_editor_venue_details',
326
-                    ],
327
-                    'event_editor_event_datetimes_help_tab'            => [
328
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
329
-                        'filename' => 'event_editor_event_datetimes',
330
-                    ],
331
-                    'event_editor_event_tickets_help_tab'              => [
332
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
333
-                        'filename' => 'event_editor_event_tickets',
334
-                    ],
335
-                    'event_editor_event_registration_options_help_tab' => [
336
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
337
-                        'filename' => 'event_editor_event_registration_options',
338
-                    ],
339
-                    'event_editor_tags_categories_help_tab'            => [
340
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
341
-                        'filename' => 'event_editor_tags_categories',
342
-                    ],
343
-                    'event_editor_questions_registrants_help_tab'      => [
344
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
345
-                        'filename' => 'event_editor_questions_registrants',
346
-                    ],
347
-                    'event_editor_save_new_event_help_tab'             => [
348
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
349
-                        'filename' => 'event_editor_save_new_event',
350
-                    ],
351
-                    'event_editor_other_help_tab'                      => [
352
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
353
-                        'filename' => 'event_editor_other',
354
-                    ],
355
-                ],
356
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
357
-                'require_nonce' => false,
358
-            ],
359
-            'edit'                   => [
360
-                'nav'           => [
361
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
362
-                    'icon'       => 'dashicons-edit',
363
-                    'order'      => 15,
364
-                    'persistent' => false,
365
-                    'url'        => $post_id
366
-                        ? EE_Admin_Page::add_query_args_and_nonce(
367
-                            ['post' => $post_id, 'action' => 'edit'],
368
-                            $this->_current_page_view_url
369
-                        )
370
-                        : $this->_admin_base_url,
371
-                ],
372
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
373
-                'help_tabs'     => [
374
-                    'event_editor_help_tab'                            => [
375
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
376
-                        'filename' => 'event_editor',
377
-                    ],
378
-                    'event_editor_title_richtexteditor_help_tab'       => [
379
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
380
-                        'filename' => 'event_editor_title_richtexteditor',
381
-                    ],
382
-                    'event_editor_venue_details_help_tab'              => [
383
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
384
-                        'filename' => 'event_editor_venue_details',
385
-                    ],
386
-                    'event_editor_event_datetimes_help_tab'            => [
387
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
388
-                        'filename' => 'event_editor_event_datetimes',
389
-                    ],
390
-                    'event_editor_event_tickets_help_tab'              => [
391
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
392
-                        'filename' => 'event_editor_event_tickets',
393
-                    ],
394
-                    'event_editor_event_registration_options_help_tab' => [
395
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
396
-                        'filename' => 'event_editor_event_registration_options',
397
-                    ],
398
-                    'event_editor_tags_categories_help_tab'            => [
399
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
400
-                        'filename' => 'event_editor_tags_categories',
401
-                    ],
402
-                    'event_editor_questions_registrants_help_tab'      => [
403
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
404
-                        'filename' => 'event_editor_questions_registrants',
405
-                    ],
406
-                    'event_editor_save_new_event_help_tab'             => [
407
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
408
-                        'filename' => 'event_editor_save_new_event',
409
-                    ],
410
-                    'event_editor_other_help_tab'                      => [
411
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
412
-                        'filename' => 'event_editor_other',
413
-                    ],
414
-                ],
415
-                'require_nonce' => false,
416
-            ],
417
-            'default_event_settings' => [
418
-                'nav'           => [
419
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
420
-                    'icon'  => 'dashicons-admin-generic',
421
-                    'order' => 40,
422
-                ],
423
-                'metaboxes'     => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes),
424
-                'labels'        => [
425
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
426
-                ],
427
-                'help_tabs'     => [
428
-                    'default_settings_help_tab'        => [
429
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
430
-                        'filename' => 'events_default_settings',
431
-                    ],
432
-                    'default_settings_status_help_tab' => [
433
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
434
-                        'filename' => 'events_default_settings_status',
435
-                    ],
436
-                    'default_maximum_tickets_help_tab' => [
437
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
438
-                        'filename' => 'events_default_settings_max_tickets',
439
-                    ],
440
-                ],
441
-                'require_nonce' => false,
442
-            ],
443
-            // template settings
444
-            'template_settings'      => [
445
-                'nav'           => [
446
-                    'label' => esc_html__('Templates', 'event_espresso'),
447
-                    'icon'  => 'dashicons-layout',
448
-                    'order' => 30,
449
-                ],
450
-                'metaboxes'     => $this->_default_espresso_metaboxes,
451
-                'help_tabs'     => [
452
-                    'general_settings_templates_help_tab' => [
453
-                        'title'    => esc_html__('Templates', 'event_espresso'),
454
-                        'filename' => 'general_settings_templates',
455
-                    ],
456
-                ],
457
-                'require_nonce' => false,
458
-            ],
459
-            // event category stuff
460
-            'add_category'           => [
461
-                'nav'           => [
462
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
463
-                    'icon'       => 'dashicons-plus-alt',
464
-                    'order'      => 25,
465
-                    'persistent' => false,
466
-                ],
467
-                'help_tabs'     => [
468
-                    'add_category_help_tab' => [
469
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
470
-                        'filename' => 'events_add_category',
471
-                    ],
472
-                ],
473
-                'metaboxes'     => ['_publish_post_box'],
474
-                'require_nonce' => false,
475
-            ],
476
-            'edit_category'          => [
477
-                'nav'           => [
478
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
479
-                    'icon'       => 'dashicons-edit',
480
-                    'order'      => 25,
481
-                    'persistent' => false,
482
-                    'url'        => $EVT_CAT_ID
483
-                        ? add_query_arg(
484
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
485
-                            $this->_current_page_view_url
486
-                        )
487
-                        : $this->_admin_base_url,
488
-                ],
489
-                'help_tabs'     => [
490
-                    'edit_category_help_tab' => [
491
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
492
-                        'filename' => 'events_edit_category',
493
-                    ],
494
-                ],
495
-                'metaboxes'     => ['_publish_post_box'],
496
-                'require_nonce' => false,
497
-            ],
498
-            'category_list'          => [
499
-                'nav'           => [
500
-                    'label' => esc_html__('Categories', 'event_espresso'),
501
-                    'icon'  => 'dashicons-networking',
502
-                    'order' => 20,
503
-                ],
504
-                'list_table'    => 'Event_Categories_Admin_List_Table',
505
-                'help_tabs'     => [
506
-                    'events_categories_help_tab'                       => [
507
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
508
-                        'filename' => 'events_categories',
509
-                    ],
510
-                    'events_categories_table_column_headings_help_tab' => [
511
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
512
-                        'filename' => 'events_categories_table_column_headings',
513
-                    ],
514
-                    'events_categories_view_help_tab'                  => [
515
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
516
-                        'filename' => 'events_categories_views',
517
-                    ],
518
-                    'events_categories_other_help_tab'                 => [
519
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
520
-                        'filename' => 'events_categories_other',
521
-                    ],
522
-                ],
523
-                'metaboxes'     => $this->_default_espresso_metaboxes,
524
-                'require_nonce' => false,
525
-            ],
526
-            'preview_deletion'       => [
527
-                'nav'           => [
528
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
529
-                    'icon'       => 'dashicons-remove',
530
-                    'order'      => 15,
531
-                    'persistent' => false,
532
-                    'url'        => '',
533
-                ],
534
-                'require_nonce' => false,
535
-            ],
536
-        ];
537
-    }
538
-
539
-
540
-    /**
541
-     * Used to register any global screen options if necessary for every route in this admin page group.
542
-     */
543
-    protected function _add_screen_options()
544
-    {
545
-    }
546
-
547
-
548
-    /**
549
-     * Implementing the screen options for the 'default' route.
550
-     *
551
-     * @throws InvalidArgumentException
552
-     * @throws InvalidDataTypeException
553
-     * @throws InvalidInterfaceException
554
-     */
555
-    protected function _add_screen_options_default()
556
-    {
557
-        $this->_per_page_screen_option();
558
-    }
559
-
560
-
561
-    /**
562
-     * Implementing screen options for the category list route.
563
-     *
564
-     * @throws InvalidArgumentException
565
-     * @throws InvalidDataTypeException
566
-     * @throws InvalidInterfaceException
567
-     */
568
-    protected function _add_screen_options_category_list()
569
-    {
570
-        $page_title              = $this->_admin_page_title;
571
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
572
-        $this->_per_page_screen_option();
573
-        $this->_admin_page_title = $page_title;
574
-    }
575
-
576
-
577
-    /**
578
-     * Used to register any global feature pointers for the admin page group.
579
-     */
580
-    protected function _add_feature_pointers()
581
-    {
582
-    }
583
-
584
-
585
-    /**
586
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
587
-     */
588
-    public function load_scripts_styles()
589
-    {
590
-        wp_register_style(
591
-            'events-admin-css',
592
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
593
-            [],
594
-            EVENT_ESPRESSO_VERSION
595
-        );
596
-        wp_register_style(
597
-            'ee-cat-admin',
598
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
599
-            [],
600
-            EVENT_ESPRESSO_VERSION
601
-        );
602
-        wp_enqueue_style('events-admin-css');
603
-        wp_enqueue_style('ee-cat-admin');
604
-        // scripts
605
-        wp_register_script(
606
-            'event_editor_js',
607
-            EVENTS_ASSETS_URL . 'event_editor.js',
608
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
609
-            EVENT_ESPRESSO_VERSION,
610
-            true
611
-        );
612
-    }
613
-
614
-
615
-    /**
616
-     * Enqueuing scripts and styles specific to this view
617
-     */
618
-    public function load_scripts_styles_create_new()
619
-    {
620
-        $this->load_scripts_styles_edit();
621
-    }
622
-
623
-
624
-    /**
625
-     * Enqueuing scripts and styles specific to this view
626
-     */
627
-    public function load_scripts_styles_edit()
628
-    {
629
-        // styles
630
-        wp_enqueue_style('espresso-ui-theme');
631
-        wp_register_style(
632
-            'event-editor-css',
633
-            EVENTS_ASSETS_URL . 'event-editor.css',
634
-            ['ee-admin-css'],
635
-            EVENT_ESPRESSO_VERSION
636
-        );
637
-        wp_enqueue_style('event-editor-css');
638
-        // scripts
639
-        if (! $this->admin_config->useAdvancedEditor()) {
640
-            wp_register_script(
641
-                'event-datetime-metabox',
642
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
643
-                ['event_editor_js', 'ee-datepicker'],
644
-                EVENT_ESPRESSO_VERSION
645
-            );
646
-            wp_enqueue_script('event-datetime-metabox');
647
-        }
648
-    }
649
-
650
-
651
-    /**
652
-     * Populating the _views property for the category list table view.
653
-     */
654
-    protected function _set_list_table_views_category_list()
655
-    {
656
-        $this->_views = [
657
-            'all' => [
658
-                'slug'        => 'all',
659
-                'label'       => esc_html__('All', 'event_espresso'),
660
-                'count'       => 0,
661
-                'bulk_action' => [
662
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
663
-                ],
664
-            ],
665
-        ];
666
-    }
667
-
668
-
669
-    /**
670
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
671
-     */
672
-    public function admin_init()
673
-    {
674
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
675
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
676
-            'event_espresso'
677
-        );
678
-    }
679
-
680
-
681
-    /**
682
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
683
-     * group.
684
-     */
685
-    public function admin_notices()
686
-    {
687
-    }
688
-
689
-
690
-    /**
691
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
692
-     * this admin page group.
693
-     */
694
-    public function admin_footer_scripts()
695
-    {
696
-    }
697
-
698
-
699
-    /**
700
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
701
-     * warning (via EE_Error::add_error());
702
-     *
703
-     * @param EE_Event|null $event Event object
704
-     * @param string        $req_type
705
-     * @return void
706
-     * @throws EE_Error
707
-     * @throws ReflectionException
708
-     */
709
-    public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '')
710
-    {
711
-        // don't need to do this when processing
712
-        if (! empty($req_type)) {
713
-            return;
714
-        }
715
-        // no event?
716
-        if (! $event instanceof EE_Event) {
717
-            $event = $this->_cpt_model_obj;
718
-        }
719
-        // STILL no event?
720
-        if (! $event instanceof EE_Event) {
721
-            return;
722
-        }
723
-        // don't need to keep calling this
724
-        remove_action(
725
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
726
-            [$this, 'verify_event_edit']
727
-        );
728
-        $orig_status = $event->status();
729
-        // first check if event is active.
730
-        if (
731
-            $orig_status === EEM_Event::cancelled
732
-            || $orig_status === EEM_Event::postponed
733
-            || $event->is_expired()
734
-            || $event->is_inactive()
735
-        ) {
736
-            return;
737
-        }
738
-        // made it here so it IS active... next check that any of the tickets are sold.
739
-        if ($event->is_sold_out(true)) {
740
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
741
-                EE_Error::add_attention(
742
-                    sprintf(
743
-                        esc_html__(
744
-                            '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.',
745
-                            'event_espresso'
746
-                        ),
747
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
748
-                    )
749
-                );
750
-            }
751
-            return;
752
-        }
753
-        if ($orig_status === EEM_Event::sold_out) {
754
-            EE_Error::add_attention(
755
-                sprintf(
756
-                    esc_html__(
757
-                        '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.',
758
-                        'event_espresso'
759
-                    ),
760
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
761
-                )
762
-            );
763
-        }
764
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
765
-        if (! $event->tickets_on_sale()) {
766
-            return;
767
-        }
768
-        // made it here so show warning
769
-        $this->_edit_event_warning();
770
-    }
771
-
772
-
773
-    /**
774
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
775
-     * When needed, hook this into a EE_Error::add_error() notice.
776
-     *
777
-     * @access protected
778
-     * @return void
779
-     */
780
-    protected function _edit_event_warning()
781
-    {
782
-        // we don't want to add warnings during these requests
783
-        if ($this->request->getRequestParam('action') === 'editpost') {
784
-            return;
785
-        }
786
-        EE_Error::add_attention(
787
-            sprintf(
788
-                esc_html__(
789
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
790
-                    'event_espresso'
791
-                ),
792
-                '<a class="espresso-help-tab-lnk ee-help-tab-link">',
793
-                '</a>'
794
-            )
795
-        );
796
-    }
797
-
798
-
799
-    /**
800
-     * When a user is creating a new event, notify them if they haven't set their timezone.
801
-     * Otherwise, do the normal logic
802
-     *
803
-     * @return void
804
-     * @throws EE_Error
805
-     * @throws InvalidArgumentException
806
-     * @throws InvalidDataTypeException
807
-     * @throws InvalidInterfaceException
808
-     * @throws ReflectionException
809
-     */
810
-    protected function _create_new_cpt_item()
811
-    {
812
-        $has_timezone_string = get_option('timezone_string');
813
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
814
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
815
-            EE_Error::add_attention(
816
-                sprintf(
817
-                    esc_html__(
818
-                        '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',
819
-                        'event_espresso'
820
-                    ),
821
-                    '<br>',
822
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
823
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
824
-                    . '</select>',
825
-                    '<button class="button button--secondary timezone-submit">',
826
-                    '</button><span class="spinner"></span>'
827
-                ),
828
-                __FILE__,
829
-                __FUNCTION__,
830
-                __LINE__
831
-            );
832
-        }
833
-        parent::_create_new_cpt_item();
834
-    }
835
-
836
-
837
-    /**
838
-     * Sets the _views property for the default route in this admin page group.
839
-     */
840
-    protected function _set_list_table_views_default()
841
-    {
842
-        $this->_views = [
843
-            'all'   => [
844
-                'slug'        => 'all',
845
-                'label'       => esc_html__('View All Events', 'event_espresso'),
846
-                'count'       => 0,
847
-                'bulk_action' => [
848
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
849
-                ],
850
-            ],
851
-            'draft' => [
852
-                'slug'        => 'draft',
853
-                'label'       => esc_html__('Draft', 'event_espresso'),
854
-                'count'       => 0,
855
-                'bulk_action' => [
856
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
857
-                ],
858
-            ],
859
-        ];
860
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
861
-            $this->_views['trash'] = [
862
-                'slug'        => 'trash',
863
-                'label'       => esc_html__('Trash', 'event_espresso'),
864
-                'count'       => 0,
865
-                'bulk_action' => [
866
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
867
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
868
-                ],
869
-            ];
870
-        }
871
-    }
872
-
873
-
874
-    /**
875
-     * Provides the legend item array for the default list table view.
876
-     *
877
-     * @return array
878
-     * @throws EE_Error
879
-     * @throws EE_Error
880
-     */
881
-    protected function _event_legend_items(): array
882
-    {
883
-        $items    = [
884
-            'view_details'   => [
885
-                'class' => 'dashicons dashicons-visibility',
886
-                'desc'  => esc_html__('View Event', 'event_espresso'),
887
-            ],
888
-            'edit_event'     => [
889
-                'class' => 'dashicons dashicons-calendar-alt',
890
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
891
-            ],
892
-            'view_attendees' => [
893
-                'class' => 'dashicons dashicons-groups',
894
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
895
-            ],
896
-        ];
897
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
898
-        $statuses = [
899
-            'sold_out_status'  => [
900
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
901
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
902
-            ],
903
-            'active_status'    => [
904
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
905
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
906
-            ],
907
-            'upcoming_status'  => [
908
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
909
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
910
-            ],
911
-            'postponed_status' => [
912
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
913
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
914
-            ],
915
-            'cancelled_status' => [
916
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
917
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
918
-            ],
919
-            'expired_status'   => [
920
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
921
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
922
-            ],
923
-            'inactive_status'  => [
924
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
925
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
926
-            ],
927
-        ];
928
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
929
-        return array_merge($items, $statuses);
930
-    }
931
-
932
-
933
-    /**
934
-     * @return EEM_Event
935
-     * @throws EE_Error
936
-     * @throws InvalidArgumentException
937
-     * @throws InvalidDataTypeException
938
-     * @throws InvalidInterfaceException
939
-     * @throws ReflectionException
940
-     */
941
-    private function _event_model(): EEM_Event
942
-    {
943
-        if (! $this->_event_model instanceof EEM_Event) {
944
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
945
-        }
946
-        return $this->_event_model;
947
-    }
948
-
949
-
950
-    /**
951
-     * Adds extra buttons to the WP CPT permalink field row.
952
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
953
-     *
954
-     * @param string      $return    the current html
955
-     * @param int         $id        the post id for the page
956
-     * @param string|null $new_title What the title is
957
-     * @param string|null $new_slug  what the slug is
958
-     * @return string            The new html string for the permalink area
959
-     * @deprecated $VID:$
960
-     * @see TicketSelectorShortcodeButton::addButton
961
-     */
962
-    public function extra_permalink_field_buttons(
963
-        string $return,
964
-        int $id,
965
-        ?string $new_title,
966
-        ?string $new_slug
967
-    ): string {
968
-        return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug);
969
-    }
970
-
971
-
972
-    /**
973
-     * _events_overview_list_table
974
-     * This contains the logic for showing the events_overview list
975
-     *
976
-     * @access protected
977
-     * @return void
978
-     * @throws DomainException
979
-     * @throws EE_Error
980
-     * @throws InvalidArgumentException
981
-     * @throws InvalidDataTypeException
982
-     * @throws InvalidInterfaceException
983
-     */
984
-    protected function _events_overview_list_table()
985
-    {
986
-        $after_list_table = [];
987
-        $links_html       = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
988
-        $links_html       .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
989
-        $links_html       .= EEH_HTML::div(
990
-            EEH_Template::get_button_or_link(
991
-                get_post_type_archive_link('espresso_events'),
992
-                esc_html__('View Event Archive Page', 'event_espresso'),
993
-                'button button--small button--secondary'
994
-            ),
995
-            '',
996
-            'ee-admin-button-row ee-admin-button-row--align-start'
997
-        );
998
-        $links_html       .= EEH_HTML::divx();
999
-
1000
-        $after_list_table['view_event_list_button'] = $links_html;
1001
-
1002
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
1003
-        $this->_admin_page_title    .= ' ' . $this->get_action_link_or_button(
1004
-            'create_new',
1005
-            'add',
1006
-            [],
1007
-            'add-new-h2'
1008
-        );
1009
-
1010
-        $this->_template_args['after_list_table'] = array_merge(
1011
-            (array) $this->_template_args['after_list_table'],
1012
-            $after_list_table
1013
-        );
1014
-        $this->display_admin_list_table_page_with_no_sidebar();
1015
-    }
1016
-
1017
-
1018
-    /**
1019
-     * this allows for extra misc actions in the default WP publish box
1020
-     *
1021
-     * @return void
1022
-     * @throws DomainException
1023
-     * @throws EE_Error
1024
-     * @throws InvalidArgumentException
1025
-     * @throws InvalidDataTypeException
1026
-     * @throws InvalidInterfaceException
1027
-     * @throws ReflectionException
1028
-     */
1029
-    public function extra_misc_actions_publish_box()
1030
-    {
1031
-        $this->_generate_publish_box_extra_content();
1032
-    }
1033
-
1034
-
1035
-    /**
1036
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1037
-     * saved.
1038
-     * Typically you would use this to save any additional data.
1039
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1040
-     * ALSO very important.  When a post transitions from scheduled to published,
1041
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1042
-     * other meta saves. So MAKE sure that you handle this accordingly.
1043
-     *
1044
-     * @access protected
1045
-     * @abstract
1046
-     * @param string  $post_id The ID of the cpt that was saved (so you can link relationally)
1047
-     * @param WP_Post $post    The post object of the cpt that was saved.
1048
-     * @return void
1049
-     * @throws EE_Error
1050
-     * @throws InvalidArgumentException
1051
-     * @throws InvalidDataTypeException
1052
-     * @throws InvalidInterfaceException
1053
-     * @throws ReflectionException
1054
-     */
1055
-    protected function _insert_update_cpt_item($post_id, $post)
1056
-    {
1057
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1058
-            // get out we're not processing an event save.
1059
-            return;
1060
-        }
1061
-        $event_values = [
1062
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, DataType::BOOL),
1063
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, DataType::BOOL),
1064
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1065
-        ];
1066
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1067
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1068
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1069
-                'display_ticket_selector',
1070
-                false,
1071
-                'bool'
1072
-            );
1073
-            $event_values['EVT_additional_limit']            = min(
1074
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1075
-                $this->request->getRequestParam(
1076
-                    'additional_limit',
1077
-                    EEM_Event::get_default_additional_limit(),
1078
-                    'int'
1079
-                )
1080
-            );
1081
-            $event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1082
-                'EVT_default_registration_status',
1083
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1084
-            );
1085
-
1086
-            $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1087
-            $event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1088
-            $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, DataType::BOOL);
1089
-        } elseif ($post instanceof WP_Post) {
1090
-            $event_values['EVT_name'] = $post->post_title;
1091
-            $event_values['EVT_desc'] = $post->post_content;
1092
-        }
1093
-        // update event
1094
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1095
-        // get event_object for other metaboxes...
1096
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1097
-        // i have to setup where conditions to override the filters in the model
1098
-        // that filter out auto-draft and inherit statuses so we GET the inherit id!
1099
-        /** @var EE_Event $event */
1100
-        $event = $this->_event_model()->get_one(
1101
-            [
1102
-                [
1103
-                    $this->_event_model()->primary_key_name() => $post_id,
1104
-                    'OR'                                      => [
1105
-                        'status'   => $post->post_status,
1106
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1107
-                        // but the returned object here has a status of "publish", so use the original post status as well
1108
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1109
-                    ],
1110
-                ],
1111
-            ]
1112
-        );
1113
-
1114
-        // the following are default callbacks for event attachment updates
1115
-        // that can be overridden by caffeinated functionality and/or addons.
1116
-        $event_update_callbacks = [];
1117
-        if (! $this->admin_config->useAdvancedEditor()) {
1118
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1119
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1120
-        }
1121
-        $event_update_callbacks = apply_filters(
1122
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1123
-            $event_update_callbacks
1124
-        );
1125
-
1126
-        $att_success = true;
1127
-        foreach ($event_update_callbacks as $e_callback) {
1128
-            $_success = is_callable($e_callback)
1129
-                ? $e_callback($event, $this->request->requestParams())
1130
-                : false;
1131
-            // if ANY of these updates fail then we want the appropriate global error message
1132
-            $att_success = $_success !== false ? $att_success : false;
1133
-        }
1134
-        // any errors?
1135
-        if ($success && $att_success === false) {
1136
-            EE_Error::add_error(
1137
-                esc_html__(
1138
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1139
-                    'event_espresso'
1140
-                ),
1141
-                __FILE__,
1142
-                __FUNCTION__,
1143
-                __LINE__
1144
-            );
1145
-        } elseif ($success === false) {
1146
-            EE_Error::add_error(
1147
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1148
-                __FILE__,
1149
-                __FUNCTION__,
1150
-                __LINE__
1151
-            );
1152
-        }
1153
-    }
1154
-
1155
-
1156
-    /**
1157
-     * @param int $post_id
1158
-     * @param int $revision_id
1159
-     * @throws EE_Error
1160
-     * @throws EE_Error
1161
-     * @throws ReflectionException
1162
-     * @see parent::restore_item()
1163
-     */
1164
-    protected function _restore_cpt_item(int $post_id, int $revision_id)
1165
-    {
1166
-        // copy existing event meta to new post
1167
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1168
-        if ($post_evt instanceof EE_Event) {
1169
-            // meta revision restore
1170
-            $post_evt->restore_revision($revision_id);
1171
-            // related objs restore
1172
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1173
-        }
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * Attach the venue to the Event
1179
-     *
1180
-     * @param EE_Event $event Event Object to add the venue to
1181
-     * @param array    $data  The request data from the form
1182
-     * @return bool           Success or fail.
1183
-     * @throws EE_Error
1184
-     * @throws ReflectionException
1185
-     */
1186
-    protected function _default_venue_update(EE_Event $event, array $data): bool
1187
-    {
1188
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1189
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1190
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1191
-        // very important.  If we don't have a venue name...
1192
-        // then we'll get out because not necessary to create empty venue
1193
-        if (empty($data['venue_title'])) {
1194
-            return false;
1195
-        }
1196
-        $venue_array = [
1197
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1198
-            'VNU_name'            => $data['venue_title'],
1199
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1200
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1201
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1202
-                ? $data['venue_short_description']
1203
-                : null,
1204
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1205
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1206
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1207
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1208
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1209
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1210
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1211
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1212
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1213
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1214
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1215
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1216
-            'status'              => 'publish',
1217
-        ];
1218
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1219
-        if (! empty($venue_id)) {
1220
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1221
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1222
-            // we've gotta make sure that the venue is always attached to a revision..
1223
-            // add_relation_to should take care of making sure that the relation is already present.
1224
-            $event->_add_relation_to($venue_id, 'Venue');
1225
-            return $rows_affected > 0;
1226
-        }
1227
-        // we insert the venue
1228
-        $venue_id = $venue_model->insert($venue_array);
1229
-        $event->_add_relation_to($venue_id, 'Venue');
1230
-        return ! empty($venue_id);
1231
-        // when we have the ancestor come in it's already been handled by the revision save.
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1237
-     *
1238
-     * @param EE_Event $event The Event object we're attaching data to
1239
-     * @param array    $data  The request data from the form
1240
-     * @return array
1241
-     * @throws EE_Error
1242
-     * @throws ReflectionException
1243
-     * @throws Exception
1244
-     */
1245
-    protected function _default_tickets_update(EE_Event $event, array $data): array
1246
-    {
1247
-        if ($this->admin_config->useAdvancedEditor()) {
1248
-            return [];
1249
-        }
1250
-        $datetime       = null;
1251
-        $saved_tickets  = [];
1252
-        $event_timezone = $event->get_timezone();
1253
-        $date_formats   = ['Y-m-d', 'h:i a'];
1254
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1255
-            // trim all values to ensure any excess whitespace is removed.
1256
-            $datetime_data                = array_map('trim', $datetime_data);
1257
-            $datetime_data['DTT_EVT_end'] =
1258
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1259
-                    ? $datetime_data['DTT_EVT_end']
1260
-                    : $datetime_data['DTT_EVT_start'];
1261
-            $datetime_values              = [
1262
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1263
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1264
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1265
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1266
-                'DTT_order'     => $row,
1267
-            ];
1268
-            // if we have an id then let's get existing object first and then set the new values.
1269
-            //  Otherwise we instantiate a new object for save.
1270
-            if (! empty($datetime_data['DTT_ID'])) {
1271
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1272
-                if (! $datetime instanceof EE_Datetime) {
1273
-                    throw new RuntimeException(
1274
-                        sprintf(
1275
-                            esc_html__(
1276
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1277
-                                'event_espresso'
1278
-                            ),
1279
-                            $datetime_data['DTT_ID']
1280
-                        )
1281
-                    );
1282
-                }
1283
-                $datetime->set_date_format($date_formats[0]);
1284
-                $datetime->set_time_format($date_formats[1]);
1285
-                foreach ($datetime_values as $field => $value) {
1286
-                    $datetime->set($field, $value);
1287
-                }
1288
-            } else {
1289
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1290
-            }
1291
-            if (! $datetime instanceof EE_Datetime) {
1292
-                throw new RuntimeException(
1293
-                    sprintf(
1294
-                        esc_html__(
1295
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1296
-                            'event_espresso'
1297
-                        ),
1298
-                        print_r($datetime_values, true)
1299
-                    )
1300
-                );
1301
-            }
1302
-            // before going any further make sure our dates are setup correctly
1303
-            // so that the end date is always equal or greater than the start date.
1304
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1305
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1306
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1307
-            }
1308
-            $datetime->save();
1309
-            $event->_add_relation_to($datetime, 'Datetime');
1310
-        }
1311
-        // no datetimes get deleted so we don't do any of that logic here.
1312
-        // update tickets next
1313
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1314
-
1315
-        // set up some default start and end dates in case those are not present in the incoming data
1316
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1317
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1318
-        // use the start date of the first datetime for the end date
1319
-        $first_datetime   = $event->first_datetime();
1320
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1321
-
1322
-        // now process the incoming data
1323
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1324
-            $update_prices = false;
1325
-            $ticket_price  = $data['edit_prices'][ $row ][1]['PRC_amount'] ?? 0;
1326
-            // trim inputs to ensure any excess whitespace is removed.
1327
-            $ticket_data   = array_map('trim', $ticket_data);
1328
-            $ticket_values = [
1329
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1330
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1331
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1332
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1333
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1334
-                    ? $ticket_data['TKT_start_date']
1335
-                    : $default_start_date,
1336
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1337
-                    ? $ticket_data['TKT_end_date']
1338
-                    : $default_end_date,
1339
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1340
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1341
-                    ? $ticket_data['TKT_qty']
1342
-                    : EE_INF,
1343
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1344
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1345
-                    ? $ticket_data['TKT_uses']
1346
-                    : EE_INF,
1347
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1348
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1349
-                'TKT_order'       => $ticket_data['TKT_order'] ?? $row,
1350
-                'TKT_price'       => $ticket_price,
1351
-                'TKT_row'         => $row,
1352
-            ];
1353
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1354
-            // which means in turn that the prices will become new prices as well.
1355
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1356
-                $ticket_values['TKT_ID']         = 0;
1357
-                $ticket_values['TKT_is_default'] = 0;
1358
-                $update_prices                   = true;
1359
-            }
1360
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1361
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1362
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1363
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1364
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1365
-            if (! empty($ticket_data['TKT_ID'])) {
1366
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1367
-                if (! $existing_ticket instanceof EE_Ticket) {
1368
-                    throw new RuntimeException(
1369
-                        sprintf(
1370
-                            esc_html__(
1371
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1372
-                                'event_espresso'
1373
-                            ),
1374
-                            $ticket_data['TKT_ID']
1375
-                        )
1376
-                    );
1377
-                }
1378
-                $ticket_sold = $existing_ticket->count_related(
1379
-                    'Registration',
1380
-                    [
1381
-                            [
1382
-                                'STS_ID' => [
1383
-                                    'NOT IN',
1384
-                                    [EEM_Registration::status_id_incomplete],
1385
-                                ],
1386
-                            ],
1387
-                        ]
1388
-                ) > 0;
1389
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1390
-                // if they are different then we create a new ticket (if $ticket_sold)
1391
-                // if they aren't different then we go ahead and modify existing ticket.
1392
-                $create_new_ticket = $ticket_sold
1393
-                                     && $ticket_price !== $existing_ticket->price()
1394
-                                     && ! $existing_ticket->deleted();
1395
-                $existing_ticket->set_date_format($date_formats[0]);
1396
-                $existing_ticket->set_time_format($date_formats[1]);
1397
-                // set new values
1398
-                foreach ($ticket_values as $field => $value) {
1399
-                    if ($field == 'TKT_qty') {
1400
-                        $existing_ticket->set_qty($value);
1401
-                    } elseif ($field == 'TKT_price') {
1402
-                        $existing_ticket->set('TKT_price', $ticket_price);
1403
-                    } else {
1404
-                        $existing_ticket->set($field, $value);
1405
-                    }
1406
-                }
1407
-                $ticket = $existing_ticket;
1408
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1409
-                //  Otherwise we have to create a new ticket.
1410
-                if ($create_new_ticket) {
1411
-                    // archive the old ticket first
1412
-                    $existing_ticket->set('TKT_deleted', 1);
1413
-                    $existing_ticket->save();
1414
-                    // make sure this ticket is still recorded in our $saved_tickets
1415
-                    // so we don't run it through the regular trash routine.
1416
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1417
-                    // create new ticket that's a copy of the existing except,
1418
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1419
-                    $new_ticket = clone $existing_ticket;
1420
-                    $new_ticket->set('TKT_ID', 0);
1421
-                    $new_ticket->set('TKT_deleted', 0);
1422
-                    $new_ticket->set('TKT_sold', 0);
1423
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1424
-                    $update_prices = true;
1425
-                    $ticket        = $new_ticket;
1426
-                }
1427
-            } else {
1428
-                // no TKT_id so a new ticket
1429
-                $ticket_values['TKT_price'] = $ticket_price;
1430
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1431
-                $update_prices              = true;
1432
-            }
1433
-            if (! $ticket instanceof EE_Ticket) {
1434
-                throw new RuntimeException(
1435
-                    sprintf(
1436
-                        esc_html__(
1437
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1438
-                            'event_espresso'
1439
-                        ),
1440
-                        print_r($ticket_values, true)
1441
-                    )
1442
-                );
1443
-            }
1444
-            // cap ticket qty by datetime reg limits
1445
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1446
-            // update ticket.
1447
-            $ticket->save();
1448
-            // before going any further make sure our dates are setup correctly
1449
-            // so that the end date is always equal or greater than the start date.
1450
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1451
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1452
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1453
-                $ticket->save();
1454
-            }
1455
-            // initially let's add the ticket to the datetime
1456
-            $datetime->_add_relation_to($ticket, 'Ticket');
1457
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1458
-            // add prices to ticket
1459
-            $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1460
-                ? $data['edit_prices'][ $row ]
1461
-                : [];
1462
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1463
-        }
1464
-        // however now we need to handle permanently deleting tickets via the ui.
1465
-        // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1466
-        // However, it does allow for deleting tickets that have no tickets sold,
1467
-        // in which case we want to get rid of permanently because there is no need to save in db.
1468
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1469
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1470
-        foreach ($tickets_removed as $id) {
1471
-            $id = absint($id);
1472
-            // get the ticket for this id
1473
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1474
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1475
-                continue;
1476
-            }
1477
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1478
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1479
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1480
-            foreach ($related_datetimes as $related_datetime) {
1481
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1482
-            }
1483
-            // need to do the same for prices (except these prices can also be deleted because again,
1484
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1485
-            $ticket_to_remove->delete_related_permanently('Price');
1486
-            // finally let's delete this ticket
1487
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1488
-            $ticket_to_remove->delete_permanently();
1489
-        }
1490
-        return [$datetime, $saved_tickets];
1491
-    }
1492
-
1493
-
1494
-    /**
1495
-     * This attaches a list of given prices to a ticket.
1496
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1497
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1498
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1499
-     *
1500
-     * @access  private
1501
-     * @param array     $prices_data Array of prices from the form.
1502
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1503
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1504
-     * @return  void
1505
-     * @throws EE_Error
1506
-     * @throws ReflectionException
1507
-     */
1508
-    private function _add_prices_to_ticket(array $prices_data, EE_Ticket $ticket, bool $new_prices = false)
1509
-    {
1510
-        $timezone = $ticket->get_timezone();
1511
-        foreach ($prices_data as $row => $price_data) {
1512
-            $price_values = [
1513
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1514
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1515
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1516
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1517
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1518
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1519
-                'PRC_order'      => $row,
1520
-            ];
1521
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1522
-                $price_values['PRC_ID'] = 0;
1523
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1524
-            } else {
1525
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1526
-                // update this price with new values
1527
-                foreach ($price_values as $field => $new_price) {
1528
-                    $price->set($field, $new_price);
1529
-                }
1530
-            }
1531
-            if (! $price instanceof EE_Price) {
1532
-                throw new RuntimeException(
1533
-                    sprintf(
1534
-                        esc_html__(
1535
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1536
-                            'event_espresso'
1537
-                        ),
1538
-                        print_r($price_values, true)
1539
-                    )
1540
-                );
1541
-            }
1542
-            $price->save();
1543
-            $ticket->_add_relation_to($price, 'Price');
1544
-        }
1545
-    }
1546
-
1547
-
1548
-    /**
1549
-     * Add in our autosave ajax handlers
1550
-     *
1551
-     */
1552
-    protected function _ee_autosave_create_new()
1553
-    {
1554
-    }
1555
-
1556
-
1557
-    /**
1558
-     * More autosave handlers.
1559
-     */
1560
-    protected function _ee_autosave_edit()
1561
-    {
1562
-    }
1563
-
1564
-
1565
-    /**
1566
-     * @throws EE_Error
1567
-     * @throws ReflectionException
1568
-     */
1569
-    private function _generate_publish_box_extra_content()
1570
-    {
1571
-        // load formatter helper
1572
-        // args for getting related registrations
1573
-        $approved_query_args        = [
1574
-            [
1575
-                'REG_deleted' => 0,
1576
-                'STS_ID'      => EEM_Registration::status_id_approved,
1577
-            ],
1578
-        ];
1579
-        $not_approved_query_args    = [
1580
-            [
1581
-                'REG_deleted' => 0,
1582
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1583
-            ],
1584
-        ];
1585
-        $pending_payment_query_args = [
1586
-            [
1587
-                'REG_deleted' => 0,
1588
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1589
-            ],
1590
-        ];
1591
-        // publish box
1592
-        $publish_box_extra_args = [
1593
-            'view_approved_reg_url'        => add_query_arg(
1594
-                [
1595
-                    'action'      => 'default',
1596
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1597
-                    '_reg_status' => EEM_Registration::status_id_approved,
1598
-                    'use_filters' => true,
1599
-                ],
1600
-                REG_ADMIN_URL
1601
-            ),
1602
-            'view_not_approved_reg_url'    => add_query_arg(
1603
-                [
1604
-                    'action'      => 'default',
1605
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1606
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1607
-                    'use_filters' => true,
1608
-                ],
1609
-                REG_ADMIN_URL
1610
-            ),
1611
-            'view_pending_payment_reg_url' => add_query_arg(
1612
-                [
1613
-                    'action'      => 'default',
1614
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1615
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1616
-                    'use_filters' => true,
1617
-                ],
1618
-                REG_ADMIN_URL
1619
-            ),
1620
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1621
-                'Registration',
1622
-                $approved_query_args
1623
-            ),
1624
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1625
-                'Registration',
1626
-                $not_approved_query_args
1627
-            ),
1628
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1629
-                'Registration',
1630
-                $pending_payment_query_args
1631
-            ),
1632
-            'misc_pub_section_class'       => apply_filters(
1633
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1634
-                'misc-pub-section'
1635
-            ),
1636
-        ];
1637
-        ob_start();
1638
-        do_action(
1639
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1640
-            $this->_cpt_model_obj
1641
-        );
1642
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1643
-        // load template
1644
-        EEH_Template::display_template(
1645
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1646
-            $publish_box_extra_args
1647
-        );
1648
-    }
1649
-
1650
-
1651
-    /**
1652
-     * @return EE_Event
1653
-     */
1654
-    public function get_event_object()
1655
-    {
1656
-        return $this->_cpt_model_obj;
1657
-    }
1658
-
1659
-
1660
-
1661
-
1662
-    /** METABOXES * */
1663
-    /**
1664
-     * _register_event_editor_meta_boxes
1665
-     * add all metaboxes related to the event_editor
1666
-     *
1667
-     * @return void
1668
-     * @throws EE_Error
1669
-     * @throws ReflectionException
1670
-     */
1671
-    protected function _register_event_editor_meta_boxes()
1672
-    {
1673
-        $this->verify_cpt_object();
1674
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1675
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1676
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1677
-            $this->addMetaBox(
1678
-                'espresso_event_editor_event_options',
1679
-                esc_html__('Event Registration Options', 'event_espresso'),
1680
-                [$this, 'registration_options_meta_box'],
1681
-                $this->page_slug,
1682
-                'side'
1683
-            );
1684
-        }
1685
-        if (! $use_advanced_editor) {
1686
-            $this->addMetaBox(
1687
-                'espresso_event_editor_tickets',
1688
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1689
-                [$this, 'ticket_metabox'],
1690
-                $this->page_slug,
1691
-                'normal',
1692
-                'high'
1693
-            );
1694
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1695
-            add_action(
1696
-                'add_meta_boxes_espresso_events',
1697
-                function () {
1698
-                    global $current_screen;
1699
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1700
-                },
1701
-                99
1702
-            );
1703
-        }
1704
-        // NOTE: if you're looking for other metaboxes in here,
1705
-        // where a metabox has a related management page in the admin
1706
-        // you will find it setup in the related management page's "_Hooks" file.
1707
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1708
-    }
1709
-
1710
-
1711
-    /**
1712
-     * @throws DomainException
1713
-     * @throws EE_Error
1714
-     * @throws ReflectionException
1715
-     */
1716
-    public function ticket_metabox()
1717
-    {
1718
-        $existing_datetime_ids = $existing_ticket_ids = [];
1719
-        // defaults for template args
1720
-        $template_args = [
1721
-            'ticket_rows'       => '',
1722
-            'total_ticket_rows' => 1,
1723
-            'trash_icon'        => 'dashicons dashicons-lock',
1724
-            'disabled'          => '',
1725
-        ];
1726
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1727
-        /**
1728
-         * 1. Start with retrieving Datetimes
1729
-         * 2. Fore each datetime get related tickets
1730
-         * 3. For each ticket get related prices
1731
-         */
1732
-        /** @var EEM_Datetime $datetime_model */
1733
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1734
-        /** @var EEM_Ticket $datetime_model */
1735
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1736
-        $times        = $datetime_model->get_all_event_dates($event_id);
1737
-        /** @type EE_Datetime $first_datetime */
1738
-        $first_datetime = reset($times);
1739
-        // do we get related tickets?
1740
-        if (
1741
-            $first_datetime instanceof EE_Datetime
1742
-            && $first_datetime->ID() !== 0
1743
-        ) {
1744
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1745
-            $template_args['time']   = $first_datetime;
1746
-            $related_tickets         = $first_datetime->tickets(
1747
-                [
1748
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1749
-                    'default_where_conditions' => 'none',
1750
-                ]
1751
-            );
1752
-            if (! empty($related_tickets)) {
1753
-                $template_args['total_ticket_rows'] = count($related_tickets);
1754
-                $row                                = 0;
1755
-                foreach ($related_tickets as $ticket) {
1756
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1757
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1758
-                    $row++;
1759
-                }
1760
-            } else {
1761
-                $template_args['total_ticket_rows'] = 1;
1762
-                /** @type EE_Ticket $ticket */
1763
-                $ticket                       = $ticket_model->create_default_object();
1764
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1765
-            }
1766
-        } else {
1767
-            $template_args['time'] = $times[0];
1768
-            /** @type EE_Ticket[] $tickets */
1769
-            $tickets                      = $ticket_model->get_all_default_tickets();
1770
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1771
-            // NOTE: we're just sending the first default row
1772
-            // (decaf can't manage default tickets so this should be sufficient);
1773
-        }
1774
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1775
-            'event_editor_event_datetimes_help_tab'
1776
-        );
1777
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1778
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1779
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1780
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1781
-            $ticket_model->create_default_object(),
1782
-            true
1783
-        );
1784
-        $template                                  = apply_filters(
1785
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1786
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1787
-        );
1788
-        EEH_Template::display_template($template, $template_args);
1789
-    }
1790
-
1791
-
1792
-    /**
1793
-     * Setup an individual ticket form for the decaf event editor page
1794
-     *
1795
-     * @access private
1796
-     * @param EE_Ticket $ticket   the ticket object
1797
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1798
-     * @param int       $row
1799
-     * @return string generated html for the ticket row.
1800
-     * @throws EE_Error
1801
-     * @throws ReflectionException
1802
-     */
1803
-    private function _get_ticket_row(EE_Ticket $ticket, bool $skeleton = false, int $row = 0): string
1804
-    {
1805
-        $template_args = [
1806
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1807
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1808
-                : '',
1809
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1810
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1811
-            'TKT_name'            => $ticket->get('TKT_name'),
1812
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1813
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1814
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1815
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1816
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1817
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1818
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1819
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1820
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1821
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1822
-                : ' disabled=disabled',
1823
-        ];
1824
-        $price         = $ticket->ID() !== 0
1825
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1826
-            : null;
1827
-        $price         = $price instanceof EE_Price
1828
-            ? $price
1829
-            : EEM_Price::instance()->create_default_object();
1830
-        $price_args    = [
1831
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1832
-            'PRC_amount'            => $price->get('PRC_amount'),
1833
-            'PRT_ID'                => $price->get('PRT_ID'),
1834
-            'PRC_ID'                => $price->get('PRC_ID'),
1835
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1836
-        ];
1837
-        // make sure we have default start and end dates if skeleton
1838
-        // handle rows that should NOT be empty
1839
-        if (empty($template_args['TKT_start_date'])) {
1840
-            // if empty then the start date will be now.
1841
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1842
-        }
1843
-        if (empty($template_args['TKT_end_date'])) {
1844
-            // get the earliest datetime (if present);
1845
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1846
-                ? $this->_cpt_model_obj->get_first_related(
1847
-                    'Datetime',
1848
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1849
-                )
1850
-                : null;
1851
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1852
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1853
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1854
-        }
1855
-        $template_args = array_merge($template_args, $price_args);
1856
-        $template      = apply_filters(
1857
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1858
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1859
-            $ticket
1860
-        );
1861
-        return EEH_Template::display_template($template, $template_args, true);
1862
-    }
1863
-
1864
-
1865
-    /**
1866
-     * @throws EE_Error
1867
-     * @throws ReflectionException
1868
-     */
1869
-    public function registration_options_meta_box()
1870
-    {
1871
-        $yes_no_values             = [
1872
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1873
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1874
-        ];
1875
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1876
-            [
1877
-                EEM_Registration::status_id_cancelled,
1878
-                EEM_Registration::status_id_declined,
1879
-                EEM_Registration::status_id_incomplete,
1880
-            ],
1881
-            true
1882
-        );
1883
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1884
-        $template_args['_event']                          = $this->_cpt_model_obj;
1885
-        $template_args['event']                           = $this->_cpt_model_obj;
1886
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1887
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1888
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1889
-            'default_reg_status',
1890
-            $default_reg_status_values,
1891
-            $this->_cpt_model_obj->default_registration_status()
1892
-        );
1893
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1894
-            'display_desc',
1895
-            $yes_no_values,
1896
-            $this->_cpt_model_obj->display_description()
1897
-        );
1898
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1899
-            'display_ticket_selector',
1900
-            $yes_no_values,
1901
-            $this->_cpt_model_obj->display_ticket_selector(),
1902
-            '',
1903
-            '',
1904
-            false
1905
-        );
1906
-        $template_args['additional_registration_options'] = apply_filters(
1907
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1908
-            '',
1909
-            $template_args,
1910
-            $yes_no_values,
1911
-            $default_reg_status_values
1912
-        );
1913
-        EEH_Template::display_template(
1914
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1915
-            $template_args
1916
-        );
1917
-    }
1918
-
1919
-
1920
-    /**
1921
-     * _get_events()
1922
-     * This method simply returns all the events (for the given _view and paging)
1923
-     *
1924
-     * @access public
1925
-     * @param int  $per_page     count of items per page (20 default);
1926
-     * @param int  $current_page what is the current page being viewed.
1927
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1928
-     *                           If FALSE then we return an array of event objects
1929
-     *                           that match the given _view and paging parameters.
1930
-     * @return array|int         an array of event objects or a count of them.
1931
-     * @throws Exception
1932
-     */
1933
-    public function get_events(int $per_page = 10, int $current_page = 1, bool $count = false)
1934
-    {
1935
-        $EEM_Event   = $this->_event_model();
1936
-        $offset      = ($current_page - 1) * $per_page;
1937
-        $limit       = $count ? null : $offset . ',' . $per_page;
1938
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1939
-        $order       = $this->request->getRequestParam('order', 'DESC');
1940
-        $month_range = $this->request->getRequestParam('month_range');
1941
-        if ($month_range) {
1942
-            $pieces = explode(' ', $month_range, 3);
1943
-            // simulate the FIRST day of the month, that fixes issues for months like February
1944
-            // where PHP doesn't know what to assume for date.
1945
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1946
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1947
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1948
-        }
1949
-        $where  = [];
1950
-        $status = $this->request->getRequestParam('status');
1951
-        // determine what post_status our condition will have for the query.
1952
-        switch ($status) {
1953
-            case 'month':
1954
-            case 'today':
1955
-            case null:
1956
-            case 'all':
1957
-                break;
1958
-            case 'draft':
1959
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1960
-                break;
1961
-            default:
1962
-                $where['status'] = $status;
1963
-        }
1964
-        // categories? The default for all categories is -1
1965
-        $category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INT);
1966
-        if ($category !== -1) {
1967
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1968
-            $where['Term_Taxonomy.term_id']  = $category;
1969
-        }
1970
-        // date where conditions
1971
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1972
-        if ($month_range) {
1973
-            $DateTime = new DateTime(
1974
-                $year_r . '-' . $month_r . '-01 00:00:00',
1975
-                new DateTimeZone('UTC')
1976
-            );
1977
-            $start    = $DateTime->getTimestamp();
1978
-            // set the datetime to be the end of the month
1979
-            $DateTime->setDate(
1980
-                $year_r,
1981
-                $month_r,
1982
-                $DateTime->format('t')
1983
-            )->setTime(23, 59, 59);
1984
-            $end                             = $DateTime->getTimestamp();
1985
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
-        } elseif ($status === 'today') {
1987
-            $DateTime                        =
1988
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1989
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1990
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1991
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1992
-        } elseif ($status === 'month') {
1993
-            $now                             = date('Y-m-01');
1994
-            $DateTime                        =
1995
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1996
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1997
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1998
-                                                        ->setTime(23, 59, 59)
1999
-                                                        ->format(implode(' ', $start_formats));
2000
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2001
-        }
2002
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2003
-            $where['EVT_wp_user'] = get_current_user_id();
2004
-        } else {
2005
-            if (! isset($where['status'])) {
2006
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
2007
-                    $where['OR'] = [
2008
-                        'status*restrict_private' => ['!=', 'private'],
2009
-                        'AND'                     => [
2010
-                            'status*inclusive' => ['=', 'private'],
2011
-                            'EVT_wp_user'      => get_current_user_id(),
2012
-                        ],
2013
-                    ];
2014
-                }
2015
-            }
2016
-        }
2017
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, DataType::INT);
2018
-        if (
2019
-            $wp_user
2020
-            && $wp_user !== get_current_user_id()
2021
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2022
-        ) {
2023
-            $where['EVT_wp_user'] = $wp_user;
2024
-        }
2025
-        // search query handling
2026
-        $search_term = $this->request->getRequestParam('s');
2027
-        if ($search_term) {
2028
-            $search_term = '%' . $search_term . '%';
2029
-            $where['OR'] = [
2030
-                'EVT_name'       => ['LIKE', $search_term],
2031
-                'EVT_desc'       => ['LIKE', $search_term],
2032
-                'EVT_short_desc' => ['LIKE', $search_term],
2033
-            ];
2034
-        }
2035
-        // filter events by venue.
2036
-        $venue = $this->request->getRequestParam('venue', 0, DataType::INT);
2037
-        if ($venue) {
2038
-            $where['Venue.VNU_ID'] = $venue;
2039
-        }
2040
-        $request_params = $this->request->requestParams();
2041
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2042
-        $query_params   = apply_filters(
2043
-            'FHEE__Events_Admin_Page__get_events__query_params',
2044
-            [
2045
-                $where,
2046
-                'limit'    => $limit,
2047
-                'order_by' => $orderby,
2048
-                'order'    => $order,
2049
-                'group_by' => 'EVT_ID',
2050
-            ],
2051
-            $request_params
2052
-        );
2053
-
2054
-        // let's first check if we have special requests coming in.
2055
-        $active_status = $this->request->getRequestParam('active_status');
2056
-        if ($active_status) {
2057
-            switch ($active_status) {
2058
-                case 'upcoming':
2059
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
2060
-                case 'expired':
2061
-                    return $EEM_Event->get_expired_events($query_params, $count);
2062
-                case 'active':
2063
-                    return $EEM_Event->get_active_events($query_params, $count);
2064
-                case 'inactive':
2065
-                    return $EEM_Event->get_inactive_events($query_params, $count);
2066
-            }
2067
-        }
2068
-
2069
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2070
-    }
2071
-
2072
-
2073
-    /**
2074
-     * handling for WordPress CPT actions (trash, restore, delete)
2075
-     *
2076
-     * @param string $post_id
2077
-     * @throws EE_Error
2078
-     * @throws ReflectionException
2079
-     */
2080
-    public function trash_cpt_item($post_id)
2081
-    {
2082
-        $this->request->setRequestParam('EVT_ID', $post_id);
2083
-        $this->_trash_or_restore_event('trash', false);
2084
-    }
2085
-
2086
-
2087
-    /**
2088
-     * @param string $post_id
2089
-     * @throws EE_Error
2090
-     * @throws ReflectionException
2091
-     */
2092
-    public function restore_cpt_item($post_id)
2093
-    {
2094
-        $this->request->setRequestParam('EVT_ID', $post_id);
2095
-        $this->_trash_or_restore_event('draft', false);
2096
-    }
2097
-
2098
-
2099
-    /**
2100
-     * @param string $post_id
2101
-     * @throws EE_Error
2102
-     * @throws EE_Error
2103
-     */
2104
-    public function delete_cpt_item($post_id)
2105
-    {
2106
-        throw new EE_Error(
2107
-            esc_html__(
2108
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2109
-                'event_espresso'
2110
-            )
2111
-        );
2112
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2113
-        // $this->_delete_event();
2114
-    }
2115
-
2116
-
2117
-    /**
2118
-     * _trash_or_restore_event
2119
-     *
2120
-     * @access protected
2121
-     * @param string $event_status
2122
-     * @param bool   $redirect_after
2123
-     * @throws EE_Error
2124
-     * @throws EE_Error
2125
-     * @throws ReflectionException
2126
-     */
2127
-    protected function _trash_or_restore_event(string $event_status = 'trash', bool $redirect_after = true)
2128
-    {
2129
-        // determine the event id and set to array.
2130
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT);
2131
-        // loop thru events
2132
-        if ($EVT_ID) {
2133
-            // clean status
2134
-            $event_status = sanitize_key($event_status);
2135
-            // grab status
2136
-            if (! empty($event_status)) {
2137
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2138
-            } else {
2139
-                $success = false;
2140
-                $msg     = esc_html__(
2141
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2142
-                    'event_espresso'
2143
-                );
2144
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2145
-            }
2146
-        } else {
2147
-            $success = false;
2148
-            $msg     = esc_html__(
2149
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2150
-                'event_espresso'
2151
-            );
2152
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2153
-        }
2154
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2155
-        if ($redirect_after) {
2156
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2157
-        }
2158
-    }
2159
-
2160
-
2161
-    /**
2162
-     * _trash_or_restore_events
2163
-     *
2164
-     * @access protected
2165
-     * @param string $event_status
2166
-     * @return void
2167
-     * @throws EE_Error
2168
-     * @throws EE_Error
2169
-     * @throws ReflectionException
2170
-     */
2171
-    protected function _trash_or_restore_events(string $event_status = 'trash')
2172
-    {
2173
-        // clean status
2174
-        $event_status = sanitize_key($event_status);
2175
-        // grab status
2176
-        if (! empty($event_status)) {
2177
-            $success = true;
2178
-            // determine the event id and set to array.
2179
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2180
-            // loop thru events
2181
-            foreach ($EVT_IDs as $EVT_ID) {
2182
-                if ($EVT_ID = absint($EVT_ID)) {
2183
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2184
-                    $success = $results !== false ? $success : false;
2185
-                } else {
2186
-                    $msg = sprintf(
2187
-                        esc_html__(
2188
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2189
-                            'event_espresso'
2190
-                        ),
2191
-                        $EVT_ID
2192
-                    );
2193
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2194
-                    $success = false;
2195
-                }
2196
-            }
2197
-        } else {
2198
-            $success = false;
2199
-            $msg     = esc_html__(
2200
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2201
-                'event_espresso'
2202
-            );
2203
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2204
-        }
2205
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2206
-        $success = $success ? 2 : false;
2207
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2208
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2209
-    }
2210
-
2211
-
2212
-    /**
2213
-     * @param int    $EVT_ID
2214
-     * @param string $event_status
2215
-     * @return bool
2216
-     * @throws EE_Error
2217
-     * @throws ReflectionException
2218
-     */
2219
-    private function _change_event_status(int $EVT_ID = 0, string $event_status = ''): bool
2220
-    {
2221
-        // grab event id
2222
-        if (! $EVT_ID) {
2223
-            $msg = esc_html__(
2224
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2225
-                'event_espresso'
2226
-            );
2227
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2228
-            return false;
2229
-        }
2230
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2231
-        // clean status
2232
-        $event_status = sanitize_key($event_status);
2233
-        // grab status
2234
-        if (empty($event_status)) {
2235
-            $msg = esc_html__(
2236
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2237
-                'event_espresso'
2238
-            );
2239
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2240
-            return false;
2241
-        }
2242
-        // was event trashed or restored ?
2243
-        switch ($event_status) {
2244
-            case 'draft':
2245
-                $action = 'restored from the trash';
2246
-                $hook   = 'AHEE_event_restored_from_trash';
2247
-                break;
2248
-            case 'trash':
2249
-                $action = 'moved to the trash';
2250
-                $hook   = 'AHEE_event_moved_to_trash';
2251
-                break;
2252
-            default:
2253
-                $action = 'updated';
2254
-                $hook   = false;
2255
-        }
2256
-        // use class to change status
2257
-        $this->_cpt_model_obj->set_status($event_status);
2258
-        $success = $this->_cpt_model_obj->save();
2259
-        if (! $success) {
2260
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2261
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2262
-            return false;
2263
-        }
2264
-        if ($hook) {
2265
-            do_action($hook);
2266
-            // fake the action hook in EE_Soft_Delete_Base_Class::delete_or_restore()
2267
-            // because events side step that and it otherwise won't get called
2268
-            do_action(
2269
-                'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after',
2270
-                $this->_cpt_model_obj,
2271
-                $hook === 'AHEE_event_moved_to_trash',
2272
-                $success
2273
-            );
2274
-        }
2275
-        return true;
2276
-    }
2277
-
2278
-
2279
-    /**
2280
-     * @param array $event_ids
2281
-     * @return array
2282
-     * @since   4.10.23.p
2283
-     */
2284
-    private function cleanEventIds(array $event_ids): array
2285
-    {
2286
-        return array_map('absint', $event_ids);
2287
-    }
2288
-
2289
-
2290
-    /**
2291
-     * @return array
2292
-     * @since   4.10.23.p
2293
-     */
2294
-    private function getEventIdsFromRequest(): array
2295
-    {
2296
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2297
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2298
-        } else {
2299
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2300
-        }
2301
-    }
2302
-
2303
-
2304
-    /**
2305
-     * @param bool $preview_delete
2306
-     * @throws EE_Error
2307
-     * @throws ReflectionException
2308
-     */
2309
-    protected function _delete_event(bool $preview_delete = true)
2310
-    {
2311
-        $this->_delete_events($preview_delete);
2312
-    }
2313
-
2314
-
2315
-    /**
2316
-     * Gets the tree traversal batch persister.
2317
-     *
2318
-     * @return NodeGroupDao
2319
-     * @throws InvalidArgumentException
2320
-     * @throws InvalidDataTypeException
2321
-     * @throws InvalidInterfaceException
2322
-     * @since 4.10.12.p
2323
-     */
2324
-    protected function getModelObjNodeGroupPersister(): NodeGroupDao
2325
-    {
2326
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2327
-            $this->model_obj_node_group_persister =
2328
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2329
-        }
2330
-        return $this->model_obj_node_group_persister;
2331
-    }
2332
-
2333
-
2334
-    /**
2335
-     * @param bool $preview_delete
2336
-     * @return void
2337
-     * @throws EE_Error
2338
-     * @throws ReflectionException
2339
-     */
2340
-    protected function _delete_events(bool $preview_delete = true)
2341
-    {
2342
-        $event_ids = $this->getEventIdsFromRequest();
2343
-        if ($preview_delete) {
2344
-            $this->generateDeletionPreview($event_ids);
2345
-        } else {
2346
-            foreach ($event_ids as $event_id) {
2347
-                $event = EEM_Event::instance()->get_one_by_ID($event_id);
2348
-                if ($event instanceof EE_Event) {
2349
-                    $event->delete_permanently();
2350
-                }
2351
-            }
2352
-        }
2353
-    }
2354
-
2355
-
2356
-    /**
2357
-     * @param array $event_ids
2358
-     */
2359
-    protected function generateDeletionPreview(array $event_ids)
2360
-    {
2361
-        $event_ids = $this->cleanEventIds($event_ids);
2362
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2363
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2364
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2365
-            [
2366
-                'action'            => 'preview_deletion',
2367
-                'deletion_job_code' => $deletion_job_code,
2368
-            ],
2369
-            $this->_admin_base_url
2370
-        );
2371
-        EEH_URL::safeRedirectAndExit(
2372
-            EE_Admin_Page::add_query_args_and_nonce(
2373
-                [
2374
-                    'page'              => EED_Batch::PAGE_SLUG,
2375
-                    'batch'             => EED_Batch::batch_job,
2376
-                    'EVT_IDs'           => $event_ids,
2377
-                    'deletion_job_code' => $deletion_job_code,
2378
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2379
-                    'return_url'        => urlencode($return_url),
2380
-                ],
2381
-                admin_url()
2382
-            )
2383
-        );
2384
-    }
2385
-
2386
-
2387
-    /**
2388
-     * Checks for a POST submission
2389
-     *
2390
-     * @since 4.10.12.p
2391
-     */
2392
-    protected function confirmDeletion()
2393
-    {
2394
-        $deletion_redirect_logic = $this->getLoader()->getShared(
2395
-            'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'
2396
-        );
2397
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2398
-    }
2399
-
2400
-
2401
-    /**
2402
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2403
-     *
2404
-     * @throws EE_Error
2405
-     * @since 4.10.12.p
2406
-     */
2407
-    protected function previewDeletion()
2408
-    {
2409
-        $preview_deletion_logic = $this->getLoader()->getShared(
2410
-            'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'
2411
-        );
2412
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2413
-        $this->display_admin_page_with_no_sidebar();
2414
-    }
2415
-
2416
-
2417
-    /**
2418
-     * get total number of events
2419
-     *
2420
-     * @access public
2421
-     * @return int
2422
-     * @throws EE_Error
2423
-     * @throws EE_Error
2424
-     * @throws ReflectionException
2425
-     */
2426
-    public function total_events(): int
2427
-    {
2428
-        return EEM_Event::instance()->count(
2429
-            ['caps' => 'read_admin'],
2430
-            'EVT_ID',
2431
-            true
2432
-        );
2433
-    }
2434
-
2435
-
2436
-    /**
2437
-     * get total number of draft events
2438
-     *
2439
-     * @access public
2440
-     * @return int
2441
-     * @throws EE_Error
2442
-     * @throws EE_Error
2443
-     * @throws ReflectionException
2444
-     */
2445
-    public function total_events_draft(): int
2446
-    {
2447
-        return EEM_Event::instance()->count(
2448
-            [
2449
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2450
-                'caps' => 'read_admin',
2451
-            ],
2452
-            'EVT_ID',
2453
-            true
2454
-        );
2455
-    }
2456
-
2457
-
2458
-    /**
2459
-     * get total number of trashed events
2460
-     *
2461
-     * @access public
2462
-     * @return int
2463
-     * @throws EE_Error
2464
-     * @throws EE_Error
2465
-     * @throws ReflectionException
2466
-     */
2467
-    public function total_trashed_events(): int
2468
-    {
2469
-        return EEM_Event::instance()->count(
2470
-            [
2471
-                ['status' => 'trash'],
2472
-                'caps' => 'read_admin',
2473
-            ],
2474
-            'EVT_ID',
2475
-            true
2476
-        );
2477
-    }
2478
-
2479
-
2480
-    /**
2481
-     *    _default_event_settings
2482
-     *    This generates the Default Settings Tab
2483
-     *
2484
-     * @return void
2485
-     * @throws DomainException
2486
-     * @throws EE_Error
2487
-     * @throws InvalidArgumentException
2488
-     * @throws InvalidDataTypeException
2489
-     * @throws InvalidInterfaceException
2490
-     */
2491
-    protected function _default_event_settings()
2492
-    {
2493
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2494
-        $this->_set_publish_post_box_vars();
2495
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
2496
-            $this->_default_event_settings_form()->get_html(),
2497
-            '',
2498
-            'padding'
2499
-        );
2500
-        $this->display_admin_page_with_sidebar();
2501
-    }
2502
-
2503
-
2504
-    /**
2505
-     * Return the form for event settings.
2506
-     *
2507
-     * @return EE_Form_Section_Proper
2508
-     * @throws EE_Error
2509
-     */
2510
-    protected function _default_event_settings_form(): EE_Form_Section_Proper
2511
-    {
2512
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2513
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2514
-        // exclude
2515
-            [
2516
-                EEM_Registration::status_id_cancelled,
2517
-                EEM_Registration::status_id_declined,
2518
-                EEM_Registration::status_id_incomplete,
2519
-                EEM_Registration::status_id_wait_list,
2520
-            ],
2521
-            true
2522
-        );
2523
-        // setup Advanced Editor ???
2524
-        if (
2525
-            $this->raw_req_action === 'default_event_settings'
2526
-            || $this->raw_req_action === 'update_default_event_settings'
2527
-        ) {
2528
-            $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2529
-        }
2530
-        return new EE_Form_Section_Proper(
2531
-            [
2532
-                'name'            => 'update_default_event_settings',
2533
-                'html_id'         => 'update_default_event_settings',
2534
-                'html_class'      => 'form-table',
2535
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2536
-                'subsections'     => apply_filters(
2537
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2538
-                    [
2539
-                        'defaults_section_header' => new EE_Form_Section_HTML(
2540
-                            EEH_HTML::h2(
2541
-                                esc_html__('Default Settings', 'event_espresso'),
2542
-                                '',
2543
-                                'ee-admin-settings-hdr'
2544
-                            )
2545
-                        ),
2546
-                        'default_reg_status'      => new EE_Select_Input(
2547
-                            $registration_stati_for_selection,
2548
-                            [
2549
-                                'default'         => isset($registration_config->default_STS_ID)
2550
-                                                     && array_key_exists(
2551
-                                                         $registration_config->default_STS_ID,
2552
-                                                         $registration_stati_for_selection
2553
-                                                     )
2554
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2555
-                                    : EEM_Registration::status_id_pending_payment,
2556
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2557
-                                                     . EEH_Template::get_help_tab_link(
2558
-                                                         'default_settings_status_help_tab'
2559
-                                                     ),
2560
-                                'html_help_text'  => esc_html__(
2561
-                                    '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.',
2562
-                                    'event_espresso'
2563
-                                ),
2564
-                            ]
2565
-                        ),
2566
-                        'default_max_tickets'     => new EE_Integer_Input(
2567
-                            [
2568
-                                'default'         => $registration_config->default_maximum_number_of_tickets
2569
-                                                     ?? EEM_Event::get_default_additional_limit(),
2570
-                                'html_label_text' => esc_html__(
2571
-                                    'Default Maximum Tickets Allowed Per Order:',
2572
-                                    'event_espresso'
2573
-                                )
2574
-                                                     . EEH_Template::get_help_tab_link(
2575
-                                                         'default_maximum_tickets_help_tab"'
2576
-                                                     ),
2577
-                                'html_help_text'  => esc_html__(
2578
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2579
-                                    'event_espresso'
2580
-                                ),
2581
-                            ]
2582
-                        ),
2583
-                    ]
2584
-                ),
2585
-            ]
2586
-        );
2587
-    }
2588
-
2589
-
2590
-    /**
2591
-     * @return void
2592
-     * @throws EE_Error
2593
-     * @throws InvalidArgumentException
2594
-     * @throws InvalidDataTypeException
2595
-     * @throws InvalidInterfaceException
2596
-     */
2597
-    protected function _update_default_event_settings()
2598
-    {
2599
-        $form = $this->_default_event_settings_form();
2600
-        if ($form->was_submitted()) {
2601
-            $form->receive_form_submission();
2602
-            if ($form->is_valid()) {
2603
-                $registration_config = EE_Registry::instance()->CFG->registration;
2604
-                $valid_data          = $form->valid_data();
2605
-                if (isset($valid_data['default_reg_status'])) {
2606
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2607
-                }
2608
-                if (isset($valid_data['default_max_tickets'])) {
2609
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2610
-                }
2611
-                do_action(
2612
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2613
-                    $valid_data,
2614
-                    EE_Registry::instance()->CFG,
2615
-                    $this
2616
-                );
2617
-                // update because data was valid!
2618
-                EE_Registry::instance()->CFG->update_espresso_config();
2619
-                EE_Error::overwrite_success();
2620
-                EE_Error::add_success(
2621
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2622
-                );
2623
-            }
2624
-        }
2625
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2626
-    }
2627
-
2628
-
2629
-    /*************        Templates        *************
2630
-     *
2631
-     * @throws EE_Error
2632
-     */
2633
-    protected function _template_settings()
2634
-    {
2635
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2636
-        $this->_template_args['preview_img']  = '<img src="'
2637
-                                                . EVENTS_ASSETS_URL
2638
-                                                . '/images/'
2639
-                                                . 'caffeinated_template_features.jpg" alt="'
2640
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2641
-                                                . '" />';
2642
-        $this->_template_args['preview_text'] = '<strong>'
2643
-                                                . esc_html__(
2644
-                                                    '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.',
2645
-                                                    'event_espresso'
2646
-                                                ) . '</strong>';
2647
-        $this->display_admin_caf_preview_page('template_settings_tab');
2648
-    }
2649
-
2650
-
2651
-    /** Event Category Stuff **/
2652
-    /**
2653
-     * set the _category property with the category object for the loaded page.
2654
-     *
2655
-     * @access private
2656
-     * @return void
2657
-     */
2658
-    private function _set_category_object()
2659
-    {
2660
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2661
-            return;
2662
-        } //already have the category object so get out.
2663
-        // set default category object
2664
-        $this->_set_empty_category_object();
2665
-        // only set if we've got an id
2666
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
2667
-        if (! $category_ID) {
2668
-            return;
2669
-        }
2670
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2671
-        if (! empty($term)) {
2672
-            $this->_category->category_name       = $term->name;
2673
-            $this->_category->category_identifier = $term->slug;
2674
-            $this->_category->category_desc       = $term->description;
2675
-            $this->_category->id                  = $term->term_id;
2676
-            $this->_category->parent              = $term->parent;
2677
-        }
2678
-    }
2679
-
2680
-
2681
-    /**
2682
-     * Clears out category properties.
2683
-     */
2684
-    private function _set_empty_category_object()
2685
-    {
2686
-        $this->_category                = new stdClass();
2687
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2688
-        $this->_category->id            = $this->_category->parent = 0;
2689
-    }
2690
-
2691
-
2692
-    /**
2693
-     * @throws DomainException
2694
-     * @throws EE_Error
2695
-     * @throws InvalidArgumentException
2696
-     * @throws InvalidDataTypeException
2697
-     * @throws InvalidInterfaceException
2698
-     */
2699
-    protected function _category_list_table()
2700
-    {
2701
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2702
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2703
-        $this->_admin_page_title .= ' ';
2704
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2705
-            'add_category',
2706
-            'add_category',
2707
-            [],
2708
-            'add-new-h2'
2709
-        );
2710
-        $this->display_admin_list_table_page_with_sidebar();
2711
-    }
2712
-
2713
-
2714
-    /**
2715
-     * Output category details view.
2716
-     *
2717
-     * @throws EE_Error
2718
-     * @throws EE_Error
2719
-     */
2720
-    protected function _category_details($view)
2721
-    {
2722
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2723
-        $this->_set_add_edit_form_tags($route);
2724
-        $this->_set_category_object();
2725
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2726
-        $delete_action = 'delete_category';
2727
-        // custom redirect
2728
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2729
-            ['action' => 'category_list'],
2730
-            $this->_admin_base_url
2731
-        );
2732
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect, true);
2733
-        // take care of contents
2734
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2735
-        $this->display_admin_page_with_sidebar();
2736
-    }
2737
-
2738
-
2739
-    /**
2740
-     * Output category details content.
2741
-     *
2742
-     * @throws DomainException
2743
-     */
2744
-    protected function _category_details_content(): string
2745
-    {
2746
-        $editor_args['category_desc'] = [
2747
-            'type'          => 'wp_editor',
2748
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2749
-            'class'         => 'my_editor_custom',
2750
-            'wpeditor_args' => ['media_buttons' => false],
2751
-        ];
2752
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2753
-        $all_terms                    = get_terms(
2754
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2755
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2756
-        );
2757
-        // setup category select for term parents.
2758
-        $category_select_values[] = [
2759
-            'text' => esc_html__('No Parent', 'event_espresso'),
2760
-            'id'   => 0,
2761
-        ];
2762
-        foreach ($all_terms as $term) {
2763
-            $category_select_values[] = [
2764
-                'text' => $term->name,
2765
-                'id'   => $term->term_id,
2766
-            ];
2767
-        }
2768
-        $category_select = EEH_Form_Fields::select_input(
2769
-            'category_parent',
2770
-            $category_select_values,
2771
-            $this->_category->parent
2772
-        );
2773
-        $template_args   = [
2774
-            'category'                 => $this->_category,
2775
-            'category_select'          => $category_select,
2776
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2777
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2778
-            'disable'                  => '',
2779
-            'disabled_message'         => false,
2780
-        ];
2781
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2782
-        return EEH_Template::display_template($template, $template_args, true);
2783
-    }
2784
-
2785
-
2786
-    /**
2787
-     * Handles deleting categories.
2788
-     *
2789
-     * @throws EE_Error
2790
-     */
2791
-    protected function _delete_categories()
2792
-    {
2793
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2794
-        foreach ($category_IDs as $category_ID) {
2795
-            $this->_delete_category($category_ID);
2796
-        }
2797
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2798
-        $query_args = [
2799
-            'action' => 'category_list',
2800
-        ];
2801
-        $this->_redirect_after_action(0, '', '', $query_args);
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * Handles deleting specific category.
2807
-     *
2808
-     * @param int $cat_id
2809
-     */
2810
-    protected function _delete_category(int $cat_id)
2811
-    {
2812
-        $cat_id = absint($cat_id);
2813
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2814
-    }
2815
-
2816
-
2817
-    /**
2818
-     * Handles triggering the update or insertion of a new category.
2819
-     *
2820
-     * @param bool $new_category true means we're triggering the insert of a new category.
2821
-     * @throws EE_Error
2822
-     * @throws EE_Error
2823
-     */
2824
-    protected function _insert_or_update_category(bool $new_category)
2825
-    {
2826
-        $cat_id  = $this->_insert_category($new_category);
2827
-        $success = 0; // we already have a success message so lets not send another.
2828
-        if ($cat_id) {
2829
-            $query_args = [
2830
-                'action'     => 'edit_category',
2831
-                'EVT_CAT_ID' => $cat_id,
2832
-            ];
2833
-        } else {
2834
-            $query_args = ['action' => 'add_category'];
2835
-        }
2836
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2837
-    }
2838
-
2839
-
2840
-    /**
2841
-     * Inserts or updates category
2842
-     *
2843
-     * @param bool $new_category (true indicates we're updating a category).
2844
-     * @return bool|mixed|string
2845
-     */
2846
-    private function _insert_category(bool $new_category)
2847
-    {
2848
-        $category_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
2849
-        $category_name       = $this->request->getRequestParam('category_name', '');
2850
-        $category_desc       = $this->request->getRequestParam('category_desc', '', DataType::HTML);
2851
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, DataType::INT);
2852
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2853
-
2854
-        if (empty($category_name)) {
2855
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2856
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2857
-            return 0;
2858
-        }
2859
-        $term_args = [
2860
-            'name'        => $category_name,
2861
-            'description' => $category_desc,
2862
-            'parent'      => $category_parent,
2863
-        ];
2864
-        // was the category_identifier input disabled?
2865
-        if ($category_identifier) {
2866
-            $term_args['slug'] = $category_identifier;
2867
-        }
2868
-        $insert_ids = $new_category
2869
-            ? wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2870
-            : wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2871
-
2872
-        if ($insert_ids instanceof WP_Error) {
2873
-            EE_Error::add_error($insert_ids->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
2874
-            return 0;
2875
-        }
2876
-        $category_ID = $insert_ids['term_id'] ?? 0;
2877
-        if (! $category_ID) {
2878
-            EE_Error::add_error(
2879
-                esc_html__(
2880
-                    'An error occurred and the category has not been saved to the database.',
2881
-                    'event_espresso'
2882
-                ),
2883
-                __FILE__,
2884
-                __FUNCTION__,
2885
-                __LINE__
2886
-            );
2887
-            return 0;
2888
-        }
2889
-        EE_Error::add_success(
2890
-            sprintf(
2891
-                esc_html__('The category %s was successfully saved', 'event_espresso'),
2892
-                $category_name
2893
-            )
2894
-        );
2895
-        return $category_ID;
2896
-    }
2897
-
2898
-
2899
-    /**
2900
-     * Gets categories or count of categories matching the arguments in the request.
2901
-     *
2902
-     * @param int  $per_page
2903
-     * @param int  $current_page
2904
-     * @param bool $count
2905
-     * @return EE_Term_Taxonomy[]|int
2906
-     * @throws EE_Error
2907
-     * @throws ReflectionException
2908
-     */
2909
-    public function get_categories(int $per_page = 10, int $current_page = 1, bool $count = false)
2910
-    {
2911
-        // testing term stuff
2912
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2913
-        $order       = $this->request->getRequestParam('order', 'DESC');
2914
-        $limit       = ($current_page - 1) * $per_page;
2915
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2916
-        $search_term = $this->request->getRequestParam('s');
2917
-        if ($search_term) {
2918
-            $search_term = '%' . $search_term . '%';
2919
-            $where['OR'] = [
2920
-                'Term.name'   => ['LIKE', $search_term],
2921
-                'description' => ['LIKE', $search_term],
2922
-            ];
2923
-        }
2924
-        $query_params = [
2925
-            $where,
2926
-            'order_by'   => [$orderby => $order],
2927
-            'limit'      => $limit . ',' . $per_page,
2928
-            'force_join' => ['Term'],
2929
-        ];
2930
-        return $count
2931
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2932
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2933
-    }
2934
-
2935
-    /* end category stuff */
2936
-
2937
-
2938
-    /**************/
2939
-
2940
-
2941
-    /**
2942
-     * Callback for the `ee_save_timezone_setting` ajax action.
2943
-     *
2944
-     * @throws EE_Error
2945
-     * @throws InvalidArgumentException
2946
-     * @throws InvalidDataTypeException
2947
-     * @throws InvalidInterfaceException
2948
-     */
2949
-    public function saveTimezoneString()
2950
-    {
2951
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2952
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2953
-            EE_Error::add_error(
2954
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2955
-                __FILE__,
2956
-                __FUNCTION__,
2957
-                __LINE__
2958
-            );
2959
-            $this->_template_args['error'] = true;
2960
-            $this->_return_json();
2961
-        }
2962
-
2963
-        update_option('timezone_string', $timezone_string);
2964
-        EE_Error::add_success(
2965
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2966
-        );
2967
-        $this->_template_args['success'] = true;
2968
-        $this->_return_json(true, ['action' => 'create_new']);
2969
-    }
2970
-
2971
-
2972
-    /**
2973 2631
      * @throws EE_Error
2974
-     * @deprecated 4.10.25.p
2975 2632
      */
2976
-    public function save_timezonestring_setting()
2977
-    {
2978
-        $this->saveTimezoneString();
2979
-    }
2633
+	protected function _template_settings()
2634
+	{
2635
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2636
+		$this->_template_args['preview_img']  = '<img src="'
2637
+												. EVENTS_ASSETS_URL
2638
+												. '/images/'
2639
+												. 'caffeinated_template_features.jpg" alt="'
2640
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2641
+												. '" />';
2642
+		$this->_template_args['preview_text'] = '<strong>'
2643
+												. esc_html__(
2644
+													'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.',
2645
+													'event_espresso'
2646
+												) . '</strong>';
2647
+		$this->display_admin_caf_preview_page('template_settings_tab');
2648
+	}
2649
+
2650
+
2651
+	/** Event Category Stuff **/
2652
+	/**
2653
+	 * set the _category property with the category object for the loaded page.
2654
+	 *
2655
+	 * @access private
2656
+	 * @return void
2657
+	 */
2658
+	private function _set_category_object()
2659
+	{
2660
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2661
+			return;
2662
+		} //already have the category object so get out.
2663
+		// set default category object
2664
+		$this->_set_empty_category_object();
2665
+		// only set if we've got an id
2666
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
2667
+		if (! $category_ID) {
2668
+			return;
2669
+		}
2670
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2671
+		if (! empty($term)) {
2672
+			$this->_category->category_name       = $term->name;
2673
+			$this->_category->category_identifier = $term->slug;
2674
+			$this->_category->category_desc       = $term->description;
2675
+			$this->_category->id                  = $term->term_id;
2676
+			$this->_category->parent              = $term->parent;
2677
+		}
2678
+	}
2679
+
2680
+
2681
+	/**
2682
+	 * Clears out category properties.
2683
+	 */
2684
+	private function _set_empty_category_object()
2685
+	{
2686
+		$this->_category                = new stdClass();
2687
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2688
+		$this->_category->id            = $this->_category->parent = 0;
2689
+	}
2690
+
2691
+
2692
+	/**
2693
+	 * @throws DomainException
2694
+	 * @throws EE_Error
2695
+	 * @throws InvalidArgumentException
2696
+	 * @throws InvalidDataTypeException
2697
+	 * @throws InvalidInterfaceException
2698
+	 */
2699
+	protected function _category_list_table()
2700
+	{
2701
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2702
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2703
+		$this->_admin_page_title .= ' ';
2704
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2705
+			'add_category',
2706
+			'add_category',
2707
+			[],
2708
+			'add-new-h2'
2709
+		);
2710
+		$this->display_admin_list_table_page_with_sidebar();
2711
+	}
2712
+
2713
+
2714
+	/**
2715
+	 * Output category details view.
2716
+	 *
2717
+	 * @throws EE_Error
2718
+	 * @throws EE_Error
2719
+	 */
2720
+	protected function _category_details($view)
2721
+	{
2722
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2723
+		$this->_set_add_edit_form_tags($route);
2724
+		$this->_set_category_object();
2725
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2726
+		$delete_action = 'delete_category';
2727
+		// custom redirect
2728
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2729
+			['action' => 'category_list'],
2730
+			$this->_admin_base_url
2731
+		);
2732
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect, true);
2733
+		// take care of contents
2734
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2735
+		$this->display_admin_page_with_sidebar();
2736
+	}
2737
+
2738
+
2739
+	/**
2740
+	 * Output category details content.
2741
+	 *
2742
+	 * @throws DomainException
2743
+	 */
2744
+	protected function _category_details_content(): string
2745
+	{
2746
+		$editor_args['category_desc'] = [
2747
+			'type'          => 'wp_editor',
2748
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2749
+			'class'         => 'my_editor_custom',
2750
+			'wpeditor_args' => ['media_buttons' => false],
2751
+		];
2752
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2753
+		$all_terms                    = get_terms(
2754
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2755
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2756
+		);
2757
+		// setup category select for term parents.
2758
+		$category_select_values[] = [
2759
+			'text' => esc_html__('No Parent', 'event_espresso'),
2760
+			'id'   => 0,
2761
+		];
2762
+		foreach ($all_terms as $term) {
2763
+			$category_select_values[] = [
2764
+				'text' => $term->name,
2765
+				'id'   => $term->term_id,
2766
+			];
2767
+		}
2768
+		$category_select = EEH_Form_Fields::select_input(
2769
+			'category_parent',
2770
+			$category_select_values,
2771
+			$this->_category->parent
2772
+		);
2773
+		$template_args   = [
2774
+			'category'                 => $this->_category,
2775
+			'category_select'          => $category_select,
2776
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2777
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2778
+			'disable'                  => '',
2779
+			'disabled_message'         => false,
2780
+		];
2781
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2782
+		return EEH_Template::display_template($template, $template_args, true);
2783
+	}
2784
+
2785
+
2786
+	/**
2787
+	 * Handles deleting categories.
2788
+	 *
2789
+	 * @throws EE_Error
2790
+	 */
2791
+	protected function _delete_categories()
2792
+	{
2793
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2794
+		foreach ($category_IDs as $category_ID) {
2795
+			$this->_delete_category($category_ID);
2796
+		}
2797
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2798
+		$query_args = [
2799
+			'action' => 'category_list',
2800
+		];
2801
+		$this->_redirect_after_action(0, '', '', $query_args);
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * Handles deleting specific category.
2807
+	 *
2808
+	 * @param int $cat_id
2809
+	 */
2810
+	protected function _delete_category(int $cat_id)
2811
+	{
2812
+		$cat_id = absint($cat_id);
2813
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2814
+	}
2815
+
2816
+
2817
+	/**
2818
+	 * Handles triggering the update or insertion of a new category.
2819
+	 *
2820
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2821
+	 * @throws EE_Error
2822
+	 * @throws EE_Error
2823
+	 */
2824
+	protected function _insert_or_update_category(bool $new_category)
2825
+	{
2826
+		$cat_id  = $this->_insert_category($new_category);
2827
+		$success = 0; // we already have a success message so lets not send another.
2828
+		if ($cat_id) {
2829
+			$query_args = [
2830
+				'action'     => 'edit_category',
2831
+				'EVT_CAT_ID' => $cat_id,
2832
+			];
2833
+		} else {
2834
+			$query_args = ['action' => 'add_category'];
2835
+		}
2836
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2837
+	}
2838
+
2839
+
2840
+	/**
2841
+	 * Inserts or updates category
2842
+	 *
2843
+	 * @param bool $new_category (true indicates we're updating a category).
2844
+	 * @return bool|mixed|string
2845
+	 */
2846
+	private function _insert_category(bool $new_category)
2847
+	{
2848
+		$category_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
2849
+		$category_name       = $this->request->getRequestParam('category_name', '');
2850
+		$category_desc       = $this->request->getRequestParam('category_desc', '', DataType::HTML);
2851
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, DataType::INT);
2852
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2853
+
2854
+		if (empty($category_name)) {
2855
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2856
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2857
+			return 0;
2858
+		}
2859
+		$term_args = [
2860
+			'name'        => $category_name,
2861
+			'description' => $category_desc,
2862
+			'parent'      => $category_parent,
2863
+		];
2864
+		// was the category_identifier input disabled?
2865
+		if ($category_identifier) {
2866
+			$term_args['slug'] = $category_identifier;
2867
+		}
2868
+		$insert_ids = $new_category
2869
+			? wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2870
+			: wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2871
+
2872
+		if ($insert_ids instanceof WP_Error) {
2873
+			EE_Error::add_error($insert_ids->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
2874
+			return 0;
2875
+		}
2876
+		$category_ID = $insert_ids['term_id'] ?? 0;
2877
+		if (! $category_ID) {
2878
+			EE_Error::add_error(
2879
+				esc_html__(
2880
+					'An error occurred and the category has not been saved to the database.',
2881
+					'event_espresso'
2882
+				),
2883
+				__FILE__,
2884
+				__FUNCTION__,
2885
+				__LINE__
2886
+			);
2887
+			return 0;
2888
+		}
2889
+		EE_Error::add_success(
2890
+			sprintf(
2891
+				esc_html__('The category %s was successfully saved', 'event_espresso'),
2892
+				$category_name
2893
+			)
2894
+		);
2895
+		return $category_ID;
2896
+	}
2897
+
2898
+
2899
+	/**
2900
+	 * Gets categories or count of categories matching the arguments in the request.
2901
+	 *
2902
+	 * @param int  $per_page
2903
+	 * @param int  $current_page
2904
+	 * @param bool $count
2905
+	 * @return EE_Term_Taxonomy[]|int
2906
+	 * @throws EE_Error
2907
+	 * @throws ReflectionException
2908
+	 */
2909
+	public function get_categories(int $per_page = 10, int $current_page = 1, bool $count = false)
2910
+	{
2911
+		// testing term stuff
2912
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2913
+		$order       = $this->request->getRequestParam('order', 'DESC');
2914
+		$limit       = ($current_page - 1) * $per_page;
2915
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2916
+		$search_term = $this->request->getRequestParam('s');
2917
+		if ($search_term) {
2918
+			$search_term = '%' . $search_term . '%';
2919
+			$where['OR'] = [
2920
+				'Term.name'   => ['LIKE', $search_term],
2921
+				'description' => ['LIKE', $search_term],
2922
+			];
2923
+		}
2924
+		$query_params = [
2925
+			$where,
2926
+			'order_by'   => [$orderby => $order],
2927
+			'limit'      => $limit . ',' . $per_page,
2928
+			'force_join' => ['Term'],
2929
+		];
2930
+		return $count
2931
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2932
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2933
+	}
2934
+
2935
+	/* end category stuff */
2936
+
2937
+
2938
+	/**************/
2939
+
2940
+
2941
+	/**
2942
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2943
+	 *
2944
+	 * @throws EE_Error
2945
+	 * @throws InvalidArgumentException
2946
+	 * @throws InvalidDataTypeException
2947
+	 * @throws InvalidInterfaceException
2948
+	 */
2949
+	public function saveTimezoneString()
2950
+	{
2951
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2952
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2953
+			EE_Error::add_error(
2954
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2955
+				__FILE__,
2956
+				__FUNCTION__,
2957
+				__LINE__
2958
+			);
2959
+			$this->_template_args['error'] = true;
2960
+			$this->_return_json();
2961
+		}
2962
+
2963
+		update_option('timezone_string', $timezone_string);
2964
+		EE_Error::add_success(
2965
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2966
+		);
2967
+		$this->_template_args['success'] = true;
2968
+		$this->_return_json(true, ['action' => 'create_new']);
2969
+	}
2970
+
2971
+
2972
+	/**
2973
+	 * @throws EE_Error
2974
+	 * @deprecated 4.10.25.p
2975
+	 */
2976
+	public function save_timezonestring_setting()
2977
+	{
2978
+		$this->saveTimezoneString();
2979
+	}
2980 2980
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 2 patches
Indentation   +2176 added lines, -2176 removed lines patch added patch discarded remove patch
@@ -15,2194 +15,2194 @@
 block discarded – undo
15 15
  */
16 16
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
17 17
 {
18
-    /**
19
-     * This property is just used to hold the status of whether an event is currently being
20
-     * created (true) or edited (false)
21
-     *
22
-     * @access protected
23
-     * @var bool
24
-     */
25
-    protected $_is_creating_event;
26
-
27
-    /**
28
-     * Used to contain the format strings for date and time that will be used for php date and
29
-     * time.
30
-     * Is set in the _set_hooks_properties() method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_date_format_strings;
35
-
36
-    /**
37
-     * @var string $_date_time_format
38
-     */
39
-    protected $_date_time_format;
40
-
41
-
42
-    /**
43
-     * @throws InvalidArgumentException
44
-     * @throws InvalidInterfaceException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    protected function _set_hooks_properties()
48
-    {
49
-        $this->_name = 'pricing';
50
-        // capability check
51
-        if (
52
-            $this->_adminpage_obj->adminConfig()->useAdvancedEditor()
53
-            || ! EE_Registry::instance()->CAP->current_user_can(
54
-                'ee_read_default_prices',
55
-                'advanced_ticket_datetime_metabox'
56
-            )
57
-        ) {
58
-            $this->_metaboxes      = [];
59
-            $this->_scripts_styles = [];
60
-            return;
61
-        }
62
-        $this->_setup_metaboxes();
63
-        $this->_set_date_time_formats();
64
-        $this->_validate_format_strings();
65
-        $this->_set_scripts_styles();
66
-        add_filter(
67
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
68
-            [$this, 'caf_updates']
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * @return void
75
-     */
76
-    protected function _setup_metaboxes()
77
-    {
78
-        // if we were going to add our own metaboxes we'd use the below.
79
-        $this->_metaboxes        = [
80
-            0 => [
81
-                'page_route' => ['edit', 'create_new'],
82
-                'func'       => [$this, 'pricing_metabox'],
83
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
84
-                'priority'   => 'high',
85
-                'context'    => 'normal',
86
-            ],
87
-        ];
88
-        $this->_remove_metaboxes = [
89
-            0 => [
90
-                'page_route' => ['edit', 'create_new'],
91
-                'id'         => 'espresso_event_editor_tickets',
92
-                'context'    => 'normal',
93
-            ],
94
-        ];
95
-    }
96
-
97
-
98
-    /**
99
-     * @return void
100
-     */
101
-    protected function _set_date_time_formats()
102
-    {
103
-        /**
104
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
105
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
106
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
107
-         *
108
-         * @since 4.6.7
109
-         * @var array  Expected an array returned with 'date' and 'time' keys.
110
-         */
111
-        $this->_date_format_strings = apply_filters(
112
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
113
-            [
114
-                'date' => 'Y-m-d',
115
-                'time' => 'h:i a',
116
-            ]
117
-        );
118
-        // validate
119
-        $this->_date_format_strings['date'] = $this->_date_format_strings['date'] ?? '';
120
-        $this->_date_format_strings['time'] = $this->_date_format_strings['time'] ?? '';
121
-
122
-        $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'];
123
-    }
124
-
125
-
126
-    /**
127
-     * @return void
128
-     */
129
-    protected function _validate_format_strings()
130
-    {
131
-        // validate format strings
132
-        $format_validation = EEH_DTT_Helper::validate_format_string(
133
-            $this->_date_time_format
134
-        );
135
-        if (is_array($format_validation)) {
136
-            $msg = '<p>';
137
-            $msg .= sprintf(
138
-                esc_html__(
139
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
140
-                    'event_espresso'
141
-                ),
142
-                $this->_date_time_format
143
-            );
144
-            $msg .= '</p><ul>';
145
-            foreach ($format_validation as $error) {
146
-                $msg .= '<li>' . $error . '</li>';
147
-            }
148
-            $msg .= '</ul><p>';
149
-            $msg .= sprintf(
150
-                esc_html__(
151
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
152
-                    'event_espresso'
153
-                ),
154
-                '<span style="color:#D54E21;">',
155
-                '</span>'
156
-            );
157
-            $msg .= '</p>';
158
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
159
-            $this->_date_format_strings = [
160
-                'date' => 'Y-m-d',
161
-                'time' => 'h:i a',
162
-            ];
163
-        }
164
-    }
165
-
166
-
167
-    /**
168
-     * @return void
169
-     */
170
-    protected function _set_scripts_styles()
171
-    {
172
-        $this->_scripts_styles = [
173
-            'registers'   => [
174
-                'ee-tickets-datetimes-css' => [
175
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
176
-                    'type' => 'css',
177
-                ],
178
-                'ee-dtt-ticket-metabox'    => [
179
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
180
-                    'depends' => ['ee-datepicker', 'ee-dialog', 'underscore'],
181
-                ],
182
-            ],
183
-            'deregisters' => [
184
-                'event-editor-css'       => ['type' => 'css'],
185
-                'event-datetime-metabox' => ['type' => 'js'],
186
-            ],
187
-            'enqueues'    => [
188
-                'ee-tickets-datetimes-css' => ['edit', 'create_new'],
189
-                'ee-dtt-ticket-metabox'    => ['edit', 'create_new'],
190
-            ],
191
-            'localize'    => [
192
-                'ee-dtt-ticket-metabox' => [
193
-                    'DTT_TRASH_BLOCK'       => [
194
-                        'main_warning'            => esc_html__(
195
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
196
-                            'event_espresso'
197
-                        ),
198
-                        'after_warning'           => esc_html__(
199
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
200
-                            'event_espresso'
201
-                        ),
202
-                        'cancel_button'           => '
18
+	/**
19
+	 * This property is just used to hold the status of whether an event is currently being
20
+	 * created (true) or edited (false)
21
+	 *
22
+	 * @access protected
23
+	 * @var bool
24
+	 */
25
+	protected $_is_creating_event;
26
+
27
+	/**
28
+	 * Used to contain the format strings for date and time that will be used for php date and
29
+	 * time.
30
+	 * Is set in the _set_hooks_properties() method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_date_format_strings;
35
+
36
+	/**
37
+	 * @var string $_date_time_format
38
+	 */
39
+	protected $_date_time_format;
40
+
41
+
42
+	/**
43
+	 * @throws InvalidArgumentException
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	protected function _set_hooks_properties()
48
+	{
49
+		$this->_name = 'pricing';
50
+		// capability check
51
+		if (
52
+			$this->_adminpage_obj->adminConfig()->useAdvancedEditor()
53
+			|| ! EE_Registry::instance()->CAP->current_user_can(
54
+				'ee_read_default_prices',
55
+				'advanced_ticket_datetime_metabox'
56
+			)
57
+		) {
58
+			$this->_metaboxes      = [];
59
+			$this->_scripts_styles = [];
60
+			return;
61
+		}
62
+		$this->_setup_metaboxes();
63
+		$this->_set_date_time_formats();
64
+		$this->_validate_format_strings();
65
+		$this->_set_scripts_styles();
66
+		add_filter(
67
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
68
+			[$this, 'caf_updates']
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * @return void
75
+	 */
76
+	protected function _setup_metaboxes()
77
+	{
78
+		// if we were going to add our own metaboxes we'd use the below.
79
+		$this->_metaboxes        = [
80
+			0 => [
81
+				'page_route' => ['edit', 'create_new'],
82
+				'func'       => [$this, 'pricing_metabox'],
83
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
84
+				'priority'   => 'high',
85
+				'context'    => 'normal',
86
+			],
87
+		];
88
+		$this->_remove_metaboxes = [
89
+			0 => [
90
+				'page_route' => ['edit', 'create_new'],
91
+				'id'         => 'espresso_event_editor_tickets',
92
+				'context'    => 'normal',
93
+			],
94
+		];
95
+	}
96
+
97
+
98
+	/**
99
+	 * @return void
100
+	 */
101
+	protected function _set_date_time_formats()
102
+	{
103
+		/**
104
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
105
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
106
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
107
+		 *
108
+		 * @since 4.6.7
109
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
110
+		 */
111
+		$this->_date_format_strings = apply_filters(
112
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
113
+			[
114
+				'date' => 'Y-m-d',
115
+				'time' => 'h:i a',
116
+			]
117
+		);
118
+		// validate
119
+		$this->_date_format_strings['date'] = $this->_date_format_strings['date'] ?? '';
120
+		$this->_date_format_strings['time'] = $this->_date_format_strings['time'] ?? '';
121
+
122
+		$this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'];
123
+	}
124
+
125
+
126
+	/**
127
+	 * @return void
128
+	 */
129
+	protected function _validate_format_strings()
130
+	{
131
+		// validate format strings
132
+		$format_validation = EEH_DTT_Helper::validate_format_string(
133
+			$this->_date_time_format
134
+		);
135
+		if (is_array($format_validation)) {
136
+			$msg = '<p>';
137
+			$msg .= sprintf(
138
+				esc_html__(
139
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
140
+					'event_espresso'
141
+				),
142
+				$this->_date_time_format
143
+			);
144
+			$msg .= '</p><ul>';
145
+			foreach ($format_validation as $error) {
146
+				$msg .= '<li>' . $error . '</li>';
147
+			}
148
+			$msg .= '</ul><p>';
149
+			$msg .= sprintf(
150
+				esc_html__(
151
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
152
+					'event_espresso'
153
+				),
154
+				'<span style="color:#D54E21;">',
155
+				'</span>'
156
+			);
157
+			$msg .= '</p>';
158
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
159
+			$this->_date_format_strings = [
160
+				'date' => 'Y-m-d',
161
+				'time' => 'h:i a',
162
+			];
163
+		}
164
+	}
165
+
166
+
167
+	/**
168
+	 * @return void
169
+	 */
170
+	protected function _set_scripts_styles()
171
+	{
172
+		$this->_scripts_styles = [
173
+			'registers'   => [
174
+				'ee-tickets-datetimes-css' => [
175
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
176
+					'type' => 'css',
177
+				],
178
+				'ee-dtt-ticket-metabox'    => [
179
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
180
+					'depends' => ['ee-datepicker', 'ee-dialog', 'underscore'],
181
+				],
182
+			],
183
+			'deregisters' => [
184
+				'event-editor-css'       => ['type' => 'css'],
185
+				'event-datetime-metabox' => ['type' => 'js'],
186
+			],
187
+			'enqueues'    => [
188
+				'ee-tickets-datetimes-css' => ['edit', 'create_new'],
189
+				'ee-dtt-ticket-metabox'    => ['edit', 'create_new'],
190
+			],
191
+			'localize'    => [
192
+				'ee-dtt-ticket-metabox' => [
193
+					'DTT_TRASH_BLOCK'       => [
194
+						'main_warning'            => esc_html__(
195
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
196
+							'event_espresso'
197
+						),
198
+						'after_warning'           => esc_html__(
199
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
200
+							'event_espresso'
201
+						),
202
+						'cancel_button'           => '
203 203
                             <button class="button--secondary ee-modal-cancel">
204 204
                                 ' . esc_html__('Cancel', 'event_espresso') . '
205 205
                             </button>',
206
-                        'close_button'            => '
206
+						'close_button'            => '
207 207
                             <button class="button--secondary ee-modal-cancel">
208 208
                                 ' . esc_html__('Close', 'event_espresso') . '
209 209
                             </button>',
210
-                        'single_warning_from_tkt' => esc_html__(
211
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
212
-                            'event_espresso'
213
-                        ),
214
-                        'single_warning_from_dtt' => esc_html__(
215
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
216
-                            'event_espresso'
217
-                        ),
218
-                        'dismiss_button'          => '
210
+						'single_warning_from_tkt' => esc_html__(
211
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
212
+							'event_espresso'
213
+						),
214
+						'single_warning_from_dtt' => esc_html__(
215
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
216
+							'event_espresso'
217
+						),
218
+						'dismiss_button'          => '
219 219
                             <button class="button--secondary ee-modal-cancel">
220 220
                                 ' . esc_html__('Dismiss', 'event_espresso') . '
221 221
                             </button>',
222
-                    ],
223
-                    'DTT_ERROR_MSG'         => [
224
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
225
-                        'dismiss_button' => '
222
+					],
223
+					'DTT_ERROR_MSG'         => [
224
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
225
+						'dismiss_button' => '
226 226
                             <div class="save-cancel-button-container">
227 227
                                 <button class="button--secondary ee-modal-cancel">
228 228
                                     ' . esc_html__('Dismiss', 'event_espresso') . '
229 229
                                 </button>
230 230
                             </div>',
231
-                    ],
232
-                    'DTT_OVERSELL_WARNING'  => [
233
-                        'datetime_ticket' => esc_html__(
234
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
235
-                            'event_espresso'
236
-                        ),
237
-                        'ticket_datetime' => esc_html__(
238
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
239
-                            'event_espresso'
240
-                        ),
241
-                    ],
242
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
243
-                        $this->_date_format_strings['date'],
244
-                        $this->_date_format_strings['time']
245
-                    ),
246
-                    'DTT_START_OF_WEEK'     => ['dayValue' => (int) get_option('start_of_week')],
247
-                ],
248
-            ],
249
-        ];
250
-    }
251
-
252
-
253
-    /**
254
-     * @param array $update_callbacks
255
-     * @return array
256
-     */
257
-    public function caf_updates(array $update_callbacks): array
258
-    {
259
-        unset($update_callbacks['_default_tickets_update']);
260
-        $update_callbacks['datetime_and_tickets_caf_update'] = [$this, 'datetime_and_tickets_caf_update'];
261
-        return $update_callbacks;
262
-    }
263
-
264
-
265
-    /**
266
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
267
-     *
268
-     * @param EE_Event $event The Event object we're attaching data to
269
-     * @param array    $data  The request data from the form
270
-     * @throws ReflectionException
271
-     * @throws Exception
272
-     * @throws InvalidInterfaceException
273
-     * @throws InvalidDataTypeException
274
-     * @throws EE_Error
275
-     * @throws InvalidArgumentException
276
-     */
277
-    public function datetime_and_tickets_caf_update(EE_Event $event, array $data)
278
-    {
279
-        // first we need to start with datetimes cause they are the "root" items attached to events.
280
-        $saved_datetimes = $this->_update_datetimes($event, $data);
281
-        // next tackle the tickets (and prices?)
282
-        $this->_update_tickets($event, $saved_datetimes, $data);
283
-    }
284
-
285
-
286
-    /**
287
-     * update event_datetimes
288
-     *
289
-     * @param EE_Event $event Event being updated
290
-     * @param array    $data  the request data from the form
291
-     * @return EE_Datetime[]
292
-     * @throws Exception
293
-     * @throws ReflectionException
294
-     * @throws InvalidInterfaceException
295
-     * @throws InvalidDataTypeException
296
-     * @throws InvalidArgumentException
297
-     * @throws EE_Error
298
-     */
299
-    protected function _update_datetimes(EE_Event $event, array $data): array
300
-    {
301
-        $saved_datetime_ids  = [];
302
-        $saved_datetime_objs = [];
303
-        $timezone       = $data['timezone_string'] ?? null;
304
-        $datetime_model = EEM_Datetime::instance($timezone);
305
-
306
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
307
-            throw new InvalidArgumentException(
308
-                esc_html__(
309
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
310
-                    'event_espresso'
311
-                )
312
-            );
313
-        }
314
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
315
-            // trim all values to ensure any excess whitespace is removed.
316
-            $datetime_data = array_map(
317
-                function ($datetime_data) {
318
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
319
-                },
320
-                $datetime_data
321
-            );
322
-
323
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
324
-                                            && ! empty($datetime_data['DTT_EVT_end'])
325
-                ? $datetime_data['DTT_EVT_end']
326
-                : $datetime_data['DTT_EVT_start'];
327
-            $datetime_values              = [
328
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329
-                    ? $datetime_data['DTT_ID']
330
-                    : null,
331
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
332
-                    ? $datetime_data['DTT_name']
333
-                    : '',
334
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
335
-                    ? $datetime_data['DTT_description']
336
-                    : '',
337
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
338
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
339
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
340
-                    ? EE_INF
341
-                    : $datetime_data['DTT_reg_limit'],
342
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
343
-                    ? $row
344
-                    : $datetime_data['DTT_order'],
345
-            ];
346
-
347
-            // if we have an id then let's get existing object first and then set the new values.
348
-            // Otherwise we instantiate a new object for save.
349
-            if (! empty($datetime_data['DTT_ID'])) {
350
-                $datetime = EE_Registry::instance()
351
-                                       ->load_model('Datetime', [$timezone])
352
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
353
-                // set date and time format according to what is set in this class.
354
-                $datetime->set_date_format($this->_date_format_strings['date']);
355
-                $datetime->set_time_format($this->_date_format_strings['time']);
356
-                foreach ($datetime_values as $field => $value) {
357
-                    $datetime->set($field, $value);
358
-                }
359
-
360
-                // make sure the $datetime_id here is saved just in case
361
-                // after the add_relation_to() the autosave replaces it.
362
-                // We need to do this so we dont' TRASH the parent DTT.
363
-                // (save the ID for both key and value to avoid duplications)
364
-                $saved_datetime_ids[ $datetime->ID() ] = $datetime->ID();
365
-            } else {
366
-                $datetime = EE_Datetime::new_instance(
367
-                    $datetime_values,
368
-                    $timezone,
369
-                    [$this->_date_format_strings['date'], $this->_date_format_strings['time']]
370
-                );
371
-                foreach ($datetime_values as $field => $value) {
372
-                    $datetime->set($field, $value);
373
-                }
374
-            }
375
-            $datetime->save();
376
-            do_action(
377
-                'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
378
-                $datetime,
379
-                $row,
380
-                $datetime_data,
381
-                $data
382
-            );
383
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
384
-            // before going any further make sure our dates are setup correctly
385
-            // so that the end date is always equal or greater than the start date.
386
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
387
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
388
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
389
-                $datetime->save();
390
-            }
391
-            // now we have to make sure we add the new DTT_ID to the $saved_datetime_ids array
392
-            // because it is possible there was a new one created for the autosave.
393
-            // (save the ID for both key and value to avoid duplications)
394
-            $DTT_ID                        = $datetime->ID();
395
-            $saved_datetime_ids[ $DTT_ID ] = $DTT_ID;
396
-            $saved_datetime_objs[ $row ]   = $datetime;
397
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
398
-        }
399
-        $event->save();
400
-        // now we need to REMOVE any datetimes that got deleted.
401
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
402
-        // So its safe to permanently delete at this point.
403
-        $old_datetimes = explode(',', $data['datetime_IDs']);
404
-        $old_datetimes = $old_datetimes[0] === '' ? [] : $old_datetimes;
405
-        if (is_array($old_datetimes)) {
406
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_datetime_ids);
407
-            foreach ($datetimes_to_delete as $id) {
408
-                $id = absint($id);
409
-                if (empty($id)) {
410
-                    continue;
411
-                }
412
-                $dtt_to_remove = $datetime_model->get_one_by_ID($id);
413
-                // remove tkt relationships.
414
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
415
-                foreach ($related_tickets as $ticket) {
416
-                    $dtt_to_remove->_remove_relation_to($ticket, 'Ticket');
417
-                }
418
-                $event->_remove_relation_to($id, 'Datetime');
419
-                $dtt_to_remove->refresh_cache_of_related_objects();
420
-            }
421
-        }
422
-        return $saved_datetime_objs;
423
-    }
424
-
425
-
426
-    /**
427
-     * update tickets
428
-     *
429
-     * @param EE_Event      $event           Event object being updated
430
-     * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated
431
-     * @param array         $data            incoming request data
432
-     * @return EE_Ticket[]
433
-     * @throws Exception
434
-     * @throws ReflectionException
435
-     * @throws InvalidInterfaceException
436
-     * @throws InvalidDataTypeException
437
-     * @throws InvalidArgumentException
438
-     * @throws EE_Error
439
-     */
440
-    protected function _update_tickets(EE_Event $event, array $saved_datetimes, array $data): array
441
-    {
442
-        $new_ticket = null;
443
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
444
-        $data          = stripslashes_deep($data);
445
-        $timezone      = $data['timezone_string'] ?? null;
446
-        $ticket_model = EEM_Ticket::instance($timezone);
447
-
448
-        $saved_tickets = [];
449
-        $old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
450
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
451
-            throw new InvalidArgumentException(
452
-                esc_html__(
453
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
454
-                    'event_espresso'
455
-                )
456
-            );
457
-        }
458
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
459
-            $update_prices = $create_new_TKT = false;
460
-            // figure out what datetimes were added to the ticket
461
-            // and what datetimes were removed from the ticket in the session.
462
-            $starting_ticket_datetime_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
463
-            $ticket_datetime_rows          = explode(',', $data['ticket_datetime_rows'][ $row ]);
464
-            $datetimes_added               = array_diff($ticket_datetime_rows, $starting_ticket_datetime_rows);
465
-            $datetimes_removed             = array_diff($starting_ticket_datetime_rows, $ticket_datetime_rows);
466
-            // trim inputs to ensure any excess whitespace is removed.
467
-            $ticket_data = array_map(
468
-                function ($ticket_data) {
469
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
470
-                },
471
-                $ticket_data
472
-            );
473
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
474
-            // because we're doing calculations prior to using the models.
475
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
476
-            $ticket_price = isset($ticket_data['TKT_price'])
477
-                ? round((float) $ticket_data['TKT_price'], 3)
478
-                : 0;
479
-            // note incoming base price needs converted from localized value.
480
-            $base_price = isset($ticket_data['TKT_base_price'])
481
-                ? EEH_Money::convert_to_float_from_localized_money($ticket_data['TKT_base_price'])
482
-                : 0;
483
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
484
-            $ticket_price  = $ticket_price === 0 && $base_price !== 0
485
-                ? $base_price
486
-                : $ticket_price;
487
-            $base_price_id = $ticket_data['TKT_base_price_ID'] ?? 0;
488
-            $price_rows    = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
489
-                ? $data['edit_prices'][ $row ]
490
-                : [];
491
-            $now           = null;
492
-            if (empty($ticket_data['TKT_start_date'])) {
493
-                // lets' use now in the set timezone.
494
-                $now                           = new DateTime('now', new DateTimeZone($event->get_timezone()));
495
-                $ticket_data['TKT_start_date'] = $now->format($this->_date_time_format);
496
-            }
497
-            if (empty($ticket_data['TKT_end_date'])) {
498
-                /**
499
-                 * set the TKT_end_date to the first datetime attached to the ticket.
500
-                 */
501
-                $first_datetime              = $saved_datetimes[ reset($ticket_datetime_rows) ];
502
-                $ticket_data['TKT_end_date'] = $first_datetime->start_date_and_time($this->_date_time_format);
503
-            }
504
-            $TKT_values = [
505
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
506
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
507
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
508
-                'TKT_description' => ! empty($ticket_data['TKT_description'])
509
-                                     && $ticket_data['TKT_description'] !== esc_html__(
510
-                                         'You can modify this description',
511
-                                         'event_espresso'
512
-                                     )
513
-                    ? $ticket_data['TKT_description']
514
-                    : '',
515
-                'TKT_start_date'  => $ticket_data['TKT_start_date'],
516
-                'TKT_end_date'    => $ticket_data['TKT_end_date'],
517
-                'TKT_qty'         => ! isset($ticket_data['TKT_qty']) || $ticket_data['TKT_qty'] === ''
518
-                    ? EE_INF
519
-                    : $ticket_data['TKT_qty'],
520
-                'TKT_uses'        => ! isset($ticket_data['TKT_uses']) || $ticket_data['TKT_uses'] === ''
521
-                    ? EE_INF
522
-                    : $ticket_data['TKT_uses'],
523
-                'TKT_min'         => empty($ticket_data['TKT_min']) ? 0 : $ticket_data['TKT_min'],
524
-                'TKT_max'         => empty($ticket_data['TKT_max']) ? EE_INF : $ticket_data['TKT_max'],
525
-                'TKT_row'         => $row,
526
-                'TKT_order'       => $ticket_data['TKT_order'] ?? 0,
527
-                'TKT_taxable'     => ! empty($ticket_data['TKT_taxable']) ? 1 : 0,
528
-                'TKT_required'    => ! empty($ticket_data['TKT_required']) ? 1 : 0,
529
-                'TKT_price'       => $ticket_price,
530
-            ];
531
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
532
-            // which means in turn that the prices will become new prices as well.
533
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
534
-                $TKT_values['TKT_ID']         = 0;
535
-                $TKT_values['TKT_is_default'] = 0;
536
-                $update_prices                = true;
537
-            }
538
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
539
-            // we actually do our saves ahead of doing any add_relations to
540
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
541
-            // but DID have it's items modified.
542
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
543
-            // then we won't be updating the ticket but instead a new ticket will be created and the old one archived.
544
-            if (absint($TKT_values['TKT_ID'])) {
545
-                $ticket = EE_Registry::instance()
546
-                                     ->load_model('Ticket', [$timezone])
547
-                                     ->get_one_by_ID($TKT_values['TKT_ID']);
548
-                if ($ticket instanceof EE_Ticket) {
549
-                    $ticket = $this->_update_ticket_datetimes(
550
-                        $ticket,
551
-                        $saved_datetimes,
552
-                        $datetimes_added,
553
-                        $datetimes_removed
554
-                    );
555
-                    // are there any registrations using this ticket ?
556
-                    $tickets_sold = $ticket->count_related(
557
-                        'Registration',
558
-                        [
559
-                            [
560
-                                'STS_ID' => ['NOT IN', [EEM_Registration::status_id_incomplete]],
561
-                            ],
562
-                        ]
563
-                    );
564
-                    // set ticket formats
565
-                    $ticket->set_date_format($this->_date_format_strings['date']);
566
-                    $ticket->set_time_format($this->_date_format_strings['time']);
567
-                    // let's just check the total price for the existing ticket
568
-                    // and determine if it matches the new total price.
569
-                    // if they are different then we create a new ticket (if tickets sold)
570
-                    // if they aren't different then we go ahead and modify existing ticket.
571
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
572
-                    // set new values
573
-                    foreach ($TKT_values as $field => $value) {
574
-                        if ($field === 'TKT_qty') {
575
-                            $ticket->set_qty($value);
576
-                        } else {
577
-                            $ticket->set($field, $value);
578
-                        }
579
-                    }
580
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
581
-                    // Otherwise we have to create a new ticket.
582
-                    if ($create_new_TKT) {
583
-                        $new_ticket = $this->_duplicate_ticket(
584
-                            $ticket,
585
-                            $price_rows,
586
-                            $ticket_price,
587
-                            $base_price,
588
-                            $base_price_id
589
-                        );
590
-                    }
591
-                }
592
-            } else {
593
-                // no TKT_id so a new TKT
594
-                $ticket = EE_Ticket::new_instance(
595
-                    $TKT_values,
596
-                    $timezone,
597
-                    [$this->_date_format_strings['date'], $this->_date_format_strings['time']]
598
-                );
599
-                if ($ticket instanceof EE_Ticket) {
600
-                    // make sure ticket has an ID of setting relations won't work
601
-                    $ticket->save();
602
-                    $ticket        = $this->_update_ticket_datetimes(
603
-                        $ticket,
604
-                        $saved_datetimes,
605
-                        $datetimes_added,
606
-                        $datetimes_removed
607
-                    );
608
-                    $update_prices = true;
609
-                }
610
-            }
611
-            // make sure any current values have been saved.
612
-            // $ticket->save();
613
-            // before going any further make sure our dates are setup correctly
614
-            // so that the end date is always equal or greater than the start date.
615
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
616
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
617
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
618
-            }
619
-            // let's make sure the base price is handled
620
-            $ticket = ! $create_new_TKT
621
-                ? $this->_add_prices_to_ticket(
622
-                    [],
623
-                    $ticket,
624
-                    $update_prices,
625
-                    $base_price,
626
-                    $base_price_id
627
-                )
628
-                : $ticket;
629
-            // add/update price_modifiers
630
-            $ticket = ! $create_new_TKT
631
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
632
-                : $ticket;
633
-            // need to make sue that the TKT_price is accurate after saving the prices.
634
-            $ticket->ensure_TKT_Price_correct();
635
-            // handle CREATING a default ticket from the incoming ticket but ONLY if this isn't an autosave.
636
-            if (! defined('DOING_AUTOSAVE') && ! empty($ticket_data['TKT_is_default_selector'])) {
637
-                $new_default = clone $ticket;
638
-                $new_default->set('TKT_ID', 0);
639
-                $new_default->set('TKT_is_default', 1);
640
-                $new_default->set('TKT_row', 1);
641
-                $new_default->set('TKT_price', $ticket_price);
642
-                // remove any datetime relations cause we DON'T want datetime relations attached
643
-                // (note this is just removing the cached relations in the object)
644
-                $new_default->_remove_relations('Datetime');
645
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
646
-                $new_default = $this->_add_prices_to_ticket(
647
-                    $price_rows,
648
-                    $new_default,
649
-                    true
650
-                );
651
-                // don't forget the base price!
652
-                $new_default = $this->_add_prices_to_ticket(
653
-                    [],
654
-                    $new_default,
655
-                    true,
656
-                    $base_price,
657
-                    $base_price_id
658
-                );
659
-                $new_default->save();
660
-                do_action(
661
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
662
-                    $new_default,
663
-                    $row,
664
-                    $ticket,
665
-                    $data
666
-                );
667
-            }
668
-            // DO ALL datetime relationships for both current tickets and any archived tickets
669
-            // for the given datetime that are related to the current ticket.
670
-            // TODO... not sure exactly how we're going to do this considering we don't know
671
-            // what current ticket the archived tickets are related to
672
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
673
-            // let's assign any tickets that have been setup to the saved_tickets tracker
674
-            // save existing TKT
675
-            $ticket->save();
676
-            if ($create_new_TKT && $new_ticket instanceof EE_Ticket) {
677
-                // save new TKT
678
-                $new_ticket->save();
679
-                // add new ticket to array
680
-                $saved_tickets[ $new_ticket->ID() ] = $new_ticket;
681
-                do_action(
682
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
683
-                    $new_ticket,
684
-                    $row,
685
-                    $ticket_data,
686
-                    $data
687
-                );
688
-            } else {
689
-                // add ticket to saved tickets
690
-                $saved_tickets[ $ticket->ID() ] = $ticket;
691
-                do_action(
692
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
693
-                    $ticket,
694
-                    $row,
695
-                    $ticket_data,
696
-                    $data
697
-                );
698
-            }
699
-        }
700
-        // now we need to handle tickets actually "deleted permanently".
701
-        // There are cases where we'd want this to happen
702
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
703
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
704
-        // No sense in keeping all the related data in the db!
705
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
706
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
707
-        foreach ($tickets_removed as $id) {
708
-            $id = absint($id);
709
-            // get the ticket for this id
710
-            $ticket_to_remove = $ticket_model->get_one_by_ID($id);
711
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
712
-            if ($ticket_to_remove->get('TKT_is_default')) {
713
-                continue;
714
-            }
715
-            // if this ticket has any registrations attached so then we just ARCHIVE
716
-            // because we don't actually permanently delete these tickets.
717
-            if ($ticket_to_remove->count_related('Registration') > 0) {
718
-                $ticket_to_remove->delete();
719
-                continue;
720
-            }
721
-            // need to get all the related datetimes on this ticket and remove from every single one of them
722
-            // (remember this process can ONLY kick off if there are NO tickets_sold)
723
-            $datetimes = $ticket_to_remove->get_many_related('Datetime');
724
-            foreach ($datetimes as $datetime) {
725
-                $ticket_to_remove->_remove_relation_to($datetime, 'Datetime');
726
-            }
727
-            // need to do the same for prices (except these prices can also be deleted because again,
728
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
729
-            $ticket_to_remove->delete_related('Price');
730
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $ticket_to_remove);
731
-            // finally let's delete this ticket
732
-            // (which should not be blocked at this point b/c we've removed all our relationships)
733
-            $ticket_to_remove->delete_or_restore();
734
-        }
735
-        return $saved_tickets;
736
-    }
737
-
738
-
739
-    /**
740
-     * @access  protected
741
-     * @param EE_Ticket     $ticket
742
-     * @param EE_Datetime[] $saved_datetimes
743
-     * @param int[]         $added_datetimes
744
-     * @param int[]         $removed_datetimes
745
-     * @return EE_Ticket
746
-     * @throws EE_Error
747
-     * @throws ReflectionException
748
-     */
749
-    protected function _update_ticket_datetimes(
750
-        EE_Ticket $ticket,
751
-        array $saved_datetimes = [],
752
-        array $added_datetimes = [],
753
-        array $removed_datetimes = []
754
-    ): EE_Ticket {
755
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
756
-        // and removing the ticket from datetimes it got removed from.
757
-        // first let's add datetimes
758
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
759
-            foreach ($added_datetimes as $row_id) {
760
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
761
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
762
-                    // Is this an existing ticket (has an ID) and does it have any sold?
763
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
764
-                    if ($ticket->ID() && $ticket->sold() > 0) {
765
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
766
-                    }
767
-                }
768
-            }
769
-        }
770
-        // then remove datetimes
771
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
772
-            foreach ($removed_datetimes as $row_id) {
773
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
774
-                // So make sure we skip over this if the datetime isn't in the $saved_datetimes array)
775
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
776
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
777
-                }
778
-            }
779
-        }
780
-        // cap ticket qty by datetime reg limits
781
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
782
-        return $ticket;
783
-    }
784
-
785
-
786
-    /**
787
-     * @access  protected
788
-     * @param EE_Ticket $ticket
789
-     * @param array     $price_rows
790
-     * @param int|float $ticket_price
791
-     * @param int|float $base_price
792
-     * @param int       $base_price_id
793
-     * @return EE_Ticket
794
-     * @throws ReflectionException
795
-     * @throws InvalidArgumentException
796
-     * @throws InvalidInterfaceException
797
-     * @throws InvalidDataTypeException
798
-     * @throws EE_Error
799
-     */
800
-    protected function _duplicate_ticket(
801
-        EE_Ticket $ticket,
802
-        array $price_rows = [],
803
-        $ticket_price = 0,
804
-        $base_price = 0,
805
-        int $base_price_id = 0
806
-    ): EE_Ticket {
807
-        // create new ticket that's a copy of the existing
808
-        // except a new id of course (and not archived)
809
-        // AND has the new TKT_price associated with it.
810
-        $new_ticket = clone $ticket;
811
-        $new_ticket->set('TKT_ID', 0);
812
-        $new_ticket->set_deleted(0);
813
-        $new_ticket->set_price($ticket_price);
814
-        $new_ticket->set_sold(0);
815
-        // let's get a new ID for this ticket
816
-        $new_ticket->save();
817
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
818
-        $datetimes_on_existing = $ticket->datetimes();
819
-        $new_ticket            = $this->_update_ticket_datetimes(
820
-            $new_ticket,
821
-            $datetimes_on_existing,
822
-            array_keys($datetimes_on_existing)
823
-        );
824
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
825
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
826
-        // available.
827
-        if ($ticket->sold() > 0) {
828
-            $new_qty = $ticket->qty() - $ticket->sold();
829
-            $new_ticket->set_qty($new_qty);
830
-        }
831
-        // now we update the prices just for this ticket
832
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
833
-        // and we update the base price
834
-        return $this->_add_prices_to_ticket(
835
-            [],
836
-            $new_ticket,
837
-            true,
838
-            $base_price,
839
-            $base_price_id
840
-        );
841
-    }
842
-
843
-
844
-    /**
845
-     * This attaches a list of given prices to a ticket.
846
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
847
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
848
-     * price info and prices are automatically "archived" via the ticket.
849
-     *
850
-     * @access  private
851
-     * @param array     $prices        Array of prices from the form.
852
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
853
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
854
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
855
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
856
-     * @return EE_Ticket
857
-     * @throws ReflectionException
858
-     * @throws InvalidArgumentException
859
-     * @throws InvalidInterfaceException
860
-     * @throws InvalidDataTypeException
861
-     * @throws EE_Error
862
-     */
863
-    protected function _add_prices_to_ticket(
864
-        array $prices,
865
-        EE_Ticket $ticket,
866
-        bool $new_prices = false,
867
-        $base_price = false,
868
-        $base_price_id = false
869
-    ): EE_Ticket {
870
-        $price_model = EEM_Price::instance();
871
-        // let's just get any current prices that may exist on the given ticket
872
-        // so we can remove any prices that got trashed in this session.
873
-        $current_prices_on_ticket = $base_price !== false
874
-            ? $ticket->base_price(true)
875
-            : $ticket->price_modifiers();
876
-        $updated_prices           = [];
877
-        // if $base_price ! FALSE then updating a base price.
878
-        if ($base_price !== false) {
879
-            $prices[1] = [
880
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
881
-                'PRT_ID'     => 1,
882
-                'PRC_amount' => $base_price,
883
-                'PRC_name'   => $ticket->get('TKT_name'),
884
-                'PRC_desc'   => $ticket->get('TKT_description'),
885
-            ];
886
-        }
887
-        // possibly need to save ticket
888
-        if (! $ticket->ID()) {
889
-            $ticket->save();
890
-        }
891
-        foreach ($prices as $row => $prc) {
892
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
893
-            if (empty($prt_id)) {
894
-                continue;
895
-            } //prices MUST have a price type id.
896
-            $PRC_values = [
897
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
898
-                'PRT_ID'         => $prt_id,
899
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
900
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
901
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
902
-                'PRC_is_default' => false,
903
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
904
-                'PRC_order'      => $row,
905
-            ];
906
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
907
-                $PRC_values['PRC_ID'] = 0;
908
-                $price                = EE_Registry::instance()->load_class(
909
-                    'Price',
910
-                    [$PRC_values],
911
-                    false,
912
-                    false
913
-                );
914
-            } else {
915
-                $price = $price_model->get_one_by_ID($prc['PRC_ID']);
916
-                // update this price with new values
917
-                foreach ($PRC_values as $field => $value) {
918
-                    $price->set($field, $value);
919
-                }
920
-            }
921
-            $price->save();
922
-            $updated_prices[ $price->ID() ] = $price;
923
-            $ticket->_add_relation_to($price, 'Price');
924
-        }
925
-        // now let's remove any prices that got removed from the ticket
926
-        if (! empty($current_prices_on_ticket)) {
927
-            $current          = array_keys($current_prices_on_ticket);
928
-            $updated          = array_keys($updated_prices);
929
-            $prices_to_remove = array_diff($current, $updated);
930
-            if (! empty($prices_to_remove)) {
931
-                foreach ($prices_to_remove as $prc_id) {
932
-                    $p = $current_prices_on_ticket[ $prc_id ];
933
-                    $ticket->_remove_relation_to($p, 'Price');
934
-                    // delete permanently the price
935
-                    $p->delete_or_restore();
936
-                }
937
-            }
938
-        }
939
-        return $ticket;
940
-    }
941
-
942
-
943
-    /**
944
-     * @throws ReflectionException
945
-     * @throws InvalidArgumentException
946
-     * @throws InvalidInterfaceException
947
-     * @throws InvalidDataTypeException
948
-     * @throws DomainException
949
-     * @throws EE_Error
950
-     */
951
-    public function pricing_metabox()
952
-    {
953
-        $event          = $this->_adminpage_obj->get_cpt_model_obj();
954
-        $timezone       = $event instanceof EE_Event ? $event->timezone_string() : null;
955
-        $price_model    = EEM_Price::instance($timezone);
956
-        $ticket_model   = EEM_Ticket::instance($timezone);
957
-        $datetime_model = EEM_Datetime::instance($timezone);
958
-        $all_tickets    = [];
959
-
960
-        // set is_creating_event property.
961
-        $EVT_ID                   = $event->ID();
962
-        $this->_is_creating_event = empty($this->_req_data['post']);
963
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = [];
964
-
965
-        // default main template args
966
-        $main_template_args = [
967
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
968
-                'event_editor_event_datetimes_help_tab',
969
-                $this->_adminpage_obj->page_slug,
970
-                $this->_adminpage_obj->get_req_action()
971
-            ),
972
-
973
-            // todo need to add a filter to the template for the help text
974
-            // in the Events_Admin_Page core file so we can add further help
975
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
976
-                'add_new_dtt_info',
977
-                $this->_adminpage_obj->page_slug,
978
-                $this->_adminpage_obj->get_req_action()
979
-            ),
980
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
981
-            'datetime_rows'            => '',
982
-            'show_tickets_container'   => '',
983
-            'ticket_rows'              => '',
984
-            'ee_collapsible_status'    => ' ee-collapsible-open'
985
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
986
-        ];
987
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
988
-
989
-        /**
990
-         * 1. Start with retrieving Datetimes
991
-         * 2. For each datetime get related tickets
992
-         * 3. For each ticket get related prices
993
-         */
994
-        $datetimes                            = $datetime_model->get_all_event_dates($EVT_ID);
995
-        $main_template_args['total_dtt_rows'] = count($datetimes);
996
-
997
-        /**
998
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
999
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1000
-         */
1001
-        $datetime_row = 1;
1002
-        foreach ($datetimes as $datetime) {
1003
-            $DTT_ID = $datetime->get('DTT_ID');
1004
-            $datetime->set('DTT_order', $datetime_row);
1005
-            $existing_datetime_ids[] = $DTT_ID;
1006
-            // tickets attached
1007
-            $related_tickets = $datetime->ID() > 0
1008
-                ? $datetime->get_many_related(
1009
-                    'Ticket',
1010
-                    [
1011
-                        [
1012
-                            'OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0],
1013
-                        ],
1014
-                        'default_where_conditions' => 'none',
1015
-                        'order_by'                 => ['TKT_order' => 'ASC'],
1016
-                    ]
1017
-                )
1018
-                : [];
1019
-            // if there are no related tickets this is likely a new event OR auto-draft
1020
-            // event so we need to generate the default tickets because datetimes
1021
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1022
-            // datetime on the event.
1023
-            if (empty($related_tickets) && count($datetimes) < 2) {
1024
-                $related_tickets = $ticket_model->get_all_default_tickets();
1025
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1026
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1027
-                $default_prices      = $price_model->get_all_default_prices();
1028
-                $main_default_ticket = reset($related_tickets);
1029
-                if ($main_default_ticket instanceof EE_Ticket) {
1030
-                    foreach ($default_prices as $default_price) {
1031
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1032
-                            continue;
1033
-                        }
1034
-                        $main_default_ticket->cache('Price', $default_price);
1035
-                    }
1036
-                }
1037
-            }
1038
-            // we can't actually setup rows in this loop yet cause we don't know all
1039
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1040
-            // So we're going to temporarily cache some of that information.
1041
-            // loop through and setup the ticket rows and make sure the order is set.
1042
-            foreach ($related_tickets as $ticket) {
1043
-                $TKT_ID     = $ticket->get('TKT_ID');
1044
-                $ticket_row = $ticket->get('TKT_row');
1045
-                // we only want unique tickets in our final display!!
1046
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1047
-                    $existing_ticket_ids[] = $TKT_ID;
1048
-                    $all_tickets[]         = $ticket;
1049
-                }
1050
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1051
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1052
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1053
-                if (
1054
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1055
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1056
-                ) {
1057
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1058
-                }
1059
-            }
1060
-            $datetime_row++;
1061
-        }
1062
-        $main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
1063
-        $main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
1064
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1065
-        // sort $all_tickets by order
1066
-        usort(
1067
-            $all_tickets,
1068
-            function (EE_Ticket $a, EE_Ticket $b) {
1069
-                $a_order = (int) $a->get('TKT_order');
1070
-                $b_order = (int) $b->get('TKT_order');
1071
-                if ($a_order === $b_order) {
1072
-                    return 0;
1073
-                }
1074
-                return ($a_order < $b_order) ? -1 : 1;
1075
-            }
1076
-        );
1077
-        // k NOW we have all the data we need for setting up the datetime rows
1078
-        // and ticket rows so we start our datetime loop again.
1079
-        $datetime_row = 1;
1080
-        foreach ($datetimes as $datetime) {
1081
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1082
-                $datetime_row,
1083
-                $datetime,
1084
-                $datetime_tickets,
1085
-                $all_tickets,
1086
-                false,
1087
-                $datetimes
1088
-            );
1089
-            $datetime_row++;
1090
-        }
1091
-        // then loop through all tickets for the ticket rows.
1092
-        $ticket_row = 1;
1093
-        foreach ($all_tickets as $ticket) {
1094
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1095
-                $ticket_row,
1096
-                $ticket,
1097
-                $ticket_datetimes,
1098
-                $datetimes,
1099
-                false,
1100
-                $all_tickets
1101
-            );
1102
-            $ticket_row++;
1103
-        }
1104
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1105
-
1106
-        $status_change_notice = LoaderFactory::getLoader()->getShared(
1107
-            'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
1108
-        );
1109
-
1110
-        $main_template_args['status_change_notice'] = $status_change_notice->display(
1111
-            '__event-editor',
1112
-            'espresso-events'
1113
-        );
1114
-
1115
-        EEH_Template::display_template(
1116
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1117
-            $main_template_args
1118
-        );
1119
-    }
1120
-
1121
-
1122
-    /**
1123
-     * @param int|string  $datetime_row
1124
-     * @param EE_Datetime $datetime
1125
-     * @param array       $datetime_tickets
1126
-     * @param array       $all_tickets
1127
-     * @param bool        $default
1128
-     * @param array       $all_datetimes
1129
-     * @return string
1130
-     * @throws DomainException
1131
-     * @throws EE_Error
1132
-     * @throws ReflectionException
1133
-     */
1134
-    protected function _get_datetime_row(
1135
-        $datetime_row,
1136
-        EE_Datetime $datetime,
1137
-        array $datetime_tickets = [],
1138
-        array $all_tickets = [],
1139
-        bool $default = false,
1140
-        array $all_datetimes = []
1141
-    ): string {
1142
-        return EEH_Template::display_template(
1143
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1144
-            [
1145
-                'dtt_edit_row'             => $this->_get_dtt_edit_row(
1146
-                    $datetime_row,
1147
-                    $datetime,
1148
-                    $default,
1149
-                    $all_datetimes
1150
-                ),
1151
-                'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1152
-                    $datetime_row,
1153
-                    $datetime,
1154
-                    $datetime_tickets,
1155
-                    $all_tickets,
1156
-                    $default
1157
-                ),
1158
-                'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1159
-            ],
1160
-            true
1161
-        );
1162
-    }
1163
-
1164
-
1165
-    /**
1166
-     * This method is used to generate a datetime fields  edit row.
1167
-     * The same row is used to generate a row with valid DTT objects
1168
-     * and the default row that is used as the skeleton by the js.
1169
-     *
1170
-     * @param int|string       $datetime_row  The row number for the row being generated.
1171
-     * @param EE_Datetime|null $datetime
1172
-     * @param bool             $default       Whether a default row is being generated or not.
1173
-     * @param EE_Datetime[]    $all_datetimes This is the array of all datetimes used in the editor.
1174
-     * @return string
1175
-     * @throws EE_Error
1176
-     * @throws ReflectionException
1177
-     */
1178
-    protected function _get_dtt_edit_row(
1179
-        $datetime_row,
1180
-        ?EE_Datetime $datetime,
1181
-        bool $default,
1182
-        array $all_datetimes
1183
-    ): string {
1184
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1185
-        $default                     = ! $datetime instanceof EE_Datetime ? true : $default;
1186
-        $template_args               = [
1187
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1188
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1189
-            'edit_dtt_expanded'    => '',
1190
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1191
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1192
-            'DTT_description'      => $default ? '' : $datetime->get_raw('DTT_description'),
1193
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1194
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1195
-            'DTT_reg_limit'        => $default
1196
-                ? ''
1197
-                : $datetime->get_pretty(
1198
-                    'DTT_reg_limit',
1199
-                    'input'
1200
-                ),
1201
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1202
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1203
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1204
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1205
-                ? ''
1206
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1207
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1208
-                ? 'dashicons dashicons-lock'
1209
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1210
-            'reg_list_url'         => $default || ! $datetime->event() instanceof EE_Event
1211
-                ? ''
1212
-                : EE_Admin_Page::add_query_args_and_nonce(
1213
-                    [
1214
-                        'event_id'    => $datetime->event()->ID(),
1215
-                        'datetime_id' => $datetime->ID(),
1216
-                        'use_filters' => true,
1217
-                    ],
1218
-                    REG_ADMIN_URL
1219
-                ),
1220
-        ];
1221
-        $template_args['show_trash'] = count($all_datetimes) === 1
1222
-                                       && $template_args['trash_icon'] !== 'dashicons dashicons-lock'
1223
-            ? 'display:none'
1224
-            : '';
1225
-        // allow filtering of template args at this point.
1226
-        $template_args = apply_filters(
1227
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1228
-            $template_args,
1229
-            $datetime_row,
1230
-            $datetime,
1231
-            $default,
1232
-            $all_datetimes,
1233
-            $this->_is_creating_event
1234
-        );
1235
-        return EEH_Template::display_template(
1236
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1237
-            $template_args,
1238
-            true
1239
-        );
1240
-    }
1241
-
1242
-
1243
-    /**
1244
-     * @param int|string       $datetime_row
1245
-     * @param EE_Datetime|null $datetime
1246
-     * @param array            $datetime_tickets
1247
-     * @param array            $all_tickets
1248
-     * @param bool             $default
1249
-     * @return string
1250
-     * @throws DomainException
1251
-     * @throws EE_Error
1252
-     * @throws ReflectionException
1253
-     */
1254
-    protected function _get_dtt_attached_tickets_row(
1255
-        $datetime_row,
1256
-        ?EE_Datetime $datetime,
1257
-        array $datetime_tickets = [],
1258
-        array $all_tickets = [],
1259
-        bool $default = false
1260
-    ): string {
1261
-        $template_args = [
1262
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1263
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1264
-            'DTT_description'                   => $default ? '' : $datetime->get_raw('DTT_description'),
1265
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1266
-            'show_tickets_row'                  => 'display:none;',
1267
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1268
-                'add_new_ticket_via_datetime',
1269
-                $this->_adminpage_obj->page_slug,
1270
-                $this->_adminpage_obj->get_req_action()
1271
-            ),
1272
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1273
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1274
-        ];
1275
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1276
-        if (! $default) {
1277
-            $ticket_row = 1;
1278
-            foreach ($all_tickets as $ticket) {
1279
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1280
-                    $datetime_row,
1281
-                    $ticket_row,
1282
-                    $datetime,
1283
-                    $ticket,
1284
-                    $datetime_tickets
1285
-                );
1286
-                $ticket_row++;
1287
-            }
1288
-        }
1289
-        // filter template args at this point
1290
-        $template_args = apply_filters(
1291
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1292
-            $template_args,
1293
-            $datetime_row,
1294
-            $datetime,
1295
-            $datetime_tickets,
1296
-            $all_tickets,
1297
-            $default,
1298
-            $this->_is_creating_event
1299
-        );
1300
-        return EEH_Template::display_template(
1301
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1302
-            $template_args,
1303
-            true
1304
-        );
1305
-    }
1306
-
1307
-
1308
-    /**
1309
-     * @param int|string       $datetime_row
1310
-     * @param int|string       $ticket_row
1311
-     * @param EE_Datetime|null $datetime
1312
-     * @param EE_Ticket|null   $ticket
1313
-     * @param array            $datetime_tickets
1314
-     * @param bool             $default
1315
-     * @return string
1316
-     * @throws EE_Error
1317
-     * @throws ReflectionException
1318
-     */
1319
-    protected function _get_datetime_tickets_list_item(
1320
-        $datetime_row,
1321
-        $ticket_row,
1322
-        ?EE_Datetime $datetime,
1323
-        ?EE_Ticket $ticket,
1324
-        array $datetime_tickets = [],
1325
-        bool $default = false
1326
-    ): string {
1327
-        $datetime_tickets = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1328
-            ? $datetime_tickets[ $datetime->ID() ]
1329
-            : [];
1330
-        $display_row      = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1331
-        $no_ticket        = $default && empty($ticket);
1332
-        $template_args    = [
1333
-            'dtt_row'                 => $default
1334
-                ? 'DTTNUM'
1335
-                : $datetime_row,
1336
-            'tkt_row'                 => $no_ticket
1337
-                ? 'TICKETNUM'
1338
-                : $ticket_row,
1339
-            'datetime_ticket_checked' => in_array($display_row, $datetime_tickets, true)
1340
-                ? ' checked'
1341
-                : '',
1342
-            'ticket_selected'         => in_array($display_row, $datetime_tickets, true)
1343
-                ? ' ticket-selected'
1344
-                : '',
1345
-            'TKT_name'                => $no_ticket
1346
-                ? 'TKTNAME'
1347
-                : $ticket->get('TKT_name'),
1348
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1349
-                ? ' tkt-status-' . EE_Ticket::onsale
1350
-                : ' tkt-status-' . $ticket->ticket_status(),
1351
-        ];
1352
-        // filter template args
1353
-        $template_args = apply_filters(
1354
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1355
-            $template_args,
1356
-            $datetime_row,
1357
-            $ticket_row,
1358
-            $datetime,
1359
-            $ticket,
1360
-            $datetime_tickets,
1361
-            $default,
1362
-            $this->_is_creating_event
1363
-        );
1364
-        return EEH_Template::display_template(
1365
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1366
-            $template_args,
1367
-            true
1368
-        );
1369
-    }
1370
-
1371
-
1372
-    /**
1373
-     * This generates the ticket row for tickets.
1374
-     * This same method is used to generate both the actual rows and the js skeleton row
1375
-     * (when default === true)
1376
-     *
1377
-     * @param int|string     $ticket_row       Represents the row number being generated.
1378
-     * @param EE_Ticket|null $ticket
1379
-     * @param EE_Datetime[]  $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1380
-     *                                         or empty for default
1381
-     * @param EE_Datetime[]  $all_datetimes    All Datetimes on the event or empty for default.
1382
-     * @param bool           $default          Whether default row being generated or not.
1383
-     * @param EE_Ticket[]    $all_tickets      This is an array of all tickets attached to the event
1384
-     *                                         (or empty in the case of defaults)
1385
-     * @return string
1386
-     * @throws InvalidArgumentException
1387
-     * @throws InvalidInterfaceException
1388
-     * @throws InvalidDataTypeException
1389
-     * @throws DomainException
1390
-     * @throws EE_Error
1391
-     * @throws ReflectionException
1392
-     */
1393
-    protected function _get_ticket_row(
1394
-        $ticket_row,
1395
-        ?EE_Ticket $ticket,
1396
-        array $ticket_datetimes,
1397
-        array $all_datetimes,
1398
-        bool $default = false,
1399
-        array $all_tickets = []
1400
-    ): string {
1401
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1402
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1403
-        $prices  = ! empty($ticket) && ! $default
1404
-            ? $ticket->get_many_related(
1405
-                'Price',
1406
-                ['default_where_conditions' => 'none', 'order_by' => ['PRC_order' => 'ASC']]
1407
-            )
1408
-            : [];
1409
-        // if there is only one price (which would be the base price)
1410
-        // or NO prices and this ticket is a default ticket,
1411
-        // let's just make sure there are no cached default prices on the object.
1412
-        // This is done by not including any query_params.
1413
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1414
-            $prices = $ticket->prices();
1415
-        }
1416
-        // check if we're dealing with a default ticket in which case
1417
-        // we don't want any starting_ticket_datetime_row values set
1418
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1419
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1420
-        $default_datetime = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1421
-        $ticket_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1422
-            ? $ticket_datetimes[ $ticket->ID() ]
1423
-            : [];
1424
-        $ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1425
-        $base_price       = $default ? null : $ticket->base_price();
1426
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1427
-        // breaking out complicated condition for ticket_status
1428
-        if ($default) {
1429
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1430
-        } else {
1431
-            $ticket_status_class = $ticket->is_default()
1432
-                ? ' tkt-status-' . EE_Ticket::onsale
1433
-                : ' tkt-status-' . $ticket->ticket_status();
1434
-        }
1435
-        // breaking out complicated condition for TKT_taxable
1436
-        if ($default) {
1437
-            $TKT_taxable = '';
1438
-        } else {
1439
-            $TKT_taxable = $ticket->taxable()
1440
-                ? 'checked'
1441
-                : '';
1442
-        }
1443
-        if ($default) {
1444
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1445
-        } elseif ($ticket->is_default()) {
1446
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1447
-        } else {
1448
-            $TKT_status = $ticket->ticket_status(true);
1449
-        }
1450
-        if ($default) {
1451
-            $TKT_min = '';
1452
-        } else {
1453
-            $TKT_min = $ticket->min();
1454
-            if ($TKT_min === -1 || $TKT_min === 0) {
1455
-                $TKT_min = '';
1456
-            }
1457
-        }
1458
-        $template_args                 = [
1459
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1460
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1461
-            // on initial page load this will always be the correct order.
1462
-            'tkt_status_class'              => $ticket_status_class,
1463
-            'display_edit_tkt_row'          => 'display:none;',
1464
-            'edit_tkt_expanded'             => '',
1465
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1466
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1467
-            'TKT_start_date'                => $default
1468
-                ? ''
1469
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1470
-            'TKT_end_date'                  => $default
1471
-                ? ''
1472
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1473
-            'TKT_status'                    => $TKT_status,
1474
-            'TKT_price'                     => $default
1475
-                ? ''
1476
-                : EEH_Template::format_currency(
1477
-                    $ticket->get_ticket_total_with_taxes(),
1478
-                    false,
1479
-                    false
1480
-                ),
1481
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1482
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1483
-            'TKT_qty'                       => $default
1484
-                ? ''
1485
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1486
-            'TKT_qty_for_input'             => $default
1487
-                ? ''
1488
-                : $ticket->get_pretty('TKT_qty', 'input'),
1489
-            'TKT_uses'                      => $default
1490
-                ? ''
1491
-                : $ticket->get_pretty('TKT_uses', 'input'),
1492
-            'TKT_min'                       => $TKT_min,
1493
-            'TKT_max'                       => $default
1494
-                ? ''
1495
-                : $ticket->get_pretty('TKT_max', 'input'),
1496
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold(),
1497
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1498
-            'TKT_registrations'             => $default
1499
-                ? 0
1500
-                : $ticket->count_registrations(
1501
-                    [
1502
-                        [
1503
-                            'STS_ID' => [
1504
-                                '!=',
1505
-                                EEM_Registration::status_id_incomplete,
1506
-                            ],
1507
-                        ],
1508
-                    ]
1509
-                ),
1510
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1511
-            'TKT_description'               => $default ? '' : $ticket->get_raw('TKT_description'),
1512
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1513
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1514
-            'TKT_is_default_selector'       => '',
1515
-            'ticket_price_rows'             => '',
1516
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1517
-                ? ''
1518
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1519
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1520
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1521
-                ? ''
1522
-                : 'display:none;',
1523
-            'show_price_mod_button'         => count($prices) > 1
1524
-                                               || ($default && $count_price_mods > 0)
1525
-                                               || (! $default && $ticket->deleted())
1526
-                ? 'display:none;'
1527
-                : '',
1528
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1529
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1530
-            'starting_ticket_datetime_rows' => $default || $default_datetime ? '' : implode(',', $ticket_datetimes),
1531
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $ticket_datetimes),
1532
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1533
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1534
-            'TKT_taxable'                   => $TKT_taxable,
1535
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1536
-                ? ''
1537
-                : 'display:none;',
1538
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1539
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1540
-                $ticket_subtotal,
1541
-                false,
1542
-                false
1543
-            ),
1544
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1545
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1546
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1547
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1548
-                ? ' ticket-archived'
1549
-                : '',
1550
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1551
-                                               && $ticket->deleted()
1552
-                                               && ! $ticket->is_permanently_deleteable()
1553
-                ? 'dashicons dashicons-lock '
1554
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1555
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1556
-                ? ''
1557
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1558
-        ];
1559
-        $template_args['trash_hidden'] = count($all_tickets) === 1
1560
-                                         && $template_args['trash_icon'] !== 'dashicons dashicons-lock'
1561
-            ? 'display:none'
1562
-            : '';
1563
-        // handle rows that should NOT be empty
1564
-        if (empty($template_args['TKT_start_date'])) {
1565
-            // if empty then the start date will be now.
1566
-            $template_args['TKT_start_date']   = date(
1567
-                $this->_date_time_format,
1568
-                current_time('timestamp')
1569
-            );
1570
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1571
-        }
1572
-        if (empty($template_args['TKT_end_date'])) {
1573
-            // get the earliest datetime (if present);
1574
-            $earliest_datetime = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1575
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1576
-                    'Datetime',
1577
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1578
-                )
1579
-                : null;
1580
-            if (! empty($earliest_datetime)) {
1581
-                $template_args['TKT_end_date'] = $earliest_datetime->get_datetime(
1582
-                    'DTT_EVT_start',
1583
-                    $this->_date_time_format
1584
-                );
1585
-            } else {
1586
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1587
-                $template_args['TKT_end_date'] = date(
1588
-                    $this->_date_time_format,
1589
-                    mktime(
1590
-                        24,
1591
-                        0,
1592
-                        0,
1593
-                        date('m'),
1594
-                        date('d') + 29,
1595
-                        date('Y')
1596
-                    )
1597
-                );
1598
-            }
1599
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1600
-        }
1601
-        // generate ticket_datetime items
1602
-        if (! $default) {
1603
-            $datetime_row = 1;
1604
-            foreach ($all_datetimes as $datetime) {
1605
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1606
-                    $datetime_row,
1607
-                    $ticket_row,
1608
-                    $datetime,
1609
-                    $ticket,
1610
-                    $ticket_datetimes,
1611
-                    $default
1612
-                );
1613
-                $datetime_row++;
1614
-            }
1615
-        }
1616
-        $price_row = 1;
1617
-        foreach ($prices as $price) {
1618
-            if (! $price instanceof EE_Price) {
1619
-                continue;
1620
-            }
1621
-            if ($price->is_base_price()) {
1622
-                $price_row++;
1623
-                continue;
1624
-            }
1625
-
1626
-            $show_trash  = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1627
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1628
-
1629
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1630
-                $ticket_row,
1631
-                $price_row,
1632
-                $price,
1633
-                $default,
1634
-                $ticket,
1635
-                $show_trash,
1636
-                $show_create
1637
-            );
1638
-            $price_row++;
1639
-        }
1640
-        // filter $template_args
1641
-        $template_args = apply_filters(
1642
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1643
-            $template_args,
1644
-            $ticket_row,
1645
-            $ticket,
1646
-            $ticket_datetimes,
1647
-            $all_datetimes,
1648
-            $default,
1649
-            $all_tickets,
1650
-            $this->_is_creating_event
1651
-        );
1652
-        return EEH_Template::display_template(
1653
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1654
-            $template_args,
1655
-            true
1656
-        );
1657
-    }
1658
-
1659
-
1660
-    /**
1661
-     * @param int|string     $ticket_row
1662
-     * @param EE_Ticket|null $ticket
1663
-     * @return string
1664
-     * @throws DomainException
1665
-     * @throws EE_Error
1666
-     * @throws ReflectionException
1667
-     */
1668
-    protected function _get_tax_rows($ticket_row, ?EE_Ticket $ticket): string
1669
-    {
1670
-        $tax_rows = '';
1671
-        /** @var EE_Price[] $taxes */
1672
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1673
-        foreach ($taxes as $tax) {
1674
-            $tax_added     = $this->_get_tax_added($tax, $ticket);
1675
-            $template_args = [
1676
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1677
-                    ? ''
1678
-                    : 'display:none;',
1679
-                'tax_id'            => $tax->ID(),
1680
-                'tkt_row'           => $ticket_row,
1681
-                'tax_label'         => $tax->get('PRC_name'),
1682
-                'tax_added'         => $tax_added,
1683
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1684
-                'tax_amount'        => $tax->get('PRC_amount'),
1685
-            ];
1686
-            $template_args = apply_filters(
1687
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1688
-                $template_args,
1689
-                $ticket_row,
1690
-                $ticket,
1691
-                $this->_is_creating_event
1692
-            );
1693
-            $tax_rows      .= EEH_Template::display_template(
1694
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1695
-                $template_args,
1696
-                true
1697
-            );
1698
-        }
1699
-        return $tax_rows;
1700
-    }
1701
-
1702
-
1703
-    /**
1704
-     * @param EE_Price       $tax
1705
-     * @param EE_Ticket|null $ticket
1706
-     * @return float|int
1707
-     * @throws EE_Error
1708
-     * @throws ReflectionException
1709
-     */
1710
-    protected function _get_tax_added(EE_Price $tax, ?EE_Ticket $ticket)
1711
-    {
1712
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1713
-        return $subtotal * $tax->get('PRC_amount') / 100;
1714
-    }
1715
-
1716
-
1717
-    /**
1718
-     * @param int|string     $ticket_row
1719
-     * @param int|string     $price_row
1720
-     * @param EE_Price|null  $price
1721
-     * @param bool           $default
1722
-     * @param EE_Ticket|null $ticket
1723
-     * @param bool           $show_trash
1724
-     * @param bool           $show_create
1725
-     * @return string
1726
-     * @throws InvalidArgumentException
1727
-     * @throws InvalidInterfaceException
1728
-     * @throws InvalidDataTypeException
1729
-     * @throws DomainException
1730
-     * @throws EE_Error
1731
-     * @throws ReflectionException
1732
-     */
1733
-    protected function _get_ticket_price_row(
1734
-        $ticket_row,
1735
-        $price_row,
1736
-        ?EE_Price $price,
1737
-        bool $default,
1738
-        ?EE_Ticket $ticket,
1739
-        bool $show_trash = true,
1740
-        bool $show_create = true
1741
-    ): string {
1742
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1743
-        $template_args = [
1744
-            'tkt_row'               => $default && empty($ticket)
1745
-                ? 'TICKETNUM'
1746
-                : $ticket_row,
1747
-            'PRC_order'             => $default && empty($price)
1748
-                ? 'PRICENUM'
1749
-                : $price_row,
1750
-            'edit_prices_name'      => $default && empty($price)
1751
-                ? 'PRICENAMEATTR'
1752
-                : 'edit_prices',
1753
-            'price_type_selector'   => $default && empty($price)
1754
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, true)
1755
-                : $this->_get_price_type_selector(
1756
-                    $ticket_row,
1757
-                    $price_row,
1758
-                    $price,
1759
-                    $default,
1760
-                    $send_disabled
1761
-                ),
1762
-            'PRC_ID'                => $default && empty($price)
1763
-                ? 0
1764
-                : $price->ID(),
1765
-            'PRC_is_default'        => $default && empty($price)
1766
-                ? 0
1767
-                : $price->get('PRC_is_default'),
1768
-            'PRC_name'              => $default && empty($price)
1769
-                ? ''
1770
-                : $price->get('PRC_name'),
1771
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1772
-            'show_plus_or_minus'    => $default && empty($price)
1773
-                ? ''
1774
-                : 'display:none;',
1775
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1776
-                ? 'display:none;'
1777
-                : '',
1778
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1779
-                ? 'display:none;'
1780
-                : '',
1781
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1782
-                ? 'display:none'
1783
-                : '',
1784
-            'PRC_amount'            => $default && empty($price)
1785
-                ? 0
1786
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1787
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1788
-                ? 'display:none;'
1789
-                : '',
1790
-            'show_trash_icon'       => $show_trash
1791
-                ? ''
1792
-                : ' style="display:none;"',
1793
-            'show_create_button'    => $show_create
1794
-                ? ''
1795
-                : ' style="display:none;"',
1796
-            'PRC_desc'              => $default && empty($price)
1797
-                ? ''
1798
-                : $price->get('PRC_desc'),
1799
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1800
-        ];
1801
-        $template_args = apply_filters(
1802
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1803
-            $template_args,
1804
-            $ticket_row,
1805
-            $price_row,
1806
-            $price,
1807
-            $default,
1808
-            $ticket,
1809
-            $show_trash,
1810
-            $show_create,
1811
-            $this->_is_creating_event
1812
-        );
1813
-        return EEH_Template::display_template(
1814
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1815
-            $template_args,
1816
-            true
1817
-        );
1818
-    }
1819
-
1820
-
1821
-    /**
1822
-     * @param int|string    $ticket_row
1823
-     * @param int|string    $price_row
1824
-     * @param EE_Price|null $price
1825
-     * @param bool          $default
1826
-     * @param bool          $disabled
1827
-     * @return string
1828
-     * @throws ReflectionException
1829
-     * @throws InvalidArgumentException
1830
-     * @throws InvalidInterfaceException
1831
-     * @throws InvalidDataTypeException
1832
-     * @throws DomainException
1833
-     * @throws EE_Error
1834
-     */
1835
-    protected function _get_price_type_selector(
1836
-        $ticket_row,
1837
-        $price_row,
1838
-        ?EE_Price $price,
1839
-        bool $default,
1840
-        bool $disabled = false
1841
-    ): string {
1842
-        if ($price->is_base_price()) {
1843
-            return $this->_get_base_price_template(
1844
-                $ticket_row,
1845
-                $price_row,
1846
-                $price,
1847
-                $default
1848
-            );
1849
-        }
1850
-        return $this->_get_price_modifier_template(
1851
-            $ticket_row,
1852
-            $price_row,
1853
-            $price,
1854
-            $default,
1855
-            $disabled
1856
-        );
1857
-    }
1858
-
1859
-
1860
-    /**
1861
-     * @param int|string    $ticket_row
1862
-     * @param int|string    $price_row
1863
-     * @param EE_Price|null $price
1864
-     * @param bool          $default
1865
-     * @return string
1866
-     * @throws DomainException
1867
-     * @throws EE_Error
1868
-     * @throws ReflectionException
1869
-     */
1870
-    protected function _get_base_price_template(
1871
-        $ticket_row,
1872
-        $price_row,
1873
-        ?EE_Price $price,
1874
-        bool $default
1875
-    ): string {
1876
-        $template_args = [
1877
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1878
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1879
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1880
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1881
-            'price_selected_operator'   => '+',
1882
-            'price_selected_is_percent' => 0,
1883
-        ];
1884
-        $template_args = apply_filters(
1885
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1886
-            $template_args,
1887
-            $ticket_row,
1888
-            $price_row,
1889
-            $price,
1890
-            $default,
1891
-            $this->_is_creating_event
1892
-        );
1893
-        return EEH_Template::display_template(
1894
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1895
-            $template_args,
1896
-            true
1897
-        );
1898
-    }
1899
-
1900
-
1901
-    /**
1902
-     * @param int|string    $ticket_row
1903
-     * @param int|string    $price_row
1904
-     * @param EE_Price|null $price
1905
-     * @param bool          $default
1906
-     * @param bool          $disabled
1907
-     * @return string
1908
-     * @throws ReflectionException
1909
-     * @throws InvalidArgumentException
1910
-     * @throws InvalidInterfaceException
1911
-     * @throws InvalidDataTypeException
1912
-     * @throws DomainException
1913
-     * @throws EE_Error
1914
-     */
1915
-    protected function _get_price_modifier_template(
1916
-        $ticket_row,
1917
-        $price_row,
1918
-        ?EE_Price $price,
1919
-        bool $default,
1920
-        bool $disabled = false
1921
-    ): string {
1922
-        $select_name = $default && ! $price instanceof EE_Price
1923
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1924
-            : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1925
-
1926
-        $price_type_model       = EEM_Price_Type::instance();
1927
-        $price_types            = $price_type_model->get_all(
1928
-            [
1929
-                [
1930
-                    'OR' => [
1931
-                        'PBT_ID'  => '2',
1932
-                        'PBT_ID*' => '3',
1933
-                    ],
1934
-                ],
1935
-            ]
1936
-        );
1937
-        $all_price_types        = $default && ! $price instanceof EE_Price
1938
-            ? [esc_html__('Select Modifier', 'event_espresso')]
1939
-            : [];
1940
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1941
-        $price_option_spans     = '';
1942
-        // setup price types for selector
1943
-        foreach ($price_types as $price_type) {
1944
-            if (! $price_type instanceof EE_Price_Type) {
1945
-                continue;
1946
-            }
1947
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1948
-            // while we're in the loop let's setup the option spans used by js
1949
-            $span_args          = [
1950
-                'PRT_ID'         => $price_type->ID(),
1951
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1952
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1953
-            ];
1954
-            $price_option_spans .= EEH_Template::display_template(
1955
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1956
-                $span_args,
1957
-                true
1958
-            );
1959
-        }
1960
-
1961
-        $select_name = $disabled
1962
-            ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1963
-            : $select_name;
1964
-
1965
-        $select_input = new EE_Select_Input(
1966
-            $all_price_types,
1967
-            [
1968
-                'default'               => $selected_price_type_id,
1969
-                'html_name'             => $select_name,
1970
-                'html_class'            => 'edit-price-PRT_ID',
1971
-                'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1972
-            ]
1973
-        );
1974
-
1975
-        $price_selected_operator   = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1976
-        $price_selected_operator   = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1977
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1978
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1979
-        $template_args             = [
1980
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1981
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1982
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1983
-            'main_name'                 => $select_name,
1984
-            'selected_price_type_id'    => $selected_price_type_id,
1985
-            'price_option_spans'        => $price_option_spans,
1986
-            'price_selected_operator'   => $price_selected_operator,
1987
-            'price_selected_is_percent' => $price_selected_is_percent,
1988
-            'disabled'                  => $disabled,
1989
-        ];
1990
-        $template_args             = apply_filters(
1991
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992
-            $template_args,
1993
-            $ticket_row,
1994
-            $price_row,
1995
-            $price,
1996
-            $default,
1997
-            $disabled,
1998
-            $this->_is_creating_event
1999
-        );
2000
-        return EEH_Template::display_template(
2001
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2002
-            $template_args,
2003
-            true
2004
-        );
2005
-    }
2006
-
2007
-
2008
-    /**
2009
-     * @param int|string       $datetime_row
2010
-     * @param int|string       $ticket_row
2011
-     * @param EE_Datetime|null $datetime
2012
-     * @param EE_Ticket|null   $ticket
2013
-     * @param array            $ticket_datetimes
2014
-     * @param bool             $default
2015
-     * @return string
2016
-     * @throws DomainException
2017
-     * @throws EE_Error
2018
-     * @throws ReflectionException
2019
-     */
2020
-    protected function _get_ticket_datetime_list_item(
2021
-        $datetime_row,
2022
-        $ticket_row,
2023
-        ?EE_Datetime $datetime,
2024
-        ?EE_Ticket $ticket,
2025
-        array $ticket_datetimes = [],
2026
-        bool $default = false
2027
-    ): string {
2028
-        $ticket_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2029
-            ? $ticket_datetimes[ $ticket->ID() ]
2030
-            : [];
2031
-        $template_args    = [
2032
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2033
-                ? 'DTTNUM'
2034
-                : $datetime_row,
2035
-            'tkt_row'                  => $default
2036
-                ? 'TICKETNUM'
2037
-                : $ticket_row,
2038
-            'ticket_datetime_selected' => in_array($datetime_row, $ticket_datetimes, true)
2039
-                ? ' ticket-selected'
2040
-                : '',
2041
-            'ticket_datetime_checked'  => in_array($datetime_row, $ticket_datetimes, true)
2042
-                ? ' checked'
2043
-                : '',
2044
-            'DTT_name'                 => $default && empty($datetime)
2045
-                ? 'DTTNAME'
2046
-                : $datetime->get_dtt_display_name(true),
2047
-            'tkt_status_class'         => '',
2048
-        ];
2049
-        $template_args    = apply_filters(
2050
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2051
-            $template_args,
2052
-            $datetime_row,
2053
-            $ticket_row,
2054
-            $datetime,
2055
-            $ticket,
2056
-            $ticket_datetimes,
2057
-            $default,
2058
-            $this->_is_creating_event
2059
-        );
2060
-        return EEH_Template::display_template(
2061
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2062
-            $template_args,
2063
-            true
2064
-        );
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     * @param array $all_datetimes
2070
-     * @param array $all_tickets
2071
-     * @return string
2072
-     * @throws ReflectionException
2073
-     * @throws InvalidArgumentException
2074
-     * @throws InvalidInterfaceException
2075
-     * @throws InvalidDataTypeException
2076
-     * @throws DomainException
2077
-     * @throws EE_Error
2078
-     */
2079
-    protected function _get_ticket_js_structure(array $all_datetimes = [], array $all_tickets = []): string
2080
-    {
2081
-        $template_args = [
2082
-            'default_datetime_edit_row' => $this->_get_dtt_edit_row(
2083
-                'DTTNUM',
2084
-                null,
2085
-                true,
2086
-                $all_datetimes
2087
-            ),
2088
-            'default_ticket_row'        => $this->_get_ticket_row(
2089
-                'TICKETNUM',
2090
-                null,
2091
-                [],
2092
-                [],
2093
-                true
2094
-            ),
2095
-            'default_price_row'         => $this->_get_ticket_price_row(
2096
-                'TICKETNUM',
2097
-                'PRICENUM',
2098
-                null,
2099
-                true,
2100
-                null
2101
-            ),
2102
-
2103
-            'default_price_rows'                       => '',
2104
-            'default_base_price_amount'                => 0,
2105
-            'default_base_price_name'                  => '',
2106
-            'default_base_price_description'           => '',
2107
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2108
-                'TICKETNUM',
2109
-                'PRICENUM',
2110
-                null,
2111
-                true
2112
-            ),
2113
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2114
-                'DTTNUM',
2115
-                null,
2116
-                [],
2117
-                [],
2118
-                true
2119
-            ),
2120
-            'existing_available_datetime_tickets_list' => '',
2121
-            'existing_available_ticket_datetimes_list' => '',
2122
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2123
-                'DTTNUM',
2124
-                'TICKETNUM',
2125
-                null,
2126
-                null,
2127
-                [],
2128
-                true
2129
-            ),
2130
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2131
-                'DTTNUM',
2132
-                'TICKETNUM',
2133
-                null,
2134
-                null,
2135
-                [],
2136
-                true
2137
-            ),
2138
-        ];
2139
-        $ticket_row    = 1;
2140
-        foreach ($all_tickets as $ticket) {
2141
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142
-                'DTTNUM',
2143
-                $ticket_row,
2144
-                null,
2145
-                $ticket,
2146
-                [],
2147
-                true
2148
-            );
2149
-            $ticket_row++;
2150
-        }
2151
-        $datetime_row = 1;
2152
-        foreach ($all_datetimes as $datetime) {
2153
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2154
-                $datetime_row,
2155
-                'TICKETNUM',
2156
-                $datetime,
2157
-                null,
2158
-                [],
2159
-                true
2160
-            );
2161
-            $datetime_row++;
2162
-        }
2163
-        $price_model    = EEM_Price::instance();
2164
-        $default_prices = $price_model->get_all_default_prices();
2165
-        $price_row      = 1;
2166
-        foreach ($default_prices as $price) {
2167
-            if (! $price instanceof EE_Price) {
2168
-                continue;
2169
-            }
2170
-            if ($price->is_base_price()) {
2171
-                $template_args['default_base_price_amount']      = $price->get_pretty(
2172
-                    'PRC_amount',
2173
-                    'localized_float'
2174
-                );
2175
-                $template_args['default_base_price_name']        = $price->get('PRC_name');
2176
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2177
-                $price_row++;
2178
-                continue;
2179
-            }
2180
-
2181
-            $show_trash  = ! ((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1);
2182
-            $show_create = ! (count($default_prices) > 1 && count($default_prices) !== $price_row);
2183
-
2184
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2185
-                'TICKETNUM',
2186
-                $price_row,
2187
-                $price,
2188
-                true,
2189
-                null,
2190
-                $show_trash,
2191
-                $show_create
2192
-            );
2193
-            $price_row++;
2194
-        }
2195
-        $template_args = apply_filters(
2196
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2197
-            $template_args,
2198
-            $all_datetimes,
2199
-            $all_tickets,
2200
-            $this->_is_creating_event
2201
-        );
2202
-        return EEH_Template::display_template(
2203
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2204
-            $template_args,
2205
-            true
2206
-        );
2207
-    }
231
+					],
232
+					'DTT_OVERSELL_WARNING'  => [
233
+						'datetime_ticket' => esc_html__(
234
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
235
+							'event_espresso'
236
+						),
237
+						'ticket_datetime' => esc_html__(
238
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
239
+							'event_espresso'
240
+						),
241
+					],
242
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
243
+						$this->_date_format_strings['date'],
244
+						$this->_date_format_strings['time']
245
+					),
246
+					'DTT_START_OF_WEEK'     => ['dayValue' => (int) get_option('start_of_week')],
247
+				],
248
+			],
249
+		];
250
+	}
251
+
252
+
253
+	/**
254
+	 * @param array $update_callbacks
255
+	 * @return array
256
+	 */
257
+	public function caf_updates(array $update_callbacks): array
258
+	{
259
+		unset($update_callbacks['_default_tickets_update']);
260
+		$update_callbacks['datetime_and_tickets_caf_update'] = [$this, 'datetime_and_tickets_caf_update'];
261
+		return $update_callbacks;
262
+	}
263
+
264
+
265
+	/**
266
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
267
+	 *
268
+	 * @param EE_Event $event The Event object we're attaching data to
269
+	 * @param array    $data  The request data from the form
270
+	 * @throws ReflectionException
271
+	 * @throws Exception
272
+	 * @throws InvalidInterfaceException
273
+	 * @throws InvalidDataTypeException
274
+	 * @throws EE_Error
275
+	 * @throws InvalidArgumentException
276
+	 */
277
+	public function datetime_and_tickets_caf_update(EE_Event $event, array $data)
278
+	{
279
+		// first we need to start with datetimes cause they are the "root" items attached to events.
280
+		$saved_datetimes = $this->_update_datetimes($event, $data);
281
+		// next tackle the tickets (and prices?)
282
+		$this->_update_tickets($event, $saved_datetimes, $data);
283
+	}
284
+
285
+
286
+	/**
287
+	 * update event_datetimes
288
+	 *
289
+	 * @param EE_Event $event Event being updated
290
+	 * @param array    $data  the request data from the form
291
+	 * @return EE_Datetime[]
292
+	 * @throws Exception
293
+	 * @throws ReflectionException
294
+	 * @throws InvalidInterfaceException
295
+	 * @throws InvalidDataTypeException
296
+	 * @throws InvalidArgumentException
297
+	 * @throws EE_Error
298
+	 */
299
+	protected function _update_datetimes(EE_Event $event, array $data): array
300
+	{
301
+		$saved_datetime_ids  = [];
302
+		$saved_datetime_objs = [];
303
+		$timezone       = $data['timezone_string'] ?? null;
304
+		$datetime_model = EEM_Datetime::instance($timezone);
305
+
306
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
307
+			throw new InvalidArgumentException(
308
+				esc_html__(
309
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
310
+					'event_espresso'
311
+				)
312
+			);
313
+		}
314
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
315
+			// trim all values to ensure any excess whitespace is removed.
316
+			$datetime_data = array_map(
317
+				function ($datetime_data) {
318
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
319
+				},
320
+				$datetime_data
321
+			);
322
+
323
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
324
+											&& ! empty($datetime_data['DTT_EVT_end'])
325
+				? $datetime_data['DTT_EVT_end']
326
+				: $datetime_data['DTT_EVT_start'];
327
+			$datetime_values              = [
328
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329
+					? $datetime_data['DTT_ID']
330
+					: null,
331
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
332
+					? $datetime_data['DTT_name']
333
+					: '',
334
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
335
+					? $datetime_data['DTT_description']
336
+					: '',
337
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
338
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
339
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
340
+					? EE_INF
341
+					: $datetime_data['DTT_reg_limit'],
342
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
343
+					? $row
344
+					: $datetime_data['DTT_order'],
345
+			];
346
+
347
+			// if we have an id then let's get existing object first and then set the new values.
348
+			// Otherwise we instantiate a new object for save.
349
+			if (! empty($datetime_data['DTT_ID'])) {
350
+				$datetime = EE_Registry::instance()
351
+									   ->load_model('Datetime', [$timezone])
352
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
353
+				// set date and time format according to what is set in this class.
354
+				$datetime->set_date_format($this->_date_format_strings['date']);
355
+				$datetime->set_time_format($this->_date_format_strings['time']);
356
+				foreach ($datetime_values as $field => $value) {
357
+					$datetime->set($field, $value);
358
+				}
359
+
360
+				// make sure the $datetime_id here is saved just in case
361
+				// after the add_relation_to() the autosave replaces it.
362
+				// We need to do this so we dont' TRASH the parent DTT.
363
+				// (save the ID for both key and value to avoid duplications)
364
+				$saved_datetime_ids[ $datetime->ID() ] = $datetime->ID();
365
+			} else {
366
+				$datetime = EE_Datetime::new_instance(
367
+					$datetime_values,
368
+					$timezone,
369
+					[$this->_date_format_strings['date'], $this->_date_format_strings['time']]
370
+				);
371
+				foreach ($datetime_values as $field => $value) {
372
+					$datetime->set($field, $value);
373
+				}
374
+			}
375
+			$datetime->save();
376
+			do_action(
377
+				'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
378
+				$datetime,
379
+				$row,
380
+				$datetime_data,
381
+				$data
382
+			);
383
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
384
+			// before going any further make sure our dates are setup correctly
385
+			// so that the end date is always equal or greater than the start date.
386
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
387
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
388
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
389
+				$datetime->save();
390
+			}
391
+			// now we have to make sure we add the new DTT_ID to the $saved_datetime_ids array
392
+			// because it is possible there was a new one created for the autosave.
393
+			// (save the ID for both key and value to avoid duplications)
394
+			$DTT_ID                        = $datetime->ID();
395
+			$saved_datetime_ids[ $DTT_ID ] = $DTT_ID;
396
+			$saved_datetime_objs[ $row ]   = $datetime;
397
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
398
+		}
399
+		$event->save();
400
+		// now we need to REMOVE any datetimes that got deleted.
401
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
402
+		// So its safe to permanently delete at this point.
403
+		$old_datetimes = explode(',', $data['datetime_IDs']);
404
+		$old_datetimes = $old_datetimes[0] === '' ? [] : $old_datetimes;
405
+		if (is_array($old_datetimes)) {
406
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_datetime_ids);
407
+			foreach ($datetimes_to_delete as $id) {
408
+				$id = absint($id);
409
+				if (empty($id)) {
410
+					continue;
411
+				}
412
+				$dtt_to_remove = $datetime_model->get_one_by_ID($id);
413
+				// remove tkt relationships.
414
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
415
+				foreach ($related_tickets as $ticket) {
416
+					$dtt_to_remove->_remove_relation_to($ticket, 'Ticket');
417
+				}
418
+				$event->_remove_relation_to($id, 'Datetime');
419
+				$dtt_to_remove->refresh_cache_of_related_objects();
420
+			}
421
+		}
422
+		return $saved_datetime_objs;
423
+	}
424
+
425
+
426
+	/**
427
+	 * update tickets
428
+	 *
429
+	 * @param EE_Event      $event           Event object being updated
430
+	 * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated
431
+	 * @param array         $data            incoming request data
432
+	 * @return EE_Ticket[]
433
+	 * @throws Exception
434
+	 * @throws ReflectionException
435
+	 * @throws InvalidInterfaceException
436
+	 * @throws InvalidDataTypeException
437
+	 * @throws InvalidArgumentException
438
+	 * @throws EE_Error
439
+	 */
440
+	protected function _update_tickets(EE_Event $event, array $saved_datetimes, array $data): array
441
+	{
442
+		$new_ticket = null;
443
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
444
+		$data          = stripslashes_deep($data);
445
+		$timezone      = $data['timezone_string'] ?? null;
446
+		$ticket_model = EEM_Ticket::instance($timezone);
447
+
448
+		$saved_tickets = [];
449
+		$old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
450
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
451
+			throw new InvalidArgumentException(
452
+				esc_html__(
453
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
454
+					'event_espresso'
455
+				)
456
+			);
457
+		}
458
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
459
+			$update_prices = $create_new_TKT = false;
460
+			// figure out what datetimes were added to the ticket
461
+			// and what datetimes were removed from the ticket in the session.
462
+			$starting_ticket_datetime_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
463
+			$ticket_datetime_rows          = explode(',', $data['ticket_datetime_rows'][ $row ]);
464
+			$datetimes_added               = array_diff($ticket_datetime_rows, $starting_ticket_datetime_rows);
465
+			$datetimes_removed             = array_diff($starting_ticket_datetime_rows, $ticket_datetime_rows);
466
+			// trim inputs to ensure any excess whitespace is removed.
467
+			$ticket_data = array_map(
468
+				function ($ticket_data) {
469
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
470
+				},
471
+				$ticket_data
472
+			);
473
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
474
+			// because we're doing calculations prior to using the models.
475
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
476
+			$ticket_price = isset($ticket_data['TKT_price'])
477
+				? round((float) $ticket_data['TKT_price'], 3)
478
+				: 0;
479
+			// note incoming base price needs converted from localized value.
480
+			$base_price = isset($ticket_data['TKT_base_price'])
481
+				? EEH_Money::convert_to_float_from_localized_money($ticket_data['TKT_base_price'])
482
+				: 0;
483
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
484
+			$ticket_price  = $ticket_price === 0 && $base_price !== 0
485
+				? $base_price
486
+				: $ticket_price;
487
+			$base_price_id = $ticket_data['TKT_base_price_ID'] ?? 0;
488
+			$price_rows    = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
489
+				? $data['edit_prices'][ $row ]
490
+				: [];
491
+			$now           = null;
492
+			if (empty($ticket_data['TKT_start_date'])) {
493
+				// lets' use now in the set timezone.
494
+				$now                           = new DateTime('now', new DateTimeZone($event->get_timezone()));
495
+				$ticket_data['TKT_start_date'] = $now->format($this->_date_time_format);
496
+			}
497
+			if (empty($ticket_data['TKT_end_date'])) {
498
+				/**
499
+				 * set the TKT_end_date to the first datetime attached to the ticket.
500
+				 */
501
+				$first_datetime              = $saved_datetimes[ reset($ticket_datetime_rows) ];
502
+				$ticket_data['TKT_end_date'] = $first_datetime->start_date_and_time($this->_date_time_format);
503
+			}
504
+			$TKT_values = [
505
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
506
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
507
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
508
+				'TKT_description' => ! empty($ticket_data['TKT_description'])
509
+									 && $ticket_data['TKT_description'] !== esc_html__(
510
+										 'You can modify this description',
511
+										 'event_espresso'
512
+									 )
513
+					? $ticket_data['TKT_description']
514
+					: '',
515
+				'TKT_start_date'  => $ticket_data['TKT_start_date'],
516
+				'TKT_end_date'    => $ticket_data['TKT_end_date'],
517
+				'TKT_qty'         => ! isset($ticket_data['TKT_qty']) || $ticket_data['TKT_qty'] === ''
518
+					? EE_INF
519
+					: $ticket_data['TKT_qty'],
520
+				'TKT_uses'        => ! isset($ticket_data['TKT_uses']) || $ticket_data['TKT_uses'] === ''
521
+					? EE_INF
522
+					: $ticket_data['TKT_uses'],
523
+				'TKT_min'         => empty($ticket_data['TKT_min']) ? 0 : $ticket_data['TKT_min'],
524
+				'TKT_max'         => empty($ticket_data['TKT_max']) ? EE_INF : $ticket_data['TKT_max'],
525
+				'TKT_row'         => $row,
526
+				'TKT_order'       => $ticket_data['TKT_order'] ?? 0,
527
+				'TKT_taxable'     => ! empty($ticket_data['TKT_taxable']) ? 1 : 0,
528
+				'TKT_required'    => ! empty($ticket_data['TKT_required']) ? 1 : 0,
529
+				'TKT_price'       => $ticket_price,
530
+			];
531
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
532
+			// which means in turn that the prices will become new prices as well.
533
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
534
+				$TKT_values['TKT_ID']         = 0;
535
+				$TKT_values['TKT_is_default'] = 0;
536
+				$update_prices                = true;
537
+			}
538
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
539
+			// we actually do our saves ahead of doing any add_relations to
540
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
541
+			// but DID have it's items modified.
542
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
543
+			// then we won't be updating the ticket but instead a new ticket will be created and the old one archived.
544
+			if (absint($TKT_values['TKT_ID'])) {
545
+				$ticket = EE_Registry::instance()
546
+									 ->load_model('Ticket', [$timezone])
547
+									 ->get_one_by_ID($TKT_values['TKT_ID']);
548
+				if ($ticket instanceof EE_Ticket) {
549
+					$ticket = $this->_update_ticket_datetimes(
550
+						$ticket,
551
+						$saved_datetimes,
552
+						$datetimes_added,
553
+						$datetimes_removed
554
+					);
555
+					// are there any registrations using this ticket ?
556
+					$tickets_sold = $ticket->count_related(
557
+						'Registration',
558
+						[
559
+							[
560
+								'STS_ID' => ['NOT IN', [EEM_Registration::status_id_incomplete]],
561
+							],
562
+						]
563
+					);
564
+					// set ticket formats
565
+					$ticket->set_date_format($this->_date_format_strings['date']);
566
+					$ticket->set_time_format($this->_date_format_strings['time']);
567
+					// let's just check the total price for the existing ticket
568
+					// and determine if it matches the new total price.
569
+					// if they are different then we create a new ticket (if tickets sold)
570
+					// if they aren't different then we go ahead and modify existing ticket.
571
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
572
+					// set new values
573
+					foreach ($TKT_values as $field => $value) {
574
+						if ($field === 'TKT_qty') {
575
+							$ticket->set_qty($value);
576
+						} else {
577
+							$ticket->set($field, $value);
578
+						}
579
+					}
580
+					// if $create_new_TKT is false then we can safely update the existing ticket.
581
+					// Otherwise we have to create a new ticket.
582
+					if ($create_new_TKT) {
583
+						$new_ticket = $this->_duplicate_ticket(
584
+							$ticket,
585
+							$price_rows,
586
+							$ticket_price,
587
+							$base_price,
588
+							$base_price_id
589
+						);
590
+					}
591
+				}
592
+			} else {
593
+				// no TKT_id so a new TKT
594
+				$ticket = EE_Ticket::new_instance(
595
+					$TKT_values,
596
+					$timezone,
597
+					[$this->_date_format_strings['date'], $this->_date_format_strings['time']]
598
+				);
599
+				if ($ticket instanceof EE_Ticket) {
600
+					// make sure ticket has an ID of setting relations won't work
601
+					$ticket->save();
602
+					$ticket        = $this->_update_ticket_datetimes(
603
+						$ticket,
604
+						$saved_datetimes,
605
+						$datetimes_added,
606
+						$datetimes_removed
607
+					);
608
+					$update_prices = true;
609
+				}
610
+			}
611
+			// make sure any current values have been saved.
612
+			// $ticket->save();
613
+			// before going any further make sure our dates are setup correctly
614
+			// so that the end date is always equal or greater than the start date.
615
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
616
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
617
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
618
+			}
619
+			// let's make sure the base price is handled
620
+			$ticket = ! $create_new_TKT
621
+				? $this->_add_prices_to_ticket(
622
+					[],
623
+					$ticket,
624
+					$update_prices,
625
+					$base_price,
626
+					$base_price_id
627
+				)
628
+				: $ticket;
629
+			// add/update price_modifiers
630
+			$ticket = ! $create_new_TKT
631
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
632
+				: $ticket;
633
+			// need to make sue that the TKT_price is accurate after saving the prices.
634
+			$ticket->ensure_TKT_Price_correct();
635
+			// handle CREATING a default ticket from the incoming ticket but ONLY if this isn't an autosave.
636
+			if (! defined('DOING_AUTOSAVE') && ! empty($ticket_data['TKT_is_default_selector'])) {
637
+				$new_default = clone $ticket;
638
+				$new_default->set('TKT_ID', 0);
639
+				$new_default->set('TKT_is_default', 1);
640
+				$new_default->set('TKT_row', 1);
641
+				$new_default->set('TKT_price', $ticket_price);
642
+				// remove any datetime relations cause we DON'T want datetime relations attached
643
+				// (note this is just removing the cached relations in the object)
644
+				$new_default->_remove_relations('Datetime');
645
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
646
+				$new_default = $this->_add_prices_to_ticket(
647
+					$price_rows,
648
+					$new_default,
649
+					true
650
+				);
651
+				// don't forget the base price!
652
+				$new_default = $this->_add_prices_to_ticket(
653
+					[],
654
+					$new_default,
655
+					true,
656
+					$base_price,
657
+					$base_price_id
658
+				);
659
+				$new_default->save();
660
+				do_action(
661
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
662
+					$new_default,
663
+					$row,
664
+					$ticket,
665
+					$data
666
+				);
667
+			}
668
+			// DO ALL datetime relationships for both current tickets and any archived tickets
669
+			// for the given datetime that are related to the current ticket.
670
+			// TODO... not sure exactly how we're going to do this considering we don't know
671
+			// what current ticket the archived tickets are related to
672
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
673
+			// let's assign any tickets that have been setup to the saved_tickets tracker
674
+			// save existing TKT
675
+			$ticket->save();
676
+			if ($create_new_TKT && $new_ticket instanceof EE_Ticket) {
677
+				// save new TKT
678
+				$new_ticket->save();
679
+				// add new ticket to array
680
+				$saved_tickets[ $new_ticket->ID() ] = $new_ticket;
681
+				do_action(
682
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
683
+					$new_ticket,
684
+					$row,
685
+					$ticket_data,
686
+					$data
687
+				);
688
+			} else {
689
+				// add ticket to saved tickets
690
+				$saved_tickets[ $ticket->ID() ] = $ticket;
691
+				do_action(
692
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
693
+					$ticket,
694
+					$row,
695
+					$ticket_data,
696
+					$data
697
+				);
698
+			}
699
+		}
700
+		// now we need to handle tickets actually "deleted permanently".
701
+		// There are cases where we'd want this to happen
702
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
703
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
704
+		// No sense in keeping all the related data in the db!
705
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
706
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
707
+		foreach ($tickets_removed as $id) {
708
+			$id = absint($id);
709
+			// get the ticket for this id
710
+			$ticket_to_remove = $ticket_model->get_one_by_ID($id);
711
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
712
+			if ($ticket_to_remove->get('TKT_is_default')) {
713
+				continue;
714
+			}
715
+			// if this ticket has any registrations attached so then we just ARCHIVE
716
+			// because we don't actually permanently delete these tickets.
717
+			if ($ticket_to_remove->count_related('Registration') > 0) {
718
+				$ticket_to_remove->delete();
719
+				continue;
720
+			}
721
+			// need to get all the related datetimes on this ticket and remove from every single one of them
722
+			// (remember this process can ONLY kick off if there are NO tickets_sold)
723
+			$datetimes = $ticket_to_remove->get_many_related('Datetime');
724
+			foreach ($datetimes as $datetime) {
725
+				$ticket_to_remove->_remove_relation_to($datetime, 'Datetime');
726
+			}
727
+			// need to do the same for prices (except these prices can also be deleted because again,
728
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
729
+			$ticket_to_remove->delete_related('Price');
730
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $ticket_to_remove);
731
+			// finally let's delete this ticket
732
+			// (which should not be blocked at this point b/c we've removed all our relationships)
733
+			$ticket_to_remove->delete_or_restore();
734
+		}
735
+		return $saved_tickets;
736
+	}
737
+
738
+
739
+	/**
740
+	 * @access  protected
741
+	 * @param EE_Ticket     $ticket
742
+	 * @param EE_Datetime[] $saved_datetimes
743
+	 * @param int[]         $added_datetimes
744
+	 * @param int[]         $removed_datetimes
745
+	 * @return EE_Ticket
746
+	 * @throws EE_Error
747
+	 * @throws ReflectionException
748
+	 */
749
+	protected function _update_ticket_datetimes(
750
+		EE_Ticket $ticket,
751
+		array $saved_datetimes = [],
752
+		array $added_datetimes = [],
753
+		array $removed_datetimes = []
754
+	): EE_Ticket {
755
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
756
+		// and removing the ticket from datetimes it got removed from.
757
+		// first let's add datetimes
758
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
759
+			foreach ($added_datetimes as $row_id) {
760
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
761
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
762
+					// Is this an existing ticket (has an ID) and does it have any sold?
763
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
764
+					if ($ticket->ID() && $ticket->sold() > 0) {
765
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
766
+					}
767
+				}
768
+			}
769
+		}
770
+		// then remove datetimes
771
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
772
+			foreach ($removed_datetimes as $row_id) {
773
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
774
+				// So make sure we skip over this if the datetime isn't in the $saved_datetimes array)
775
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
776
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
777
+				}
778
+			}
779
+		}
780
+		// cap ticket qty by datetime reg limits
781
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
782
+		return $ticket;
783
+	}
784
+
785
+
786
+	/**
787
+	 * @access  protected
788
+	 * @param EE_Ticket $ticket
789
+	 * @param array     $price_rows
790
+	 * @param int|float $ticket_price
791
+	 * @param int|float $base_price
792
+	 * @param int       $base_price_id
793
+	 * @return EE_Ticket
794
+	 * @throws ReflectionException
795
+	 * @throws InvalidArgumentException
796
+	 * @throws InvalidInterfaceException
797
+	 * @throws InvalidDataTypeException
798
+	 * @throws EE_Error
799
+	 */
800
+	protected function _duplicate_ticket(
801
+		EE_Ticket $ticket,
802
+		array $price_rows = [],
803
+		$ticket_price = 0,
804
+		$base_price = 0,
805
+		int $base_price_id = 0
806
+	): EE_Ticket {
807
+		// create new ticket that's a copy of the existing
808
+		// except a new id of course (and not archived)
809
+		// AND has the new TKT_price associated with it.
810
+		$new_ticket = clone $ticket;
811
+		$new_ticket->set('TKT_ID', 0);
812
+		$new_ticket->set_deleted(0);
813
+		$new_ticket->set_price($ticket_price);
814
+		$new_ticket->set_sold(0);
815
+		// let's get a new ID for this ticket
816
+		$new_ticket->save();
817
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
818
+		$datetimes_on_existing = $ticket->datetimes();
819
+		$new_ticket            = $this->_update_ticket_datetimes(
820
+			$new_ticket,
821
+			$datetimes_on_existing,
822
+			array_keys($datetimes_on_existing)
823
+		);
824
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
825
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
826
+		// available.
827
+		if ($ticket->sold() > 0) {
828
+			$new_qty = $ticket->qty() - $ticket->sold();
829
+			$new_ticket->set_qty($new_qty);
830
+		}
831
+		// now we update the prices just for this ticket
832
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
833
+		// and we update the base price
834
+		return $this->_add_prices_to_ticket(
835
+			[],
836
+			$new_ticket,
837
+			true,
838
+			$base_price,
839
+			$base_price_id
840
+		);
841
+	}
842
+
843
+
844
+	/**
845
+	 * This attaches a list of given prices to a ticket.
846
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
847
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
848
+	 * price info and prices are automatically "archived" via the ticket.
849
+	 *
850
+	 * @access  private
851
+	 * @param array     $prices        Array of prices from the form.
852
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
853
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
854
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
855
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
856
+	 * @return EE_Ticket
857
+	 * @throws ReflectionException
858
+	 * @throws InvalidArgumentException
859
+	 * @throws InvalidInterfaceException
860
+	 * @throws InvalidDataTypeException
861
+	 * @throws EE_Error
862
+	 */
863
+	protected function _add_prices_to_ticket(
864
+		array $prices,
865
+		EE_Ticket $ticket,
866
+		bool $new_prices = false,
867
+		$base_price = false,
868
+		$base_price_id = false
869
+	): EE_Ticket {
870
+		$price_model = EEM_Price::instance();
871
+		// let's just get any current prices that may exist on the given ticket
872
+		// so we can remove any prices that got trashed in this session.
873
+		$current_prices_on_ticket = $base_price !== false
874
+			? $ticket->base_price(true)
875
+			: $ticket->price_modifiers();
876
+		$updated_prices           = [];
877
+		// if $base_price ! FALSE then updating a base price.
878
+		if ($base_price !== false) {
879
+			$prices[1] = [
880
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
881
+				'PRT_ID'     => 1,
882
+				'PRC_amount' => $base_price,
883
+				'PRC_name'   => $ticket->get('TKT_name'),
884
+				'PRC_desc'   => $ticket->get('TKT_description'),
885
+			];
886
+		}
887
+		// possibly need to save ticket
888
+		if (! $ticket->ID()) {
889
+			$ticket->save();
890
+		}
891
+		foreach ($prices as $row => $prc) {
892
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
893
+			if (empty($prt_id)) {
894
+				continue;
895
+			} //prices MUST have a price type id.
896
+			$PRC_values = [
897
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
898
+				'PRT_ID'         => $prt_id,
899
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
900
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
901
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
902
+				'PRC_is_default' => false,
903
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
904
+				'PRC_order'      => $row,
905
+			];
906
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
907
+				$PRC_values['PRC_ID'] = 0;
908
+				$price                = EE_Registry::instance()->load_class(
909
+					'Price',
910
+					[$PRC_values],
911
+					false,
912
+					false
913
+				);
914
+			} else {
915
+				$price = $price_model->get_one_by_ID($prc['PRC_ID']);
916
+				// update this price with new values
917
+				foreach ($PRC_values as $field => $value) {
918
+					$price->set($field, $value);
919
+				}
920
+			}
921
+			$price->save();
922
+			$updated_prices[ $price->ID() ] = $price;
923
+			$ticket->_add_relation_to($price, 'Price');
924
+		}
925
+		// now let's remove any prices that got removed from the ticket
926
+		if (! empty($current_prices_on_ticket)) {
927
+			$current          = array_keys($current_prices_on_ticket);
928
+			$updated          = array_keys($updated_prices);
929
+			$prices_to_remove = array_diff($current, $updated);
930
+			if (! empty($prices_to_remove)) {
931
+				foreach ($prices_to_remove as $prc_id) {
932
+					$p = $current_prices_on_ticket[ $prc_id ];
933
+					$ticket->_remove_relation_to($p, 'Price');
934
+					// delete permanently the price
935
+					$p->delete_or_restore();
936
+				}
937
+			}
938
+		}
939
+		return $ticket;
940
+	}
941
+
942
+
943
+	/**
944
+	 * @throws ReflectionException
945
+	 * @throws InvalidArgumentException
946
+	 * @throws InvalidInterfaceException
947
+	 * @throws InvalidDataTypeException
948
+	 * @throws DomainException
949
+	 * @throws EE_Error
950
+	 */
951
+	public function pricing_metabox()
952
+	{
953
+		$event          = $this->_adminpage_obj->get_cpt_model_obj();
954
+		$timezone       = $event instanceof EE_Event ? $event->timezone_string() : null;
955
+		$price_model    = EEM_Price::instance($timezone);
956
+		$ticket_model   = EEM_Ticket::instance($timezone);
957
+		$datetime_model = EEM_Datetime::instance($timezone);
958
+		$all_tickets    = [];
959
+
960
+		// set is_creating_event property.
961
+		$EVT_ID                   = $event->ID();
962
+		$this->_is_creating_event = empty($this->_req_data['post']);
963
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = [];
964
+
965
+		// default main template args
966
+		$main_template_args = [
967
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
968
+				'event_editor_event_datetimes_help_tab',
969
+				$this->_adminpage_obj->page_slug,
970
+				$this->_adminpage_obj->get_req_action()
971
+			),
972
+
973
+			// todo need to add a filter to the template for the help text
974
+			// in the Events_Admin_Page core file so we can add further help
975
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
976
+				'add_new_dtt_info',
977
+				$this->_adminpage_obj->page_slug,
978
+				$this->_adminpage_obj->get_req_action()
979
+			),
980
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
981
+			'datetime_rows'            => '',
982
+			'show_tickets_container'   => '',
983
+			'ticket_rows'              => '',
984
+			'ee_collapsible_status'    => ' ee-collapsible-open'
985
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
986
+		];
987
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
988
+
989
+		/**
990
+		 * 1. Start with retrieving Datetimes
991
+		 * 2. For each datetime get related tickets
992
+		 * 3. For each ticket get related prices
993
+		 */
994
+		$datetimes                            = $datetime_model->get_all_event_dates($EVT_ID);
995
+		$main_template_args['total_dtt_rows'] = count($datetimes);
996
+
997
+		/**
998
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
999
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1000
+		 */
1001
+		$datetime_row = 1;
1002
+		foreach ($datetimes as $datetime) {
1003
+			$DTT_ID = $datetime->get('DTT_ID');
1004
+			$datetime->set('DTT_order', $datetime_row);
1005
+			$existing_datetime_ids[] = $DTT_ID;
1006
+			// tickets attached
1007
+			$related_tickets = $datetime->ID() > 0
1008
+				? $datetime->get_many_related(
1009
+					'Ticket',
1010
+					[
1011
+						[
1012
+							'OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0],
1013
+						],
1014
+						'default_where_conditions' => 'none',
1015
+						'order_by'                 => ['TKT_order' => 'ASC'],
1016
+					]
1017
+				)
1018
+				: [];
1019
+			// if there are no related tickets this is likely a new event OR auto-draft
1020
+			// event so we need to generate the default tickets because datetimes
1021
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1022
+			// datetime on the event.
1023
+			if (empty($related_tickets) && count($datetimes) < 2) {
1024
+				$related_tickets = $ticket_model->get_all_default_tickets();
1025
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1026
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1027
+				$default_prices      = $price_model->get_all_default_prices();
1028
+				$main_default_ticket = reset($related_tickets);
1029
+				if ($main_default_ticket instanceof EE_Ticket) {
1030
+					foreach ($default_prices as $default_price) {
1031
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1032
+							continue;
1033
+						}
1034
+						$main_default_ticket->cache('Price', $default_price);
1035
+					}
1036
+				}
1037
+			}
1038
+			// we can't actually setup rows in this loop yet cause we don't know all
1039
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1040
+			// So we're going to temporarily cache some of that information.
1041
+			// loop through and setup the ticket rows and make sure the order is set.
1042
+			foreach ($related_tickets as $ticket) {
1043
+				$TKT_ID     = $ticket->get('TKT_ID');
1044
+				$ticket_row = $ticket->get('TKT_row');
1045
+				// we only want unique tickets in our final display!!
1046
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1047
+					$existing_ticket_ids[] = $TKT_ID;
1048
+					$all_tickets[]         = $ticket;
1049
+				}
1050
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1051
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1052
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1053
+				if (
1054
+					! isset($ticket_datetimes[ $TKT_ID ])
1055
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1056
+				) {
1057
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1058
+				}
1059
+			}
1060
+			$datetime_row++;
1061
+		}
1062
+		$main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
1063
+		$main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
1064
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1065
+		// sort $all_tickets by order
1066
+		usort(
1067
+			$all_tickets,
1068
+			function (EE_Ticket $a, EE_Ticket $b) {
1069
+				$a_order = (int) $a->get('TKT_order');
1070
+				$b_order = (int) $b->get('TKT_order');
1071
+				if ($a_order === $b_order) {
1072
+					return 0;
1073
+				}
1074
+				return ($a_order < $b_order) ? -1 : 1;
1075
+			}
1076
+		);
1077
+		// k NOW we have all the data we need for setting up the datetime rows
1078
+		// and ticket rows so we start our datetime loop again.
1079
+		$datetime_row = 1;
1080
+		foreach ($datetimes as $datetime) {
1081
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1082
+				$datetime_row,
1083
+				$datetime,
1084
+				$datetime_tickets,
1085
+				$all_tickets,
1086
+				false,
1087
+				$datetimes
1088
+			);
1089
+			$datetime_row++;
1090
+		}
1091
+		// then loop through all tickets for the ticket rows.
1092
+		$ticket_row = 1;
1093
+		foreach ($all_tickets as $ticket) {
1094
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1095
+				$ticket_row,
1096
+				$ticket,
1097
+				$ticket_datetimes,
1098
+				$datetimes,
1099
+				false,
1100
+				$all_tickets
1101
+			);
1102
+			$ticket_row++;
1103
+		}
1104
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1105
+
1106
+		$status_change_notice = LoaderFactory::getLoader()->getShared(
1107
+			'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
1108
+		);
1109
+
1110
+		$main_template_args['status_change_notice'] = $status_change_notice->display(
1111
+			'__event-editor',
1112
+			'espresso-events'
1113
+		);
1114
+
1115
+		EEH_Template::display_template(
1116
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1117
+			$main_template_args
1118
+		);
1119
+	}
1120
+
1121
+
1122
+	/**
1123
+	 * @param int|string  $datetime_row
1124
+	 * @param EE_Datetime $datetime
1125
+	 * @param array       $datetime_tickets
1126
+	 * @param array       $all_tickets
1127
+	 * @param bool        $default
1128
+	 * @param array       $all_datetimes
1129
+	 * @return string
1130
+	 * @throws DomainException
1131
+	 * @throws EE_Error
1132
+	 * @throws ReflectionException
1133
+	 */
1134
+	protected function _get_datetime_row(
1135
+		$datetime_row,
1136
+		EE_Datetime $datetime,
1137
+		array $datetime_tickets = [],
1138
+		array $all_tickets = [],
1139
+		bool $default = false,
1140
+		array $all_datetimes = []
1141
+	): string {
1142
+		return EEH_Template::display_template(
1143
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1144
+			[
1145
+				'dtt_edit_row'             => $this->_get_dtt_edit_row(
1146
+					$datetime_row,
1147
+					$datetime,
1148
+					$default,
1149
+					$all_datetimes
1150
+				),
1151
+				'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1152
+					$datetime_row,
1153
+					$datetime,
1154
+					$datetime_tickets,
1155
+					$all_tickets,
1156
+					$default
1157
+				),
1158
+				'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1159
+			],
1160
+			true
1161
+		);
1162
+	}
1163
+
1164
+
1165
+	/**
1166
+	 * This method is used to generate a datetime fields  edit row.
1167
+	 * The same row is used to generate a row with valid DTT objects
1168
+	 * and the default row that is used as the skeleton by the js.
1169
+	 *
1170
+	 * @param int|string       $datetime_row  The row number for the row being generated.
1171
+	 * @param EE_Datetime|null $datetime
1172
+	 * @param bool             $default       Whether a default row is being generated or not.
1173
+	 * @param EE_Datetime[]    $all_datetimes This is the array of all datetimes used in the editor.
1174
+	 * @return string
1175
+	 * @throws EE_Error
1176
+	 * @throws ReflectionException
1177
+	 */
1178
+	protected function _get_dtt_edit_row(
1179
+		$datetime_row,
1180
+		?EE_Datetime $datetime,
1181
+		bool $default,
1182
+		array $all_datetimes
1183
+	): string {
1184
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1185
+		$default                     = ! $datetime instanceof EE_Datetime ? true : $default;
1186
+		$template_args               = [
1187
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1188
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1189
+			'edit_dtt_expanded'    => '',
1190
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1191
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1192
+			'DTT_description'      => $default ? '' : $datetime->get_raw('DTT_description'),
1193
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1194
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1195
+			'DTT_reg_limit'        => $default
1196
+				? ''
1197
+				: $datetime->get_pretty(
1198
+					'DTT_reg_limit',
1199
+					'input'
1200
+				),
1201
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1202
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1203
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1204
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1205
+				? ''
1206
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1207
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1208
+				? 'dashicons dashicons-lock'
1209
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1210
+			'reg_list_url'         => $default || ! $datetime->event() instanceof EE_Event
1211
+				? ''
1212
+				: EE_Admin_Page::add_query_args_and_nonce(
1213
+					[
1214
+						'event_id'    => $datetime->event()->ID(),
1215
+						'datetime_id' => $datetime->ID(),
1216
+						'use_filters' => true,
1217
+					],
1218
+					REG_ADMIN_URL
1219
+				),
1220
+		];
1221
+		$template_args['show_trash'] = count($all_datetimes) === 1
1222
+									   && $template_args['trash_icon'] !== 'dashicons dashicons-lock'
1223
+			? 'display:none'
1224
+			: '';
1225
+		// allow filtering of template args at this point.
1226
+		$template_args = apply_filters(
1227
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1228
+			$template_args,
1229
+			$datetime_row,
1230
+			$datetime,
1231
+			$default,
1232
+			$all_datetimes,
1233
+			$this->_is_creating_event
1234
+		);
1235
+		return EEH_Template::display_template(
1236
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1237
+			$template_args,
1238
+			true
1239
+		);
1240
+	}
1241
+
1242
+
1243
+	/**
1244
+	 * @param int|string       $datetime_row
1245
+	 * @param EE_Datetime|null $datetime
1246
+	 * @param array            $datetime_tickets
1247
+	 * @param array            $all_tickets
1248
+	 * @param bool             $default
1249
+	 * @return string
1250
+	 * @throws DomainException
1251
+	 * @throws EE_Error
1252
+	 * @throws ReflectionException
1253
+	 */
1254
+	protected function _get_dtt_attached_tickets_row(
1255
+		$datetime_row,
1256
+		?EE_Datetime $datetime,
1257
+		array $datetime_tickets = [],
1258
+		array $all_tickets = [],
1259
+		bool $default = false
1260
+	): string {
1261
+		$template_args = [
1262
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1263
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1264
+			'DTT_description'                   => $default ? '' : $datetime->get_raw('DTT_description'),
1265
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1266
+			'show_tickets_row'                  => 'display:none;',
1267
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1268
+				'add_new_ticket_via_datetime',
1269
+				$this->_adminpage_obj->page_slug,
1270
+				$this->_adminpage_obj->get_req_action()
1271
+			),
1272
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1273
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1274
+		];
1275
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1276
+		if (! $default) {
1277
+			$ticket_row = 1;
1278
+			foreach ($all_tickets as $ticket) {
1279
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1280
+					$datetime_row,
1281
+					$ticket_row,
1282
+					$datetime,
1283
+					$ticket,
1284
+					$datetime_tickets
1285
+				);
1286
+				$ticket_row++;
1287
+			}
1288
+		}
1289
+		// filter template args at this point
1290
+		$template_args = apply_filters(
1291
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1292
+			$template_args,
1293
+			$datetime_row,
1294
+			$datetime,
1295
+			$datetime_tickets,
1296
+			$all_tickets,
1297
+			$default,
1298
+			$this->_is_creating_event
1299
+		);
1300
+		return EEH_Template::display_template(
1301
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1302
+			$template_args,
1303
+			true
1304
+		);
1305
+	}
1306
+
1307
+
1308
+	/**
1309
+	 * @param int|string       $datetime_row
1310
+	 * @param int|string       $ticket_row
1311
+	 * @param EE_Datetime|null $datetime
1312
+	 * @param EE_Ticket|null   $ticket
1313
+	 * @param array            $datetime_tickets
1314
+	 * @param bool             $default
1315
+	 * @return string
1316
+	 * @throws EE_Error
1317
+	 * @throws ReflectionException
1318
+	 */
1319
+	protected function _get_datetime_tickets_list_item(
1320
+		$datetime_row,
1321
+		$ticket_row,
1322
+		?EE_Datetime $datetime,
1323
+		?EE_Ticket $ticket,
1324
+		array $datetime_tickets = [],
1325
+		bool $default = false
1326
+	): string {
1327
+		$datetime_tickets = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1328
+			? $datetime_tickets[ $datetime->ID() ]
1329
+			: [];
1330
+		$display_row      = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1331
+		$no_ticket        = $default && empty($ticket);
1332
+		$template_args    = [
1333
+			'dtt_row'                 => $default
1334
+				? 'DTTNUM'
1335
+				: $datetime_row,
1336
+			'tkt_row'                 => $no_ticket
1337
+				? 'TICKETNUM'
1338
+				: $ticket_row,
1339
+			'datetime_ticket_checked' => in_array($display_row, $datetime_tickets, true)
1340
+				? ' checked'
1341
+				: '',
1342
+			'ticket_selected'         => in_array($display_row, $datetime_tickets, true)
1343
+				? ' ticket-selected'
1344
+				: '',
1345
+			'TKT_name'                => $no_ticket
1346
+				? 'TKTNAME'
1347
+				: $ticket->get('TKT_name'),
1348
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1349
+				? ' tkt-status-' . EE_Ticket::onsale
1350
+				: ' tkt-status-' . $ticket->ticket_status(),
1351
+		];
1352
+		// filter template args
1353
+		$template_args = apply_filters(
1354
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1355
+			$template_args,
1356
+			$datetime_row,
1357
+			$ticket_row,
1358
+			$datetime,
1359
+			$ticket,
1360
+			$datetime_tickets,
1361
+			$default,
1362
+			$this->_is_creating_event
1363
+		);
1364
+		return EEH_Template::display_template(
1365
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1366
+			$template_args,
1367
+			true
1368
+		);
1369
+	}
1370
+
1371
+
1372
+	/**
1373
+	 * This generates the ticket row for tickets.
1374
+	 * This same method is used to generate both the actual rows and the js skeleton row
1375
+	 * (when default === true)
1376
+	 *
1377
+	 * @param int|string     $ticket_row       Represents the row number being generated.
1378
+	 * @param EE_Ticket|null $ticket
1379
+	 * @param EE_Datetime[]  $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1380
+	 *                                         or empty for default
1381
+	 * @param EE_Datetime[]  $all_datetimes    All Datetimes on the event or empty for default.
1382
+	 * @param bool           $default          Whether default row being generated or not.
1383
+	 * @param EE_Ticket[]    $all_tickets      This is an array of all tickets attached to the event
1384
+	 *                                         (or empty in the case of defaults)
1385
+	 * @return string
1386
+	 * @throws InvalidArgumentException
1387
+	 * @throws InvalidInterfaceException
1388
+	 * @throws InvalidDataTypeException
1389
+	 * @throws DomainException
1390
+	 * @throws EE_Error
1391
+	 * @throws ReflectionException
1392
+	 */
1393
+	protected function _get_ticket_row(
1394
+		$ticket_row,
1395
+		?EE_Ticket $ticket,
1396
+		array $ticket_datetimes,
1397
+		array $all_datetimes,
1398
+		bool $default = false,
1399
+		array $all_tickets = []
1400
+	): string {
1401
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1402
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1403
+		$prices  = ! empty($ticket) && ! $default
1404
+			? $ticket->get_many_related(
1405
+				'Price',
1406
+				['default_where_conditions' => 'none', 'order_by' => ['PRC_order' => 'ASC']]
1407
+			)
1408
+			: [];
1409
+		// if there is only one price (which would be the base price)
1410
+		// or NO prices and this ticket is a default ticket,
1411
+		// let's just make sure there are no cached default prices on the object.
1412
+		// This is done by not including any query_params.
1413
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1414
+			$prices = $ticket->prices();
1415
+		}
1416
+		// check if we're dealing with a default ticket in which case
1417
+		// we don't want any starting_ticket_datetime_row values set
1418
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1419
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1420
+		$default_datetime = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1421
+		$ticket_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1422
+			? $ticket_datetimes[ $ticket->ID() ]
1423
+			: [];
1424
+		$ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1425
+		$base_price       = $default ? null : $ticket->base_price();
1426
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1427
+		// breaking out complicated condition for ticket_status
1428
+		if ($default) {
1429
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1430
+		} else {
1431
+			$ticket_status_class = $ticket->is_default()
1432
+				? ' tkt-status-' . EE_Ticket::onsale
1433
+				: ' tkt-status-' . $ticket->ticket_status();
1434
+		}
1435
+		// breaking out complicated condition for TKT_taxable
1436
+		if ($default) {
1437
+			$TKT_taxable = '';
1438
+		} else {
1439
+			$TKT_taxable = $ticket->taxable()
1440
+				? 'checked'
1441
+				: '';
1442
+		}
1443
+		if ($default) {
1444
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1445
+		} elseif ($ticket->is_default()) {
1446
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1447
+		} else {
1448
+			$TKT_status = $ticket->ticket_status(true);
1449
+		}
1450
+		if ($default) {
1451
+			$TKT_min = '';
1452
+		} else {
1453
+			$TKT_min = $ticket->min();
1454
+			if ($TKT_min === -1 || $TKT_min === 0) {
1455
+				$TKT_min = '';
1456
+			}
1457
+		}
1458
+		$template_args                 = [
1459
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1460
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1461
+			// on initial page load this will always be the correct order.
1462
+			'tkt_status_class'              => $ticket_status_class,
1463
+			'display_edit_tkt_row'          => 'display:none;',
1464
+			'edit_tkt_expanded'             => '',
1465
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1466
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1467
+			'TKT_start_date'                => $default
1468
+				? ''
1469
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1470
+			'TKT_end_date'                  => $default
1471
+				? ''
1472
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1473
+			'TKT_status'                    => $TKT_status,
1474
+			'TKT_price'                     => $default
1475
+				? ''
1476
+				: EEH_Template::format_currency(
1477
+					$ticket->get_ticket_total_with_taxes(),
1478
+					false,
1479
+					false
1480
+				),
1481
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1482
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1483
+			'TKT_qty'                       => $default
1484
+				? ''
1485
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1486
+			'TKT_qty_for_input'             => $default
1487
+				? ''
1488
+				: $ticket->get_pretty('TKT_qty', 'input'),
1489
+			'TKT_uses'                      => $default
1490
+				? ''
1491
+				: $ticket->get_pretty('TKT_uses', 'input'),
1492
+			'TKT_min'                       => $TKT_min,
1493
+			'TKT_max'                       => $default
1494
+				? ''
1495
+				: $ticket->get_pretty('TKT_max', 'input'),
1496
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold(),
1497
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1498
+			'TKT_registrations'             => $default
1499
+				? 0
1500
+				: $ticket->count_registrations(
1501
+					[
1502
+						[
1503
+							'STS_ID' => [
1504
+								'!=',
1505
+								EEM_Registration::status_id_incomplete,
1506
+							],
1507
+						],
1508
+					]
1509
+				),
1510
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1511
+			'TKT_description'               => $default ? '' : $ticket->get_raw('TKT_description'),
1512
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1513
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1514
+			'TKT_is_default_selector'       => '',
1515
+			'ticket_price_rows'             => '',
1516
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1517
+				? ''
1518
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1519
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1520
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1521
+				? ''
1522
+				: 'display:none;',
1523
+			'show_price_mod_button'         => count($prices) > 1
1524
+											   || ($default && $count_price_mods > 0)
1525
+											   || (! $default && $ticket->deleted())
1526
+				? 'display:none;'
1527
+				: '',
1528
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1529
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1530
+			'starting_ticket_datetime_rows' => $default || $default_datetime ? '' : implode(',', $ticket_datetimes),
1531
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $ticket_datetimes),
1532
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1533
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1534
+			'TKT_taxable'                   => $TKT_taxable,
1535
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1536
+				? ''
1537
+				: 'display:none;',
1538
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1539
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1540
+				$ticket_subtotal,
1541
+				false,
1542
+				false
1543
+			),
1544
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1545
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1546
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1547
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1548
+				? ' ticket-archived'
1549
+				: '',
1550
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1551
+											   && $ticket->deleted()
1552
+											   && ! $ticket->is_permanently_deleteable()
1553
+				? 'dashicons dashicons-lock '
1554
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1555
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1556
+				? ''
1557
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1558
+		];
1559
+		$template_args['trash_hidden'] = count($all_tickets) === 1
1560
+										 && $template_args['trash_icon'] !== 'dashicons dashicons-lock'
1561
+			? 'display:none'
1562
+			: '';
1563
+		// handle rows that should NOT be empty
1564
+		if (empty($template_args['TKT_start_date'])) {
1565
+			// if empty then the start date will be now.
1566
+			$template_args['TKT_start_date']   = date(
1567
+				$this->_date_time_format,
1568
+				current_time('timestamp')
1569
+			);
1570
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1571
+		}
1572
+		if (empty($template_args['TKT_end_date'])) {
1573
+			// get the earliest datetime (if present);
1574
+			$earliest_datetime = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1575
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1576
+					'Datetime',
1577
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1578
+				)
1579
+				: null;
1580
+			if (! empty($earliest_datetime)) {
1581
+				$template_args['TKT_end_date'] = $earliest_datetime->get_datetime(
1582
+					'DTT_EVT_start',
1583
+					$this->_date_time_format
1584
+				);
1585
+			} else {
1586
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1587
+				$template_args['TKT_end_date'] = date(
1588
+					$this->_date_time_format,
1589
+					mktime(
1590
+						24,
1591
+						0,
1592
+						0,
1593
+						date('m'),
1594
+						date('d') + 29,
1595
+						date('Y')
1596
+					)
1597
+				);
1598
+			}
1599
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1600
+		}
1601
+		// generate ticket_datetime items
1602
+		if (! $default) {
1603
+			$datetime_row = 1;
1604
+			foreach ($all_datetimes as $datetime) {
1605
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1606
+					$datetime_row,
1607
+					$ticket_row,
1608
+					$datetime,
1609
+					$ticket,
1610
+					$ticket_datetimes,
1611
+					$default
1612
+				);
1613
+				$datetime_row++;
1614
+			}
1615
+		}
1616
+		$price_row = 1;
1617
+		foreach ($prices as $price) {
1618
+			if (! $price instanceof EE_Price) {
1619
+				continue;
1620
+			}
1621
+			if ($price->is_base_price()) {
1622
+				$price_row++;
1623
+				continue;
1624
+			}
1625
+
1626
+			$show_trash  = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1627
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1628
+
1629
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1630
+				$ticket_row,
1631
+				$price_row,
1632
+				$price,
1633
+				$default,
1634
+				$ticket,
1635
+				$show_trash,
1636
+				$show_create
1637
+			);
1638
+			$price_row++;
1639
+		}
1640
+		// filter $template_args
1641
+		$template_args = apply_filters(
1642
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1643
+			$template_args,
1644
+			$ticket_row,
1645
+			$ticket,
1646
+			$ticket_datetimes,
1647
+			$all_datetimes,
1648
+			$default,
1649
+			$all_tickets,
1650
+			$this->_is_creating_event
1651
+		);
1652
+		return EEH_Template::display_template(
1653
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1654
+			$template_args,
1655
+			true
1656
+		);
1657
+	}
1658
+
1659
+
1660
+	/**
1661
+	 * @param int|string     $ticket_row
1662
+	 * @param EE_Ticket|null $ticket
1663
+	 * @return string
1664
+	 * @throws DomainException
1665
+	 * @throws EE_Error
1666
+	 * @throws ReflectionException
1667
+	 */
1668
+	protected function _get_tax_rows($ticket_row, ?EE_Ticket $ticket): string
1669
+	{
1670
+		$tax_rows = '';
1671
+		/** @var EE_Price[] $taxes */
1672
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1673
+		foreach ($taxes as $tax) {
1674
+			$tax_added     = $this->_get_tax_added($tax, $ticket);
1675
+			$template_args = [
1676
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1677
+					? ''
1678
+					: 'display:none;',
1679
+				'tax_id'            => $tax->ID(),
1680
+				'tkt_row'           => $ticket_row,
1681
+				'tax_label'         => $tax->get('PRC_name'),
1682
+				'tax_added'         => $tax_added,
1683
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1684
+				'tax_amount'        => $tax->get('PRC_amount'),
1685
+			];
1686
+			$template_args = apply_filters(
1687
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1688
+				$template_args,
1689
+				$ticket_row,
1690
+				$ticket,
1691
+				$this->_is_creating_event
1692
+			);
1693
+			$tax_rows      .= EEH_Template::display_template(
1694
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1695
+				$template_args,
1696
+				true
1697
+			);
1698
+		}
1699
+		return $tax_rows;
1700
+	}
1701
+
1702
+
1703
+	/**
1704
+	 * @param EE_Price       $tax
1705
+	 * @param EE_Ticket|null $ticket
1706
+	 * @return float|int
1707
+	 * @throws EE_Error
1708
+	 * @throws ReflectionException
1709
+	 */
1710
+	protected function _get_tax_added(EE_Price $tax, ?EE_Ticket $ticket)
1711
+	{
1712
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1713
+		return $subtotal * $tax->get('PRC_amount') / 100;
1714
+	}
1715
+
1716
+
1717
+	/**
1718
+	 * @param int|string     $ticket_row
1719
+	 * @param int|string     $price_row
1720
+	 * @param EE_Price|null  $price
1721
+	 * @param bool           $default
1722
+	 * @param EE_Ticket|null $ticket
1723
+	 * @param bool           $show_trash
1724
+	 * @param bool           $show_create
1725
+	 * @return string
1726
+	 * @throws InvalidArgumentException
1727
+	 * @throws InvalidInterfaceException
1728
+	 * @throws InvalidDataTypeException
1729
+	 * @throws DomainException
1730
+	 * @throws EE_Error
1731
+	 * @throws ReflectionException
1732
+	 */
1733
+	protected function _get_ticket_price_row(
1734
+		$ticket_row,
1735
+		$price_row,
1736
+		?EE_Price $price,
1737
+		bool $default,
1738
+		?EE_Ticket $ticket,
1739
+		bool $show_trash = true,
1740
+		bool $show_create = true
1741
+	): string {
1742
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1743
+		$template_args = [
1744
+			'tkt_row'               => $default && empty($ticket)
1745
+				? 'TICKETNUM'
1746
+				: $ticket_row,
1747
+			'PRC_order'             => $default && empty($price)
1748
+				? 'PRICENUM'
1749
+				: $price_row,
1750
+			'edit_prices_name'      => $default && empty($price)
1751
+				? 'PRICENAMEATTR'
1752
+				: 'edit_prices',
1753
+			'price_type_selector'   => $default && empty($price)
1754
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, true)
1755
+				: $this->_get_price_type_selector(
1756
+					$ticket_row,
1757
+					$price_row,
1758
+					$price,
1759
+					$default,
1760
+					$send_disabled
1761
+				),
1762
+			'PRC_ID'                => $default && empty($price)
1763
+				? 0
1764
+				: $price->ID(),
1765
+			'PRC_is_default'        => $default && empty($price)
1766
+				? 0
1767
+				: $price->get('PRC_is_default'),
1768
+			'PRC_name'              => $default && empty($price)
1769
+				? ''
1770
+				: $price->get('PRC_name'),
1771
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1772
+			'show_plus_or_minus'    => $default && empty($price)
1773
+				? ''
1774
+				: 'display:none;',
1775
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1776
+				? 'display:none;'
1777
+				: '',
1778
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1779
+				? 'display:none;'
1780
+				: '',
1781
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1782
+				? 'display:none'
1783
+				: '',
1784
+			'PRC_amount'            => $default && empty($price)
1785
+				? 0
1786
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1787
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1788
+				? 'display:none;'
1789
+				: '',
1790
+			'show_trash_icon'       => $show_trash
1791
+				? ''
1792
+				: ' style="display:none;"',
1793
+			'show_create_button'    => $show_create
1794
+				? ''
1795
+				: ' style="display:none;"',
1796
+			'PRC_desc'              => $default && empty($price)
1797
+				? ''
1798
+				: $price->get('PRC_desc'),
1799
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1800
+		];
1801
+		$template_args = apply_filters(
1802
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1803
+			$template_args,
1804
+			$ticket_row,
1805
+			$price_row,
1806
+			$price,
1807
+			$default,
1808
+			$ticket,
1809
+			$show_trash,
1810
+			$show_create,
1811
+			$this->_is_creating_event
1812
+		);
1813
+		return EEH_Template::display_template(
1814
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1815
+			$template_args,
1816
+			true
1817
+		);
1818
+	}
1819
+
1820
+
1821
+	/**
1822
+	 * @param int|string    $ticket_row
1823
+	 * @param int|string    $price_row
1824
+	 * @param EE_Price|null $price
1825
+	 * @param bool          $default
1826
+	 * @param bool          $disabled
1827
+	 * @return string
1828
+	 * @throws ReflectionException
1829
+	 * @throws InvalidArgumentException
1830
+	 * @throws InvalidInterfaceException
1831
+	 * @throws InvalidDataTypeException
1832
+	 * @throws DomainException
1833
+	 * @throws EE_Error
1834
+	 */
1835
+	protected function _get_price_type_selector(
1836
+		$ticket_row,
1837
+		$price_row,
1838
+		?EE_Price $price,
1839
+		bool $default,
1840
+		bool $disabled = false
1841
+	): string {
1842
+		if ($price->is_base_price()) {
1843
+			return $this->_get_base_price_template(
1844
+				$ticket_row,
1845
+				$price_row,
1846
+				$price,
1847
+				$default
1848
+			);
1849
+		}
1850
+		return $this->_get_price_modifier_template(
1851
+			$ticket_row,
1852
+			$price_row,
1853
+			$price,
1854
+			$default,
1855
+			$disabled
1856
+		);
1857
+	}
1858
+
1859
+
1860
+	/**
1861
+	 * @param int|string    $ticket_row
1862
+	 * @param int|string    $price_row
1863
+	 * @param EE_Price|null $price
1864
+	 * @param bool          $default
1865
+	 * @return string
1866
+	 * @throws DomainException
1867
+	 * @throws EE_Error
1868
+	 * @throws ReflectionException
1869
+	 */
1870
+	protected function _get_base_price_template(
1871
+		$ticket_row,
1872
+		$price_row,
1873
+		?EE_Price $price,
1874
+		bool $default
1875
+	): string {
1876
+		$template_args = [
1877
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1878
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1879
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1880
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1881
+			'price_selected_operator'   => '+',
1882
+			'price_selected_is_percent' => 0,
1883
+		];
1884
+		$template_args = apply_filters(
1885
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1886
+			$template_args,
1887
+			$ticket_row,
1888
+			$price_row,
1889
+			$price,
1890
+			$default,
1891
+			$this->_is_creating_event
1892
+		);
1893
+		return EEH_Template::display_template(
1894
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1895
+			$template_args,
1896
+			true
1897
+		);
1898
+	}
1899
+
1900
+
1901
+	/**
1902
+	 * @param int|string    $ticket_row
1903
+	 * @param int|string    $price_row
1904
+	 * @param EE_Price|null $price
1905
+	 * @param bool          $default
1906
+	 * @param bool          $disabled
1907
+	 * @return string
1908
+	 * @throws ReflectionException
1909
+	 * @throws InvalidArgumentException
1910
+	 * @throws InvalidInterfaceException
1911
+	 * @throws InvalidDataTypeException
1912
+	 * @throws DomainException
1913
+	 * @throws EE_Error
1914
+	 */
1915
+	protected function _get_price_modifier_template(
1916
+		$ticket_row,
1917
+		$price_row,
1918
+		?EE_Price $price,
1919
+		bool $default,
1920
+		bool $disabled = false
1921
+	): string {
1922
+		$select_name = $default && ! $price instanceof EE_Price
1923
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1924
+			: 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1925
+
1926
+		$price_type_model       = EEM_Price_Type::instance();
1927
+		$price_types            = $price_type_model->get_all(
1928
+			[
1929
+				[
1930
+					'OR' => [
1931
+						'PBT_ID'  => '2',
1932
+						'PBT_ID*' => '3',
1933
+					],
1934
+				],
1935
+			]
1936
+		);
1937
+		$all_price_types        = $default && ! $price instanceof EE_Price
1938
+			? [esc_html__('Select Modifier', 'event_espresso')]
1939
+			: [];
1940
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1941
+		$price_option_spans     = '';
1942
+		// setup price types for selector
1943
+		foreach ($price_types as $price_type) {
1944
+			if (! $price_type instanceof EE_Price_Type) {
1945
+				continue;
1946
+			}
1947
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1948
+			// while we're in the loop let's setup the option spans used by js
1949
+			$span_args          = [
1950
+				'PRT_ID'         => $price_type->ID(),
1951
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1952
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1953
+			];
1954
+			$price_option_spans .= EEH_Template::display_template(
1955
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1956
+				$span_args,
1957
+				true
1958
+			);
1959
+		}
1960
+
1961
+		$select_name = $disabled
1962
+			? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1963
+			: $select_name;
1964
+
1965
+		$select_input = new EE_Select_Input(
1966
+			$all_price_types,
1967
+			[
1968
+				'default'               => $selected_price_type_id,
1969
+				'html_name'             => $select_name,
1970
+				'html_class'            => 'edit-price-PRT_ID',
1971
+				'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1972
+			]
1973
+		);
1974
+
1975
+		$price_selected_operator   = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1976
+		$price_selected_operator   = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1977
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1978
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1979
+		$template_args             = [
1980
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1981
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1982
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1983
+			'main_name'                 => $select_name,
1984
+			'selected_price_type_id'    => $selected_price_type_id,
1985
+			'price_option_spans'        => $price_option_spans,
1986
+			'price_selected_operator'   => $price_selected_operator,
1987
+			'price_selected_is_percent' => $price_selected_is_percent,
1988
+			'disabled'                  => $disabled,
1989
+		];
1990
+		$template_args             = apply_filters(
1991
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992
+			$template_args,
1993
+			$ticket_row,
1994
+			$price_row,
1995
+			$price,
1996
+			$default,
1997
+			$disabled,
1998
+			$this->_is_creating_event
1999
+		);
2000
+		return EEH_Template::display_template(
2001
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2002
+			$template_args,
2003
+			true
2004
+		);
2005
+	}
2006
+
2007
+
2008
+	/**
2009
+	 * @param int|string       $datetime_row
2010
+	 * @param int|string       $ticket_row
2011
+	 * @param EE_Datetime|null $datetime
2012
+	 * @param EE_Ticket|null   $ticket
2013
+	 * @param array            $ticket_datetimes
2014
+	 * @param bool             $default
2015
+	 * @return string
2016
+	 * @throws DomainException
2017
+	 * @throws EE_Error
2018
+	 * @throws ReflectionException
2019
+	 */
2020
+	protected function _get_ticket_datetime_list_item(
2021
+		$datetime_row,
2022
+		$ticket_row,
2023
+		?EE_Datetime $datetime,
2024
+		?EE_Ticket $ticket,
2025
+		array $ticket_datetimes = [],
2026
+		bool $default = false
2027
+	): string {
2028
+		$ticket_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2029
+			? $ticket_datetimes[ $ticket->ID() ]
2030
+			: [];
2031
+		$template_args    = [
2032
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2033
+				? 'DTTNUM'
2034
+				: $datetime_row,
2035
+			'tkt_row'                  => $default
2036
+				? 'TICKETNUM'
2037
+				: $ticket_row,
2038
+			'ticket_datetime_selected' => in_array($datetime_row, $ticket_datetimes, true)
2039
+				? ' ticket-selected'
2040
+				: '',
2041
+			'ticket_datetime_checked'  => in_array($datetime_row, $ticket_datetimes, true)
2042
+				? ' checked'
2043
+				: '',
2044
+			'DTT_name'                 => $default && empty($datetime)
2045
+				? 'DTTNAME'
2046
+				: $datetime->get_dtt_display_name(true),
2047
+			'tkt_status_class'         => '',
2048
+		];
2049
+		$template_args    = apply_filters(
2050
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2051
+			$template_args,
2052
+			$datetime_row,
2053
+			$ticket_row,
2054
+			$datetime,
2055
+			$ticket,
2056
+			$ticket_datetimes,
2057
+			$default,
2058
+			$this->_is_creating_event
2059
+		);
2060
+		return EEH_Template::display_template(
2061
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2062
+			$template_args,
2063
+			true
2064
+		);
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 * @param array $all_datetimes
2070
+	 * @param array $all_tickets
2071
+	 * @return string
2072
+	 * @throws ReflectionException
2073
+	 * @throws InvalidArgumentException
2074
+	 * @throws InvalidInterfaceException
2075
+	 * @throws InvalidDataTypeException
2076
+	 * @throws DomainException
2077
+	 * @throws EE_Error
2078
+	 */
2079
+	protected function _get_ticket_js_structure(array $all_datetimes = [], array $all_tickets = []): string
2080
+	{
2081
+		$template_args = [
2082
+			'default_datetime_edit_row' => $this->_get_dtt_edit_row(
2083
+				'DTTNUM',
2084
+				null,
2085
+				true,
2086
+				$all_datetimes
2087
+			),
2088
+			'default_ticket_row'        => $this->_get_ticket_row(
2089
+				'TICKETNUM',
2090
+				null,
2091
+				[],
2092
+				[],
2093
+				true
2094
+			),
2095
+			'default_price_row'         => $this->_get_ticket_price_row(
2096
+				'TICKETNUM',
2097
+				'PRICENUM',
2098
+				null,
2099
+				true,
2100
+				null
2101
+			),
2102
+
2103
+			'default_price_rows'                       => '',
2104
+			'default_base_price_amount'                => 0,
2105
+			'default_base_price_name'                  => '',
2106
+			'default_base_price_description'           => '',
2107
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2108
+				'TICKETNUM',
2109
+				'PRICENUM',
2110
+				null,
2111
+				true
2112
+			),
2113
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2114
+				'DTTNUM',
2115
+				null,
2116
+				[],
2117
+				[],
2118
+				true
2119
+			),
2120
+			'existing_available_datetime_tickets_list' => '',
2121
+			'existing_available_ticket_datetimes_list' => '',
2122
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2123
+				'DTTNUM',
2124
+				'TICKETNUM',
2125
+				null,
2126
+				null,
2127
+				[],
2128
+				true
2129
+			),
2130
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2131
+				'DTTNUM',
2132
+				'TICKETNUM',
2133
+				null,
2134
+				null,
2135
+				[],
2136
+				true
2137
+			),
2138
+		];
2139
+		$ticket_row    = 1;
2140
+		foreach ($all_tickets as $ticket) {
2141
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142
+				'DTTNUM',
2143
+				$ticket_row,
2144
+				null,
2145
+				$ticket,
2146
+				[],
2147
+				true
2148
+			);
2149
+			$ticket_row++;
2150
+		}
2151
+		$datetime_row = 1;
2152
+		foreach ($all_datetimes as $datetime) {
2153
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2154
+				$datetime_row,
2155
+				'TICKETNUM',
2156
+				$datetime,
2157
+				null,
2158
+				[],
2159
+				true
2160
+			);
2161
+			$datetime_row++;
2162
+		}
2163
+		$price_model    = EEM_Price::instance();
2164
+		$default_prices = $price_model->get_all_default_prices();
2165
+		$price_row      = 1;
2166
+		foreach ($default_prices as $price) {
2167
+			if (! $price instanceof EE_Price) {
2168
+				continue;
2169
+			}
2170
+			if ($price->is_base_price()) {
2171
+				$template_args['default_base_price_amount']      = $price->get_pretty(
2172
+					'PRC_amount',
2173
+					'localized_float'
2174
+				);
2175
+				$template_args['default_base_price_name']        = $price->get('PRC_name');
2176
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2177
+				$price_row++;
2178
+				continue;
2179
+			}
2180
+
2181
+			$show_trash  = ! ((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1);
2182
+			$show_create = ! (count($default_prices) > 1 && count($default_prices) !== $price_row);
2183
+
2184
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2185
+				'TICKETNUM',
2186
+				$price_row,
2187
+				$price,
2188
+				true,
2189
+				null,
2190
+				$show_trash,
2191
+				$show_create
2192
+			);
2193
+			$price_row++;
2194
+		}
2195
+		$template_args = apply_filters(
2196
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2197
+			$template_args,
2198
+			$all_datetimes,
2199
+			$all_tickets,
2200
+			$this->_is_creating_event
2201
+		);
2202
+		return EEH_Template::display_template(
2203
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2204
+			$template_args,
2205
+			true
2206
+		);
2207
+	}
2208 2208
 }
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     protected function _setup_metaboxes()
77 77
     {
78 78
         // if we were going to add our own metaboxes we'd use the below.
79
-        $this->_metaboxes        = [
79
+        $this->_metaboxes = [
80 80
             0 => [
81 81
                 'page_route' => ['edit', 'create_new'],
82 82
                 'func'       => [$this, 'pricing_metabox'],
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         $this->_date_format_strings['date'] = $this->_date_format_strings['date'] ?? '';
120 120
         $this->_date_format_strings['time'] = $this->_date_format_strings['time'] ?? '';
121 121
 
122
-        $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'];
122
+        $this->_date_time_format = $this->_date_format_strings['date'].' '.$this->_date_format_strings['time'];
123 123
     }
124 124
 
125 125
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             );
144 144
             $msg .= '</p><ul>';
145 145
             foreach ($format_validation as $error) {
146
-                $msg .= '<li>' . $error . '</li>';
146
+                $msg .= '<li>'.$error.'</li>';
147 147
             }
148 148
             $msg .= '</ul><p>';
149 149
             $msg .= sprintf(
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
         $this->_scripts_styles = [
173 173
             'registers'   => [
174 174
                 'ee-tickets-datetimes-css' => [
175
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
175
+                    'url'  => PRICING_ASSETS_URL.'event-tickets-datetimes.css',
176 176
                     'type' => 'css',
177 177
                 ],
178 178
                 'ee-dtt-ticket-metabox'    => [
179
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
179
+                    'url'     => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js',
180 180
                     'depends' => ['ee-datepicker', 'ee-dialog', 'underscore'],
181 181
                 ],
182 182
             ],
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
                         ),
202 202
                         'cancel_button'           => '
203 203
                             <button class="button--secondary ee-modal-cancel">
204
-                                ' . esc_html__('Cancel', 'event_espresso') . '
204
+                                ' . esc_html__('Cancel', 'event_espresso').'
205 205
                             </button>',
206 206
                         'close_button'            => '
207 207
                             <button class="button--secondary ee-modal-cancel">
208
-                                ' . esc_html__('Close', 'event_espresso') . '
208
+                                ' . esc_html__('Close', 'event_espresso').'
209 209
                             </button>',
210 210
                         'single_warning_from_tkt' => esc_html__(
211 211
                             'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
                         ),
218 218
                         'dismiss_button'          => '
219 219
                             <button class="button--secondary ee-modal-cancel">
220
-                                ' . esc_html__('Dismiss', 'event_espresso') . '
220
+                                ' . esc_html__('Dismiss', 'event_espresso').'
221 221
                             </button>',
222 222
                     ],
223 223
                     'DTT_ERROR_MSG'         => [
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
                         'dismiss_button' => '
226 226
                             <div class="save-cancel-button-container">
227 227
                                 <button class="button--secondary ee-modal-cancel">
228
-                                    ' . esc_html__('Dismiss', 'event_espresso') . '
228
+                                    ' . esc_html__('Dismiss', 'event_espresso').'
229 229
                                 </button>
230 230
                             </div>',
231 231
                     ],
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
315 315
             // trim all values to ensure any excess whitespace is removed.
316 316
             $datetime_data = array_map(
317
-                function ($datetime_data) {
317
+                function($datetime_data) {
318 318
                     return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
319 319
                 },
320 320
                 $datetime_data
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
                                             && ! empty($datetime_data['DTT_EVT_end'])
325 325
                 ? $datetime_data['DTT_EVT_end']
326 326
                 : $datetime_data['DTT_EVT_start'];
327
-            $datetime_values              = [
327
+            $datetime_values = [
328 328
                 'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
329 329
                     ? $datetime_data['DTT_ID']
330 330
                     : null,
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 
347 347
             // if we have an id then let's get existing object first and then set the new values.
348 348
             // Otherwise we instantiate a new object for save.
349
-            if (! empty($datetime_data['DTT_ID'])) {
349
+            if ( ! empty($datetime_data['DTT_ID'])) {
350 350
                 $datetime = EE_Registry::instance()
351 351
                                        ->load_model('Datetime', [$timezone])
352 352
                                        ->get_one_by_ID($datetime_data['DTT_ID']);
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
                 // after the add_relation_to() the autosave replaces it.
362 362
                 // We need to do this so we dont' TRASH the parent DTT.
363 363
                 // (save the ID for both key and value to avoid duplications)
364
-                $saved_datetime_ids[ $datetime->ID() ] = $datetime->ID();
364
+                $saved_datetime_ids[$datetime->ID()] = $datetime->ID();
365 365
             } else {
366 366
                 $datetime = EE_Datetime::new_instance(
367 367
                     $datetime_values,
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
             // because it is possible there was a new one created for the autosave.
393 393
             // (save the ID for both key and value to avoid duplications)
394 394
             $DTT_ID                        = $datetime->ID();
395
-            $saved_datetime_ids[ $DTT_ID ] = $DTT_ID;
396
-            $saved_datetime_objs[ $row ]   = $datetime;
395
+            $saved_datetime_ids[$DTT_ID] = $DTT_ID;
396
+            $saved_datetime_objs[$row]   = $datetime;
397 397
             // @todo if ANY of these updates fail then we want the appropriate global error message.
398 398
         }
399 399
         $event->save();
@@ -459,13 +459,13 @@  discard block
 block discarded – undo
459 459
             $update_prices = $create_new_TKT = false;
460 460
             // figure out what datetimes were added to the ticket
461 461
             // and what datetimes were removed from the ticket in the session.
462
-            $starting_ticket_datetime_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
463
-            $ticket_datetime_rows          = explode(',', $data['ticket_datetime_rows'][ $row ]);
462
+            $starting_ticket_datetime_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
463
+            $ticket_datetime_rows          = explode(',', $data['ticket_datetime_rows'][$row]);
464 464
             $datetimes_added               = array_diff($ticket_datetime_rows, $starting_ticket_datetime_rows);
465 465
             $datetimes_removed             = array_diff($starting_ticket_datetime_rows, $ticket_datetime_rows);
466 466
             // trim inputs to ensure any excess whitespace is removed.
467 467
             $ticket_data = array_map(
468
-                function ($ticket_data) {
468
+                function($ticket_data) {
469 469
                     return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
470 470
                 },
471 471
                 $ticket_data
@@ -485,8 +485,8 @@  discard block
 block discarded – undo
485 485
                 ? $base_price
486 486
                 : $ticket_price;
487 487
             $base_price_id = $ticket_data['TKT_base_price_ID'] ?? 0;
488
-            $price_rows    = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
489
-                ? $data['edit_prices'][ $row ]
488
+            $price_rows    = is_array($data['edit_prices']) && isset($data['edit_prices'][$row])
489
+                ? $data['edit_prices'][$row]
490 490
                 : [];
491 491
             $now           = null;
492 492
             if (empty($ticket_data['TKT_start_date'])) {
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
                 /**
499 499
                  * set the TKT_end_date to the first datetime attached to the ticket.
500 500
                  */
501
-                $first_datetime              = $saved_datetimes[ reset($ticket_datetime_rows) ];
501
+                $first_datetime              = $saved_datetimes[reset($ticket_datetime_rows)];
502 502
                 $ticket_data['TKT_end_date'] = $first_datetime->start_date_and_time($this->_date_time_format);
503 503
             }
504 504
             $TKT_values = [
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
                 if ($ticket instanceof EE_Ticket) {
600 600
                     // make sure ticket has an ID of setting relations won't work
601 601
                     $ticket->save();
602
-                    $ticket        = $this->_update_ticket_datetimes(
602
+                    $ticket = $this->_update_ticket_datetimes(
603 603
                         $ticket,
604 604
                         $saved_datetimes,
605 605
                         $datetimes_added,
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
             // need to make sue that the TKT_price is accurate after saving the prices.
634 634
             $ticket->ensure_TKT_Price_correct();
635 635
             // handle CREATING a default ticket from the incoming ticket but ONLY if this isn't an autosave.
636
-            if (! defined('DOING_AUTOSAVE') && ! empty($ticket_data['TKT_is_default_selector'])) {
636
+            if ( ! defined('DOING_AUTOSAVE') && ! empty($ticket_data['TKT_is_default_selector'])) {
637 637
                 $new_default = clone $ticket;
638 638
                 $new_default->set('TKT_ID', 0);
639 639
                 $new_default->set('TKT_is_default', 1);
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
                 // save new TKT
678 678
                 $new_ticket->save();
679 679
                 // add new ticket to array
680
-                $saved_tickets[ $new_ticket->ID() ] = $new_ticket;
680
+                $saved_tickets[$new_ticket->ID()] = $new_ticket;
681 681
                 do_action(
682 682
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
683 683
                     $new_ticket,
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
                 );
688 688
             } else {
689 689
                 // add ticket to saved tickets
690
-                $saved_tickets[ $ticket->ID() ] = $ticket;
690
+                $saved_tickets[$ticket->ID()] = $ticket;
691 691
                 do_action(
692 692
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
693 693
                     $ticket,
@@ -755,25 +755,25 @@  discard block
 block discarded – undo
755 755
         // to start we have to add the ticket to all the datetimes its supposed to be with,
756 756
         // and removing the ticket from datetimes it got removed from.
757 757
         // first let's add datetimes
758
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
758
+        if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
759 759
             foreach ($added_datetimes as $row_id) {
760
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
761
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
760
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
761
+                    $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
762 762
                     // Is this an existing ticket (has an ID) and does it have any sold?
763 763
                     // If so, then we need to add that to the DTT sold because this DTT is getting added.
764 764
                     if ($ticket->ID() && $ticket->sold() > 0) {
765
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
765
+                        $saved_datetimes[$row_id]->increaseSold($ticket->sold(), false);
766 766
                     }
767 767
                 }
768 768
             }
769 769
         }
770 770
         // then remove datetimes
771
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
771
+        if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
772 772
             foreach ($removed_datetimes as $row_id) {
773 773
                 // its entirely possible that a datetime got deleted (instead of just removed from relationship.
774 774
                 // So make sure we skip over this if the datetime isn't in the $saved_datetimes array)
775
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
776
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
775
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
776
+                    $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
777 777
                 }
778 778
             }
779 779
         }
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
             ];
886 886
         }
887 887
         // possibly need to save ticket
888
-        if (! $ticket->ID()) {
888
+        if ( ! $ticket->ID()) {
889 889
             $ticket->save();
890 890
         }
891 891
         foreach ($prices as $row => $prc) {
@@ -919,17 +919,17 @@  discard block
 block discarded – undo
919 919
                 }
920 920
             }
921 921
             $price->save();
922
-            $updated_prices[ $price->ID() ] = $price;
922
+            $updated_prices[$price->ID()] = $price;
923 923
             $ticket->_add_relation_to($price, 'Price');
924 924
         }
925 925
         // now let's remove any prices that got removed from the ticket
926
-        if (! empty($current_prices_on_ticket)) {
926
+        if ( ! empty($current_prices_on_ticket)) {
927 927
             $current          = array_keys($current_prices_on_ticket);
928 928
             $updated          = array_keys($updated_prices);
929 929
             $prices_to_remove = array_diff($current, $updated);
930
-            if (! empty($prices_to_remove)) {
930
+            if ( ! empty($prices_to_remove)) {
931 931
                 foreach ($prices_to_remove as $prc_id) {
932
-                    $p = $current_prices_on_ticket[ $prc_id ];
932
+                    $p = $current_prices_on_ticket[$prc_id];
933 933
                     $ticket->_remove_relation_to($p, 'Price');
934 934
                     // delete permanently the price
935 935
                     $p->delete_or_restore();
@@ -1043,18 +1043,18 @@  discard block
 block discarded – undo
1043 1043
                 $TKT_ID     = $ticket->get('TKT_ID');
1044 1044
                 $ticket_row = $ticket->get('TKT_row');
1045 1045
                 // we only want unique tickets in our final display!!
1046
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1046
+                if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) {
1047 1047
                     $existing_ticket_ids[] = $TKT_ID;
1048 1048
                     $all_tickets[]         = $ticket;
1049 1049
                 }
1050 1050
                 // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1051
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1051
+                $datetime_tickets[$DTT_ID][] = $ticket_row;
1052 1052
                 // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1053 1053
                 if (
1054
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1055
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1054
+                    ! isset($ticket_datetimes[$TKT_ID])
1055
+                    || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true)
1056 1056
                 ) {
1057
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1057
+                    $ticket_datetimes[$TKT_ID][] = $datetime_row;
1058 1058
                 }
1059 1059
             }
1060 1060
             $datetime_row++;
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
         // sort $all_tickets by order
1066 1066
         usort(
1067 1067
             $all_tickets,
1068
-            function (EE_Ticket $a, EE_Ticket $b) {
1068
+            function(EE_Ticket $a, EE_Ticket $b) {
1069 1069
                 $a_order = (int) $a->get('TKT_order');
1070 1070
                 $b_order = (int) $b->get('TKT_order');
1071 1071
                 if ($a_order === $b_order) {
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
         );
1114 1114
 
1115 1115
         EEH_Template::display_template(
1116
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1116
+            PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php',
1117 1117
             $main_template_args
1118 1118
         );
1119 1119
     }
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
         array $all_datetimes = []
1141 1141
     ): string {
1142 1142
         return EEH_Template::display_template(
1143
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1143
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php',
1144 1144
             [
1145 1145
                 'dtt_edit_row'             => $this->_get_dtt_edit_row(
1146 1146
                     $datetime_row,
@@ -1233,7 +1233,7 @@  discard block
 block discarded – undo
1233 1233
             $this->_is_creating_event
1234 1234
         );
1235 1235
         return EEH_Template::display_template(
1236
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1236
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php',
1237 1237
             $template_args,
1238 1238
             true
1239 1239
         );
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
             'DTT_ID'                            => $default ? '' : $datetime->ID(),
1274 1274
         ];
1275 1275
         // need to setup the list items (but only if this isn't a default skeleton setup)
1276
-        if (! $default) {
1276
+        if ( ! $default) {
1277 1277
             $ticket_row = 1;
1278 1278
             foreach ($all_tickets as $ticket) {
1279 1279
                 $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
             $this->_is_creating_event
1299 1299
         );
1300 1300
         return EEH_Template::display_template(
1301
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1301
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php',
1302 1302
             $template_args,
1303 1303
             true
1304 1304
         );
@@ -1324,8 +1324,8 @@  discard block
 block discarded – undo
1324 1324
         array $datetime_tickets = [],
1325 1325
         bool $default = false
1326 1326
     ): string {
1327
-        $datetime_tickets = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1328
-            ? $datetime_tickets[ $datetime->ID() ]
1327
+        $datetime_tickets = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()])
1328
+            ? $datetime_tickets[$datetime->ID()]
1329 1329
             : [];
1330 1330
         $display_row      = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1331 1331
         $no_ticket        = $default && empty($ticket);
@@ -1346,8 +1346,8 @@  discard block
 block discarded – undo
1346 1346
                 ? 'TKTNAME'
1347 1347
                 : $ticket->get('TKT_name'),
1348 1348
             'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1349
-                ? ' tkt-status-' . EE_Ticket::onsale
1350
-                : ' tkt-status-' . $ticket->ticket_status(),
1349
+                ? ' tkt-status-'.EE_Ticket::onsale
1350
+                : ' tkt-status-'.$ticket->ticket_status(),
1351 1351
         ];
1352 1352
         // filter template args
1353 1353
         $template_args = apply_filters(
@@ -1362,7 +1362,7 @@  discard block
 block discarded – undo
1362 1362
             $this->_is_creating_event
1363 1363
         );
1364 1364
         return EEH_Template::display_template(
1365
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1365
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php',
1366 1366
             $template_args,
1367 1367
             true
1368 1368
         );
@@ -1418,19 +1418,19 @@  discard block
 block discarded – undo
1418 1418
         // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1419 1419
         // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1420 1420
         $default_datetime = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1421
-        $ticket_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1422
-            ? $ticket_datetimes[ $ticket->ID() ]
1421
+        $ticket_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
1422
+            ? $ticket_datetimes[$ticket->ID()]
1423 1423
             : [];
1424 1424
         $ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1425 1425
         $base_price       = $default ? null : $ticket->base_price();
1426 1426
         $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1427 1427
         // breaking out complicated condition for ticket_status
1428 1428
         if ($default) {
1429
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1429
+            $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale;
1430 1430
         } else {
1431 1431
             $ticket_status_class = $ticket->is_default()
1432
-                ? ' tkt-status-' . EE_Ticket::onsale
1433
-                : ' tkt-status-' . $ticket->ticket_status();
1432
+                ? ' tkt-status-'.EE_Ticket::onsale
1433
+                : ' tkt-status-'.$ticket->ticket_status();
1434 1434
         }
1435 1435
         // breaking out complicated condition for TKT_taxable
1436 1436
         if ($default) {
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
                 $TKT_min = '';
1456 1456
             }
1457 1457
         }
1458
-        $template_args                 = [
1458
+        $template_args = [
1459 1459
             'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1460 1460
             'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1461 1461
             // on initial page load this will always be the correct order.
@@ -1522,7 +1522,7 @@  discard block
 block discarded – undo
1522 1522
                 : 'display:none;',
1523 1523
             'show_price_mod_button'         => count($prices) > 1
1524 1524
                                                || ($default && $count_price_mods > 0)
1525
-                                               || (! $default && $ticket->deleted())
1525
+                                               || ( ! $default && $ticket->deleted())
1526 1526
                 ? 'display:none;'
1527 1527
                 : '',
1528 1528
             'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
@@ -1563,11 +1563,11 @@  discard block
 block discarded – undo
1563 1563
         // handle rows that should NOT be empty
1564 1564
         if (empty($template_args['TKT_start_date'])) {
1565 1565
             // if empty then the start date will be now.
1566
-            $template_args['TKT_start_date']   = date(
1566
+            $template_args['TKT_start_date'] = date(
1567 1567
                 $this->_date_time_format,
1568 1568
                 current_time('timestamp')
1569 1569
             );
1570
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1570
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1571 1571
         }
1572 1572
         if (empty($template_args['TKT_end_date'])) {
1573 1573
             // get the earliest datetime (if present);
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
                     ['order_by' => ['DTT_EVT_start' => 'ASC']]
1578 1578
                 )
1579 1579
                 : null;
1580
-            if (! empty($earliest_datetime)) {
1580
+            if ( ! empty($earliest_datetime)) {
1581 1581
                 $template_args['TKT_end_date'] = $earliest_datetime->get_datetime(
1582 1582
                     'DTT_EVT_start',
1583 1583
                     $this->_date_time_format
@@ -1596,10 +1596,10 @@  discard block
 block discarded – undo
1596 1596
                     )
1597 1597
                 );
1598 1598
             }
1599
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1599
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1600 1600
         }
1601 1601
         // generate ticket_datetime items
1602
-        if (! $default) {
1602
+        if ( ! $default) {
1603 1603
             $datetime_row = 1;
1604 1604
             foreach ($all_datetimes as $datetime) {
1605 1605
                 $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
@@ -1615,7 +1615,7 @@  discard block
 block discarded – undo
1615 1615
         }
1616 1616
         $price_row = 1;
1617 1617
         foreach ($prices as $price) {
1618
-            if (! $price instanceof EE_Price) {
1618
+            if ( ! $price instanceof EE_Price) {
1619 1619
                 continue;
1620 1620
             }
1621 1621
             if ($price->is_base_price()) {
@@ -1650,7 +1650,7 @@  discard block
 block discarded – undo
1650 1650
             $this->_is_creating_event
1651 1651
         );
1652 1652
         return EEH_Template::display_template(
1653
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1653
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php',
1654 1654
             $template_args,
1655 1655
             true
1656 1656
         );
@@ -1690,8 +1690,8 @@  discard block
 block discarded – undo
1690 1690
                 $ticket,
1691 1691
                 $this->_is_creating_event
1692 1692
             );
1693
-            $tax_rows      .= EEH_Template::display_template(
1694
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1693
+            $tax_rows .= EEH_Template::display_template(
1694
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php',
1695 1695
                 $template_args,
1696 1696
                 true
1697 1697
             );
@@ -1811,7 +1811,7 @@  discard block
 block discarded – undo
1811 1811
             $this->_is_creating_event
1812 1812
         );
1813 1813
         return EEH_Template::display_template(
1814
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1814
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php',
1815 1815
             $template_args,
1816 1816
             true
1817 1817
         );
@@ -1891,7 +1891,7 @@  discard block
 block discarded – undo
1891 1891
             $this->_is_creating_event
1892 1892
         );
1893 1893
         return EEH_Template::display_template(
1894
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1894
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php',
1895 1895
             $template_args,
1896 1896
             true
1897 1897
         );
@@ -1921,7 +1921,7 @@  discard block
 block discarded – undo
1921 1921
     ): string {
1922 1922
         $select_name = $default && ! $price instanceof EE_Price
1923 1923
             ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1924
-            : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1924
+            : 'edit_prices['.esc_attr($ticket_row).']['.esc_attr($price_row).'][PRT_ID]';
1925 1925
 
1926 1926
         $price_type_model       = EEM_Price_Type::instance();
1927 1927
         $price_types            = $price_type_model->get_all(
@@ -1941,25 +1941,25 @@  discard block
 block discarded – undo
1941 1941
         $price_option_spans     = '';
1942 1942
         // setup price types for selector
1943 1943
         foreach ($price_types as $price_type) {
1944
-            if (! $price_type instanceof EE_Price_Type) {
1944
+            if ( ! $price_type instanceof EE_Price_Type) {
1945 1945
                 continue;
1946 1946
             }
1947
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1947
+            $all_price_types[$price_type->ID()] = $price_type->get('PRT_name');
1948 1948
             // while we're in the loop let's setup the option spans used by js
1949
-            $span_args          = [
1949
+            $span_args = [
1950 1950
                 'PRT_ID'         => $price_type->ID(),
1951 1951
                 'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1952 1952
                 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1953 1953
             ];
1954 1954
             $price_option_spans .= EEH_Template::display_template(
1955
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1955
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php',
1956 1956
                 $span_args,
1957 1957
                 true
1958 1958
             );
1959 1959
         }
1960 1960
 
1961 1961
         $select_name = $disabled
1962
-            ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1962
+            ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]'
1963 1963
             : $select_name;
1964 1964
 
1965 1965
         $select_input = new EE_Select_Input(
@@ -1987,7 +1987,7 @@  discard block
 block discarded – undo
1987 1987
             'price_selected_is_percent' => $price_selected_is_percent,
1988 1988
             'disabled'                  => $disabled,
1989 1989
         ];
1990
-        $template_args             = apply_filters(
1990
+        $template_args = apply_filters(
1991 1991
             'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992 1992
             $template_args,
1993 1993
             $ticket_row,
@@ -1998,7 +1998,7 @@  discard block
 block discarded – undo
1998 1998
             $this->_is_creating_event
1999 1999
         );
2000 2000
         return EEH_Template::display_template(
2001
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2001
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php',
2002 2002
             $template_args,
2003 2003
             true
2004 2004
         );
@@ -2025,8 +2025,8 @@  discard block
 block discarded – undo
2025 2025
         array $ticket_datetimes = [],
2026 2026
         bool $default = false
2027 2027
     ): string {
2028
-        $ticket_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2029
-            ? $ticket_datetimes[ $ticket->ID() ]
2028
+        $ticket_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
2029
+            ? $ticket_datetimes[$ticket->ID()]
2030 2030
             : [];
2031 2031
         $template_args    = [
2032 2032
             'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
@@ -2046,7 +2046,7 @@  discard block
 block discarded – undo
2046 2046
                 : $datetime->get_dtt_display_name(true),
2047 2047
             'tkt_status_class'         => '',
2048 2048
         ];
2049
-        $template_args    = apply_filters(
2049
+        $template_args = apply_filters(
2050 2050
             'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2051 2051
             $template_args,
2052 2052
             $datetime_row,
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
             $this->_is_creating_event
2059 2059
         );
2060 2060
         return EEH_Template::display_template(
2061
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2061
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2062 2062
             $template_args,
2063 2063
             true
2064 2064
         );
@@ -2136,7 +2136,7 @@  discard block
 block discarded – undo
2136 2136
                 true
2137 2137
             ),
2138 2138
         ];
2139
-        $ticket_row    = 1;
2139
+        $ticket_row = 1;
2140 2140
         foreach ($all_tickets as $ticket) {
2141 2141
             $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142 2142
                 'DTTNUM',
@@ -2164,11 +2164,11 @@  discard block
 block discarded – undo
2164 2164
         $default_prices = $price_model->get_all_default_prices();
2165 2165
         $price_row      = 1;
2166 2166
         foreach ($default_prices as $price) {
2167
-            if (! $price instanceof EE_Price) {
2167
+            if ( ! $price instanceof EE_Price) {
2168 2168
                 continue;
2169 2169
             }
2170 2170
             if ($price->is_base_price()) {
2171
-                $template_args['default_base_price_amount']      = $price->get_pretty(
2171
+                $template_args['default_base_price_amount'] = $price->get_pretty(
2172 2172
                     'PRC_amount',
2173 2173
                     'localized_float'
2174 2174
                 );
@@ -2200,7 +2200,7 @@  discard block
 block discarded – undo
2200 2200
             $this->_is_creating_event
2201 2201
         );
2202 2202
         return EEH_Template::display_template(
2203
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2203
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php',
2204 2204
             $template_args,
2205 2205
             true
2206 2206
         );
Please login to merge, or discard this patch.