Completed
Branch master (3457d3)
by
unknown
25:39 queued 23:21
created
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 2 patches
Indentation   +2147 added lines, -2147 removed lines patch added patch discarded remove patch
@@ -14,2207 +14,2207 @@
 block discarded – undo
14 14
  */
15 15
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
16 16
 {
17
-    /**
18
-     * This property is just used to hold the status of whether an event is currently being
19
-     * created (true) or edited (false)
20
-     *
21
-     * @access protected
22
-     * @var bool
23
-     */
24
-    protected $_is_creating_event;
17
+	/**
18
+	 * This property is just used to hold the status of whether an event is currently being
19
+	 * created (true) or edited (false)
20
+	 *
21
+	 * @access protected
22
+	 * @var bool
23
+	 */
24
+	protected $_is_creating_event;
25 25
 
26
-    /**
27
-     * Used to contain the format strings for date and time that will be used for php date and
28
-     * time.
29
-     * Is set in the _set_hooks_properties() method.
30
-     *
31
-     * @var array
32
-     */
33
-    protected $_date_format_strings;
26
+	/**
27
+	 * Used to contain the format strings for date and time that will be used for php date and
28
+	 * time.
29
+	 * Is set in the _set_hooks_properties() method.
30
+	 *
31
+	 * @var array
32
+	 */
33
+	protected $_date_format_strings;
34 34
 
35
-    /**
36
-     * @var string $_date_time_format
37
-     */
38
-    protected $_date_time_format;
35
+	/**
36
+	 * @var string $_date_time_format
37
+	 */
38
+	protected $_date_time_format;
39 39
 
40 40
 
41
-    /**
42
-     * @throws InvalidArgumentException
43
-     * @throws InvalidInterfaceException
44
-     * @throws InvalidDataTypeException
45
-     */
46
-    protected function _set_hooks_properties()
47
-    {
48
-        $this->_name = 'pricing';
49
-        // capability check
50
-        if (
51
-            ! EE_Registry::instance()->CAP->current_user_can(
52
-                'ee_read_default_prices',
53
-                'advanced_ticket_datetime_metabox'
54
-            )
55
-        ) {
56
-            return;
57
-        }
58
-        $this->_setup_metaboxes();
59
-        $this->_set_date_time_formats();
60
-        $this->_validate_format_strings();
61
-        $this->_set_scripts_styles();
62
-        // commented out temporarily until logic is implemented in callback
63
-        // add_action(
64
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
65
-        //     array($this, 'autosave_handling')
66
-        // );
67
-        add_filter(
68
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
69
-            array($this, 'caf_updates')
70
-        );
71
-    }
41
+	/**
42
+	 * @throws InvalidArgumentException
43
+	 * @throws InvalidInterfaceException
44
+	 * @throws InvalidDataTypeException
45
+	 */
46
+	protected function _set_hooks_properties()
47
+	{
48
+		$this->_name = 'pricing';
49
+		// capability check
50
+		if (
51
+			! EE_Registry::instance()->CAP->current_user_can(
52
+				'ee_read_default_prices',
53
+				'advanced_ticket_datetime_metabox'
54
+			)
55
+		) {
56
+			return;
57
+		}
58
+		$this->_setup_metaboxes();
59
+		$this->_set_date_time_formats();
60
+		$this->_validate_format_strings();
61
+		$this->_set_scripts_styles();
62
+		// commented out temporarily until logic is implemented in callback
63
+		// add_action(
64
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
65
+		//     array($this, 'autosave_handling')
66
+		// );
67
+		add_filter(
68
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
69
+			array($this, 'caf_updates')
70
+		);
71
+	}
72 72
 
73 73
 
74
-    /**
75
-     * @return void
76
-     */
77
-    protected function _setup_metaboxes()
78
-    {
79
-        // if we were going to add our own metaboxes we'd use the below.
80
-        $this->_metaboxes = array(
81
-            0 => array(
82
-                'page_route' => array('edit', 'create_new'),
83
-                'func'       => 'pricing_metabox',
84
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
85
-                'priority'   => 'high',
86
-                'context'    => 'normal',
87
-            ),
88
-        );
89
-        $this->_remove_metaboxes = array(
90
-            0 => array(
91
-                'page_route' => array('edit', 'create_new'),
92
-                'id'         => 'espresso_event_editor_tickets',
93
-                'context'    => 'normal',
94
-            ),
95
-        );
96
-    }
74
+	/**
75
+	 * @return void
76
+	 */
77
+	protected function _setup_metaboxes()
78
+	{
79
+		// if we were going to add our own metaboxes we'd use the below.
80
+		$this->_metaboxes = array(
81
+			0 => array(
82
+				'page_route' => array('edit', 'create_new'),
83
+				'func'       => 'pricing_metabox',
84
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
85
+				'priority'   => 'high',
86
+				'context'    => 'normal',
87
+			),
88
+		);
89
+		$this->_remove_metaboxes = array(
90
+			0 => array(
91
+				'page_route' => array('edit', 'create_new'),
92
+				'id'         => 'espresso_event_editor_tickets',
93
+				'context'    => 'normal',
94
+			),
95
+		);
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * @return void
101
-     */
102
-    protected function _set_date_time_formats()
103
-    {
104
-        /**
105
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
106
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
107
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
108
-         *
109
-         * @since 4.6.7
110
-         * @var array  Expected an array returned with 'date' and 'time' keys.
111
-         */
112
-        $this->_date_format_strings = apply_filters(
113
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
114
-            array(
115
-                'date' => 'Y-m-d',
116
-                'time' => 'h:i a',
117
-            )
118
-        );
119
-        // validate
120
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
121
-            ? $this->_date_format_strings['date']
122
-            : null;
123
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
124
-            ? $this->_date_format_strings['time']
125
-            : null;
126
-        $this->_date_time_format = $this->_date_format_strings['date']
127
-                                   . ' '
128
-                                   . $this->_date_format_strings['time'];
129
-    }
99
+	/**
100
+	 * @return void
101
+	 */
102
+	protected function _set_date_time_formats()
103
+	{
104
+		/**
105
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
106
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
107
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
108
+		 *
109
+		 * @since 4.6.7
110
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
111
+		 */
112
+		$this->_date_format_strings = apply_filters(
113
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
114
+			array(
115
+				'date' => 'Y-m-d',
116
+				'time' => 'h:i a',
117
+			)
118
+		);
119
+		// validate
120
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
121
+			? $this->_date_format_strings['date']
122
+			: null;
123
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
124
+			? $this->_date_format_strings['time']
125
+			: null;
126
+		$this->_date_time_format = $this->_date_format_strings['date']
127
+								   . ' '
128
+								   . $this->_date_format_strings['time'];
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * @return void
134
-     */
135
-    protected function _validate_format_strings()
136
-    {
137
-        // validate format strings
138
-        $format_validation = EEH_DTT_Helper::validate_format_string(
139
-            $this->_date_time_format
140
-        );
141
-        if (is_array($format_validation)) {
142
-            $msg = '<p>';
143
-            $msg .= sprintf(
144
-                esc_html__(
145
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
146
-                    'event_espresso'
147
-                ),
148
-                $this->_date_time_format
149
-            );
150
-            $msg .= '</p><ul>';
151
-            foreach ($format_validation as $error) {
152
-                $msg .= '<li>' . $error . '</li>';
153
-            }
154
-            $msg .= '</ul><p>';
155
-            $msg .= sprintf(
156
-                esc_html__(
157
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
158
-                    'event_espresso'
159
-                ),
160
-                '<span style="color:#D54E21;">',
161
-                '</span>'
162
-            );
163
-            $msg .= '</p>';
164
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
165
-            $this->_date_format_strings = array(
166
-                'date' => 'Y-m-d',
167
-                'time' => 'h:i a',
168
-            );
169
-        }
170
-    }
132
+	/**
133
+	 * @return void
134
+	 */
135
+	protected function _validate_format_strings()
136
+	{
137
+		// validate format strings
138
+		$format_validation = EEH_DTT_Helper::validate_format_string(
139
+			$this->_date_time_format
140
+		);
141
+		if (is_array($format_validation)) {
142
+			$msg = '<p>';
143
+			$msg .= sprintf(
144
+				esc_html__(
145
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
146
+					'event_espresso'
147
+				),
148
+				$this->_date_time_format
149
+			);
150
+			$msg .= '</p><ul>';
151
+			foreach ($format_validation as $error) {
152
+				$msg .= '<li>' . $error . '</li>';
153
+			}
154
+			$msg .= '</ul><p>';
155
+			$msg .= sprintf(
156
+				esc_html__(
157
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
158
+					'event_espresso'
159
+				),
160
+				'<span style="color:#D54E21;">',
161
+				'</span>'
162
+			);
163
+			$msg .= '</p>';
164
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
165
+			$this->_date_format_strings = array(
166
+				'date' => 'Y-m-d',
167
+				'time' => 'h:i a',
168
+			);
169
+		}
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * @return void
175
-     */
176
-    protected function _set_scripts_styles()
177
-    {
178
-        $this->_scripts_styles = array(
179
-            'registers'   => array(
180
-                'ee-tickets-datetimes-css' => array(
181
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
182
-                    'type' => 'css',
183
-                ),
184
-                'ee-dtt-ticket-metabox'    => array(
185
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
186
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
187
-                ),
188
-            ),
189
-            'deregisters' => array(
190
-                'event-editor-css'       => array('type' => 'css'),
191
-                'event-datetime-metabox' => array('type' => 'js'),
192
-            ),
193
-            'enqueues'    => array(
194
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
195
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
196
-            ),
197
-            'localize'    => array(
198
-                'ee-dtt-ticket-metabox' => array(
199
-                    'DTT_TRASH_BLOCK'       => array(
200
-                        'main_warning'            => esc_html__(
201
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
202
-                            'event_espresso'
203
-                        ),
204
-                        'after_warning'           => esc_html__(
205
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
206
-                            'event_espresso'
207
-                        ),
208
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
209
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
210
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
211
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
212
-                        'single_warning_from_tkt' => esc_html__(
213
-                            '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.',
214
-                            'event_espresso'
215
-                        ),
216
-                        'single_warning_from_dtt' => esc_html__(
217
-                            '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.',
218
-                            'event_espresso'
219
-                        ),
220
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
221
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
222
-                    ),
223
-                    'DTT_ERROR_MSG'         => array(
224
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
225
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
226
-                                            . '<button class="button-secondary ee-modal-cancel">'
227
-                                            . esc_html__('Dismiss', 'event_espresso')
228
-                                            . '</button></div>',
229
-                    ),
230
-                    'DTT_OVERSELL_WARNING'  => array(
231
-                        'datetime_ticket' => esc_html__(
232
-                            '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.',
233
-                            'event_espresso'
234
-                        ),
235
-                        'ticket_datetime' => esc_html__(
236
-                            '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.',
237
-                            'event_espresso'
238
-                        ),
239
-                    ),
240
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
241
-                        $this->_date_format_strings['date'],
242
-                        $this->_date_format_strings['time']
243
-                    ),
244
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
245
-                ),
246
-            ),
247
-        );
248
-    }
173
+	/**
174
+	 * @return void
175
+	 */
176
+	protected function _set_scripts_styles()
177
+	{
178
+		$this->_scripts_styles = array(
179
+			'registers'   => array(
180
+				'ee-tickets-datetimes-css' => array(
181
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
182
+					'type' => 'css',
183
+				),
184
+				'ee-dtt-ticket-metabox'    => array(
185
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
186
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
187
+				),
188
+			),
189
+			'deregisters' => array(
190
+				'event-editor-css'       => array('type' => 'css'),
191
+				'event-datetime-metabox' => array('type' => 'js'),
192
+			),
193
+			'enqueues'    => array(
194
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
195
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
196
+			),
197
+			'localize'    => array(
198
+				'ee-dtt-ticket-metabox' => array(
199
+					'DTT_TRASH_BLOCK'       => array(
200
+						'main_warning'            => esc_html__(
201
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
202
+							'event_espresso'
203
+						),
204
+						'after_warning'           => esc_html__(
205
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
206
+							'event_espresso'
207
+						),
208
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
209
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
210
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
211
+													 . esc_html__('Close', 'event_espresso') . '</button>',
212
+						'single_warning_from_tkt' => esc_html__(
213
+							'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.',
214
+							'event_espresso'
215
+						),
216
+						'single_warning_from_dtt' => esc_html__(
217
+							'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.',
218
+							'event_espresso'
219
+						),
220
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
221
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
222
+					),
223
+					'DTT_ERROR_MSG'         => array(
224
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
225
+						'dismiss_button' => '<div class="save-cancel-button-container">'
226
+											. '<button class="button-secondary ee-modal-cancel">'
227
+											. esc_html__('Dismiss', 'event_espresso')
228
+											. '</button></div>',
229
+					),
230
+					'DTT_OVERSELL_WARNING'  => array(
231
+						'datetime_ticket' => esc_html__(
232
+							'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.',
233
+							'event_espresso'
234
+						),
235
+						'ticket_datetime' => esc_html__(
236
+							'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.',
237
+							'event_espresso'
238
+						),
239
+					),
240
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
241
+						$this->_date_format_strings['date'],
242
+						$this->_date_format_strings['time']
243
+					),
244
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
245
+				),
246
+			),
247
+		);
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * @param array $update_callbacks
253
-     * @return array
254
-     */
255
-    public function caf_updates(array $update_callbacks)
256
-    {
257
-        foreach ($update_callbacks as $key => $callback) {
258
-            if ($callback[1] === '_default_tickets_update') {
259
-                unset($update_callbacks[ $key ]);
260
-            }
261
-        }
262
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
263
-        return $update_callbacks;
264
-    }
251
+	/**
252
+	 * @param array $update_callbacks
253
+	 * @return array
254
+	 */
255
+	public function caf_updates(array $update_callbacks)
256
+	{
257
+		foreach ($update_callbacks as $key => $callback) {
258
+			if ($callback[1] === '_default_tickets_update') {
259
+				unset($update_callbacks[ $key ]);
260
+			}
261
+		}
262
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
263
+		return $update_callbacks;
264
+	}
265 265
 
266 266
 
267
-    /**
268
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
269
-     *
270
-     * @param  EE_Event $event The Event object we're attaching data to
271
-     * @param  array    $data  The request data from the form
272
-     * @throws ReflectionException
273
-     * @throws Exception
274
-     * @throws InvalidInterfaceException
275
-     * @throws InvalidDataTypeException
276
-     * @throws EE_Error
277
-     * @throws InvalidArgumentException
278
-     */
279
-    public function datetime_and_tickets_caf_update($event, $data)
280
-    {
281
-        // first we need to start with datetimes cause they are the "root" items attached to events.
282
-        $saved_datetimes = $this->_update_datetimes($event, $data);
283
-        // next tackle the tickets (and prices?)
284
-        $this->_update_tickets($event, $saved_datetimes, $data);
285
-    }
267
+	/**
268
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
269
+	 *
270
+	 * @param  EE_Event $event The Event object we're attaching data to
271
+	 * @param  array    $data  The request data from the form
272
+	 * @throws ReflectionException
273
+	 * @throws Exception
274
+	 * @throws InvalidInterfaceException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws EE_Error
277
+	 * @throws InvalidArgumentException
278
+	 */
279
+	public function datetime_and_tickets_caf_update($event, $data)
280
+	{
281
+		// first we need to start with datetimes cause they are the "root" items attached to events.
282
+		$saved_datetimes = $this->_update_datetimes($event, $data);
283
+		// next tackle the tickets (and prices?)
284
+		$this->_update_tickets($event, $saved_datetimes, $data);
285
+	}
286 286
 
287 287
 
288
-    /**
289
-     * update event_datetimes
290
-     *
291
-     * @param  EE_Event $event Event being updated
292
-     * @param  array    $data  the request data from the form
293
-     * @return EE_Datetime[]
294
-     * @throws Exception
295
-     * @throws ReflectionException
296
-     * @throws InvalidInterfaceException
297
-     * @throws InvalidDataTypeException
298
-     * @throws InvalidArgumentException
299
-     * @throws EE_Error
300
-     */
301
-    protected function _update_datetimes($event, $data)
302
-    {
303
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
304
-        $saved_dtt_ids = array();
305
-        $saved_dtt_objs = array();
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
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
323
-                                            && ! empty($datetime_data['DTT_EVT_end'])
324
-                ? $datetime_data['DTT_EVT_end']
325
-                : $datetime_data['DTT_EVT_start'];
326
-            $datetime_values = array(
327
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
328
-                    ? $datetime_data['DTT_ID']
329
-                    : null,
330
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
331
-                    ? $datetime_data['DTT_name']
332
-                    : '',
333
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
334
-                    ? $datetime_data['DTT_description']
335
-                    : '',
336
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
337
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
338
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
339
-                    ? EE_INF
340
-                    : $datetime_data['DTT_reg_limit'],
341
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
342
-                    ? $row
343
-                    : $datetime_data['DTT_order'],
344
-            );
345
-            // if we have an id then let's get existing object first and then set the new values.
346
-            // Otherwise we instantiate a new object for save.
347
-            if (! empty($datetime_data['DTT_ID'])) {
348
-                $datetime = EE_Registry::instance()
349
-                                       ->load_model('Datetime', array($timezone))
350
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
351
-                // set date and time format according to what is set in this class.
352
-                $datetime->set_date_format($this->_date_format_strings['date']);
353
-                $datetime->set_time_format($this->_date_format_strings['time']);
354
-                foreach ($datetime_values as $field => $value) {
355
-                    $datetime->set($field, $value);
356
-                }
357
-                // make sure the $dtt_id here is saved just in case
358
-                // after the add_relation_to() the autosave replaces it.
359
-                // We need to do this so we dont' TRASH the parent DTT.
360
-                // (save the ID for both key and value to avoid duplications)
361
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
362
-            } else {
363
-                $datetime = EE_Registry::instance()->load_class(
364
-                    'Datetime',
365
-                    array(
366
-                        $datetime_values,
367
-                        $timezone,
368
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
369
-                    ),
370
-                    false,
371
-                    false
372
-                );
373
-                foreach ($datetime_values as $field => $value) {
374
-                    $datetime->set($field, $value);
375
-                }
376
-            }
377
-            $datetime->save();
378
-            do_action(
379
-                'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
380
-                $datetime,
381
-                $row,
382
-                $datetime_data,
383
-                $data
384
-            );
385
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
386
-            // before going any further make sure our dates are setup correctly
387
-            // so that the end date is always equal or greater than the start date.
388
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
389
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
390
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
391
-                $datetime->save();
392
-            }
393
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
394
-            // because it is possible there was a new one created for the autosave.
395
-            // (save the ID for both key and value to avoid duplications)
396
-            $DTT_ID = $datetime->ID();
397
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
398
-            $saved_dtt_objs[ $row ] = $datetime;
399
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
400
-        }
401
-        $event->save();
402
-        // now we need to REMOVE any datetimes that got deleted.
403
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
404
-        // So its safe to permanently delete at this point.
405
-        $old_datetimes = explode(',', $data['datetime_IDs']);
406
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
407
-        if (is_array($old_datetimes)) {
408
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
409
-            foreach ($datetimes_to_delete as $id) {
410
-                $id = absint($id);
411
-                if (empty($id)) {
412
-                    continue;
413
-                }
414
-                /** @var EE_Datetime $dtt_to_remove */
415
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
416
-                // remove tkt relationships.
417
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
418
-                foreach ($related_tickets as $tkt) {
419
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
420
-                }
421
-                $event->_remove_relation_to($id, 'Datetime');
422
-                $dtt_to_remove->refresh_cache_of_related_objects();
423
-                $dtt_to_remove->delete_or_restore();
424
-            }
425
-        }
426
-        return $saved_dtt_objs;
427
-    }
288
+	/**
289
+	 * update event_datetimes
290
+	 *
291
+	 * @param  EE_Event $event Event being updated
292
+	 * @param  array    $data  the request data from the form
293
+	 * @return EE_Datetime[]
294
+	 * @throws Exception
295
+	 * @throws ReflectionException
296
+	 * @throws InvalidInterfaceException
297
+	 * @throws InvalidDataTypeException
298
+	 * @throws InvalidArgumentException
299
+	 * @throws EE_Error
300
+	 */
301
+	protected function _update_datetimes($event, $data)
302
+	{
303
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
304
+		$saved_dtt_ids = array();
305
+		$saved_dtt_objs = array();
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
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
323
+											&& ! empty($datetime_data['DTT_EVT_end'])
324
+				? $datetime_data['DTT_EVT_end']
325
+				: $datetime_data['DTT_EVT_start'];
326
+			$datetime_values = array(
327
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
328
+					? $datetime_data['DTT_ID']
329
+					: null,
330
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
331
+					? $datetime_data['DTT_name']
332
+					: '',
333
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
334
+					? $datetime_data['DTT_description']
335
+					: '',
336
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
337
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
338
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
339
+					? EE_INF
340
+					: $datetime_data['DTT_reg_limit'],
341
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
342
+					? $row
343
+					: $datetime_data['DTT_order'],
344
+			);
345
+			// if we have an id then let's get existing object first and then set the new values.
346
+			// Otherwise we instantiate a new object for save.
347
+			if (! empty($datetime_data['DTT_ID'])) {
348
+				$datetime = EE_Registry::instance()
349
+									   ->load_model('Datetime', array($timezone))
350
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
351
+				// set date and time format according to what is set in this class.
352
+				$datetime->set_date_format($this->_date_format_strings['date']);
353
+				$datetime->set_time_format($this->_date_format_strings['time']);
354
+				foreach ($datetime_values as $field => $value) {
355
+					$datetime->set($field, $value);
356
+				}
357
+				// make sure the $dtt_id here is saved just in case
358
+				// after the add_relation_to() the autosave replaces it.
359
+				// We need to do this so we dont' TRASH the parent DTT.
360
+				// (save the ID for both key and value to avoid duplications)
361
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
362
+			} else {
363
+				$datetime = EE_Registry::instance()->load_class(
364
+					'Datetime',
365
+					array(
366
+						$datetime_values,
367
+						$timezone,
368
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
369
+					),
370
+					false,
371
+					false
372
+				);
373
+				foreach ($datetime_values as $field => $value) {
374
+					$datetime->set($field, $value);
375
+				}
376
+			}
377
+			$datetime->save();
378
+			do_action(
379
+				'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save',
380
+				$datetime,
381
+				$row,
382
+				$datetime_data,
383
+				$data
384
+			);
385
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
386
+			// before going any further make sure our dates are setup correctly
387
+			// so that the end date is always equal or greater than the start date.
388
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
389
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
390
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
391
+				$datetime->save();
392
+			}
393
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
394
+			// because it is possible there was a new one created for the autosave.
395
+			// (save the ID for both key and value to avoid duplications)
396
+			$DTT_ID = $datetime->ID();
397
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
398
+			$saved_dtt_objs[ $row ] = $datetime;
399
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
400
+		}
401
+		$event->save();
402
+		// now we need to REMOVE any datetimes that got deleted.
403
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
404
+		// So its safe to permanently delete at this point.
405
+		$old_datetimes = explode(',', $data['datetime_IDs']);
406
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
407
+		if (is_array($old_datetimes)) {
408
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
409
+			foreach ($datetimes_to_delete as $id) {
410
+				$id = absint($id);
411
+				if (empty($id)) {
412
+					continue;
413
+				}
414
+				/** @var EE_Datetime $dtt_to_remove */
415
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
416
+				// remove tkt relationships.
417
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
418
+				foreach ($related_tickets as $tkt) {
419
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
420
+				}
421
+				$event->_remove_relation_to($id, 'Datetime');
422
+				$dtt_to_remove->refresh_cache_of_related_objects();
423
+				$dtt_to_remove->delete_or_restore();
424
+			}
425
+		}
426
+		return $saved_dtt_objs;
427
+	}
428 428
 
429 429
 
430
-    /**
431
-     * update tickets
432
-     *
433
-     * @param  EE_Event      $event           Event object being updated
434
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
435
-     * @param  array         $data            incoming request data
436
-     * @return EE_Ticket[]
437
-     * @throws Exception
438
-     * @throws ReflectionException
439
-     * @throws InvalidInterfaceException
440
-     * @throws InvalidDataTypeException
441
-     * @throws InvalidArgumentException
442
-     * @throws EE_Error
443
-     */
444
-    protected function _update_tickets($event, $saved_datetimes, $data)
445
-    {
446
-        $new_tkt = null;
447
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
448
-        $data = stripslashes_deep($data);
449
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
450
-        $saved_tickets = array();
451
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
452
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
453
-            throw new InvalidArgumentException(
454
-                esc_html__(
455
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
456
-                    'event_espresso'
457
-                )
458
-            );
459
-        }
460
-        foreach ($data['edit_tickets'] as $row => $tkt) {
461
-            $update_prices = $create_new_TKT = false;
462
-            // figure out what datetimes were added to the ticket
463
-            // and what datetimes were removed from the ticket in the session.
464
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
465
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
466
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
467
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
468
-            // trim inputs to ensure any excess whitespace is removed.
469
-            $tkt = array_map(
470
-                function ($ticket_data) {
471
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
472
-                },
473
-                $tkt
474
-            );
475
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
476
-            // because we're doing calculations prior to using the models.
477
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
478
-            $ticket_price = isset($tkt['TKT_price'])
479
-                ? round((float) $tkt['TKT_price'], 3)
480
-                : 0;
481
-            // note incoming base price needs converted from localized value.
482
-            $base_price = isset($tkt['TKT_base_price'])
483
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
484
-                : 0;
485
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
486
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
487
-                ? $base_price
488
-                : $ticket_price;
489
-            $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
490
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
491
-                ? $data['edit_prices'][ $row ]
492
-                : array();
493
-            $now = null;
494
-            if (empty($tkt['TKT_start_date'])) {
495
-                // lets' use now in the set timezone.
496
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
497
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
498
-            }
499
-            if (empty($tkt['TKT_end_date'])) {
500
-                /**
501
-                 * set the TKT_end_date to the first datetime attached to the ticket.
502
-                 */
503
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
504
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
505
-            }
506
-            $TKT_values = array(
507
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
508
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
509
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
510
-                'TKT_description' => ! empty($tkt['TKT_description'])
511
-                                     && $tkt['TKT_description'] !== esc_html__(
512
-                                         'You can modify this description',
513
-                                         'event_espresso'
514
-                                     )
515
-                    ? $tkt['TKT_description']
516
-                    : '',
517
-                'TKT_start_date'  => $tkt['TKT_start_date'],
518
-                'TKT_end_date'    => $tkt['TKT_end_date'],
519
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
520
-                    ? EE_INF
521
-                    : $tkt['TKT_qty'],
522
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
523
-                    ? EE_INF
524
-                    : $tkt['TKT_uses'],
525
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
526
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
527
-                'TKT_row'         => $row,
528
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
529
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
530
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
531
-                'TKT_price'       => $ticket_price,
532
-            );
533
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
534
-            // which means in turn that the prices will become new prices as well.
535
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
536
-                $TKT_values['TKT_ID'] = 0;
537
-                $TKT_values['TKT_is_default'] = 0;
538
-                $update_prices = true;
539
-            }
540
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
541
-            // we actually do our saves ahead of doing any add_relations to
542
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
543
-            // but DID have it's items modified.
544
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
545
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
546
-            if (absint($TKT_values['TKT_ID'])) {
547
-                $ticket = EE_Registry::instance()
548
-                                     ->load_model('Ticket', array($timezone))
549
-                                     ->get_one_by_ID($tkt['TKT_ID']);
550
-                if ($ticket instanceof EE_Ticket) {
551
-                    $ticket = $this->_update_ticket_datetimes(
552
-                        $ticket,
553
-                        $saved_datetimes,
554
-                        $datetimes_added,
555
-                        $datetimes_removed
556
-                    );
557
-                    // are there any registrations using this ticket ?
558
-                    $tickets_sold = $ticket->count_related(
559
-                        'Registration',
560
-                        array(
561
-                            array(
562
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
563
-                            ),
564
-                        )
565
-                    );
566
-                    // set ticket formats
567
-                    $ticket->set_date_format($this->_date_format_strings['date']);
568
-                    $ticket->set_time_format($this->_date_format_strings['time']);
569
-                    // let's just check the total price for the existing ticket
570
-                    // and determine if it matches the new total price.
571
-                    // if they are different then we create a new ticket (if tickets sold)
572
-                    // if they aren't different then we go ahead and modify existing ticket.
573
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
574
-                    // set new values
575
-                    foreach ($TKT_values as $field => $value) {
576
-                        if ($field === 'TKT_qty') {
577
-                            $ticket->set_qty($value);
578
-                        } else {
579
-                            $ticket->set($field, $value);
580
-                        }
581
-                    }
582
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
583
-                    // Otherwise we have to create a new ticket.
584
-                    if ($create_new_TKT) {
585
-                        $new_tkt = $this->_duplicate_ticket(
586
-                            $ticket,
587
-                            $price_rows,
588
-                            $ticket_price,
589
-                            $base_price,
590
-                            $base_price_id
591
-                        );
592
-                    }
593
-                }
594
-            } else {
595
-                // no TKT_id so a new TKT
596
-                $ticket = EE_Ticket::new_instance(
597
-                    $TKT_values,
598
-                    $timezone,
599
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
600
-                );
601
-                if ($ticket instanceof EE_Ticket) {
602
-                    // make sure ticket has an ID of setting relations won't work
603
-                    $ticket->save();
604
-                    $ticket = $this->_update_ticket_datetimes(
605
-                        $ticket,
606
-                        $saved_datetimes,
607
-                        $datetimes_added,
608
-                        $datetimes_removed
609
-                    );
610
-                    $update_prices = true;
611
-                }
612
-            }
613
-            // make sure any current values have been saved.
614
-            // $ticket->save();
615
-            // before going any further make sure our dates are setup correctly
616
-            // so that the end date is always equal or greater than the start date.
617
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
618
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
619
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
620
-            }
621
-            // let's make sure the base price is handled
622
-            $ticket = ! $create_new_TKT
623
-                ? $this->_add_prices_to_ticket(
624
-                    array(),
625
-                    $ticket,
626
-                    $update_prices,
627
-                    $base_price,
628
-                    $base_price_id
629
-                )
630
-                : $ticket;
631
-            // add/update price_modifiers
632
-            $ticket = ! $create_new_TKT
633
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
634
-                : $ticket;
635
-            // need to make sue that the TKT_price is accurate after saving the prices.
636
-            $ticket->ensure_TKT_Price_correct();
637
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
638
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
639
-                $update_prices = true;
640
-                $new_default = clone $ticket;
641
-                $new_default->set('TKT_ID', 0);
642
-                $new_default->set('TKT_is_default', 1);
643
-                $new_default->set('TKT_row', 1);
644
-                $new_default->set('TKT_price', $ticket_price);
645
-                // remove any dtt relations cause we DON'T want dtt relations attached
646
-                // (note this is just removing the cached relations in the object)
647
-                $new_default->_remove_relations('Datetime');
648
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
649
-                $new_default = $this->_add_prices_to_ticket(
650
-                    $price_rows,
651
-                    $new_default,
652
-                    $update_prices
653
-                );
654
-                // don't forget the base price!
655
-                $new_default = $this->_add_prices_to_ticket(
656
-                    array(),
657
-                    $new_default,
658
-                    $update_prices,
659
-                    $base_price,
660
-                    $base_price_id
661
-                );
662
-                $new_default->save();
663
-                do_action(
664
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
665
-                    $new_default,
666
-                    $row,
667
-                    $ticket,
668
-                    $data
669
-                );
670
-            }
671
-            // DO ALL dtt relationships for both current tickets and any archived tickets
672
-            // for the given dtt that are related to the current ticket.
673
-            // TODO... not sure exactly how we're going to do this considering we don't know
674
-            // what current ticket the archived tickets are related to
675
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
676
-            // let's assign any tickets that have been setup to the saved_tickets tracker
677
-            // save existing TKT
678
-            $ticket->save();
679
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
680
-                // save new TKT
681
-                $new_tkt->save();
682
-                // add new ticket to array
683
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
684
-                do_action(
685
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
686
-                    $new_tkt,
687
-                    $row,
688
-                    $tkt,
689
-                    $data
690
-                );
691
-            } else {
692
-                // add tkt to saved tkts
693
-                $saved_tickets[ $ticket->ID() ] = $ticket;
694
-                do_action(
695
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
696
-                    $ticket,
697
-                    $row,
698
-                    $tkt,
699
-                    $data
700
-                );
701
-            }
702
-        }
703
-        // now we need to handle tickets actually "deleted permanently".
704
-        // There are cases where we'd want this to happen
705
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
706
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
707
-        // No sense in keeping all the related data in the db!
708
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
709
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
710
-        foreach ($tickets_removed as $id) {
711
-            $id = absint($id);
712
-            // get the ticket for this id
713
-            $tkt_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
714
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
715
-            if ($tkt_to_remove->get('TKT_is_default')) {
716
-                continue;
717
-            }
718
-            // if this tkt has any registrations attached so then we just ARCHIVE
719
-            // because we don't actually permanently delete these tickets.
720
-            if ($tkt_to_remove->count_related('Registration') > 0) {
721
-                $tkt_to_remove->delete();
722
-                continue;
723
-            }
724
-            // need to get all the related datetimes on this ticket and remove from every single one of them
725
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
726
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
727
-            foreach ($datetimes as $datetime) {
728
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
729
-            }
730
-            // need to do the same for prices (except these prices can also be deleted because again,
731
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
732
-            $tkt_to_remove->delete_related('Price');
733
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
734
-            // finally let's delete this ticket
735
-            // (which should not be blocked at this point b/c we've removed all our relationships)
736
-            $tkt_to_remove->delete_or_restore();
737
-        }
738
-        return $saved_tickets;
739
-    }
430
+	/**
431
+	 * update tickets
432
+	 *
433
+	 * @param  EE_Event      $event           Event object being updated
434
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
435
+	 * @param  array         $data            incoming request data
436
+	 * @return EE_Ticket[]
437
+	 * @throws Exception
438
+	 * @throws ReflectionException
439
+	 * @throws InvalidInterfaceException
440
+	 * @throws InvalidDataTypeException
441
+	 * @throws InvalidArgumentException
442
+	 * @throws EE_Error
443
+	 */
444
+	protected function _update_tickets($event, $saved_datetimes, $data)
445
+	{
446
+		$new_tkt = null;
447
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
448
+		$data = stripslashes_deep($data);
449
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
450
+		$saved_tickets = array();
451
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
452
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
453
+			throw new InvalidArgumentException(
454
+				esc_html__(
455
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
456
+					'event_espresso'
457
+				)
458
+			);
459
+		}
460
+		foreach ($data['edit_tickets'] as $row => $tkt) {
461
+			$update_prices = $create_new_TKT = false;
462
+			// figure out what datetimes were added to the ticket
463
+			// and what datetimes were removed from the ticket in the session.
464
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
465
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
466
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
467
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
468
+			// trim inputs to ensure any excess whitespace is removed.
469
+			$tkt = array_map(
470
+				function ($ticket_data) {
471
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
472
+				},
473
+				$tkt
474
+			);
475
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
476
+			// because we're doing calculations prior to using the models.
477
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
478
+			$ticket_price = isset($tkt['TKT_price'])
479
+				? round((float) $tkt['TKT_price'], 3)
480
+				: 0;
481
+			// note incoming base price needs converted from localized value.
482
+			$base_price = isset($tkt['TKT_base_price'])
483
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
484
+				: 0;
485
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
486
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
487
+				? $base_price
488
+				: $ticket_price;
489
+			$base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
490
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
491
+				? $data['edit_prices'][ $row ]
492
+				: array();
493
+			$now = null;
494
+			if (empty($tkt['TKT_start_date'])) {
495
+				// lets' use now in the set timezone.
496
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
497
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
498
+			}
499
+			if (empty($tkt['TKT_end_date'])) {
500
+				/**
501
+				 * set the TKT_end_date to the first datetime attached to the ticket.
502
+				 */
503
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
504
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
505
+			}
506
+			$TKT_values = array(
507
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
508
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
509
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
510
+				'TKT_description' => ! empty($tkt['TKT_description'])
511
+									 && $tkt['TKT_description'] !== esc_html__(
512
+										 'You can modify this description',
513
+										 'event_espresso'
514
+									 )
515
+					? $tkt['TKT_description']
516
+					: '',
517
+				'TKT_start_date'  => $tkt['TKT_start_date'],
518
+				'TKT_end_date'    => $tkt['TKT_end_date'],
519
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
520
+					? EE_INF
521
+					: $tkt['TKT_qty'],
522
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
523
+					? EE_INF
524
+					: $tkt['TKT_uses'],
525
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
526
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
527
+				'TKT_row'         => $row,
528
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
529
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
530
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
531
+				'TKT_price'       => $ticket_price,
532
+			);
533
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
534
+			// which means in turn that the prices will become new prices as well.
535
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
536
+				$TKT_values['TKT_ID'] = 0;
537
+				$TKT_values['TKT_is_default'] = 0;
538
+				$update_prices = true;
539
+			}
540
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
541
+			// we actually do our saves ahead of doing any add_relations to
542
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
543
+			// but DID have it's items modified.
544
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
545
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
546
+			if (absint($TKT_values['TKT_ID'])) {
547
+				$ticket = EE_Registry::instance()
548
+									 ->load_model('Ticket', array($timezone))
549
+									 ->get_one_by_ID($tkt['TKT_ID']);
550
+				if ($ticket instanceof EE_Ticket) {
551
+					$ticket = $this->_update_ticket_datetimes(
552
+						$ticket,
553
+						$saved_datetimes,
554
+						$datetimes_added,
555
+						$datetimes_removed
556
+					);
557
+					// are there any registrations using this ticket ?
558
+					$tickets_sold = $ticket->count_related(
559
+						'Registration',
560
+						array(
561
+							array(
562
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
563
+							),
564
+						)
565
+					);
566
+					// set ticket formats
567
+					$ticket->set_date_format($this->_date_format_strings['date']);
568
+					$ticket->set_time_format($this->_date_format_strings['time']);
569
+					// let's just check the total price for the existing ticket
570
+					// and determine if it matches the new total price.
571
+					// if they are different then we create a new ticket (if tickets sold)
572
+					// if they aren't different then we go ahead and modify existing ticket.
573
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
574
+					// set new values
575
+					foreach ($TKT_values as $field => $value) {
576
+						if ($field === 'TKT_qty') {
577
+							$ticket->set_qty($value);
578
+						} else {
579
+							$ticket->set($field, $value);
580
+						}
581
+					}
582
+					// if $create_new_TKT is false then we can safely update the existing ticket.
583
+					// Otherwise we have to create a new ticket.
584
+					if ($create_new_TKT) {
585
+						$new_tkt = $this->_duplicate_ticket(
586
+							$ticket,
587
+							$price_rows,
588
+							$ticket_price,
589
+							$base_price,
590
+							$base_price_id
591
+						);
592
+					}
593
+				}
594
+			} else {
595
+				// no TKT_id so a new TKT
596
+				$ticket = EE_Ticket::new_instance(
597
+					$TKT_values,
598
+					$timezone,
599
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
600
+				);
601
+				if ($ticket instanceof EE_Ticket) {
602
+					// make sure ticket has an ID of setting relations won't work
603
+					$ticket->save();
604
+					$ticket = $this->_update_ticket_datetimes(
605
+						$ticket,
606
+						$saved_datetimes,
607
+						$datetimes_added,
608
+						$datetimes_removed
609
+					);
610
+					$update_prices = true;
611
+				}
612
+			}
613
+			// make sure any current values have been saved.
614
+			// $ticket->save();
615
+			// before going any further make sure our dates are setup correctly
616
+			// so that the end date is always equal or greater than the start date.
617
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
618
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
619
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
620
+			}
621
+			// let's make sure the base price is handled
622
+			$ticket = ! $create_new_TKT
623
+				? $this->_add_prices_to_ticket(
624
+					array(),
625
+					$ticket,
626
+					$update_prices,
627
+					$base_price,
628
+					$base_price_id
629
+				)
630
+				: $ticket;
631
+			// add/update price_modifiers
632
+			$ticket = ! $create_new_TKT
633
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
634
+				: $ticket;
635
+			// need to make sue that the TKT_price is accurate after saving the prices.
636
+			$ticket->ensure_TKT_Price_correct();
637
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
638
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
639
+				$update_prices = true;
640
+				$new_default = clone $ticket;
641
+				$new_default->set('TKT_ID', 0);
642
+				$new_default->set('TKT_is_default', 1);
643
+				$new_default->set('TKT_row', 1);
644
+				$new_default->set('TKT_price', $ticket_price);
645
+				// remove any dtt relations cause we DON'T want dtt relations attached
646
+				// (note this is just removing the cached relations in the object)
647
+				$new_default->_remove_relations('Datetime');
648
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
649
+				$new_default = $this->_add_prices_to_ticket(
650
+					$price_rows,
651
+					$new_default,
652
+					$update_prices
653
+				);
654
+				// don't forget the base price!
655
+				$new_default = $this->_add_prices_to_ticket(
656
+					array(),
657
+					$new_default,
658
+					$update_prices,
659
+					$base_price,
660
+					$base_price_id
661
+				);
662
+				$new_default->save();
663
+				do_action(
664
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
665
+					$new_default,
666
+					$row,
667
+					$ticket,
668
+					$data
669
+				);
670
+			}
671
+			// DO ALL dtt relationships for both current tickets and any archived tickets
672
+			// for the given dtt that are related to the current ticket.
673
+			// TODO... not sure exactly how we're going to do this considering we don't know
674
+			// what current ticket the archived tickets are related to
675
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
676
+			// let's assign any tickets that have been setup to the saved_tickets tracker
677
+			// save existing TKT
678
+			$ticket->save();
679
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
680
+				// save new TKT
681
+				$new_tkt->save();
682
+				// add new ticket to array
683
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
684
+				do_action(
685
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
686
+					$new_tkt,
687
+					$row,
688
+					$tkt,
689
+					$data
690
+				);
691
+			} else {
692
+				// add tkt to saved tkts
693
+				$saved_tickets[ $ticket->ID() ] = $ticket;
694
+				do_action(
695
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
696
+					$ticket,
697
+					$row,
698
+					$tkt,
699
+					$data
700
+				);
701
+			}
702
+		}
703
+		// now we need to handle tickets actually "deleted permanently".
704
+		// There are cases where we'd want this to happen
705
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
706
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
707
+		// No sense in keeping all the related data in the db!
708
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
709
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
710
+		foreach ($tickets_removed as $id) {
711
+			$id = absint($id);
712
+			// get the ticket for this id
713
+			$tkt_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
714
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
715
+			if ($tkt_to_remove->get('TKT_is_default')) {
716
+				continue;
717
+			}
718
+			// if this tkt has any registrations attached so then we just ARCHIVE
719
+			// because we don't actually permanently delete these tickets.
720
+			if ($tkt_to_remove->count_related('Registration') > 0) {
721
+				$tkt_to_remove->delete();
722
+				continue;
723
+			}
724
+			// need to get all the related datetimes on this ticket and remove from every single one of them
725
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
726
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
727
+			foreach ($datetimes as $datetime) {
728
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
729
+			}
730
+			// need to do the same for prices (except these prices can also be deleted because again,
731
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
732
+			$tkt_to_remove->delete_related('Price');
733
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
734
+			// finally let's delete this ticket
735
+			// (which should not be blocked at this point b/c we've removed all our relationships)
736
+			$tkt_to_remove->delete_or_restore();
737
+		}
738
+		return $saved_tickets;
739
+	}
740 740
 
741 741
 
742
-    /**
743
-     * @access  protected
744
-     * @param EE_Ticket      $ticket
745
-     * @param \EE_Datetime[] $saved_datetimes
746
-     * @param \EE_Datetime[] $added_datetimes
747
-     * @param \EE_Datetime[] $removed_datetimes
748
-     * @return EE_Ticket
749
-     * @throws EE_Error
750
-     */
751
-    protected function _update_ticket_datetimes(
752
-        EE_Ticket $ticket,
753
-        $saved_datetimes = array(),
754
-        $added_datetimes = array(),
755
-        $removed_datetimes = array()
756
-    ) {
757
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
758
-        // and removing the ticket from datetimes it got removed from.
759
-        // first let's add datetimes
760
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
761
-            foreach ($added_datetimes as $row_id) {
762
-                $row_id = (int) $row_id;
763
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
764
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
765
-                    // Is this an existing ticket (has an ID) and does it have any sold?
766
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
767
-                    if ($ticket->ID() && $ticket->sold() > 0) {
768
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
769
-                    }
770
-                }
771
-            }
772
-        }
773
-        // then remove datetimes
774
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
775
-            foreach ($removed_datetimes as $row_id) {
776
-                $row_id = (int) $row_id;
777
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
778
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
779
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
780
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
781
-                    // Is this an existing ticket (has an ID) and does it have any sold?
782
-                    // If so, then we need to remove it's sold from the DTT_sold.
783
-                    if ($ticket->ID() && $ticket->sold() > 0) {
784
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
785
-                    }
786
-                }
787
-            }
788
-        }
789
-        // cap ticket qty by datetime reg limits
790
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
791
-        return $ticket;
792
-    }
742
+	/**
743
+	 * @access  protected
744
+	 * @param EE_Ticket      $ticket
745
+	 * @param \EE_Datetime[] $saved_datetimes
746
+	 * @param \EE_Datetime[] $added_datetimes
747
+	 * @param \EE_Datetime[] $removed_datetimes
748
+	 * @return EE_Ticket
749
+	 * @throws EE_Error
750
+	 */
751
+	protected function _update_ticket_datetimes(
752
+		EE_Ticket $ticket,
753
+		$saved_datetimes = array(),
754
+		$added_datetimes = array(),
755
+		$removed_datetimes = array()
756
+	) {
757
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
758
+		// and removing the ticket from datetimes it got removed from.
759
+		// first let's add datetimes
760
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
761
+			foreach ($added_datetimes as $row_id) {
762
+				$row_id = (int) $row_id;
763
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
764
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
765
+					// Is this an existing ticket (has an ID) and does it have any sold?
766
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
767
+					if ($ticket->ID() && $ticket->sold() > 0) {
768
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
769
+					}
770
+				}
771
+			}
772
+		}
773
+		// then remove datetimes
774
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
775
+			foreach ($removed_datetimes as $row_id) {
776
+				$row_id = (int) $row_id;
777
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
778
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
779
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
780
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
781
+					// Is this an existing ticket (has an ID) and does it have any sold?
782
+					// If so, then we need to remove it's sold from the DTT_sold.
783
+					if ($ticket->ID() && $ticket->sold() > 0) {
784
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
785
+					}
786
+				}
787
+			}
788
+		}
789
+		// cap ticket qty by datetime reg limits
790
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
791
+		return $ticket;
792
+	}
793 793
 
794 794
 
795
-    /**
796
-     * @access  protected
797
-     * @param EE_Ticket $ticket
798
-     * @param array     $price_rows
799
-     * @param int       $ticket_price
800
-     * @param int       $base_price
801
-     * @param int       $base_price_id
802
-     * @return EE_Ticket
803
-     * @throws ReflectionException
804
-     * @throws InvalidArgumentException
805
-     * @throws InvalidInterfaceException
806
-     * @throws InvalidDataTypeException
807
-     * @throws EE_Error
808
-     */
809
-    protected function _duplicate_ticket(
810
-        EE_Ticket $ticket,
811
-        $price_rows = array(),
812
-        $ticket_price = 0,
813
-        $base_price = 0,
814
-        $base_price_id = 0
815
-    ) {
816
-        // create new ticket that's a copy of the existing
817
-        // except a new id of course (and not archived)
818
-        // AND has the new TKT_price associated with it.
819
-        $new_ticket = clone $ticket;
820
-        $new_ticket->set('TKT_ID', 0);
821
-        $new_ticket->set_deleted(0);
822
-        $new_ticket->set_price($ticket_price);
823
-        $new_ticket->set_sold(0);
824
-        // let's get a new ID for this ticket
825
-        $new_ticket->save();
826
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
827
-        $datetimes_on_existing = $ticket->datetimes();
828
-        $new_ticket = $this->_update_ticket_datetimes(
829
-            $new_ticket,
830
-            $datetimes_on_existing,
831
-            array_keys($datetimes_on_existing)
832
-        );
833
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
834
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
835
-        // available.
836
-        if ($ticket->sold() > 0) {
837
-            $new_qty = $ticket->qty() - $ticket->sold();
838
-            $new_ticket->set_qty($new_qty);
839
-        }
840
-        // now we update the prices just for this ticket
841
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
842
-        // and we update the base price
843
-        $new_ticket = $this->_add_prices_to_ticket(
844
-            array(),
845
-            $new_ticket,
846
-            true,
847
-            $base_price,
848
-            $base_price_id
849
-        );
850
-        return $new_ticket;
851
-    }
795
+	/**
796
+	 * @access  protected
797
+	 * @param EE_Ticket $ticket
798
+	 * @param array     $price_rows
799
+	 * @param int       $ticket_price
800
+	 * @param int       $base_price
801
+	 * @param int       $base_price_id
802
+	 * @return EE_Ticket
803
+	 * @throws ReflectionException
804
+	 * @throws InvalidArgumentException
805
+	 * @throws InvalidInterfaceException
806
+	 * @throws InvalidDataTypeException
807
+	 * @throws EE_Error
808
+	 */
809
+	protected function _duplicate_ticket(
810
+		EE_Ticket $ticket,
811
+		$price_rows = array(),
812
+		$ticket_price = 0,
813
+		$base_price = 0,
814
+		$base_price_id = 0
815
+	) {
816
+		// create new ticket that's a copy of the existing
817
+		// except a new id of course (and not archived)
818
+		// AND has the new TKT_price associated with it.
819
+		$new_ticket = clone $ticket;
820
+		$new_ticket->set('TKT_ID', 0);
821
+		$new_ticket->set_deleted(0);
822
+		$new_ticket->set_price($ticket_price);
823
+		$new_ticket->set_sold(0);
824
+		// let's get a new ID for this ticket
825
+		$new_ticket->save();
826
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
827
+		$datetimes_on_existing = $ticket->datetimes();
828
+		$new_ticket = $this->_update_ticket_datetimes(
829
+			$new_ticket,
830
+			$datetimes_on_existing,
831
+			array_keys($datetimes_on_existing)
832
+		);
833
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
834
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
835
+		// available.
836
+		if ($ticket->sold() > 0) {
837
+			$new_qty = $ticket->qty() - $ticket->sold();
838
+			$new_ticket->set_qty($new_qty);
839
+		}
840
+		// now we update the prices just for this ticket
841
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
842
+		// and we update the base price
843
+		$new_ticket = $this->_add_prices_to_ticket(
844
+			array(),
845
+			$new_ticket,
846
+			true,
847
+			$base_price,
848
+			$base_price_id
849
+		);
850
+		return $new_ticket;
851
+	}
852 852
 
853 853
 
854
-    /**
855
-     * This attaches a list of given prices to a ticket.
856
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
857
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
858
-     * price info and prices are automatically "archived" via the ticket.
859
-     *
860
-     * @access  private
861
-     * @param array     $prices        Array of prices from the form.
862
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
863
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
864
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
865
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
866
-     * @return EE_Ticket
867
-     * @throws ReflectionException
868
-     * @throws InvalidArgumentException
869
-     * @throws InvalidInterfaceException
870
-     * @throws InvalidDataTypeException
871
-     * @throws EE_Error
872
-     */
873
-    protected function _add_prices_to_ticket(
874
-        array $prices,
875
-        EE_Ticket $ticket,
876
-        $new_prices = false,
877
-        $base_price = false,
878
-        $base_price_id = false
879
-    ) {
880
-        // let's just get any current prices that may exist on the given ticket
881
-        // so we can remove any prices that got trashed in this session.
882
-        $current_prices_on_ticket = $base_price !== false
883
-            ? $ticket->base_price(true)
884
-            : $ticket->price_modifiers();
885
-        $updated_prices = array();
886
-        // if $base_price ! FALSE then updating a base price.
887
-        if ($base_price !== false) {
888
-            $prices[1] = array(
889
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
890
-                'PRT_ID'     => 1,
891
-                'PRC_amount' => $base_price,
892
-                'PRC_name'   => $ticket->get('TKT_name'),
893
-                'PRC_desc'   => $ticket->get('TKT_description'),
894
-            );
895
-        }
896
-        // possibly need to save tkt
897
-        if (! $ticket->ID()) {
898
-            $ticket->save();
899
-        }
900
-        foreach ($prices as $row => $prc) {
901
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
902
-            if (empty($prt_id)) {
903
-                continue;
904
-            } //prices MUST have a price type id.
905
-            $PRC_values = array(
906
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
907
-                'PRT_ID'         => $prt_id,
908
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
909
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
910
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
911
-                'PRC_is_default' => false,
912
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
913
-                'PRC_order'      => $row,
914
-            );
915
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
916
-                $PRC_values['PRC_ID'] = 0;
917
-                $price = EE_Registry::instance()->load_class(
918
-                    'Price',
919
-                    array($PRC_values),
920
-                    false,
921
-                    false
922
-                );
923
-            } else {
924
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
925
-                // update this price with new values
926
-                foreach ($PRC_values as $field => $value) {
927
-                    $price->set($field, $value);
928
-                }
929
-            }
930
-            $price->save();
931
-            $updated_prices[ $price->ID() ] = $price;
932
-            $ticket->_add_relation_to($price, 'Price');
933
-        }
934
-        // now let's remove any prices that got removed from the ticket
935
-        if (! empty($current_prices_on_ticket)) {
936
-            $current = array_keys($current_prices_on_ticket);
937
-            $updated = array_keys($updated_prices);
938
-            $prices_to_remove = array_diff($current, $updated);
939
-            if (! empty($prices_to_remove)) {
940
-                foreach ($prices_to_remove as $prc_id) {
941
-                    $p = $current_prices_on_ticket[ $prc_id ];
942
-                    $ticket->_remove_relation_to($p, 'Price');
943
-                    // delete permanently the price
944
-                    $p->delete_or_restore();
945
-                }
946
-            }
947
-        }
948
-        return $ticket;
949
-    }
854
+	/**
855
+	 * This attaches a list of given prices to a ticket.
856
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
857
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
858
+	 * price info and prices are automatically "archived" via the ticket.
859
+	 *
860
+	 * @access  private
861
+	 * @param array     $prices        Array of prices from the form.
862
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
863
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
864
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
865
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
866
+	 * @return EE_Ticket
867
+	 * @throws ReflectionException
868
+	 * @throws InvalidArgumentException
869
+	 * @throws InvalidInterfaceException
870
+	 * @throws InvalidDataTypeException
871
+	 * @throws EE_Error
872
+	 */
873
+	protected function _add_prices_to_ticket(
874
+		array $prices,
875
+		EE_Ticket $ticket,
876
+		$new_prices = false,
877
+		$base_price = false,
878
+		$base_price_id = false
879
+	) {
880
+		// let's just get any current prices that may exist on the given ticket
881
+		// so we can remove any prices that got trashed in this session.
882
+		$current_prices_on_ticket = $base_price !== false
883
+			? $ticket->base_price(true)
884
+			: $ticket->price_modifiers();
885
+		$updated_prices = array();
886
+		// if $base_price ! FALSE then updating a base price.
887
+		if ($base_price !== false) {
888
+			$prices[1] = array(
889
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
890
+				'PRT_ID'     => 1,
891
+				'PRC_amount' => $base_price,
892
+				'PRC_name'   => $ticket->get('TKT_name'),
893
+				'PRC_desc'   => $ticket->get('TKT_description'),
894
+			);
895
+		}
896
+		// possibly need to save tkt
897
+		if (! $ticket->ID()) {
898
+			$ticket->save();
899
+		}
900
+		foreach ($prices as $row => $prc) {
901
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
902
+			if (empty($prt_id)) {
903
+				continue;
904
+			} //prices MUST have a price type id.
905
+			$PRC_values = array(
906
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
907
+				'PRT_ID'         => $prt_id,
908
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
909
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
910
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
911
+				'PRC_is_default' => false,
912
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
913
+				'PRC_order'      => $row,
914
+			);
915
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
916
+				$PRC_values['PRC_ID'] = 0;
917
+				$price = EE_Registry::instance()->load_class(
918
+					'Price',
919
+					array($PRC_values),
920
+					false,
921
+					false
922
+				);
923
+			} else {
924
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
925
+				// update this price with new values
926
+				foreach ($PRC_values as $field => $value) {
927
+					$price->set($field, $value);
928
+				}
929
+			}
930
+			$price->save();
931
+			$updated_prices[ $price->ID() ] = $price;
932
+			$ticket->_add_relation_to($price, 'Price');
933
+		}
934
+		// now let's remove any prices that got removed from the ticket
935
+		if (! empty($current_prices_on_ticket)) {
936
+			$current = array_keys($current_prices_on_ticket);
937
+			$updated = array_keys($updated_prices);
938
+			$prices_to_remove = array_diff($current, $updated);
939
+			if (! empty($prices_to_remove)) {
940
+				foreach ($prices_to_remove as $prc_id) {
941
+					$p = $current_prices_on_ticket[ $prc_id ];
942
+					$ticket->_remove_relation_to($p, 'Price');
943
+					// delete permanently the price
944
+					$p->delete_or_restore();
945
+				}
946
+			}
947
+		}
948
+		return $ticket;
949
+	}
950 950
 
951 951
 
952
-    /**
953
-     * @param Events_Admin_Page $event_admin_obj
954
-     * @return Events_Admin_Page
955
-     */
956
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
957
-    {
958
-        return $event_admin_obj;
959
-        // doing nothing for the moment.
960
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
961
-        // (use the set_template_args() method)
962
-        /**
963
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
964
-         * 1. TKT_is_default_selector (visible)
965
-         * 2. TKT_is_default (hidden)
966
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
967
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
968
-         * this ticket to be saved as a default.
969
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
970
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
971
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
972
-         * the TKT HAS been saved as a default..
973
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
974
-         * On Autosave:
975
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
976
-         * then set the TKT_is_default to false.
977
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
978
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
979
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
980
-         */
981
-    }
952
+	/**
953
+	 * @param Events_Admin_Page $event_admin_obj
954
+	 * @return Events_Admin_Page
955
+	 */
956
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
957
+	{
958
+		return $event_admin_obj;
959
+		// doing nothing for the moment.
960
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
961
+		// (use the set_template_args() method)
962
+		/**
963
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
964
+		 * 1. TKT_is_default_selector (visible)
965
+		 * 2. TKT_is_default (hidden)
966
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
967
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
968
+		 * this ticket to be saved as a default.
969
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
970
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
971
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
972
+		 * the TKT HAS been saved as a default..
973
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
974
+		 * On Autosave:
975
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
976
+		 * then set the TKT_is_default to false.
977
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
978
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
979
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
980
+		 */
981
+	}
982 982
 
983 983
 
984
-    /**
985
-     * @throws ReflectionException
986
-     * @throws InvalidArgumentException
987
-     * @throws InvalidInterfaceException
988
-     * @throws InvalidDataTypeException
989
-     * @throws DomainException
990
-     * @throws EE_Error
991
-     */
992
-    public function pricing_metabox()
993
-    {
994
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
995
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
996
-        // set is_creating_event property.
997
-        $EVT_ID = $event->ID();
998
-        $this->_is_creating_event = empty($this->_req_data['post']);
999
-        // default main template args
1000
-        $main_template_args = array(
1001
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1002
-                'event_editor_event_datetimes_help_tab',
1003
-                $this->_adminpage_obj->page_slug,
1004
-                $this->_adminpage_obj->get_req_action(),
1005
-                false,
1006
-                false
1007
-            ),
1008
-            // todo need to add a filter to the template for the help text
1009
-            // in the Events_Admin_Page core file so we can add further help
1010
-            'existing_datetime_ids'    => '',
1011
-            'total_dtt_rows'           => 1,
1012
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1013
-                'add_new_dtt_info',
1014
-                $this->_adminpage_obj->page_slug,
1015
-                $this->_adminpage_obj->get_req_action(),
1016
-                false,
1017
-                false
1018
-            ),
1019
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1020
-            'datetime_rows'            => '',
1021
-            'show_tickets_container'   => '',
1022
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1023
-            'ticket_rows'              => '',
1024
-            'existing_ticket_ids'      => '',
1025
-            'total_ticket_rows'        => 1,
1026
-            'ticket_js_structure'      => '',
1027
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1028
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1029
-        );
1030
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1031
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1032
-        /**
1033
-         * 1. Start with retrieving Datetimes
1034
-         * 2. For each datetime get related tickets
1035
-         * 3. For each ticket get related prices
1036
-         */
1037
-        /** @var EEM_Datetime $datetime_model */
1038
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1039
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1040
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1041
-        /**
1042
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1043
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1044
-         */
1045
-        $datetime_row = 1;
1046
-        foreach ($datetimes as $datetime) {
1047
-            $DTT_ID = $datetime->get('DTT_ID');
1048
-            $datetime->set('DTT_order', $datetime_row);
1049
-            $existing_datetime_ids[] = $DTT_ID;
1050
-            // tickets attached
1051
-            $related_tickets = $datetime->ID() > 0
1052
-                ? $datetime->get_many_related(
1053
-                    'Ticket',
1054
-                    array(
1055
-                        array(
1056
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1057
-                        ),
1058
-                        'default_where_conditions' => 'none',
1059
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1060
-                    )
1061
-                )
1062
-                : array();
1063
-            // if there are no related tickets this is likely a new event OR autodraft
1064
-            // event so we need to generate the default tickets because datetimes
1065
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1066
-            // datetime on the event.
1067
-            if (empty($related_tickets) && count($datetimes) < 2) {
1068
-                /** @var EEM_Ticket $ticket_model */
1069
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1070
-                $related_tickets = $ticket_model->get_all_default_tickets();
1071
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1072
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1073
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1074
-                $main_default_ticket = reset($related_tickets);
1075
-                if ($main_default_ticket instanceof EE_Ticket) {
1076
-                    foreach ($default_prices as $default_price) {
1077
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1078
-                            continue;
1079
-                        }
1080
-                        $main_default_ticket->cache('Price', $default_price);
1081
-                    }
1082
-                }
1083
-            }
1084
-            // we can't actually setup rows in this loop yet cause we don't know all
1085
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1086
-            // So we're going to temporarily cache some of that information.
1087
-            // loop through and setup the ticket rows and make sure the order is set.
1088
-            foreach ($related_tickets as $ticket) {
1089
-                $TKT_ID = $ticket->get('TKT_ID');
1090
-                $ticket_row = $ticket->get('TKT_row');
1091
-                // we only want unique tickets in our final display!!
1092
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1093
-                    $existing_ticket_ids[] = $TKT_ID;
1094
-                    $all_tickets[] = $ticket;
1095
-                }
1096
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1097
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1098
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1099
-                if (
1100
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1101
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1102
-                ) {
1103
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1104
-                }
1105
-            }
1106
-            $datetime_row++;
1107
-        }
1108
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1109
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1110
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1111
-        // sort $all_tickets by order
1112
-        usort(
1113
-            $all_tickets,
1114
-            function (EE_Ticket $a, EE_Ticket $b) {
1115
-                $a_order = (int) $a->get('TKT_order');
1116
-                $b_order = (int) $b->get('TKT_order');
1117
-                if ($a_order === $b_order) {
1118
-                    return 0;
1119
-                }
1120
-                return ($a_order < $b_order) ? -1 : 1;
1121
-            }
1122
-        );
1123
-        // k NOW we have all the data we need for setting up the dtt rows
1124
-        // and ticket rows so we start our dtt loop again.
1125
-        $datetime_row = 1;
1126
-        foreach ($datetimes as $datetime) {
1127
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1128
-                $datetime_row,
1129
-                $datetime,
1130
-                $datetime_tickets,
1131
-                $all_tickets,
1132
-                false,
1133
-                $datetimes
1134
-            );
1135
-            $datetime_row++;
1136
-        }
1137
-        // then loop through all tickets for the ticket rows.
1138
-        $ticket_row = 1;
1139
-        foreach ($all_tickets as $ticket) {
1140
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1141
-                $ticket_row,
1142
-                $ticket,
1143
-                $ticket_datetimes,
1144
-                $datetimes,
1145
-                false,
1146
-                $all_tickets
1147
-            );
1148
-            $ticket_row++;
1149
-        }
1150
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1151
-        EEH_Template::display_template(
1152
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1153
-            $main_template_args
1154
-        );
1155
-    }
984
+	/**
985
+	 * @throws ReflectionException
986
+	 * @throws InvalidArgumentException
987
+	 * @throws InvalidInterfaceException
988
+	 * @throws InvalidDataTypeException
989
+	 * @throws DomainException
990
+	 * @throws EE_Error
991
+	 */
992
+	public function pricing_metabox()
993
+	{
994
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
995
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
996
+		// set is_creating_event property.
997
+		$EVT_ID = $event->ID();
998
+		$this->_is_creating_event = empty($this->_req_data['post']);
999
+		// default main template args
1000
+		$main_template_args = array(
1001
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1002
+				'event_editor_event_datetimes_help_tab',
1003
+				$this->_adminpage_obj->page_slug,
1004
+				$this->_adminpage_obj->get_req_action(),
1005
+				false,
1006
+				false
1007
+			),
1008
+			// todo need to add a filter to the template for the help text
1009
+			// in the Events_Admin_Page core file so we can add further help
1010
+			'existing_datetime_ids'    => '',
1011
+			'total_dtt_rows'           => 1,
1012
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1013
+				'add_new_dtt_info',
1014
+				$this->_adminpage_obj->page_slug,
1015
+				$this->_adminpage_obj->get_req_action(),
1016
+				false,
1017
+				false
1018
+			),
1019
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1020
+			'datetime_rows'            => '',
1021
+			'show_tickets_container'   => '',
1022
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1023
+			'ticket_rows'              => '',
1024
+			'existing_ticket_ids'      => '',
1025
+			'total_ticket_rows'        => 1,
1026
+			'ticket_js_structure'      => '',
1027
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1028
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1029
+		);
1030
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1031
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1032
+		/**
1033
+		 * 1. Start with retrieving Datetimes
1034
+		 * 2. For each datetime get related tickets
1035
+		 * 3. For each ticket get related prices
1036
+		 */
1037
+		/** @var EEM_Datetime $datetime_model */
1038
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1039
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1040
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1041
+		/**
1042
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1043
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1044
+		 */
1045
+		$datetime_row = 1;
1046
+		foreach ($datetimes as $datetime) {
1047
+			$DTT_ID = $datetime->get('DTT_ID');
1048
+			$datetime->set('DTT_order', $datetime_row);
1049
+			$existing_datetime_ids[] = $DTT_ID;
1050
+			// tickets attached
1051
+			$related_tickets = $datetime->ID() > 0
1052
+				? $datetime->get_many_related(
1053
+					'Ticket',
1054
+					array(
1055
+						array(
1056
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1057
+						),
1058
+						'default_where_conditions' => 'none',
1059
+						'order_by'                 => array('TKT_order' => 'ASC'),
1060
+					)
1061
+				)
1062
+				: array();
1063
+			// if there are no related tickets this is likely a new event OR autodraft
1064
+			// event so we need to generate the default tickets because datetimes
1065
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1066
+			// datetime on the event.
1067
+			if (empty($related_tickets) && count($datetimes) < 2) {
1068
+				/** @var EEM_Ticket $ticket_model */
1069
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1070
+				$related_tickets = $ticket_model->get_all_default_tickets();
1071
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1072
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1073
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1074
+				$main_default_ticket = reset($related_tickets);
1075
+				if ($main_default_ticket instanceof EE_Ticket) {
1076
+					foreach ($default_prices as $default_price) {
1077
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1078
+							continue;
1079
+						}
1080
+						$main_default_ticket->cache('Price', $default_price);
1081
+					}
1082
+				}
1083
+			}
1084
+			// we can't actually setup rows in this loop yet cause we don't know all
1085
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1086
+			// So we're going to temporarily cache some of that information.
1087
+			// loop through and setup the ticket rows and make sure the order is set.
1088
+			foreach ($related_tickets as $ticket) {
1089
+				$TKT_ID = $ticket->get('TKT_ID');
1090
+				$ticket_row = $ticket->get('TKT_row');
1091
+				// we only want unique tickets in our final display!!
1092
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1093
+					$existing_ticket_ids[] = $TKT_ID;
1094
+					$all_tickets[] = $ticket;
1095
+				}
1096
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1097
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1098
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1099
+				if (
1100
+					! isset($ticket_datetimes[ $TKT_ID ])
1101
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1102
+				) {
1103
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1104
+				}
1105
+			}
1106
+			$datetime_row++;
1107
+		}
1108
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1109
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1110
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1111
+		// sort $all_tickets by order
1112
+		usort(
1113
+			$all_tickets,
1114
+			function (EE_Ticket $a, EE_Ticket $b) {
1115
+				$a_order = (int) $a->get('TKT_order');
1116
+				$b_order = (int) $b->get('TKT_order');
1117
+				if ($a_order === $b_order) {
1118
+					return 0;
1119
+				}
1120
+				return ($a_order < $b_order) ? -1 : 1;
1121
+			}
1122
+		);
1123
+		// k NOW we have all the data we need for setting up the dtt rows
1124
+		// and ticket rows so we start our dtt loop again.
1125
+		$datetime_row = 1;
1126
+		foreach ($datetimes as $datetime) {
1127
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1128
+				$datetime_row,
1129
+				$datetime,
1130
+				$datetime_tickets,
1131
+				$all_tickets,
1132
+				false,
1133
+				$datetimes
1134
+			);
1135
+			$datetime_row++;
1136
+		}
1137
+		// then loop through all tickets for the ticket rows.
1138
+		$ticket_row = 1;
1139
+		foreach ($all_tickets as $ticket) {
1140
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1141
+				$ticket_row,
1142
+				$ticket,
1143
+				$ticket_datetimes,
1144
+				$datetimes,
1145
+				false,
1146
+				$all_tickets
1147
+			);
1148
+			$ticket_row++;
1149
+		}
1150
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1151
+		EEH_Template::display_template(
1152
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1153
+			$main_template_args
1154
+		);
1155
+	}
1156 1156
 
1157 1157
 
1158
-    /**
1159
-     * @param int         $datetime_row
1160
-     * @param EE_Datetime $datetime
1161
-     * @param array       $datetime_tickets
1162
-     * @param array       $all_tickets
1163
-     * @param bool        $default
1164
-     * @param array       $all_datetimes
1165
-     * @return mixed
1166
-     * @throws DomainException
1167
-     * @throws EE_Error
1168
-     */
1169
-    protected function _get_datetime_row(
1170
-        $datetime_row,
1171
-        EE_Datetime $datetime,
1172
-        $datetime_tickets = array(),
1173
-        $all_tickets = array(),
1174
-        $default = false,
1175
-        $all_datetimes = array()
1176
-    ) {
1177
-        $dtt_display_template_args = array(
1178
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1179
-                $datetime_row,
1180
-                $datetime,
1181
-                $default,
1182
-                $all_datetimes
1183
-            ),
1184
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1185
-                $datetime_row,
1186
-                $datetime,
1187
-                $datetime_tickets,
1188
-                $all_tickets,
1189
-                $default
1190
-            ),
1191
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1192
-        );
1193
-        return EEH_Template::display_template(
1194
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1195
-            $dtt_display_template_args,
1196
-            true
1197
-        );
1198
-    }
1158
+	/**
1159
+	 * @param int         $datetime_row
1160
+	 * @param EE_Datetime $datetime
1161
+	 * @param array       $datetime_tickets
1162
+	 * @param array       $all_tickets
1163
+	 * @param bool        $default
1164
+	 * @param array       $all_datetimes
1165
+	 * @return mixed
1166
+	 * @throws DomainException
1167
+	 * @throws EE_Error
1168
+	 */
1169
+	protected function _get_datetime_row(
1170
+		$datetime_row,
1171
+		EE_Datetime $datetime,
1172
+		$datetime_tickets = array(),
1173
+		$all_tickets = array(),
1174
+		$default = false,
1175
+		$all_datetimes = array()
1176
+	) {
1177
+		$dtt_display_template_args = array(
1178
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1179
+				$datetime_row,
1180
+				$datetime,
1181
+				$default,
1182
+				$all_datetimes
1183
+			),
1184
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1185
+				$datetime_row,
1186
+				$datetime,
1187
+				$datetime_tickets,
1188
+				$all_tickets,
1189
+				$default
1190
+			),
1191
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1192
+		);
1193
+		return EEH_Template::display_template(
1194
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1195
+			$dtt_display_template_args,
1196
+			true
1197
+		);
1198
+	}
1199 1199
 
1200 1200
 
1201
-    /**
1202
-     * This method is used to generate a dtt fields  edit row.
1203
-     * The same row is used to generate a row with valid DTT objects
1204
-     * and the default row that is used as the skeleton by the js.
1205
-     *
1206
-     * @param int           $datetime_row  The row number for the row being generated.
1207
-     * @param EE_Datetime   $datetime
1208
-     * @param bool          $default       Whether a default row is being generated or not.
1209
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1210
-     * @return string
1211
-     * @throws DomainException
1212
-     * @throws EE_Error
1213
-     */
1214
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1215
-    {
1216
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1217
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1218
-        $template_args = array(
1219
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1220
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1221
-            'edit_dtt_expanded'    => '',
1222
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1223
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1224
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1225
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1226
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1227
-            'DTT_reg_limit'        => $default
1228
-                ? ''
1229
-                : $datetime->get_pretty(
1230
-                    'DTT_reg_limit',
1231
-                    'input'
1232
-                ),
1233
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1234
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1235
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1236
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1237
-                ? ''
1238
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1239
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1240
-                ? 'ee-lock-icon'
1241
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1242
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1243
-                ? ''
1244
-                : EE_Admin_Page::add_query_args_and_nonce(
1245
-                    array(
1246
-                        'event_id' => $datetime->event()->ID(),
1247
-                        'datetime_id' => $datetime->ID(),
1248
-                        'use_filters' => true
1249
-                    ),
1250
-                    REG_ADMIN_URL
1251
-                ),
1252
-        );
1253
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1254
-            ? 'display:none'
1255
-            : '';
1256
-        // allow filtering of template args at this point.
1257
-        $template_args = apply_filters(
1258
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1259
-            $template_args,
1260
-            $datetime_row,
1261
-            $datetime,
1262
-            $default,
1263
-            $all_datetimes,
1264
-            $this->_is_creating_event
1265
-        );
1266
-        return EEH_Template::display_template(
1267
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1268
-            $template_args,
1269
-            true
1270
-        );
1271
-    }
1201
+	/**
1202
+	 * This method is used to generate a dtt fields  edit row.
1203
+	 * The same row is used to generate a row with valid DTT objects
1204
+	 * and the default row that is used as the skeleton by the js.
1205
+	 *
1206
+	 * @param int           $datetime_row  The row number for the row being generated.
1207
+	 * @param EE_Datetime   $datetime
1208
+	 * @param bool          $default       Whether a default row is being generated or not.
1209
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1210
+	 * @return string
1211
+	 * @throws DomainException
1212
+	 * @throws EE_Error
1213
+	 */
1214
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1215
+	{
1216
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1217
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1218
+		$template_args = array(
1219
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1220
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1221
+			'edit_dtt_expanded'    => '',
1222
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1223
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1224
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1225
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1226
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1227
+			'DTT_reg_limit'        => $default
1228
+				? ''
1229
+				: $datetime->get_pretty(
1230
+					'DTT_reg_limit',
1231
+					'input'
1232
+				),
1233
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1234
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1235
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1236
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1237
+				? ''
1238
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1239
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1240
+				? 'ee-lock-icon'
1241
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1242
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1243
+				? ''
1244
+				: EE_Admin_Page::add_query_args_and_nonce(
1245
+					array(
1246
+						'event_id' => $datetime->event()->ID(),
1247
+						'datetime_id' => $datetime->ID(),
1248
+						'use_filters' => true
1249
+					),
1250
+					REG_ADMIN_URL
1251
+				),
1252
+		);
1253
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1254
+			? 'display:none'
1255
+			: '';
1256
+		// allow filtering of template args at this point.
1257
+		$template_args = apply_filters(
1258
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1259
+			$template_args,
1260
+			$datetime_row,
1261
+			$datetime,
1262
+			$default,
1263
+			$all_datetimes,
1264
+			$this->_is_creating_event
1265
+		);
1266
+		return EEH_Template::display_template(
1267
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1268
+			$template_args,
1269
+			true
1270
+		);
1271
+	}
1272 1272
 
1273 1273
 
1274
-    /**
1275
-     * @param int         $datetime_row
1276
-     * @param EE_Datetime $datetime
1277
-     * @param array       $datetime_tickets
1278
-     * @param array       $all_tickets
1279
-     * @param bool       $default
1280
-     * @return mixed
1281
-     * @throws DomainException
1282
-     * @throws EE_Error
1283
-     */
1284
-    protected function _get_dtt_attached_tickets_row(
1285
-        $datetime_row,
1286
-        $datetime,
1287
-        $datetime_tickets = array(),
1288
-        $all_tickets = array(),
1289
-        $default = false
1290
-    ) {
1291
-        $template_args = array(
1292
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1293
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1294
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1295
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1296
-            'show_tickets_row'                  => 'display:none;',
1297
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1298
-                'add_new_ticket_via_datetime',
1299
-                $this->_adminpage_obj->page_slug,
1300
-                $this->_adminpage_obj->get_req_action(),
1301
-                false,
1302
-                false
1303
-            ),
1304
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1305
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1306
-        );
1307
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1308
-        if (! $default) {
1309
-            $ticket_row = 1;
1310
-            foreach ($all_tickets as $ticket) {
1311
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1312
-                    $datetime_row,
1313
-                    $ticket_row,
1314
-                    $datetime,
1315
-                    $ticket,
1316
-                    $datetime_tickets,
1317
-                    $default
1318
-                );
1319
-                $ticket_row++;
1320
-            }
1321
-        }
1322
-        // filter template args at this point
1323
-        $template_args = apply_filters(
1324
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1325
-            $template_args,
1326
-            $datetime_row,
1327
-            $datetime,
1328
-            $datetime_tickets,
1329
-            $all_tickets,
1330
-            $default,
1331
-            $this->_is_creating_event
1332
-        );
1333
-        return EEH_Template::display_template(
1334
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1335
-            $template_args,
1336
-            true
1337
-        );
1338
-    }
1274
+	/**
1275
+	 * @param int         $datetime_row
1276
+	 * @param EE_Datetime $datetime
1277
+	 * @param array       $datetime_tickets
1278
+	 * @param array       $all_tickets
1279
+	 * @param bool       $default
1280
+	 * @return mixed
1281
+	 * @throws DomainException
1282
+	 * @throws EE_Error
1283
+	 */
1284
+	protected function _get_dtt_attached_tickets_row(
1285
+		$datetime_row,
1286
+		$datetime,
1287
+		$datetime_tickets = array(),
1288
+		$all_tickets = array(),
1289
+		$default = false
1290
+	) {
1291
+		$template_args = array(
1292
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1293
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1294
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1295
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1296
+			'show_tickets_row'                  => 'display:none;',
1297
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1298
+				'add_new_ticket_via_datetime',
1299
+				$this->_adminpage_obj->page_slug,
1300
+				$this->_adminpage_obj->get_req_action(),
1301
+				false,
1302
+				false
1303
+			),
1304
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1305
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1306
+		);
1307
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1308
+		if (! $default) {
1309
+			$ticket_row = 1;
1310
+			foreach ($all_tickets as $ticket) {
1311
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1312
+					$datetime_row,
1313
+					$ticket_row,
1314
+					$datetime,
1315
+					$ticket,
1316
+					$datetime_tickets,
1317
+					$default
1318
+				);
1319
+				$ticket_row++;
1320
+			}
1321
+		}
1322
+		// filter template args at this point
1323
+		$template_args = apply_filters(
1324
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1325
+			$template_args,
1326
+			$datetime_row,
1327
+			$datetime,
1328
+			$datetime_tickets,
1329
+			$all_tickets,
1330
+			$default,
1331
+			$this->_is_creating_event
1332
+		);
1333
+		return EEH_Template::display_template(
1334
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1335
+			$template_args,
1336
+			true
1337
+		);
1338
+	}
1339 1339
 
1340 1340
 
1341
-    /**
1342
-     * @param int         $datetime_row
1343
-     * @param int         $ticket_row
1344
-     * @param EE_Datetime $datetime
1345
-     * @param EE_Ticket   $ticket
1346
-     * @param array       $datetime_tickets
1347
-     * @param bool        $default
1348
-     * @return mixed
1349
-     * @throws DomainException
1350
-     * @throws EE_Error
1351
-     */
1352
-    protected function _get_datetime_tickets_list_item(
1353
-        $datetime_row,
1354
-        $ticket_row,
1355
-        $datetime,
1356
-        $ticket,
1357
-        $datetime_tickets = array(),
1358
-        $default = false
1359
-    ) {
1360
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1361
-            ? $datetime_tickets[ $datetime->ID() ]
1362
-            : array();
1363
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1364
-        $no_ticket = $default && empty($ticket);
1365
-        $template_args = array(
1366
-            'dtt_row'                 => $default
1367
-                ? 'DTTNUM'
1368
-                : $datetime_row,
1369
-            'tkt_row'                 => $no_ticket
1370
-                ? 'TICKETNUM'
1371
-                : $ticket_row,
1372
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1373
-                ? ' checked'
1374
-                : '',
1375
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1376
-                ? ' ticket-selected'
1377
-                : '',
1378
-            'TKT_name'                => $no_ticket
1379
-                ? 'TKTNAME'
1380
-                : $ticket->get('TKT_name'),
1381
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1382
-                ? ' tkt-status-' . EE_Ticket::onsale
1383
-                : ' tkt-status-' . $ticket->ticket_status(),
1384
-        );
1385
-        // filter template args
1386
-        $template_args = apply_filters(
1387
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1388
-            $template_args,
1389
-            $datetime_row,
1390
-            $ticket_row,
1391
-            $datetime,
1392
-            $ticket,
1393
-            $datetime_tickets,
1394
-            $default,
1395
-            $this->_is_creating_event
1396
-        );
1397
-        return EEH_Template::display_template(
1398
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1399
-            $template_args,
1400
-            true
1401
-        );
1402
-    }
1341
+	/**
1342
+	 * @param int         $datetime_row
1343
+	 * @param int         $ticket_row
1344
+	 * @param EE_Datetime $datetime
1345
+	 * @param EE_Ticket   $ticket
1346
+	 * @param array       $datetime_tickets
1347
+	 * @param bool        $default
1348
+	 * @return mixed
1349
+	 * @throws DomainException
1350
+	 * @throws EE_Error
1351
+	 */
1352
+	protected function _get_datetime_tickets_list_item(
1353
+		$datetime_row,
1354
+		$ticket_row,
1355
+		$datetime,
1356
+		$ticket,
1357
+		$datetime_tickets = array(),
1358
+		$default = false
1359
+	) {
1360
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1361
+			? $datetime_tickets[ $datetime->ID() ]
1362
+			: array();
1363
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1364
+		$no_ticket = $default && empty($ticket);
1365
+		$template_args = array(
1366
+			'dtt_row'                 => $default
1367
+				? 'DTTNUM'
1368
+				: $datetime_row,
1369
+			'tkt_row'                 => $no_ticket
1370
+				? 'TICKETNUM'
1371
+				: $ticket_row,
1372
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1373
+				? ' checked'
1374
+				: '',
1375
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1376
+				? ' ticket-selected'
1377
+				: '',
1378
+			'TKT_name'                => $no_ticket
1379
+				? 'TKTNAME'
1380
+				: $ticket->get('TKT_name'),
1381
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1382
+				? ' tkt-status-' . EE_Ticket::onsale
1383
+				: ' tkt-status-' . $ticket->ticket_status(),
1384
+		);
1385
+		// filter template args
1386
+		$template_args = apply_filters(
1387
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1388
+			$template_args,
1389
+			$datetime_row,
1390
+			$ticket_row,
1391
+			$datetime,
1392
+			$ticket,
1393
+			$datetime_tickets,
1394
+			$default,
1395
+			$this->_is_creating_event
1396
+		);
1397
+		return EEH_Template::display_template(
1398
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1399
+			$template_args,
1400
+			true
1401
+		);
1402
+	}
1403 1403
 
1404 1404
 
1405
-    /**
1406
-     * This generates the ticket row for tickets.
1407
-     * This same method is used to generate both the actual rows and the js skeleton row
1408
-     * (when default === true)
1409
-     *
1410
-     * @param int           $ticket_row       Represents the row number being generated.
1411
-     * @param               $ticket
1412
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1413
-     *                                        or empty for default
1414
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1415
-     * @param bool          $default          Whether default row being generated or not.
1416
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1417
-     *                                        (or empty in the case of defaults)
1418
-     * @return mixed
1419
-     * @throws InvalidArgumentException
1420
-     * @throws InvalidInterfaceException
1421
-     * @throws InvalidDataTypeException
1422
-     * @throws DomainException
1423
-     * @throws EE_Error
1424
-     * @throws ReflectionException
1425
-     */
1426
-    protected function _get_ticket_row(
1427
-        $ticket_row,
1428
-        $ticket,
1429
-        $ticket_datetimes,
1430
-        $all_datetimes,
1431
-        $default = false,
1432
-        $all_tickets = array()
1433
-    ) {
1434
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1435
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1436
-        $prices = ! empty($ticket) && ! $default
1437
-            ? $ticket->get_many_related(
1438
-                'Price',
1439
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1440
-            )
1441
-            : array();
1442
-        // if there is only one price (which would be the base price)
1443
-        // or NO prices and this ticket is a default ticket,
1444
-        // let's just make sure there are no cached default prices on the object.
1445
-        // This is done by not including any query_params.
1446
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1447
-            $prices = $ticket->prices();
1448
-        }
1449
-        // check if we're dealing with a default ticket in which case
1450
-        // we don't want any starting_ticket_datetime_row values set
1451
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1452
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1453
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1454
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1455
-            ? $ticket_datetimes[ $ticket->ID() ]
1456
-            : array();
1457
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1458
-        $base_price = $default ? null : $ticket->base_price();
1459
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1460
-        // breaking out complicated condition for ticket_status
1461
-        if ($default) {
1462
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1463
-        } else {
1464
-            $ticket_status_class = $ticket->is_default()
1465
-                ? ' tkt-status-' . EE_Ticket::onsale
1466
-                : ' tkt-status-' . $ticket->ticket_status();
1467
-        }
1468
-        // breaking out complicated condition for TKT_taxable
1469
-        if ($default) {
1470
-            $TKT_taxable = '';
1471
-        } else {
1472
-            $TKT_taxable = $ticket->taxable()
1473
-                ? 'checked'
1474
-                : '';
1475
-        }
1476
-        if ($default) {
1477
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1478
-        } elseif ($ticket->is_default()) {
1479
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1480
-        } else {
1481
-            $TKT_status = $ticket->ticket_status(true);
1482
-        }
1483
-        if ($default) {
1484
-            $TKT_min = '';
1485
-        } else {
1486
-            $TKT_min = $ticket->min();
1487
-            if ($TKT_min === -1 || $TKT_min === 0) {
1488
-                $TKT_min = '';
1489
-            }
1490
-        }
1491
-        $template_args = array(
1492
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1493
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1494
-            // on initial page load this will always be the correct order.
1495
-            'tkt_status_class'              => $ticket_status_class,
1496
-            'display_edit_tkt_row'          => 'display:none;',
1497
-            'edit_tkt_expanded'             => '',
1498
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1499
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1500
-            'TKT_start_date'                => $default
1501
-                ? ''
1502
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1503
-            'TKT_end_date'                  => $default
1504
-                ? ''
1505
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1506
-            'TKT_status'                    => $TKT_status,
1507
-            'TKT_price'                     => $default
1508
-                ? ''
1509
-                : EEH_Template::format_currency(
1510
-                    $ticket->get_ticket_total_with_taxes(),
1511
-                    false,
1512
-                    false
1513
-                ),
1514
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1515
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1516
-            'TKT_qty'                       => $default
1517
-                ? ''
1518
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1519
-            'TKT_qty_for_input'             => $default
1520
-                ? ''
1521
-                : $ticket->get_pretty('TKT_qty', 'input'),
1522
-            'TKT_uses'                      => $default
1523
-                ? ''
1524
-                : $ticket->get_pretty('TKT_uses', 'input'),
1525
-            'TKT_min'                       => $TKT_min,
1526
-            'TKT_max'                       => $default
1527
-                ? ''
1528
-                : $ticket->get_pretty('TKT_max', 'input'),
1529
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1530
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1531
-            'TKT_registrations'             => $default
1532
-                ? 0
1533
-                : $ticket->count_registrations(
1534
-                    array(
1535
-                        array(
1536
-                            'STS_ID' => array(
1537
-                                '!=',
1538
-                                EEM_Registration::status_id_incomplete,
1539
-                            ),
1540
-                        ),
1541
-                    )
1542
-                ),
1543
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1544
-            'TKT_description'               => $default ? '' : $ticket->get_raw('TKT_description'),
1545
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1546
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1547
-            'TKT_is_default_selector'       => '',
1548
-            'ticket_price_rows'             => '',
1549
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1550
-                ? ''
1551
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1552
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1553
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1554
-                ? ''
1555
-                : 'display:none;',
1556
-            'show_price_mod_button'         => count($prices) > 1
1557
-                                               || ($default && $count_price_mods > 0)
1558
-                                               || (! $default && $ticket->deleted())
1559
-                ? 'display:none;'
1560
-                : '',
1561
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1562
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1563
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1564
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1565
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1566
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1567
-            'TKT_taxable'                   => $TKT_taxable,
1568
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1569
-                ? ''
1570
-                : 'display:none;',
1571
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1572
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1573
-                $ticket_subtotal,
1574
-                false,
1575
-                false
1576
-            ),
1577
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1578
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1579
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1580
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1581
-                ? ' ticket-archived'
1582
-                : '',
1583
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1584
-                                               && $ticket->deleted()
1585
-                                               && ! $ticket->is_permanently_deleteable()
1586
-                ? 'ee-lock-icon '
1587
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1588
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1589
-                ? ''
1590
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1591
-        );
1592
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1593
-            ? 'display:none'
1594
-            : '';
1595
-        // handle rows that should NOT be empty
1596
-        if (empty($template_args['TKT_start_date'])) {
1597
-            // if empty then the start date will be now.
1598
-            $template_args['TKT_start_date'] = date(
1599
-                $this->_date_time_format,
1600
-                current_time('timestamp')
1601
-            );
1602
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1603
-        }
1604
-        if (empty($template_args['TKT_end_date'])) {
1605
-            // get the earliest datetime (if present);
1606
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1607
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1608
-                    'Datetime',
1609
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1610
-                )
1611
-                : null;
1612
-            if (! empty($earliest_dtt)) {
1613
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1614
-                    'DTT_EVT_start',
1615
-                    $this->_date_time_format
1616
-                );
1617
-            } else {
1618
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1619
-                $template_args['TKT_end_date'] = date(
1620
-                    $this->_date_time_format,
1621
-                    mktime(
1622
-                        24,
1623
-                        0,
1624
-                        0,
1625
-                        date('m'),
1626
-                        date('d') + 29,
1627
-                        date('Y')
1628
-                    )
1629
-                );
1630
-            }
1631
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1632
-        }
1633
-        // generate ticket_datetime items
1634
-        if (! $default) {
1635
-            $datetime_row = 1;
1636
-            foreach ($all_datetimes as $datetime) {
1637
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1638
-                    $datetime_row,
1639
-                    $ticket_row,
1640
-                    $datetime,
1641
-                    $ticket,
1642
-                    $ticket_datetimes,
1643
-                    $default
1644
-                );
1645
-                $datetime_row++;
1646
-            }
1647
-        }
1648
-        $price_row = 1;
1649
-        foreach ($prices as $price) {
1650
-            if (! $price instanceof EE_Price) {
1651
-                continue;
1652
-            }
1653
-            if ($price->is_base_price()) {
1654
-                $price_row++;
1655
-                continue;
1656
-            }
1657
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1658
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1659
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1660
-                $ticket_row,
1661
-                $price_row,
1662
-                $price,
1663
-                $default,
1664
-                $ticket,
1665
-                $show_trash,
1666
-                $show_create
1667
-            );
1668
-            $price_row++;
1669
-        }
1670
-        // filter $template_args
1671
-        $template_args = apply_filters(
1672
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1673
-            $template_args,
1674
-            $ticket_row,
1675
-            $ticket,
1676
-            $ticket_datetimes,
1677
-            $all_datetimes,
1678
-            $default,
1679
-            $all_tickets,
1680
-            $this->_is_creating_event
1681
-        );
1682
-        return EEH_Template::display_template(
1683
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1684
-            $template_args,
1685
-            true
1686
-        );
1687
-    }
1405
+	/**
1406
+	 * This generates the ticket row for tickets.
1407
+	 * This same method is used to generate both the actual rows and the js skeleton row
1408
+	 * (when default === true)
1409
+	 *
1410
+	 * @param int           $ticket_row       Represents the row number being generated.
1411
+	 * @param               $ticket
1412
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1413
+	 *                                        or empty for default
1414
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1415
+	 * @param bool          $default          Whether default row being generated or not.
1416
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1417
+	 *                                        (or empty in the case of defaults)
1418
+	 * @return mixed
1419
+	 * @throws InvalidArgumentException
1420
+	 * @throws InvalidInterfaceException
1421
+	 * @throws InvalidDataTypeException
1422
+	 * @throws DomainException
1423
+	 * @throws EE_Error
1424
+	 * @throws ReflectionException
1425
+	 */
1426
+	protected function _get_ticket_row(
1427
+		$ticket_row,
1428
+		$ticket,
1429
+		$ticket_datetimes,
1430
+		$all_datetimes,
1431
+		$default = false,
1432
+		$all_tickets = array()
1433
+	) {
1434
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1435
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1436
+		$prices = ! empty($ticket) && ! $default
1437
+			? $ticket->get_many_related(
1438
+				'Price',
1439
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1440
+			)
1441
+			: array();
1442
+		// if there is only one price (which would be the base price)
1443
+		// or NO prices and this ticket is a default ticket,
1444
+		// let's just make sure there are no cached default prices on the object.
1445
+		// This is done by not including any query_params.
1446
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1447
+			$prices = $ticket->prices();
1448
+		}
1449
+		// check if we're dealing with a default ticket in which case
1450
+		// we don't want any starting_ticket_datetime_row values set
1451
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1452
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1453
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1454
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1455
+			? $ticket_datetimes[ $ticket->ID() ]
1456
+			: array();
1457
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1458
+		$base_price = $default ? null : $ticket->base_price();
1459
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1460
+		// breaking out complicated condition for ticket_status
1461
+		if ($default) {
1462
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1463
+		} else {
1464
+			$ticket_status_class = $ticket->is_default()
1465
+				? ' tkt-status-' . EE_Ticket::onsale
1466
+				: ' tkt-status-' . $ticket->ticket_status();
1467
+		}
1468
+		// breaking out complicated condition for TKT_taxable
1469
+		if ($default) {
1470
+			$TKT_taxable = '';
1471
+		} else {
1472
+			$TKT_taxable = $ticket->taxable()
1473
+				? 'checked'
1474
+				: '';
1475
+		}
1476
+		if ($default) {
1477
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1478
+		} elseif ($ticket->is_default()) {
1479
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1480
+		} else {
1481
+			$TKT_status = $ticket->ticket_status(true);
1482
+		}
1483
+		if ($default) {
1484
+			$TKT_min = '';
1485
+		} else {
1486
+			$TKT_min = $ticket->min();
1487
+			if ($TKT_min === -1 || $TKT_min === 0) {
1488
+				$TKT_min = '';
1489
+			}
1490
+		}
1491
+		$template_args = array(
1492
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1493
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1494
+			// on initial page load this will always be the correct order.
1495
+			'tkt_status_class'              => $ticket_status_class,
1496
+			'display_edit_tkt_row'          => 'display:none;',
1497
+			'edit_tkt_expanded'             => '',
1498
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1499
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1500
+			'TKT_start_date'                => $default
1501
+				? ''
1502
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1503
+			'TKT_end_date'                  => $default
1504
+				? ''
1505
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1506
+			'TKT_status'                    => $TKT_status,
1507
+			'TKT_price'                     => $default
1508
+				? ''
1509
+				: EEH_Template::format_currency(
1510
+					$ticket->get_ticket_total_with_taxes(),
1511
+					false,
1512
+					false
1513
+				),
1514
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1515
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1516
+			'TKT_qty'                       => $default
1517
+				? ''
1518
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1519
+			'TKT_qty_for_input'             => $default
1520
+				? ''
1521
+				: $ticket->get_pretty('TKT_qty', 'input'),
1522
+			'TKT_uses'                      => $default
1523
+				? ''
1524
+				: $ticket->get_pretty('TKT_uses', 'input'),
1525
+			'TKT_min'                       => $TKT_min,
1526
+			'TKT_max'                       => $default
1527
+				? ''
1528
+				: $ticket->get_pretty('TKT_max', 'input'),
1529
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1530
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1531
+			'TKT_registrations'             => $default
1532
+				? 0
1533
+				: $ticket->count_registrations(
1534
+					array(
1535
+						array(
1536
+							'STS_ID' => array(
1537
+								'!=',
1538
+								EEM_Registration::status_id_incomplete,
1539
+							),
1540
+						),
1541
+					)
1542
+				),
1543
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1544
+			'TKT_description'               => $default ? '' : $ticket->get_raw('TKT_description'),
1545
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1546
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1547
+			'TKT_is_default_selector'       => '',
1548
+			'ticket_price_rows'             => '',
1549
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1550
+				? ''
1551
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1552
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1553
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1554
+				? ''
1555
+				: 'display:none;',
1556
+			'show_price_mod_button'         => count($prices) > 1
1557
+											   || ($default && $count_price_mods > 0)
1558
+											   || (! $default && $ticket->deleted())
1559
+				? 'display:none;'
1560
+				: '',
1561
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1562
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1563
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1564
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1565
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1566
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1567
+			'TKT_taxable'                   => $TKT_taxable,
1568
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1569
+				? ''
1570
+				: 'display:none;',
1571
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1572
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1573
+				$ticket_subtotal,
1574
+				false,
1575
+				false
1576
+			),
1577
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1578
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1579
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1580
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1581
+				? ' ticket-archived'
1582
+				: '',
1583
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1584
+											   && $ticket->deleted()
1585
+											   && ! $ticket->is_permanently_deleteable()
1586
+				? 'ee-lock-icon '
1587
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1588
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1589
+				? ''
1590
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1591
+		);
1592
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1593
+			? 'display:none'
1594
+			: '';
1595
+		// handle rows that should NOT be empty
1596
+		if (empty($template_args['TKT_start_date'])) {
1597
+			// if empty then the start date will be now.
1598
+			$template_args['TKT_start_date'] = date(
1599
+				$this->_date_time_format,
1600
+				current_time('timestamp')
1601
+			);
1602
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1603
+		}
1604
+		if (empty($template_args['TKT_end_date'])) {
1605
+			// get the earliest datetime (if present);
1606
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1607
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1608
+					'Datetime',
1609
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1610
+				)
1611
+				: null;
1612
+			if (! empty($earliest_dtt)) {
1613
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1614
+					'DTT_EVT_start',
1615
+					$this->_date_time_format
1616
+				);
1617
+			} else {
1618
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1619
+				$template_args['TKT_end_date'] = date(
1620
+					$this->_date_time_format,
1621
+					mktime(
1622
+						24,
1623
+						0,
1624
+						0,
1625
+						date('m'),
1626
+						date('d') + 29,
1627
+						date('Y')
1628
+					)
1629
+				);
1630
+			}
1631
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1632
+		}
1633
+		// generate ticket_datetime items
1634
+		if (! $default) {
1635
+			$datetime_row = 1;
1636
+			foreach ($all_datetimes as $datetime) {
1637
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1638
+					$datetime_row,
1639
+					$ticket_row,
1640
+					$datetime,
1641
+					$ticket,
1642
+					$ticket_datetimes,
1643
+					$default
1644
+				);
1645
+				$datetime_row++;
1646
+			}
1647
+		}
1648
+		$price_row = 1;
1649
+		foreach ($prices as $price) {
1650
+			if (! $price instanceof EE_Price) {
1651
+				continue;
1652
+			}
1653
+			if ($price->is_base_price()) {
1654
+				$price_row++;
1655
+				continue;
1656
+			}
1657
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1658
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1659
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1660
+				$ticket_row,
1661
+				$price_row,
1662
+				$price,
1663
+				$default,
1664
+				$ticket,
1665
+				$show_trash,
1666
+				$show_create
1667
+			);
1668
+			$price_row++;
1669
+		}
1670
+		// filter $template_args
1671
+		$template_args = apply_filters(
1672
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1673
+			$template_args,
1674
+			$ticket_row,
1675
+			$ticket,
1676
+			$ticket_datetimes,
1677
+			$all_datetimes,
1678
+			$default,
1679
+			$all_tickets,
1680
+			$this->_is_creating_event
1681
+		);
1682
+		return EEH_Template::display_template(
1683
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1684
+			$template_args,
1685
+			true
1686
+		);
1687
+	}
1688 1688
 
1689 1689
 
1690
-    /**
1691
-     * @param int            $ticket_row
1692
-     * @param EE_Ticket|null $ticket
1693
-     * @return string
1694
-     * @throws DomainException
1695
-     * @throws EE_Error
1696
-     */
1697
-    protected function _get_tax_rows($ticket_row, $ticket)
1698
-    {
1699
-        $tax_rows = '';
1700
-        /** @var EE_Price[] $taxes */
1701
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1702
-        foreach ($taxes as $tax) {
1703
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1704
-            $template_args = array(
1705
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1706
-                    ? ''
1707
-                    : 'display:none;',
1708
-                'tax_id'            => $tax->ID(),
1709
-                'tkt_row'           => $ticket_row,
1710
-                'tax_label'         => $tax->get('PRC_name'),
1711
-                'tax_added'         => $tax_added,
1712
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1713
-                'tax_amount'        => $tax->get('PRC_amount'),
1714
-            );
1715
-            $template_args = apply_filters(
1716
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1717
-                $template_args,
1718
-                $ticket_row,
1719
-                $ticket,
1720
-                $this->_is_creating_event
1721
-            );
1722
-            $tax_rows .= EEH_Template::display_template(
1723
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1724
-                $template_args,
1725
-                true
1726
-            );
1727
-        }
1728
-        return $tax_rows;
1729
-    }
1690
+	/**
1691
+	 * @param int            $ticket_row
1692
+	 * @param EE_Ticket|null $ticket
1693
+	 * @return string
1694
+	 * @throws DomainException
1695
+	 * @throws EE_Error
1696
+	 */
1697
+	protected function _get_tax_rows($ticket_row, $ticket)
1698
+	{
1699
+		$tax_rows = '';
1700
+		/** @var EE_Price[] $taxes */
1701
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1702
+		foreach ($taxes as $tax) {
1703
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1704
+			$template_args = array(
1705
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1706
+					? ''
1707
+					: 'display:none;',
1708
+				'tax_id'            => $tax->ID(),
1709
+				'tkt_row'           => $ticket_row,
1710
+				'tax_label'         => $tax->get('PRC_name'),
1711
+				'tax_added'         => $tax_added,
1712
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1713
+				'tax_amount'        => $tax->get('PRC_amount'),
1714
+			);
1715
+			$template_args = apply_filters(
1716
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1717
+				$template_args,
1718
+				$ticket_row,
1719
+				$ticket,
1720
+				$this->_is_creating_event
1721
+			);
1722
+			$tax_rows .= EEH_Template::display_template(
1723
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1724
+				$template_args,
1725
+				true
1726
+			);
1727
+		}
1728
+		return $tax_rows;
1729
+	}
1730 1730
 
1731 1731
 
1732
-    /**
1733
-     * @param EE_Price       $tax
1734
-     * @param EE_Ticket|null $ticket
1735
-     * @return float|int
1736
-     * @throws EE_Error
1737
-     */
1738
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1739
-    {
1740
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1741
-        return $subtotal * $tax->get('PRC_amount') / 100;
1742
-    }
1732
+	/**
1733
+	 * @param EE_Price       $tax
1734
+	 * @param EE_Ticket|null $ticket
1735
+	 * @return float|int
1736
+	 * @throws EE_Error
1737
+	 */
1738
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1739
+	{
1740
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1741
+		return $subtotal * $tax->get('PRC_amount') / 100;
1742
+	}
1743 1743
 
1744 1744
 
1745
-    /**
1746
-     * @param int            $ticket_row
1747
-     * @param int            $price_row
1748
-     * @param EE_Price|null  $price
1749
-     * @param bool           $default
1750
-     * @param EE_Ticket|null $ticket
1751
-     * @param bool           $show_trash
1752
-     * @param bool           $show_create
1753
-     * @return mixed
1754
-     * @throws InvalidArgumentException
1755
-     * @throws InvalidInterfaceException
1756
-     * @throws InvalidDataTypeException
1757
-     * @throws DomainException
1758
-     * @throws EE_Error
1759
-     * @throws ReflectionException
1760
-     */
1761
-    protected function _get_ticket_price_row(
1762
-        $ticket_row,
1763
-        $price_row,
1764
-        $price,
1765
-        $default,
1766
-        $ticket,
1767
-        $show_trash = true,
1768
-        $show_create = true
1769
-    ) {
1770
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1771
-        $template_args = array(
1772
-            'tkt_row'               => $default && empty($ticket)
1773
-                ? 'TICKETNUM'
1774
-                : $ticket_row,
1775
-            'PRC_order'             => $default && empty($price)
1776
-                ? 'PRICENUM'
1777
-                : $price_row,
1778
-            'edit_prices_name'      => $default && empty($price)
1779
-                ? 'PRICENAMEATTR'
1780
-                : 'edit_prices',
1781
-            'price_type_selector'   => $default && empty($price)
1782
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1783
-                : $this->_get_price_type_selector(
1784
-                    $ticket_row,
1785
-                    $price_row,
1786
-                    $price,
1787
-                    $default,
1788
-                    $send_disabled
1789
-                ),
1790
-            'PRC_ID'                => $default && empty($price)
1791
-                ? 0
1792
-                : $price->ID(),
1793
-            'PRC_is_default'        => $default && empty($price)
1794
-                ? 0
1795
-                : $price->get('PRC_is_default'),
1796
-            'PRC_name'              => $default && empty($price)
1797
-                ? ''
1798
-                : $price->get('PRC_name'),
1799
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1800
-            'show_plus_or_minus'    => $default && empty($price)
1801
-                ? ''
1802
-                : 'display:none;',
1803
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1804
-                ? 'display:none;'
1805
-                : '',
1806
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1807
-                ? 'display:none;'
1808
-                : '',
1809
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1810
-                ? 'display:none'
1811
-                : '',
1812
-            'PRC_amount'            => $default && empty($price)
1813
-                ? 0
1814
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1815
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1816
-                ? 'display:none;'
1817
-                : '',
1818
-            'show_trash_icon'       => $show_trash
1819
-                ? ''
1820
-                : ' style="display:none;"',
1821
-            'show_create_button'    => $show_create
1822
-                ? ''
1823
-                : ' style="display:none;"',
1824
-            'PRC_desc'              => $default && empty($price)
1825
-                ? ''
1826
-                : $price->get('PRC_desc'),
1827
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1828
-        );
1829
-        $template_args = apply_filters(
1830
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1831
-            $template_args,
1832
-            $ticket_row,
1833
-            $price_row,
1834
-            $price,
1835
-            $default,
1836
-            $ticket,
1837
-            $show_trash,
1838
-            $show_create,
1839
-            $this->_is_creating_event
1840
-        );
1841
-        return EEH_Template::display_template(
1842
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1843
-            $template_args,
1844
-            true
1845
-        );
1846
-    }
1745
+	/**
1746
+	 * @param int            $ticket_row
1747
+	 * @param int            $price_row
1748
+	 * @param EE_Price|null  $price
1749
+	 * @param bool           $default
1750
+	 * @param EE_Ticket|null $ticket
1751
+	 * @param bool           $show_trash
1752
+	 * @param bool           $show_create
1753
+	 * @return mixed
1754
+	 * @throws InvalidArgumentException
1755
+	 * @throws InvalidInterfaceException
1756
+	 * @throws InvalidDataTypeException
1757
+	 * @throws DomainException
1758
+	 * @throws EE_Error
1759
+	 * @throws ReflectionException
1760
+	 */
1761
+	protected function _get_ticket_price_row(
1762
+		$ticket_row,
1763
+		$price_row,
1764
+		$price,
1765
+		$default,
1766
+		$ticket,
1767
+		$show_trash = true,
1768
+		$show_create = true
1769
+	) {
1770
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1771
+		$template_args = array(
1772
+			'tkt_row'               => $default && empty($ticket)
1773
+				? 'TICKETNUM'
1774
+				: $ticket_row,
1775
+			'PRC_order'             => $default && empty($price)
1776
+				? 'PRICENUM'
1777
+				: $price_row,
1778
+			'edit_prices_name'      => $default && empty($price)
1779
+				? 'PRICENAMEATTR'
1780
+				: 'edit_prices',
1781
+			'price_type_selector'   => $default && empty($price)
1782
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1783
+				: $this->_get_price_type_selector(
1784
+					$ticket_row,
1785
+					$price_row,
1786
+					$price,
1787
+					$default,
1788
+					$send_disabled
1789
+				),
1790
+			'PRC_ID'                => $default && empty($price)
1791
+				? 0
1792
+				: $price->ID(),
1793
+			'PRC_is_default'        => $default && empty($price)
1794
+				? 0
1795
+				: $price->get('PRC_is_default'),
1796
+			'PRC_name'              => $default && empty($price)
1797
+				? ''
1798
+				: $price->get('PRC_name'),
1799
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1800
+			'show_plus_or_minus'    => $default && empty($price)
1801
+				? ''
1802
+				: 'display:none;',
1803
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1804
+				? 'display:none;'
1805
+				: '',
1806
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1807
+				? 'display:none;'
1808
+				: '',
1809
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1810
+				? 'display:none'
1811
+				: '',
1812
+			'PRC_amount'            => $default && empty($price)
1813
+				? 0
1814
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1815
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1816
+				? 'display:none;'
1817
+				: '',
1818
+			'show_trash_icon'       => $show_trash
1819
+				? ''
1820
+				: ' style="display:none;"',
1821
+			'show_create_button'    => $show_create
1822
+				? ''
1823
+				: ' style="display:none;"',
1824
+			'PRC_desc'              => $default && empty($price)
1825
+				? ''
1826
+				: $price->get('PRC_desc'),
1827
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1828
+		);
1829
+		$template_args = apply_filters(
1830
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1831
+			$template_args,
1832
+			$ticket_row,
1833
+			$price_row,
1834
+			$price,
1835
+			$default,
1836
+			$ticket,
1837
+			$show_trash,
1838
+			$show_create,
1839
+			$this->_is_creating_event
1840
+		);
1841
+		return EEH_Template::display_template(
1842
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1843
+			$template_args,
1844
+			true
1845
+		);
1846
+	}
1847 1847
 
1848 1848
 
1849
-    /**
1850
-     * @param int      $ticket_row
1851
-     * @param int      $price_row
1852
-     * @param EE_Price $price
1853
-     * @param bool     $default
1854
-     * @param bool     $disabled
1855
-     * @return mixed
1856
-     * @throws ReflectionException
1857
-     * @throws InvalidArgumentException
1858
-     * @throws InvalidInterfaceException
1859
-     * @throws InvalidDataTypeException
1860
-     * @throws DomainException
1861
-     * @throws EE_Error
1862
-     */
1863
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1864
-    {
1865
-        if ($price->is_base_price()) {
1866
-            return $this->_get_base_price_template(
1867
-                $ticket_row,
1868
-                $price_row,
1869
-                $price,
1870
-                $default
1871
-            );
1872
-        }
1873
-        return $this->_get_price_modifier_template(
1874
-            $ticket_row,
1875
-            $price_row,
1876
-            $price,
1877
-            $default,
1878
-            $disabled
1879
-        );
1880
-    }
1849
+	/**
1850
+	 * @param int      $ticket_row
1851
+	 * @param int      $price_row
1852
+	 * @param EE_Price $price
1853
+	 * @param bool     $default
1854
+	 * @param bool     $disabled
1855
+	 * @return mixed
1856
+	 * @throws ReflectionException
1857
+	 * @throws InvalidArgumentException
1858
+	 * @throws InvalidInterfaceException
1859
+	 * @throws InvalidDataTypeException
1860
+	 * @throws DomainException
1861
+	 * @throws EE_Error
1862
+	 */
1863
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1864
+	{
1865
+		if ($price->is_base_price()) {
1866
+			return $this->_get_base_price_template(
1867
+				$ticket_row,
1868
+				$price_row,
1869
+				$price,
1870
+				$default
1871
+			);
1872
+		}
1873
+		return $this->_get_price_modifier_template(
1874
+			$ticket_row,
1875
+			$price_row,
1876
+			$price,
1877
+			$default,
1878
+			$disabled
1879
+		);
1880
+	}
1881 1881
 
1882 1882
 
1883
-    /**
1884
-     * @param int      $ticket_row
1885
-     * @param int      $price_row
1886
-     * @param EE_Price $price
1887
-     * @param bool     $default
1888
-     * @return mixed
1889
-     * @throws DomainException
1890
-     * @throws EE_Error
1891
-     */
1892
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1893
-    {
1894
-        $template_args = array(
1895
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1896
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1897
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1898
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1899
-            'price_selected_operator'   => '+',
1900
-            'price_selected_is_percent' => 0,
1901
-        );
1902
-        $template_args = apply_filters(
1903
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1904
-            $template_args,
1905
-            $ticket_row,
1906
-            $price_row,
1907
-            $price,
1908
-            $default,
1909
-            $this->_is_creating_event
1910
-        );
1911
-        return EEH_Template::display_template(
1912
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1913
-            $template_args,
1914
-            true
1915
-        );
1916
-    }
1883
+	/**
1884
+	 * @param int      $ticket_row
1885
+	 * @param int      $price_row
1886
+	 * @param EE_Price $price
1887
+	 * @param bool     $default
1888
+	 * @return mixed
1889
+	 * @throws DomainException
1890
+	 * @throws EE_Error
1891
+	 */
1892
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1893
+	{
1894
+		$template_args = array(
1895
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1896
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1897
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1898
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1899
+			'price_selected_operator'   => '+',
1900
+			'price_selected_is_percent' => 0,
1901
+		);
1902
+		$template_args = apply_filters(
1903
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1904
+			$template_args,
1905
+			$ticket_row,
1906
+			$price_row,
1907
+			$price,
1908
+			$default,
1909
+			$this->_is_creating_event
1910
+		);
1911
+		return EEH_Template::display_template(
1912
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1913
+			$template_args,
1914
+			true
1915
+		);
1916
+	}
1917 1917
 
1918 1918
 
1919
-    /**
1920
-     * @param int      $ticket_row
1921
-     * @param int      $price_row
1922
-     * @param EE_Price $price
1923
-     * @param bool     $default
1924
-     * @param bool     $disabled
1925
-     * @return mixed
1926
-     * @throws ReflectionException
1927
-     * @throws InvalidArgumentException
1928
-     * @throws InvalidInterfaceException
1929
-     * @throws InvalidDataTypeException
1930
-     * @throws DomainException
1931
-     * @throws EE_Error
1932
-     */
1933
-    protected function _get_price_modifier_template(
1934
-        $ticket_row,
1935
-        $price_row,
1936
-        $price,
1937
-        $default,
1938
-        $disabled = false
1939
-    ) {
1940
-        $select_name = $default && ! $price instanceof EE_Price
1941
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1942
-            : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1943
-        /** @var EEM_Price_Type $price_type_model */
1944
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1945
-        $price_types = $price_type_model->get_all(array(
1946
-            array(
1947
-                'OR' => array(
1948
-                    'PBT_ID'  => '2',
1949
-                    'PBT_ID*' => '3',
1950
-                ),
1951
-            ),
1952
-        ));
1953
-        $all_price_types = $default && ! $price instanceof EE_Price
1954
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1955
-            : array();
1956
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1957
-        $price_option_spans = '';
1958
-        // setup price types for selector
1959
-        foreach ($price_types as $price_type) {
1960
-            if (! $price_type instanceof EE_Price_Type) {
1961
-                continue;
1962
-            }
1963
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1964
-            // while we're in the loop let's setup the option spans used by js
1965
-            $span_args = array(
1966
-                'PRT_ID'         => $price_type->ID(),
1967
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1968
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1969
-            );
1970
-            $price_option_spans .= EEH_Template::display_template(
1971
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1972
-                $span_args,
1973
-                true
1974
-            );
1975
-        }
1976
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1977
-            : $select_name;
1978
-        $select_input = new EE_Select_Input(
1979
-            $all_price_types,
1980
-            array(
1981
-                'default'               => $selected_price_type_id,
1982
-                'html_name'             => $select_name,
1983
-                'html_class'            => 'edit-price-PRT_ID',
1984
-                'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1985
-            )
1986
-        );
1987
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1988
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1989
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1990
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1991
-        $template_args = array(
1992
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1993
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1994
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1995
-            'main_name'                 => $select_name,
1996
-            'selected_price_type_id'    => $selected_price_type_id,
1997
-            'price_option_spans'        => $price_option_spans,
1998
-            'price_selected_operator'   => $price_selected_operator,
1999
-            'price_selected_is_percent' => $price_selected_is_percent,
2000
-            'disabled'                  => $disabled,
2001
-        );
2002
-        $template_args = apply_filters(
2003
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
2004
-            $template_args,
2005
-            $ticket_row,
2006
-            $price_row,
2007
-            $price,
2008
-            $default,
2009
-            $disabled,
2010
-            $this->_is_creating_event
2011
-        );
2012
-        return EEH_Template::display_template(
2013
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2014
-            $template_args,
2015
-            true
2016
-        );
2017
-    }
1919
+	/**
1920
+	 * @param int      $ticket_row
1921
+	 * @param int      $price_row
1922
+	 * @param EE_Price $price
1923
+	 * @param bool     $default
1924
+	 * @param bool     $disabled
1925
+	 * @return mixed
1926
+	 * @throws ReflectionException
1927
+	 * @throws InvalidArgumentException
1928
+	 * @throws InvalidInterfaceException
1929
+	 * @throws InvalidDataTypeException
1930
+	 * @throws DomainException
1931
+	 * @throws EE_Error
1932
+	 */
1933
+	protected function _get_price_modifier_template(
1934
+		$ticket_row,
1935
+		$price_row,
1936
+		$price,
1937
+		$default,
1938
+		$disabled = false
1939
+	) {
1940
+		$select_name = $default && ! $price instanceof EE_Price
1941
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1942
+			: 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1943
+		/** @var EEM_Price_Type $price_type_model */
1944
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1945
+		$price_types = $price_type_model->get_all(array(
1946
+			array(
1947
+				'OR' => array(
1948
+					'PBT_ID'  => '2',
1949
+					'PBT_ID*' => '3',
1950
+				),
1951
+			),
1952
+		));
1953
+		$all_price_types = $default && ! $price instanceof EE_Price
1954
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1955
+			: array();
1956
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1957
+		$price_option_spans = '';
1958
+		// setup price types for selector
1959
+		foreach ($price_types as $price_type) {
1960
+			if (! $price_type instanceof EE_Price_Type) {
1961
+				continue;
1962
+			}
1963
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1964
+			// while we're in the loop let's setup the option spans used by js
1965
+			$span_args = array(
1966
+				'PRT_ID'         => $price_type->ID(),
1967
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1968
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1969
+			);
1970
+			$price_option_spans .= EEH_Template::display_template(
1971
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1972
+				$span_args,
1973
+				true
1974
+			);
1975
+		}
1976
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1977
+			: $select_name;
1978
+		$select_input = new EE_Select_Input(
1979
+			$all_price_types,
1980
+			array(
1981
+				'default'               => $selected_price_type_id,
1982
+				'html_name'             => $select_name,
1983
+				'html_class'            => 'edit-price-PRT_ID',
1984
+				'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1985
+			)
1986
+		);
1987
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1988
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1989
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1990
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1991
+		$template_args = array(
1992
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1993
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1994
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1995
+			'main_name'                 => $select_name,
1996
+			'selected_price_type_id'    => $selected_price_type_id,
1997
+			'price_option_spans'        => $price_option_spans,
1998
+			'price_selected_operator'   => $price_selected_operator,
1999
+			'price_selected_is_percent' => $price_selected_is_percent,
2000
+			'disabled'                  => $disabled,
2001
+		);
2002
+		$template_args = apply_filters(
2003
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
2004
+			$template_args,
2005
+			$ticket_row,
2006
+			$price_row,
2007
+			$price,
2008
+			$default,
2009
+			$disabled,
2010
+			$this->_is_creating_event
2011
+		);
2012
+		return EEH_Template::display_template(
2013
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2014
+			$template_args,
2015
+			true
2016
+		);
2017
+	}
2018 2018
 
2019 2019
 
2020
-    /**
2021
-     * @param int              $datetime_row
2022
-     * @param int              $ticket_row
2023
-     * @param EE_Datetime|null $datetime
2024
-     * @param EE_Ticket|null   $ticket
2025
-     * @param array            $ticket_datetimes
2026
-     * @param bool             $default
2027
-     * @return mixed
2028
-     * @throws DomainException
2029
-     * @throws EE_Error
2030
-     */
2031
-    protected function _get_ticket_datetime_list_item(
2032
-        $datetime_row,
2033
-        $ticket_row,
2034
-        $datetime,
2035
-        $ticket,
2036
-        $ticket_datetimes = array(),
2037
-        $default = false
2038
-    ) {
2039
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2040
-            ? $ticket_datetimes[ $ticket->ID() ]
2041
-            : array();
2042
-        $template_args = array(
2043
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2044
-                ? 'DTTNUM'
2045
-                : $datetime_row,
2046
-            'tkt_row'                  => $default
2047
-                ? 'TICKETNUM'
2048
-                : $ticket_row,
2049
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2050
-                ? ' ticket-selected'
2051
-                : '',
2052
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2053
-                ? ' checked'
2054
-                : '',
2055
-            'DTT_name'                 => $default && empty($datetime)
2056
-                ? 'DTTNAME'
2057
-                : $datetime->get_dtt_display_name(true),
2058
-            'tkt_status_class'         => '',
2059
-        );
2060
-        $template_args = apply_filters(
2061
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2062
-            $template_args,
2063
-            $datetime_row,
2064
-            $ticket_row,
2065
-            $datetime,
2066
-            $ticket,
2067
-            $ticket_datetimes,
2068
-            $default,
2069
-            $this->_is_creating_event
2070
-        );
2071
-        return EEH_Template::display_template(
2072
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2073
-            $template_args,
2074
-            true
2075
-        );
2076
-    }
2020
+	/**
2021
+	 * @param int              $datetime_row
2022
+	 * @param int              $ticket_row
2023
+	 * @param EE_Datetime|null $datetime
2024
+	 * @param EE_Ticket|null   $ticket
2025
+	 * @param array            $ticket_datetimes
2026
+	 * @param bool             $default
2027
+	 * @return mixed
2028
+	 * @throws DomainException
2029
+	 * @throws EE_Error
2030
+	 */
2031
+	protected function _get_ticket_datetime_list_item(
2032
+		$datetime_row,
2033
+		$ticket_row,
2034
+		$datetime,
2035
+		$ticket,
2036
+		$ticket_datetimes = array(),
2037
+		$default = false
2038
+	) {
2039
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2040
+			? $ticket_datetimes[ $ticket->ID() ]
2041
+			: array();
2042
+		$template_args = array(
2043
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2044
+				? 'DTTNUM'
2045
+				: $datetime_row,
2046
+			'tkt_row'                  => $default
2047
+				? 'TICKETNUM'
2048
+				: $ticket_row,
2049
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2050
+				? ' ticket-selected'
2051
+				: '',
2052
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2053
+				? ' checked'
2054
+				: '',
2055
+			'DTT_name'                 => $default && empty($datetime)
2056
+				? 'DTTNAME'
2057
+				: $datetime->get_dtt_display_name(true),
2058
+			'tkt_status_class'         => '',
2059
+		);
2060
+		$template_args = apply_filters(
2061
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2062
+			$template_args,
2063
+			$datetime_row,
2064
+			$ticket_row,
2065
+			$datetime,
2066
+			$ticket,
2067
+			$ticket_datetimes,
2068
+			$default,
2069
+			$this->_is_creating_event
2070
+		);
2071
+		return EEH_Template::display_template(
2072
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2073
+			$template_args,
2074
+			true
2075
+		);
2076
+	}
2077 2077
 
2078 2078
 
2079
-    /**
2080
-     * @param array $all_datetimes
2081
-     * @param array $all_tickets
2082
-     * @return mixed
2083
-     * @throws ReflectionException
2084
-     * @throws InvalidArgumentException
2085
-     * @throws InvalidInterfaceException
2086
-     * @throws InvalidDataTypeException
2087
-     * @throws DomainException
2088
-     * @throws EE_Error
2089
-     */
2090
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2091
-    {
2092
-        $template_args = array(
2093
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2094
-                'DTTNUM',
2095
-                null,
2096
-                true,
2097
-                $all_datetimes
2098
-            ),
2099
-            'default_ticket_row'                       => $this->_get_ticket_row(
2100
-                'TICKETNUM',
2101
-                null,
2102
-                array(),
2103
-                array(),
2104
-                true
2105
-            ),
2106
-            'default_price_row'                        => $this->_get_ticket_price_row(
2107
-                'TICKETNUM',
2108
-                'PRICENUM',
2109
-                null,
2110
-                true,
2111
-                null
2112
-            ),
2113
-            'default_price_rows'                       => '',
2114
-            'default_base_price_amount'                => 0,
2115
-            'default_base_price_name'                  => '',
2116
-            'default_base_price_description'           => '',
2117
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2118
-                'TICKETNUM',
2119
-                'PRICENUM',
2120
-                null,
2121
-                true
2122
-            ),
2123
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2124
-                'DTTNUM',
2125
-                null,
2126
-                array(),
2127
-                array(),
2128
-                true
2129
-            ),
2130
-            'existing_available_datetime_tickets_list' => '',
2131
-            'existing_available_ticket_datetimes_list' => '',
2132
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2133
-                'DTTNUM',
2134
-                'TICKETNUM',
2135
-                null,
2136
-                null,
2137
-                array(),
2138
-                true
2139
-            ),
2140
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2141
-                'DTTNUM',
2142
-                'TICKETNUM',
2143
-                null,
2144
-                null,
2145
-                array(),
2146
-                true
2147
-            ),
2148
-        );
2149
-        $ticket_row = 1;
2150
-        foreach ($all_tickets as $ticket) {
2151
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2152
-                'DTTNUM',
2153
-                $ticket_row,
2154
-                null,
2155
-                $ticket,
2156
-                array(),
2157
-                true
2158
-            );
2159
-            $ticket_row++;
2160
-        }
2161
-        $datetime_row = 1;
2162
-        foreach ($all_datetimes as $datetime) {
2163
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2164
-                $datetime_row,
2165
-                'TICKETNUM',
2166
-                $datetime,
2167
-                null,
2168
-                array(),
2169
-                true
2170
-            );
2171
-            $datetime_row++;
2172
-        }
2173
-        /** @var EEM_Price $price_model */
2174
-        $price_model = EE_Registry::instance()->load_model('Price');
2175
-        $default_prices = $price_model->get_all_default_prices();
2176
-        $price_row = 1;
2177
-        foreach ($default_prices as $price) {
2178
-            if (! $price instanceof EE_Price) {
2179
-                continue;
2180
-            }
2181
-            if ($price->is_base_price()) {
2182
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2183
-                    'PRC_amount',
2184
-                    'localized_float'
2185
-                );
2186
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2187
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2188
-                $price_row++;
2189
-                continue;
2190
-            }
2191
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2192
-                             || count($default_prices) === 1);
2193
-            $show_create = ! (count($default_prices) > 1
2194
-                              && count($default_prices)
2195
-                                 !== $price_row);
2196
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2197
-                'TICKETNUM',
2198
-                $price_row,
2199
-                $price,
2200
-                true,
2201
-                null,
2202
-                $show_trash,
2203
-                $show_create
2204
-            );
2205
-            $price_row++;
2206
-        }
2207
-        $template_args = apply_filters(
2208
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2209
-            $template_args,
2210
-            $all_datetimes,
2211
-            $all_tickets,
2212
-            $this->_is_creating_event
2213
-        );
2214
-        return EEH_Template::display_template(
2215
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2216
-            $template_args,
2217
-            true
2218
-        );
2219
-    }
2079
+	/**
2080
+	 * @param array $all_datetimes
2081
+	 * @param array $all_tickets
2082
+	 * @return mixed
2083
+	 * @throws ReflectionException
2084
+	 * @throws InvalidArgumentException
2085
+	 * @throws InvalidInterfaceException
2086
+	 * @throws InvalidDataTypeException
2087
+	 * @throws DomainException
2088
+	 * @throws EE_Error
2089
+	 */
2090
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2091
+	{
2092
+		$template_args = array(
2093
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2094
+				'DTTNUM',
2095
+				null,
2096
+				true,
2097
+				$all_datetimes
2098
+			),
2099
+			'default_ticket_row'                       => $this->_get_ticket_row(
2100
+				'TICKETNUM',
2101
+				null,
2102
+				array(),
2103
+				array(),
2104
+				true
2105
+			),
2106
+			'default_price_row'                        => $this->_get_ticket_price_row(
2107
+				'TICKETNUM',
2108
+				'PRICENUM',
2109
+				null,
2110
+				true,
2111
+				null
2112
+			),
2113
+			'default_price_rows'                       => '',
2114
+			'default_base_price_amount'                => 0,
2115
+			'default_base_price_name'                  => '',
2116
+			'default_base_price_description'           => '',
2117
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2118
+				'TICKETNUM',
2119
+				'PRICENUM',
2120
+				null,
2121
+				true
2122
+			),
2123
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2124
+				'DTTNUM',
2125
+				null,
2126
+				array(),
2127
+				array(),
2128
+				true
2129
+			),
2130
+			'existing_available_datetime_tickets_list' => '',
2131
+			'existing_available_ticket_datetimes_list' => '',
2132
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2133
+				'DTTNUM',
2134
+				'TICKETNUM',
2135
+				null,
2136
+				null,
2137
+				array(),
2138
+				true
2139
+			),
2140
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2141
+				'DTTNUM',
2142
+				'TICKETNUM',
2143
+				null,
2144
+				null,
2145
+				array(),
2146
+				true
2147
+			),
2148
+		);
2149
+		$ticket_row = 1;
2150
+		foreach ($all_tickets as $ticket) {
2151
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2152
+				'DTTNUM',
2153
+				$ticket_row,
2154
+				null,
2155
+				$ticket,
2156
+				array(),
2157
+				true
2158
+			);
2159
+			$ticket_row++;
2160
+		}
2161
+		$datetime_row = 1;
2162
+		foreach ($all_datetimes as $datetime) {
2163
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2164
+				$datetime_row,
2165
+				'TICKETNUM',
2166
+				$datetime,
2167
+				null,
2168
+				array(),
2169
+				true
2170
+			);
2171
+			$datetime_row++;
2172
+		}
2173
+		/** @var EEM_Price $price_model */
2174
+		$price_model = EE_Registry::instance()->load_model('Price');
2175
+		$default_prices = $price_model->get_all_default_prices();
2176
+		$price_row = 1;
2177
+		foreach ($default_prices as $price) {
2178
+			if (! $price instanceof EE_Price) {
2179
+				continue;
2180
+			}
2181
+			if ($price->is_base_price()) {
2182
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2183
+					'PRC_amount',
2184
+					'localized_float'
2185
+				);
2186
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2187
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2188
+				$price_row++;
2189
+				continue;
2190
+			}
2191
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2192
+							 || count($default_prices) === 1);
2193
+			$show_create = ! (count($default_prices) > 1
2194
+							  && count($default_prices)
2195
+								 !== $price_row);
2196
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2197
+				'TICKETNUM',
2198
+				$price_row,
2199
+				$price,
2200
+				true,
2201
+				null,
2202
+				$show_trash,
2203
+				$show_create
2204
+			);
2205
+			$price_row++;
2206
+		}
2207
+		$template_args = apply_filters(
2208
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2209
+			$template_args,
2210
+			$all_datetimes,
2211
+			$all_tickets,
2212
+			$this->_is_creating_event
2213
+		);
2214
+		return EEH_Template::display_template(
2215
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2216
+			$template_args,
2217
+			true
2218
+		);
2219
+	}
2220 2220
 }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
             );
150 150
             $msg .= '</p><ul>';
151 151
             foreach ($format_validation as $error) {
152
-                $msg .= '<li>' . $error . '</li>';
152
+                $msg .= '<li>'.$error.'</li>';
153 153
             }
154 154
             $msg .= '</ul><p>';
155 155
             $msg .= sprintf(
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
         $this->_scripts_styles = array(
179 179
             'registers'   => array(
180 180
                 'ee-tickets-datetimes-css' => array(
181
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
181
+                    'url'  => PRICING_ASSETS_URL.'event-tickets-datetimes.css',
182 182
                     'type' => 'css',
183 183
                 ),
184 184
                 'ee-dtt-ticket-metabox'    => array(
185
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
185
+                    'url'     => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js',
186 186
                     'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
187 187
                 ),
188 188
             ),
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
                             'event_espresso'
207 207
                         ),
208 208
                         'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
209
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
209
+                                                     . esc_html__('Cancel', 'event_espresso').'</button>',
210 210
                         'close_button'            => '<button class="button-secondary ee-modal-cancel">'
211
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
211
+                                                     . esc_html__('Close', 'event_espresso').'</button>',
212 212
                         'single_warning_from_tkt' => esc_html__(
213 213
                             '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.',
214 214
                             'event_espresso'
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
                             'event_espresso'
219 219
                         ),
220 220
                         'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
221
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
221
+                                                     . esc_html__('Dismiss', 'event_espresso').'</button>',
222 222
                     ),
223 223
                     'DTT_ERROR_MSG'         => array(
224 224
                         'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     {
257 257
         foreach ($update_callbacks as $key => $callback) {
258 258
             if ($callback[1] === '_default_tickets_update') {
259
-                unset($update_callbacks[ $key ]);
259
+                unset($update_callbacks[$key]);
260 260
             }
261 261
         }
262 262
         $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
@@ -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
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
             );
345 345
             // if we have an id then let's get existing object first and then set the new values.
346 346
             // Otherwise we instantiate a new object for save.
347
-            if (! empty($datetime_data['DTT_ID'])) {
347
+            if ( ! empty($datetime_data['DTT_ID'])) {
348 348
                 $datetime = EE_Registry::instance()
349 349
                                        ->load_model('Datetime', array($timezone))
350 350
                                        ->get_one_by_ID($datetime_data['DTT_ID']);
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
                 // after the add_relation_to() the autosave replaces it.
359 359
                 // We need to do this so we dont' TRASH the parent DTT.
360 360
                 // (save the ID for both key and value to avoid duplications)
361
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
361
+                $saved_dtt_ids[$datetime->ID()] = $datetime->ID();
362 362
             } else {
363 363
                 $datetime = EE_Registry::instance()->load_class(
364 364
                     'Datetime',
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
             // because it is possible there was a new one created for the autosave.
395 395
             // (save the ID for both key and value to avoid duplications)
396 396
             $DTT_ID = $datetime->ID();
397
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
398
-            $saved_dtt_objs[ $row ] = $datetime;
397
+            $saved_dtt_ids[$DTT_ID] = $DTT_ID;
398
+            $saved_dtt_objs[$row] = $datetime;
399 399
             // @todo if ANY of these updates fail then we want the appropriate global error message.
400 400
         }
401 401
         $event->save();
@@ -461,13 +461,13 @@  discard block
 block discarded – undo
461 461
             $update_prices = $create_new_TKT = false;
462 462
             // figure out what datetimes were added to the ticket
463 463
             // and what datetimes were removed from the ticket in the session.
464
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
465
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
464
+            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
465
+            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]);
466 466
             $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
467 467
             $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
468 468
             // trim inputs to ensure any excess whitespace is removed.
469 469
             $tkt = array_map(
470
-                function ($ticket_data) {
470
+                function($ticket_data) {
471 471
                     return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
472 472
                 },
473 473
                 $tkt
@@ -487,8 +487,8 @@  discard block
 block discarded – undo
487 487
                 ? $base_price
488 488
                 : $ticket_price;
489 489
             $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
490
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
491
-                ? $data['edit_prices'][ $row ]
490
+            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row])
491
+                ? $data['edit_prices'][$row]
492 492
                 : array();
493 493
             $now = null;
494 494
             if (empty($tkt['TKT_start_date'])) {
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
                 /**
501 501
                  * set the TKT_end_date to the first datetime attached to the ticket.
502 502
                  */
503
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
503
+                $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)];
504 504
                 $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
505 505
             }
506 506
             $TKT_values = array(
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
             // need to make sue that the TKT_price is accurate after saving the prices.
636 636
             $ticket->ensure_TKT_Price_correct();
637 637
             // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
638
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
638
+            if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
639 639
                 $update_prices = true;
640 640
                 $new_default = clone $ticket;
641 641
                 $new_default->set('TKT_ID', 0);
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
                 // save new TKT
681 681
                 $new_tkt->save();
682 682
                 // add new ticket to array
683
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
683
+                $saved_tickets[$new_tkt->ID()] = $new_tkt;
684 684
                 do_action(
685 685
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
686 686
                     $new_tkt,
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
                 );
691 691
             } else {
692 692
                 // add tkt to saved tkts
693
-                $saved_tickets[ $ticket->ID() ] = $ticket;
693
+                $saved_tickets[$ticket->ID()] = $ticket;
694 694
                 do_action(
695 695
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
696 696
                     $ticket,
@@ -757,31 +757,31 @@  discard block
 block discarded – undo
757 757
         // to start we have to add the ticket to all the datetimes its supposed to be with,
758 758
         // and removing the ticket from datetimes it got removed from.
759 759
         // first let's add datetimes
760
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
760
+        if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
761 761
             foreach ($added_datetimes as $row_id) {
762 762
                 $row_id = (int) $row_id;
763
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
764
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
763
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
764
+                    $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
765 765
                     // Is this an existing ticket (has an ID) and does it have any sold?
766 766
                     // If so, then we need to add that to the DTT sold because this DTT is getting added.
767 767
                     if ($ticket->ID() && $ticket->sold() > 0) {
768
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
768
+                        $saved_datetimes[$row_id]->increaseSold($ticket->sold(), false);
769 769
                     }
770 770
                 }
771 771
             }
772 772
         }
773 773
         // then remove datetimes
774
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
774
+        if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
775 775
             foreach ($removed_datetimes as $row_id) {
776 776
                 $row_id = (int) $row_id;
777 777
                 // its entirely possible that a datetime got deleted (instead of just removed from relationship.
778 778
                 // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
779
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
780
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
779
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
780
+                    $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
781 781
                     // Is this an existing ticket (has an ID) and does it have any sold?
782 782
                     // If so, then we need to remove it's sold from the DTT_sold.
783 783
                     if ($ticket->ID() && $ticket->sold() > 0) {
784
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
784
+                        $saved_datetimes[$row_id]->decreaseSold($ticket->sold());
785 785
                     }
786 786
                 }
787 787
             }
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
             );
895 895
         }
896 896
         // possibly need to save tkt
897
-        if (! $ticket->ID()) {
897
+        if ( ! $ticket->ID()) {
898 898
             $ticket->save();
899 899
         }
900 900
         foreach ($prices as $row => $prc) {
@@ -928,17 +928,17 @@  discard block
 block discarded – undo
928 928
                 }
929 929
             }
930 930
             $price->save();
931
-            $updated_prices[ $price->ID() ] = $price;
931
+            $updated_prices[$price->ID()] = $price;
932 932
             $ticket->_add_relation_to($price, 'Price');
933 933
         }
934 934
         // now let's remove any prices that got removed from the ticket
935
-        if (! empty($current_prices_on_ticket)) {
935
+        if ( ! empty($current_prices_on_ticket)) {
936 936
             $current = array_keys($current_prices_on_ticket);
937 937
             $updated = array_keys($updated_prices);
938 938
             $prices_to_remove = array_diff($current, $updated);
939
-            if (! empty($prices_to_remove)) {
939
+            if ( ! empty($prices_to_remove)) {
940 940
                 foreach ($prices_to_remove as $prc_id) {
941
-                    $p = $current_prices_on_ticket[ $prc_id ];
941
+                    $p = $current_prices_on_ticket[$prc_id];
942 942
                     $ticket->_remove_relation_to($p, 'Price');
943 943
                     // delete permanently the price
944 944
                     $p->delete_or_restore();
@@ -1089,18 +1089,18 @@  discard block
 block discarded – undo
1089 1089
                 $TKT_ID = $ticket->get('TKT_ID');
1090 1090
                 $ticket_row = $ticket->get('TKT_row');
1091 1091
                 // we only want unique tickets in our final display!!
1092
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1092
+                if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) {
1093 1093
                     $existing_ticket_ids[] = $TKT_ID;
1094 1094
                     $all_tickets[] = $ticket;
1095 1095
                 }
1096 1096
                 // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1097
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1097
+                $datetime_tickets[$DTT_ID][] = $ticket_row;
1098 1098
                 // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1099 1099
                 if (
1100
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1101
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1100
+                    ! isset($ticket_datetimes[$TKT_ID])
1101
+                    || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true)
1102 1102
                 ) {
1103
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1103
+                    $ticket_datetimes[$TKT_ID][] = $datetime_row;
1104 1104
                 }
1105 1105
             }
1106 1106
             $datetime_row++;
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
         // sort $all_tickets by order
1112 1112
         usort(
1113 1113
             $all_tickets,
1114
-            function (EE_Ticket $a, EE_Ticket $b) {
1114
+            function(EE_Ticket $a, EE_Ticket $b) {
1115 1115
                 $a_order = (int) $a->get('TKT_order');
1116 1116
                 $b_order = (int) $b->get('TKT_order');
1117 1117
                 if ($a_order === $b_order) {
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
         }
1150 1150
         $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1151 1151
         EEH_Template::display_template(
1152
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1152
+            PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php',
1153 1153
             $main_template_args
1154 1154
         );
1155 1155
     }
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
             'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1192 1192
         );
1193 1193
         return EEH_Template::display_template(
1194
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1194
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php',
1195 1195
             $dtt_display_template_args,
1196 1196
             true
1197 1197
         );
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
             $this->_is_creating_event
1265 1265
         );
1266 1266
         return EEH_Template::display_template(
1267
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1267
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php',
1268 1268
             $template_args,
1269 1269
             true
1270 1270
         );
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
1305 1305
             'DTT_ID'                            => $default ? '' : $datetime->ID(),
1306 1306
         );
1307 1307
         // need to setup the list items (but only if this isn't a default skeleton setup)
1308
-        if (! $default) {
1308
+        if ( ! $default) {
1309 1309
             $ticket_row = 1;
1310 1310
             foreach ($all_tickets as $ticket) {
1311 1311
                 $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
             $this->_is_creating_event
1332 1332
         );
1333 1333
         return EEH_Template::display_template(
1334
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1334
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php',
1335 1335
             $template_args,
1336 1336
             true
1337 1337
         );
@@ -1357,8 +1357,8 @@  discard block
 block discarded – undo
1357 1357
         $datetime_tickets = array(),
1358 1358
         $default = false
1359 1359
     ) {
1360
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1361
-            ? $datetime_tickets[ $datetime->ID() ]
1360
+        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()])
1361
+            ? $datetime_tickets[$datetime->ID()]
1362 1362
             : array();
1363 1363
         $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1364 1364
         $no_ticket = $default && empty($ticket);
@@ -1379,8 +1379,8 @@  discard block
 block discarded – undo
1379 1379
                 ? 'TKTNAME'
1380 1380
                 : $ticket->get('TKT_name'),
1381 1381
             'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1382
-                ? ' tkt-status-' . EE_Ticket::onsale
1383
-                : ' tkt-status-' . $ticket->ticket_status(),
1382
+                ? ' tkt-status-'.EE_Ticket::onsale
1383
+                : ' tkt-status-'.$ticket->ticket_status(),
1384 1384
         );
1385 1385
         // filter template args
1386 1386
         $template_args = apply_filters(
@@ -1395,7 +1395,7 @@  discard block
 block discarded – undo
1395 1395
             $this->_is_creating_event
1396 1396
         );
1397 1397
         return EEH_Template::display_template(
1398
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1398
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php',
1399 1399
             $template_args,
1400 1400
             true
1401 1401
         );
@@ -1451,19 +1451,19 @@  discard block
 block discarded – undo
1451 1451
         // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1452 1452
         // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1453 1453
         $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1454
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1455
-            ? $ticket_datetimes[ $ticket->ID() ]
1454
+        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
1455
+            ? $ticket_datetimes[$ticket->ID()]
1456 1456
             : array();
1457 1457
         $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1458 1458
         $base_price = $default ? null : $ticket->base_price();
1459 1459
         $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1460 1460
         // breaking out complicated condition for ticket_status
1461 1461
         if ($default) {
1462
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1462
+            $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale;
1463 1463
         } else {
1464 1464
             $ticket_status_class = $ticket->is_default()
1465
-                ? ' tkt-status-' . EE_Ticket::onsale
1466
-                : ' tkt-status-' . $ticket->ticket_status();
1465
+                ? ' tkt-status-'.EE_Ticket::onsale
1466
+                : ' tkt-status-'.$ticket->ticket_status();
1467 1467
         }
1468 1468
         // breaking out complicated condition for TKT_taxable
1469 1469
         if ($default) {
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
                 : 'display:none;',
1556 1556
             'show_price_mod_button'         => count($prices) > 1
1557 1557
                                                || ($default && $count_price_mods > 0)
1558
-                                               || (! $default && $ticket->deleted())
1558
+                                               || ( ! $default && $ticket->deleted())
1559 1559
                 ? 'display:none;'
1560 1560
                 : '',
1561 1561
             'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
@@ -1599,7 +1599,7 @@  discard block
 block discarded – undo
1599 1599
                 $this->_date_time_format,
1600 1600
                 current_time('timestamp')
1601 1601
             );
1602
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1602
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1603 1603
         }
1604 1604
         if (empty($template_args['TKT_end_date'])) {
1605 1605
             // get the earliest datetime (if present);
@@ -1609,7 +1609,7 @@  discard block
 block discarded – undo
1609 1609
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1610 1610
                 )
1611 1611
                 : null;
1612
-            if (! empty($earliest_dtt)) {
1612
+            if ( ! empty($earliest_dtt)) {
1613 1613
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1614 1614
                     'DTT_EVT_start',
1615 1615
                     $this->_date_time_format
@@ -1628,10 +1628,10 @@  discard block
 block discarded – undo
1628 1628
                     )
1629 1629
                 );
1630 1630
             }
1631
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1631
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1632 1632
         }
1633 1633
         // generate ticket_datetime items
1634
-        if (! $default) {
1634
+        if ( ! $default) {
1635 1635
             $datetime_row = 1;
1636 1636
             foreach ($all_datetimes as $datetime) {
1637 1637
                 $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
@@ -1647,7 +1647,7 @@  discard block
 block discarded – undo
1647 1647
         }
1648 1648
         $price_row = 1;
1649 1649
         foreach ($prices as $price) {
1650
-            if (! $price instanceof EE_Price) {
1650
+            if ( ! $price instanceof EE_Price) {
1651 1651
                 continue;
1652 1652
             }
1653 1653
             if ($price->is_base_price()) {
@@ -1680,7 +1680,7 @@  discard block
 block discarded – undo
1680 1680
             $this->_is_creating_event
1681 1681
         );
1682 1682
         return EEH_Template::display_template(
1683
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1683
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php',
1684 1684
             $template_args,
1685 1685
             true
1686 1686
         );
@@ -1720,7 +1720,7 @@  discard block
 block discarded – undo
1720 1720
                 $this->_is_creating_event
1721 1721
             );
1722 1722
             $tax_rows .= EEH_Template::display_template(
1723
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1723
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php',
1724 1724
                 $template_args,
1725 1725
                 true
1726 1726
             );
@@ -1839,7 +1839,7 @@  discard block
 block discarded – undo
1839 1839
             $this->_is_creating_event
1840 1840
         );
1841 1841
         return EEH_Template::display_template(
1842
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1842
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php',
1843 1843
             $template_args,
1844 1844
             true
1845 1845
         );
@@ -1909,7 +1909,7 @@  discard block
 block discarded – undo
1909 1909
             $this->_is_creating_event
1910 1910
         );
1911 1911
         return EEH_Template::display_template(
1912
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1912
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php',
1913 1913
             $template_args,
1914 1914
             true
1915 1915
         );
@@ -1939,7 +1939,7 @@  discard block
 block discarded – undo
1939 1939
     ) {
1940 1940
         $select_name = $default && ! $price instanceof EE_Price
1941 1941
             ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1942
-            : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]';
1942
+            : 'edit_prices['.esc_attr($ticket_row).']['.esc_attr($price_row).'][PRT_ID]';
1943 1943
         /** @var EEM_Price_Type $price_type_model */
1944 1944
         $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1945 1945
         $price_types = $price_type_model->get_all(array(
@@ -1957,10 +1957,10 @@  discard block
 block discarded – undo
1957 1957
         $price_option_spans = '';
1958 1958
         // setup price types for selector
1959 1959
         foreach ($price_types as $price_type) {
1960
-            if (! $price_type instanceof EE_Price_Type) {
1960
+            if ( ! $price_type instanceof EE_Price_Type) {
1961 1961
                 continue;
1962 1962
             }
1963
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1963
+            $all_price_types[$price_type->ID()] = $price_type->get('PRT_name');
1964 1964
             // while we're in the loop let's setup the option spans used by js
1965 1965
             $span_args = array(
1966 1966
                 'PRT_ID'         => $price_type->ID(),
@@ -1968,12 +1968,12 @@  discard block
 block discarded – undo
1968 1968
                 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1969 1969
             );
1970 1970
             $price_option_spans .= EEH_Template::display_template(
1971
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1971
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php',
1972 1972
                 $span_args,
1973 1973
                 true
1974 1974
             );
1975 1975
         }
1976
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1976
+        $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]'
1977 1977
             : $select_name;
1978 1978
         $select_input = new EE_Select_Input(
1979 1979
             $all_price_types,
@@ -2010,7 +2010,7 @@  discard block
 block discarded – undo
2010 2010
             $this->_is_creating_event
2011 2011
         );
2012 2012
         return EEH_Template::display_template(
2013
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2013
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php',
2014 2014
             $template_args,
2015 2015
             true
2016 2016
         );
@@ -2036,8 +2036,8 @@  discard block
 block discarded – undo
2036 2036
         $ticket_datetimes = array(),
2037 2037
         $default = false
2038 2038
     ) {
2039
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2040
-            ? $ticket_datetimes[ $ticket->ID() ]
2039
+        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
2040
+            ? $ticket_datetimes[$ticket->ID()]
2041 2041
             : array();
2042 2042
         $template_args = array(
2043 2043
             'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
@@ -2069,7 +2069,7 @@  discard block
 block discarded – undo
2069 2069
             $this->_is_creating_event
2070 2070
         );
2071 2071
         return EEH_Template::display_template(
2072
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2072
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2073 2073
             $template_args,
2074 2074
             true
2075 2075
         );
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
         $default_prices = $price_model->get_all_default_prices();
2176 2176
         $price_row = 1;
2177 2177
         foreach ($default_prices as $price) {
2178
-            if (! $price instanceof EE_Price) {
2178
+            if ( ! $price instanceof EE_Price) {
2179 2179
                 continue;
2180 2180
             }
2181 2181
             if ($price->is_base_price()) {
@@ -2212,7 +2212,7 @@  discard block
 block discarded – undo
2212 2212
             $this->_is_creating_event
2213 2213
         );
2214 2214
         return EEH_Template::display_template(
2215
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2215
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php',
2216 2216
             $template_args,
2217 2217
             true
2218 2218
         );
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/Pricing_Admin_Page.core.php 1 patch
Indentation   +1256 added lines, -1256 removed lines patch added patch discarded remove patch
@@ -11,1267 +11,1267 @@
 block discarded – undo
11 11
  */
12 12
 class Pricing_Admin_Page extends EE_Admin_Page
13 13
 {
14
-    protected function _init_page_props()
15
-    {
16
-        $this->page_slug        = PRICING_PG_SLUG;
17
-        $this->page_label       = PRICING_LABEL;
18
-        $this->_admin_base_url  = PRICING_ADMIN_URL;
19
-        $this->_admin_base_path = PRICING_ADMIN;
20
-    }
21
-
22
-
23
-    protected function _ajax_hooks()
24
-    {
25
-        add_action('wp_ajax_espresso_update_prices_order', [$this, 'update_price_order']);
26
-    }
27
-
28
-
29
-    protected function _define_page_props()
30
-    {
31
-        $this->_admin_page_title = PRICING_LABEL;
32
-        $this->_labels           = [
33
-            'buttons' => [
34
-                'add'         => esc_html__('Add New Default Price', 'event_espresso'),
35
-                'edit'        => esc_html__('Edit Default Price', 'event_espresso'),
36
-                'delete'      => esc_html__('Delete Default Price', 'event_espresso'),
37
-                'add_type'    => esc_html__('Add New Default Price Type', 'event_espresso'),
38
-                'edit_type'   => esc_html__('Edit Price Type', 'event_espresso'),
39
-                'delete_type' => esc_html__('Delete Price Type', 'event_espresso'),
40
-            ],
41
-        ];
42
-    }
43
-
44
-
45
-    /**
46
-     * an array for storing request actions and their corresponding methods
47
-     *
48
-     * @return void
49
-     */
50
-    protected function _set_page_routes()
51
-    {
52
-        $PRC_ID             = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
53
-        $PRT_ID             = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
54
-        $this->_page_routes = [
55
-            'default'                     => [
56
-                'func'       => [$this, '_price_overview_list_table'],
57
-                'capability' => 'ee_read_default_prices',
58
-            ],
59
-            'add_new_price'               => [
60
-                'func'       => [$this, '_edit_price_details'],
61
-                'capability' => 'ee_edit_default_prices',
62
-            ],
63
-            'edit_price'                  => [
64
-                'func'       => [$this, '_edit_price_details'],
65
-                'capability' => 'ee_edit_default_price',
66
-                'obj_id'     => $PRC_ID,
67
-            ],
68
-            'insert_price'                => [
69
-                'func'       => [$this, '_insert_or_update_price'],
70
-                'args'       => ['insert' => true],
71
-                'noheader'   => true,
72
-                'capability' => 'ee_edit_default_prices',
73
-            ],
74
-            'update_price'                => [
75
-                'func'       => [$this, '_insert_or_update_price'],
76
-                'args'       => ['insert' => false],
77
-                'noheader'   => true,
78
-                'capability' => 'ee_edit_default_price',
79
-                'obj_id'     => $PRC_ID,
80
-            ],
81
-            'trash_price'                 => [
82
-                'func'       => [$this, '_trash_or_restore_price'],
83
-                'args'       => ['trash' => true],
84
-                'noheader'   => true,
85
-                'capability' => 'ee_delete_default_price',
86
-                'obj_id'     => $PRC_ID,
87
-            ],
88
-            'restore_price'               => [
89
-                'func'       => [$this, '_trash_or_restore_price'],
90
-                'args'       => ['trash' => false],
91
-                'noheader'   => true,
92
-                'capability' => 'ee_delete_default_price',
93
-                'obj_id'     => $PRC_ID,
94
-            ],
95
-            'delete_price'                => [
96
-                'func'       => [$this, '_delete_price'],
97
-                'noheader'   => true,
98
-                'capability' => 'ee_delete_default_price',
99
-                'obj_id'     => $PRC_ID,
100
-            ],
101
-            'espresso_update_price_order' => [
102
-                'func'       => [$this, 'update_price_order'],
103
-                'noheader'   => true,
104
-                'capability' => 'ee_edit_default_prices',
105
-            ],
106
-            // price types
107
-            'price_types'                 => [
108
-                'func'       => [$this, '_price_types_overview_list_table'],
109
-                'capability' => 'ee_read_default_price_types',
110
-            ],
111
-            'add_new_price_type'          => [
112
-                'func'       => [$this, '_edit_price_type_details'],
113
-                'capability' => 'ee_edit_default_price_types',
114
-            ],
115
-            'edit_price_type'             => [
116
-                'func'       => [$this, '_edit_price_type_details'],
117
-                'capability' => 'ee_edit_default_price_type',
118
-                'obj_id'     => $PRT_ID,
119
-            ],
120
-            'insert_price_type'           => [
121
-                'func'       => [$this, '_insert_or_update_price_type'],
122
-                'args'       => ['new_price_type' => true],
123
-                'noheader'   => true,
124
-                'capability' => 'ee_edit_default_price_types',
125
-            ],
126
-            'update_price_type'           => [
127
-                'func'       => [$this, '_insert_or_update_price_type'],
128
-                'args'       => ['new_price_type' => false],
129
-                'noheader'   => true,
130
-                'capability' => 'ee_edit_default_price_type',
131
-                'obj_id'     => $PRT_ID,
132
-            ],
133
-            'trash_price_type'            => [
134
-                'func'       => [$this, '_trash_or_restore_price_type'],
135
-                'args'       => ['trash' => true],
136
-                'noheader'   => true,
137
-                'capability' => 'ee_delete_default_price_type',
138
-                'obj_id'     => $PRT_ID,
139
-            ],
140
-            'restore_price_type'          => [
141
-                'func'       => [$this, '_trash_or_restore_price_type'],
142
-                'args'       => ['trash' => false],
143
-                'noheader'   => true,
144
-                'capability' => 'ee_delete_default_price_type',
145
-                'obj_id'     => $PRT_ID,
146
-            ],
147
-            'delete_price_type'           => [
148
-                'func'       => [$this, '_delete_price_type'],
149
-                'noheader'   => true,
150
-                'capability' => 'ee_delete_default_price_type',
151
-                'obj_id'     => $PRT_ID,
152
-            ],
153
-            'tax_settings'                => [
154
-                'func'       => [$this, '_tax_settings'],
155
-                'capability' => 'manage_options',
156
-            ],
157
-            'update_tax_settings'         => [
158
-                'func'       => [$this, '_update_tax_settings'],
159
-                'capability' => 'manage_options',
160
-                'noheader'   => true,
161
-            ],
162
-        ];
163
-    }
164
-
165
-
166
-    protected function _set_page_config()
167
-    {
168
-        $PRC_ID             = $this->request->getRequestParam('id', 0, DataType::INTEGER);
169
-        $this->_page_config = [
170
-            'default'            => [
171
-                'nav'           => [
172
-                    'label' => esc_html__('Default Pricing', 'event_espresso'),
173
-                    'order' => 10,
174
-                ],
175
-                'list_table'    => 'Prices_List_Table',
176
-                'metaboxes'     => $this->_default_espresso_metaboxes,
177
-                'help_tabs'     => [
178
-                    'pricing_default_pricing_help_tab'                           => [
179
-                        'title'    => esc_html__('Default Pricing', 'event_espresso'),
180
-                        'filename' => 'pricing_default_pricing',
181
-                    ],
182
-                    'pricing_default_pricing_table_column_headings_help_tab'     => [
183
-                        'title'    => esc_html__('Default Pricing Table Column Headings', 'event_espresso'),
184
-                        'filename' => 'pricing_default_pricing_table_column_headings',
185
-                    ],
186
-                    'pricing_default_pricing_views_bulk_actions_search_help_tab' => [
187
-                        'title'    => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
188
-                        'filename' => 'pricing_default_pricing_views_bulk_actions_search',
189
-                    ],
190
-                ],
191
-                'require_nonce' => false,
192
-            ],
193
-            'add_new_price'      => [
194
-                'nav'           => [
195
-                    'label'      => esc_html__('Add New Default Price', 'event_espresso'),
196
-                    'order'      => 20,
197
-                    'persistent' => false,
198
-                ],
199
-                'help_tabs'     => [
200
-                    'add_new_default_price_help_tab' => [
201
-                        'title'    => esc_html__('Add New Default Price', 'event_espresso'),
202
-                        'filename' => 'pricing_add_new_default_price',
203
-                    ],
204
-                ],
205
-                'metaboxes'     => array_merge(
206
-                    ['_publish_post_box'],
207
-                    $this->_default_espresso_metaboxes
208
-                ),
209
-                'require_nonce' => false,
210
-            ],
211
-            'edit_price'         => [
212
-                'nav'           => [
213
-                    'label'      => esc_html__('Edit Default Price', 'event_espresso'),
214
-                    'order'      => 20,
215
-                    'url'        => $PRC_ID
216
-                        ? add_query_arg(['id' => $PRC_ID], $this->_current_page_view_url)
217
-                        : $this->_admin_base_url,
218
-                    'persistent' => false,
219
-                ],
220
-                'metaboxes'     => array_merge(
221
-                    ['_publish_post_box'],
222
-                    $this->_default_espresso_metaboxes
223
-                ),
224
-                'help_tabs'     => [
225
-                    'edit_default_price_help_tab' => [
226
-                        'title'    => esc_html__('Edit Default Price', 'event_espresso'),
227
-                        'filename' => 'pricing_edit_default_price',
228
-                    ],
229
-                ],
230
-                'require_nonce' => false,
231
-            ],
232
-            'price_types'        => [
233
-                'nav'           => [
234
-                    'label' => esc_html__('Price Types', 'event_espresso'),
235
-                    'order' => 30,
236
-                ],
237
-                'list_table'    => 'Price_Types_List_Table',
238
-                'help_tabs'     => [
239
-                    'pricing_price_types_help_tab'                           => [
240
-                        'title'    => esc_html__('Price Types', 'event_espresso'),
241
-                        'filename' => 'pricing_price_types',
242
-                    ],
243
-                    'pricing_price_types_table_column_headings_help_tab'     => [
244
-                        'title'    => esc_html__('Price Types Table Column Headings', 'event_espresso'),
245
-                        'filename' => 'pricing_price_types_table_column_headings',
246
-                    ],
247
-                    'pricing_price_types_views_bulk_actions_search_help_tab' => [
248
-                        'title'    => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'),
249
-                        'filename' => 'pricing_price_types_views_bulk_actions_search',
250
-                    ],
251
-                ],
252
-                'metaboxes'     => $this->_default_espresso_metaboxes,
253
-                'require_nonce' => false,
254
-            ],
255
-            'add_new_price_type' => [
256
-                'nav'           => [
257
-                    'label'      => esc_html__('Add New Price Type', 'event_espresso'),
258
-                    'order'      => 40,
259
-                    'persistent' => false,
260
-                ],
261
-                'help_tabs'     => [
262
-                    'add_new_price_type_help_tab' => [
263
-                        'title'    => esc_html__('Add New Price Type', 'event_espresso'),
264
-                        'filename' => 'pricing_add_new_price_type',
265
-                    ],
266
-                ],
267
-                'metaboxes'     => array_merge(
268
-                    ['_publish_post_box'],
269
-                    $this->_default_espresso_metaboxes
270
-                ),
271
-                'require_nonce' => false,
272
-            ],
273
-            'edit_price_type'    => [
274
-                'nav'           => [
275
-                    'label'      => esc_html__('Edit Price Type', 'event_espresso'),
276
-                    'order'      => 40,
277
-                    'persistent' => false,
278
-                ],
279
-                'help_tabs'     => [
280
-                    'edit_price_type_help_tab' => [
281
-                        'title'    => esc_html__('Edit Price Type', 'event_espresso'),
282
-                        'filename' => 'pricing_edit_price_type',
283
-                    ],
284
-                ],
285
-                'metaboxes'     => array_merge(
286
-                    ['_publish_post_box'],
287
-                    $this->_default_espresso_metaboxes
288
-                ),
289
-                'require_nonce' => false,
290
-            ],
291
-            'tax_settings'       => [
292
-                'nav'           => [
293
-                    'label' => esc_html__('Tax Settings', 'event_espresso'),
294
-                    'order' => 40,
295
-                ],
296
-                'labels'        => [
297
-                    'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'),
298
-                ],
299
-                'metaboxes'     => array_merge(
300
-                    ['_publish_post_box'],
301
-                    $this->_default_espresso_metaboxes
302
-                ),
303
-                'require_nonce' => true,
304
-            ],
305
-        ];
306
-    }
307
-
308
-
309
-    protected function _add_screen_options()
310
-    {
311
-        // todo
312
-    }
313
-
314
-
315
-    protected function _add_screen_options_default()
316
-    {
317
-        $this->_per_page_screen_option();
318
-    }
319
-
320
-
321
-    protected function _add_screen_options_price_types()
322
-    {
323
-        $page_title              = $this->_admin_page_title;
324
-        $this->_admin_page_title = esc_html__('Price Types', 'event_espresso');
325
-        $this->_per_page_screen_option();
326
-        $this->_admin_page_title = $page_title;
327
-    }
328
-
329
-
330
-    protected function _add_feature_pointers()
331
-    {
332
-    }
333
-
334
-
335
-    public function load_scripts_styles()
336
-    {
337
-        // styles
338
-        wp_enqueue_style('espresso-ui-theme');
339
-        wp_register_style(
340
-            'espresso_PRICING',
341
-            PRICING_ASSETS_URL . 'espresso_pricing_admin.css',
342
-            [],
343
-            EVENT_ESPRESSO_VERSION
344
-        );
345
-        wp_enqueue_style('espresso_PRICING');
346
-
347
-        // scripts
348
-        wp_enqueue_script('ee_admin_js');
349
-        wp_enqueue_script('jquery-ui-position');
350
-        wp_enqueue_script('jquery-ui-widget');
351
-        wp_register_script(
352
-            'espresso_PRICING',
353
-            PRICING_ASSETS_URL . 'espresso_pricing_admin.js',
354
-            ['jquery'],
355
-            EVENT_ESPRESSO_VERSION,
356
-            true
357
-        );
358
-        wp_enqueue_script('espresso_PRICING');
359
-    }
360
-
361
-
362
-    public function load_scripts_styles_default()
363
-    {
364
-        wp_enqueue_script('espresso_ajax_table_sorting');
365
-    }
366
-
367
-
368
-    public function admin_footer_scripts()
369
-    {
370
-    }
371
-
372
-
373
-    public function admin_init()
374
-    {
375
-    }
376
-
377
-
378
-    public function admin_notices()
379
-    {
380
-    }
381
-
382
-
383
-    protected function _set_list_table_views_default()
384
-    {
385
-        $this->_views = [
386
-            'all' => [
387
-                'slug'        => 'all',
388
-                'label'       => esc_html__('View All Default Pricing', 'event_espresso'),
389
-                'count'       => 0,
390
-                'bulk_action' => [
391
-                    'trash_price' => esc_html__('Move to Trash', 'event_espresso'),
392
-                ],
393
-            ],
394
-        ];
395
-
396
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
397
-            $this->_views['trashed'] = [
398
-                'slug'        => 'trashed',
399
-                'label'       => esc_html__('Trash', 'event_espresso'),
400
-                'count'       => 0,
401
-                'bulk_action' => [
402
-                    'restore_price' => esc_html__('Restore from Trash', 'event_espresso'),
403
-                    'delete_price'  => esc_html__('Delete Permanently', 'event_espresso'),
404
-                ],
405
-            ];
406
-        }
407
-    }
408
-
409
-
410
-    protected function _set_list_table_views_price_types()
411
-    {
412
-        $this->_views = [
413
-            'all' => [
414
-                'slug'        => 'all',
415
-                'label'       => esc_html__('All', 'event_espresso'),
416
-                'count'       => 0,
417
-                'bulk_action' => [
418
-                    'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'),
419
-                ],
420
-            ],
421
-        ];
422
-
423
-        if (
424
-            EE_Registry::instance()->CAP->current_user_can(
425
-                'ee_delete_default_price_types',
426
-                'pricing_trash_price_type'
427
-            )
428
-        ) {
429
-            $this->_views['trashed'] = [
430
-                'slug'        => 'trashed',
431
-                'label'       => esc_html__('Trash', 'event_espresso'),
432
-                'count'       => 0,
433
-                'bulk_action' => [
434
-                    'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'),
435
-                    'delete_price_type'  => esc_html__('Delete Permanently', 'event_espresso'),
436
-                ],
437
-            ];
438
-        }
439
-    }
440
-
441
-
442
-    /**
443
-     * generates HTML for main Prices Admin page
444
-     *
445
-     * @return void
446
-     * @throws EE_Error
447
-     */
448
-    protected function _price_overview_list_table()
449
-    {
450
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
451
-            'add_new_price',
452
-            'add',
453
-            [],
454
-            'add-new-h2'
455
-        );
456
-        $this->_admin_page_title .= $this->_learn_more_about_pricing_link();
457
-        $this->_search_btn_label = esc_html__('Default Prices', 'event_espresso');
458
-        $this->display_admin_list_table_page_with_sidebar();
459
-    }
460
-
461
-
462
-    /**
463
-     * retrieve data for Prices List table
464
-     *
465
-     * @param int  $per_page how many prices displayed per page
466
-     * @param bool $count    return the count or objects
467
-     * @param bool $trashed  whether the current view is of the trash can - eww yuck!
468
-     * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
469
-     * @throws EE_Error
470
-     * @throws ReflectionException
471
-     */
472
-    public function get_prices_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
473
-    {
474
-        // start with an empty array
475
-        $event_pricing = [];
476
-
477
-        require_once(PRICING_ADMIN . 'Prices_List_Table.class.php');
478
-
479
-        $orderby = $this->request->getRequestParam('orderby', '');
480
-        $order   = $this->request->getRequestParam('order', 'ASC');
481
-
482
-        switch ($orderby) {
483
-            case 'name':
484
-                $orderby = ['PRC_name' => $order];
485
-                break;
486
-            case 'type':
487
-                $orderby = ['Price_Type.PRT_name' => $order];
488
-                break;
489
-            case 'amount':
490
-                $orderby = ['PRC_amount' => $order];
491
-                break;
492
-            default:
493
-                $orderby = ['PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order];
494
-        }
495
-
496
-        $current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
497
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
498
-
499
-        $where = [
500
-            'PRC_is_default' => 1,
501
-            'PRC_deleted'    => $trashed,
502
-        ];
503
-
504
-        $offset = ($current_page - 1) * $per_page;
505
-        $limit  = [$offset, $per_page];
506
-
507
-        $search_term = $this->request->getRequestParam('s');
508
-        if ($search_term) {
509
-            $search_term = "%{$search_term}%";
510
-            $where['OR'] = [
511
-                'PRC_name'            => ['LIKE', $search_term],
512
-                'PRC_desc'            => ['LIKE', $search_term],
513
-                'PRC_amount'          => ['LIKE', $search_term],
514
-                'Price_Type.PRT_name' => ['LIKE', $search_term],
515
-            ];
516
-        }
517
-
518
-        $query_params = [
519
-            $where,
520
-            'order_by' => $orderby,
521
-            'limit'    => $limit,
522
-            'group_by' => 'PRC_ID',
523
-        ];
524
-
525
-        if ($count) {
526
-            return $trashed
527
-                ? EEM_Price::instance()->count([$where])
528
-                : EEM_Price::instance()->count_deleted_and_undeleted([$where]);
529
-        }
530
-        return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
531
-    }
532
-
533
-
534
-    /**
535
-     * @return void
536
-     * @throws EE_Error
537
-     * @throws ReflectionException
538
-     */
539
-    protected function _edit_price_details()
540
-    {
541
-        // grab price ID
542
-        $PRC_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
543
-        // change page title based on request action
544
-        switch ($this->_req_action) {
545
-            case 'add_new_price':
546
-                $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso');
547
-                break;
548
-            case 'edit_price':
549
-                $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso');
550
-                break;
551
-            default:
552
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
553
-        }
554
-        // add PRC_ID to title if editing
555
-        $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
556
-
557
-        if ($PRC_ID) {
558
-            $price                    = EEM_Price::instance()->get_one_by_ID($PRC_ID);
559
-            $additional_hidden_fields = [
560
-                'PRC_ID' => ['type' => 'hidden', 'value' => $PRC_ID],
561
-            ];
562
-            $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields);
563
-        } else {
564
-            $price = EEM_Price::instance()->get_new_price();
565
-            $this->_set_add_edit_form_tags('insert_price');
566
-        }
567
-
568
-        if (! $price instanceof EE_Price) {
569
-            throw new RuntimeException(
570
-                sprintf(
571
-                    esc_html__(
572
-                        'A valid Price could not be retrieved from the database with ID: %1$s',
573
-                        'event_espresso'
574
-                    ),
575
-                    $PRC_ID
576
-                )
577
-            );
578
-        }
579
-
580
-        $this->_template_args['PRC_ID'] = $PRC_ID;
581
-        $this->_template_args['price']  = $price;
582
-
583
-        $default_base_price = $price->type_obj() && $price->type_obj()->base_type() === 1;
584
-
585
-        $this->_template_args['default_base_price'] = $default_base_price;
586
-
587
-        // get price types
588
-        $price_types = EEM_Price_Type::instance()->get_all([['PBT_ID' => ['!=', 1]]]);
589
-        if (empty($price_types)) {
590
-            $msg = esc_html__(
591
-                'You have no price types defined. Please add a price type before adding a price.',
592
-                'event_espresso'
593
-            );
594
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
595
-            $this->display_admin_page_with_sidebar();
596
-        }
597
-        $attributes       = [];
598
-        $price_type_names = [];
599
-        $attributes[]     = 'id="PRT_ID"';
600
-        if ($default_base_price) {
601
-            $attributes[]       = 'disabled="disabled"';
602
-            $price_type_names[] = ['id' => 1, 'text' => esc_html__('Base Price', 'event_espresso')];
603
-        }
604
-        foreach ($price_types as $type) {
605
-            $price_type_names[] = ['id' => $type->ID(), 'text' => $type->name()];
606
-        }
607
-        $this->_template_args['attributes']  = implode(' ', $attributes);
608
-        $this->_template_args['price_types'] = $price_type_names;
609
-
610
-        $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
611
-        $this->_template_args['admin_page_content']            = $this->_edit_price_details_meta_box();
612
-
613
-        $this->_set_publish_post_box_vars('id', $PRC_ID);
614
-        // the details template wrapper
615
-        $this->display_admin_page_with_sidebar();
616
-    }
617
-
618
-
619
-    /**
620
-     *
621
-     * @return string
622
-     */
623
-    public function _edit_price_details_meta_box(): string
624
-    {
625
-        return EEH_Template::display_template(
626
-            PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php',
627
-            $this->_template_args,
628
-            true
629
-        );
630
-    }
631
-
632
-
633
-    /**
634
-     * @return array
635
-     * @throws EE_Error
636
-     * @throws ReflectionException
637
-     */
638
-    protected function set_price_column_values(): array
639
-    {
640
-        $PRC_order = 0;
641
-        $PRT_ID    = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
642
-        if ($PRT_ID) {
643
-            /** @var EE_Price_Type $price_type */
644
-            $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
645
-            if ($price_type instanceof EE_Price_Type) {
646
-                $PRC_order = $price_type->order();
647
-            }
648
-        }
649
-        return [
650
-            'PRT_ID'         => $PRT_ID,
651
-            'PRC_amount'     => $this->request->getRequestParam('PRC_amount', 0, DataType::FLOAT),
652
-            'PRC_name'       => $this->request->getRequestParam('PRC_name'),
653
-            'PRC_desc'       => $this->request->getRequestParam('PRC_desc'),
654
-            'PRC_is_default' => 1,
655
-            'PRC_overrides'  => null,
656
-            'PRC_order'      => $PRC_order,
657
-            'PRC_deleted'    => 0,
658
-            'PRC_parent'     => 0,
659
-        ];
660
-    }
661
-
662
-
663
-    /**
664
-     * @param bool $insert - whether to insert or update
665
-     * @return void
666
-     * @throws EE_Error
667
-     * @throws ReflectionException
668
-     */
669
-    protected function _insert_or_update_price(bool $insert = false)
670
-    {
671
-        // why be so pessimistic ???  : (
672
-        $updated = 0;
673
-
674
-        $set_column_values = $this->set_price_column_values();
675
-        // is this a new Price ?
676
-        if ($insert) {
677
-            // run the insert
678
-            $PRC_ID = EEM_Price::instance()->insert($set_column_values);
679
-            if ($PRC_ID) {
680
-                // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
681
-                $price = EEM_price::instance()->get_one_by_ID($PRC_ID);
682
-                if (
683
-                    $price instanceof EE_Price
684
-                    && $price->type_obj() instanceof EE_Price_type
685
-                    && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax
686
-                ) {
687
-                    $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
688
-                    $ticket->_add_relation_to($price, 'Price');
689
-                    $ticket->save();
690
-                }
691
-                $updated = 1;
692
-            }
693
-            $action_desc = 'created';
694
-        } else {
695
-            $PRC_ID = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
696
-            // run the update
697
-            $where_cols_n_values = ['PRC_ID' => $PRC_ID];
698
-            $updated             = EEM_Price::instance()->update($set_column_values, [$where_cols_n_values]);
699
-
700
-            $price = EEM_Price::instance()->get_one_by_ID($PRC_ID);
701
-            if ($price instanceof EE_Price && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
702
-                // if this is $PRC_ID == 1,
703
-                // then we need to update the default ticket attached to this price so the TKT_price value is updated.
704
-                if ($PRC_ID === 1) {
705
-                    $ticket = $price->get_first_related('Ticket');
706
-                    if ($ticket) {
707
-                        $ticket->set('TKT_price', $price->get('PRC_amount'));
708
-                        $ticket->set('TKT_name', $price->get('PRC_name'));
709
-                        $ticket->set('TKT_description', $price->get('PRC_desc'));
710
-                        $ticket->save();
711
-                    }
712
-                } else {
713
-                    // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type.
714
-                    $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
715
-                    $ticket->_add_relation_to($PRC_ID, 'Price');
716
-                    $ticket->save();
717
-                }
718
-            }
719
-
720
-            $action_desc = 'updated';
721
-        }
722
-
723
-        $query_args = ['action' => 'edit_price', 'id' => $PRC_ID];
724
-
725
-        $this->_redirect_after_action($updated, 'Prices', $action_desc, $query_args);
726
-    }
727
-
728
-
729
-    /**
730
-     * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
731
-     * @return void
732
-     * @throws EE_Error
733
-     */
734
-    protected function _trash_or_restore_price($trash = true)
735
-    {
736
-        $entity_model = EEM_Price::instance();
737
-        $action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
738
-        $result       = $this->trashRestoreDeleteEntities(
739
-            $entity_model,
740
-            'id',
741
-            $action,
742
-            'PRC_deleted',
743
-            [$this, 'adjustTicketRelations']
744
-        );
745
-
746
-        if ($result) {
747
-            $msg = $trash
748
-                ? esc_html(
749
-                    _n(
750
-                        'The Price has been trashed',
751
-                        'The Prices have been trashed',
752
-                        $result,
753
-                        'event_espresso'
754
-                    )
755
-                )
756
-                : esc_html(
757
-                    _n(
758
-                        'The Price has been restored',
759
-                        'The Prices have been restored',
760
-                        $result,
761
-                        'event_espresso'
762
-                    )
763
-                );
764
-            EE_Error::add_success($msg);
765
-        }
766
-
767
-        $this->_redirect_after_action(
768
-            $result,
769
-            _n('Price', 'Prices', $result, 'event_espresso'),
770
-            $trash ? 'trashed' : 'restored',
771
-            ['action' => 'default'],
772
-            true
773
-        );
774
-    }
775
-
776
-
777
-    /**
778
-     * @param EEM_Base   $entity_model
779
-     * @param int|string $entity_ID
780
-     * @param string     $action
781
-     * @param int        $result
782
-     * @throws EE_Error
783
-     * @throws ReflectionException
784
-     * @since 4.10.30.p
785
-     */
786
-    public function adjustTicketRelations(EEM_Base $entity_model, $entity_ID, string $action, int $result)
787
-    {
788
-        if (! $entity_ID || (float) $result < 1) {
789
-            return;
790
-        }
791
-
792
-        $entity = $entity_model->get_one_by_ID($entity_ID);
793
-        if (! $entity instanceof EE_Price || $entity->type_obj()->base_type() === EEM_Price_Type::base_type_tax) {
794
-            return;
795
-        }
796
-
797
-        // get default tickets for updating
798
-        $default_tickets = EEM_Ticket::instance()->get_all_default_tickets();
799
-        foreach ($default_tickets as $default_ticket) {
800
-            if (! $default_ticket instanceof EE_Ticket) {
801
-                continue;
802
-            }
803
-            switch ($action) {
804
-                case EE_Admin_List_Table::ACTION_DELETE:
805
-                case EE_Admin_List_Table::ACTION_TRASH:
806
-                    // if trashing then remove relations to base default ticket.
807
-                    $default_ticket->_remove_relation_to($entity_ID, 'Price');
808
-                    break;
809
-                case EE_Admin_List_Table::ACTION_RESTORE:
810
-                    // if restoring then add back to base default ticket
811
-                    $default_ticket->_add_relation_to($entity_ID, 'Price');
812
-                    break;
813
-            }
814
-            $default_ticket->save();
815
-        }
816
-    }
817
-
818
-
819
-    /**
820
-     * @return void
821
-     * @throws EE_Error
822
-     * @throws ReflectionException
823
-     */
824
-    protected function _delete_price()
825
-    {
826
-        $entity_model = EEM_Price::instance();
827
-        $deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
828
-        $entity       = $entity_model->item_name($deleted);
829
-        $this->_redirect_after_action($deleted, $entity, 'deleted', ['action' => 'default']);
830
-    }
831
-
832
-
833
-    /**
834
-     * @throws EE_Error
835
-     * @throws ReflectionException
836
-     */
837
-    public function update_price_order()
838
-    {
839
-        // grab our row IDs
840
-        $row_ids = $this->request->getRequestParam('row_ids', '');
841
-        $row_ids = explode(',', rtrim($row_ids, ','));
842
-
843
-        $all_updated = true;
844
-        foreach ($row_ids as $i => $row_id) {
845
-            // Update the prices when re-ordering
846
-            $fields_n_values = ['PRC_order' => $i + 1];
847
-            $query_params    = [['PRC_ID' => absint($row_id)]];
848
-            // any failure will toggle $all_updated to false
849
-            $all_updated = $row_id && EEM_Price::instance()->update($fields_n_values, $query_params) !== false
850
-                ? $all_updated
851
-                : false;
852
-        }
853
-        $success = $all_updated ? esc_html__('Price order was updated successfully.', 'event_espresso') : false;
854
-        $errors  = ! $all_updated ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso')
855
-            : false;
856
-
857
-        echo wp_json_encode(['return_data' => false, 'success' => $success, 'errors' => $errors]);
858
-        die();
859
-    }
860
-
861
-
862
-    /******************************************************************************************************************
14
+	protected function _init_page_props()
15
+	{
16
+		$this->page_slug        = PRICING_PG_SLUG;
17
+		$this->page_label       = PRICING_LABEL;
18
+		$this->_admin_base_url  = PRICING_ADMIN_URL;
19
+		$this->_admin_base_path = PRICING_ADMIN;
20
+	}
21
+
22
+
23
+	protected function _ajax_hooks()
24
+	{
25
+		add_action('wp_ajax_espresso_update_prices_order', [$this, 'update_price_order']);
26
+	}
27
+
28
+
29
+	protected function _define_page_props()
30
+	{
31
+		$this->_admin_page_title = PRICING_LABEL;
32
+		$this->_labels           = [
33
+			'buttons' => [
34
+				'add'         => esc_html__('Add New Default Price', 'event_espresso'),
35
+				'edit'        => esc_html__('Edit Default Price', 'event_espresso'),
36
+				'delete'      => esc_html__('Delete Default Price', 'event_espresso'),
37
+				'add_type'    => esc_html__('Add New Default Price Type', 'event_espresso'),
38
+				'edit_type'   => esc_html__('Edit Price Type', 'event_espresso'),
39
+				'delete_type' => esc_html__('Delete Price Type', 'event_espresso'),
40
+			],
41
+		];
42
+	}
43
+
44
+
45
+	/**
46
+	 * an array for storing request actions and their corresponding methods
47
+	 *
48
+	 * @return void
49
+	 */
50
+	protected function _set_page_routes()
51
+	{
52
+		$PRC_ID             = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
53
+		$PRT_ID             = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
54
+		$this->_page_routes = [
55
+			'default'                     => [
56
+				'func'       => [$this, '_price_overview_list_table'],
57
+				'capability' => 'ee_read_default_prices',
58
+			],
59
+			'add_new_price'               => [
60
+				'func'       => [$this, '_edit_price_details'],
61
+				'capability' => 'ee_edit_default_prices',
62
+			],
63
+			'edit_price'                  => [
64
+				'func'       => [$this, '_edit_price_details'],
65
+				'capability' => 'ee_edit_default_price',
66
+				'obj_id'     => $PRC_ID,
67
+			],
68
+			'insert_price'                => [
69
+				'func'       => [$this, '_insert_or_update_price'],
70
+				'args'       => ['insert' => true],
71
+				'noheader'   => true,
72
+				'capability' => 'ee_edit_default_prices',
73
+			],
74
+			'update_price'                => [
75
+				'func'       => [$this, '_insert_or_update_price'],
76
+				'args'       => ['insert' => false],
77
+				'noheader'   => true,
78
+				'capability' => 'ee_edit_default_price',
79
+				'obj_id'     => $PRC_ID,
80
+			],
81
+			'trash_price'                 => [
82
+				'func'       => [$this, '_trash_or_restore_price'],
83
+				'args'       => ['trash' => true],
84
+				'noheader'   => true,
85
+				'capability' => 'ee_delete_default_price',
86
+				'obj_id'     => $PRC_ID,
87
+			],
88
+			'restore_price'               => [
89
+				'func'       => [$this, '_trash_or_restore_price'],
90
+				'args'       => ['trash' => false],
91
+				'noheader'   => true,
92
+				'capability' => 'ee_delete_default_price',
93
+				'obj_id'     => $PRC_ID,
94
+			],
95
+			'delete_price'                => [
96
+				'func'       => [$this, '_delete_price'],
97
+				'noheader'   => true,
98
+				'capability' => 'ee_delete_default_price',
99
+				'obj_id'     => $PRC_ID,
100
+			],
101
+			'espresso_update_price_order' => [
102
+				'func'       => [$this, 'update_price_order'],
103
+				'noheader'   => true,
104
+				'capability' => 'ee_edit_default_prices',
105
+			],
106
+			// price types
107
+			'price_types'                 => [
108
+				'func'       => [$this, '_price_types_overview_list_table'],
109
+				'capability' => 'ee_read_default_price_types',
110
+			],
111
+			'add_new_price_type'          => [
112
+				'func'       => [$this, '_edit_price_type_details'],
113
+				'capability' => 'ee_edit_default_price_types',
114
+			],
115
+			'edit_price_type'             => [
116
+				'func'       => [$this, '_edit_price_type_details'],
117
+				'capability' => 'ee_edit_default_price_type',
118
+				'obj_id'     => $PRT_ID,
119
+			],
120
+			'insert_price_type'           => [
121
+				'func'       => [$this, '_insert_or_update_price_type'],
122
+				'args'       => ['new_price_type' => true],
123
+				'noheader'   => true,
124
+				'capability' => 'ee_edit_default_price_types',
125
+			],
126
+			'update_price_type'           => [
127
+				'func'       => [$this, '_insert_or_update_price_type'],
128
+				'args'       => ['new_price_type' => false],
129
+				'noheader'   => true,
130
+				'capability' => 'ee_edit_default_price_type',
131
+				'obj_id'     => $PRT_ID,
132
+			],
133
+			'trash_price_type'            => [
134
+				'func'       => [$this, '_trash_or_restore_price_type'],
135
+				'args'       => ['trash' => true],
136
+				'noheader'   => true,
137
+				'capability' => 'ee_delete_default_price_type',
138
+				'obj_id'     => $PRT_ID,
139
+			],
140
+			'restore_price_type'          => [
141
+				'func'       => [$this, '_trash_or_restore_price_type'],
142
+				'args'       => ['trash' => false],
143
+				'noheader'   => true,
144
+				'capability' => 'ee_delete_default_price_type',
145
+				'obj_id'     => $PRT_ID,
146
+			],
147
+			'delete_price_type'           => [
148
+				'func'       => [$this, '_delete_price_type'],
149
+				'noheader'   => true,
150
+				'capability' => 'ee_delete_default_price_type',
151
+				'obj_id'     => $PRT_ID,
152
+			],
153
+			'tax_settings'                => [
154
+				'func'       => [$this, '_tax_settings'],
155
+				'capability' => 'manage_options',
156
+			],
157
+			'update_tax_settings'         => [
158
+				'func'       => [$this, '_update_tax_settings'],
159
+				'capability' => 'manage_options',
160
+				'noheader'   => true,
161
+			],
162
+		];
163
+	}
164
+
165
+
166
+	protected function _set_page_config()
167
+	{
168
+		$PRC_ID             = $this->request->getRequestParam('id', 0, DataType::INTEGER);
169
+		$this->_page_config = [
170
+			'default'            => [
171
+				'nav'           => [
172
+					'label' => esc_html__('Default Pricing', 'event_espresso'),
173
+					'order' => 10,
174
+				],
175
+				'list_table'    => 'Prices_List_Table',
176
+				'metaboxes'     => $this->_default_espresso_metaboxes,
177
+				'help_tabs'     => [
178
+					'pricing_default_pricing_help_tab'                           => [
179
+						'title'    => esc_html__('Default Pricing', 'event_espresso'),
180
+						'filename' => 'pricing_default_pricing',
181
+					],
182
+					'pricing_default_pricing_table_column_headings_help_tab'     => [
183
+						'title'    => esc_html__('Default Pricing Table Column Headings', 'event_espresso'),
184
+						'filename' => 'pricing_default_pricing_table_column_headings',
185
+					],
186
+					'pricing_default_pricing_views_bulk_actions_search_help_tab' => [
187
+						'title'    => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
188
+						'filename' => 'pricing_default_pricing_views_bulk_actions_search',
189
+					],
190
+				],
191
+				'require_nonce' => false,
192
+			],
193
+			'add_new_price'      => [
194
+				'nav'           => [
195
+					'label'      => esc_html__('Add New Default Price', 'event_espresso'),
196
+					'order'      => 20,
197
+					'persistent' => false,
198
+				],
199
+				'help_tabs'     => [
200
+					'add_new_default_price_help_tab' => [
201
+						'title'    => esc_html__('Add New Default Price', 'event_espresso'),
202
+						'filename' => 'pricing_add_new_default_price',
203
+					],
204
+				],
205
+				'metaboxes'     => array_merge(
206
+					['_publish_post_box'],
207
+					$this->_default_espresso_metaboxes
208
+				),
209
+				'require_nonce' => false,
210
+			],
211
+			'edit_price'         => [
212
+				'nav'           => [
213
+					'label'      => esc_html__('Edit Default Price', 'event_espresso'),
214
+					'order'      => 20,
215
+					'url'        => $PRC_ID
216
+						? add_query_arg(['id' => $PRC_ID], $this->_current_page_view_url)
217
+						: $this->_admin_base_url,
218
+					'persistent' => false,
219
+				],
220
+				'metaboxes'     => array_merge(
221
+					['_publish_post_box'],
222
+					$this->_default_espresso_metaboxes
223
+				),
224
+				'help_tabs'     => [
225
+					'edit_default_price_help_tab' => [
226
+						'title'    => esc_html__('Edit Default Price', 'event_espresso'),
227
+						'filename' => 'pricing_edit_default_price',
228
+					],
229
+				],
230
+				'require_nonce' => false,
231
+			],
232
+			'price_types'        => [
233
+				'nav'           => [
234
+					'label' => esc_html__('Price Types', 'event_espresso'),
235
+					'order' => 30,
236
+				],
237
+				'list_table'    => 'Price_Types_List_Table',
238
+				'help_tabs'     => [
239
+					'pricing_price_types_help_tab'                           => [
240
+						'title'    => esc_html__('Price Types', 'event_espresso'),
241
+						'filename' => 'pricing_price_types',
242
+					],
243
+					'pricing_price_types_table_column_headings_help_tab'     => [
244
+						'title'    => esc_html__('Price Types Table Column Headings', 'event_espresso'),
245
+						'filename' => 'pricing_price_types_table_column_headings',
246
+					],
247
+					'pricing_price_types_views_bulk_actions_search_help_tab' => [
248
+						'title'    => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'),
249
+						'filename' => 'pricing_price_types_views_bulk_actions_search',
250
+					],
251
+				],
252
+				'metaboxes'     => $this->_default_espresso_metaboxes,
253
+				'require_nonce' => false,
254
+			],
255
+			'add_new_price_type' => [
256
+				'nav'           => [
257
+					'label'      => esc_html__('Add New Price Type', 'event_espresso'),
258
+					'order'      => 40,
259
+					'persistent' => false,
260
+				],
261
+				'help_tabs'     => [
262
+					'add_new_price_type_help_tab' => [
263
+						'title'    => esc_html__('Add New Price Type', 'event_espresso'),
264
+						'filename' => 'pricing_add_new_price_type',
265
+					],
266
+				],
267
+				'metaboxes'     => array_merge(
268
+					['_publish_post_box'],
269
+					$this->_default_espresso_metaboxes
270
+				),
271
+				'require_nonce' => false,
272
+			],
273
+			'edit_price_type'    => [
274
+				'nav'           => [
275
+					'label'      => esc_html__('Edit Price Type', 'event_espresso'),
276
+					'order'      => 40,
277
+					'persistent' => false,
278
+				],
279
+				'help_tabs'     => [
280
+					'edit_price_type_help_tab' => [
281
+						'title'    => esc_html__('Edit Price Type', 'event_espresso'),
282
+						'filename' => 'pricing_edit_price_type',
283
+					],
284
+				],
285
+				'metaboxes'     => array_merge(
286
+					['_publish_post_box'],
287
+					$this->_default_espresso_metaboxes
288
+				),
289
+				'require_nonce' => false,
290
+			],
291
+			'tax_settings'       => [
292
+				'nav'           => [
293
+					'label' => esc_html__('Tax Settings', 'event_espresso'),
294
+					'order' => 40,
295
+				],
296
+				'labels'        => [
297
+					'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'),
298
+				],
299
+				'metaboxes'     => array_merge(
300
+					['_publish_post_box'],
301
+					$this->_default_espresso_metaboxes
302
+				),
303
+				'require_nonce' => true,
304
+			],
305
+		];
306
+	}
307
+
308
+
309
+	protected function _add_screen_options()
310
+	{
311
+		// todo
312
+	}
313
+
314
+
315
+	protected function _add_screen_options_default()
316
+	{
317
+		$this->_per_page_screen_option();
318
+	}
319
+
320
+
321
+	protected function _add_screen_options_price_types()
322
+	{
323
+		$page_title              = $this->_admin_page_title;
324
+		$this->_admin_page_title = esc_html__('Price Types', 'event_espresso');
325
+		$this->_per_page_screen_option();
326
+		$this->_admin_page_title = $page_title;
327
+	}
328
+
329
+
330
+	protected function _add_feature_pointers()
331
+	{
332
+	}
333
+
334
+
335
+	public function load_scripts_styles()
336
+	{
337
+		// styles
338
+		wp_enqueue_style('espresso-ui-theme');
339
+		wp_register_style(
340
+			'espresso_PRICING',
341
+			PRICING_ASSETS_URL . 'espresso_pricing_admin.css',
342
+			[],
343
+			EVENT_ESPRESSO_VERSION
344
+		);
345
+		wp_enqueue_style('espresso_PRICING');
346
+
347
+		// scripts
348
+		wp_enqueue_script('ee_admin_js');
349
+		wp_enqueue_script('jquery-ui-position');
350
+		wp_enqueue_script('jquery-ui-widget');
351
+		wp_register_script(
352
+			'espresso_PRICING',
353
+			PRICING_ASSETS_URL . 'espresso_pricing_admin.js',
354
+			['jquery'],
355
+			EVENT_ESPRESSO_VERSION,
356
+			true
357
+		);
358
+		wp_enqueue_script('espresso_PRICING');
359
+	}
360
+
361
+
362
+	public function load_scripts_styles_default()
363
+	{
364
+		wp_enqueue_script('espresso_ajax_table_sorting');
365
+	}
366
+
367
+
368
+	public function admin_footer_scripts()
369
+	{
370
+	}
371
+
372
+
373
+	public function admin_init()
374
+	{
375
+	}
376
+
377
+
378
+	public function admin_notices()
379
+	{
380
+	}
381
+
382
+
383
+	protected function _set_list_table_views_default()
384
+	{
385
+		$this->_views = [
386
+			'all' => [
387
+				'slug'        => 'all',
388
+				'label'       => esc_html__('View All Default Pricing', 'event_espresso'),
389
+				'count'       => 0,
390
+				'bulk_action' => [
391
+					'trash_price' => esc_html__('Move to Trash', 'event_espresso'),
392
+				],
393
+			],
394
+		];
395
+
396
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
397
+			$this->_views['trashed'] = [
398
+				'slug'        => 'trashed',
399
+				'label'       => esc_html__('Trash', 'event_espresso'),
400
+				'count'       => 0,
401
+				'bulk_action' => [
402
+					'restore_price' => esc_html__('Restore from Trash', 'event_espresso'),
403
+					'delete_price'  => esc_html__('Delete Permanently', 'event_espresso'),
404
+				],
405
+			];
406
+		}
407
+	}
408
+
409
+
410
+	protected function _set_list_table_views_price_types()
411
+	{
412
+		$this->_views = [
413
+			'all' => [
414
+				'slug'        => 'all',
415
+				'label'       => esc_html__('All', 'event_espresso'),
416
+				'count'       => 0,
417
+				'bulk_action' => [
418
+					'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'),
419
+				],
420
+			],
421
+		];
422
+
423
+		if (
424
+			EE_Registry::instance()->CAP->current_user_can(
425
+				'ee_delete_default_price_types',
426
+				'pricing_trash_price_type'
427
+			)
428
+		) {
429
+			$this->_views['trashed'] = [
430
+				'slug'        => 'trashed',
431
+				'label'       => esc_html__('Trash', 'event_espresso'),
432
+				'count'       => 0,
433
+				'bulk_action' => [
434
+					'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'),
435
+					'delete_price_type'  => esc_html__('Delete Permanently', 'event_espresso'),
436
+				],
437
+			];
438
+		}
439
+	}
440
+
441
+
442
+	/**
443
+	 * generates HTML for main Prices Admin page
444
+	 *
445
+	 * @return void
446
+	 * @throws EE_Error
447
+	 */
448
+	protected function _price_overview_list_table()
449
+	{
450
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
451
+			'add_new_price',
452
+			'add',
453
+			[],
454
+			'add-new-h2'
455
+		);
456
+		$this->_admin_page_title .= $this->_learn_more_about_pricing_link();
457
+		$this->_search_btn_label = esc_html__('Default Prices', 'event_espresso');
458
+		$this->display_admin_list_table_page_with_sidebar();
459
+	}
460
+
461
+
462
+	/**
463
+	 * retrieve data for Prices List table
464
+	 *
465
+	 * @param int  $per_page how many prices displayed per page
466
+	 * @param bool $count    return the count or objects
467
+	 * @param bool $trashed  whether the current view is of the trash can - eww yuck!
468
+	 * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
469
+	 * @throws EE_Error
470
+	 * @throws ReflectionException
471
+	 */
472
+	public function get_prices_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
473
+	{
474
+		// start with an empty array
475
+		$event_pricing = [];
476
+
477
+		require_once(PRICING_ADMIN . 'Prices_List_Table.class.php');
478
+
479
+		$orderby = $this->request->getRequestParam('orderby', '');
480
+		$order   = $this->request->getRequestParam('order', 'ASC');
481
+
482
+		switch ($orderby) {
483
+			case 'name':
484
+				$orderby = ['PRC_name' => $order];
485
+				break;
486
+			case 'type':
487
+				$orderby = ['Price_Type.PRT_name' => $order];
488
+				break;
489
+			case 'amount':
490
+				$orderby = ['PRC_amount' => $order];
491
+				break;
492
+			default:
493
+				$orderby = ['PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order];
494
+		}
495
+
496
+		$current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
497
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
498
+
499
+		$where = [
500
+			'PRC_is_default' => 1,
501
+			'PRC_deleted'    => $trashed,
502
+		];
503
+
504
+		$offset = ($current_page - 1) * $per_page;
505
+		$limit  = [$offset, $per_page];
506
+
507
+		$search_term = $this->request->getRequestParam('s');
508
+		if ($search_term) {
509
+			$search_term = "%{$search_term}%";
510
+			$where['OR'] = [
511
+				'PRC_name'            => ['LIKE', $search_term],
512
+				'PRC_desc'            => ['LIKE', $search_term],
513
+				'PRC_amount'          => ['LIKE', $search_term],
514
+				'Price_Type.PRT_name' => ['LIKE', $search_term],
515
+			];
516
+		}
517
+
518
+		$query_params = [
519
+			$where,
520
+			'order_by' => $orderby,
521
+			'limit'    => $limit,
522
+			'group_by' => 'PRC_ID',
523
+		];
524
+
525
+		if ($count) {
526
+			return $trashed
527
+				? EEM_Price::instance()->count([$where])
528
+				: EEM_Price::instance()->count_deleted_and_undeleted([$where]);
529
+		}
530
+		return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
531
+	}
532
+
533
+
534
+	/**
535
+	 * @return void
536
+	 * @throws EE_Error
537
+	 * @throws ReflectionException
538
+	 */
539
+	protected function _edit_price_details()
540
+	{
541
+		// grab price ID
542
+		$PRC_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
543
+		// change page title based on request action
544
+		switch ($this->_req_action) {
545
+			case 'add_new_price':
546
+				$this->_admin_page_title = esc_html__('Add New Price', 'event_espresso');
547
+				break;
548
+			case 'edit_price':
549
+				$this->_admin_page_title = esc_html__('Edit Price', 'event_espresso');
550
+				break;
551
+			default:
552
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
553
+		}
554
+		// add PRC_ID to title if editing
555
+		$this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
556
+
557
+		if ($PRC_ID) {
558
+			$price                    = EEM_Price::instance()->get_one_by_ID($PRC_ID);
559
+			$additional_hidden_fields = [
560
+				'PRC_ID' => ['type' => 'hidden', 'value' => $PRC_ID],
561
+			];
562
+			$this->_set_add_edit_form_tags('update_price', $additional_hidden_fields);
563
+		} else {
564
+			$price = EEM_Price::instance()->get_new_price();
565
+			$this->_set_add_edit_form_tags('insert_price');
566
+		}
567
+
568
+		if (! $price instanceof EE_Price) {
569
+			throw new RuntimeException(
570
+				sprintf(
571
+					esc_html__(
572
+						'A valid Price could not be retrieved from the database with ID: %1$s',
573
+						'event_espresso'
574
+					),
575
+					$PRC_ID
576
+				)
577
+			);
578
+		}
579
+
580
+		$this->_template_args['PRC_ID'] = $PRC_ID;
581
+		$this->_template_args['price']  = $price;
582
+
583
+		$default_base_price = $price->type_obj() && $price->type_obj()->base_type() === 1;
584
+
585
+		$this->_template_args['default_base_price'] = $default_base_price;
586
+
587
+		// get price types
588
+		$price_types = EEM_Price_Type::instance()->get_all([['PBT_ID' => ['!=', 1]]]);
589
+		if (empty($price_types)) {
590
+			$msg = esc_html__(
591
+				'You have no price types defined. Please add a price type before adding a price.',
592
+				'event_espresso'
593
+			);
594
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
595
+			$this->display_admin_page_with_sidebar();
596
+		}
597
+		$attributes       = [];
598
+		$price_type_names = [];
599
+		$attributes[]     = 'id="PRT_ID"';
600
+		if ($default_base_price) {
601
+			$attributes[]       = 'disabled="disabled"';
602
+			$price_type_names[] = ['id' => 1, 'text' => esc_html__('Base Price', 'event_espresso')];
603
+		}
604
+		foreach ($price_types as $type) {
605
+			$price_type_names[] = ['id' => $type->ID(), 'text' => $type->name()];
606
+		}
607
+		$this->_template_args['attributes']  = implode(' ', $attributes);
608
+		$this->_template_args['price_types'] = $price_type_names;
609
+
610
+		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
611
+		$this->_template_args['admin_page_content']            = $this->_edit_price_details_meta_box();
612
+
613
+		$this->_set_publish_post_box_vars('id', $PRC_ID);
614
+		// the details template wrapper
615
+		$this->display_admin_page_with_sidebar();
616
+	}
617
+
618
+
619
+	/**
620
+	 *
621
+	 * @return string
622
+	 */
623
+	public function _edit_price_details_meta_box(): string
624
+	{
625
+		return EEH_Template::display_template(
626
+			PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php',
627
+			$this->_template_args,
628
+			true
629
+		);
630
+	}
631
+
632
+
633
+	/**
634
+	 * @return array
635
+	 * @throws EE_Error
636
+	 * @throws ReflectionException
637
+	 */
638
+	protected function set_price_column_values(): array
639
+	{
640
+		$PRC_order = 0;
641
+		$PRT_ID    = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
642
+		if ($PRT_ID) {
643
+			/** @var EE_Price_Type $price_type */
644
+			$price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
645
+			if ($price_type instanceof EE_Price_Type) {
646
+				$PRC_order = $price_type->order();
647
+			}
648
+		}
649
+		return [
650
+			'PRT_ID'         => $PRT_ID,
651
+			'PRC_amount'     => $this->request->getRequestParam('PRC_amount', 0, DataType::FLOAT),
652
+			'PRC_name'       => $this->request->getRequestParam('PRC_name'),
653
+			'PRC_desc'       => $this->request->getRequestParam('PRC_desc'),
654
+			'PRC_is_default' => 1,
655
+			'PRC_overrides'  => null,
656
+			'PRC_order'      => $PRC_order,
657
+			'PRC_deleted'    => 0,
658
+			'PRC_parent'     => 0,
659
+		];
660
+	}
661
+
662
+
663
+	/**
664
+	 * @param bool $insert - whether to insert or update
665
+	 * @return void
666
+	 * @throws EE_Error
667
+	 * @throws ReflectionException
668
+	 */
669
+	protected function _insert_or_update_price(bool $insert = false)
670
+	{
671
+		// why be so pessimistic ???  : (
672
+		$updated = 0;
673
+
674
+		$set_column_values = $this->set_price_column_values();
675
+		// is this a new Price ?
676
+		if ($insert) {
677
+			// run the insert
678
+			$PRC_ID = EEM_Price::instance()->insert($set_column_values);
679
+			if ($PRC_ID) {
680
+				// make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
681
+				$price = EEM_price::instance()->get_one_by_ID($PRC_ID);
682
+				if (
683
+					$price instanceof EE_Price
684
+					&& $price->type_obj() instanceof EE_Price_type
685
+					&& $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax
686
+				) {
687
+					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
688
+					$ticket->_add_relation_to($price, 'Price');
689
+					$ticket->save();
690
+				}
691
+				$updated = 1;
692
+			}
693
+			$action_desc = 'created';
694
+		} else {
695
+			$PRC_ID = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
696
+			// run the update
697
+			$where_cols_n_values = ['PRC_ID' => $PRC_ID];
698
+			$updated             = EEM_Price::instance()->update($set_column_values, [$where_cols_n_values]);
699
+
700
+			$price = EEM_Price::instance()->get_one_by_ID($PRC_ID);
701
+			if ($price instanceof EE_Price && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
702
+				// if this is $PRC_ID == 1,
703
+				// then we need to update the default ticket attached to this price so the TKT_price value is updated.
704
+				if ($PRC_ID === 1) {
705
+					$ticket = $price->get_first_related('Ticket');
706
+					if ($ticket) {
707
+						$ticket->set('TKT_price', $price->get('PRC_amount'));
708
+						$ticket->set('TKT_name', $price->get('PRC_name'));
709
+						$ticket->set('TKT_description', $price->get('PRC_desc'));
710
+						$ticket->save();
711
+					}
712
+				} else {
713
+					// we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type.
714
+					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
715
+					$ticket->_add_relation_to($PRC_ID, 'Price');
716
+					$ticket->save();
717
+				}
718
+			}
719
+
720
+			$action_desc = 'updated';
721
+		}
722
+
723
+		$query_args = ['action' => 'edit_price', 'id' => $PRC_ID];
724
+
725
+		$this->_redirect_after_action($updated, 'Prices', $action_desc, $query_args);
726
+	}
727
+
728
+
729
+	/**
730
+	 * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
731
+	 * @return void
732
+	 * @throws EE_Error
733
+	 */
734
+	protected function _trash_or_restore_price($trash = true)
735
+	{
736
+		$entity_model = EEM_Price::instance();
737
+		$action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
738
+		$result       = $this->trashRestoreDeleteEntities(
739
+			$entity_model,
740
+			'id',
741
+			$action,
742
+			'PRC_deleted',
743
+			[$this, 'adjustTicketRelations']
744
+		);
745
+
746
+		if ($result) {
747
+			$msg = $trash
748
+				? esc_html(
749
+					_n(
750
+						'The Price has been trashed',
751
+						'The Prices have been trashed',
752
+						$result,
753
+						'event_espresso'
754
+					)
755
+				)
756
+				: esc_html(
757
+					_n(
758
+						'The Price has been restored',
759
+						'The Prices have been restored',
760
+						$result,
761
+						'event_espresso'
762
+					)
763
+				);
764
+			EE_Error::add_success($msg);
765
+		}
766
+
767
+		$this->_redirect_after_action(
768
+			$result,
769
+			_n('Price', 'Prices', $result, 'event_espresso'),
770
+			$trash ? 'trashed' : 'restored',
771
+			['action' => 'default'],
772
+			true
773
+		);
774
+	}
775
+
776
+
777
+	/**
778
+	 * @param EEM_Base   $entity_model
779
+	 * @param int|string $entity_ID
780
+	 * @param string     $action
781
+	 * @param int        $result
782
+	 * @throws EE_Error
783
+	 * @throws ReflectionException
784
+	 * @since 4.10.30.p
785
+	 */
786
+	public function adjustTicketRelations(EEM_Base $entity_model, $entity_ID, string $action, int $result)
787
+	{
788
+		if (! $entity_ID || (float) $result < 1) {
789
+			return;
790
+		}
791
+
792
+		$entity = $entity_model->get_one_by_ID($entity_ID);
793
+		if (! $entity instanceof EE_Price || $entity->type_obj()->base_type() === EEM_Price_Type::base_type_tax) {
794
+			return;
795
+		}
796
+
797
+		// get default tickets for updating
798
+		$default_tickets = EEM_Ticket::instance()->get_all_default_tickets();
799
+		foreach ($default_tickets as $default_ticket) {
800
+			if (! $default_ticket instanceof EE_Ticket) {
801
+				continue;
802
+			}
803
+			switch ($action) {
804
+				case EE_Admin_List_Table::ACTION_DELETE:
805
+				case EE_Admin_List_Table::ACTION_TRASH:
806
+					// if trashing then remove relations to base default ticket.
807
+					$default_ticket->_remove_relation_to($entity_ID, 'Price');
808
+					break;
809
+				case EE_Admin_List_Table::ACTION_RESTORE:
810
+					// if restoring then add back to base default ticket
811
+					$default_ticket->_add_relation_to($entity_ID, 'Price');
812
+					break;
813
+			}
814
+			$default_ticket->save();
815
+		}
816
+	}
817
+
818
+
819
+	/**
820
+	 * @return void
821
+	 * @throws EE_Error
822
+	 * @throws ReflectionException
823
+	 */
824
+	protected function _delete_price()
825
+	{
826
+		$entity_model = EEM_Price::instance();
827
+		$deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
828
+		$entity       = $entity_model->item_name($deleted);
829
+		$this->_redirect_after_action($deleted, $entity, 'deleted', ['action' => 'default']);
830
+	}
831
+
832
+
833
+	/**
834
+	 * @throws EE_Error
835
+	 * @throws ReflectionException
836
+	 */
837
+	public function update_price_order()
838
+	{
839
+		// grab our row IDs
840
+		$row_ids = $this->request->getRequestParam('row_ids', '');
841
+		$row_ids = explode(',', rtrim($row_ids, ','));
842
+
843
+		$all_updated = true;
844
+		foreach ($row_ids as $i => $row_id) {
845
+			// Update the prices when re-ordering
846
+			$fields_n_values = ['PRC_order' => $i + 1];
847
+			$query_params    = [['PRC_ID' => absint($row_id)]];
848
+			// any failure will toggle $all_updated to false
849
+			$all_updated = $row_id && EEM_Price::instance()->update($fields_n_values, $query_params) !== false
850
+				? $all_updated
851
+				: false;
852
+		}
853
+		$success = $all_updated ? esc_html__('Price order was updated successfully.', 'event_espresso') : false;
854
+		$errors  = ! $all_updated ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso')
855
+			: false;
856
+
857
+		echo wp_json_encode(['return_data' => false, 'success' => $success, 'errors' => $errors]);
858
+		die();
859
+	}
860
+
861
+
862
+	/******************************************************************************************************************
863 863
      ***********************************************  TICKET PRICE TYPES  *********************************************
864 864
      ******************************************************************************************************************/
865 865
 
866 866
 
867
-    /**
868
-     * generates HTML for main Prices Admin page
869
-     *
870
-     * @return void
871
-     * @throws EE_Error
872
-     */
873
-    protected function _price_types_overview_list_table()
874
-    {
875
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
876
-            'add_new_price_type',
877
-            'add_type',
878
-            [],
879
-            'add-new-h2'
880
-        );
881
-        $this->_admin_page_title .= $this->_learn_more_about_pricing_link();
882
-        $this->_search_btn_label = esc_html__('Price Types', 'event_espresso');
883
-        $this->display_admin_list_table_page_with_sidebar();
884
-    }
885
-
886
-
887
-    /**
888
-     * retrieve data for Price Types List table
889
-     *
890
-     * @param int  $per_page how many prices displayed per page
891
-     * @param bool $count    return the count or objects
892
-     * @param bool $trashed  whether the current view is of the trash can - eww yuck!
893
-     * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
894
-     * @throws EE_Error
895
-     * @throws ReflectionException
896
-     */
897
-    public function get_price_types_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
898
-    {
899
-        // start with an empty array
900
-        require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php');
901
-
902
-        $orderby = $this->request->getRequestParam('orderby', '');
903
-        $order   = $this->request->getRequestParam('order', 'ASC');
904
-
905
-        switch ($orderby) {
906
-            case 'name':
907
-                $orderby = ['PRT_name' => $order];
908
-                break;
909
-            default:
910
-                $orderby = ['PRT_order' => $order];
911
-        }
912
-
913
-        $current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
914
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
915
-
916
-        $offset = ($current_page - 1) * $per_page;
917
-        $limit  = [$offset, $per_page];
918
-
919
-        $where = ['PRT_deleted' => $trashed, 'PBT_ID' => ['!=', 1]];
920
-
921
-        $search_term = $this->request->getRequestParam('s');
922
-        if ($search_term) {
923
-            $where['OR'] = [
924
-                'PRT_name' => ['LIKE', "%{$search_term}%"],
925
-            ];
926
-        }
927
-        $query_params = [
928
-            $where,
929
-            'order_by' => $orderby,
930
-            'limit'    => $limit,
931
-        ];
932
-        return $count
933
-            ? EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params)
934
-            : EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
935
-    }
936
-
937
-
938
-    /**
939
-     * _edit_price_type_details
940
-     *
941
-     * @return void
942
-     * @throws EE_Error
943
-     * @throws ReflectionException
944
-     */
945
-    protected function _edit_price_type_details()
946
-    {
947
-        // grab price type ID
948
-        $PRT_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
949
-        // change page title based on request action
950
-        switch ($this->_req_action) {
951
-            case 'add_new_price_type':
952
-                $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso');
953
-                break;
954
-            case 'edit_price_type':
955
-                $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso');
956
-                break;
957
-            default:
958
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
959
-        }
960
-        // add PRT_ID to title if editing
961
-        $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
962
-
963
-        if ($PRT_ID) {
964
-            $price_type               = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
965
-            $additional_hidden_fields = ['PRT_ID' => ['type' => 'hidden', 'value' => $PRT_ID]];
966
-            $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields);
967
-        } else {
968
-            $price_type = EEM_Price_Type::instance()->get_new_price_type();
969
-            $this->_set_add_edit_form_tags('insert_price_type');
970
-        }
971
-
972
-        if (! $price_type instanceof EE_Price_Type) {
973
-            throw new RuntimeException(
974
-                sprintf(
975
-                    esc_html__(
976
-                        'A valid Price Type could not be retrieved from the database with ID: %1$s',
977
-                        'event_espresso'
978
-                    ),
979
-                    $PRT_ID
980
-                )
981
-            );
982
-        }
983
-
984
-        $this->_template_args['PRT_ID']     = $PRT_ID;
985
-        $this->_template_args['price_type'] = $price_type;
986
-
987
-        $base_types    = EEM_Price_Type::instance()->get_base_types();
988
-        $select_values = [];
989
-        foreach ($base_types as $ref => $text) {
990
-            if ($ref == EEM_Price_Type::base_type_base_price) {
991
-                // do not allow creation of base_type_base_prices because that's a system only base type.
992
-                continue;
993
-            }
994
-            $select_values[] = ['id' => $ref, 'text' => $text];
995
-        }
996
-
997
-        $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input(
998
-            'base_type',
999
-            $select_values,
1000
-            $price_type->base_type(),
1001
-            'id="price-type-base-type-slct"'
1002
-        );
1003
-
1004
-        $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1005
-        $this->_template_args['admin_page_content']            = $this->_edit_price_type_details_meta_box();
1006
-
1007
-        $redirect_URL = add_query_arg(['action' => 'price_types'], $this->_admin_base_url);
1008
-        $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL);
1009
-        // the details template wrapper
1010
-        $this->display_admin_page_with_sidebar();
1011
-    }
1012
-
1013
-
1014
-    /**
1015
-     * _edit_price_type_details_meta_box
1016
-     *
1017
-     * @return string
1018
-     */
1019
-    public function _edit_price_type_details_meta_box(): string
1020
-    {
1021
-        return EEH_Template::display_template(
1022
-            PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php',
1023
-            $this->_template_args,
1024
-            true
1025
-        );
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     * @return array
1031
-     */
1032
-    protected function set_price_type_column_values(): array
1033
-    {
1034
-        $base_type  = $this->request->getRequestParam(
1035
-            'base_type',
1036
-            EEM_Price_Type::base_type_base_price,
1037
-            DataType::INTEGER
1038
-        );
1039
-        $is_percent = $this->request->getRequestParam('PRT_is_percent', 0, DataType::INTEGER);
1040
-        $order      = $this->request->getRequestParam('PRT_order', 0, DataType::INTEGER);
1041
-        switch ($base_type) {
1042
-            case EEM_Price_Type::base_type_base_price:
1043
-                $is_percent = 0;
1044
-                $order      = 0;
1045
-                break;
1046
-
1047
-            case EEM_Price_Type::base_type_discount:
1048
-            case EEM_Price_Type::base_type_surcharge:
1049
-                break;
1050
-
1051
-            case EEM_Price_Type::base_type_tax:
1052
-                $is_percent = 1;
1053
-                break;
1054
-        }
1055
-
1056
-        return [
1057
-            'PBT_ID'         => $base_type,
1058
-            'PRT_name'       => $this->request->getRequestParam('PRT_name', ''),
1059
-            'PRT_is_percent' => $is_percent,
1060
-            'PRT_order'      => $order,
1061
-            'PRT_deleted'    => 0,
1062
-        ];
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * @param bool $new_price_type - whether to insert or update
1068
-     * @return void
1069
-     * @throws EE_Error
1070
-     * @throws ReflectionException
1071
-     */
1072
-    protected function _insert_or_update_price_type(bool $new_price_type = false)
1073
-    {
1074
-        // why be so pessimistic ???  : (
1075
-        $success = 0;
1076
-
1077
-        $set_column_values = $this->set_price_type_column_values();
1078
-        // is this a new Price ?
1079
-        if ($new_price_type) {
1080
-            // run the insert
1081
-            if ($PRT_ID = EEM_Price_Type::instance()->insert($set_column_values)) {
1082
-                $success = 1;
1083
-            }
1084
-            $action_desc = 'created';
1085
-        } else {
1086
-            $PRT_ID = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
1087
-            // run the update
1088
-            $where_cols_n_values = ['PRT_ID' => $PRT_ID];
1089
-            if (EEM_Price_Type::instance()->update($set_column_values, [$where_cols_n_values])) {
1090
-                $success = 1;
1091
-            }
1092
-            $action_desc = 'updated';
1093
-        }
1094
-
1095
-        $query_args = ['action' => 'edit_price_type', 'id' => $PRT_ID];
1096
-        $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args);
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
1102
-     * @return void
1103
-     * @throws EE_Error
1104
-     * @throws ReflectionException
1105
-     */
1106
-    protected function _trash_or_restore_price_type(bool $trash = true)
1107
-    {
1108
-        $entity_model = EEM_Price_Type::instance();
1109
-        $action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
1110
-        $success      = $this->trashRestoreDeleteEntities($entity_model, 'id', $action, 'PRT_deleted');
1111
-        if ($success) {
1112
-            $msg = $trash
1113
-                ? esc_html(
1114
-                    _n(
1115
-                        'The Price Type has been trashed',
1116
-                        'The Price Types have been trashed',
1117
-                        $success,
1118
-                        'event_espresso'
1119
-                    )
1120
-                )
1121
-                : esc_html(
1122
-                    _n(
1123
-                        'The Price Type has been restored',
1124
-                        'The Price Types have been restored',
1125
-                        $success,
1126
-                        'event_espresso'
1127
-                    )
1128
-                );
1129
-            EE_Error::add_success($msg);
1130
-        }
1131
-        $this->_redirect_after_action('', '', '', ['action' => 'price_types'], true);
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * @return void
1137
-     * @throws EE_Error
1138
-     * @throws ReflectionException
1139
-     */
1140
-    protected function _delete_price_type()
1141
-    {
1142
-        $entity_model = EEM_Price_Type::instance();
1143
-        $deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
1144
-        $this->_redirect_after_action(
1145
-            $deleted,
1146
-            $entity_model->item_name($deleted),
1147
-            'deleted',
1148
-            ['action' => 'price_types']
1149
-        );
1150
-    }
1151
-
1152
-
1153
-    /**
1154
-     * @return string
1155
-     */
1156
-    protected function _learn_more_about_pricing_link(): string
1157
-    {
1158
-        return '
867
+	/**
868
+	 * generates HTML for main Prices Admin page
869
+	 *
870
+	 * @return void
871
+	 * @throws EE_Error
872
+	 */
873
+	protected function _price_types_overview_list_table()
874
+	{
875
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
876
+			'add_new_price_type',
877
+			'add_type',
878
+			[],
879
+			'add-new-h2'
880
+		);
881
+		$this->_admin_page_title .= $this->_learn_more_about_pricing_link();
882
+		$this->_search_btn_label = esc_html__('Price Types', 'event_espresso');
883
+		$this->display_admin_list_table_page_with_sidebar();
884
+	}
885
+
886
+
887
+	/**
888
+	 * retrieve data for Price Types List table
889
+	 *
890
+	 * @param int  $per_page how many prices displayed per page
891
+	 * @param bool $count    return the count or objects
892
+	 * @param bool $trashed  whether the current view is of the trash can - eww yuck!
893
+	 * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
894
+	 * @throws EE_Error
895
+	 * @throws ReflectionException
896
+	 */
897
+	public function get_price_types_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
898
+	{
899
+		// start with an empty array
900
+		require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php');
901
+
902
+		$orderby = $this->request->getRequestParam('orderby', '');
903
+		$order   = $this->request->getRequestParam('order', 'ASC');
904
+
905
+		switch ($orderby) {
906
+			case 'name':
907
+				$orderby = ['PRT_name' => $order];
908
+				break;
909
+			default:
910
+				$orderby = ['PRT_order' => $order];
911
+		}
912
+
913
+		$current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
914
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
915
+
916
+		$offset = ($current_page - 1) * $per_page;
917
+		$limit  = [$offset, $per_page];
918
+
919
+		$where = ['PRT_deleted' => $trashed, 'PBT_ID' => ['!=', 1]];
920
+
921
+		$search_term = $this->request->getRequestParam('s');
922
+		if ($search_term) {
923
+			$where['OR'] = [
924
+				'PRT_name' => ['LIKE', "%{$search_term}%"],
925
+			];
926
+		}
927
+		$query_params = [
928
+			$where,
929
+			'order_by' => $orderby,
930
+			'limit'    => $limit,
931
+		];
932
+		return $count
933
+			? EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params)
934
+			: EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
935
+	}
936
+
937
+
938
+	/**
939
+	 * _edit_price_type_details
940
+	 *
941
+	 * @return void
942
+	 * @throws EE_Error
943
+	 * @throws ReflectionException
944
+	 */
945
+	protected function _edit_price_type_details()
946
+	{
947
+		// grab price type ID
948
+		$PRT_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
949
+		// change page title based on request action
950
+		switch ($this->_req_action) {
951
+			case 'add_new_price_type':
952
+				$this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso');
953
+				break;
954
+			case 'edit_price_type':
955
+				$this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso');
956
+				break;
957
+			default:
958
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
959
+		}
960
+		// add PRT_ID to title if editing
961
+		$this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
962
+
963
+		if ($PRT_ID) {
964
+			$price_type               = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
965
+			$additional_hidden_fields = ['PRT_ID' => ['type' => 'hidden', 'value' => $PRT_ID]];
966
+			$this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields);
967
+		} else {
968
+			$price_type = EEM_Price_Type::instance()->get_new_price_type();
969
+			$this->_set_add_edit_form_tags('insert_price_type');
970
+		}
971
+
972
+		if (! $price_type instanceof EE_Price_Type) {
973
+			throw new RuntimeException(
974
+				sprintf(
975
+					esc_html__(
976
+						'A valid Price Type could not be retrieved from the database with ID: %1$s',
977
+						'event_espresso'
978
+					),
979
+					$PRT_ID
980
+				)
981
+			);
982
+		}
983
+
984
+		$this->_template_args['PRT_ID']     = $PRT_ID;
985
+		$this->_template_args['price_type'] = $price_type;
986
+
987
+		$base_types    = EEM_Price_Type::instance()->get_base_types();
988
+		$select_values = [];
989
+		foreach ($base_types as $ref => $text) {
990
+			if ($ref == EEM_Price_Type::base_type_base_price) {
991
+				// do not allow creation of base_type_base_prices because that's a system only base type.
992
+				continue;
993
+			}
994
+			$select_values[] = ['id' => $ref, 'text' => $text];
995
+		}
996
+
997
+		$this->_template_args['base_type_select'] = EEH_Form_Fields::select_input(
998
+			'base_type',
999
+			$select_values,
1000
+			$price_type->base_type(),
1001
+			'id="price-type-base-type-slct"'
1002
+		);
1003
+
1004
+		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1005
+		$this->_template_args['admin_page_content']            = $this->_edit_price_type_details_meta_box();
1006
+
1007
+		$redirect_URL = add_query_arg(['action' => 'price_types'], $this->_admin_base_url);
1008
+		$this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL);
1009
+		// the details template wrapper
1010
+		$this->display_admin_page_with_sidebar();
1011
+	}
1012
+
1013
+
1014
+	/**
1015
+	 * _edit_price_type_details_meta_box
1016
+	 *
1017
+	 * @return string
1018
+	 */
1019
+	public function _edit_price_type_details_meta_box(): string
1020
+	{
1021
+		return EEH_Template::display_template(
1022
+			PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php',
1023
+			$this->_template_args,
1024
+			true
1025
+		);
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 * @return array
1031
+	 */
1032
+	protected function set_price_type_column_values(): array
1033
+	{
1034
+		$base_type  = $this->request->getRequestParam(
1035
+			'base_type',
1036
+			EEM_Price_Type::base_type_base_price,
1037
+			DataType::INTEGER
1038
+		);
1039
+		$is_percent = $this->request->getRequestParam('PRT_is_percent', 0, DataType::INTEGER);
1040
+		$order      = $this->request->getRequestParam('PRT_order', 0, DataType::INTEGER);
1041
+		switch ($base_type) {
1042
+			case EEM_Price_Type::base_type_base_price:
1043
+				$is_percent = 0;
1044
+				$order      = 0;
1045
+				break;
1046
+
1047
+			case EEM_Price_Type::base_type_discount:
1048
+			case EEM_Price_Type::base_type_surcharge:
1049
+				break;
1050
+
1051
+			case EEM_Price_Type::base_type_tax:
1052
+				$is_percent = 1;
1053
+				break;
1054
+		}
1055
+
1056
+		return [
1057
+			'PBT_ID'         => $base_type,
1058
+			'PRT_name'       => $this->request->getRequestParam('PRT_name', ''),
1059
+			'PRT_is_percent' => $is_percent,
1060
+			'PRT_order'      => $order,
1061
+			'PRT_deleted'    => 0,
1062
+		];
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * @param bool $new_price_type - whether to insert or update
1068
+	 * @return void
1069
+	 * @throws EE_Error
1070
+	 * @throws ReflectionException
1071
+	 */
1072
+	protected function _insert_or_update_price_type(bool $new_price_type = false)
1073
+	{
1074
+		// why be so pessimistic ???  : (
1075
+		$success = 0;
1076
+
1077
+		$set_column_values = $this->set_price_type_column_values();
1078
+		// is this a new Price ?
1079
+		if ($new_price_type) {
1080
+			// run the insert
1081
+			if ($PRT_ID = EEM_Price_Type::instance()->insert($set_column_values)) {
1082
+				$success = 1;
1083
+			}
1084
+			$action_desc = 'created';
1085
+		} else {
1086
+			$PRT_ID = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
1087
+			// run the update
1088
+			$where_cols_n_values = ['PRT_ID' => $PRT_ID];
1089
+			if (EEM_Price_Type::instance()->update($set_column_values, [$where_cols_n_values])) {
1090
+				$success = 1;
1091
+			}
1092
+			$action_desc = 'updated';
1093
+		}
1094
+
1095
+		$query_args = ['action' => 'edit_price_type', 'id' => $PRT_ID];
1096
+		$this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args);
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
1102
+	 * @return void
1103
+	 * @throws EE_Error
1104
+	 * @throws ReflectionException
1105
+	 */
1106
+	protected function _trash_or_restore_price_type(bool $trash = true)
1107
+	{
1108
+		$entity_model = EEM_Price_Type::instance();
1109
+		$action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
1110
+		$success      = $this->trashRestoreDeleteEntities($entity_model, 'id', $action, 'PRT_deleted');
1111
+		if ($success) {
1112
+			$msg = $trash
1113
+				? esc_html(
1114
+					_n(
1115
+						'The Price Type has been trashed',
1116
+						'The Price Types have been trashed',
1117
+						$success,
1118
+						'event_espresso'
1119
+					)
1120
+				)
1121
+				: esc_html(
1122
+					_n(
1123
+						'The Price Type has been restored',
1124
+						'The Price Types have been restored',
1125
+						$success,
1126
+						'event_espresso'
1127
+					)
1128
+				);
1129
+			EE_Error::add_success($msg);
1130
+		}
1131
+		$this->_redirect_after_action('', '', '', ['action' => 'price_types'], true);
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * @return void
1137
+	 * @throws EE_Error
1138
+	 * @throws ReflectionException
1139
+	 */
1140
+	protected function _delete_price_type()
1141
+	{
1142
+		$entity_model = EEM_Price_Type::instance();
1143
+		$deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
1144
+		$this->_redirect_after_action(
1145
+			$deleted,
1146
+			$entity_model->item_name($deleted),
1147
+			'deleted',
1148
+			['action' => 'price_types']
1149
+		);
1150
+	}
1151
+
1152
+
1153
+	/**
1154
+	 * @return string
1155
+	 */
1156
+	protected function _learn_more_about_pricing_link(): string
1157
+	{
1158
+		return '
1159 1159
             <a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >
1160 1160
                 ' . esc_html__('learn more about how pricing works', 'event_espresso') . '
1161 1161
             </a>';
1162
-    }
1163
-
1164
-
1165
-    /**
1166
-     * @throws EE_Error
1167
-     */
1168
-    protected function _tax_settings()
1169
-    {
1170
-        $this->_set_add_edit_form_tags('update_tax_settings');
1171
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1172
-        $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1173
-        $this->display_admin_page_with_sidebar();
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * @return EE_Form_Section_Proper
1179
-     * @throws EE_Error
1180
-     */
1181
-    protected function tax_settings_form(): EE_Form_Section_Proper
1182
-    {
1183
-        $tax_settings = EE_Config::instance()->tax_settings;
1184
-        return new EE_Form_Section_Proper(
1185
-            [
1186
-                'name'            => 'tax_settings_form',
1187
-                'html_id'         => 'tax_settings_form',
1188
-                'html_class'      => 'padding',
1189
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1190
-                'subsections'     => apply_filters(
1191
-                    'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1192
-                    [
1193
-                        'tax_settings' => new EE_Form_Section_Proper(
1194
-                            [
1195
-                                'name'            => 'tax_settings_tbl',
1196
-                                'html_id'         => 'tax_settings_tbl',
1197
-                                'html_class'      => 'form-table',
1198
-                                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1199
-                                'subsections'     => [
1200
-                                    'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1201
-                                        [
1202
-                                            'html_label_text'         => esc_html__(
1203
-                                                'Show Prices With Taxes Included?',
1204
-                                                'event_espresso'
1205
-                                            ),
1206
-                                            'html_help_text'          => esc_html__(
1207
-                                                'Indicates whether or not to display prices with the taxes included',
1208
-                                                'event_espresso'
1209
-                                            ),
1210
-                                            'default'                 => $tax_settings->prices_displayed_including_taxes
1211
-                                                                         ?? true,
1212
-                                            'display_html_label_text' => false,
1213
-                                        ]
1214
-                                    ),
1215
-                                ],
1216
-                            ]
1217
-                        ),
1218
-                    ]
1219
-                ),
1220
-            ]
1221
-        );
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * _update_tax_settings
1227
-     *
1228
-     * @return void
1229
-     * @throws EE_Error
1230
-     * @throws ReflectionException
1231
-     * @since 4.9.13
1232
-     */
1233
-    public function _update_tax_settings()
1234
-    {
1235
-        $tax_settings = EE_Config::instance()->tax_settings;
1236
-        if (! $tax_settings instanceof EE_Tax_Config) {
1237
-            $tax_settings = new EE_Tax_Config();
1238
-        }
1239
-        try {
1240
-            $tax_form = $this->tax_settings_form();
1241
-            // check for form submission
1242
-            if ($tax_form->was_submitted()) {
1243
-                // capture form data
1244
-                $tax_form->receive_form_submission();
1245
-                // validate form data
1246
-                if ($tax_form->is_valid()) {
1247
-                    // grab validated data from form
1248
-                    $valid_data = $tax_form->valid_data();
1249
-                    // set data on config
1250
-                    $tax_settings->prices_displayed_including_taxes =
1251
-                        $valid_data['tax_settings']['prices_displayed_including_taxes'];
1252
-                } else {
1253
-                    if ($tax_form->submission_error_message() !== '') {
1254
-                        EE_Error::add_error(
1255
-                            $tax_form->submission_error_message(),
1256
-                            __FILE__,
1257
-                            __FUNCTION__,
1258
-                            __LINE__
1259
-                        );
1260
-                    }
1261
-                }
1262
-            }
1263
-        } catch (EE_Error $e) {
1264
-            EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__);
1265
-        }
1266
-
1267
-        $what    = 'Tax Settings';
1268
-        $success = $this->_update_espresso_configuration(
1269
-            $what,
1270
-            $tax_settings,
1271
-            __FILE__,
1272
-            __FUNCTION__,
1273
-            __LINE__
1274
-        );
1275
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'tax_settings']);
1276
-    }
1162
+	}
1163
+
1164
+
1165
+	/**
1166
+	 * @throws EE_Error
1167
+	 */
1168
+	protected function _tax_settings()
1169
+	{
1170
+		$this->_set_add_edit_form_tags('update_tax_settings');
1171
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1172
+		$this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1173
+		$this->display_admin_page_with_sidebar();
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * @return EE_Form_Section_Proper
1179
+	 * @throws EE_Error
1180
+	 */
1181
+	protected function tax_settings_form(): EE_Form_Section_Proper
1182
+	{
1183
+		$tax_settings = EE_Config::instance()->tax_settings;
1184
+		return new EE_Form_Section_Proper(
1185
+			[
1186
+				'name'            => 'tax_settings_form',
1187
+				'html_id'         => 'tax_settings_form',
1188
+				'html_class'      => 'padding',
1189
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1190
+				'subsections'     => apply_filters(
1191
+					'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1192
+					[
1193
+						'tax_settings' => new EE_Form_Section_Proper(
1194
+							[
1195
+								'name'            => 'tax_settings_tbl',
1196
+								'html_id'         => 'tax_settings_tbl',
1197
+								'html_class'      => 'form-table',
1198
+								'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1199
+								'subsections'     => [
1200
+									'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1201
+										[
1202
+											'html_label_text'         => esc_html__(
1203
+												'Show Prices With Taxes Included?',
1204
+												'event_espresso'
1205
+											),
1206
+											'html_help_text'          => esc_html__(
1207
+												'Indicates whether or not to display prices with the taxes included',
1208
+												'event_espresso'
1209
+											),
1210
+											'default'                 => $tax_settings->prices_displayed_including_taxes
1211
+																		 ?? true,
1212
+											'display_html_label_text' => false,
1213
+										]
1214
+									),
1215
+								],
1216
+							]
1217
+						),
1218
+					]
1219
+				),
1220
+			]
1221
+		);
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * _update_tax_settings
1227
+	 *
1228
+	 * @return void
1229
+	 * @throws EE_Error
1230
+	 * @throws ReflectionException
1231
+	 * @since 4.9.13
1232
+	 */
1233
+	public function _update_tax_settings()
1234
+	{
1235
+		$tax_settings = EE_Config::instance()->tax_settings;
1236
+		if (! $tax_settings instanceof EE_Tax_Config) {
1237
+			$tax_settings = new EE_Tax_Config();
1238
+		}
1239
+		try {
1240
+			$tax_form = $this->tax_settings_form();
1241
+			// check for form submission
1242
+			if ($tax_form->was_submitted()) {
1243
+				// capture form data
1244
+				$tax_form->receive_form_submission();
1245
+				// validate form data
1246
+				if ($tax_form->is_valid()) {
1247
+					// grab validated data from form
1248
+					$valid_data = $tax_form->valid_data();
1249
+					// set data on config
1250
+					$tax_settings->prices_displayed_including_taxes =
1251
+						$valid_data['tax_settings']['prices_displayed_including_taxes'];
1252
+				} else {
1253
+					if ($tax_form->submission_error_message() !== '') {
1254
+						EE_Error::add_error(
1255
+							$tax_form->submission_error_message(),
1256
+							__FILE__,
1257
+							__FUNCTION__,
1258
+							__LINE__
1259
+						);
1260
+					}
1261
+				}
1262
+			}
1263
+		} catch (EE_Error $e) {
1264
+			EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__);
1265
+		}
1266
+
1267
+		$what    = 'Tax Settings';
1268
+		$success = $this->_update_espresso_configuration(
1269
+			$what,
1270
+			$tax_settings,
1271
+			__FILE__,
1272
+			__FUNCTION__,
1273
+			__LINE__
1274
+		);
1275
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'tax_settings']);
1276
+	}
1277 1277
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +4102 added lines, -4102 removed lines patch added patch discarded remove patch
@@ -18,4178 +18,4178 @@
 block discarded – undo
18 18
  */
19 19
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
20 20
 {
21
-    /**
22
-     * @var LoaderInterface
23
-     */
24
-    protected $loader;
21
+	/**
22
+	 * @var LoaderInterface
23
+	 */
24
+	protected $loader;
25 25
 
26
-    /**
27
-     * @var RequestInterface
28
-     */
29
-    protected $request;
26
+	/**
27
+	 * @var RequestInterface
28
+	 */
29
+	protected $request;
30 30
 
31
-    // set in _init_page_props()
32
-    public $page_slug;
31
+	// set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    // set in define_page_props()
39
-    protected $_admin_base_url;
38
+	// set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    // set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	// set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    // navtabs
52
-    protected $_nav_tabs;
51
+	// navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56 56
 
57
-    // template variables (used by templates)
58
-    protected $_template_path;
57
+	// template variables (used by templates)
58
+	protected $_template_path;
59 59
 
60
-    protected $_column_template_path;
60
+	protected $_column_template_path;
61 61
 
62
-    /**
63
-     * @var array $_template_args
64
-     */
65
-    protected $_template_args = [];
62
+	/**
63
+	 * @var array $_template_args
64
+	 */
65
+	protected $_template_args = [];
66 66
 
67
-    /**
68
-     * this will hold the list table object for a given view.
69
-     *
70
-     * @var EE_Admin_List_Table $_list_table_object
71
-     */
72
-    protected $_list_table_object;
67
+	/**
68
+	 * this will hold the list table object for a given view.
69
+	 *
70
+	 * @var EE_Admin_List_Table $_list_table_object
71
+	 */
72
+	protected $_list_table_object;
73 73
 
74
-    // bools
75
-    protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
74
+	// bools
75
+	protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
76 76
 
77
-    protected $_routing;
77
+	protected $_routing;
78 78
 
79
-    // list table args
80
-    protected $_view;
79
+	// list table args
80
+	protected $_view;
81 81
 
82
-    protected $_views;
82
+	protected $_views;
83 83
 
84 84
 
85
-    // action => method pairs used for routing incoming requests
86
-    protected $_page_routes;
85
+	// action => method pairs used for routing incoming requests
86
+	protected $_page_routes;
87 87
 
88
-    /**
89
-     * @var array $_page_config
90
-     */
91
-    protected $_page_config;
88
+	/**
89
+	 * @var array $_page_config
90
+	 */
91
+	protected $_page_config;
92 92
 
93
-    /**
94
-     * the current page route and route config
95
-     *
96
-     * @var string $_route
97
-     */
98
-    protected $_route;
93
+	/**
94
+	 * the current page route and route config
95
+	 *
96
+	 * @var string $_route
97
+	 */
98
+	protected $_route;
99 99
 
100
-    /**
101
-     * @var string $_cpt_route
102
-     */
103
-    protected $_cpt_route;
100
+	/**
101
+	 * @var string $_cpt_route
102
+	 */
103
+	protected $_cpt_route;
104 104
 
105
-    /**
106
-     * @var array $_route_config
107
-     */
108
-    protected $_route_config;
105
+	/**
106
+	 * @var array $_route_config
107
+	 */
108
+	protected $_route_config;
109 109
 
110
-    /**
111
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
112
-     * actions.
113
-     *
114
-     * @since 4.6.x
115
-     * @var array.
116
-     */
117
-    protected $_default_route_query_args;
118
-
119
-    // set via request page and action args.
120
-    protected $_current_page;
121
-
122
-    protected $_current_view;
123
-
124
-    protected $_current_page_view_url;
125
-
126
-    /**
127
-     * unprocessed value for the 'action' request param (default '')
128
-     *
129
-     * @var string
130
-     */
131
-    protected $raw_req_action = '';
132
-
133
-    /**
134
-     * unprocessed value for the 'page' request param (default '')
135
-     *
136
-     * @var string
137
-     */
138
-    protected $raw_req_page = '';
139
-
140
-    /**
141
-     * sanitized request action (and nonce)
142
-     *
143
-     * @var string
144
-     */
145
-    protected $_req_action = '';
146
-
147
-    /**
148
-     * sanitized request action nonce
149
-     *
150
-     * @var string
151
-     */
152
-    protected $_req_nonce = '';
153
-
154
-    /**
155
-     * @var string
156
-     */
157
-    protected $_search_btn_label = '';
158
-
159
-    /**
160
-     * @var string
161
-     */
162
-    protected $_search_box_callback = '';
163
-
164
-    /**
165
-     * @var WP_Screen
166
-     */
167
-    protected $_current_screen;
168
-
169
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
170
-    protected $_hook_obj;
171
-
172
-    // for holding incoming request data
173
-    protected $_req_data = [];
174
-
175
-    // yes / no array for admin form fields
176
-    protected $_yes_no_values = [];
177
-
178
-    // some default things shared by all child classes
179
-    protected $_default_espresso_metaboxes;
180
-
181
-    /**
182
-     * @var EE_Registry
183
-     */
184
-    protected $EE = null;
185
-
186
-
187
-    /**
188
-     * This is just a property that flags whether the given route is a caffeinated route or not.
189
-     *
190
-     * @var boolean
191
-     */
192
-    protected $_is_caf = false;
193
-
194
-
195
-    /**
196
-     * @Constructor
197
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
198
-     * @throws EE_Error
199
-     * @throws InvalidArgumentException
200
-     * @throws ReflectionException
201
-     * @throws InvalidDataTypeException
202
-     * @throws InvalidInterfaceException
203
-     */
204
-    public function __construct($routing = true)
205
-    {
206
-        $this->loader  = LoaderFactory::getLoader();
207
-        $this->request = $this->loader->getShared(RequestInterface::class);
208
-        $this->_routing = $routing;
209
-
210
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
211
-            $this->_is_caf = true;
212
-        }
213
-        $this->_yes_no_values = [
214
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
215
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
216
-        ];
217
-        // set the _req_data property.
218
-        $this->_req_data = $this->request->requestParams();
219
-        // set initial page props (child method)
220
-        $this->_init_page_props();
221
-        // set global defaults
222
-        $this->_set_defaults();
223
-        // set early because incoming requests could be ajax related and we need to register those hooks.
224
-        $this->_global_ajax_hooks();
225
-        $this->_ajax_hooks();
226
-        // other_page_hooks have to be early too.
227
-        $this->_do_other_page_hooks();
228
-        // set up page dependencies
229
-        $this->_before_page_setup();
230
-        $this->_page_setup();
231
-        // die();
232
-    }
233
-
234
-
235
-    /**
236
-     * _init_page_props
237
-     * Child classes use to set at least the following properties:
238
-     * $page_slug.
239
-     * $page_label.
240
-     *
241
-     * @abstract
242
-     * @return void
243
-     */
244
-    abstract protected function _init_page_props();
245
-
246
-
247
-    /**
248
-     * _ajax_hooks
249
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
250
-     * Note: within the ajax callback methods.
251
-     *
252
-     * @abstract
253
-     * @return void
254
-     */
255
-    abstract protected function _ajax_hooks();
256
-
257
-
258
-    /**
259
-     * _define_page_props
260
-     * child classes define page properties in here.  Must include at least:
261
-     * $_admin_base_url = base_url for all admin pages
262
-     * $_admin_page_title = default admin_page_title for admin pages
263
-     * $_labels = array of default labels for various automatically generated elements:
264
-     *    array(
265
-     *        'buttons' => array(
266
-     *            'add' => esc_html__('label for add new button'),
267
-     *            'edit' => esc_html__('label for edit button'),
268
-     *            'delete' => esc_html__('label for delete button')
269
-     *            )
270
-     *        )
271
-     *
272
-     * @abstract
273
-     * @return void
274
-     */
275
-    abstract protected function _define_page_props();
276
-
277
-
278
-    /**
279
-     * _set_page_routes
280
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
281
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
282
-     * have a 'default' route. Here's the format
283
-     * $this->_page_routes = array(
284
-     *        'default' => array(
285
-     *            'func' => '_default_method_handling_route',
286
-     *            'args' => array('array','of','args'),
287
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
288
-     *            ajax request, backend processing)
289
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
290
-     *            headers route after.  The string you enter here should match the defined route reference for a
291
-     *            headers sent route.
292
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
293
-     *            this route.
294
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
295
-     *            checks).
296
-     *        ),
297
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
298
-     *        handling method.
299
-     *        )
300
-     * )
301
-     *
302
-     * @abstract
303
-     * @return void
304
-     */
305
-    abstract protected function _set_page_routes();
306
-
307
-
308
-    /**
309
-     * _set_page_config
310
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
311
-     * array corresponds to the page_route for the loaded page. Format:
312
-     * $this->_page_config = array(
313
-     *        'default' => array(
314
-     *            'labels' => array(
315
-     *                'buttons' => array(
316
-     *                    'add' => esc_html__('label for adding item'),
317
-     *                    'edit' => esc_html__('label for editing item'),
318
-     *                    'delete' => esc_html__('label for deleting item')
319
-     *                ),
320
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
321
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
322
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
323
-     *            _define_page_props() method
324
-     *            'nav' => array(
325
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
326
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
327
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
328
-     *                'order' => 10, //required to indicate tab position.
329
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
330
-     *                displayed then add this parameter.
331
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
332
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
333
-     *            metaboxes set for eventespresso admin pages.
334
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
335
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
336
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
337
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
338
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
339
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
340
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
341
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
342
-     *            want to display.
343
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
344
-     *                'tab_id' => array(
345
-     *                    'title' => 'tab_title',
346
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
347
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
348
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
349
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
350
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
351
-     *                    attempt to use the callback which should match the name of a method in the class
352
-     *                    ),
353
-     *                'tab2_id' => array(
354
-     *                    'title' => 'tab2 title',
355
-     *                    'filename' => 'file_name_2'
356
-     *                    'callback' => 'callback_method_for_content',
357
-     *                 ),
358
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
359
-     *            help tab area on an admin page. @return void
360
-     *
361
-     * @abstract
362
-     */
363
-    abstract protected function _set_page_config();
364
-
365
-
366
-    /**
367
-     * _add_screen_options
368
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
369
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
370
-     * to a particular view.
371
-     *
372
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
373
-     *         see also WP_Screen object documents...
374
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
375
-     * @abstract
376
-     * @return void
377
-     */
378
-    abstract protected function _add_screen_options();
379
-
380
-
381
-    /**
382
-     * _add_feature_pointers
383
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
384
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
385
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
386
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
387
-     * extended) also see:
388
-     *
389
-     * @link   http://eamann.com/tech/wordpress-portland/
390
-     * @abstract
391
-     * @return void
392
-     */
393
-    abstract protected function _add_feature_pointers();
394
-
395
-
396
-    /**
397
-     * load_scripts_styles
398
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
399
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
400
-     * scripts/styles per view by putting them in a dynamic function in this format
401
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
402
-     *
403
-     * @abstract
404
-     * @return void
405
-     */
406
-    abstract public function load_scripts_styles();
407
-
408
-
409
-    /**
410
-     * admin_init
411
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
412
-     * all pages/views loaded by child class.
413
-     *
414
-     * @abstract
415
-     * @return void
416
-     */
417
-    abstract public function admin_init();
418
-
419
-
420
-    /**
421
-     * admin_notices
422
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
423
-     * all pages/views loaded by child class.
424
-     *
425
-     * @abstract
426
-     * @return void
427
-     */
428
-    abstract public function admin_notices();
429
-
430
-
431
-    /**
432
-     * admin_footer_scripts
433
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
434
-     * will apply to all pages/views loaded by child class.
435
-     *
436
-     * @return void
437
-     */
438
-    abstract public function admin_footer_scripts();
439
-
440
-
441
-    /**
442
-     * admin_footer
443
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
444
-     * apply to all pages/views loaded by child class.
445
-     *
446
-     * @return void
447
-     */
448
-    public function admin_footer()
449
-    {
450
-    }
451
-
452
-
453
-    /**
454
-     * _global_ajax_hooks
455
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
456
-     * Note: within the ajax callback methods.
457
-     *
458
-     * @abstract
459
-     * @return void
460
-     */
461
-    protected function _global_ajax_hooks()
462
-    {
463
-        // for lazy loading of metabox content
464
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
465
-    }
466
-
467
-
468
-    public function ajax_metabox_content()
469
-    {
470
-        $content_id  = $this->request->getRequestParam('contentid', '');
471
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
472
-        self::cached_rss_display($content_id, $content_url);
473
-        wp_die();
474
-    }
475
-
476
-
477
-    /**
478
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
479
-     *
480
-     * @return void
481
-     */
482
-    protected function _before_page_setup()
483
-    {
484
-        // default is to do nothing
485
-    }
486
-
487
-
488
-    /**
489
-     * Makes sure any things that need to be loaded early get handled.
490
-     * We also escape early here if the page requested doesn't match the object.
491
-     *
492
-     * @final
493
-     * @return void
494
-     * @throws EE_Error
495
-     * @throws InvalidArgumentException
496
-     * @throws ReflectionException
497
-     * @throws InvalidDataTypeException
498
-     * @throws InvalidInterfaceException
499
-     */
500
-    final protected function _page_setup()
501
-    {
502
-        // requires?
503
-        // admin_init stuff - global - we're setting this REALLY early
504
-        // so if EE_Admin pages have to hook into other WP pages they can.
505
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
506
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
507
-        // next verify if we need to load anything...
508
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
509
-        $this->page_folder   = strtolower(
510
-            str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
511
-        );
512
-        global $ee_menu_slugs;
513
-        $ee_menu_slugs = (array) $ee_menu_slugs;
514
-        if (
515
-            ! $this->request->isAjax()
516
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
517
-        ) {
518
-            return;
519
-        }
520
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
521
-        // we need to copy the action from the second to the first
522
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
523
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
524
-        $action     = $action !== '-1' ? $action : $action2;
525
-        $req_action = $action !== '-1' ? $action : 'default';
526
-
527
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
528
-        // then let's use the route as the action.
529
-        // This covers cases where we're coming in from a list table that isn't on the default route.
530
-        $route = $this->request->getRequestParam('route');
531
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
532
-            ? $route
533
-            : $req_action;
534
-
535
-        $this->_current_view = $this->_req_action;
536
-        $this->_req_nonce    = $this->_req_action . '_nonce';
537
-        $this->_define_page_props();
538
-        $this->_current_page_view_url = add_query_arg(
539
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
540
-            $this->_admin_base_url
541
-        );
542
-        // default things
543
-        $this->_default_espresso_metaboxes = [
544
-            '_espresso_news_post_box',
545
-            '_espresso_links_post_box',
546
-            '_espresso_ratings_request',
547
-            '_espresso_sponsors_post_box',
548
-        ];
549
-        // set page configs
550
-        $this->_set_page_routes();
551
-        $this->_set_page_config();
552
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
553
-        if ($this->request->requestParamIsSet('wp_referer')) {
554
-            $wp_referer = $this->request->getRequestParam('wp_referer');
555
-            if ($wp_referer) {
556
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
557
-            }
558
-        }
559
-        // for caffeinated and other extended functionality.
560
-        //  If there is a _extend_page_config method
561
-        // then let's run that to modify the all the various page configuration arrays
562
-        if (method_exists($this, '_extend_page_config')) {
563
-            $this->_extend_page_config();
564
-        }
565
-        // for CPT and other extended functionality.
566
-        // If there is an _extend_page_config_for_cpt
567
-        // then let's run that to modify all the various page configuration arrays.
568
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
569
-            $this->_extend_page_config_for_cpt();
570
-        }
571
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
572
-        $this->_page_routes = apply_filters(
573
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
574
-            $this->_page_routes,
575
-            $this
576
-        );
577
-        $this->_page_config = apply_filters(
578
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
579
-            $this->_page_config,
580
-            $this
581
-        );
582
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
583
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
584
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
585
-            add_action(
586
-                'AHEE__EE_Admin_Page__route_admin_request',
587
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
588
-                10,
589
-                2
590
-            );
591
-        }
592
-        // next route only if routing enabled
593
-        if ($this->_routing && ! $this->request->isAjax()) {
594
-            $this->_verify_routes();
595
-            // next let's just check user_access and kill if no access
596
-            $this->check_user_access();
597
-            if ($this->_is_UI_request) {
598
-                // admin_init stuff - global, all views for this page class, specific view
599
-                add_action('admin_init', [$this, 'admin_init'], 10);
600
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
601
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
602
-                }
603
-            } else {
604
-                // hijack regular WP loading and route admin request immediately
605
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
606
-                $this->route_admin_request();
607
-            }
608
-        }
609
-    }
610
-
611
-
612
-    /**
613
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
614
-     *
615
-     * @return void
616
-     * @throws EE_Error
617
-     */
618
-    private function _do_other_page_hooks()
619
-    {
620
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
621
-        foreach ($registered_pages as $page) {
622
-            // now let's setup the file name and class that should be present
623
-            $classname = str_replace('.class.php', '', $page);
624
-            // autoloaders should take care of loading file
625
-            if (! class_exists($classname)) {
626
-                $error_msg[] = sprintf(
627
-                    esc_html__(
628
-                        'Something went wrong with loading the %s admin hooks page.',
629
-                        'event_espresso'
630
-                    ),
631
-                    $page
632
-                );
633
-                $error_msg[] = $error_msg[0]
634
-                               . "\r\n"
635
-                               . sprintf(
636
-                                   esc_html__(
637
-                                       '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',
638
-                                       'event_espresso'
639
-                                   ),
640
-                                   $page,
641
-                                   '<br />',
642
-                                   '<strong>' . $classname . '</strong>'
643
-                               );
644
-                throw new EE_Error(implode('||', $error_msg));
645
-            }
646
-            // notice we are passing the instance of this class to the hook object.
647
-            $this->loader->getShared($classname, [$this]);
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * @throws ReflectionException
654
-     * @throws EE_Error
655
-     */
656
-    public function load_page_dependencies()
657
-    {
658
-        try {
659
-            $this->_load_page_dependencies();
660
-        } catch (EE_Error $e) {
661
-            $e->get_error();
662
-        }
663
-    }
664
-
665
-
666
-    /**
667
-     * load_page_dependencies
668
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
669
-     *
670
-     * @return void
671
-     * @throws DomainException
672
-     * @throws EE_Error
673
-     * @throws InvalidArgumentException
674
-     * @throws InvalidDataTypeException
675
-     * @throws InvalidInterfaceException
676
-     */
677
-    protected function _load_page_dependencies()
678
-    {
679
-        // let's set the current_screen and screen options to override what WP set
680
-        $this->_current_screen = get_current_screen();
681
-        // load admin_notices - global, page class, and view specific
682
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
683
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
684
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
685
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
686
-        }
687
-        // load network admin_notices - global, page class, and view specific
688
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
689
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
690
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
691
-        }
692
-        // this will save any per_page screen options if they are present
693
-        $this->_set_per_page_screen_options();
694
-        // setup list table properties
695
-        $this->_set_list_table();
696
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
697
-        // However in some cases the metaboxes will need to be added within a route handling callback.
698
-        $this->_add_registered_meta_boxes();
699
-        $this->_add_screen_columns();
700
-        // add screen options - global, page child class, and view specific
701
-        $this->_add_global_screen_options();
702
-        $this->_add_screen_options();
703
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
704
-        if (method_exists($this, $add_screen_options)) {
705
-            $this->{$add_screen_options}();
706
-        }
707
-        // add help tab(s) - set via page_config and qtips.
708
-        $this->_add_help_tabs();
709
-        $this->_add_qtips();
710
-        // add feature_pointers - global, page child class, and view specific
711
-        $this->_add_feature_pointers();
712
-        $this->_add_global_feature_pointers();
713
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
714
-        if (method_exists($this, $add_feature_pointer)) {
715
-            $this->{$add_feature_pointer}();
716
-        }
717
-        // enqueue scripts/styles - global, page class, and view specific
718
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
719
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
720
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
721
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
722
-        }
723
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
724
-        // admin_print_footer_scripts - global, page child class, and view specific.
725
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
726
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
727
-        // is a good use case. Notice the late priority we're giving these
728
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
729
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
730
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
731
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
732
-        }
733
-        // admin footer scripts
734
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
735
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
736
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
737
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
738
-        }
739
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
740
-        // targeted hook
741
-        do_action(
742
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
743
-        );
744
-    }
745
-
746
-
747
-    /**
748
-     * _set_defaults
749
-     * This sets some global defaults for class properties.
750
-     */
751
-    private function _set_defaults()
752
-    {
753
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
754
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
755
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
756
-        $this->_page_config          = $this->_default_route_query_args = [];
757
-        $this->_default_nav_tab_name = 'overview';
758
-        // init template args
759
-        $this->_template_args = [
760
-            'admin_page_header'  => '',
761
-            'admin_page_content' => '',
762
-            'post_body_content'  => '',
763
-            'before_list_table'  => '',
764
-            'after_list_table'   => '',
765
-        ];
766
-    }
767
-
768
-
769
-    /**
770
-     * route_admin_request
771
-     *
772
-     * @return void
773
-     * @throws InvalidArgumentException
774
-     * @throws InvalidInterfaceException
775
-     * @throws InvalidDataTypeException
776
-     * @throws EE_Error
777
-     * @throws ReflectionException
778
-     * @see    _route_admin_request()
779
-     */
780
-    public function route_admin_request()
781
-    {
782
-        try {
783
-            $this->_route_admin_request();
784
-        } catch (EE_Error $e) {
785
-            $e->get_error();
786
-        }
787
-    }
788
-
789
-
790
-    public function set_wp_page_slug($wp_page_slug)
791
-    {
792
-        $this->_wp_page_slug = $wp_page_slug;
793
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
794
-        if (is_network_admin()) {
795
-            $this->_wp_page_slug .= '-network';
796
-        }
797
-    }
798
-
799
-
800
-    /**
801
-     * _verify_routes
802
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
803
-     * we know if we need to drop out.
804
-     *
805
-     * @return bool
806
-     * @throws EE_Error
807
-     */
808
-    protected function _verify_routes()
809
-    {
810
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
811
-        if (! $this->_current_page && ! $this->request->isAjax()) {
812
-            return false;
813
-        }
814
-        $this->_route = false;
815
-        // check that the page_routes array is not empty
816
-        if (empty($this->_page_routes)) {
817
-            // user error msg
818
-            $error_msg = sprintf(
819
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
820
-                $this->_admin_page_title
821
-            );
822
-            // developer error msg
823
-            $error_msg .= '||' . $error_msg
824
-                          . esc_html__(
825
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
826
-                              'event_espresso'
827
-                          );
828
-            throw new EE_Error($error_msg);
829
-        }
830
-        // and that the requested page route exists
831
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
832
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
833
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
834
-                ? $this->_page_config[ $this->_req_action ]
835
-                : [];
836
-        } else {
837
-            // user error msg
838
-            $error_msg = sprintf(
839
-                esc_html__(
840
-                    'The requested page route does not exist for the %s admin page.',
841
-                    'event_espresso'
842
-                ),
843
-                $this->_admin_page_title
844
-            );
845
-            // developer error msg
846
-            $error_msg .= '||' . $error_msg
847
-                          . sprintf(
848
-                              esc_html__(
849
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
850
-                                  'event_espresso'
851
-                              ),
852
-                              $this->_req_action
853
-                          );
854
-            throw new EE_Error($error_msg);
855
-        }
856
-        // and that a default route exists
857
-        if (! array_key_exists('default', $this->_page_routes)) {
858
-            // user error msg
859
-            $error_msg = sprintf(
860
-                esc_html__(
861
-                    'A default page route has not been set for the % admin page.',
862
-                    'event_espresso'
863
-                ),
864
-                $this->_admin_page_title
865
-            );
866
-            // developer error msg
867
-            $error_msg .= '||' . $error_msg
868
-                          . esc_html__(
869
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
870
-                              'event_espresso'
871
-                          );
872
-            throw new EE_Error($error_msg);
873
-        }
874
-        // first lets' catch if the UI request has EVER been set.
875
-        if ($this->_is_UI_request === null) {
876
-            // lets set if this is a UI request or not.
877
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
878
-            // wait a minute... we might have a noheader in the route array
879
-            $this->_is_UI_request = ! (
880
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
881
-            )
882
-                ? $this->_is_UI_request
883
-                : false;
884
-        }
885
-        $this->_set_current_labels();
886
-        return true;
887
-    }
888
-
889
-
890
-    /**
891
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
892
-     *
893
-     * @param string $route the route name we're verifying
894
-     * @return bool we'll throw an exception if this isn't a valid route.
895
-     * @throws EE_Error
896
-     */
897
-    protected function _verify_route($route)
898
-    {
899
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
900
-            return true;
901
-        }
902
-        // user error msg
903
-        $error_msg = sprintf(
904
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
905
-            $this->_admin_page_title
906
-        );
907
-        // developer error msg
908
-        $error_msg .= '||' . $error_msg
909
-                      . sprintf(
910
-                          esc_html__(
911
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
912
-                              'event_espresso'
913
-                          ),
914
-                          $route
915
-                      );
916
-        throw new EE_Error($error_msg);
917
-    }
918
-
919
-
920
-    /**
921
-     * perform nonce verification
922
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
923
-     * using this method (and save retyping!)
924
-     *
925
-     * @param string $nonce     The nonce sent
926
-     * @param string $nonce_ref The nonce reference string (name0)
927
-     * @return void
928
-     * @throws EE_Error
929
-     */
930
-    protected function _verify_nonce($nonce, $nonce_ref)
931
-    {
932
-        // verify nonce against expected value
933
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
934
-            // these are not the droids you are looking for !!!
935
-            $msg = sprintf(
936
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
937
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
938
-                '</a>'
939
-            );
940
-            if (WP_DEBUG) {
941
-                $msg .= "\n  ";
942
-                $msg .= sprintf(
943
-                    esc_html__(
944
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
945
-                        'event_espresso'
946
-                    ),
947
-                    __CLASS__
948
-                );
949
-            }
950
-            if (! $this->request->isAjax()) {
951
-                wp_die($msg);
952
-            }
953
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
954
-            $this->_return_json();
955
-        }
956
-    }
957
-
958
-
959
-    /**
960
-     * _route_admin_request()
961
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
962
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
963
-     * in the page routes and then will try to load the corresponding method.
964
-     *
965
-     * @return void
966
-     * @throws EE_Error
967
-     * @throws InvalidArgumentException
968
-     * @throws InvalidDataTypeException
969
-     * @throws InvalidInterfaceException
970
-     * @throws ReflectionException
971
-     */
972
-    protected function _route_admin_request()
973
-    {
974
-        if (! $this->_is_UI_request) {
975
-            $this->_verify_routes();
976
-        }
977
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
978
-        if ($this->_req_action !== 'default' && $nonce_check) {
979
-            // set nonce from post data
980
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
981
-            $this->_verify_nonce($nonce, $this->_req_nonce);
982
-        }
983
-        // set the nav_tabs array but ONLY if this is  UI_request
984
-        if ($this->_is_UI_request) {
985
-            $this->_set_nav_tabs();
986
-        }
987
-        // grab callback function
988
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
989
-        // check if callback has args
990
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
991
-        $error_msg = '';
992
-        // action right before calling route
993
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
994
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
995
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
996
-        }
997
-        // right before calling the route, let's clean the _wp_http_referer
998
-        $this->request->unSetRequestParam('_wp_http_referer');
999
-        $this->request->unSetServerParam('_wp_http_referer');
1000
-        $cleaner_request_uri = remove_query_arg(
1001
-            '_wp_http_referer',
1002
-            wp_unslash($this->request->getServerParam('REQUEST_URI'))
1003
-        );
1004
-        $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri);
1005
-        $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri);
1006
-        if (! empty($func)) {
1007
-            if (is_array($func)) {
1008
-                [$class, $method] = $func;
1009
-            } elseif (strpos($func, '::') !== false) {
1010
-                [$class, $method] = explode('::', $func);
1011
-            } else {
1012
-                $class  = $this;
1013
-                $method = $func;
1014
-            }
1015
-            if (! (is_object($class) && $class === $this)) {
1016
-                // send along this admin page object for access by addons.
1017
-                $args['admin_page_object'] = $this;
1018
-            }
1019
-            if (
1020
-                // is it a method on a class that doesn't work?
1021
-                (
1022
-                    (
1023
-                        method_exists($class, $method)
1024
-                        && call_user_func_array([$class, $method], $args) === false
1025
-                    )
1026
-                    && (
1027
-                        // is it a standalone function that doesn't work?
1028
-                        function_exists($method)
1029
-                        && call_user_func_array(
1030
-                            $func,
1031
-                            array_merge(['admin_page_object' => $this], $args)
1032
-                        ) === false
1033
-                    )
1034
-                )
1035
-                || (
1036
-                    // is it neither a class method NOR a standalone function?
1037
-                    ! method_exists($class, $method)
1038
-                    && ! function_exists($method)
1039
-                )
1040
-            ) {
1041
-                // user error msg
1042
-                $error_msg = esc_html__(
1043
-                    'An error occurred. The  requested page route could not be found.',
1044
-                    'event_espresso'
1045
-                );
1046
-                // developer error msg
1047
-                $error_msg .= '||';
1048
-                $error_msg .= sprintf(
1049
-                    esc_html__(
1050
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1051
-                        'event_espresso'
1052
-                    ),
1053
-                    $method
1054
-                );
1055
-            }
1056
-            if (! empty($error_msg)) {
1057
-                throw new EE_Error($error_msg);
1058
-            }
1059
-        }
1060
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1061
-        // then we need to reset the routing properties to the new route.
1062
-        // 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.
1063
-        if (
1064
-            $this->_is_UI_request === false
1065
-            && is_array($this->_route)
1066
-            && ! empty($this->_route['headers_sent_route'])
1067
-        ) {
1068
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1069
-        }
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     * This method just allows the resetting of page properties in the case where a no headers
1075
-     * route redirects to a headers route in its route config.
1076
-     *
1077
-     * @param string $new_route New (non header) route to redirect to.
1078
-     * @return   void
1079
-     * @throws ReflectionException
1080
-     * @throws InvalidArgumentException
1081
-     * @throws InvalidInterfaceException
1082
-     * @throws InvalidDataTypeException
1083
-     * @throws EE_Error
1084
-     * @since   4.3.0
1085
-     */
1086
-    protected function _reset_routing_properties($new_route)
1087
-    {
1088
-        $this->_is_UI_request = true;
1089
-        // now we set the current route to whatever the headers_sent_route is set at
1090
-        $this->request->setRequestParam('action', $new_route);
1091
-        // rerun page setup
1092
-        $this->_page_setup();
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * _add_query_arg
1098
-     * adds nonce to array of arguments then calls WP add_query_arg function
1099
-     *(internally just uses EEH_URL's function with the same name)
1100
-     *
1101
-     * @param array  $args
1102
-     * @param string $url
1103
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1104
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1105
-     *                                        Example usage: If the current page is:
1106
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1107
-     *                                        &action=default&event_id=20&month_range=March%202015
1108
-     *                                        &_wpnonce=5467821
1109
-     *                                        and you call:
1110
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1111
-     *                                        array(
1112
-     *                                        'action' => 'resend_something',
1113
-     *                                        'page=>espresso_registrations'
1114
-     *                                        ),
1115
-     *                                        $some_url,
1116
-     *                                        true
1117
-     *                                        );
1118
-     *                                        It will produce a url in this structure:
1119
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1120
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1121
-     *                                        month_range]=March%202015
1122
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1123
-     * @return string
1124
-     */
1125
-    public static function add_query_args_and_nonce(
1126
-        $args = [],
1127
-        $url = false,
1128
-        $sticky = false,
1129
-        $exclude_nonce = false
1130
-    ) {
1131
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1132
-        if ($sticky) {
1133
-            /** @var RequestInterface $request */
1134
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1135
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1136
-            foreach ($request->requestParams() as $key => $value) {
1137
-                // do not add nonces
1138
-                if (strpos($key, 'nonce') !== false) {
1139
-                    continue;
1140
-                }
1141
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1142
-            }
1143
-        }
1144
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1145
-    }
1146
-
1147
-
1148
-    /**
1149
-     * This returns a generated link that will load the related help tab.
1150
-     *
1151
-     * @param string $help_tab_id the id for the connected help tab
1152
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1153
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1154
-     * @return string              generated link
1155
-     * @uses EEH_Template::get_help_tab_link()
1156
-     */
1157
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1158
-    {
1159
-        return EEH_Template::get_help_tab_link(
1160
-            $help_tab_id,
1161
-            $this->page_slug,
1162
-            $this->_req_action,
1163
-            $icon_style,
1164
-            $help_text
1165
-        );
1166
-    }
1167
-
1168
-
1169
-    /**
1170
-     * _add_help_tabs
1171
-     * Note child classes define their help tabs within the page_config array.
1172
-     *
1173
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1174
-     * @return void
1175
-     * @throws DomainException
1176
-     * @throws EE_Error
1177
-     */
1178
-    protected function _add_help_tabs()
1179
-    {
1180
-        if (isset($this->_page_config[ $this->_req_action ])) {
1181
-            $config = $this->_page_config[ $this->_req_action ];
1182
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1183
-            if (is_array($config) && isset($config['help_sidebar'])) {
1184
-                // check that the callback given is valid
1185
-                if (! method_exists($this, $config['help_sidebar'])) {
1186
-                    throw new EE_Error(
1187
-                        sprintf(
1188
-                            esc_html__(
1189
-                                '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',
1190
-                                'event_espresso'
1191
-                            ),
1192
-                            $config['help_sidebar'],
1193
-                            get_class($this)
1194
-                        )
1195
-                    );
1196
-                }
1197
-                $content = apply_filters(
1198
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1199
-                    $this->{$config['help_sidebar']}()
1200
-                );
1201
-                $this->_current_screen->set_help_sidebar($content);
1202
-            }
1203
-            if (! isset($config['help_tabs'])) {
1204
-                return;
1205
-            } //no help tabs for this route
1206
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1207
-                // we're here so there ARE help tabs!
1208
-                // make sure we've got what we need
1209
-                if (! isset($cfg['title'])) {
1210
-                    throw new EE_Error(
1211
-                        esc_html__(
1212
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1213
-                            'event_espresso'
1214
-                        )
1215
-                    );
1216
-                }
1217
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1218
-                    throw new EE_Error(
1219
-                        esc_html__(
1220
-                            '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',
1221
-                            'event_espresso'
1222
-                        )
1223
-                    );
1224
-                }
1225
-                // first priority goes to content.
1226
-                if (! empty($cfg['content'])) {
1227
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1228
-                    // second priority goes to filename
1229
-                } elseif (! empty($cfg['filename'])) {
1230
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1231
-                    // 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)
1232
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1233
-                                                             . basename($this->_get_dir())
1234
-                                                             . '/help_tabs/'
1235
-                                                             . $cfg['filename']
1236
-                                                             . '.help_tab.php' : $file_path;
1237
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1238
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1239
-                        EE_Error::add_error(
1240
-                            sprintf(
1241
-                                esc_html__(
1242
-                                    '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',
1243
-                                    'event_espresso'
1244
-                                ),
1245
-                                $tab_id,
1246
-                                key($config),
1247
-                                $file_path
1248
-                            ),
1249
-                            __FILE__,
1250
-                            __FUNCTION__,
1251
-                            __LINE__
1252
-                        );
1253
-                        return;
1254
-                    }
1255
-                    $template_args['admin_page_obj'] = $this;
1256
-                    $content                         = EEH_Template::display_template(
1257
-                        $file_path,
1258
-                        $template_args,
1259
-                        true
1260
-                    );
1261
-                } else {
1262
-                    $content = '';
1263
-                }
1264
-                // check if callback is valid
1265
-                if (
1266
-                    empty($content)
1267
-                    && (
1268
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1269
-                    )
1270
-                ) {
1271
-                    EE_Error::add_error(
1272
-                        sprintf(
1273
-                            esc_html__(
1274
-                                '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.',
1275
-                                'event_espresso'
1276
-                            ),
1277
-                            $cfg['title']
1278
-                        ),
1279
-                        __FILE__,
1280
-                        __FUNCTION__,
1281
-                        __LINE__
1282
-                    );
1283
-                    return;
1284
-                }
1285
-                // setup config array for help tab method
1286
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1287
-                $_ht = [
1288
-                    'id'       => $id,
1289
-                    'title'    => $cfg['title'],
1290
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1291
-                    'content'  => $content,
1292
-                ];
1293
-                $this->_current_screen->add_help_tab($_ht);
1294
-            }
1295
-        }
1296
-    }
1297
-
1298
-
1299
-    /**
1300
-     * This simply sets up any qtips that have been defined in the page config
1301
-     *
1302
-     * @return void
1303
-     */
1304
-    protected function _add_qtips()
1305
-    {
1306
-        if (isset($this->_route_config['qtips'])) {
1307
-            $qtips = (array) $this->_route_config['qtips'];
1308
-            // load qtip loader
1309
-            $path = [
1310
-                $this->_get_dir() . '/qtips/',
1311
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1312
-            ];
1313
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1314
-        }
1315
-    }
1316
-
1317
-
1318
-    /**
1319
-     * _set_nav_tabs
1320
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1321
-     * wish to add additional tabs or modify accordingly.
1322
-     *
1323
-     * @return void
1324
-     * @throws InvalidArgumentException
1325
-     * @throws InvalidInterfaceException
1326
-     * @throws InvalidDataTypeException
1327
-     */
1328
-    protected function _set_nav_tabs()
1329
-    {
1330
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1331
-        $i = 0;
1332
-        foreach ($this->_page_config as $slug => $config) {
1333
-            if (! is_array($config) || empty($config['nav'])) {
1334
-                continue;
1335
-            }
1336
-            // no nav tab for this config
1337
-            // check for persistent flag
1338
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1339
-                // nav tab is only to appear when route requested.
1340
-                continue;
1341
-            }
1342
-            if (! $this->check_user_access($slug, true)) {
1343
-                // no nav tab because current user does not have access.
1344
-                continue;
1345
-            }
1346
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1347
-            $this->_nav_tabs[ $slug ] = [
1348
-                'url'       => isset($config['nav']['url'])
1349
-                    ? $config['nav']['url']
1350
-                    : self::add_query_args_and_nonce(
1351
-                        ['action' => $slug],
1352
-                        $this->_admin_base_url
1353
-                    ),
1354
-                'link_text' => isset($config['nav']['label'])
1355
-                    ? $config['nav']['label']
1356
-                    : ucwords(
1357
-                        str_replace('_', ' ', $slug)
1358
-                    ),
1359
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1360
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1361
-            ];
1362
-            $i++;
1363
-        }
1364
-        // if $this->_nav_tabs is empty then lets set the default
1365
-        if (empty($this->_nav_tabs)) {
1366
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1367
-                'url'       => $this->_admin_base_url,
1368
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1369
-                'css_class' => 'nav-tab-active',
1370
-                'order'     => 10,
1371
-            ];
1372
-        }
1373
-        // now let's sort the tabs according to order
1374
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1375
-    }
1376
-
1377
-
1378
-    /**
1379
-     * _set_current_labels
1380
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1381
-     * property array
1382
-     *
1383
-     * @return void
1384
-     */
1385
-    private function _set_current_labels()
1386
-    {
1387
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1388
-            foreach ($this->_route_config['labels'] as $label => $text) {
1389
-                if (is_array($text)) {
1390
-                    foreach ($text as $sublabel => $subtext) {
1391
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1392
-                    }
1393
-                } else {
1394
-                    $this->_labels[ $label ] = $text;
1395
-                }
1396
-            }
1397
-        }
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     *        verifies user access for this admin page
1403
-     *
1404
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1405
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1406
-     *                               return false if verify fail.
1407
-     * @return bool
1408
-     * @throws InvalidArgumentException
1409
-     * @throws InvalidDataTypeException
1410
-     * @throws InvalidInterfaceException
1411
-     */
1412
-    public function check_user_access($route_to_check = '', $verify_only = false)
1413
-    {
1414
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1415
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1416
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1417
-                          && is_array(
1418
-                              $this->_page_routes[ $route_to_check ]
1419
-                          )
1420
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1421
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1422
-        if (empty($capability) && empty($route_to_check)) {
1423
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1424
-                : $this->_route['capability'];
1425
-        } else {
1426
-            $capability = empty($capability) ? 'manage_options' : $capability;
1427
-        }
1428
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1429
-        if (
1430
-            ! $this->request->isAjax()
1431
-            && (
1432
-                ! function_exists('is_admin')
1433
-                || ! EE_Registry::instance()->CAP->current_user_can(
1434
-                    $capability,
1435
-                    $this->page_slug
1436
-                    . '_'
1437
-                    . $route_to_check,
1438
-                    $id
1439
-                )
1440
-            )
1441
-        ) {
1442
-            if ($verify_only) {
1443
-                return false;
1444
-            }
1445
-            if (is_user_logged_in()) {
1446
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1447
-            } else {
1448
-                return false;
1449
-            }
1450
-        }
1451
-        return true;
1452
-    }
1453
-
1454
-
1455
-    /**
1456
-     * admin_init_global
1457
-     * This runs all the code that we want executed within the WP admin_init hook.
1458
-     * This method executes for ALL EE Admin pages.
1459
-     *
1460
-     * @return void
1461
-     */
1462
-    public function admin_init_global()
1463
-    {
1464
-    }
1465
-
1466
-
1467
-    /**
1468
-     * wp_loaded_global
1469
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1470
-     * EE_Admin page and will execute on every EE Admin Page load
1471
-     *
1472
-     * @return void
1473
-     */
1474
-    public function wp_loaded()
1475
-    {
1476
-    }
1477
-
1478
-
1479
-    /**
1480
-     * admin_notices
1481
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1482
-     * ALL EE_Admin pages.
1483
-     *
1484
-     * @return void
1485
-     */
1486
-    public function admin_notices_global()
1487
-    {
1488
-        $this->_display_no_javascript_warning();
1489
-        $this->_display_espresso_notices();
1490
-    }
1491
-
1492
-
1493
-    public function network_admin_notices_global()
1494
-    {
1495
-        $this->_display_no_javascript_warning();
1496
-        $this->_display_espresso_notices();
1497
-    }
1498
-
1499
-
1500
-    /**
1501
-     * admin_footer_scripts_global
1502
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1503
-     * will apply on ALL EE_Admin pages.
1504
-     *
1505
-     * @return void
1506
-     */
1507
-    public function admin_footer_scripts_global()
1508
-    {
1509
-        $this->_add_admin_page_ajax_loading_img();
1510
-        $this->_add_admin_page_overlay();
1511
-        // if metaboxes are present we need to add the nonce field
1512
-        if (
1513
-            isset($this->_route_config['metaboxes'])
1514
-            || isset($this->_route_config['list_table'])
1515
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1516
-        ) {
1517
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1518
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1519
-        }
1520
-    }
1521
-
1522
-
1523
-    /**
1524
-     * admin_footer_global
1525
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1526
-     * ALL EE_Admin Pages.
1527
-     *
1528
-     * @return void
1529
-     */
1530
-    public function admin_footer_global()
1531
-    {
1532
-        // dialog container for dialog helper
1533
-        echo '
110
+	/**
111
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
112
+	 * actions.
113
+	 *
114
+	 * @since 4.6.x
115
+	 * @var array.
116
+	 */
117
+	protected $_default_route_query_args;
118
+
119
+	// set via request page and action args.
120
+	protected $_current_page;
121
+
122
+	protected $_current_view;
123
+
124
+	protected $_current_page_view_url;
125
+
126
+	/**
127
+	 * unprocessed value for the 'action' request param (default '')
128
+	 *
129
+	 * @var string
130
+	 */
131
+	protected $raw_req_action = '';
132
+
133
+	/**
134
+	 * unprocessed value for the 'page' request param (default '')
135
+	 *
136
+	 * @var string
137
+	 */
138
+	protected $raw_req_page = '';
139
+
140
+	/**
141
+	 * sanitized request action (and nonce)
142
+	 *
143
+	 * @var string
144
+	 */
145
+	protected $_req_action = '';
146
+
147
+	/**
148
+	 * sanitized request action nonce
149
+	 *
150
+	 * @var string
151
+	 */
152
+	protected $_req_nonce = '';
153
+
154
+	/**
155
+	 * @var string
156
+	 */
157
+	protected $_search_btn_label = '';
158
+
159
+	/**
160
+	 * @var string
161
+	 */
162
+	protected $_search_box_callback = '';
163
+
164
+	/**
165
+	 * @var WP_Screen
166
+	 */
167
+	protected $_current_screen;
168
+
169
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
170
+	protected $_hook_obj;
171
+
172
+	// for holding incoming request data
173
+	protected $_req_data = [];
174
+
175
+	// yes / no array for admin form fields
176
+	protected $_yes_no_values = [];
177
+
178
+	// some default things shared by all child classes
179
+	protected $_default_espresso_metaboxes;
180
+
181
+	/**
182
+	 * @var EE_Registry
183
+	 */
184
+	protected $EE = null;
185
+
186
+
187
+	/**
188
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
189
+	 *
190
+	 * @var boolean
191
+	 */
192
+	protected $_is_caf = false;
193
+
194
+
195
+	/**
196
+	 * @Constructor
197
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
198
+	 * @throws EE_Error
199
+	 * @throws InvalidArgumentException
200
+	 * @throws ReflectionException
201
+	 * @throws InvalidDataTypeException
202
+	 * @throws InvalidInterfaceException
203
+	 */
204
+	public function __construct($routing = true)
205
+	{
206
+		$this->loader  = LoaderFactory::getLoader();
207
+		$this->request = $this->loader->getShared(RequestInterface::class);
208
+		$this->_routing = $routing;
209
+
210
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
211
+			$this->_is_caf = true;
212
+		}
213
+		$this->_yes_no_values = [
214
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
215
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
216
+		];
217
+		// set the _req_data property.
218
+		$this->_req_data = $this->request->requestParams();
219
+		// set initial page props (child method)
220
+		$this->_init_page_props();
221
+		// set global defaults
222
+		$this->_set_defaults();
223
+		// set early because incoming requests could be ajax related and we need to register those hooks.
224
+		$this->_global_ajax_hooks();
225
+		$this->_ajax_hooks();
226
+		// other_page_hooks have to be early too.
227
+		$this->_do_other_page_hooks();
228
+		// set up page dependencies
229
+		$this->_before_page_setup();
230
+		$this->_page_setup();
231
+		// die();
232
+	}
233
+
234
+
235
+	/**
236
+	 * _init_page_props
237
+	 * Child classes use to set at least the following properties:
238
+	 * $page_slug.
239
+	 * $page_label.
240
+	 *
241
+	 * @abstract
242
+	 * @return void
243
+	 */
244
+	abstract protected function _init_page_props();
245
+
246
+
247
+	/**
248
+	 * _ajax_hooks
249
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
250
+	 * Note: within the ajax callback methods.
251
+	 *
252
+	 * @abstract
253
+	 * @return void
254
+	 */
255
+	abstract protected function _ajax_hooks();
256
+
257
+
258
+	/**
259
+	 * _define_page_props
260
+	 * child classes define page properties in here.  Must include at least:
261
+	 * $_admin_base_url = base_url for all admin pages
262
+	 * $_admin_page_title = default admin_page_title for admin pages
263
+	 * $_labels = array of default labels for various automatically generated elements:
264
+	 *    array(
265
+	 *        'buttons' => array(
266
+	 *            'add' => esc_html__('label for add new button'),
267
+	 *            'edit' => esc_html__('label for edit button'),
268
+	 *            'delete' => esc_html__('label for delete button')
269
+	 *            )
270
+	 *        )
271
+	 *
272
+	 * @abstract
273
+	 * @return void
274
+	 */
275
+	abstract protected function _define_page_props();
276
+
277
+
278
+	/**
279
+	 * _set_page_routes
280
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
281
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
282
+	 * have a 'default' route. Here's the format
283
+	 * $this->_page_routes = array(
284
+	 *        'default' => array(
285
+	 *            'func' => '_default_method_handling_route',
286
+	 *            'args' => array('array','of','args'),
287
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
288
+	 *            ajax request, backend processing)
289
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
290
+	 *            headers route after.  The string you enter here should match the defined route reference for a
291
+	 *            headers sent route.
292
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
293
+	 *            this route.
294
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
295
+	 *            checks).
296
+	 *        ),
297
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
298
+	 *        handling method.
299
+	 *        )
300
+	 * )
301
+	 *
302
+	 * @abstract
303
+	 * @return void
304
+	 */
305
+	abstract protected function _set_page_routes();
306
+
307
+
308
+	/**
309
+	 * _set_page_config
310
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
311
+	 * array corresponds to the page_route for the loaded page. Format:
312
+	 * $this->_page_config = array(
313
+	 *        'default' => array(
314
+	 *            'labels' => array(
315
+	 *                'buttons' => array(
316
+	 *                    'add' => esc_html__('label for adding item'),
317
+	 *                    'edit' => esc_html__('label for editing item'),
318
+	 *                    'delete' => esc_html__('label for deleting item')
319
+	 *                ),
320
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
321
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
322
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
323
+	 *            _define_page_props() method
324
+	 *            'nav' => array(
325
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
326
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
327
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
328
+	 *                'order' => 10, //required to indicate tab position.
329
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
330
+	 *                displayed then add this parameter.
331
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
332
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
333
+	 *            metaboxes set for eventespresso admin pages.
334
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
335
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
336
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
337
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
338
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
339
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
340
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
341
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
342
+	 *            want to display.
343
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
344
+	 *                'tab_id' => array(
345
+	 *                    'title' => 'tab_title',
346
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
347
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
348
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
349
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
350
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
351
+	 *                    attempt to use the callback which should match the name of a method in the class
352
+	 *                    ),
353
+	 *                'tab2_id' => array(
354
+	 *                    'title' => 'tab2 title',
355
+	 *                    'filename' => 'file_name_2'
356
+	 *                    'callback' => 'callback_method_for_content',
357
+	 *                 ),
358
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
359
+	 *            help tab area on an admin page. @return void
360
+	 *
361
+	 * @abstract
362
+	 */
363
+	abstract protected function _set_page_config();
364
+
365
+
366
+	/**
367
+	 * _add_screen_options
368
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
369
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
370
+	 * to a particular view.
371
+	 *
372
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
373
+	 *         see also WP_Screen object documents...
374
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
375
+	 * @abstract
376
+	 * @return void
377
+	 */
378
+	abstract protected function _add_screen_options();
379
+
380
+
381
+	/**
382
+	 * _add_feature_pointers
383
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
384
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
385
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
386
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
387
+	 * extended) also see:
388
+	 *
389
+	 * @link   http://eamann.com/tech/wordpress-portland/
390
+	 * @abstract
391
+	 * @return void
392
+	 */
393
+	abstract protected function _add_feature_pointers();
394
+
395
+
396
+	/**
397
+	 * load_scripts_styles
398
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
399
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
400
+	 * scripts/styles per view by putting them in a dynamic function in this format
401
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
402
+	 *
403
+	 * @abstract
404
+	 * @return void
405
+	 */
406
+	abstract public function load_scripts_styles();
407
+
408
+
409
+	/**
410
+	 * admin_init
411
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
412
+	 * all pages/views loaded by child class.
413
+	 *
414
+	 * @abstract
415
+	 * @return void
416
+	 */
417
+	abstract public function admin_init();
418
+
419
+
420
+	/**
421
+	 * admin_notices
422
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
423
+	 * all pages/views loaded by child class.
424
+	 *
425
+	 * @abstract
426
+	 * @return void
427
+	 */
428
+	abstract public function admin_notices();
429
+
430
+
431
+	/**
432
+	 * admin_footer_scripts
433
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
434
+	 * will apply to all pages/views loaded by child class.
435
+	 *
436
+	 * @return void
437
+	 */
438
+	abstract public function admin_footer_scripts();
439
+
440
+
441
+	/**
442
+	 * admin_footer
443
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
444
+	 * apply to all pages/views loaded by child class.
445
+	 *
446
+	 * @return void
447
+	 */
448
+	public function admin_footer()
449
+	{
450
+	}
451
+
452
+
453
+	/**
454
+	 * _global_ajax_hooks
455
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
456
+	 * Note: within the ajax callback methods.
457
+	 *
458
+	 * @abstract
459
+	 * @return void
460
+	 */
461
+	protected function _global_ajax_hooks()
462
+	{
463
+		// for lazy loading of metabox content
464
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
465
+	}
466
+
467
+
468
+	public function ajax_metabox_content()
469
+	{
470
+		$content_id  = $this->request->getRequestParam('contentid', '');
471
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
472
+		self::cached_rss_display($content_id, $content_url);
473
+		wp_die();
474
+	}
475
+
476
+
477
+	/**
478
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
479
+	 *
480
+	 * @return void
481
+	 */
482
+	protected function _before_page_setup()
483
+	{
484
+		// default is to do nothing
485
+	}
486
+
487
+
488
+	/**
489
+	 * Makes sure any things that need to be loaded early get handled.
490
+	 * We also escape early here if the page requested doesn't match the object.
491
+	 *
492
+	 * @final
493
+	 * @return void
494
+	 * @throws EE_Error
495
+	 * @throws InvalidArgumentException
496
+	 * @throws ReflectionException
497
+	 * @throws InvalidDataTypeException
498
+	 * @throws InvalidInterfaceException
499
+	 */
500
+	final protected function _page_setup()
501
+	{
502
+		// requires?
503
+		// admin_init stuff - global - we're setting this REALLY early
504
+		// so if EE_Admin pages have to hook into other WP pages they can.
505
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
506
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
507
+		// next verify if we need to load anything...
508
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
509
+		$this->page_folder   = strtolower(
510
+			str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
511
+		);
512
+		global $ee_menu_slugs;
513
+		$ee_menu_slugs = (array) $ee_menu_slugs;
514
+		if (
515
+			! $this->request->isAjax()
516
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
517
+		) {
518
+			return;
519
+		}
520
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
521
+		// we need to copy the action from the second to the first
522
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
523
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
524
+		$action     = $action !== '-1' ? $action : $action2;
525
+		$req_action = $action !== '-1' ? $action : 'default';
526
+
527
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
528
+		// then let's use the route as the action.
529
+		// This covers cases where we're coming in from a list table that isn't on the default route.
530
+		$route = $this->request->getRequestParam('route');
531
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
532
+			? $route
533
+			: $req_action;
534
+
535
+		$this->_current_view = $this->_req_action;
536
+		$this->_req_nonce    = $this->_req_action . '_nonce';
537
+		$this->_define_page_props();
538
+		$this->_current_page_view_url = add_query_arg(
539
+			['page' => $this->_current_page, 'action' => $this->_current_view],
540
+			$this->_admin_base_url
541
+		);
542
+		// default things
543
+		$this->_default_espresso_metaboxes = [
544
+			'_espresso_news_post_box',
545
+			'_espresso_links_post_box',
546
+			'_espresso_ratings_request',
547
+			'_espresso_sponsors_post_box',
548
+		];
549
+		// set page configs
550
+		$this->_set_page_routes();
551
+		$this->_set_page_config();
552
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
553
+		if ($this->request->requestParamIsSet('wp_referer')) {
554
+			$wp_referer = $this->request->getRequestParam('wp_referer');
555
+			if ($wp_referer) {
556
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
557
+			}
558
+		}
559
+		// for caffeinated and other extended functionality.
560
+		//  If there is a _extend_page_config method
561
+		// then let's run that to modify the all the various page configuration arrays
562
+		if (method_exists($this, '_extend_page_config')) {
563
+			$this->_extend_page_config();
564
+		}
565
+		// for CPT and other extended functionality.
566
+		// If there is an _extend_page_config_for_cpt
567
+		// then let's run that to modify all the various page configuration arrays.
568
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
569
+			$this->_extend_page_config_for_cpt();
570
+		}
571
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
572
+		$this->_page_routes = apply_filters(
573
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
574
+			$this->_page_routes,
575
+			$this
576
+		);
577
+		$this->_page_config = apply_filters(
578
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
579
+			$this->_page_config,
580
+			$this
581
+		);
582
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
583
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
584
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
585
+			add_action(
586
+				'AHEE__EE_Admin_Page__route_admin_request',
587
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
588
+				10,
589
+				2
590
+			);
591
+		}
592
+		// next route only if routing enabled
593
+		if ($this->_routing && ! $this->request->isAjax()) {
594
+			$this->_verify_routes();
595
+			// next let's just check user_access and kill if no access
596
+			$this->check_user_access();
597
+			if ($this->_is_UI_request) {
598
+				// admin_init stuff - global, all views for this page class, specific view
599
+				add_action('admin_init', [$this, 'admin_init'], 10);
600
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
601
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
602
+				}
603
+			} else {
604
+				// hijack regular WP loading and route admin request immediately
605
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
606
+				$this->route_admin_request();
607
+			}
608
+		}
609
+	}
610
+
611
+
612
+	/**
613
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
614
+	 *
615
+	 * @return void
616
+	 * @throws EE_Error
617
+	 */
618
+	private function _do_other_page_hooks()
619
+	{
620
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
621
+		foreach ($registered_pages as $page) {
622
+			// now let's setup the file name and class that should be present
623
+			$classname = str_replace('.class.php', '', $page);
624
+			// autoloaders should take care of loading file
625
+			if (! class_exists($classname)) {
626
+				$error_msg[] = sprintf(
627
+					esc_html__(
628
+						'Something went wrong with loading the %s admin hooks page.',
629
+						'event_espresso'
630
+					),
631
+					$page
632
+				);
633
+				$error_msg[] = $error_msg[0]
634
+							   . "\r\n"
635
+							   . sprintf(
636
+								   esc_html__(
637
+									   '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',
638
+									   'event_espresso'
639
+								   ),
640
+								   $page,
641
+								   '<br />',
642
+								   '<strong>' . $classname . '</strong>'
643
+							   );
644
+				throw new EE_Error(implode('||', $error_msg));
645
+			}
646
+			// notice we are passing the instance of this class to the hook object.
647
+			$this->loader->getShared($classname, [$this]);
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * @throws ReflectionException
654
+	 * @throws EE_Error
655
+	 */
656
+	public function load_page_dependencies()
657
+	{
658
+		try {
659
+			$this->_load_page_dependencies();
660
+		} catch (EE_Error $e) {
661
+			$e->get_error();
662
+		}
663
+	}
664
+
665
+
666
+	/**
667
+	 * load_page_dependencies
668
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
669
+	 *
670
+	 * @return void
671
+	 * @throws DomainException
672
+	 * @throws EE_Error
673
+	 * @throws InvalidArgumentException
674
+	 * @throws InvalidDataTypeException
675
+	 * @throws InvalidInterfaceException
676
+	 */
677
+	protected function _load_page_dependencies()
678
+	{
679
+		// let's set the current_screen and screen options to override what WP set
680
+		$this->_current_screen = get_current_screen();
681
+		// load admin_notices - global, page class, and view specific
682
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
683
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
684
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
685
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
686
+		}
687
+		// load network admin_notices - global, page class, and view specific
688
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
689
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
690
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
691
+		}
692
+		// this will save any per_page screen options if they are present
693
+		$this->_set_per_page_screen_options();
694
+		// setup list table properties
695
+		$this->_set_list_table();
696
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
697
+		// However in some cases the metaboxes will need to be added within a route handling callback.
698
+		$this->_add_registered_meta_boxes();
699
+		$this->_add_screen_columns();
700
+		// add screen options - global, page child class, and view specific
701
+		$this->_add_global_screen_options();
702
+		$this->_add_screen_options();
703
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
704
+		if (method_exists($this, $add_screen_options)) {
705
+			$this->{$add_screen_options}();
706
+		}
707
+		// add help tab(s) - set via page_config and qtips.
708
+		$this->_add_help_tabs();
709
+		$this->_add_qtips();
710
+		// add feature_pointers - global, page child class, and view specific
711
+		$this->_add_feature_pointers();
712
+		$this->_add_global_feature_pointers();
713
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
714
+		if (method_exists($this, $add_feature_pointer)) {
715
+			$this->{$add_feature_pointer}();
716
+		}
717
+		// enqueue scripts/styles - global, page class, and view specific
718
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
719
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
720
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
721
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
722
+		}
723
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
724
+		// admin_print_footer_scripts - global, page child class, and view specific.
725
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
726
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
727
+		// is a good use case. Notice the late priority we're giving these
728
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
729
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
730
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
731
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
732
+		}
733
+		// admin footer scripts
734
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
735
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
736
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
737
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
738
+		}
739
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
740
+		// targeted hook
741
+		do_action(
742
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
743
+		);
744
+	}
745
+
746
+
747
+	/**
748
+	 * _set_defaults
749
+	 * This sets some global defaults for class properties.
750
+	 */
751
+	private function _set_defaults()
752
+	{
753
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
754
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
755
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
756
+		$this->_page_config          = $this->_default_route_query_args = [];
757
+		$this->_default_nav_tab_name = 'overview';
758
+		// init template args
759
+		$this->_template_args = [
760
+			'admin_page_header'  => '',
761
+			'admin_page_content' => '',
762
+			'post_body_content'  => '',
763
+			'before_list_table'  => '',
764
+			'after_list_table'   => '',
765
+		];
766
+	}
767
+
768
+
769
+	/**
770
+	 * route_admin_request
771
+	 *
772
+	 * @return void
773
+	 * @throws InvalidArgumentException
774
+	 * @throws InvalidInterfaceException
775
+	 * @throws InvalidDataTypeException
776
+	 * @throws EE_Error
777
+	 * @throws ReflectionException
778
+	 * @see    _route_admin_request()
779
+	 */
780
+	public function route_admin_request()
781
+	{
782
+		try {
783
+			$this->_route_admin_request();
784
+		} catch (EE_Error $e) {
785
+			$e->get_error();
786
+		}
787
+	}
788
+
789
+
790
+	public function set_wp_page_slug($wp_page_slug)
791
+	{
792
+		$this->_wp_page_slug = $wp_page_slug;
793
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
794
+		if (is_network_admin()) {
795
+			$this->_wp_page_slug .= '-network';
796
+		}
797
+	}
798
+
799
+
800
+	/**
801
+	 * _verify_routes
802
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
803
+	 * we know if we need to drop out.
804
+	 *
805
+	 * @return bool
806
+	 * @throws EE_Error
807
+	 */
808
+	protected function _verify_routes()
809
+	{
810
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
811
+		if (! $this->_current_page && ! $this->request->isAjax()) {
812
+			return false;
813
+		}
814
+		$this->_route = false;
815
+		// check that the page_routes array is not empty
816
+		if (empty($this->_page_routes)) {
817
+			// user error msg
818
+			$error_msg = sprintf(
819
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
820
+				$this->_admin_page_title
821
+			);
822
+			// developer error msg
823
+			$error_msg .= '||' . $error_msg
824
+						  . esc_html__(
825
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
826
+							  'event_espresso'
827
+						  );
828
+			throw new EE_Error($error_msg);
829
+		}
830
+		// and that the requested page route exists
831
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
832
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
833
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
834
+				? $this->_page_config[ $this->_req_action ]
835
+				: [];
836
+		} else {
837
+			// user error msg
838
+			$error_msg = sprintf(
839
+				esc_html__(
840
+					'The requested page route does not exist for the %s admin page.',
841
+					'event_espresso'
842
+				),
843
+				$this->_admin_page_title
844
+			);
845
+			// developer error msg
846
+			$error_msg .= '||' . $error_msg
847
+						  . sprintf(
848
+							  esc_html__(
849
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
850
+								  'event_espresso'
851
+							  ),
852
+							  $this->_req_action
853
+						  );
854
+			throw new EE_Error($error_msg);
855
+		}
856
+		// and that a default route exists
857
+		if (! array_key_exists('default', $this->_page_routes)) {
858
+			// user error msg
859
+			$error_msg = sprintf(
860
+				esc_html__(
861
+					'A default page route has not been set for the % admin page.',
862
+					'event_espresso'
863
+				),
864
+				$this->_admin_page_title
865
+			);
866
+			// developer error msg
867
+			$error_msg .= '||' . $error_msg
868
+						  . esc_html__(
869
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
870
+							  'event_espresso'
871
+						  );
872
+			throw new EE_Error($error_msg);
873
+		}
874
+		// first lets' catch if the UI request has EVER been set.
875
+		if ($this->_is_UI_request === null) {
876
+			// lets set if this is a UI request or not.
877
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
878
+			// wait a minute... we might have a noheader in the route array
879
+			$this->_is_UI_request = ! (
880
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
881
+			)
882
+				? $this->_is_UI_request
883
+				: false;
884
+		}
885
+		$this->_set_current_labels();
886
+		return true;
887
+	}
888
+
889
+
890
+	/**
891
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
892
+	 *
893
+	 * @param string $route the route name we're verifying
894
+	 * @return bool we'll throw an exception if this isn't a valid route.
895
+	 * @throws EE_Error
896
+	 */
897
+	protected function _verify_route($route)
898
+	{
899
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
900
+			return true;
901
+		}
902
+		// user error msg
903
+		$error_msg = sprintf(
904
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
905
+			$this->_admin_page_title
906
+		);
907
+		// developer error msg
908
+		$error_msg .= '||' . $error_msg
909
+					  . sprintf(
910
+						  esc_html__(
911
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
912
+							  'event_espresso'
913
+						  ),
914
+						  $route
915
+					  );
916
+		throw new EE_Error($error_msg);
917
+	}
918
+
919
+
920
+	/**
921
+	 * perform nonce verification
922
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
923
+	 * using this method (and save retyping!)
924
+	 *
925
+	 * @param string $nonce     The nonce sent
926
+	 * @param string $nonce_ref The nonce reference string (name0)
927
+	 * @return void
928
+	 * @throws EE_Error
929
+	 */
930
+	protected function _verify_nonce($nonce, $nonce_ref)
931
+	{
932
+		// verify nonce against expected value
933
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
934
+			// these are not the droids you are looking for !!!
935
+			$msg = sprintf(
936
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
937
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
938
+				'</a>'
939
+			);
940
+			if (WP_DEBUG) {
941
+				$msg .= "\n  ";
942
+				$msg .= sprintf(
943
+					esc_html__(
944
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
945
+						'event_espresso'
946
+					),
947
+					__CLASS__
948
+				);
949
+			}
950
+			if (! $this->request->isAjax()) {
951
+				wp_die($msg);
952
+			}
953
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
954
+			$this->_return_json();
955
+		}
956
+	}
957
+
958
+
959
+	/**
960
+	 * _route_admin_request()
961
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
962
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
963
+	 * in the page routes and then will try to load the corresponding method.
964
+	 *
965
+	 * @return void
966
+	 * @throws EE_Error
967
+	 * @throws InvalidArgumentException
968
+	 * @throws InvalidDataTypeException
969
+	 * @throws InvalidInterfaceException
970
+	 * @throws ReflectionException
971
+	 */
972
+	protected function _route_admin_request()
973
+	{
974
+		if (! $this->_is_UI_request) {
975
+			$this->_verify_routes();
976
+		}
977
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
978
+		if ($this->_req_action !== 'default' && $nonce_check) {
979
+			// set nonce from post data
980
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
981
+			$this->_verify_nonce($nonce, $this->_req_nonce);
982
+		}
983
+		// set the nav_tabs array but ONLY if this is  UI_request
984
+		if ($this->_is_UI_request) {
985
+			$this->_set_nav_tabs();
986
+		}
987
+		// grab callback function
988
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
989
+		// check if callback has args
990
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
991
+		$error_msg = '';
992
+		// action right before calling route
993
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
994
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
995
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
996
+		}
997
+		// right before calling the route, let's clean the _wp_http_referer
998
+		$this->request->unSetRequestParam('_wp_http_referer');
999
+		$this->request->unSetServerParam('_wp_http_referer');
1000
+		$cleaner_request_uri = remove_query_arg(
1001
+			'_wp_http_referer',
1002
+			wp_unslash($this->request->getServerParam('REQUEST_URI'))
1003
+		);
1004
+		$this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri);
1005
+		$this->request->setServerParam('REQUEST_URI', $cleaner_request_uri);
1006
+		if (! empty($func)) {
1007
+			if (is_array($func)) {
1008
+				[$class, $method] = $func;
1009
+			} elseif (strpos($func, '::') !== false) {
1010
+				[$class, $method] = explode('::', $func);
1011
+			} else {
1012
+				$class  = $this;
1013
+				$method = $func;
1014
+			}
1015
+			if (! (is_object($class) && $class === $this)) {
1016
+				// send along this admin page object for access by addons.
1017
+				$args['admin_page_object'] = $this;
1018
+			}
1019
+			if (
1020
+				// is it a method on a class that doesn't work?
1021
+				(
1022
+					(
1023
+						method_exists($class, $method)
1024
+						&& call_user_func_array([$class, $method], $args) === false
1025
+					)
1026
+					&& (
1027
+						// is it a standalone function that doesn't work?
1028
+						function_exists($method)
1029
+						&& call_user_func_array(
1030
+							$func,
1031
+							array_merge(['admin_page_object' => $this], $args)
1032
+						) === false
1033
+					)
1034
+				)
1035
+				|| (
1036
+					// is it neither a class method NOR a standalone function?
1037
+					! method_exists($class, $method)
1038
+					&& ! function_exists($method)
1039
+				)
1040
+			) {
1041
+				// user error msg
1042
+				$error_msg = esc_html__(
1043
+					'An error occurred. The  requested page route could not be found.',
1044
+					'event_espresso'
1045
+				);
1046
+				// developer error msg
1047
+				$error_msg .= '||';
1048
+				$error_msg .= sprintf(
1049
+					esc_html__(
1050
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1051
+						'event_espresso'
1052
+					),
1053
+					$method
1054
+				);
1055
+			}
1056
+			if (! empty($error_msg)) {
1057
+				throw new EE_Error($error_msg);
1058
+			}
1059
+		}
1060
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1061
+		// then we need to reset the routing properties to the new route.
1062
+		// 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.
1063
+		if (
1064
+			$this->_is_UI_request === false
1065
+			&& is_array($this->_route)
1066
+			&& ! empty($this->_route['headers_sent_route'])
1067
+		) {
1068
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1069
+		}
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 * This method just allows the resetting of page properties in the case where a no headers
1075
+	 * route redirects to a headers route in its route config.
1076
+	 *
1077
+	 * @param string $new_route New (non header) route to redirect to.
1078
+	 * @return   void
1079
+	 * @throws ReflectionException
1080
+	 * @throws InvalidArgumentException
1081
+	 * @throws InvalidInterfaceException
1082
+	 * @throws InvalidDataTypeException
1083
+	 * @throws EE_Error
1084
+	 * @since   4.3.0
1085
+	 */
1086
+	protected function _reset_routing_properties($new_route)
1087
+	{
1088
+		$this->_is_UI_request = true;
1089
+		// now we set the current route to whatever the headers_sent_route is set at
1090
+		$this->request->setRequestParam('action', $new_route);
1091
+		// rerun page setup
1092
+		$this->_page_setup();
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * _add_query_arg
1098
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1099
+	 *(internally just uses EEH_URL's function with the same name)
1100
+	 *
1101
+	 * @param array  $args
1102
+	 * @param string $url
1103
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1104
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1105
+	 *                                        Example usage: If the current page is:
1106
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1107
+	 *                                        &action=default&event_id=20&month_range=March%202015
1108
+	 *                                        &_wpnonce=5467821
1109
+	 *                                        and you call:
1110
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1111
+	 *                                        array(
1112
+	 *                                        'action' => 'resend_something',
1113
+	 *                                        'page=>espresso_registrations'
1114
+	 *                                        ),
1115
+	 *                                        $some_url,
1116
+	 *                                        true
1117
+	 *                                        );
1118
+	 *                                        It will produce a url in this structure:
1119
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1120
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1121
+	 *                                        month_range]=March%202015
1122
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1123
+	 * @return string
1124
+	 */
1125
+	public static function add_query_args_and_nonce(
1126
+		$args = [],
1127
+		$url = false,
1128
+		$sticky = false,
1129
+		$exclude_nonce = false
1130
+	) {
1131
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1132
+		if ($sticky) {
1133
+			/** @var RequestInterface $request */
1134
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1135
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1136
+			foreach ($request->requestParams() as $key => $value) {
1137
+				// do not add nonces
1138
+				if (strpos($key, 'nonce') !== false) {
1139
+					continue;
1140
+				}
1141
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1142
+			}
1143
+		}
1144
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1145
+	}
1146
+
1147
+
1148
+	/**
1149
+	 * This returns a generated link that will load the related help tab.
1150
+	 *
1151
+	 * @param string $help_tab_id the id for the connected help tab
1152
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1153
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1154
+	 * @return string              generated link
1155
+	 * @uses EEH_Template::get_help_tab_link()
1156
+	 */
1157
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1158
+	{
1159
+		return EEH_Template::get_help_tab_link(
1160
+			$help_tab_id,
1161
+			$this->page_slug,
1162
+			$this->_req_action,
1163
+			$icon_style,
1164
+			$help_text
1165
+		);
1166
+	}
1167
+
1168
+
1169
+	/**
1170
+	 * _add_help_tabs
1171
+	 * Note child classes define their help tabs within the page_config array.
1172
+	 *
1173
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1174
+	 * @return void
1175
+	 * @throws DomainException
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	protected function _add_help_tabs()
1179
+	{
1180
+		if (isset($this->_page_config[ $this->_req_action ])) {
1181
+			$config = $this->_page_config[ $this->_req_action ];
1182
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1183
+			if (is_array($config) && isset($config['help_sidebar'])) {
1184
+				// check that the callback given is valid
1185
+				if (! method_exists($this, $config['help_sidebar'])) {
1186
+					throw new EE_Error(
1187
+						sprintf(
1188
+							esc_html__(
1189
+								'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',
1190
+								'event_espresso'
1191
+							),
1192
+							$config['help_sidebar'],
1193
+							get_class($this)
1194
+						)
1195
+					);
1196
+				}
1197
+				$content = apply_filters(
1198
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1199
+					$this->{$config['help_sidebar']}()
1200
+				);
1201
+				$this->_current_screen->set_help_sidebar($content);
1202
+			}
1203
+			if (! isset($config['help_tabs'])) {
1204
+				return;
1205
+			} //no help tabs for this route
1206
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1207
+				// we're here so there ARE help tabs!
1208
+				// make sure we've got what we need
1209
+				if (! isset($cfg['title'])) {
1210
+					throw new EE_Error(
1211
+						esc_html__(
1212
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1213
+							'event_espresso'
1214
+						)
1215
+					);
1216
+				}
1217
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1218
+					throw new EE_Error(
1219
+						esc_html__(
1220
+							'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',
1221
+							'event_espresso'
1222
+						)
1223
+					);
1224
+				}
1225
+				// first priority goes to content.
1226
+				if (! empty($cfg['content'])) {
1227
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1228
+					// second priority goes to filename
1229
+				} elseif (! empty($cfg['filename'])) {
1230
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1231
+					// 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)
1232
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1233
+															 . basename($this->_get_dir())
1234
+															 . '/help_tabs/'
1235
+															 . $cfg['filename']
1236
+															 . '.help_tab.php' : $file_path;
1237
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1238
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1239
+						EE_Error::add_error(
1240
+							sprintf(
1241
+								esc_html__(
1242
+									'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',
1243
+									'event_espresso'
1244
+								),
1245
+								$tab_id,
1246
+								key($config),
1247
+								$file_path
1248
+							),
1249
+							__FILE__,
1250
+							__FUNCTION__,
1251
+							__LINE__
1252
+						);
1253
+						return;
1254
+					}
1255
+					$template_args['admin_page_obj'] = $this;
1256
+					$content                         = EEH_Template::display_template(
1257
+						$file_path,
1258
+						$template_args,
1259
+						true
1260
+					);
1261
+				} else {
1262
+					$content = '';
1263
+				}
1264
+				// check if callback is valid
1265
+				if (
1266
+					empty($content)
1267
+					&& (
1268
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1269
+					)
1270
+				) {
1271
+					EE_Error::add_error(
1272
+						sprintf(
1273
+							esc_html__(
1274
+								'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.',
1275
+								'event_espresso'
1276
+							),
1277
+							$cfg['title']
1278
+						),
1279
+						__FILE__,
1280
+						__FUNCTION__,
1281
+						__LINE__
1282
+					);
1283
+					return;
1284
+				}
1285
+				// setup config array for help tab method
1286
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1287
+				$_ht = [
1288
+					'id'       => $id,
1289
+					'title'    => $cfg['title'],
1290
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1291
+					'content'  => $content,
1292
+				];
1293
+				$this->_current_screen->add_help_tab($_ht);
1294
+			}
1295
+		}
1296
+	}
1297
+
1298
+
1299
+	/**
1300
+	 * This simply sets up any qtips that have been defined in the page config
1301
+	 *
1302
+	 * @return void
1303
+	 */
1304
+	protected function _add_qtips()
1305
+	{
1306
+		if (isset($this->_route_config['qtips'])) {
1307
+			$qtips = (array) $this->_route_config['qtips'];
1308
+			// load qtip loader
1309
+			$path = [
1310
+				$this->_get_dir() . '/qtips/',
1311
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1312
+			];
1313
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1314
+		}
1315
+	}
1316
+
1317
+
1318
+	/**
1319
+	 * _set_nav_tabs
1320
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1321
+	 * wish to add additional tabs or modify accordingly.
1322
+	 *
1323
+	 * @return void
1324
+	 * @throws InvalidArgumentException
1325
+	 * @throws InvalidInterfaceException
1326
+	 * @throws InvalidDataTypeException
1327
+	 */
1328
+	protected function _set_nav_tabs()
1329
+	{
1330
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1331
+		$i = 0;
1332
+		foreach ($this->_page_config as $slug => $config) {
1333
+			if (! is_array($config) || empty($config['nav'])) {
1334
+				continue;
1335
+			}
1336
+			// no nav tab for this config
1337
+			// check for persistent flag
1338
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1339
+				// nav tab is only to appear when route requested.
1340
+				continue;
1341
+			}
1342
+			if (! $this->check_user_access($slug, true)) {
1343
+				// no nav tab because current user does not have access.
1344
+				continue;
1345
+			}
1346
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1347
+			$this->_nav_tabs[ $slug ] = [
1348
+				'url'       => isset($config['nav']['url'])
1349
+					? $config['nav']['url']
1350
+					: self::add_query_args_and_nonce(
1351
+						['action' => $slug],
1352
+						$this->_admin_base_url
1353
+					),
1354
+				'link_text' => isset($config['nav']['label'])
1355
+					? $config['nav']['label']
1356
+					: ucwords(
1357
+						str_replace('_', ' ', $slug)
1358
+					),
1359
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1360
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1361
+			];
1362
+			$i++;
1363
+		}
1364
+		// if $this->_nav_tabs is empty then lets set the default
1365
+		if (empty($this->_nav_tabs)) {
1366
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1367
+				'url'       => $this->_admin_base_url,
1368
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1369
+				'css_class' => 'nav-tab-active',
1370
+				'order'     => 10,
1371
+			];
1372
+		}
1373
+		// now let's sort the tabs according to order
1374
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1375
+	}
1376
+
1377
+
1378
+	/**
1379
+	 * _set_current_labels
1380
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1381
+	 * property array
1382
+	 *
1383
+	 * @return void
1384
+	 */
1385
+	private function _set_current_labels()
1386
+	{
1387
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1388
+			foreach ($this->_route_config['labels'] as $label => $text) {
1389
+				if (is_array($text)) {
1390
+					foreach ($text as $sublabel => $subtext) {
1391
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1392
+					}
1393
+				} else {
1394
+					$this->_labels[ $label ] = $text;
1395
+				}
1396
+			}
1397
+		}
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 *        verifies user access for this admin page
1403
+	 *
1404
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1405
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1406
+	 *                               return false if verify fail.
1407
+	 * @return bool
1408
+	 * @throws InvalidArgumentException
1409
+	 * @throws InvalidDataTypeException
1410
+	 * @throws InvalidInterfaceException
1411
+	 */
1412
+	public function check_user_access($route_to_check = '', $verify_only = false)
1413
+	{
1414
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1415
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1416
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1417
+						  && is_array(
1418
+							  $this->_page_routes[ $route_to_check ]
1419
+						  )
1420
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1421
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1422
+		if (empty($capability) && empty($route_to_check)) {
1423
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1424
+				: $this->_route['capability'];
1425
+		} else {
1426
+			$capability = empty($capability) ? 'manage_options' : $capability;
1427
+		}
1428
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1429
+		if (
1430
+			! $this->request->isAjax()
1431
+			&& (
1432
+				! function_exists('is_admin')
1433
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1434
+					$capability,
1435
+					$this->page_slug
1436
+					. '_'
1437
+					. $route_to_check,
1438
+					$id
1439
+				)
1440
+			)
1441
+		) {
1442
+			if ($verify_only) {
1443
+				return false;
1444
+			}
1445
+			if (is_user_logged_in()) {
1446
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1447
+			} else {
1448
+				return false;
1449
+			}
1450
+		}
1451
+		return true;
1452
+	}
1453
+
1454
+
1455
+	/**
1456
+	 * admin_init_global
1457
+	 * This runs all the code that we want executed within the WP admin_init hook.
1458
+	 * This method executes for ALL EE Admin pages.
1459
+	 *
1460
+	 * @return void
1461
+	 */
1462
+	public function admin_init_global()
1463
+	{
1464
+	}
1465
+
1466
+
1467
+	/**
1468
+	 * wp_loaded_global
1469
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1470
+	 * EE_Admin page and will execute on every EE Admin Page load
1471
+	 *
1472
+	 * @return void
1473
+	 */
1474
+	public function wp_loaded()
1475
+	{
1476
+	}
1477
+
1478
+
1479
+	/**
1480
+	 * admin_notices
1481
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1482
+	 * ALL EE_Admin pages.
1483
+	 *
1484
+	 * @return void
1485
+	 */
1486
+	public function admin_notices_global()
1487
+	{
1488
+		$this->_display_no_javascript_warning();
1489
+		$this->_display_espresso_notices();
1490
+	}
1491
+
1492
+
1493
+	public function network_admin_notices_global()
1494
+	{
1495
+		$this->_display_no_javascript_warning();
1496
+		$this->_display_espresso_notices();
1497
+	}
1498
+
1499
+
1500
+	/**
1501
+	 * admin_footer_scripts_global
1502
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1503
+	 * will apply on ALL EE_Admin pages.
1504
+	 *
1505
+	 * @return void
1506
+	 */
1507
+	public function admin_footer_scripts_global()
1508
+	{
1509
+		$this->_add_admin_page_ajax_loading_img();
1510
+		$this->_add_admin_page_overlay();
1511
+		// if metaboxes are present we need to add the nonce field
1512
+		if (
1513
+			isset($this->_route_config['metaboxes'])
1514
+			|| isset($this->_route_config['list_table'])
1515
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1516
+		) {
1517
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1518
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1519
+		}
1520
+	}
1521
+
1522
+
1523
+	/**
1524
+	 * admin_footer_global
1525
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1526
+	 * ALL EE_Admin Pages.
1527
+	 *
1528
+	 * @return void
1529
+	 */
1530
+	public function admin_footer_global()
1531
+	{
1532
+		// dialog container for dialog helper
1533
+		echo '
1534 1534
         <div class="ee-admin-dialog-container auto-hide hidden">
1535 1535
             <div class="ee-notices"></div>
1536 1536
             <div class="ee-admin-dialog-container-inner-content"></div>
1537 1537
         </div>
1538 1538
         ';
1539 1539
 
1540
-        // current set timezone for timezone js
1541
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1542
-    }
1543
-
1544
-
1545
-    /**
1546
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1547
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1548
-     * help popups then in your templates or your content you set "triggers" for the content using the
1549
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1550
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1551
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1552
-     * for the
1553
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1554
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1555
-     *    'help_trigger_id' => array(
1556
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1557
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1558
-     *    )
1559
-     * );
1560
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1561
-     *
1562
-     * @param array $help_array
1563
-     * @param bool  $display
1564
-     * @return string content
1565
-     * @throws DomainException
1566
-     * @throws EE_Error
1567
-     */
1568
-    protected function _set_help_popup_content($help_array = [], $display = false)
1569
-    {
1570
-        $content    = '';
1571
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1572
-        // loop through the array and setup content
1573
-        foreach ($help_array as $trigger => $help) {
1574
-            // make sure the array is setup properly
1575
-            if (! isset($help['title']) || ! isset($help['content'])) {
1576
-                throw new EE_Error(
1577
-                    esc_html__(
1578
-                        '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',
1579
-                        'event_espresso'
1580
-                    )
1581
-                );
1582
-            }
1583
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1584
-            $template_args = [
1585
-                'help_popup_id'      => $trigger,
1586
-                'help_popup_title'   => $help['title'],
1587
-                'help_popup_content' => $help['content'],
1588
-            ];
1589
-            $content       .= EEH_Template::display_template(
1590
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1591
-                $template_args,
1592
-                true
1593
-            );
1594
-        }
1595
-        if ($display) {
1596
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1597
-            return '';
1598
-        }
1599
-        return $content;
1600
-    }
1601
-
1602
-
1603
-    /**
1604
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1605
-     *
1606
-     * @return array properly formatted array for help popup content
1607
-     * @throws EE_Error
1608
-     */
1609
-    private function _get_help_content()
1610
-    {
1611
-        // what is the method we're looking for?
1612
-        $method_name = '_help_popup_content_' . $this->_req_action;
1613
-        // if method doesn't exist let's get out.
1614
-        if (! method_exists($this, $method_name)) {
1615
-            return [];
1616
-        }
1617
-        // k we're good to go let's retrieve the help array
1618
-        $help_array = call_user_func([$this, $method_name]);
1619
-        // make sure we've got an array!
1620
-        if (! is_array($help_array)) {
1621
-            throw new EE_Error(
1622
-                esc_html__(
1623
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1624
-                    'event_espresso'
1625
-                )
1626
-            );
1627
-        }
1628
-        return $help_array;
1629
-    }
1630
-
1631
-
1632
-    /**
1633
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1634
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1635
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1636
-     *
1637
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1638
-     * @param boolean $display    if false then we return the trigger string
1639
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1640
-     * @return string
1641
-     * @throws DomainException
1642
-     * @throws EE_Error
1643
-     */
1644
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1645
-    {
1646
-        if ($this->request->isAjax()) {
1647
-            return '';
1648
-        }
1649
-        // 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
1650
-        $help_array   = $this->_get_help_content();
1651
-        $help_content = '';
1652
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1653
-            $help_array[ $trigger_id ] = [
1654
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1655
-                'content' => esc_html__(
1656
-                    '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.)',
1657
-                    'event_espresso'
1658
-                ),
1659
-            ];
1660
-            $help_content              = $this->_set_help_popup_content($help_array);
1661
-        }
1662
-        // let's setup the trigger
1663
-        $content = '<a class="ee-dialog" href="?height='
1664
-                   . esc_attr($dimensions[0])
1665
-                   . '&width='
1666
-                   . esc_attr($dimensions[1])
1667
-                   . '&inlineId='
1668
-                   . esc_attr($trigger_id)
1669
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1670
-        $content .= $help_content;
1671
-        if ($display) {
1672
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1673
-            return '';
1674
-        }
1675
-        return $content;
1676
-    }
1677
-
1678
-
1679
-    /**
1680
-     * _add_global_screen_options
1681
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1682
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1683
-     *
1684
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1685
-     *         see also WP_Screen object documents...
1686
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1687
-     * @abstract
1688
-     * @return void
1689
-     */
1690
-    private function _add_global_screen_options()
1691
-    {
1692
-    }
1693
-
1694
-
1695
-    /**
1696
-     * _add_global_feature_pointers
1697
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1698
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1699
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1700
-     *
1701
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1702
-     *         extended) also see:
1703
-     * @link   http://eamann.com/tech/wordpress-portland/
1704
-     * @abstract
1705
-     * @return void
1706
-     */
1707
-    private function _add_global_feature_pointers()
1708
-    {
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * load_global_scripts_styles
1714
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1715
-     *
1716
-     * @return void
1717
-     */
1718
-    public function load_global_scripts_styles()
1719
-    {
1720
-        /** STYLES **/
1721
-        // add debugging styles
1722
-        if (WP_DEBUG) {
1723
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1724
-        }
1725
-        // register all styles
1726
-        wp_register_style(
1727
-            'espresso-ui-theme',
1728
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1729
-            [],
1730
-            EVENT_ESPRESSO_VERSION
1731
-        );
1732
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1733
-        // helpers styles
1734
-        wp_register_style(
1735
-            'ee-text-links',
1736
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1737
-            [],
1738
-            EVENT_ESPRESSO_VERSION
1739
-        );
1740
-        /** SCRIPTS **/
1741
-        // register all scripts
1742
-        wp_register_script(
1743
-            'ee-dialog',
1744
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1745
-            ['jquery', 'jquery-ui-draggable'],
1746
-            EVENT_ESPRESSO_VERSION,
1747
-            true
1748
-        );
1749
-        wp_register_script(
1750
-            'ee_admin_js',
1751
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1752
-            ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1753
-            EVENT_ESPRESSO_VERSION,
1754
-            true
1755
-        );
1756
-        wp_register_script(
1757
-            'jquery-ui-timepicker-addon',
1758
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1759
-            ['jquery-ui-datepicker', 'jquery-ui-slider'],
1760
-            EVENT_ESPRESSO_VERSION,
1761
-            true
1762
-        );
1763
-        // script for sorting tables
1764
-        wp_register_script(
1765
-            'espresso_ajax_table_sorting',
1766
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1767
-            ['ee_admin_js', 'jquery-ui-sortable'],
1768
-            EVENT_ESPRESSO_VERSION,
1769
-            true
1770
-        );
1771
-        // script for parsing uri's
1772
-        wp_register_script(
1773
-            'ee-parse-uri',
1774
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1775
-            [],
1776
-            EVENT_ESPRESSO_VERSION,
1777
-            true
1778
-        );
1779
-        // and parsing associative serialized form elements
1780
-        wp_register_script(
1781
-            'ee-serialize-full-array',
1782
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1783
-            ['jquery'],
1784
-            EVENT_ESPRESSO_VERSION,
1785
-            true
1786
-        );
1787
-        // helpers scripts
1788
-        wp_register_script(
1789
-            'ee-text-links',
1790
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1791
-            ['jquery'],
1792
-            EVENT_ESPRESSO_VERSION,
1793
-            true
1794
-        );
1795
-        wp_register_script(
1796
-            'ee-moment-core',
1797
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1798
-            [],
1799
-            EVENT_ESPRESSO_VERSION,
1800
-            true
1801
-        );
1802
-        wp_register_script(
1803
-            'ee-moment',
1804
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1805
-            ['ee-moment-core'],
1806
-            EVENT_ESPRESSO_VERSION,
1807
-            true
1808
-        );
1809
-        wp_register_script(
1810
-            'ee-datepicker',
1811
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1812
-            ['jquery-ui-timepicker-addon', 'ee-moment'],
1813
-            EVENT_ESPRESSO_VERSION,
1814
-            true
1815
-        );
1816
-        // google charts
1817
-        wp_register_script(
1818
-            'google-charts',
1819
-            'https://www.gstatic.com/charts/loader.js',
1820
-            [],
1821
-            EVENT_ESPRESSO_VERSION
1822
-        );
1823
-        // ENQUEUE ALL BASICS BY DEFAULT
1824
-        wp_enqueue_style('ee-admin-css');
1825
-        wp_enqueue_script('ee_admin_js');
1826
-        wp_enqueue_script('ee-accounting');
1827
-        wp_enqueue_script('jquery-validate');
1828
-        // taking care of metaboxes
1829
-        if (
1830
-            empty($this->_cpt_route)
1831
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1832
-        ) {
1833
-            wp_enqueue_script('dashboard');
1834
-        }
1835
-        // LOCALIZED DATA
1836
-        // localize script for ajax lazy loading
1837
-        $lazy_loader_container_ids = apply_filters(
1838
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1839
-            ['espresso_news_post_box_content']
1840
-        );
1841
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1842
-        add_filter(
1843
-            'admin_body_class',
1844
-            function ($classes) {
1845
-                if (strpos($classes, 'espresso-admin') === false) {
1846
-                    $classes .= ' espresso-admin';
1847
-                }
1848
-                return $classes;
1849
-            }
1850
-        );
1851
-    }
1852
-
1853
-
1854
-    /**
1855
-     *        admin_footer_scripts_eei18n_js_strings
1856
-     *
1857
-     * @return        void
1858
-     */
1859
-    public function admin_footer_scripts_eei18n_js_strings()
1860
-    {
1861
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1862
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1863
-            __(
1864
-                '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!!!',
1865
-                'event_espresso'
1866
-            )
1867
-        );
1868
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1869
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1870
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1871
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1872
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1873
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1874
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1875
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1876
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1877
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1878
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1879
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1880
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1881
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1882
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1883
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1884
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1885
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1886
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1887
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1888
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1889
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1890
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1891
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1892
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1893
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1894
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1895
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1896
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1897
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1898
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1899
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1900
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1901
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1902
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1903
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1904
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1905
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1906
-    }
1907
-
1908
-
1909
-    /**
1910
-     *        load enhanced xdebug styles for ppl with failing eyesight
1911
-     *
1912
-     * @return        void
1913
-     */
1914
-    public function add_xdebug_style()
1915
-    {
1916
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1917
-    }
1918
-
1919
-
1920
-    /************************/
1921
-    /** LIST TABLE METHODS **/
1922
-    /************************/
1923
-    /**
1924
-     * this sets up the list table if the current view requires it.
1925
-     *
1926
-     * @return void
1927
-     * @throws EE_Error
1928
-     */
1929
-    protected function _set_list_table()
1930
-    {
1931
-        // first is this a list_table view?
1932
-        if (! isset($this->_route_config['list_table'])) {
1933
-            return;
1934
-        } //not a list_table view so get out.
1935
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
1936
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
1937
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1938
-            // user error msg
1939
-            $error_msg = esc_html__(
1940
-                'An error occurred. The requested list table views could not be found.',
1941
-                'event_espresso'
1942
-            );
1943
-            // developer error msg
1944
-            $error_msg .= '||'
1945
-                          . sprintf(
1946
-                              esc_html__(
1947
-                                  '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.',
1948
-                                  'event_espresso'
1949
-                              ),
1950
-                              $this->_req_action,
1951
-                              $list_table_view
1952
-                          );
1953
-            throw new EE_Error($error_msg);
1954
-        }
1955
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1956
-        $this->_views = apply_filters(
1957
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1958
-            $this->_views
1959
-        );
1960
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1961
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1962
-        $this->_set_list_table_view();
1963
-        $this->_set_list_table_object();
1964
-    }
1965
-
1966
-
1967
-    /**
1968
-     * set current view for List Table
1969
-     *
1970
-     * @return void
1971
-     */
1972
-    protected function _set_list_table_view()
1973
-    {
1974
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1975
-        $status = $this->request->getRequestParam('status', null, 'key');
1976
-        $this->_view = $status && array_key_exists($status, $this->_views)
1977
-            ? $status
1978
-            : $this->_view;
1979
-    }
1980
-
1981
-
1982
-    /**
1983
-     * _set_list_table_object
1984
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1985
-     *
1986
-     * @throws InvalidInterfaceException
1987
-     * @throws InvalidArgumentException
1988
-     * @throws InvalidDataTypeException
1989
-     * @throws EE_Error
1990
-     * @throws InvalidInterfaceException
1991
-     */
1992
-    protected function _set_list_table_object()
1993
-    {
1994
-        if (isset($this->_route_config['list_table'])) {
1995
-            if (! class_exists($this->_route_config['list_table'])) {
1996
-                throw new EE_Error(
1997
-                    sprintf(
1998
-                        esc_html__(
1999
-                            '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.',
2000
-                            'event_espresso'
2001
-                        ),
2002
-                        $this->_route_config['list_table'],
2003
-                        get_class($this)
2004
-                    )
2005
-                );
2006
-            }
2007
-            $this->_list_table_object = $this->loader->getShared(
2008
-                $this->_route_config['list_table'],
2009
-                [$this]
2010
-            );
2011
-        }
2012
-    }
2013
-
2014
-
2015
-    /**
2016
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2017
-     *
2018
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2019
-     *                                                    urls.  The array should be indexed by the view it is being
2020
-     *                                                    added to.
2021
-     * @return array
2022
-     */
2023
-    public function get_list_table_view_RLs($extra_query_args = [])
2024
-    {
2025
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2026
-        if (empty($this->_views)) {
2027
-            $this->_views = [];
2028
-        }
2029
-        // cycle thru views
2030
-        foreach ($this->_views as $key => $view) {
2031
-            $query_args = [];
2032
-            // check for current view
2033
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2034
-            $query_args['action']                        = $this->_req_action;
2035
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2036
-            $query_args['status']                        = $view['slug'];
2037
-            // merge any other arguments sent in.
2038
-            if (isset($extra_query_args[ $view['slug'] ])) {
2039
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2040
-            }
2041
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2042
-        }
2043
-        return $this->_views;
2044
-    }
2045
-
2046
-
2047
-    /**
2048
-     * _entries_per_page_dropdown
2049
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2050
-     *
2051
-     * @param int $max_entries total number of rows in the table
2052
-     * @return string
2053
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2054
-     *         WP does it.
2055
-     */
2056
-    protected function _entries_per_page_dropdown($max_entries = 0)
2057
-    {
2058
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2059
-        $values   = [10, 25, 50, 100];
2060
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2061
-        if ($max_entries) {
2062
-            $values[] = $max_entries;
2063
-            sort($values);
2064
-        }
2065
-        $entries_per_page_dropdown = '
1540
+		// current set timezone for timezone js
1541
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1542
+	}
1543
+
1544
+
1545
+	/**
1546
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1547
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1548
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1549
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1550
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1551
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1552
+	 * for the
1553
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1554
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1555
+	 *    'help_trigger_id' => array(
1556
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1557
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1558
+	 *    )
1559
+	 * );
1560
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1561
+	 *
1562
+	 * @param array $help_array
1563
+	 * @param bool  $display
1564
+	 * @return string content
1565
+	 * @throws DomainException
1566
+	 * @throws EE_Error
1567
+	 */
1568
+	protected function _set_help_popup_content($help_array = [], $display = false)
1569
+	{
1570
+		$content    = '';
1571
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1572
+		// loop through the array and setup content
1573
+		foreach ($help_array as $trigger => $help) {
1574
+			// make sure the array is setup properly
1575
+			if (! isset($help['title']) || ! isset($help['content'])) {
1576
+				throw new EE_Error(
1577
+					esc_html__(
1578
+						'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',
1579
+						'event_espresso'
1580
+					)
1581
+				);
1582
+			}
1583
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1584
+			$template_args = [
1585
+				'help_popup_id'      => $trigger,
1586
+				'help_popup_title'   => $help['title'],
1587
+				'help_popup_content' => $help['content'],
1588
+			];
1589
+			$content       .= EEH_Template::display_template(
1590
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1591
+				$template_args,
1592
+				true
1593
+			);
1594
+		}
1595
+		if ($display) {
1596
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1597
+			return '';
1598
+		}
1599
+		return $content;
1600
+	}
1601
+
1602
+
1603
+	/**
1604
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1605
+	 *
1606
+	 * @return array properly formatted array for help popup content
1607
+	 * @throws EE_Error
1608
+	 */
1609
+	private function _get_help_content()
1610
+	{
1611
+		// what is the method we're looking for?
1612
+		$method_name = '_help_popup_content_' . $this->_req_action;
1613
+		// if method doesn't exist let's get out.
1614
+		if (! method_exists($this, $method_name)) {
1615
+			return [];
1616
+		}
1617
+		// k we're good to go let's retrieve the help array
1618
+		$help_array = call_user_func([$this, $method_name]);
1619
+		// make sure we've got an array!
1620
+		if (! is_array($help_array)) {
1621
+			throw new EE_Error(
1622
+				esc_html__(
1623
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1624
+					'event_espresso'
1625
+				)
1626
+			);
1627
+		}
1628
+		return $help_array;
1629
+	}
1630
+
1631
+
1632
+	/**
1633
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1634
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1635
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1636
+	 *
1637
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1638
+	 * @param boolean $display    if false then we return the trigger string
1639
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1640
+	 * @return string
1641
+	 * @throws DomainException
1642
+	 * @throws EE_Error
1643
+	 */
1644
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1645
+	{
1646
+		if ($this->request->isAjax()) {
1647
+			return '';
1648
+		}
1649
+		// 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
1650
+		$help_array   = $this->_get_help_content();
1651
+		$help_content = '';
1652
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1653
+			$help_array[ $trigger_id ] = [
1654
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1655
+				'content' => esc_html__(
1656
+					'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.)',
1657
+					'event_espresso'
1658
+				),
1659
+			];
1660
+			$help_content              = $this->_set_help_popup_content($help_array);
1661
+		}
1662
+		// let's setup the trigger
1663
+		$content = '<a class="ee-dialog" href="?height='
1664
+				   . esc_attr($dimensions[0])
1665
+				   . '&width='
1666
+				   . esc_attr($dimensions[1])
1667
+				   . '&inlineId='
1668
+				   . esc_attr($trigger_id)
1669
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1670
+		$content .= $help_content;
1671
+		if ($display) {
1672
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1673
+			return '';
1674
+		}
1675
+		return $content;
1676
+	}
1677
+
1678
+
1679
+	/**
1680
+	 * _add_global_screen_options
1681
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1682
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1683
+	 *
1684
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1685
+	 *         see also WP_Screen object documents...
1686
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1687
+	 * @abstract
1688
+	 * @return void
1689
+	 */
1690
+	private function _add_global_screen_options()
1691
+	{
1692
+	}
1693
+
1694
+
1695
+	/**
1696
+	 * _add_global_feature_pointers
1697
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1698
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1699
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1700
+	 *
1701
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1702
+	 *         extended) also see:
1703
+	 * @link   http://eamann.com/tech/wordpress-portland/
1704
+	 * @abstract
1705
+	 * @return void
1706
+	 */
1707
+	private function _add_global_feature_pointers()
1708
+	{
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * load_global_scripts_styles
1714
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1715
+	 *
1716
+	 * @return void
1717
+	 */
1718
+	public function load_global_scripts_styles()
1719
+	{
1720
+		/** STYLES **/
1721
+		// add debugging styles
1722
+		if (WP_DEBUG) {
1723
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1724
+		}
1725
+		// register all styles
1726
+		wp_register_style(
1727
+			'espresso-ui-theme',
1728
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1729
+			[],
1730
+			EVENT_ESPRESSO_VERSION
1731
+		);
1732
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1733
+		// helpers styles
1734
+		wp_register_style(
1735
+			'ee-text-links',
1736
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1737
+			[],
1738
+			EVENT_ESPRESSO_VERSION
1739
+		);
1740
+		/** SCRIPTS **/
1741
+		// register all scripts
1742
+		wp_register_script(
1743
+			'ee-dialog',
1744
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1745
+			['jquery', 'jquery-ui-draggable'],
1746
+			EVENT_ESPRESSO_VERSION,
1747
+			true
1748
+		);
1749
+		wp_register_script(
1750
+			'ee_admin_js',
1751
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1752
+			['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1753
+			EVENT_ESPRESSO_VERSION,
1754
+			true
1755
+		);
1756
+		wp_register_script(
1757
+			'jquery-ui-timepicker-addon',
1758
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1759
+			['jquery-ui-datepicker', 'jquery-ui-slider'],
1760
+			EVENT_ESPRESSO_VERSION,
1761
+			true
1762
+		);
1763
+		// script for sorting tables
1764
+		wp_register_script(
1765
+			'espresso_ajax_table_sorting',
1766
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1767
+			['ee_admin_js', 'jquery-ui-sortable'],
1768
+			EVENT_ESPRESSO_VERSION,
1769
+			true
1770
+		);
1771
+		// script for parsing uri's
1772
+		wp_register_script(
1773
+			'ee-parse-uri',
1774
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1775
+			[],
1776
+			EVENT_ESPRESSO_VERSION,
1777
+			true
1778
+		);
1779
+		// and parsing associative serialized form elements
1780
+		wp_register_script(
1781
+			'ee-serialize-full-array',
1782
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1783
+			['jquery'],
1784
+			EVENT_ESPRESSO_VERSION,
1785
+			true
1786
+		);
1787
+		// helpers scripts
1788
+		wp_register_script(
1789
+			'ee-text-links',
1790
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1791
+			['jquery'],
1792
+			EVENT_ESPRESSO_VERSION,
1793
+			true
1794
+		);
1795
+		wp_register_script(
1796
+			'ee-moment-core',
1797
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1798
+			[],
1799
+			EVENT_ESPRESSO_VERSION,
1800
+			true
1801
+		);
1802
+		wp_register_script(
1803
+			'ee-moment',
1804
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1805
+			['ee-moment-core'],
1806
+			EVENT_ESPRESSO_VERSION,
1807
+			true
1808
+		);
1809
+		wp_register_script(
1810
+			'ee-datepicker',
1811
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1812
+			['jquery-ui-timepicker-addon', 'ee-moment'],
1813
+			EVENT_ESPRESSO_VERSION,
1814
+			true
1815
+		);
1816
+		// google charts
1817
+		wp_register_script(
1818
+			'google-charts',
1819
+			'https://www.gstatic.com/charts/loader.js',
1820
+			[],
1821
+			EVENT_ESPRESSO_VERSION
1822
+		);
1823
+		// ENQUEUE ALL BASICS BY DEFAULT
1824
+		wp_enqueue_style('ee-admin-css');
1825
+		wp_enqueue_script('ee_admin_js');
1826
+		wp_enqueue_script('ee-accounting');
1827
+		wp_enqueue_script('jquery-validate');
1828
+		// taking care of metaboxes
1829
+		if (
1830
+			empty($this->_cpt_route)
1831
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1832
+		) {
1833
+			wp_enqueue_script('dashboard');
1834
+		}
1835
+		// LOCALIZED DATA
1836
+		// localize script for ajax lazy loading
1837
+		$lazy_loader_container_ids = apply_filters(
1838
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1839
+			['espresso_news_post_box_content']
1840
+		);
1841
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1842
+		add_filter(
1843
+			'admin_body_class',
1844
+			function ($classes) {
1845
+				if (strpos($classes, 'espresso-admin') === false) {
1846
+					$classes .= ' espresso-admin';
1847
+				}
1848
+				return $classes;
1849
+			}
1850
+		);
1851
+	}
1852
+
1853
+
1854
+	/**
1855
+	 *        admin_footer_scripts_eei18n_js_strings
1856
+	 *
1857
+	 * @return        void
1858
+	 */
1859
+	public function admin_footer_scripts_eei18n_js_strings()
1860
+	{
1861
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1862
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1863
+			__(
1864
+				'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!!!',
1865
+				'event_espresso'
1866
+			)
1867
+		);
1868
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1869
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1870
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1871
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1872
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1873
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1874
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1875
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1876
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1877
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1878
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1879
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1880
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1881
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1882
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1883
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1884
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1885
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1886
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1887
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1888
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1889
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1890
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1891
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1892
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1893
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1894
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1895
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1896
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1897
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1898
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1899
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1900
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1901
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1902
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1903
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1904
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1905
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1906
+	}
1907
+
1908
+
1909
+	/**
1910
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1911
+	 *
1912
+	 * @return        void
1913
+	 */
1914
+	public function add_xdebug_style()
1915
+	{
1916
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1917
+	}
1918
+
1919
+
1920
+	/************************/
1921
+	/** LIST TABLE METHODS **/
1922
+	/************************/
1923
+	/**
1924
+	 * this sets up the list table if the current view requires it.
1925
+	 *
1926
+	 * @return void
1927
+	 * @throws EE_Error
1928
+	 */
1929
+	protected function _set_list_table()
1930
+	{
1931
+		// first is this a list_table view?
1932
+		if (! isset($this->_route_config['list_table'])) {
1933
+			return;
1934
+		} //not a list_table view so get out.
1935
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
1936
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
1937
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1938
+			// user error msg
1939
+			$error_msg = esc_html__(
1940
+				'An error occurred. The requested list table views could not be found.',
1941
+				'event_espresso'
1942
+			);
1943
+			// developer error msg
1944
+			$error_msg .= '||'
1945
+						  . sprintf(
1946
+							  esc_html__(
1947
+								  '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.',
1948
+								  'event_espresso'
1949
+							  ),
1950
+							  $this->_req_action,
1951
+							  $list_table_view
1952
+						  );
1953
+			throw new EE_Error($error_msg);
1954
+		}
1955
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1956
+		$this->_views = apply_filters(
1957
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1958
+			$this->_views
1959
+		);
1960
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1961
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1962
+		$this->_set_list_table_view();
1963
+		$this->_set_list_table_object();
1964
+	}
1965
+
1966
+
1967
+	/**
1968
+	 * set current view for List Table
1969
+	 *
1970
+	 * @return void
1971
+	 */
1972
+	protected function _set_list_table_view()
1973
+	{
1974
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1975
+		$status = $this->request->getRequestParam('status', null, 'key');
1976
+		$this->_view = $status && array_key_exists($status, $this->_views)
1977
+			? $status
1978
+			: $this->_view;
1979
+	}
1980
+
1981
+
1982
+	/**
1983
+	 * _set_list_table_object
1984
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1985
+	 *
1986
+	 * @throws InvalidInterfaceException
1987
+	 * @throws InvalidArgumentException
1988
+	 * @throws InvalidDataTypeException
1989
+	 * @throws EE_Error
1990
+	 * @throws InvalidInterfaceException
1991
+	 */
1992
+	protected function _set_list_table_object()
1993
+	{
1994
+		if (isset($this->_route_config['list_table'])) {
1995
+			if (! class_exists($this->_route_config['list_table'])) {
1996
+				throw new EE_Error(
1997
+					sprintf(
1998
+						esc_html__(
1999
+							'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.',
2000
+							'event_espresso'
2001
+						),
2002
+						$this->_route_config['list_table'],
2003
+						get_class($this)
2004
+					)
2005
+				);
2006
+			}
2007
+			$this->_list_table_object = $this->loader->getShared(
2008
+				$this->_route_config['list_table'],
2009
+				[$this]
2010
+			);
2011
+		}
2012
+	}
2013
+
2014
+
2015
+	/**
2016
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2017
+	 *
2018
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2019
+	 *                                                    urls.  The array should be indexed by the view it is being
2020
+	 *                                                    added to.
2021
+	 * @return array
2022
+	 */
2023
+	public function get_list_table_view_RLs($extra_query_args = [])
2024
+	{
2025
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2026
+		if (empty($this->_views)) {
2027
+			$this->_views = [];
2028
+		}
2029
+		// cycle thru views
2030
+		foreach ($this->_views as $key => $view) {
2031
+			$query_args = [];
2032
+			// check for current view
2033
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2034
+			$query_args['action']                        = $this->_req_action;
2035
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2036
+			$query_args['status']                        = $view['slug'];
2037
+			// merge any other arguments sent in.
2038
+			if (isset($extra_query_args[ $view['slug'] ])) {
2039
+				$query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2040
+			}
2041
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2042
+		}
2043
+		return $this->_views;
2044
+	}
2045
+
2046
+
2047
+	/**
2048
+	 * _entries_per_page_dropdown
2049
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2050
+	 *
2051
+	 * @param int $max_entries total number of rows in the table
2052
+	 * @return string
2053
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2054
+	 *         WP does it.
2055
+	 */
2056
+	protected function _entries_per_page_dropdown($max_entries = 0)
2057
+	{
2058
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2059
+		$values   = [10, 25, 50, 100];
2060
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2061
+		if ($max_entries) {
2062
+			$values[] = $max_entries;
2063
+			sort($values);
2064
+		}
2065
+		$entries_per_page_dropdown = '
2066 2066
 			<div id="entries-per-page-dv" class="alignleft actions">
2067 2067
 				<label class="hide-if-no-js">
2068 2068
 					Show
2069 2069
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2070
-        foreach ($values as $value) {
2071
-            if ($value < $max_entries) {
2072
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2073
-                $entries_per_page_dropdown .= '
2070
+		foreach ($values as $value) {
2071
+			if ($value < $max_entries) {
2072
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2073
+				$entries_per_page_dropdown .= '
2074 2074
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2075
-            }
2076
-        }
2077
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2078
-        $entries_per_page_dropdown .= '
2075
+			}
2076
+		}
2077
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2078
+		$entries_per_page_dropdown .= '
2079 2079
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2080
-        $entries_per_page_dropdown .= '
2080
+		$entries_per_page_dropdown .= '
2081 2081
 					</select>
2082 2082
 					entries
2083 2083
 				</label>
2084 2084
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2085 2085
 			</div>
2086 2086
 		';
2087
-        return $entries_per_page_dropdown;
2088
-    }
2089
-
2090
-
2091
-    /**
2092
-     *        _set_search_attributes
2093
-     *
2094
-     * @return        void
2095
-     */
2096
-    public function _set_search_attributes()
2097
-    {
2098
-        $this->_template_args['search']['btn_label'] = sprintf(
2099
-            esc_html__('Search %s', 'event_espresso'),
2100
-            empty($this->_search_btn_label) ? $this->page_label
2101
-                : $this->_search_btn_label
2102
-        );
2103
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2104
-    }
2105
-
2106
-
2107
-
2108
-    /*** END LIST TABLE METHODS **/
2109
-
2110
-
2111
-    /**
2112
-     * _add_registered_metaboxes
2113
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2114
-     *
2115
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2116
-     * @return void
2117
-     * @throws EE_Error
2118
-     */
2119
-    private function _add_registered_meta_boxes()
2120
-    {
2121
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2122
-        // we only add meta boxes if the page_route calls for it
2123
-        if (
2124
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2125
-            && is_array(
2126
-                $this->_route_config['metaboxes']
2127
-            )
2128
-        ) {
2129
-            // this simply loops through the callbacks provided
2130
-            // and checks if there is a corresponding callback registered by the child
2131
-            // if there is then we go ahead and process the metabox loader.
2132
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2133
-                // first check for Closures
2134
-                if ($metabox_callback instanceof Closure) {
2135
-                    $result = $metabox_callback();
2136
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2137
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2138
-                } else {
2139
-                    $result = call_user_func([$this, &$metabox_callback]);
2140
-                }
2141
-                if ($result === false) {
2142
-                    // user error msg
2143
-                    $error_msg = esc_html__(
2144
-                        'An error occurred. The  requested metabox could not be found.',
2145
-                        'event_espresso'
2146
-                    );
2147
-                    // developer error msg
2148
-                    $error_msg .= '||'
2149
-                                  . sprintf(
2150
-                                      esc_html__(
2151
-                                          '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.',
2152
-                                          'event_espresso'
2153
-                                      ),
2154
-                                      $metabox_callback
2155
-                                  );
2156
-                    throw new EE_Error($error_msg);
2157
-                }
2158
-            }
2159
-        }
2160
-    }
2161
-
2162
-
2163
-    /**
2164
-     * _add_screen_columns
2165
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2166
-     * the dynamic column template and we'll setup the column options for the page.
2167
-     *
2168
-     * @return void
2169
-     */
2170
-    private function _add_screen_columns()
2171
-    {
2172
-        if (
2173
-            is_array($this->_route_config)
2174
-            && isset($this->_route_config['columns'])
2175
-            && is_array($this->_route_config['columns'])
2176
-            && count($this->_route_config['columns']) === 2
2177
-        ) {
2178
-            add_screen_option(
2179
-                'layout_columns',
2180
-                [
2181
-                    'max'     => (int) $this->_route_config['columns'][0],
2182
-                    'default' => (int) $this->_route_config['columns'][1],
2183
-                ]
2184
-            );
2185
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2186
-            $screen_id                                           = $this->_current_screen->id;
2187
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2188
-            $total_columns                                       = ! empty($screen_columns)
2189
-                ? $screen_columns
2190
-                : $this->_route_config['columns'][1];
2191
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2192
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2193
-            $this->_template_args['screen']                      = $this->_current_screen;
2194
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2195
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2196
-            // finally if we don't have has_metaboxes set in the route config
2197
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2198
-            $this->_route_config['has_metaboxes'] = true;
2199
-        }
2200
-    }
2201
-
2202
-
2203
-
2204
-    /** GLOBALLY AVAILABLE METABOXES **/
2205
-
2206
-
2207
-    /**
2208
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2209
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2210
-     * these get loaded on.
2211
-     */
2212
-    private function _espresso_news_post_box()
2213
-    {
2214
-        $news_box_title = apply_filters(
2215
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2216
-            esc_html__('New @ Event Espresso', 'event_espresso')
2217
-        );
2218
-        add_meta_box(
2219
-            'espresso_news_post_box',
2220
-            $news_box_title,
2221
-            [
2222
-                $this,
2223
-                'espresso_news_post_box',
2224
-            ],
2225
-            $this->_wp_page_slug,
2226
-            'side'
2227
-        );
2228
-    }
2229
-
2230
-
2231
-    /**
2232
-     * Code for setting up espresso ratings request metabox.
2233
-     */
2234
-    protected function _espresso_ratings_request()
2235
-    {
2236
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2237
-            return;
2238
-        }
2239
-        $ratings_box_title = apply_filters(
2240
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2241
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2242
-        );
2243
-        add_meta_box(
2244
-            'espresso_ratings_request',
2245
-            $ratings_box_title,
2246
-            [
2247
-                $this,
2248
-                'espresso_ratings_request',
2249
-            ],
2250
-            $this->_wp_page_slug,
2251
-            'side'
2252
-        );
2253
-    }
2254
-
2255
-
2256
-    /**
2257
-     * Code for setting up espresso ratings request metabox content.
2258
-     *
2259
-     * @throws DomainException
2260
-     */
2261
-    public function espresso_ratings_request()
2262
-    {
2263
-        EEH_Template::display_template(
2264
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2265
-            []
2266
-        );
2267
-    }
2268
-
2269
-
2270
-    public static function cached_rss_display($rss_id, $url)
2271
-    {
2272
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2273
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2274
-                     . '</p><p class="hide-if-js">'
2275
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2276
-                     . '</p>';
2277
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2278
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2279
-        $post      = '</div>' . "\n";
2280
-        $cache_key = 'ee_rss_' . md5($rss_id);
2281
-        $output    = get_transient($cache_key);
2282
-        if ($output !== false) {
2283
-            echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2284
-            return true;
2285
-        }
2286
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2287
-            echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2288
-            return false;
2289
-        }
2290
-        ob_start();
2291
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2292
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2293
-        return true;
2294
-    }
2295
-
2296
-
2297
-    public function espresso_news_post_box()
2298
-    {
2299
-        ?>
2087
+		return $entries_per_page_dropdown;
2088
+	}
2089
+
2090
+
2091
+	/**
2092
+	 *        _set_search_attributes
2093
+	 *
2094
+	 * @return        void
2095
+	 */
2096
+	public function _set_search_attributes()
2097
+	{
2098
+		$this->_template_args['search']['btn_label'] = sprintf(
2099
+			esc_html__('Search %s', 'event_espresso'),
2100
+			empty($this->_search_btn_label) ? $this->page_label
2101
+				: $this->_search_btn_label
2102
+		);
2103
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2104
+	}
2105
+
2106
+
2107
+
2108
+	/*** END LIST TABLE METHODS **/
2109
+
2110
+
2111
+	/**
2112
+	 * _add_registered_metaboxes
2113
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2114
+	 *
2115
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2116
+	 * @return void
2117
+	 * @throws EE_Error
2118
+	 */
2119
+	private function _add_registered_meta_boxes()
2120
+	{
2121
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2122
+		// we only add meta boxes if the page_route calls for it
2123
+		if (
2124
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2125
+			&& is_array(
2126
+				$this->_route_config['metaboxes']
2127
+			)
2128
+		) {
2129
+			// this simply loops through the callbacks provided
2130
+			// and checks if there is a corresponding callback registered by the child
2131
+			// if there is then we go ahead and process the metabox loader.
2132
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2133
+				// first check for Closures
2134
+				if ($metabox_callback instanceof Closure) {
2135
+					$result = $metabox_callback();
2136
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2137
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2138
+				} else {
2139
+					$result = call_user_func([$this, &$metabox_callback]);
2140
+				}
2141
+				if ($result === false) {
2142
+					// user error msg
2143
+					$error_msg = esc_html__(
2144
+						'An error occurred. The  requested metabox could not be found.',
2145
+						'event_espresso'
2146
+					);
2147
+					// developer error msg
2148
+					$error_msg .= '||'
2149
+								  . sprintf(
2150
+									  esc_html__(
2151
+										  '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.',
2152
+										  'event_espresso'
2153
+									  ),
2154
+									  $metabox_callback
2155
+								  );
2156
+					throw new EE_Error($error_msg);
2157
+				}
2158
+			}
2159
+		}
2160
+	}
2161
+
2162
+
2163
+	/**
2164
+	 * _add_screen_columns
2165
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2166
+	 * the dynamic column template and we'll setup the column options for the page.
2167
+	 *
2168
+	 * @return void
2169
+	 */
2170
+	private function _add_screen_columns()
2171
+	{
2172
+		if (
2173
+			is_array($this->_route_config)
2174
+			&& isset($this->_route_config['columns'])
2175
+			&& is_array($this->_route_config['columns'])
2176
+			&& count($this->_route_config['columns']) === 2
2177
+		) {
2178
+			add_screen_option(
2179
+				'layout_columns',
2180
+				[
2181
+					'max'     => (int) $this->_route_config['columns'][0],
2182
+					'default' => (int) $this->_route_config['columns'][1],
2183
+				]
2184
+			);
2185
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2186
+			$screen_id                                           = $this->_current_screen->id;
2187
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2188
+			$total_columns                                       = ! empty($screen_columns)
2189
+				? $screen_columns
2190
+				: $this->_route_config['columns'][1];
2191
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2192
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2193
+			$this->_template_args['screen']                      = $this->_current_screen;
2194
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2195
+																   . 'admin_details_metabox_column_wrapper.template.php';
2196
+			// finally if we don't have has_metaboxes set in the route config
2197
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2198
+			$this->_route_config['has_metaboxes'] = true;
2199
+		}
2200
+	}
2201
+
2202
+
2203
+
2204
+	/** GLOBALLY AVAILABLE METABOXES **/
2205
+
2206
+
2207
+	/**
2208
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2209
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2210
+	 * these get loaded on.
2211
+	 */
2212
+	private function _espresso_news_post_box()
2213
+	{
2214
+		$news_box_title = apply_filters(
2215
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2216
+			esc_html__('New @ Event Espresso', 'event_espresso')
2217
+		);
2218
+		add_meta_box(
2219
+			'espresso_news_post_box',
2220
+			$news_box_title,
2221
+			[
2222
+				$this,
2223
+				'espresso_news_post_box',
2224
+			],
2225
+			$this->_wp_page_slug,
2226
+			'side'
2227
+		);
2228
+	}
2229
+
2230
+
2231
+	/**
2232
+	 * Code for setting up espresso ratings request metabox.
2233
+	 */
2234
+	protected function _espresso_ratings_request()
2235
+	{
2236
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2237
+			return;
2238
+		}
2239
+		$ratings_box_title = apply_filters(
2240
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2241
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2242
+		);
2243
+		add_meta_box(
2244
+			'espresso_ratings_request',
2245
+			$ratings_box_title,
2246
+			[
2247
+				$this,
2248
+				'espresso_ratings_request',
2249
+			],
2250
+			$this->_wp_page_slug,
2251
+			'side'
2252
+		);
2253
+	}
2254
+
2255
+
2256
+	/**
2257
+	 * Code for setting up espresso ratings request metabox content.
2258
+	 *
2259
+	 * @throws DomainException
2260
+	 */
2261
+	public function espresso_ratings_request()
2262
+	{
2263
+		EEH_Template::display_template(
2264
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2265
+			[]
2266
+		);
2267
+	}
2268
+
2269
+
2270
+	public static function cached_rss_display($rss_id, $url)
2271
+	{
2272
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2273
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2274
+					 . '</p><p class="hide-if-js">'
2275
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2276
+					 . '</p>';
2277
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2278
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2279
+		$post      = '</div>' . "\n";
2280
+		$cache_key = 'ee_rss_' . md5($rss_id);
2281
+		$output    = get_transient($cache_key);
2282
+		if ($output !== false) {
2283
+			echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2284
+			return true;
2285
+		}
2286
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2287
+			echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2288
+			return false;
2289
+		}
2290
+		ob_start();
2291
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2292
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2293
+		return true;
2294
+	}
2295
+
2296
+
2297
+	public function espresso_news_post_box()
2298
+	{
2299
+		?>
2300 2300
         <div class="padding">
2301 2301
             <div id="espresso_news_post_box_content" class="infolinks">
2302 2302
                 <?php
2303
-                // Get RSS Feed(s)
2304
-                self::cached_rss_display(
2305
-                    'espresso_news_post_box_content',
2306
-                    esc_url_raw(
2307
-                        apply_filters(
2308
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2309
-                            'https://eventespresso.com/feed/'
2310
-                        )
2311
-                    )
2312
-                );
2313
-                ?>
2303
+				// Get RSS Feed(s)
2304
+				self::cached_rss_display(
2305
+					'espresso_news_post_box_content',
2306
+					esc_url_raw(
2307
+						apply_filters(
2308
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2309
+							'https://eventespresso.com/feed/'
2310
+						)
2311
+					)
2312
+				);
2313
+				?>
2314 2314
             </div>
2315 2315
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2316 2316
         </div>
2317 2317
         <?php
2318
-    }
2319
-
2320
-
2321
-    private function _espresso_links_post_box()
2322
-    {
2323
-        // Hiding until we actually have content to put in here...
2324
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2325
-    }
2326
-
2327
-
2328
-    public function espresso_links_post_box()
2329
-    {
2330
-        // Hiding until we actually have content to put in here...
2331
-        // EEH_Template::display_template(
2332
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2333
-        // );
2334
-    }
2335
-
2336
-
2337
-    protected function _espresso_sponsors_post_box()
2338
-    {
2339
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2340
-            add_meta_box(
2341
-                'espresso_sponsors_post_box',
2342
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2343
-                [$this, 'espresso_sponsors_post_box'],
2344
-                $this->_wp_page_slug,
2345
-                'side'
2346
-            );
2347
-        }
2348
-    }
2349
-
2350
-
2351
-    public function espresso_sponsors_post_box()
2352
-    {
2353
-        EEH_Template::display_template(
2354
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2355
-        );
2356
-    }
2357
-
2358
-
2359
-    private function _publish_post_box()
2360
-    {
2361
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2362
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2363
-        // then we'll use that for the metabox label.
2364
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2365
-        if (! empty($this->_labels['publishbox'])) {
2366
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2367
-                : $this->_labels['publishbox'];
2368
-        } else {
2369
-            $box_label = esc_html__('Publish', 'event_espresso');
2370
-        }
2371
-        $box_label = apply_filters(
2372
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2373
-            $box_label,
2374
-            $this->_req_action,
2375
-            $this
2376
-        );
2377
-        add_meta_box(
2378
-            $meta_box_ref,
2379
-            $box_label,
2380
-            [$this, 'editor_overview'],
2381
-            $this->_current_screen->id,
2382
-            'side',
2383
-            'high'
2384
-        );
2385
-    }
2386
-
2387
-
2388
-    public function editor_overview()
2389
-    {
2390
-        // if we have extra content set let's add it in if not make sure its empty
2391
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2392
-            ? $this->_template_args['publish_box_extra_content']
2393
-            : '';
2394
-        echo EEH_Template::display_template(
2395
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2396
-            $this->_template_args,
2397
-            true
2398
-        );
2399
-    }
2400
-
2401
-
2402
-    /** end of globally available metaboxes section **/
2403
-
2404
-
2405
-    /**
2406
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2407
-     * protected method.
2408
-     *
2409
-     * @param string $name
2410
-     * @param int    $id
2411
-     * @param bool   $delete
2412
-     * @param string $save_close_redirect_URL
2413
-     * @param bool   $both_btns
2414
-     * @throws EE_Error
2415
-     * @throws InvalidArgumentException
2416
-     * @throws InvalidDataTypeException
2417
-     * @throws InvalidInterfaceException
2418
-     * @see   $this->_set_publish_post_box_vars for param details
2419
-     * @since 4.6.0
2420
-     */
2421
-    public function set_publish_post_box_vars(
2422
-        $name = '',
2423
-        $id = 0,
2424
-        $delete = false,
2425
-        $save_close_redirect_URL = '',
2426
-        $both_btns = true
2427
-    ) {
2428
-        $this->_set_publish_post_box_vars(
2429
-            $name,
2430
-            $id,
2431
-            $delete,
2432
-            $save_close_redirect_URL,
2433
-            $both_btns
2434
-        );
2435
-    }
2436
-
2437
-
2438
-    /**
2439
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2440
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2441
-     * save, and save and close buttons to work properly, then you will want to include a
2442
-     * values for the name and id arguments.
2443
-     *
2444
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2445
-     * @param int     $id                         id attached to the item published
2446
-     * @param string  $delete                     page route callback for the delete action
2447
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2448
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2449
-     *                                            the Save button
2450
-     * @throws EE_Error
2451
-     * @throws InvalidArgumentException
2452
-     * @throws InvalidDataTypeException
2453
-     * @throws InvalidInterfaceException
2454
-     * @todo  Add in validation for name/id arguments.
2455
-     */
2456
-    protected function _set_publish_post_box_vars(
2457
-        $name = '',
2458
-        $id = 0,
2459
-        $delete = '',
2460
-        $save_close_redirect_URL = '',
2461
-        $both_btns = true
2462
-    ) {
2463
-        // if Save & Close, use a custom redirect URL or default to the main page?
2464
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2465
-            ? $save_close_redirect_URL
2466
-            : $this->_admin_base_url;
2467
-        // create the Save & Close and Save buttons
2468
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2469
-        // if we have extra content set let's add it in if not make sure its empty
2470
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2471
-            ? $this->_template_args['publish_box_extra_content']
2472
-            : '';
2473
-        if ($delete && ! empty($id)) {
2474
-            // make sure we have a default if just true is sent.
2475
-            $delete           = ! empty($delete) ? $delete : 'delete';
2476
-            $delete_link_args = [$name => $id];
2477
-            $delete           = $this->get_action_link_or_button(
2478
-                $delete,
2479
-                $delete,
2480
-                $delete_link_args,
2481
-                'submitdelete deletion',
2482
-                '',
2483
-                false
2484
-            );
2485
-        }
2486
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2487
-        if (! empty($name) && ! empty($id)) {
2488
-            $hidden_field_arr[ $name ] = [
2489
-                'type'  => 'hidden',
2490
-                'value' => $id,
2491
-            ];
2492
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2493
-        } else {
2494
-            $hf = '';
2495
-        }
2496
-        // add hidden field
2497
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2498
-            ? $hf[ $name ]['field']
2499
-            : $hf;
2500
-    }
2501
-
2502
-
2503
-    /**
2504
-     * displays an error message to ppl who have javascript disabled
2505
-     *
2506
-     * @return void
2507
-     */
2508
-    private function _display_no_javascript_warning()
2509
-    {
2510
-        ?>
2318
+	}
2319
+
2320
+
2321
+	private function _espresso_links_post_box()
2322
+	{
2323
+		// Hiding until we actually have content to put in here...
2324
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2325
+	}
2326
+
2327
+
2328
+	public function espresso_links_post_box()
2329
+	{
2330
+		// Hiding until we actually have content to put in here...
2331
+		// EEH_Template::display_template(
2332
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2333
+		// );
2334
+	}
2335
+
2336
+
2337
+	protected function _espresso_sponsors_post_box()
2338
+	{
2339
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2340
+			add_meta_box(
2341
+				'espresso_sponsors_post_box',
2342
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2343
+				[$this, 'espresso_sponsors_post_box'],
2344
+				$this->_wp_page_slug,
2345
+				'side'
2346
+			);
2347
+		}
2348
+	}
2349
+
2350
+
2351
+	public function espresso_sponsors_post_box()
2352
+	{
2353
+		EEH_Template::display_template(
2354
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2355
+		);
2356
+	}
2357
+
2358
+
2359
+	private function _publish_post_box()
2360
+	{
2361
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2362
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2363
+		// then we'll use that for the metabox label.
2364
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2365
+		if (! empty($this->_labels['publishbox'])) {
2366
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2367
+				: $this->_labels['publishbox'];
2368
+		} else {
2369
+			$box_label = esc_html__('Publish', 'event_espresso');
2370
+		}
2371
+		$box_label = apply_filters(
2372
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2373
+			$box_label,
2374
+			$this->_req_action,
2375
+			$this
2376
+		);
2377
+		add_meta_box(
2378
+			$meta_box_ref,
2379
+			$box_label,
2380
+			[$this, 'editor_overview'],
2381
+			$this->_current_screen->id,
2382
+			'side',
2383
+			'high'
2384
+		);
2385
+	}
2386
+
2387
+
2388
+	public function editor_overview()
2389
+	{
2390
+		// if we have extra content set let's add it in if not make sure its empty
2391
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2392
+			? $this->_template_args['publish_box_extra_content']
2393
+			: '';
2394
+		echo EEH_Template::display_template(
2395
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2396
+			$this->_template_args,
2397
+			true
2398
+		);
2399
+	}
2400
+
2401
+
2402
+	/** end of globally available metaboxes section **/
2403
+
2404
+
2405
+	/**
2406
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2407
+	 * protected method.
2408
+	 *
2409
+	 * @param string $name
2410
+	 * @param int    $id
2411
+	 * @param bool   $delete
2412
+	 * @param string $save_close_redirect_URL
2413
+	 * @param bool   $both_btns
2414
+	 * @throws EE_Error
2415
+	 * @throws InvalidArgumentException
2416
+	 * @throws InvalidDataTypeException
2417
+	 * @throws InvalidInterfaceException
2418
+	 * @see   $this->_set_publish_post_box_vars for param details
2419
+	 * @since 4.6.0
2420
+	 */
2421
+	public function set_publish_post_box_vars(
2422
+		$name = '',
2423
+		$id = 0,
2424
+		$delete = false,
2425
+		$save_close_redirect_URL = '',
2426
+		$both_btns = true
2427
+	) {
2428
+		$this->_set_publish_post_box_vars(
2429
+			$name,
2430
+			$id,
2431
+			$delete,
2432
+			$save_close_redirect_URL,
2433
+			$both_btns
2434
+		);
2435
+	}
2436
+
2437
+
2438
+	/**
2439
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2440
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2441
+	 * save, and save and close buttons to work properly, then you will want to include a
2442
+	 * values for the name and id arguments.
2443
+	 *
2444
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2445
+	 * @param int     $id                         id attached to the item published
2446
+	 * @param string  $delete                     page route callback for the delete action
2447
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2448
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2449
+	 *                                            the Save button
2450
+	 * @throws EE_Error
2451
+	 * @throws InvalidArgumentException
2452
+	 * @throws InvalidDataTypeException
2453
+	 * @throws InvalidInterfaceException
2454
+	 * @todo  Add in validation for name/id arguments.
2455
+	 */
2456
+	protected function _set_publish_post_box_vars(
2457
+		$name = '',
2458
+		$id = 0,
2459
+		$delete = '',
2460
+		$save_close_redirect_URL = '',
2461
+		$both_btns = true
2462
+	) {
2463
+		// if Save & Close, use a custom redirect URL or default to the main page?
2464
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2465
+			? $save_close_redirect_URL
2466
+			: $this->_admin_base_url;
2467
+		// create the Save & Close and Save buttons
2468
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2469
+		// if we have extra content set let's add it in if not make sure its empty
2470
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2471
+			? $this->_template_args['publish_box_extra_content']
2472
+			: '';
2473
+		if ($delete && ! empty($id)) {
2474
+			// make sure we have a default if just true is sent.
2475
+			$delete           = ! empty($delete) ? $delete : 'delete';
2476
+			$delete_link_args = [$name => $id];
2477
+			$delete           = $this->get_action_link_or_button(
2478
+				$delete,
2479
+				$delete,
2480
+				$delete_link_args,
2481
+				'submitdelete deletion',
2482
+				'',
2483
+				false
2484
+			);
2485
+		}
2486
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2487
+		if (! empty($name) && ! empty($id)) {
2488
+			$hidden_field_arr[ $name ] = [
2489
+				'type'  => 'hidden',
2490
+				'value' => $id,
2491
+			];
2492
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2493
+		} else {
2494
+			$hf = '';
2495
+		}
2496
+		// add hidden field
2497
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2498
+			? $hf[ $name ]['field']
2499
+			: $hf;
2500
+	}
2501
+
2502
+
2503
+	/**
2504
+	 * displays an error message to ppl who have javascript disabled
2505
+	 *
2506
+	 * @return void
2507
+	 */
2508
+	private function _display_no_javascript_warning()
2509
+	{
2510
+		?>
2511 2511
         <noscript>
2512 2512
             <div id="no-js-message" class="error">
2513 2513
                 <p style="font-size:1.3em;">
2514 2514
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2515 2515
                     <?php esc_html_e(
2516
-                        '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.',
2517
-                        'event_espresso'
2518
-                    ); ?>
2516
+						'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.',
2517
+						'event_espresso'
2518
+					); ?>
2519 2519
                 </p>
2520 2520
             </div>
2521 2521
         </noscript>
2522 2522
         <?php
2523
-    }
2524
-
2525
-
2526
-    /**
2527
-     * displays espresso success and/or error notices
2528
-     *
2529
-     * @return void
2530
-     */
2531
-    protected function _display_espresso_notices()
2532
-    {
2533
-        $notices = $this->_get_transient(true);
2534
-        echo stripslashes($notices);
2535
-    }
2536
-
2537
-
2538
-    /**
2539
-     * spinny things pacify the masses
2540
-     *
2541
-     * @return void
2542
-     */
2543
-    protected function _add_admin_page_ajax_loading_img()
2544
-    {
2545
-        ?>
2523
+	}
2524
+
2525
+
2526
+	/**
2527
+	 * displays espresso success and/or error notices
2528
+	 *
2529
+	 * @return void
2530
+	 */
2531
+	protected function _display_espresso_notices()
2532
+	{
2533
+		$notices = $this->_get_transient(true);
2534
+		echo stripslashes($notices);
2535
+	}
2536
+
2537
+
2538
+	/**
2539
+	 * spinny things pacify the masses
2540
+	 *
2541
+	 * @return void
2542
+	 */
2543
+	protected function _add_admin_page_ajax_loading_img()
2544
+	{
2545
+		?>
2546 2546
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2547 2547
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2548
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2548
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2549 2549
         </div>
2550 2550
         <?php
2551
-    }
2551
+	}
2552 2552
 
2553 2553
 
2554
-    /**
2555
-     * add admin page overlay for modal boxes
2556
-     *
2557
-     * @return void
2558
-     */
2559
-    protected function _add_admin_page_overlay()
2560
-    {
2561
-        ?>
2554
+	/**
2555
+	 * add admin page overlay for modal boxes
2556
+	 *
2557
+	 * @return void
2558
+	 */
2559
+	protected function _add_admin_page_overlay()
2560
+	{
2561
+		?>
2562 2562
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2563 2563
         <?php
2564
-    }
2565
-
2566
-
2567
-    /**
2568
-     * facade for add_meta_box
2569
-     *
2570
-     * @param string  $action        where the metabox gets displayed
2571
-     * @param string  $title         Title of Metabox (output in metabox header)
2572
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2573
-     *                               instead of the one created in here.
2574
-     * @param array   $callback_args an array of args supplied for the metabox
2575
-     * @param string  $column        what metabox column
2576
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2577
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2578
-     *                               created but just set our own callback for wp's add_meta_box.
2579
-     * @throws DomainException
2580
-     */
2581
-    public function _add_admin_page_meta_box(
2582
-        $action,
2583
-        $title,
2584
-        $callback,
2585
-        $callback_args,
2586
-        $column = 'normal',
2587
-        $priority = 'high',
2588
-        $create_func = true
2589
-    ) {
2590
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2591
-        // 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.
2592
-        if (empty($callback_args) && $create_func) {
2593
-            $callback_args = [
2594
-                'template_path' => $this->_template_path,
2595
-                'template_args' => $this->_template_args,
2596
-            ];
2597
-        }
2598
-        // 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)
2599
-        $call_back_func = $create_func
2600
-            ? function ($post, $metabox) {
2601
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2602
-                echo EEH_Template::display_template(
2603
-                    $metabox['args']['template_path'],
2604
-                    $metabox['args']['template_args'],
2605
-                    true
2606
-                );
2607
-            }
2608
-            : $callback;
2609
-        add_meta_box(
2610
-            str_replace('_', '-', $action) . '-mbox',
2611
-            $title,
2612
-            $call_back_func,
2613
-            $this->_wp_page_slug,
2614
-            $column,
2615
-            $priority,
2616
-            $callback_args
2617
-        );
2618
-    }
2619
-
2620
-
2621
-    /**
2622
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2623
-     *
2624
-     * @throws DomainException
2625
-     * @throws EE_Error
2626
-     */
2627
-    public function display_admin_page_with_metabox_columns()
2628
-    {
2629
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2630
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2631
-            $this->_column_template_path,
2632
-            $this->_template_args,
2633
-            true
2634
-        );
2635
-        // the final wrapper
2636
-        $this->admin_page_wrapper();
2637
-    }
2638
-
2639
-
2640
-    /**
2641
-     * generates  HTML wrapper for an admin details page
2642
-     *
2643
-     * @return void
2644
-     * @throws EE_Error
2645
-     * @throws DomainException
2646
-     */
2647
-    public function display_admin_page_with_sidebar()
2648
-    {
2649
-        $this->_display_admin_page(true);
2650
-    }
2651
-
2652
-
2653
-    /**
2654
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2655
-     *
2656
-     * @return void
2657
-     * @throws EE_Error
2658
-     * @throws DomainException
2659
-     */
2660
-    public function display_admin_page_with_no_sidebar()
2661
-    {
2662
-        $this->_display_admin_page();
2663
-    }
2664
-
2665
-
2666
-    /**
2667
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2668
-     *
2669
-     * @return void
2670
-     * @throws EE_Error
2671
-     * @throws DomainException
2672
-     */
2673
-    public function display_about_admin_page()
2674
-    {
2675
-        $this->_display_admin_page(false, true);
2676
-    }
2677
-
2678
-
2679
-    /**
2680
-     * display_admin_page
2681
-     * contains the code for actually displaying an admin page
2682
-     *
2683
-     * @param boolean $sidebar true with sidebar, false without
2684
-     * @param boolean $about   use the about_admin_wrapper instead of the default.
2685
-     * @return void
2686
-     * @throws DomainException
2687
-     * @throws EE_Error
2688
-     */
2689
-    private function _display_admin_page($sidebar = false, $about = false)
2690
-    {
2691
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2692
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2693
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2694
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2695
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2696
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2697
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2698
-            ? 'poststuff'
2699
-            : 'espresso-default-admin';
2700
-        $template_path                                     = $sidebar
2701
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2702
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2703
-        if ($this->request->isAjax()) {
2704
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2705
-        }
2706
-        $template_path                                     = ! empty($this->_column_template_path)
2707
-            ? $this->_column_template_path : $template_path;
2708
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2709
-            ? $this->_template_args['admin_page_content']
2710
-            : '';
2711
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2712
-            ? $this->_template_args['before_admin_page_content']
2713
-            : '';
2714
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2715
-            ? $this->_template_args['after_admin_page_content']
2716
-            : '';
2717
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2718
-            $template_path,
2719
-            $this->_template_args,
2720
-            true
2721
-        );
2722
-        // the final template wrapper
2723
-        $this->admin_page_wrapper($about);
2724
-    }
2725
-
2726
-
2727
-    /**
2728
-     * This is used to display caf preview pages.
2729
-     *
2730
-     * @param string $utm_campaign_source what is the key used for google analytics link
2731
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2732
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2733
-     * @return void
2734
-     * @throws DomainException
2735
-     * @throws EE_Error
2736
-     * @throws InvalidArgumentException
2737
-     * @throws InvalidDataTypeException
2738
-     * @throws InvalidInterfaceException
2739
-     * @since 4.3.2
2740
-     */
2741
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2742
-    {
2743
-        // let's generate a default preview action button if there isn't one already present.
2744
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2745
-            'Upgrade to Event Espresso 4 Right Now',
2746
-            'event_espresso'
2747
-        );
2748
-        $buy_now_url                                   = add_query_arg(
2749
-            [
2750
-                'ee_ver'       => 'ee4',
2751
-                'utm_source'   => 'ee4_plugin_admin',
2752
-                'utm_medium'   => 'link',
2753
-                'utm_campaign' => $utm_campaign_source,
2754
-                'utm_content'  => 'buy_now_button',
2755
-            ],
2756
-            'https://eventespresso.com/pricing/'
2757
-        );
2758
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2759
-            ? $this->get_action_link_or_button(
2760
-                '',
2761
-                'buy_now',
2762
-                [],
2763
-                'button-primary button-large',
2764
-                esc_url_raw($buy_now_url),
2765
-                true
2766
-            )
2767
-            : $this->_template_args['preview_action_button'];
2768
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2769
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2770
-            $this->_template_args,
2771
-            true
2772
-        );
2773
-        $this->_display_admin_page($display_sidebar);
2774
-    }
2775
-
2776
-
2777
-    /**
2778
-     * display_admin_list_table_page_with_sidebar
2779
-     * generates HTML wrapper for an admin_page with list_table
2780
-     *
2781
-     * @return void
2782
-     * @throws EE_Error
2783
-     * @throws DomainException
2784
-     */
2785
-    public function display_admin_list_table_page_with_sidebar()
2786
-    {
2787
-        $this->_display_admin_list_table_page(true);
2788
-    }
2789
-
2790
-
2791
-    /**
2792
-     * display_admin_list_table_page_with_no_sidebar
2793
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2794
-     *
2795
-     * @return void
2796
-     * @throws EE_Error
2797
-     * @throws DomainException
2798
-     */
2799
-    public function display_admin_list_table_page_with_no_sidebar()
2800
-    {
2801
-        $this->_display_admin_list_table_page();
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * generates html wrapper for an admin_list_table page
2807
-     *
2808
-     * @param boolean $sidebar whether to display with sidebar or not.
2809
-     * @return void
2810
-     * @throws DomainException
2811
-     * @throws EE_Error
2812
-     */
2813
-    private function _display_admin_list_table_page($sidebar = false)
2814
-    {
2815
-        // setup search attributes
2816
-        $this->_set_search_attributes();
2817
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2818
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2819
-        $this->_template_args['table_url']        = $this->request->isAjax()
2820
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2821
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2822
-        $this->_template_args['list_table']       = $this->_list_table_object;
2823
-        $this->_template_args['current_route']    = $this->_req_action;
2824
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2825
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2826
-        if (! empty($ajax_sorting_callback)) {
2827
-            $sortable_list_table_form_fields = wp_nonce_field(
2828
-                $ajax_sorting_callback . '_nonce',
2829
-                $ajax_sorting_callback . '_nonce',
2830
-                false,
2831
-                false
2832
-            );
2833
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2834
-                                                . $this->page_slug
2835
-                                                . '" />';
2836
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2837
-                                                . $ajax_sorting_callback
2838
-                                                . '" />';
2839
-        } else {
2840
-            $sortable_list_table_form_fields = '';
2841
-        }
2842
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2843
-        $hidden_form_fields                                      =
2844
-            isset($this->_template_args['list_table_hidden_fields'])
2845
-                ? $this->_template_args['list_table_hidden_fields']
2846
-                : '';
2847
-
2848
-        $nonce_ref          = $this->_req_action . '_nonce';
2849
-        $hidden_form_fields .= '
2564
+	}
2565
+
2566
+
2567
+	/**
2568
+	 * facade for add_meta_box
2569
+	 *
2570
+	 * @param string  $action        where the metabox gets displayed
2571
+	 * @param string  $title         Title of Metabox (output in metabox header)
2572
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2573
+	 *                               instead of the one created in here.
2574
+	 * @param array   $callback_args an array of args supplied for the metabox
2575
+	 * @param string  $column        what metabox column
2576
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2577
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2578
+	 *                               created but just set our own callback for wp's add_meta_box.
2579
+	 * @throws DomainException
2580
+	 */
2581
+	public function _add_admin_page_meta_box(
2582
+		$action,
2583
+		$title,
2584
+		$callback,
2585
+		$callback_args,
2586
+		$column = 'normal',
2587
+		$priority = 'high',
2588
+		$create_func = true
2589
+	) {
2590
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2591
+		// 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.
2592
+		if (empty($callback_args) && $create_func) {
2593
+			$callback_args = [
2594
+				'template_path' => $this->_template_path,
2595
+				'template_args' => $this->_template_args,
2596
+			];
2597
+		}
2598
+		// 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)
2599
+		$call_back_func = $create_func
2600
+			? function ($post, $metabox) {
2601
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2602
+				echo EEH_Template::display_template(
2603
+					$metabox['args']['template_path'],
2604
+					$metabox['args']['template_args'],
2605
+					true
2606
+				);
2607
+			}
2608
+			: $callback;
2609
+		add_meta_box(
2610
+			str_replace('_', '-', $action) . '-mbox',
2611
+			$title,
2612
+			$call_back_func,
2613
+			$this->_wp_page_slug,
2614
+			$column,
2615
+			$priority,
2616
+			$callback_args
2617
+		);
2618
+	}
2619
+
2620
+
2621
+	/**
2622
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2623
+	 *
2624
+	 * @throws DomainException
2625
+	 * @throws EE_Error
2626
+	 */
2627
+	public function display_admin_page_with_metabox_columns()
2628
+	{
2629
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2630
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2631
+			$this->_column_template_path,
2632
+			$this->_template_args,
2633
+			true
2634
+		);
2635
+		// the final wrapper
2636
+		$this->admin_page_wrapper();
2637
+	}
2638
+
2639
+
2640
+	/**
2641
+	 * generates  HTML wrapper for an admin details page
2642
+	 *
2643
+	 * @return void
2644
+	 * @throws EE_Error
2645
+	 * @throws DomainException
2646
+	 */
2647
+	public function display_admin_page_with_sidebar()
2648
+	{
2649
+		$this->_display_admin_page(true);
2650
+	}
2651
+
2652
+
2653
+	/**
2654
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2655
+	 *
2656
+	 * @return void
2657
+	 * @throws EE_Error
2658
+	 * @throws DomainException
2659
+	 */
2660
+	public function display_admin_page_with_no_sidebar()
2661
+	{
2662
+		$this->_display_admin_page();
2663
+	}
2664
+
2665
+
2666
+	/**
2667
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2668
+	 *
2669
+	 * @return void
2670
+	 * @throws EE_Error
2671
+	 * @throws DomainException
2672
+	 */
2673
+	public function display_about_admin_page()
2674
+	{
2675
+		$this->_display_admin_page(false, true);
2676
+	}
2677
+
2678
+
2679
+	/**
2680
+	 * display_admin_page
2681
+	 * contains the code for actually displaying an admin page
2682
+	 *
2683
+	 * @param boolean $sidebar true with sidebar, false without
2684
+	 * @param boolean $about   use the about_admin_wrapper instead of the default.
2685
+	 * @return void
2686
+	 * @throws DomainException
2687
+	 * @throws EE_Error
2688
+	 */
2689
+	private function _display_admin_page($sidebar = false, $about = false)
2690
+	{
2691
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2692
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2693
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2694
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2695
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2696
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2697
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2698
+			? 'poststuff'
2699
+			: 'espresso-default-admin';
2700
+		$template_path                                     = $sidebar
2701
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2702
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2703
+		if ($this->request->isAjax()) {
2704
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2705
+		}
2706
+		$template_path                                     = ! empty($this->_column_template_path)
2707
+			? $this->_column_template_path : $template_path;
2708
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2709
+			? $this->_template_args['admin_page_content']
2710
+			: '';
2711
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2712
+			? $this->_template_args['before_admin_page_content']
2713
+			: '';
2714
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2715
+			? $this->_template_args['after_admin_page_content']
2716
+			: '';
2717
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2718
+			$template_path,
2719
+			$this->_template_args,
2720
+			true
2721
+		);
2722
+		// the final template wrapper
2723
+		$this->admin_page_wrapper($about);
2724
+	}
2725
+
2726
+
2727
+	/**
2728
+	 * This is used to display caf preview pages.
2729
+	 *
2730
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2731
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2732
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2733
+	 * @return void
2734
+	 * @throws DomainException
2735
+	 * @throws EE_Error
2736
+	 * @throws InvalidArgumentException
2737
+	 * @throws InvalidDataTypeException
2738
+	 * @throws InvalidInterfaceException
2739
+	 * @since 4.3.2
2740
+	 */
2741
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2742
+	{
2743
+		// let's generate a default preview action button if there isn't one already present.
2744
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2745
+			'Upgrade to Event Espresso 4 Right Now',
2746
+			'event_espresso'
2747
+		);
2748
+		$buy_now_url                                   = add_query_arg(
2749
+			[
2750
+				'ee_ver'       => 'ee4',
2751
+				'utm_source'   => 'ee4_plugin_admin',
2752
+				'utm_medium'   => 'link',
2753
+				'utm_campaign' => $utm_campaign_source,
2754
+				'utm_content'  => 'buy_now_button',
2755
+			],
2756
+			'https://eventespresso.com/pricing/'
2757
+		);
2758
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2759
+			? $this->get_action_link_or_button(
2760
+				'',
2761
+				'buy_now',
2762
+				[],
2763
+				'button-primary button-large',
2764
+				esc_url_raw($buy_now_url),
2765
+				true
2766
+			)
2767
+			: $this->_template_args['preview_action_button'];
2768
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2769
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2770
+			$this->_template_args,
2771
+			true
2772
+		);
2773
+		$this->_display_admin_page($display_sidebar);
2774
+	}
2775
+
2776
+
2777
+	/**
2778
+	 * display_admin_list_table_page_with_sidebar
2779
+	 * generates HTML wrapper for an admin_page with list_table
2780
+	 *
2781
+	 * @return void
2782
+	 * @throws EE_Error
2783
+	 * @throws DomainException
2784
+	 */
2785
+	public function display_admin_list_table_page_with_sidebar()
2786
+	{
2787
+		$this->_display_admin_list_table_page(true);
2788
+	}
2789
+
2790
+
2791
+	/**
2792
+	 * display_admin_list_table_page_with_no_sidebar
2793
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2794
+	 *
2795
+	 * @return void
2796
+	 * @throws EE_Error
2797
+	 * @throws DomainException
2798
+	 */
2799
+	public function display_admin_list_table_page_with_no_sidebar()
2800
+	{
2801
+		$this->_display_admin_list_table_page();
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * generates html wrapper for an admin_list_table page
2807
+	 *
2808
+	 * @param boolean $sidebar whether to display with sidebar or not.
2809
+	 * @return void
2810
+	 * @throws DomainException
2811
+	 * @throws EE_Error
2812
+	 */
2813
+	private function _display_admin_list_table_page($sidebar = false)
2814
+	{
2815
+		// setup search attributes
2816
+		$this->_set_search_attributes();
2817
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2818
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2819
+		$this->_template_args['table_url']        = $this->request->isAjax()
2820
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2821
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2822
+		$this->_template_args['list_table']       = $this->_list_table_object;
2823
+		$this->_template_args['current_route']    = $this->_req_action;
2824
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2825
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2826
+		if (! empty($ajax_sorting_callback)) {
2827
+			$sortable_list_table_form_fields = wp_nonce_field(
2828
+				$ajax_sorting_callback . '_nonce',
2829
+				$ajax_sorting_callback . '_nonce',
2830
+				false,
2831
+				false
2832
+			);
2833
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2834
+												. $this->page_slug
2835
+												. '" />';
2836
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2837
+												. $ajax_sorting_callback
2838
+												. '" />';
2839
+		} else {
2840
+			$sortable_list_table_form_fields = '';
2841
+		}
2842
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2843
+		$hidden_form_fields                                      =
2844
+			isset($this->_template_args['list_table_hidden_fields'])
2845
+				? $this->_template_args['list_table_hidden_fields']
2846
+				: '';
2847
+
2848
+		$nonce_ref          = $this->_req_action . '_nonce';
2849
+		$hidden_form_fields .= '
2850 2850
             <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2851 2851
 
2852
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2853
-        // display message about search results?
2854
-        $search = $this->request->getRequestParam('s');
2855
-        $this->_template_args['before_list_table'] .= ! empty($search)
2856
-            ? '<p class="ee-search-results">' . sprintf(
2857
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2858
-                trim($search, '%')
2859
-            ) . '</p>'
2860
-            : '';
2861
-        // filter before_list_table template arg
2862
-        $this->_template_args['before_list_table'] = apply_filters(
2863
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2864
-            $this->_template_args['before_list_table'],
2865
-            $this->page_slug,
2866
-            $this->request->requestParams(),
2867
-            $this->_req_action
2868
-        );
2869
-        // convert to array and filter again
2870
-        // arrays are easier to inject new items in a specific location,
2871
-        // but would not be backwards compatible, so we have to add a new filter
2872
-        $this->_template_args['before_list_table'] = implode(
2873
-            " \n",
2874
-            (array) apply_filters(
2875
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2876
-                (array) $this->_template_args['before_list_table'],
2877
-                $this->page_slug,
2878
-                $this->request->requestParams(),
2879
-                $this->_req_action
2880
-            )
2881
-        );
2882
-        // filter after_list_table template arg
2883
-        $this->_template_args['after_list_table'] = apply_filters(
2884
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2885
-            $this->_template_args['after_list_table'],
2886
-            $this->page_slug,
2887
-            $this->request->requestParams(),
2888
-            $this->_req_action
2889
-        );
2890
-        // convert to array and filter again
2891
-        // arrays are easier to inject new items in a specific location,
2892
-        // but would not be backwards compatible, so we have to add a new filter
2893
-        $this->_template_args['after_list_table']   = implode(
2894
-            " \n",
2895
-            (array) apply_filters(
2896
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2897
-                (array) $this->_template_args['after_list_table'],
2898
-                $this->page_slug,
2899
-                $this->request->requestParams(),
2900
-                $this->_req_action
2901
-            )
2902
-        );
2903
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2904
-            $template_path,
2905
-            $this->_template_args,
2906
-            true
2907
-        );
2908
-        // the final template wrapper
2909
-        if ($sidebar) {
2910
-            $this->display_admin_page_with_sidebar();
2911
-        } else {
2912
-            $this->display_admin_page_with_no_sidebar();
2913
-        }
2914
-    }
2915
-
2916
-
2917
-    /**
2918
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2919
-     * html string for the legend.
2920
-     * $items are expected in an array in the following format:
2921
-     * $legend_items = array(
2922
-     *        'item_id' => array(
2923
-     *            'icon' => 'http://url_to_icon_being_described.png',
2924
-     *            'desc' => esc_html__('localized description of item');
2925
-     *        )
2926
-     * );
2927
-     *
2928
-     * @param array $items see above for format of array
2929
-     * @return string html string of legend
2930
-     * @throws DomainException
2931
-     */
2932
-    protected function _display_legend($items)
2933
-    {
2934
-        $this->_template_args['items'] = apply_filters(
2935
-            'FHEE__EE_Admin_Page___display_legend__items',
2936
-            (array) $items,
2937
-            $this
2938
-        );
2939
-        return EEH_Template::display_template(
2940
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2941
-            $this->_template_args,
2942
-            true
2943
-        );
2944
-    }
2945
-
2946
-
2947
-    /**
2948
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2949
-     * The returned json object is created from an array in the following format:
2950
-     * array(
2951
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2952
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2953
-     *  'notices' => '', // - contains any EE_Error formatted notices
2954
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2955
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2956
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
2957
-     *  that might be included in here)
2958
-     * )
2959
-     * The json object is populated by whatever is set in the $_template_args property.
2960
-     *
2961
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2962
-     *                                 instead of displayed.
2963
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2964
-     * @return void
2965
-     * @throws EE_Error
2966
-     */
2967
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
2968
-    {
2969
-        // make sure any EE_Error notices have been handled.
2970
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2971
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
2972
-        unset($this->_template_args['data']);
2973
-        $json = [
2974
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2975
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2976
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2977
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2978
-            'notices'   => EE_Error::get_notices(),
2979
-            'content'   => isset($this->_template_args['admin_page_content'])
2980
-                ? $this->_template_args['admin_page_content'] : '',
2981
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
2982
-            'isEEajax'  => true
2983
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2984
-        ];
2985
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2986
-        if (null === error_get_last() || ! headers_sent()) {
2987
-            header('Content-Type: application/json; charset=UTF-8');
2988
-        }
2989
-        echo wp_json_encode($json);
2990
-        exit();
2991
-    }
2992
-
2993
-
2994
-    /**
2995
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2996
-     *
2997
-     * @return void
2998
-     * @throws EE_Error
2999
-     */
3000
-    public function return_json()
3001
-    {
3002
-        if ($this->request->isAjax()) {
3003
-            $this->_return_json();
3004
-        } else {
3005
-            throw new EE_Error(
3006
-                sprintf(
3007
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3008
-                    __FUNCTION__
3009
-                )
3010
-            );
3011
-        }
3012
-    }
3013
-
3014
-
3015
-    /**
3016
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3017
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3018
-     *
3019
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3020
-     */
3021
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3022
-    {
3023
-        $this->_hook_obj = $hook_obj;
3024
-    }
3025
-
3026
-
3027
-    /**
3028
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3029
-     *
3030
-     * @param boolean $about whether to use the special about page wrapper or default.
3031
-     * @return void
3032
-     * @throws DomainException
3033
-     * @throws EE_Error
3034
-     */
3035
-    public function admin_page_wrapper($about = false)
3036
-    {
3037
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3038
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3039
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3040
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3041
-
3042
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3043
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3044
-            isset($this->_template_args['before_admin_page_content'])
3045
-                ? $this->_template_args['before_admin_page_content']
3046
-                : ''
3047
-        );
3048
-
3049
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3050
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3051
-            isset($this->_template_args['after_admin_page_content'])
3052
-                ? $this->_template_args['after_admin_page_content']
3053
-                : ''
3054
-        );
3055
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3056
-
3057
-        if ($this->request->isAjax()) {
3058
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3059
-                // $template_path,
3060
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3061
-                $this->_template_args,
3062
-                true
3063
-            );
3064
-            $this->_return_json();
3065
-        }
3066
-        // load settings page wrapper template
3067
-        $template_path = $about
3068
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3069
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3070
-
3071
-        EEH_Template::display_template($template_path, $this->_template_args);
3072
-    }
3073
-
3074
-
3075
-    /**
3076
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3077
-     *
3078
-     * @return string html
3079
-     * @throws EE_Error
3080
-     */
3081
-    protected function _get_main_nav_tabs()
3082
-    {
3083
-        // let's generate the html using the EEH_Tabbed_Content helper.
3084
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3085
-        // (rather than setting in the page_routes array)
3086
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3087
-    }
3088
-
3089
-
3090
-    /**
3091
-     *        sort nav tabs
3092
-     *
3093
-     * @param $a
3094
-     * @param $b
3095
-     * @return int
3096
-     */
3097
-    private function _sort_nav_tabs($a, $b)
3098
-    {
3099
-        if ($a['order'] === $b['order']) {
3100
-            return 0;
3101
-        }
3102
-        return ($a['order'] < $b['order']) ? -1 : 1;
3103
-    }
3104
-
3105
-
3106
-    /**
3107
-     *    generates HTML for the forms used on admin pages
3108
-     *
3109
-     * @param array  $input_vars   - array of input field details
3110
-     * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3111
-     *                             use)
3112
-     * @param bool   $id
3113
-     * @return array|string
3114
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3115
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3116
-     */
3117
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3118
-    {
3119
-        return $generator === 'string'
3120
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3121
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3122
-    }
3123
-
3124
-
3125
-    /**
3126
-     * generates the "Save" and "Save & Close" buttons for edit forms
3127
-     *
3128
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3129
-     *                                   Close" button.
3130
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3131
-     *                                   'Save', [1] => 'save & close')
3132
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3133
-     *                                   via the "name" value in the button).  We can also use this to just dump
3134
-     *                                   default actions by submitting some other value.
3135
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3136
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3137
-     *                                   close (normal form handling).
3138
-     */
3139
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3140
-    {
3141
-        // make sure $text and $actions are in an array
3142
-        $text          = (array) $text;
3143
-        $actions       = (array) $actions;
3144
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3145
-        $button_text   = ! empty($text)
3146
-            ? $text
3147
-            : [
3148
-                esc_html__('Save', 'event_espresso'),
3149
-                esc_html__('Save and Close', 'event_espresso'),
3150
-            ];
3151
-        $default_names = ['save', 'save_and_close'];
3152
-        $buttons = '';
3153
-        foreach ($button_text as $key => $button) {
3154
-            $ref     = $default_names[ $key ];
3155
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3156
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3157
-                        . 'value="' . $button . '" name="' . $name . '" '
3158
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3159
-            if (! $both) {
3160
-                break;
3161
-            }
3162
-        }
3163
-        // add in a hidden index for the current page (so save and close redirects properly)
3164
-        $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3165
-                   . $referrer_url
3166
-                   . '" />';
3167
-        $this->_template_args['save_buttons'] = $buttons;
3168
-    }
3169
-
3170
-
3171
-    /**
3172
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3173
-     *
3174
-     * @param string $route
3175
-     * @param array  $additional_hidden_fields
3176
-     * @see   $this->_set_add_edit_form_tags() for details on params
3177
-     * @since 4.6.0
3178
-     */
3179
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3180
-    {
3181
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3182
-    }
3183
-
3184
-
3185
-    /**
3186
-     * set form open and close tags on add/edit pages.
3187
-     *
3188
-     * @param string $route                    the route you want the form to direct to
3189
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3190
-     * @return void
3191
-     */
3192
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3193
-    {
3194
-        if (empty($route)) {
3195
-            $user_msg = esc_html__(
3196
-                'An error occurred. No action was set for this page\'s form.',
3197
-                'event_espresso'
3198
-            );
3199
-            $dev_msg  = $user_msg . "\n"
3200
-                        . sprintf(
3201
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3202
-                            __FUNCTION__,
3203
-                            __CLASS__
3204
-                        );
3205
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3206
-        }
3207
-        // open form
3208
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3209
-                                                             . $this->_admin_base_url
3210
-                                                             . '" id="'
3211
-                                                             . $route
3212
-                                                             . '_event_form" >';
3213
-        // add nonce
3214
-        $nonce                                             =
3215
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3216
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3217
-        // add REQUIRED form action
3218
-        $hidden_fields = [
3219
-            'action' => ['type' => 'hidden', 'value' => $route],
3220
-        ];
3221
-        // merge arrays
3222
-        $hidden_fields = is_array($additional_hidden_fields)
3223
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3224
-            : $hidden_fields;
3225
-        // generate form fields
3226
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3227
-        // add fields to form
3228
-        foreach ((array) $form_fields as $form_field) {
3229
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3230
-        }
3231
-        // close form
3232
-        $this->_template_args['after_admin_page_content'] = '</form>';
3233
-    }
3234
-
3235
-
3236
-    /**
3237
-     * Public Wrapper for _redirect_after_action() method since its
3238
-     * discovered it would be useful for external code to have access.
3239
-     *
3240
-     * @param bool   $success
3241
-     * @param string $what
3242
-     * @param string $action_desc
3243
-     * @param array  $query_args
3244
-     * @param bool   $override_overwrite
3245
-     * @throws EE_Error
3246
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3247
-     * @since 4.5.0
3248
-     */
3249
-    public function redirect_after_action(
3250
-        $success = false,
3251
-        $what = 'item',
3252
-        $action_desc = 'processed',
3253
-        $query_args = [],
3254
-        $override_overwrite = false
3255
-    ) {
3256
-        $this->_redirect_after_action(
3257
-            $success,
3258
-            $what,
3259
-            $action_desc,
3260
-            $query_args,
3261
-            $override_overwrite
3262
-        );
3263
-    }
3264
-
3265
-
3266
-    /**
3267
-     * Helper method for merging existing request data with the returned redirect url.
3268
-     *
3269
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3270
-     * filters are still applied.
3271
-     *
3272
-     * @param array $new_route_data
3273
-     * @return array
3274
-     */
3275
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3276
-    {
3277
-        foreach ($this->request->requestParams() as $ref => $value) {
3278
-            // unset nonces
3279
-            if (strpos($ref, 'nonce') !== false) {
3280
-                $this->request->unSetRequestParam($ref);
3281
-                continue;
3282
-            }
3283
-            // urlencode values.
3284
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3285
-            $this->request->setRequestParam($ref, $value);
3286
-        }
3287
-        return array_merge($this->request->requestParams(), $new_route_data);
3288
-    }
3289
-
3290
-
3291
-    /**
3292
-     *    _redirect_after_action
3293
-     *
3294
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3295
-     * @param string $what               - what the action was performed on
3296
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3297
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3298
-     *                                   action is completed
3299
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3300
-     *                                   override this so that they show.
3301
-     * @return void
3302
-     * @throws EE_Error
3303
-     */
3304
-    protected function _redirect_after_action(
3305
-        $success = 0,
3306
-        $what = 'item',
3307
-        $action_desc = 'processed',
3308
-        $query_args = [],
3309
-        $override_overwrite = false
3310
-    ) {
3311
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3312
-        // class name for actions/filters.
3313
-        $classname = get_class($this);
3314
-        // set redirect url.
3315
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3316
-        // otherwise we go with whatever is set as the _admin_base_url
3317
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3318
-        $notices      = EE_Error::get_notices(false);
3319
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3320
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3321
-            EE_Error::overwrite_success();
3322
-        }
3323
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3324
-            // how many records affected ? more than one record ? or just one ?
3325
-            if ($success > 1) {
3326
-                // set plural msg
3327
-                EE_Error::add_success(
3328
-                    sprintf(
3329
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3330
-                        $what,
3331
-                        $action_desc
3332
-                    ),
3333
-                    __FILE__,
3334
-                    __FUNCTION__,
3335
-                    __LINE__
3336
-                );
3337
-            } elseif ($success === 1) {
3338
-                // set singular msg
3339
-                EE_Error::add_success(
3340
-                    sprintf(
3341
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3342
-                        $what,
3343
-                        $action_desc
3344
-                    ),
3345
-                    __FILE__,
3346
-                    __FUNCTION__,
3347
-                    __LINE__
3348
-                );
3349
-            }
3350
-        }
3351
-        // check that $query_args isn't something crazy
3352
-        if (! is_array($query_args)) {
3353
-            $query_args = [];
3354
-        }
3355
-        /**
3356
-         * Allow injecting actions before the query_args are modified for possible different
3357
-         * redirections on save and close actions
3358
-         *
3359
-         * @param array $query_args       The original query_args array coming into the
3360
-         *                                method.
3361
-         * @since 4.2.0
3362
-         */
3363
-        do_action(
3364
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3365
-            $query_args
3366
-        );
3367
-        // calculate where we're going (if we have a "save and close" button pushed)
3368
-
3369
-        if (
3370
-            $this->request->requestParamIsSet('save_and_close')
3371
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3372
-        ) {
3373
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3374
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3375
-            // regenerate query args array from referrer URL
3376
-            parse_str($parsed_url['query'], $query_args);
3377
-            // correct page and action will be in the query args now
3378
-            $redirect_url = admin_url('admin.php');
3379
-        }
3380
-        // merge any default query_args set in _default_route_query_args property
3381
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3382
-            $args_to_merge = [];
3383
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3384
-                // is there a wp_referer array in our _default_route_query_args property?
3385
-                if ($query_param === 'wp_referer') {
3386
-                    $query_value = (array) $query_value;
3387
-                    foreach ($query_value as $reference => $value) {
3388
-                        if (strpos($reference, 'nonce') !== false) {
3389
-                            continue;
3390
-                        }
3391
-                        // finally we will override any arguments in the referer with
3392
-                        // what might be set on the _default_route_query_args array.
3393
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3394
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3395
-                        } else {
3396
-                            $args_to_merge[ $reference ] = urlencode($value);
3397
-                        }
3398
-                    }
3399
-                    continue;
3400
-                }
3401
-                $args_to_merge[ $query_param ] = $query_value;
3402
-            }
3403
-            // now let's merge these arguments but override with what was specifically sent in to the
3404
-            // redirect.
3405
-            $query_args = array_merge($args_to_merge, $query_args);
3406
-        }
3407
-        $this->_process_notices($query_args);
3408
-        // generate redirect url
3409
-        // if redirecting to anything other than the main page, add a nonce
3410
-        if (isset($query_args['action'])) {
3411
-            // manually generate wp_nonce and merge that with the query vars
3412
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3413
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3414
-        }
3415
-        // we're adding some hooks and filters in here for processing any things just before redirects
3416
-        // (example: an admin page has done an insert or update and we want to run something after that).
3417
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3418
-        $redirect_url = apply_filters(
3419
-            'FHEE_redirect_' . $classname . $this->_req_action,
3420
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3421
-            $query_args
3422
-        );
3423
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3424
-        if ($this->request->isAjax()) {
3425
-            $default_data                    = [
3426
-                'close'        => true,
3427
-                'redirect_url' => $redirect_url,
3428
-                'where'        => 'main',
3429
-                'what'         => 'append',
3430
-            ];
3431
-            $this->_template_args['success'] = $success;
3432
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3433
-                $default_data,
3434
-                $this->_template_args['data']
3435
-            ) : $default_data;
3436
-            $this->_return_json();
3437
-        }
3438
-        wp_safe_redirect($redirect_url);
3439
-        exit();
3440
-    }
3441
-
3442
-
3443
-    /**
3444
-     * process any notices before redirecting (or returning ajax request)
3445
-     * This method sets the $this->_template_args['notices'] attribute;
3446
-     *
3447
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3448
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3449
-     *                                  page_routes haven't been defined yet.
3450
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3451
-     *                                  still save a transient for the notice.
3452
-     * @return void
3453
-     * @throws EE_Error
3454
-     */
3455
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3456
-    {
3457
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3458
-        if ($this->request->isAjax()) {
3459
-            $notices = EE_Error::get_notices(false);
3460
-            if (empty($this->_template_args['success'])) {
3461
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3462
-            }
3463
-            if (empty($this->_template_args['errors'])) {
3464
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3465
-            }
3466
-            if (empty($this->_template_args['attention'])) {
3467
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3468
-            }
3469
-        }
3470
-        $this->_template_args['notices'] = EE_Error::get_notices();
3471
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3472
-        if (! $this->request->isAjax() || $sticky_notices) {
3473
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3474
-            $this->_add_transient(
3475
-                $route,
3476
-                $this->_template_args['notices'],
3477
-                true,
3478
-                $skip_route_verify
3479
-            );
3480
-        }
3481
-    }
3482
-
3483
-
3484
-    /**
3485
-     * get_action_link_or_button
3486
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3487
-     *
3488
-     * @param string $action        use this to indicate which action the url is generated with.
3489
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3490
-     *                              property.
3491
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3492
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3493
-     * @param string $base_url      If this is not provided
3494
-     *                              the _admin_base_url will be used as the default for the button base_url.
3495
-     *                              Otherwise this value will be used.
3496
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3497
-     * @return string
3498
-     * @throws InvalidArgumentException
3499
-     * @throws InvalidInterfaceException
3500
-     * @throws InvalidDataTypeException
3501
-     * @throws EE_Error
3502
-     */
3503
-    public function get_action_link_or_button(
3504
-        $action,
3505
-        $type = 'add',
3506
-        $extra_request = [],
3507
-        $class = 'button button--primary',
3508
-        $base_url = '',
3509
-        $exclude_nonce = false
3510
-    ) {
3511
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3512
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3513
-            throw new EE_Error(
3514
-                sprintf(
3515
-                    esc_html__(
3516
-                        'There is no page route for given action for the button.  This action was given: %s',
3517
-                        'event_espresso'
3518
-                    ),
3519
-                    $action
3520
-                )
3521
-            );
3522
-        }
3523
-        if (! isset($this->_labels['buttons'][ $type ])) {
3524
-            throw new EE_Error(
3525
-                sprintf(
3526
-                    esc_html__(
3527
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3528
-                        'event_espresso'
3529
-                    ),
3530
-                    $type
3531
-                )
3532
-            );
3533
-        }
3534
-        // finally check user access for this button.
3535
-        $has_access = $this->check_user_access($action, true);
3536
-        if (! $has_access) {
3537
-            return '';
3538
-        }
3539
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3540
-        $query_args = [
3541
-            'action' => $action,
3542
-        ];
3543
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3544
-        if (! empty($extra_request)) {
3545
-            $query_args = array_merge($extra_request, $query_args);
3546
-        }
3547
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3548
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3549
-    }
3550
-
3551
-
3552
-    /**
3553
-     * _per_page_screen_option
3554
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3555
-     *
3556
-     * @return void
3557
-     * @throws InvalidArgumentException
3558
-     * @throws InvalidInterfaceException
3559
-     * @throws InvalidDataTypeException
3560
-     */
3561
-    protected function _per_page_screen_option()
3562
-    {
3563
-        $option = 'per_page';
3564
-        $args   = [
3565
-            'label'   => apply_filters(
3566
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3567
-                $this->_admin_page_title,
3568
-                $this
3569
-            ),
3570
-            'default' => (int) apply_filters(
3571
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3572
-                20
3573
-            ),
3574
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3575
-        ];
3576
-        // ONLY add the screen option if the user has access to it.
3577
-        if ($this->check_user_access($this->_current_view, true)) {
3578
-            add_screen_option($option, $args);
3579
-        }
3580
-    }
3581
-
3582
-
3583
-    /**
3584
-     * set_per_page_screen_option
3585
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3586
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3587
-     * admin_menu.
3588
-     *
3589
-     * @return void
3590
-     */
3591
-    private function _set_per_page_screen_options()
3592
-    {
3593
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3594
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3595
-            if (! $user = wp_get_current_user()) {
3596
-                return;
3597
-            }
3598
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3599
-            if (! $option) {
3600
-                return;
3601
-            }
3602
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3603
-            $map_option = $option;
3604
-            $option     = str_replace('-', '_', $option);
3605
-            switch ($map_option) {
3606
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3607
-                    $max_value = apply_filters(
3608
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3609
-                        999,
3610
-                        $this->_current_page,
3611
-                        $this->_current_view
3612
-                    );
3613
-                    if ($value < 1) {
3614
-                        return;
3615
-                    }
3616
-                    $value = min($value, $max_value);
3617
-                    break;
3618
-                default:
3619
-                    $value = apply_filters(
3620
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3621
-                        false,
3622
-                        $option,
3623
-                        $value
3624
-                    );
3625
-                    if (false === $value) {
3626
-                        return;
3627
-                    }
3628
-                    break;
3629
-            }
3630
-            update_user_meta($user->ID, $option, $value);
3631
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3632
-            exit;
3633
-        }
3634
-    }
3635
-
3636
-
3637
-    /**
3638
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3639
-     *
3640
-     * @param array $data array that will be assigned to template args.
3641
-     */
3642
-    public function set_template_args($data)
3643
-    {
3644
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3645
-    }
3646
-
3647
-
3648
-    /**
3649
-     * This makes available the WP transient system for temporarily moving data between routes
3650
-     *
3651
-     * @param string $route             the route that should receive the transient
3652
-     * @param array  $data              the data that gets sent
3653
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3654
-     *                                  normal route transient.
3655
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3656
-     *                                  when we are adding a transient before page_routes have been defined.
3657
-     * @return void
3658
-     * @throws EE_Error
3659
-     */
3660
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3661
-    {
3662
-        $user_id = get_current_user_id();
3663
-        if (! $skip_route_verify) {
3664
-            $this->_verify_route($route);
3665
-        }
3666
-        // now let's set the string for what kind of transient we're setting
3667
-        $transient = $notices
3668
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3669
-            : 'rte_tx_' . $route . '_' . $user_id;
3670
-        $data      = $notices ? ['notices' => $data] : $data;
3671
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3672
-        $existing = is_multisite() && is_network_admin()
3673
-            ? get_site_transient($transient)
3674
-            : get_transient($transient);
3675
-        if ($existing) {
3676
-            $data = array_merge((array) $data, (array) $existing);
3677
-        }
3678
-        if (is_multisite() && is_network_admin()) {
3679
-            set_site_transient($transient, $data, 8);
3680
-        } else {
3681
-            set_transient($transient, $data, 8);
3682
-        }
3683
-    }
3684
-
3685
-
3686
-    /**
3687
-     * this retrieves the temporary transient that has been set for moving data between routes.
3688
-     *
3689
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3690
-     * @param string $route
3691
-     * @return mixed data
3692
-     */
3693
-    protected function _get_transient($notices = false, $route = '')
3694
-    {
3695
-        $user_id   = get_current_user_id();
3696
-        $route     = ! $route ? $this->_req_action : $route;
3697
-        $transient = $notices
3698
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3699
-            : 'rte_tx_' . $route . '_' . $user_id;
3700
-        $data      = is_multisite() && is_network_admin()
3701
-            ? get_site_transient($transient)
3702
-            : get_transient($transient);
3703
-        // delete transient after retrieval (just in case it hasn't expired);
3704
-        if (is_multisite() && is_network_admin()) {
3705
-            delete_site_transient($transient);
3706
-        } else {
3707
-            delete_transient($transient);
3708
-        }
3709
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3710
-    }
3711
-
3712
-
3713
-    /**
3714
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3715
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3716
-     * default route callback on the EE_Admin page you want it run.)
3717
-     *
3718
-     * @return void
3719
-     */
3720
-    protected function _transient_garbage_collection()
3721
-    {
3722
-        global $wpdb;
3723
-        // retrieve all existing transients
3724
-        $query =
3725
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3726
-        if ($results = $wpdb->get_results($query)) {
3727
-            foreach ($results as $result) {
3728
-                $transient = str_replace('_transient_', '', $result->option_name);
3729
-                get_transient($transient);
3730
-                if (is_multisite() && is_network_admin()) {
3731
-                    get_site_transient($transient);
3732
-                }
3733
-            }
3734
-        }
3735
-    }
3736
-
3737
-
3738
-    /**
3739
-     * get_view
3740
-     *
3741
-     * @return string content of _view property
3742
-     */
3743
-    public function get_view()
3744
-    {
3745
-        return $this->_view;
3746
-    }
3747
-
3748
-
3749
-    /**
3750
-     * getter for the protected $_views property
3751
-     *
3752
-     * @return array
3753
-     */
3754
-    public function get_views()
3755
-    {
3756
-        return $this->_views;
3757
-    }
3758
-
3759
-
3760
-    /**
3761
-     * get_current_page
3762
-     *
3763
-     * @return string _current_page property value
3764
-     */
3765
-    public function get_current_page()
3766
-    {
3767
-        return $this->_current_page;
3768
-    }
3769
-
3770
-
3771
-    /**
3772
-     * get_current_view
3773
-     *
3774
-     * @return string _current_view property value
3775
-     */
3776
-    public function get_current_view()
3777
-    {
3778
-        return $this->_current_view;
3779
-    }
3780
-
3781
-
3782
-    /**
3783
-     * get_current_screen
3784
-     *
3785
-     * @return object The current WP_Screen object
3786
-     */
3787
-    public function get_current_screen()
3788
-    {
3789
-        return $this->_current_screen;
3790
-    }
3791
-
3792
-
3793
-    /**
3794
-     * get_current_page_view_url
3795
-     *
3796
-     * @return string This returns the url for the current_page_view.
3797
-     */
3798
-    public function get_current_page_view_url()
3799
-    {
3800
-        return $this->_current_page_view_url;
3801
-    }
3802
-
3803
-
3804
-    /**
3805
-     * just returns the Request
3806
-     *
3807
-     * @return RequestInterface
3808
-     */
3809
-    public function get_request()
3810
-    {
3811
-        return $this->request;
3812
-    }
3813
-
3814
-
3815
-    /**
3816
-     * just returns the _req_data property
3817
-     *
3818
-     * @return array
3819
-     */
3820
-    public function get_request_data()
3821
-    {
3822
-        return $this->request->requestParams();
3823
-    }
3824
-
3825
-
3826
-    /**
3827
-     * returns the _req_data protected property
3828
-     *
3829
-     * @return string
3830
-     */
3831
-    public function get_req_action()
3832
-    {
3833
-        return $this->_req_action;
3834
-    }
3835
-
3836
-
3837
-    /**
3838
-     * @return bool  value of $_is_caf property
3839
-     */
3840
-    public function is_caf()
3841
-    {
3842
-        return $this->_is_caf;
3843
-    }
3844
-
3845
-
3846
-    /**
3847
-     * @return mixed
3848
-     */
3849
-    public function default_espresso_metaboxes()
3850
-    {
3851
-        return $this->_default_espresso_metaboxes;
3852
-    }
3853
-
3854
-
3855
-    /**
3856
-     * @return mixed
3857
-     */
3858
-    public function admin_base_url()
3859
-    {
3860
-        return $this->_admin_base_url;
3861
-    }
3862
-
3863
-
3864
-    /**
3865
-     * @return mixed
3866
-     */
3867
-    public function wp_page_slug()
3868
-    {
3869
-        return $this->_wp_page_slug;
3870
-    }
3871
-
3872
-
3873
-    /**
3874
-     * updates  espresso configuration settings
3875
-     *
3876
-     * @param string                   $tab
3877
-     * @param EE_Config_Base|EE_Config $config
3878
-     * @param string                   $file file where error occurred
3879
-     * @param string                   $func function  where error occurred
3880
-     * @param string                   $line line no where error occurred
3881
-     * @return boolean
3882
-     */
3883
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3884
-    {
3885
-        // remove any options that are NOT going to be saved with the config settings.
3886
-        if (isset($config->core->ee_ueip_optin)) {
3887
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3888
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3889
-            update_option('ee_ueip_has_notified', true);
3890
-        }
3891
-        // and save it (note we're also doing the network save here)
3892
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3893
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3894
-        if ($config_saved && $net_saved) {
3895
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3896
-            return true;
3897
-        }
3898
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3899
-        return false;
3900
-    }
3901
-
3902
-
3903
-    /**
3904
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3905
-     *
3906
-     * @return array
3907
-     */
3908
-    public function get_yes_no_values()
3909
-    {
3910
-        return $this->_yes_no_values;
3911
-    }
3912
-
3913
-
3914
-    protected function _get_dir()
3915
-    {
3916
-        $reflector = new ReflectionClass(get_class($this));
3917
-        return dirname($reflector->getFileName());
3918
-    }
3919
-
3920
-
3921
-    /**
3922
-     * A helper for getting a "next link".
3923
-     *
3924
-     * @param string $url   The url to link to
3925
-     * @param string $class The class to use.
3926
-     * @return string
3927
-     */
3928
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3929
-    {
3930
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3931
-    }
3932
-
3933
-
3934
-    /**
3935
-     * A helper for getting a "previous link".
3936
-     *
3937
-     * @param string $url   The url to link to
3938
-     * @param string $class The class to use.
3939
-     * @return string
3940
-     */
3941
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3942
-    {
3943
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3944
-    }
3945
-
3946
-
3947
-
3948
-
3949
-
3950
-
3951
-
3952
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3953
-
3954
-
3955
-    /**
3956
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
3957
-     * 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
3958
-     * _req_data array.
3959
-     *
3960
-     * @return bool success/fail
3961
-     * @throws EE_Error
3962
-     * @throws InvalidArgumentException
3963
-     * @throws ReflectionException
3964
-     * @throws InvalidDataTypeException
3965
-     * @throws InvalidInterfaceException
3966
-     */
3967
-    protected function _process_resend_registration()
3968
-    {
3969
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3970
-        do_action(
3971
-            'AHEE__EE_Admin_Page___process_resend_registration',
3972
-            $this->_template_args['success'],
3973
-            $this->request->requestParams()
3974
-        );
3975
-        return $this->_template_args['success'];
3976
-    }
3977
-
3978
-
3979
-    /**
3980
-     * This automatically processes any payment message notifications when manual payment has been applied.
3981
-     *
3982
-     * @param EE_Payment $payment
3983
-     * @return bool success/fail
3984
-     */
3985
-    protected function _process_payment_notification(EE_Payment $payment)
3986
-    {
3987
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3988
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3989
-        $this->_template_args['success'] = apply_filters(
3990
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
3991
-            false,
3992
-            $payment
3993
-        );
3994
-        return $this->_template_args['success'];
3995
-    }
3996
-
3997
-
3998
-    /**
3999
-     * @param EEM_Base      $entity_model
4000
-     * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4001
-     * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4002
-     * @param string        $delete_column  name of the field that denotes whether entity is trashed
4003
-     * @param callable|null $callback       called after entity is trashed, restored, or deleted
4004
-     * @return int|float
4005
-     * @throws EE_Error
4006
-     */
4007
-    protected function trashRestoreDeleteEntities(
4008
-        EEM_Base $entity_model,
4009
-        $entity_PK_name,
4010
-        $action = EE_Admin_List_Table::ACTION_DELETE,
4011
-        $delete_column = '',
4012
-        callable $callback = null
4013
-    ) {
4014
-        $entity_PK      = $entity_model->get_primary_key_field();
4015
-        $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4016
-        $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4017
-        // grab ID if deleting a single entity
4018
-        if ($this->request->requestParamIsSet($entity_PK_name)) {
4019
-            $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4020
-            return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4021
-        }
4022
-        // or grab checkbox array if bulk deleting
4023
-        $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4024
-        if (empty($checkboxes)) {
4025
-            return 0;
4026
-        }
4027
-        $success = 0;
4028
-        $IDs     = array_keys($checkboxes);
4029
-        // cycle thru bulk action checkboxes
4030
-        foreach ($IDs as $ID) {
4031
-            // increment $success
4032
-            if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4033
-                $success++;
4034
-            }
4035
-        }
4036
-        $count = (int) count($checkboxes);
4037
-        // if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4038
-        // otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4039
-        return $success === $count ? $count : $success / $count;
4040
-    }
4041
-
4042
-
4043
-    /**
4044
-     * @param EE_Primary_Key_Field_Base $entity_PK
4045
-     * @return string
4046
-     * @throws EE_Error
4047
-     * @since   4.10.30.p
4048
-     */
4049
-    private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK)
4050
-    {
4051
-        $entity_PK_type = $entity_PK->getSchemaType();
4052
-        switch ($entity_PK_type) {
4053
-            case 'boolean':
4054
-                return 'bool';
4055
-            case 'integer':
4056
-                return 'int';
4057
-            case 'number':
4058
-                return 'float';
4059
-            case 'string':
4060
-                return 'string';
4061
-        }
4062
-        throw new RuntimeException(
4063
-            sprintf(
4064
-                esc_html__(
4065
-                    '"%1$s" is an invalid schema type for the %2$s primary key.',
4066
-                    'event_espresso'
4067
-                ),
4068
-                $entity_PK_type,
4069
-                $entity_PK->get_name()
4070
-            )
4071
-        );
4072
-    }
4073
-
4074
-
4075
-    /**
4076
-     * @param EEM_Base      $entity_model
4077
-     * @param int|string    $entity_ID
4078
-     * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4079
-     * @param string        $delete_column name of the field that denotes whether entity is trashed
4080
-     * @param callable|null $callback      called after entity is trashed, restored, or deleted
4081
-     * @return bool
4082
-     */
4083
-    protected function trashRestoreDeleteEntity(
4084
-        EEM_Base $entity_model,
4085
-        $entity_ID,
4086
-        $action,
4087
-        $delete_column,
4088
-        callable $callback = null
4089
-    ) {
4090
-        $entity_ID = absint($entity_ID);
4091
-        if (! $entity_ID) {
4092
-            $this->trashRestoreDeleteError($action, $entity_model);
4093
-        }
4094
-        $result = 0;
4095
-        try {
4096
-            $entity = $entity_model->get_one_by_ID($entity_ID);
4097
-            if (! $entity instanceof EE_Base_Class) {
4098
-                throw new DomainException(
4099
-                    sprintf(
4100
-                        esc_html__(
4101
-                            'Missing or invalid %1$s entity with ID of "%2$s" returned from db.',
4102
-                            'event_espresso'
4103
-                        ),
4104
-                        str_replace('EEM_', '', $entity_model->get_this_model_name()),
4105
-                        $entity_ID
4106
-                    )
4107
-                );
4108
-            }
4109
-            switch ($action) {
4110
-                case EE_Admin_List_Table::ACTION_DELETE:
4111
-                    $result = (bool) $entity->delete_permanently();
4112
-                    break;
4113
-                case EE_Admin_List_Table::ACTION_RESTORE:
4114
-                    $result = $entity->delete_or_restore(false);
4115
-                    break;
4116
-                case EE_Admin_List_Table::ACTION_TRASH:
4117
-                    $result = $entity->delete_or_restore();
4118
-                    break;
4119
-            }
4120
-        } catch (Exception $exception) {
4121
-            $this->trashRestoreDeleteError($action, $entity_model, $exception);
4122
-        }
4123
-        if (is_callable($callback)) {
4124
-            call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4125
-        }
4126
-        return $result;
4127
-    }
4128
-
4129
-
4130
-    /**
4131
-     * @param EEM_Base $entity_model
4132
-     * @param string   $delete_column
4133
-     * @since 4.10.30.p
4134
-     */
4135
-    private function validateDeleteColumn(EEM_Base $entity_model, $delete_column)
4136
-    {
4137
-        if (empty($delete_column)) {
4138
-            throw new DomainException(
4139
-                sprintf(
4140
-                    esc_html__(
4141
-                        'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4142
-                        'event_espresso'
4143
-                    ),
4144
-                    $entity_model->get_this_model_name()
4145
-                )
4146
-            );
4147
-        }
4148
-        if (! $entity_model->has_field($delete_column)) {
4149
-            throw new DomainException(
4150
-                sprintf(
4151
-                    esc_html__(
4152
-                        'The %1$s field does not exist on the %2$s model.',
4153
-                        'event_espresso'
4154
-                    ),
4155
-                    $delete_column,
4156
-                    $entity_model->get_this_model_name()
4157
-                )
4158
-            );
4159
-        }
4160
-    }
4161
-
4162
-
4163
-    /**
4164
-     * @param EEM_Base       $entity_model
4165
-     * @param Exception|null $exception
4166
-     * @param string         $action
4167
-     * @since 4.10.30.p
4168
-     */
4169
-    private function trashRestoreDeleteError($action, EEM_Base $entity_model, Exception $exception = null)
4170
-    {
4171
-        if ($exception instanceof Exception) {
4172
-            throw new RuntimeException(
4173
-                sprintf(
4174
-                    esc_html__(
4175
-                        'Could not %1$s the %2$s because the following error occurred: %3$s',
4176
-                        'event_espresso'
4177
-                    ),
4178
-                    $action,
4179
-                    $entity_model->get_this_model_name(),
4180
-                    $exception->getMessage()
4181
-                )
4182
-            );
4183
-        }
4184
-        throw new RuntimeException(
4185
-            sprintf(
4186
-                esc_html__(
4187
-                    'Could not %1$s the %2$s because an invalid ID was received.',
4188
-                    'event_espresso'
4189
-                ),
4190
-                $action,
4191
-                $entity_model->get_this_model_name()
4192
-            )
4193
-        );
4194
-    }
2852
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2853
+		// display message about search results?
2854
+		$search = $this->request->getRequestParam('s');
2855
+		$this->_template_args['before_list_table'] .= ! empty($search)
2856
+			? '<p class="ee-search-results">' . sprintf(
2857
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2858
+				trim($search, '%')
2859
+			) . '</p>'
2860
+			: '';
2861
+		// filter before_list_table template arg
2862
+		$this->_template_args['before_list_table'] = apply_filters(
2863
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2864
+			$this->_template_args['before_list_table'],
2865
+			$this->page_slug,
2866
+			$this->request->requestParams(),
2867
+			$this->_req_action
2868
+		);
2869
+		// convert to array and filter again
2870
+		// arrays are easier to inject new items in a specific location,
2871
+		// but would not be backwards compatible, so we have to add a new filter
2872
+		$this->_template_args['before_list_table'] = implode(
2873
+			" \n",
2874
+			(array) apply_filters(
2875
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2876
+				(array) $this->_template_args['before_list_table'],
2877
+				$this->page_slug,
2878
+				$this->request->requestParams(),
2879
+				$this->_req_action
2880
+			)
2881
+		);
2882
+		// filter after_list_table template arg
2883
+		$this->_template_args['after_list_table'] = apply_filters(
2884
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2885
+			$this->_template_args['after_list_table'],
2886
+			$this->page_slug,
2887
+			$this->request->requestParams(),
2888
+			$this->_req_action
2889
+		);
2890
+		// convert to array and filter again
2891
+		// arrays are easier to inject new items in a specific location,
2892
+		// but would not be backwards compatible, so we have to add a new filter
2893
+		$this->_template_args['after_list_table']   = implode(
2894
+			" \n",
2895
+			(array) apply_filters(
2896
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2897
+				(array) $this->_template_args['after_list_table'],
2898
+				$this->page_slug,
2899
+				$this->request->requestParams(),
2900
+				$this->_req_action
2901
+			)
2902
+		);
2903
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2904
+			$template_path,
2905
+			$this->_template_args,
2906
+			true
2907
+		);
2908
+		// the final template wrapper
2909
+		if ($sidebar) {
2910
+			$this->display_admin_page_with_sidebar();
2911
+		} else {
2912
+			$this->display_admin_page_with_no_sidebar();
2913
+		}
2914
+	}
2915
+
2916
+
2917
+	/**
2918
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2919
+	 * html string for the legend.
2920
+	 * $items are expected in an array in the following format:
2921
+	 * $legend_items = array(
2922
+	 *        'item_id' => array(
2923
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2924
+	 *            'desc' => esc_html__('localized description of item');
2925
+	 *        )
2926
+	 * );
2927
+	 *
2928
+	 * @param array $items see above for format of array
2929
+	 * @return string html string of legend
2930
+	 * @throws DomainException
2931
+	 */
2932
+	protected function _display_legend($items)
2933
+	{
2934
+		$this->_template_args['items'] = apply_filters(
2935
+			'FHEE__EE_Admin_Page___display_legend__items',
2936
+			(array) $items,
2937
+			$this
2938
+		);
2939
+		return EEH_Template::display_template(
2940
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2941
+			$this->_template_args,
2942
+			true
2943
+		);
2944
+	}
2945
+
2946
+
2947
+	/**
2948
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2949
+	 * The returned json object is created from an array in the following format:
2950
+	 * array(
2951
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2952
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2953
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2954
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2955
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2956
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
2957
+	 *  that might be included in here)
2958
+	 * )
2959
+	 * The json object is populated by whatever is set in the $_template_args property.
2960
+	 *
2961
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2962
+	 *                                 instead of displayed.
2963
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2964
+	 * @return void
2965
+	 * @throws EE_Error
2966
+	 */
2967
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
2968
+	{
2969
+		// make sure any EE_Error notices have been handled.
2970
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2971
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
2972
+		unset($this->_template_args['data']);
2973
+		$json = [
2974
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2975
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2976
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2977
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2978
+			'notices'   => EE_Error::get_notices(),
2979
+			'content'   => isset($this->_template_args['admin_page_content'])
2980
+				? $this->_template_args['admin_page_content'] : '',
2981
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
2982
+			'isEEajax'  => true
2983
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2984
+		];
2985
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2986
+		if (null === error_get_last() || ! headers_sent()) {
2987
+			header('Content-Type: application/json; charset=UTF-8');
2988
+		}
2989
+		echo wp_json_encode($json);
2990
+		exit();
2991
+	}
2992
+
2993
+
2994
+	/**
2995
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2996
+	 *
2997
+	 * @return void
2998
+	 * @throws EE_Error
2999
+	 */
3000
+	public function return_json()
3001
+	{
3002
+		if ($this->request->isAjax()) {
3003
+			$this->_return_json();
3004
+		} else {
3005
+			throw new EE_Error(
3006
+				sprintf(
3007
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3008
+					__FUNCTION__
3009
+				)
3010
+			);
3011
+		}
3012
+	}
3013
+
3014
+
3015
+	/**
3016
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3017
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3018
+	 *
3019
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3020
+	 */
3021
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3022
+	{
3023
+		$this->_hook_obj = $hook_obj;
3024
+	}
3025
+
3026
+
3027
+	/**
3028
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3029
+	 *
3030
+	 * @param boolean $about whether to use the special about page wrapper or default.
3031
+	 * @return void
3032
+	 * @throws DomainException
3033
+	 * @throws EE_Error
3034
+	 */
3035
+	public function admin_page_wrapper($about = false)
3036
+	{
3037
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3038
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3039
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3040
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3041
+
3042
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3043
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3044
+			isset($this->_template_args['before_admin_page_content'])
3045
+				? $this->_template_args['before_admin_page_content']
3046
+				: ''
3047
+		);
3048
+
3049
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3050
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3051
+			isset($this->_template_args['after_admin_page_content'])
3052
+				? $this->_template_args['after_admin_page_content']
3053
+				: ''
3054
+		);
3055
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3056
+
3057
+		if ($this->request->isAjax()) {
3058
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3059
+				// $template_path,
3060
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3061
+				$this->_template_args,
3062
+				true
3063
+			);
3064
+			$this->_return_json();
3065
+		}
3066
+		// load settings page wrapper template
3067
+		$template_path = $about
3068
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3069
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3070
+
3071
+		EEH_Template::display_template($template_path, $this->_template_args);
3072
+	}
3073
+
3074
+
3075
+	/**
3076
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3077
+	 *
3078
+	 * @return string html
3079
+	 * @throws EE_Error
3080
+	 */
3081
+	protected function _get_main_nav_tabs()
3082
+	{
3083
+		// let's generate the html using the EEH_Tabbed_Content helper.
3084
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3085
+		// (rather than setting in the page_routes array)
3086
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3087
+	}
3088
+
3089
+
3090
+	/**
3091
+	 *        sort nav tabs
3092
+	 *
3093
+	 * @param $a
3094
+	 * @param $b
3095
+	 * @return int
3096
+	 */
3097
+	private function _sort_nav_tabs($a, $b)
3098
+	{
3099
+		if ($a['order'] === $b['order']) {
3100
+			return 0;
3101
+		}
3102
+		return ($a['order'] < $b['order']) ? -1 : 1;
3103
+	}
3104
+
3105
+
3106
+	/**
3107
+	 *    generates HTML for the forms used on admin pages
3108
+	 *
3109
+	 * @param array  $input_vars   - array of input field details
3110
+	 * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3111
+	 *                             use)
3112
+	 * @param bool   $id
3113
+	 * @return array|string
3114
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3115
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3116
+	 */
3117
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3118
+	{
3119
+		return $generator === 'string'
3120
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3121
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3122
+	}
3123
+
3124
+
3125
+	/**
3126
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3127
+	 *
3128
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3129
+	 *                                   Close" button.
3130
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3131
+	 *                                   'Save', [1] => 'save & close')
3132
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3133
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3134
+	 *                                   default actions by submitting some other value.
3135
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3136
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3137
+	 *                                   close (normal form handling).
3138
+	 */
3139
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3140
+	{
3141
+		// make sure $text and $actions are in an array
3142
+		$text          = (array) $text;
3143
+		$actions       = (array) $actions;
3144
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3145
+		$button_text   = ! empty($text)
3146
+			? $text
3147
+			: [
3148
+				esc_html__('Save', 'event_espresso'),
3149
+				esc_html__('Save and Close', 'event_espresso'),
3150
+			];
3151
+		$default_names = ['save', 'save_and_close'];
3152
+		$buttons = '';
3153
+		foreach ($button_text as $key => $button) {
3154
+			$ref     = $default_names[ $key ];
3155
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3156
+			$buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3157
+						. 'value="' . $button . '" name="' . $name . '" '
3158
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3159
+			if (! $both) {
3160
+				break;
3161
+			}
3162
+		}
3163
+		// add in a hidden index for the current page (so save and close redirects properly)
3164
+		$buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3165
+				   . $referrer_url
3166
+				   . '" />';
3167
+		$this->_template_args['save_buttons'] = $buttons;
3168
+	}
3169
+
3170
+
3171
+	/**
3172
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3173
+	 *
3174
+	 * @param string $route
3175
+	 * @param array  $additional_hidden_fields
3176
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3177
+	 * @since 4.6.0
3178
+	 */
3179
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3180
+	{
3181
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3182
+	}
3183
+
3184
+
3185
+	/**
3186
+	 * set form open and close tags on add/edit pages.
3187
+	 *
3188
+	 * @param string $route                    the route you want the form to direct to
3189
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3190
+	 * @return void
3191
+	 */
3192
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3193
+	{
3194
+		if (empty($route)) {
3195
+			$user_msg = esc_html__(
3196
+				'An error occurred. No action was set for this page\'s form.',
3197
+				'event_espresso'
3198
+			);
3199
+			$dev_msg  = $user_msg . "\n"
3200
+						. sprintf(
3201
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3202
+							__FUNCTION__,
3203
+							__CLASS__
3204
+						);
3205
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3206
+		}
3207
+		// open form
3208
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3209
+															 . $this->_admin_base_url
3210
+															 . '" id="'
3211
+															 . $route
3212
+															 . '_event_form" >';
3213
+		// add nonce
3214
+		$nonce                                             =
3215
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3216
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3217
+		// add REQUIRED form action
3218
+		$hidden_fields = [
3219
+			'action' => ['type' => 'hidden', 'value' => $route],
3220
+		];
3221
+		// merge arrays
3222
+		$hidden_fields = is_array($additional_hidden_fields)
3223
+			? array_merge($hidden_fields, $additional_hidden_fields)
3224
+			: $hidden_fields;
3225
+		// generate form fields
3226
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3227
+		// add fields to form
3228
+		foreach ((array) $form_fields as $form_field) {
3229
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3230
+		}
3231
+		// close form
3232
+		$this->_template_args['after_admin_page_content'] = '</form>';
3233
+	}
3234
+
3235
+
3236
+	/**
3237
+	 * Public Wrapper for _redirect_after_action() method since its
3238
+	 * discovered it would be useful for external code to have access.
3239
+	 *
3240
+	 * @param bool   $success
3241
+	 * @param string $what
3242
+	 * @param string $action_desc
3243
+	 * @param array  $query_args
3244
+	 * @param bool   $override_overwrite
3245
+	 * @throws EE_Error
3246
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3247
+	 * @since 4.5.0
3248
+	 */
3249
+	public function redirect_after_action(
3250
+		$success = false,
3251
+		$what = 'item',
3252
+		$action_desc = 'processed',
3253
+		$query_args = [],
3254
+		$override_overwrite = false
3255
+	) {
3256
+		$this->_redirect_after_action(
3257
+			$success,
3258
+			$what,
3259
+			$action_desc,
3260
+			$query_args,
3261
+			$override_overwrite
3262
+		);
3263
+	}
3264
+
3265
+
3266
+	/**
3267
+	 * Helper method for merging existing request data with the returned redirect url.
3268
+	 *
3269
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3270
+	 * filters are still applied.
3271
+	 *
3272
+	 * @param array $new_route_data
3273
+	 * @return array
3274
+	 */
3275
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3276
+	{
3277
+		foreach ($this->request->requestParams() as $ref => $value) {
3278
+			// unset nonces
3279
+			if (strpos($ref, 'nonce') !== false) {
3280
+				$this->request->unSetRequestParam($ref);
3281
+				continue;
3282
+			}
3283
+			// urlencode values.
3284
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3285
+			$this->request->setRequestParam($ref, $value);
3286
+		}
3287
+		return array_merge($this->request->requestParams(), $new_route_data);
3288
+	}
3289
+
3290
+
3291
+	/**
3292
+	 *    _redirect_after_action
3293
+	 *
3294
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3295
+	 * @param string $what               - what the action was performed on
3296
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3297
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3298
+	 *                                   action is completed
3299
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3300
+	 *                                   override this so that they show.
3301
+	 * @return void
3302
+	 * @throws EE_Error
3303
+	 */
3304
+	protected function _redirect_after_action(
3305
+		$success = 0,
3306
+		$what = 'item',
3307
+		$action_desc = 'processed',
3308
+		$query_args = [],
3309
+		$override_overwrite = false
3310
+	) {
3311
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3312
+		// class name for actions/filters.
3313
+		$classname = get_class($this);
3314
+		// set redirect url.
3315
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3316
+		// otherwise we go with whatever is set as the _admin_base_url
3317
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3318
+		$notices      = EE_Error::get_notices(false);
3319
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3320
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3321
+			EE_Error::overwrite_success();
3322
+		}
3323
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3324
+			// how many records affected ? more than one record ? or just one ?
3325
+			if ($success > 1) {
3326
+				// set plural msg
3327
+				EE_Error::add_success(
3328
+					sprintf(
3329
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3330
+						$what,
3331
+						$action_desc
3332
+					),
3333
+					__FILE__,
3334
+					__FUNCTION__,
3335
+					__LINE__
3336
+				);
3337
+			} elseif ($success === 1) {
3338
+				// set singular msg
3339
+				EE_Error::add_success(
3340
+					sprintf(
3341
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3342
+						$what,
3343
+						$action_desc
3344
+					),
3345
+					__FILE__,
3346
+					__FUNCTION__,
3347
+					__LINE__
3348
+				);
3349
+			}
3350
+		}
3351
+		// check that $query_args isn't something crazy
3352
+		if (! is_array($query_args)) {
3353
+			$query_args = [];
3354
+		}
3355
+		/**
3356
+		 * Allow injecting actions before the query_args are modified for possible different
3357
+		 * redirections on save and close actions
3358
+		 *
3359
+		 * @param array $query_args       The original query_args array coming into the
3360
+		 *                                method.
3361
+		 * @since 4.2.0
3362
+		 */
3363
+		do_action(
3364
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3365
+			$query_args
3366
+		);
3367
+		// calculate where we're going (if we have a "save and close" button pushed)
3368
+
3369
+		if (
3370
+			$this->request->requestParamIsSet('save_and_close')
3371
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3372
+		) {
3373
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3374
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3375
+			// regenerate query args array from referrer URL
3376
+			parse_str($parsed_url['query'], $query_args);
3377
+			// correct page and action will be in the query args now
3378
+			$redirect_url = admin_url('admin.php');
3379
+		}
3380
+		// merge any default query_args set in _default_route_query_args property
3381
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3382
+			$args_to_merge = [];
3383
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3384
+				// is there a wp_referer array in our _default_route_query_args property?
3385
+				if ($query_param === 'wp_referer') {
3386
+					$query_value = (array) $query_value;
3387
+					foreach ($query_value as $reference => $value) {
3388
+						if (strpos($reference, 'nonce') !== false) {
3389
+							continue;
3390
+						}
3391
+						// finally we will override any arguments in the referer with
3392
+						// what might be set on the _default_route_query_args array.
3393
+						if (isset($this->_default_route_query_args[ $reference ])) {
3394
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3395
+						} else {
3396
+							$args_to_merge[ $reference ] = urlencode($value);
3397
+						}
3398
+					}
3399
+					continue;
3400
+				}
3401
+				$args_to_merge[ $query_param ] = $query_value;
3402
+			}
3403
+			// now let's merge these arguments but override with what was specifically sent in to the
3404
+			// redirect.
3405
+			$query_args = array_merge($args_to_merge, $query_args);
3406
+		}
3407
+		$this->_process_notices($query_args);
3408
+		// generate redirect url
3409
+		// if redirecting to anything other than the main page, add a nonce
3410
+		if (isset($query_args['action'])) {
3411
+			// manually generate wp_nonce and merge that with the query vars
3412
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3413
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3414
+		}
3415
+		// we're adding some hooks and filters in here for processing any things just before redirects
3416
+		// (example: an admin page has done an insert or update and we want to run something after that).
3417
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3418
+		$redirect_url = apply_filters(
3419
+			'FHEE_redirect_' . $classname . $this->_req_action,
3420
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3421
+			$query_args
3422
+		);
3423
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3424
+		if ($this->request->isAjax()) {
3425
+			$default_data                    = [
3426
+				'close'        => true,
3427
+				'redirect_url' => $redirect_url,
3428
+				'where'        => 'main',
3429
+				'what'         => 'append',
3430
+			];
3431
+			$this->_template_args['success'] = $success;
3432
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3433
+				$default_data,
3434
+				$this->_template_args['data']
3435
+			) : $default_data;
3436
+			$this->_return_json();
3437
+		}
3438
+		wp_safe_redirect($redirect_url);
3439
+		exit();
3440
+	}
3441
+
3442
+
3443
+	/**
3444
+	 * process any notices before redirecting (or returning ajax request)
3445
+	 * This method sets the $this->_template_args['notices'] attribute;
3446
+	 *
3447
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3448
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3449
+	 *                                  page_routes haven't been defined yet.
3450
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3451
+	 *                                  still save a transient for the notice.
3452
+	 * @return void
3453
+	 * @throws EE_Error
3454
+	 */
3455
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3456
+	{
3457
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3458
+		if ($this->request->isAjax()) {
3459
+			$notices = EE_Error::get_notices(false);
3460
+			if (empty($this->_template_args['success'])) {
3461
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3462
+			}
3463
+			if (empty($this->_template_args['errors'])) {
3464
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3465
+			}
3466
+			if (empty($this->_template_args['attention'])) {
3467
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3468
+			}
3469
+		}
3470
+		$this->_template_args['notices'] = EE_Error::get_notices();
3471
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3472
+		if (! $this->request->isAjax() || $sticky_notices) {
3473
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3474
+			$this->_add_transient(
3475
+				$route,
3476
+				$this->_template_args['notices'],
3477
+				true,
3478
+				$skip_route_verify
3479
+			);
3480
+		}
3481
+	}
3482
+
3483
+
3484
+	/**
3485
+	 * get_action_link_or_button
3486
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3487
+	 *
3488
+	 * @param string $action        use this to indicate which action the url is generated with.
3489
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3490
+	 *                              property.
3491
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3492
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3493
+	 * @param string $base_url      If this is not provided
3494
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3495
+	 *                              Otherwise this value will be used.
3496
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3497
+	 * @return string
3498
+	 * @throws InvalidArgumentException
3499
+	 * @throws InvalidInterfaceException
3500
+	 * @throws InvalidDataTypeException
3501
+	 * @throws EE_Error
3502
+	 */
3503
+	public function get_action_link_or_button(
3504
+		$action,
3505
+		$type = 'add',
3506
+		$extra_request = [],
3507
+		$class = 'button button--primary',
3508
+		$base_url = '',
3509
+		$exclude_nonce = false
3510
+	) {
3511
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3512
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3513
+			throw new EE_Error(
3514
+				sprintf(
3515
+					esc_html__(
3516
+						'There is no page route for given action for the button.  This action was given: %s',
3517
+						'event_espresso'
3518
+					),
3519
+					$action
3520
+				)
3521
+			);
3522
+		}
3523
+		if (! isset($this->_labels['buttons'][ $type ])) {
3524
+			throw new EE_Error(
3525
+				sprintf(
3526
+					esc_html__(
3527
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3528
+						'event_espresso'
3529
+					),
3530
+					$type
3531
+				)
3532
+			);
3533
+		}
3534
+		// finally check user access for this button.
3535
+		$has_access = $this->check_user_access($action, true);
3536
+		if (! $has_access) {
3537
+			return '';
3538
+		}
3539
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3540
+		$query_args = [
3541
+			'action' => $action,
3542
+		];
3543
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3544
+		if (! empty($extra_request)) {
3545
+			$query_args = array_merge($extra_request, $query_args);
3546
+		}
3547
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3548
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3549
+	}
3550
+
3551
+
3552
+	/**
3553
+	 * _per_page_screen_option
3554
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3555
+	 *
3556
+	 * @return void
3557
+	 * @throws InvalidArgumentException
3558
+	 * @throws InvalidInterfaceException
3559
+	 * @throws InvalidDataTypeException
3560
+	 */
3561
+	protected function _per_page_screen_option()
3562
+	{
3563
+		$option = 'per_page';
3564
+		$args   = [
3565
+			'label'   => apply_filters(
3566
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3567
+				$this->_admin_page_title,
3568
+				$this
3569
+			),
3570
+			'default' => (int) apply_filters(
3571
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3572
+				20
3573
+			),
3574
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3575
+		];
3576
+		// ONLY add the screen option if the user has access to it.
3577
+		if ($this->check_user_access($this->_current_view, true)) {
3578
+			add_screen_option($option, $args);
3579
+		}
3580
+	}
3581
+
3582
+
3583
+	/**
3584
+	 * set_per_page_screen_option
3585
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3586
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3587
+	 * admin_menu.
3588
+	 *
3589
+	 * @return void
3590
+	 */
3591
+	private function _set_per_page_screen_options()
3592
+	{
3593
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3594
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3595
+			if (! $user = wp_get_current_user()) {
3596
+				return;
3597
+			}
3598
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3599
+			if (! $option) {
3600
+				return;
3601
+			}
3602
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3603
+			$map_option = $option;
3604
+			$option     = str_replace('-', '_', $option);
3605
+			switch ($map_option) {
3606
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3607
+					$max_value = apply_filters(
3608
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3609
+						999,
3610
+						$this->_current_page,
3611
+						$this->_current_view
3612
+					);
3613
+					if ($value < 1) {
3614
+						return;
3615
+					}
3616
+					$value = min($value, $max_value);
3617
+					break;
3618
+				default:
3619
+					$value = apply_filters(
3620
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3621
+						false,
3622
+						$option,
3623
+						$value
3624
+					);
3625
+					if (false === $value) {
3626
+						return;
3627
+					}
3628
+					break;
3629
+			}
3630
+			update_user_meta($user->ID, $option, $value);
3631
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3632
+			exit;
3633
+		}
3634
+	}
3635
+
3636
+
3637
+	/**
3638
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3639
+	 *
3640
+	 * @param array $data array that will be assigned to template args.
3641
+	 */
3642
+	public function set_template_args($data)
3643
+	{
3644
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3645
+	}
3646
+
3647
+
3648
+	/**
3649
+	 * This makes available the WP transient system for temporarily moving data between routes
3650
+	 *
3651
+	 * @param string $route             the route that should receive the transient
3652
+	 * @param array  $data              the data that gets sent
3653
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3654
+	 *                                  normal route transient.
3655
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3656
+	 *                                  when we are adding a transient before page_routes have been defined.
3657
+	 * @return void
3658
+	 * @throws EE_Error
3659
+	 */
3660
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3661
+	{
3662
+		$user_id = get_current_user_id();
3663
+		if (! $skip_route_verify) {
3664
+			$this->_verify_route($route);
3665
+		}
3666
+		// now let's set the string for what kind of transient we're setting
3667
+		$transient = $notices
3668
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3669
+			: 'rte_tx_' . $route . '_' . $user_id;
3670
+		$data      = $notices ? ['notices' => $data] : $data;
3671
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3672
+		$existing = is_multisite() && is_network_admin()
3673
+			? get_site_transient($transient)
3674
+			: get_transient($transient);
3675
+		if ($existing) {
3676
+			$data = array_merge((array) $data, (array) $existing);
3677
+		}
3678
+		if (is_multisite() && is_network_admin()) {
3679
+			set_site_transient($transient, $data, 8);
3680
+		} else {
3681
+			set_transient($transient, $data, 8);
3682
+		}
3683
+	}
3684
+
3685
+
3686
+	/**
3687
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3688
+	 *
3689
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3690
+	 * @param string $route
3691
+	 * @return mixed data
3692
+	 */
3693
+	protected function _get_transient($notices = false, $route = '')
3694
+	{
3695
+		$user_id   = get_current_user_id();
3696
+		$route     = ! $route ? $this->_req_action : $route;
3697
+		$transient = $notices
3698
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3699
+			: 'rte_tx_' . $route . '_' . $user_id;
3700
+		$data      = is_multisite() && is_network_admin()
3701
+			? get_site_transient($transient)
3702
+			: get_transient($transient);
3703
+		// delete transient after retrieval (just in case it hasn't expired);
3704
+		if (is_multisite() && is_network_admin()) {
3705
+			delete_site_transient($transient);
3706
+		} else {
3707
+			delete_transient($transient);
3708
+		}
3709
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3710
+	}
3711
+
3712
+
3713
+	/**
3714
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3715
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3716
+	 * default route callback on the EE_Admin page you want it run.)
3717
+	 *
3718
+	 * @return void
3719
+	 */
3720
+	protected function _transient_garbage_collection()
3721
+	{
3722
+		global $wpdb;
3723
+		// retrieve all existing transients
3724
+		$query =
3725
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3726
+		if ($results = $wpdb->get_results($query)) {
3727
+			foreach ($results as $result) {
3728
+				$transient = str_replace('_transient_', '', $result->option_name);
3729
+				get_transient($transient);
3730
+				if (is_multisite() && is_network_admin()) {
3731
+					get_site_transient($transient);
3732
+				}
3733
+			}
3734
+		}
3735
+	}
3736
+
3737
+
3738
+	/**
3739
+	 * get_view
3740
+	 *
3741
+	 * @return string content of _view property
3742
+	 */
3743
+	public function get_view()
3744
+	{
3745
+		return $this->_view;
3746
+	}
3747
+
3748
+
3749
+	/**
3750
+	 * getter for the protected $_views property
3751
+	 *
3752
+	 * @return array
3753
+	 */
3754
+	public function get_views()
3755
+	{
3756
+		return $this->_views;
3757
+	}
3758
+
3759
+
3760
+	/**
3761
+	 * get_current_page
3762
+	 *
3763
+	 * @return string _current_page property value
3764
+	 */
3765
+	public function get_current_page()
3766
+	{
3767
+		return $this->_current_page;
3768
+	}
3769
+
3770
+
3771
+	/**
3772
+	 * get_current_view
3773
+	 *
3774
+	 * @return string _current_view property value
3775
+	 */
3776
+	public function get_current_view()
3777
+	{
3778
+		return $this->_current_view;
3779
+	}
3780
+
3781
+
3782
+	/**
3783
+	 * get_current_screen
3784
+	 *
3785
+	 * @return object The current WP_Screen object
3786
+	 */
3787
+	public function get_current_screen()
3788
+	{
3789
+		return $this->_current_screen;
3790
+	}
3791
+
3792
+
3793
+	/**
3794
+	 * get_current_page_view_url
3795
+	 *
3796
+	 * @return string This returns the url for the current_page_view.
3797
+	 */
3798
+	public function get_current_page_view_url()
3799
+	{
3800
+		return $this->_current_page_view_url;
3801
+	}
3802
+
3803
+
3804
+	/**
3805
+	 * just returns the Request
3806
+	 *
3807
+	 * @return RequestInterface
3808
+	 */
3809
+	public function get_request()
3810
+	{
3811
+		return $this->request;
3812
+	}
3813
+
3814
+
3815
+	/**
3816
+	 * just returns the _req_data property
3817
+	 *
3818
+	 * @return array
3819
+	 */
3820
+	public function get_request_data()
3821
+	{
3822
+		return $this->request->requestParams();
3823
+	}
3824
+
3825
+
3826
+	/**
3827
+	 * returns the _req_data protected property
3828
+	 *
3829
+	 * @return string
3830
+	 */
3831
+	public function get_req_action()
3832
+	{
3833
+		return $this->_req_action;
3834
+	}
3835
+
3836
+
3837
+	/**
3838
+	 * @return bool  value of $_is_caf property
3839
+	 */
3840
+	public function is_caf()
3841
+	{
3842
+		return $this->_is_caf;
3843
+	}
3844
+
3845
+
3846
+	/**
3847
+	 * @return mixed
3848
+	 */
3849
+	public function default_espresso_metaboxes()
3850
+	{
3851
+		return $this->_default_espresso_metaboxes;
3852
+	}
3853
+
3854
+
3855
+	/**
3856
+	 * @return mixed
3857
+	 */
3858
+	public function admin_base_url()
3859
+	{
3860
+		return $this->_admin_base_url;
3861
+	}
3862
+
3863
+
3864
+	/**
3865
+	 * @return mixed
3866
+	 */
3867
+	public function wp_page_slug()
3868
+	{
3869
+		return $this->_wp_page_slug;
3870
+	}
3871
+
3872
+
3873
+	/**
3874
+	 * updates  espresso configuration settings
3875
+	 *
3876
+	 * @param string                   $tab
3877
+	 * @param EE_Config_Base|EE_Config $config
3878
+	 * @param string                   $file file where error occurred
3879
+	 * @param string                   $func function  where error occurred
3880
+	 * @param string                   $line line no where error occurred
3881
+	 * @return boolean
3882
+	 */
3883
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3884
+	{
3885
+		// remove any options that are NOT going to be saved with the config settings.
3886
+		if (isset($config->core->ee_ueip_optin)) {
3887
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3888
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3889
+			update_option('ee_ueip_has_notified', true);
3890
+		}
3891
+		// and save it (note we're also doing the network save here)
3892
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3893
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3894
+		if ($config_saved && $net_saved) {
3895
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3896
+			return true;
3897
+		}
3898
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3899
+		return false;
3900
+	}
3901
+
3902
+
3903
+	/**
3904
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3905
+	 *
3906
+	 * @return array
3907
+	 */
3908
+	public function get_yes_no_values()
3909
+	{
3910
+		return $this->_yes_no_values;
3911
+	}
3912
+
3913
+
3914
+	protected function _get_dir()
3915
+	{
3916
+		$reflector = new ReflectionClass(get_class($this));
3917
+		return dirname($reflector->getFileName());
3918
+	}
3919
+
3920
+
3921
+	/**
3922
+	 * A helper for getting a "next link".
3923
+	 *
3924
+	 * @param string $url   The url to link to
3925
+	 * @param string $class The class to use.
3926
+	 * @return string
3927
+	 */
3928
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3929
+	{
3930
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3931
+	}
3932
+
3933
+
3934
+	/**
3935
+	 * A helper for getting a "previous link".
3936
+	 *
3937
+	 * @param string $url   The url to link to
3938
+	 * @param string $class The class to use.
3939
+	 * @return string
3940
+	 */
3941
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3942
+	{
3943
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3944
+	}
3945
+
3946
+
3947
+
3948
+
3949
+
3950
+
3951
+
3952
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3953
+
3954
+
3955
+	/**
3956
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
3957
+	 * 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
3958
+	 * _req_data array.
3959
+	 *
3960
+	 * @return bool success/fail
3961
+	 * @throws EE_Error
3962
+	 * @throws InvalidArgumentException
3963
+	 * @throws ReflectionException
3964
+	 * @throws InvalidDataTypeException
3965
+	 * @throws InvalidInterfaceException
3966
+	 */
3967
+	protected function _process_resend_registration()
3968
+	{
3969
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3970
+		do_action(
3971
+			'AHEE__EE_Admin_Page___process_resend_registration',
3972
+			$this->_template_args['success'],
3973
+			$this->request->requestParams()
3974
+		);
3975
+		return $this->_template_args['success'];
3976
+	}
3977
+
3978
+
3979
+	/**
3980
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3981
+	 *
3982
+	 * @param EE_Payment $payment
3983
+	 * @return bool success/fail
3984
+	 */
3985
+	protected function _process_payment_notification(EE_Payment $payment)
3986
+	{
3987
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3988
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3989
+		$this->_template_args['success'] = apply_filters(
3990
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
3991
+			false,
3992
+			$payment
3993
+		);
3994
+		return $this->_template_args['success'];
3995
+	}
3996
+
3997
+
3998
+	/**
3999
+	 * @param EEM_Base      $entity_model
4000
+	 * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4001
+	 * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4002
+	 * @param string        $delete_column  name of the field that denotes whether entity is trashed
4003
+	 * @param callable|null $callback       called after entity is trashed, restored, or deleted
4004
+	 * @return int|float
4005
+	 * @throws EE_Error
4006
+	 */
4007
+	protected function trashRestoreDeleteEntities(
4008
+		EEM_Base $entity_model,
4009
+		$entity_PK_name,
4010
+		$action = EE_Admin_List_Table::ACTION_DELETE,
4011
+		$delete_column = '',
4012
+		callable $callback = null
4013
+	) {
4014
+		$entity_PK      = $entity_model->get_primary_key_field();
4015
+		$entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4016
+		$entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4017
+		// grab ID if deleting a single entity
4018
+		if ($this->request->requestParamIsSet($entity_PK_name)) {
4019
+			$ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4020
+			return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4021
+		}
4022
+		// or grab checkbox array if bulk deleting
4023
+		$checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4024
+		if (empty($checkboxes)) {
4025
+			return 0;
4026
+		}
4027
+		$success = 0;
4028
+		$IDs     = array_keys($checkboxes);
4029
+		// cycle thru bulk action checkboxes
4030
+		foreach ($IDs as $ID) {
4031
+			// increment $success
4032
+			if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4033
+				$success++;
4034
+			}
4035
+		}
4036
+		$count = (int) count($checkboxes);
4037
+		// if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4038
+		// otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4039
+		return $success === $count ? $count : $success / $count;
4040
+	}
4041
+
4042
+
4043
+	/**
4044
+	 * @param EE_Primary_Key_Field_Base $entity_PK
4045
+	 * @return string
4046
+	 * @throws EE_Error
4047
+	 * @since   4.10.30.p
4048
+	 */
4049
+	private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK)
4050
+	{
4051
+		$entity_PK_type = $entity_PK->getSchemaType();
4052
+		switch ($entity_PK_type) {
4053
+			case 'boolean':
4054
+				return 'bool';
4055
+			case 'integer':
4056
+				return 'int';
4057
+			case 'number':
4058
+				return 'float';
4059
+			case 'string':
4060
+				return 'string';
4061
+		}
4062
+		throw new RuntimeException(
4063
+			sprintf(
4064
+				esc_html__(
4065
+					'"%1$s" is an invalid schema type for the %2$s primary key.',
4066
+					'event_espresso'
4067
+				),
4068
+				$entity_PK_type,
4069
+				$entity_PK->get_name()
4070
+			)
4071
+		);
4072
+	}
4073
+
4074
+
4075
+	/**
4076
+	 * @param EEM_Base      $entity_model
4077
+	 * @param int|string    $entity_ID
4078
+	 * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4079
+	 * @param string        $delete_column name of the field that denotes whether entity is trashed
4080
+	 * @param callable|null $callback      called after entity is trashed, restored, or deleted
4081
+	 * @return bool
4082
+	 */
4083
+	protected function trashRestoreDeleteEntity(
4084
+		EEM_Base $entity_model,
4085
+		$entity_ID,
4086
+		$action,
4087
+		$delete_column,
4088
+		callable $callback = null
4089
+	) {
4090
+		$entity_ID = absint($entity_ID);
4091
+		if (! $entity_ID) {
4092
+			$this->trashRestoreDeleteError($action, $entity_model);
4093
+		}
4094
+		$result = 0;
4095
+		try {
4096
+			$entity = $entity_model->get_one_by_ID($entity_ID);
4097
+			if (! $entity instanceof EE_Base_Class) {
4098
+				throw new DomainException(
4099
+					sprintf(
4100
+						esc_html__(
4101
+							'Missing or invalid %1$s entity with ID of "%2$s" returned from db.',
4102
+							'event_espresso'
4103
+						),
4104
+						str_replace('EEM_', '', $entity_model->get_this_model_name()),
4105
+						$entity_ID
4106
+					)
4107
+				);
4108
+			}
4109
+			switch ($action) {
4110
+				case EE_Admin_List_Table::ACTION_DELETE:
4111
+					$result = (bool) $entity->delete_permanently();
4112
+					break;
4113
+				case EE_Admin_List_Table::ACTION_RESTORE:
4114
+					$result = $entity->delete_or_restore(false);
4115
+					break;
4116
+				case EE_Admin_List_Table::ACTION_TRASH:
4117
+					$result = $entity->delete_or_restore();
4118
+					break;
4119
+			}
4120
+		} catch (Exception $exception) {
4121
+			$this->trashRestoreDeleteError($action, $entity_model, $exception);
4122
+		}
4123
+		if (is_callable($callback)) {
4124
+			call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4125
+		}
4126
+		return $result;
4127
+	}
4128
+
4129
+
4130
+	/**
4131
+	 * @param EEM_Base $entity_model
4132
+	 * @param string   $delete_column
4133
+	 * @since 4.10.30.p
4134
+	 */
4135
+	private function validateDeleteColumn(EEM_Base $entity_model, $delete_column)
4136
+	{
4137
+		if (empty($delete_column)) {
4138
+			throw new DomainException(
4139
+				sprintf(
4140
+					esc_html__(
4141
+						'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4142
+						'event_espresso'
4143
+					),
4144
+					$entity_model->get_this_model_name()
4145
+				)
4146
+			);
4147
+		}
4148
+		if (! $entity_model->has_field($delete_column)) {
4149
+			throw new DomainException(
4150
+				sprintf(
4151
+					esc_html__(
4152
+						'The %1$s field does not exist on the %2$s model.',
4153
+						'event_espresso'
4154
+					),
4155
+					$delete_column,
4156
+					$entity_model->get_this_model_name()
4157
+				)
4158
+			);
4159
+		}
4160
+	}
4161
+
4162
+
4163
+	/**
4164
+	 * @param EEM_Base       $entity_model
4165
+	 * @param Exception|null $exception
4166
+	 * @param string         $action
4167
+	 * @since 4.10.30.p
4168
+	 */
4169
+	private function trashRestoreDeleteError($action, EEM_Base $entity_model, Exception $exception = null)
4170
+	{
4171
+		if ($exception instanceof Exception) {
4172
+			throw new RuntimeException(
4173
+				sprintf(
4174
+					esc_html__(
4175
+						'Could not %1$s the %2$s because the following error occurred: %3$s',
4176
+						'event_espresso'
4177
+					),
4178
+					$action,
4179
+					$entity_model->get_this_model_name(),
4180
+					$exception->getMessage()
4181
+				)
4182
+			);
4183
+		}
4184
+		throw new RuntimeException(
4185
+			sprintf(
4186
+				esc_html__(
4187
+					'Could not %1$s the %2$s because an invalid ID was received.',
4188
+					'event_espresso'
4189
+				),
4190
+				$action,
4191
+				$entity_model->get_this_model_name()
4192
+			)
4193
+		);
4194
+	}
4195 4195
 }
Please login to merge, or discard this patch.
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
         $ee_menu_slugs = (array) $ee_menu_slugs;
514 514
         if (
515 515
             ! $this->request->isAjax()
516
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
516
+            && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))
517 517
         ) {
518 518
             return;
519 519
         }
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
             : $req_action;
534 534
 
535 535
         $this->_current_view = $this->_req_action;
536
-        $this->_req_nonce    = $this->_req_action . '_nonce';
536
+        $this->_req_nonce    = $this->_req_action.'_nonce';
537 537
         $this->_define_page_props();
538 538
         $this->_current_page_view_url = add_query_arg(
539 539
             ['page' => $this->_current_page, 'action' => $this->_current_view],
@@ -570,21 +570,21 @@  discard block
 block discarded – undo
570 570
         }
571 571
         // filter routes and page_config so addons can add their stuff. Filtering done per class
572 572
         $this->_page_routes = apply_filters(
573
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
573
+            'FHEE__'.get_class($this).'__page_setup__page_routes',
574 574
             $this->_page_routes,
575 575
             $this
576 576
         );
577 577
         $this->_page_config = apply_filters(
578
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
578
+            'FHEE__'.get_class($this).'__page_setup__page_config',
579 579
             $this->_page_config,
580 580
             $this
581 581
         );
582 582
         // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
583 583
         // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
584
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
584
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
585 585
             add_action(
586 586
                 'AHEE__EE_Admin_Page__route_admin_request',
587
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
587
+                [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view],
588 588
                 10,
589 589
                 2
590 590
             );
@@ -597,8 +597,8 @@  discard block
 block discarded – undo
597 597
             if ($this->_is_UI_request) {
598 598
                 // admin_init stuff - global, all views for this page class, specific view
599 599
                 add_action('admin_init', [$this, 'admin_init'], 10);
600
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
601
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
600
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
601
+                    add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15);
602 602
                 }
603 603
             } else {
604 604
                 // hijack regular WP loading and route admin request immediately
@@ -617,12 +617,12 @@  discard block
 block discarded – undo
617 617
      */
618 618
     private function _do_other_page_hooks()
619 619
     {
620
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
620
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []);
621 621
         foreach ($registered_pages as $page) {
622 622
             // now let's setup the file name and class that should be present
623 623
             $classname = str_replace('.class.php', '', $page);
624 624
             // autoloaders should take care of loading file
625
-            if (! class_exists($classname)) {
625
+            if ( ! class_exists($classname)) {
626 626
                 $error_msg[] = sprintf(
627 627
                     esc_html__(
628 628
                         'Something went wrong with loading the %s admin hooks page.',
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
                                    ),
640 640
                                    $page,
641 641
                                    '<br />',
642
-                                   '<strong>' . $classname . '</strong>'
642
+                                   '<strong>'.$classname.'</strong>'
643 643
                                );
644 644
                 throw new EE_Error(implode('||', $error_msg));
645 645
             }
@@ -681,13 +681,13 @@  discard block
 block discarded – undo
681 681
         // load admin_notices - global, page class, and view specific
682 682
         add_action('admin_notices', [$this, 'admin_notices_global'], 5);
683 683
         add_action('admin_notices', [$this, 'admin_notices'], 10);
684
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
685
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
684
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
685
+            add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15);
686 686
         }
687 687
         // load network admin_notices - global, page class, and view specific
688 688
         add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
689
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
690
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
689
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
690
+            add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]);
691 691
         }
692 692
         // this will save any per_page screen options if they are present
693 693
         $this->_set_per_page_screen_options();
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
     protected function _verify_routes()
809 809
     {
810 810
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
811
-        if (! $this->_current_page && ! $this->request->isAjax()) {
811
+        if ( ! $this->_current_page && ! $this->request->isAjax()) {
812 812
             return false;
813 813
         }
814 814
         $this->_route = false;
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
                 $this->_admin_page_title
821 821
             );
822 822
             // developer error msg
823
-            $error_msg .= '||' . $error_msg
823
+            $error_msg .= '||'.$error_msg
824 824
                           . esc_html__(
825 825
                               ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
826 826
                               'event_espresso'
@@ -829,9 +829,9 @@  discard block
 block discarded – undo
829 829
         }
830 830
         // and that the requested page route exists
831 831
         if (array_key_exists($this->_req_action, $this->_page_routes)) {
832
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
833
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
834
-                ? $this->_page_config[ $this->_req_action ]
832
+            $this->_route        = $this->_page_routes[$this->_req_action];
833
+            $this->_route_config = isset($this->_page_config[$this->_req_action])
834
+                ? $this->_page_config[$this->_req_action]
835 835
                 : [];
836 836
         } else {
837 837
             // user error msg
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
                 $this->_admin_page_title
844 844
             );
845 845
             // developer error msg
846
-            $error_msg .= '||' . $error_msg
846
+            $error_msg .= '||'.$error_msg
847 847
                           . sprintf(
848 848
                               esc_html__(
849 849
                                   ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
             throw new EE_Error($error_msg);
855 855
         }
856 856
         // and that a default route exists
857
-        if (! array_key_exists('default', $this->_page_routes)) {
857
+        if ( ! array_key_exists('default', $this->_page_routes)) {
858 858
             // user error msg
859 859
             $error_msg = sprintf(
860 860
                 esc_html__(
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
                 $this->_admin_page_title
865 865
             );
866 866
             // developer error msg
867
-            $error_msg .= '||' . $error_msg
867
+            $error_msg .= '||'.$error_msg
868 868
                           . esc_html__(
869 869
                               ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
870 870
                               'event_espresso'
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
             $this->_admin_page_title
906 906
         );
907 907
         // developer error msg
908
-        $error_msg .= '||' . $error_msg
908
+        $error_msg .= '||'.$error_msg
909 909
                       . sprintf(
910 910
                           esc_html__(
911 911
                               ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
     protected function _verify_nonce($nonce, $nonce_ref)
931 931
     {
932 932
         // verify nonce against expected value
933
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
933
+        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
934 934
             // these are not the droids you are looking for !!!
935 935
             $msg = sprintf(
936 936
                 esc_html__('%sNonce Fail.%s', 'event_espresso'),
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
                     __CLASS__
948 948
                 );
949 949
             }
950
-            if (! $this->request->isAjax()) {
950
+            if ( ! $this->request->isAjax()) {
951 951
                 wp_die($msg);
952 952
             }
953 953
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
      */
972 972
     protected function _route_admin_request()
973 973
     {
974
-        if (! $this->_is_UI_request) {
974
+        if ( ! $this->_is_UI_request) {
975 975
             $this->_verify_routes();
976 976
         }
977 977
         $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
         $error_msg = '';
992 992
         // action right before calling route
993 993
         // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
994
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
994
+        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
995 995
             do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
996 996
         }
997 997
         // right before calling the route, let's clean the _wp_http_referer
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
         );
1004 1004
         $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri);
1005 1005
         $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri);
1006
-        if (! empty($func)) {
1006
+        if ( ! empty($func)) {
1007 1007
             if (is_array($func)) {
1008 1008
                 [$class, $method] = $func;
1009 1009
             } elseif (strpos($func, '::') !== false) {
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
                 $class  = $this;
1013 1013
                 $method = $func;
1014 1014
             }
1015
-            if (! (is_object($class) && $class === $this)) {
1015
+            if ( ! (is_object($class) && $class === $this)) {
1016 1016
                 // send along this admin page object for access by addons.
1017 1017
                 $args['admin_page_object'] = $this;
1018 1018
             }
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
                     $method
1054 1054
                 );
1055 1055
             }
1056
-            if (! empty($error_msg)) {
1056
+            if ( ! empty($error_msg)) {
1057 1057
                 throw new EE_Error($error_msg);
1058 1058
             }
1059 1059
         }
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
                 if (strpos($key, 'nonce') !== false) {
1139 1139
                     continue;
1140 1140
                 }
1141
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1141
+                $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value;
1142 1142
             }
1143 1143
         }
1144 1144
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1177,12 +1177,12 @@  discard block
 block discarded – undo
1177 1177
      */
1178 1178
     protected function _add_help_tabs()
1179 1179
     {
1180
-        if (isset($this->_page_config[ $this->_req_action ])) {
1181
-            $config = $this->_page_config[ $this->_req_action ];
1180
+        if (isset($this->_page_config[$this->_req_action])) {
1181
+            $config = $this->_page_config[$this->_req_action];
1182 1182
             // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1183 1183
             if (is_array($config) && isset($config['help_sidebar'])) {
1184 1184
                 // check that the callback given is valid
1185
-                if (! method_exists($this, $config['help_sidebar'])) {
1185
+                if ( ! method_exists($this, $config['help_sidebar'])) {
1186 1186
                     throw new EE_Error(
1187 1187
                         sprintf(
1188 1188
                             esc_html__(
@@ -1195,18 +1195,18 @@  discard block
 block discarded – undo
1195 1195
                     );
1196 1196
                 }
1197 1197
                 $content = apply_filters(
1198
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1198
+                    'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar',
1199 1199
                     $this->{$config['help_sidebar']}()
1200 1200
                 );
1201 1201
                 $this->_current_screen->set_help_sidebar($content);
1202 1202
             }
1203
-            if (! isset($config['help_tabs'])) {
1203
+            if ( ! isset($config['help_tabs'])) {
1204 1204
                 return;
1205 1205
             } //no help tabs for this route
1206 1206
             foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1207 1207
                 // we're here so there ARE help tabs!
1208 1208
                 // make sure we've got what we need
1209
-                if (! isset($cfg['title'])) {
1209
+                if ( ! isset($cfg['title'])) {
1210 1210
                     throw new EE_Error(
1211 1211
                         esc_html__(
1212 1212
                             'The _page_config array is not set up properly for help tabs.  It is missing a title',
@@ -1214,7 +1214,7 @@  discard block
 block discarded – undo
1214 1214
                         )
1215 1215
                     );
1216 1216
                 }
1217
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1217
+                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1218 1218
                     throw new EE_Error(
1219 1219
                         esc_html__(
1220 1220
                             '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',
@@ -1223,11 +1223,11 @@  discard block
 block discarded – undo
1223 1223
                     );
1224 1224
                 }
1225 1225
                 // first priority goes to content.
1226
-                if (! empty($cfg['content'])) {
1226
+                if ( ! empty($cfg['content'])) {
1227 1227
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1228 1228
                     // second priority goes to filename
1229
-                } elseif (! empty($cfg['filename'])) {
1230
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1229
+                } elseif ( ! empty($cfg['filename'])) {
1230
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1231 1231
                     // 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)
1232 1232
                     $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1233 1233
                                                              . basename($this->_get_dir())
@@ -1235,7 +1235,7 @@  discard block
 block discarded – undo
1235 1235
                                                              . $cfg['filename']
1236 1236
                                                              . '.help_tab.php' : $file_path;
1237 1237
                     // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1238
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1238
+                    if ( ! isset($cfg['callback']) && ! is_readable($file_path)) {
1239 1239
                         EE_Error::add_error(
1240 1240
                             sprintf(
1241 1241
                                 esc_html__(
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
                     return;
1284 1284
                 }
1285 1285
                 // setup config array for help tab method
1286
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1286
+                $id  = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1287 1287
                 $_ht = [
1288 1288
                     'id'       => $id,
1289 1289
                     'title'    => $cfg['title'],
@@ -1307,8 +1307,8 @@  discard block
 block discarded – undo
1307 1307
             $qtips = (array) $this->_route_config['qtips'];
1308 1308
             // load qtip loader
1309 1309
             $path = [
1310
-                $this->_get_dir() . '/qtips/',
1311
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1310
+                $this->_get_dir().'/qtips/',
1311
+                EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1312 1312
             ];
1313 1313
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1314 1314
         }
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1331 1331
         $i = 0;
1332 1332
         foreach ($this->_page_config as $slug => $config) {
1333
-            if (! is_array($config) || empty($config['nav'])) {
1333
+            if ( ! is_array($config) || empty($config['nav'])) {
1334 1334
                 continue;
1335 1335
             }
1336 1336
             // no nav tab for this config
@@ -1339,12 +1339,12 @@  discard block
 block discarded – undo
1339 1339
                 // nav tab is only to appear when route requested.
1340 1340
                 continue;
1341 1341
             }
1342
-            if (! $this->check_user_access($slug, true)) {
1342
+            if ( ! $this->check_user_access($slug, true)) {
1343 1343
                 // no nav tab because current user does not have access.
1344 1344
                 continue;
1345 1345
             }
1346
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1347
-            $this->_nav_tabs[ $slug ] = [
1346
+            $css_class                = isset($config['css_class']) ? $config['css_class'].' ' : '';
1347
+            $this->_nav_tabs[$slug] = [
1348 1348
                 'url'       => isset($config['nav']['url'])
1349 1349
                     ? $config['nav']['url']
1350 1350
                     : self::add_query_args_and_nonce(
@@ -1356,14 +1356,14 @@  discard block
 block discarded – undo
1356 1356
                     : ucwords(
1357 1357
                         str_replace('_', ' ', $slug)
1358 1358
                     ),
1359
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1359
+                'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class,
1360 1360
                 'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1361 1361
             ];
1362 1362
             $i++;
1363 1363
         }
1364 1364
         // if $this->_nav_tabs is empty then lets set the default
1365 1365
         if (empty($this->_nav_tabs)) {
1366
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1366
+            $this->_nav_tabs[$this->_default_nav_tab_name] = [
1367 1367
                 'url'       => $this->_admin_base_url,
1368 1368
                 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1369 1369
                 'css_class' => 'nav-tab-active',
@@ -1388,10 +1388,10 @@  discard block
 block discarded – undo
1388 1388
             foreach ($this->_route_config['labels'] as $label => $text) {
1389 1389
                 if (is_array($text)) {
1390 1390
                     foreach ($text as $sublabel => $subtext) {
1391
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1391
+                        $this->_labels[$label][$sublabel] = $subtext;
1392 1392
                     }
1393 1393
                 } else {
1394
-                    $this->_labels[ $label ] = $text;
1394
+                    $this->_labels[$label] = $text;
1395 1395
                 }
1396 1396
             }
1397 1397
         }
@@ -1413,12 +1413,12 @@  discard block
 block discarded – undo
1413 1413
     {
1414 1414
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1415 1415
         $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1416
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1416
+        $capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1417 1417
                           && is_array(
1418
-                              $this->_page_routes[ $route_to_check ]
1418
+                              $this->_page_routes[$route_to_check]
1419 1419
                           )
1420
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1421
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1420
+                          && ! empty($this->_page_routes[$route_to_check]['capability'])
1421
+            ? $this->_page_routes[$route_to_check]['capability'] : null;
1422 1422
         if (empty($capability) && empty($route_to_check)) {
1423 1423
             $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1424 1424
                 : $this->_route['capability'];
@@ -1538,7 +1538,7 @@  discard block
 block discarded – undo
1538 1538
         ';
1539 1539
 
1540 1540
         // current set timezone for timezone js
1541
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1541
+        echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>';
1542 1542
     }
1543 1543
 
1544 1544
 
@@ -1572,7 +1572,7 @@  discard block
 block discarded – undo
1572 1572
         // loop through the array and setup content
1573 1573
         foreach ($help_array as $trigger => $help) {
1574 1574
             // make sure the array is setup properly
1575
-            if (! isset($help['title']) || ! isset($help['content'])) {
1575
+            if ( ! isset($help['title']) || ! isset($help['content'])) {
1576 1576
                 throw new EE_Error(
1577 1577
                     esc_html__(
1578 1578
                         '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',
@@ -1586,8 +1586,8 @@  discard block
 block discarded – undo
1586 1586
                 'help_popup_title'   => $help['title'],
1587 1587
                 'help_popup_content' => $help['content'],
1588 1588
             ];
1589
-            $content       .= EEH_Template::display_template(
1590
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1589
+            $content .= EEH_Template::display_template(
1590
+                EE_ADMIN_TEMPLATE.'admin_help_popup.template.php',
1591 1591
                 $template_args,
1592 1592
                 true
1593 1593
             );
@@ -1609,15 +1609,15 @@  discard block
 block discarded – undo
1609 1609
     private function _get_help_content()
1610 1610
     {
1611 1611
         // what is the method we're looking for?
1612
-        $method_name = '_help_popup_content_' . $this->_req_action;
1612
+        $method_name = '_help_popup_content_'.$this->_req_action;
1613 1613
         // if method doesn't exist let's get out.
1614
-        if (! method_exists($this, $method_name)) {
1614
+        if ( ! method_exists($this, $method_name)) {
1615 1615
             return [];
1616 1616
         }
1617 1617
         // k we're good to go let's retrieve the help array
1618 1618
         $help_array = call_user_func([$this, $method_name]);
1619 1619
         // make sure we've got an array!
1620
-        if (! is_array($help_array)) {
1620
+        if ( ! is_array($help_array)) {
1621 1621
             throw new EE_Error(
1622 1622
                 esc_html__(
1623 1623
                     'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
@@ -1649,15 +1649,15 @@  discard block
 block discarded – undo
1649 1649
         // 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
1650 1650
         $help_array   = $this->_get_help_content();
1651 1651
         $help_content = '';
1652
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1653
-            $help_array[ $trigger_id ] = [
1652
+        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1653
+            $help_array[$trigger_id] = [
1654 1654
                 'title'   => esc_html__('Missing Content', 'event_espresso'),
1655 1655
                 'content' => esc_html__(
1656 1656
                     '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.)',
1657 1657
                     'event_espresso'
1658 1658
                 ),
1659 1659
             ];
1660
-            $help_content              = $this->_set_help_popup_content($help_array);
1660
+            $help_content = $this->_set_help_popup_content($help_array);
1661 1661
         }
1662 1662
         // let's setup the trigger
1663 1663
         $content = '<a class="ee-dialog" href="?height='
@@ -1725,15 +1725,15 @@  discard block
 block discarded – undo
1725 1725
         // register all styles
1726 1726
         wp_register_style(
1727 1727
             'espresso-ui-theme',
1728
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1728
+            EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1729 1729
             [],
1730 1730
             EVENT_ESPRESSO_VERSION
1731 1731
         );
1732
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1732
+        wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1733 1733
         // helpers styles
1734 1734
         wp_register_style(
1735 1735
             'ee-text-links',
1736
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1736
+            EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css',
1737 1737
             [],
1738 1738
             EVENT_ESPRESSO_VERSION
1739 1739
         );
@@ -1741,21 +1741,21 @@  discard block
 block discarded – undo
1741 1741
         // register all scripts
1742 1742
         wp_register_script(
1743 1743
             'ee-dialog',
1744
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1744
+            EE_ADMIN_URL.'assets/ee-dialog-helper.js',
1745 1745
             ['jquery', 'jquery-ui-draggable'],
1746 1746
             EVENT_ESPRESSO_VERSION,
1747 1747
             true
1748 1748
         );
1749 1749
         wp_register_script(
1750 1750
             'ee_admin_js',
1751
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1751
+            EE_ADMIN_URL.'assets/ee-admin-page.js',
1752 1752
             ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1753 1753
             EVENT_ESPRESSO_VERSION,
1754 1754
             true
1755 1755
         );
1756 1756
         wp_register_script(
1757 1757
             'jquery-ui-timepicker-addon',
1758
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1758
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js',
1759 1759
             ['jquery-ui-datepicker', 'jquery-ui-slider'],
1760 1760
             EVENT_ESPRESSO_VERSION,
1761 1761
             true
@@ -1763,7 +1763,7 @@  discard block
 block discarded – undo
1763 1763
         // script for sorting tables
1764 1764
         wp_register_script(
1765 1765
             'espresso_ajax_table_sorting',
1766
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1766
+            EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js',
1767 1767
             ['ee_admin_js', 'jquery-ui-sortable'],
1768 1768
             EVENT_ESPRESSO_VERSION,
1769 1769
             true
@@ -1771,7 +1771,7 @@  discard block
 block discarded – undo
1771 1771
         // script for parsing uri's
1772 1772
         wp_register_script(
1773 1773
             'ee-parse-uri',
1774
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1774
+            EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js',
1775 1775
             [],
1776 1776
             EVENT_ESPRESSO_VERSION,
1777 1777
             true
@@ -1779,7 +1779,7 @@  discard block
 block discarded – undo
1779 1779
         // and parsing associative serialized form elements
1780 1780
         wp_register_script(
1781 1781
             'ee-serialize-full-array',
1782
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1782
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js',
1783 1783
             ['jquery'],
1784 1784
             EVENT_ESPRESSO_VERSION,
1785 1785
             true
@@ -1787,28 +1787,28 @@  discard block
 block discarded – undo
1787 1787
         // helpers scripts
1788 1788
         wp_register_script(
1789 1789
             'ee-text-links',
1790
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1790
+            EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js',
1791 1791
             ['jquery'],
1792 1792
             EVENT_ESPRESSO_VERSION,
1793 1793
             true
1794 1794
         );
1795 1795
         wp_register_script(
1796 1796
             'ee-moment-core',
1797
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1797
+            EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js',
1798 1798
             [],
1799 1799
             EVENT_ESPRESSO_VERSION,
1800 1800
             true
1801 1801
         );
1802 1802
         wp_register_script(
1803 1803
             'ee-moment',
1804
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1804
+            EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js',
1805 1805
             ['ee-moment-core'],
1806 1806
             EVENT_ESPRESSO_VERSION,
1807 1807
             true
1808 1808
         );
1809 1809
         wp_register_script(
1810 1810
             'ee-datepicker',
1811
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1811
+            EE_ADMIN_URL.'assets/ee-datepicker.js',
1812 1812
             ['jquery-ui-timepicker-addon', 'ee-moment'],
1813 1813
             EVENT_ESPRESSO_VERSION,
1814 1814
             true
@@ -1841,7 +1841,7 @@  discard block
 block discarded – undo
1841 1841
         wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1842 1842
         add_filter(
1843 1843
             'admin_body_class',
1844
-            function ($classes) {
1844
+            function($classes) {
1845 1845
                 if (strpos($classes, 'espresso-admin') === false) {
1846 1846
                     $classes .= ' espresso-admin';
1847 1847
                 }
@@ -1929,12 +1929,12 @@  discard block
 block discarded – undo
1929 1929
     protected function _set_list_table()
1930 1930
     {
1931 1931
         // first is this a list_table view?
1932
-        if (! isset($this->_route_config['list_table'])) {
1932
+        if ( ! isset($this->_route_config['list_table'])) {
1933 1933
             return;
1934 1934
         } //not a list_table view so get out.
1935 1935
         // list table functions are per view specific (because some admin pages might have more than one list table!)
1936
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
1937
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1936
+        $list_table_view = '_set_list_table_views_'.$this->_req_action;
1937
+        if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1938 1938
             // user error msg
1939 1939
             $error_msg = esc_html__(
1940 1940
                 'An error occurred. The requested list table views could not be found.',
@@ -1954,10 +1954,10 @@  discard block
 block discarded – undo
1954 1954
         }
1955 1955
         // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1956 1956
         $this->_views = apply_filters(
1957
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1957
+            'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action,
1958 1958
             $this->_views
1959 1959
         );
1960
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1960
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
1961 1961
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1962 1962
         $this->_set_list_table_view();
1963 1963
         $this->_set_list_table_object();
@@ -1992,7 +1992,7 @@  discard block
 block discarded – undo
1992 1992
     protected function _set_list_table_object()
1993 1993
     {
1994 1994
         if (isset($this->_route_config['list_table'])) {
1995
-            if (! class_exists($this->_route_config['list_table'])) {
1995
+            if ( ! class_exists($this->_route_config['list_table'])) {
1996 1996
                 throw new EE_Error(
1997 1997
                     sprintf(
1998 1998
                         esc_html__(
@@ -2030,15 +2030,15 @@  discard block
 block discarded – undo
2030 2030
         foreach ($this->_views as $key => $view) {
2031 2031
             $query_args = [];
2032 2032
             // check for current view
2033
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2033
+            $this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2034 2034
             $query_args['action']                        = $this->_req_action;
2035
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2035
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
2036 2036
             $query_args['status']                        = $view['slug'];
2037 2037
             // merge any other arguments sent in.
2038
-            if (isset($extra_query_args[ $view['slug'] ])) {
2039
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2038
+            if (isset($extra_query_args[$view['slug']])) {
2039
+                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
2040 2040
             }
2041
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2041
+            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2042 2042
         }
2043 2043
         return $this->_views;
2044 2044
     }
@@ -2069,14 +2069,14 @@  discard block
 block discarded – undo
2069 2069
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2070 2070
         foreach ($values as $value) {
2071 2071
             if ($value < $max_entries) {
2072
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2072
+                $selected = $value === $per_page ? ' selected="'.$per_page.'"' : '';
2073 2073
                 $entries_per_page_dropdown .= '
2074
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2074
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
2075 2075
             }
2076 2076
         }
2077
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2077
+        $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : '';
2078 2078
         $entries_per_page_dropdown .= '
2079
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2079
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
2080 2080
         $entries_per_page_dropdown .= '
2081 2081
 					</select>
2082 2082
 					entries
@@ -2100,7 +2100,7 @@  discard block
 block discarded – undo
2100 2100
             empty($this->_search_btn_label) ? $this->page_label
2101 2101
                 : $this->_search_btn_label
2102 2102
         );
2103
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2103
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
2104 2104
     }
2105 2105
 
2106 2106
 
@@ -2188,7 +2188,7 @@  discard block
 block discarded – undo
2188 2188
             $total_columns                                       = ! empty($screen_columns)
2189 2189
                 ? $screen_columns
2190 2190
                 : $this->_route_config['columns'][1];
2191
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2191
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
2192 2192
             $this->_template_args['current_page']                = $this->_wp_page_slug;
2193 2193
             $this->_template_args['screen']                      = $this->_current_screen;
2194 2194
             $this->_column_template_path                         = EE_ADMIN_TEMPLATE
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
      */
2234 2234
     protected function _espresso_ratings_request()
2235 2235
     {
2236
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2236
+        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2237 2237
             return;
2238 2238
         }
2239 2239
         $ratings_box_title = apply_filters(
@@ -2261,7 +2261,7 @@  discard block
 block discarded – undo
2261 2261
     public function espresso_ratings_request()
2262 2262
     {
2263 2263
         EEH_Template::display_template(
2264
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2264
+            EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php',
2265 2265
             []
2266 2266
         );
2267 2267
     }
@@ -2269,22 +2269,22 @@  discard block
 block discarded – undo
2269 2269
 
2270 2270
     public static function cached_rss_display($rss_id, $url)
2271 2271
     {
2272
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2272
+        $loading = '<p class="widget-loading hide-if-no-js">'
2273 2273
                      . esc_html__('Loading&#8230;', 'event_espresso')
2274 2274
                      . '</p><p class="hide-if-js">'
2275 2275
                      . esc_html__('This widget requires JavaScript.', 'event_espresso')
2276 2276
                      . '</p>';
2277
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2278
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2279
-        $post      = '</div>' . "\n";
2280
-        $cache_key = 'ee_rss_' . md5($rss_id);
2277
+        $pre       = '<div class="espresso-rss-display">'."\n\t";
2278
+        $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>';
2279
+        $post      = '</div>'."\n";
2280
+        $cache_key = 'ee_rss_'.md5($rss_id);
2281 2281
         $output    = get_transient($cache_key);
2282 2282
         if ($output !== false) {
2283
-            echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2283
+            echo wp_kses($pre.$output.$post, AllowedTags::getWithFormTags());
2284 2284
             return true;
2285 2285
         }
2286
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2287
-            echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2286
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
2287
+            echo wp_kses($pre.$loading.$post, AllowedTags::getWithFormTags());
2288 2288
             return false;
2289 2289
         }
2290 2290
         ob_start();
@@ -2351,19 +2351,19 @@  discard block
 block discarded – undo
2351 2351
     public function espresso_sponsors_post_box()
2352 2352
     {
2353 2353
         EEH_Template::display_template(
2354
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2354
+            EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'
2355 2355
         );
2356 2356
     }
2357 2357
 
2358 2358
 
2359 2359
     private function _publish_post_box()
2360 2360
     {
2361
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2361
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2362 2362
         // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2363 2363
         // then we'll use that for the metabox label.
2364 2364
         // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2365
-        if (! empty($this->_labels['publishbox'])) {
2366
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2365
+        if ( ! empty($this->_labels['publishbox'])) {
2366
+            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2367 2367
                 : $this->_labels['publishbox'];
2368 2368
         } else {
2369 2369
             $box_label = esc_html__('Publish', 'event_espresso');
@@ -2392,7 +2392,7 @@  discard block
 block discarded – undo
2392 2392
             ? $this->_template_args['publish_box_extra_content']
2393 2393
             : '';
2394 2394
         echo EEH_Template::display_template(
2395
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2395
+            EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php',
2396 2396
             $this->_template_args,
2397 2397
             true
2398 2398
         );
@@ -2484,18 +2484,18 @@  discard block
 block discarded – undo
2484 2484
             );
2485 2485
         }
2486 2486
         $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2487
-        if (! empty($name) && ! empty($id)) {
2488
-            $hidden_field_arr[ $name ] = [
2487
+        if ( ! empty($name) && ! empty($id)) {
2488
+            $hidden_field_arr[$name] = [
2489 2489
                 'type'  => 'hidden',
2490 2490
                 'value' => $id,
2491 2491
             ];
2492
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2492
+            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2493 2493
         } else {
2494 2494
             $hf = '';
2495 2495
         }
2496 2496
         // add hidden field
2497 2497
         $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2498
-            ? $hf[ $name ]['field']
2498
+            ? $hf[$name]['field']
2499 2499
             : $hf;
2500 2500
     }
2501 2501
 
@@ -2597,7 +2597,7 @@  discard block
 block discarded – undo
2597 2597
         }
2598 2598
         // 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)
2599 2599
         $call_back_func = $create_func
2600
-            ? function ($post, $metabox) {
2600
+            ? function($post, $metabox) {
2601 2601
                 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2602 2602
                 echo EEH_Template::display_template(
2603 2603
                     $metabox['args']['template_path'],
@@ -2607,7 +2607,7 @@  discard block
 block discarded – undo
2607 2607
             }
2608 2608
             : $callback;
2609 2609
         add_meta_box(
2610
-            str_replace('_', '-', $action) . '-mbox',
2610
+            str_replace('_', '-', $action).'-mbox',
2611 2611
             $title,
2612 2612
             $call_back_func,
2613 2613
             $this->_wp_page_slug,
@@ -2699,9 +2699,9 @@  discard block
 block discarded – undo
2699 2699
             : 'espresso-default-admin';
2700 2700
         $template_path                                     = $sidebar
2701 2701
             ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2702
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2702
+            : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2703 2703
         if ($this->request->isAjax()) {
2704
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2704
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2705 2705
         }
2706 2706
         $template_path                                     = ! empty($this->_column_template_path)
2707 2707
             ? $this->_column_template_path : $template_path;
@@ -2741,11 +2741,11 @@  discard block
 block discarded – undo
2741 2741
     public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2742 2742
     {
2743 2743
         // let's generate a default preview action button if there isn't one already present.
2744
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2744
+        $this->_labels['buttons']['buy_now'] = esc_html__(
2745 2745
             'Upgrade to Event Espresso 4 Right Now',
2746 2746
             'event_espresso'
2747 2747
         );
2748
-        $buy_now_url                                   = add_query_arg(
2748
+        $buy_now_url = add_query_arg(
2749 2749
             [
2750 2750
                 'ee_ver'       => 'ee4',
2751 2751
                 'utm_source'   => 'ee4_plugin_admin',
@@ -2765,8 +2765,8 @@  discard block
 block discarded – undo
2765 2765
                 true
2766 2766
             )
2767 2767
             : $this->_template_args['preview_action_button'];
2768
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2769
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2768
+        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2769
+            EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php',
2770 2770
             $this->_template_args,
2771 2771
             true
2772 2772
         );
@@ -2815,7 +2815,7 @@  discard block
 block discarded – undo
2815 2815
         // setup search attributes
2816 2816
         $this->_set_search_attributes();
2817 2817
         $this->_template_args['current_page']     = $this->_wp_page_slug;
2818
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2818
+        $template_path                            = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2819 2819
         $this->_template_args['table_url']        = $this->request->isAjax()
2820 2820
             ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2821 2821
             : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
@@ -2823,10 +2823,10 @@  discard block
 block discarded – undo
2823 2823
         $this->_template_args['current_route']    = $this->_req_action;
2824 2824
         $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2825 2825
         $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2826
-        if (! empty($ajax_sorting_callback)) {
2826
+        if ( ! empty($ajax_sorting_callback)) {
2827 2827
             $sortable_list_table_form_fields = wp_nonce_field(
2828
-                $ajax_sorting_callback . '_nonce',
2829
-                $ajax_sorting_callback . '_nonce',
2828
+                $ajax_sorting_callback.'_nonce',
2829
+                $ajax_sorting_callback.'_nonce',
2830 2830
                 false,
2831 2831
                 false
2832 2832
             );
@@ -2845,18 +2845,18 @@  discard block
 block discarded – undo
2845 2845
                 ? $this->_template_args['list_table_hidden_fields']
2846 2846
                 : '';
2847 2847
 
2848
-        $nonce_ref          = $this->_req_action . '_nonce';
2848
+        $nonce_ref = $this->_req_action.'_nonce';
2849 2849
         $hidden_form_fields .= '
2850
-            <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2850
+            <input type="hidden" name="' . $nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">';
2851 2851
 
2852
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2852
+        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2853 2853
         // display message about search results?
2854 2854
         $search = $this->request->getRequestParam('s');
2855 2855
         $this->_template_args['before_list_table'] .= ! empty($search)
2856
-            ? '<p class="ee-search-results">' . sprintf(
2856
+            ? '<p class="ee-search-results">'.sprintf(
2857 2857
                 esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2858 2858
                 trim($search, '%')
2859
-            ) . '</p>'
2859
+            ).'</p>'
2860 2860
             : '';
2861 2861
         // filter before_list_table template arg
2862 2862
         $this->_template_args['before_list_table'] = apply_filters(
@@ -2890,7 +2890,7 @@  discard block
 block discarded – undo
2890 2890
         // convert to array and filter again
2891 2891
         // arrays are easier to inject new items in a specific location,
2892 2892
         // but would not be backwards compatible, so we have to add a new filter
2893
-        $this->_template_args['after_list_table']   = implode(
2893
+        $this->_template_args['after_list_table'] = implode(
2894 2894
             " \n",
2895 2895
             (array) apply_filters(
2896 2896
                 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
@@ -2937,7 +2937,7 @@  discard block
 block discarded – undo
2937 2937
             $this
2938 2938
         );
2939 2939
         return EEH_Template::display_template(
2940
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2940
+            EE_ADMIN_TEMPLATE.'admin_details_legend.template.php',
2941 2941
             $this->_template_args,
2942 2942
             true
2943 2943
         );
@@ -3046,18 +3046,18 @@  discard block
 block discarded – undo
3046 3046
                 : ''
3047 3047
         );
3048 3048
 
3049
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3049
+        $this->_template_args['after_admin_page_content'] = apply_filters(
3050 3050
             "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3051 3051
             isset($this->_template_args['after_admin_page_content'])
3052 3052
                 ? $this->_template_args['after_admin_page_content']
3053 3053
                 : ''
3054 3054
         );
3055
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3055
+        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3056 3056
 
3057 3057
         if ($this->request->isAjax()) {
3058 3058
             $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3059 3059
                 // $template_path,
3060
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3060
+                EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php',
3061 3061
                 $this->_template_args,
3062 3062
                 true
3063 3063
             );
@@ -3066,7 +3066,7 @@  discard block
 block discarded – undo
3066 3066
         // load settings page wrapper template
3067 3067
         $template_path = $about
3068 3068
             ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3069
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3069
+            : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php';
3070 3070
 
3071 3071
         EEH_Template::display_template($template_path, $this->_template_args);
3072 3072
     }
@@ -3151,12 +3151,12 @@  discard block
 block discarded – undo
3151 3151
         $default_names = ['save', 'save_and_close'];
3152 3152
         $buttons = '';
3153 3153
         foreach ($button_text as $key => $button) {
3154
-            $ref     = $default_names[ $key ];
3155
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3156
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3157
-                        . 'value="' . $button . '" name="' . $name . '" '
3158
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3159
-            if (! $both) {
3154
+            $ref     = $default_names[$key];
3155
+            $name    = ! empty($actions) ? $actions[$key] : $ref;
3156
+            $buttons .= '<input type="submit" class="button-primary '.$ref.'" '
3157
+                        . 'value="'.$button.'" name="'.$name.'" '
3158
+                        . 'id="'.$this->_current_view.'_'.$ref.'" />';
3159
+            if ( ! $both) {
3160 3160
                 break;
3161 3161
             }
3162 3162
         }
@@ -3196,13 +3196,13 @@  discard block
 block discarded – undo
3196 3196
                 'An error occurred. No action was set for this page\'s form.',
3197 3197
                 'event_espresso'
3198 3198
             );
3199
-            $dev_msg  = $user_msg . "\n"
3199
+            $dev_msg = $user_msg."\n"
3200 3200
                         . sprintf(
3201 3201
                             esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3202 3202
                             __FUNCTION__,
3203 3203
                             __CLASS__
3204 3204
                         );
3205
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3205
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
3206 3206
         }
3207 3207
         // open form
3208 3208
         $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
@@ -3211,9 +3211,9 @@  discard block
 block discarded – undo
3211 3211
                                                              . $route
3212 3212
                                                              . '_event_form" >';
3213 3213
         // add nonce
3214
-        $nonce                                             =
3215
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3216
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3214
+        $nonce =
3215
+            wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
3216
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
3217 3217
         // add REQUIRED form action
3218 3218
         $hidden_fields = [
3219 3219
             'action' => ['type' => 'hidden', 'value' => $route],
@@ -3226,7 +3226,7 @@  discard block
 block discarded – undo
3226 3226
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3227 3227
         // add fields to form
3228 3228
         foreach ((array) $form_fields as $form_field) {
3229
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3229
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
3230 3230
         }
3231 3231
         // close form
3232 3232
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -3317,10 +3317,10 @@  discard block
 block discarded – undo
3317 3317
         $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3318 3318
         $notices      = EE_Error::get_notices(false);
3319 3319
         // overwrite default success messages //BUT ONLY if overwrite not overridden
3320
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3320
+        if ( ! $override_overwrite || ! empty($notices['errors'])) {
3321 3321
             EE_Error::overwrite_success();
3322 3322
         }
3323
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3323
+        if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3324 3324
             // how many records affected ? more than one record ? or just one ?
3325 3325
             if ($success > 1) {
3326 3326
                 // set plural msg
@@ -3349,7 +3349,7 @@  discard block
 block discarded – undo
3349 3349
             }
3350 3350
         }
3351 3351
         // check that $query_args isn't something crazy
3352
-        if (! is_array($query_args)) {
3352
+        if ( ! is_array($query_args)) {
3353 3353
             $query_args = [];
3354 3354
         }
3355 3355
         /**
@@ -3378,7 +3378,7 @@  discard block
 block discarded – undo
3378 3378
             $redirect_url = admin_url('admin.php');
3379 3379
         }
3380 3380
         // merge any default query_args set in _default_route_query_args property
3381
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3381
+        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3382 3382
             $args_to_merge = [];
3383 3383
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
3384 3384
                 // is there a wp_referer array in our _default_route_query_args property?
@@ -3390,15 +3390,15 @@  discard block
 block discarded – undo
3390 3390
                         }
3391 3391
                         // finally we will override any arguments in the referer with
3392 3392
                         // what might be set on the _default_route_query_args array.
3393
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3394
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3393
+                        if (isset($this->_default_route_query_args[$reference])) {
3394
+                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3395 3395
                         } else {
3396
-                            $args_to_merge[ $reference ] = urlencode($value);
3396
+                            $args_to_merge[$reference] = urlencode($value);
3397 3397
                         }
3398 3398
                     }
3399 3399
                     continue;
3400 3400
                 }
3401
-                $args_to_merge[ $query_param ] = $query_value;
3401
+                $args_to_merge[$query_param] = $query_value;
3402 3402
             }
3403 3403
             // now let's merge these arguments but override with what was specifically sent in to the
3404 3404
             // redirect.
@@ -3410,19 +3410,19 @@  discard block
 block discarded – undo
3410 3410
         if (isset($query_args['action'])) {
3411 3411
             // manually generate wp_nonce and merge that with the query vars
3412 3412
             // becuz the wp_nonce_url function wrecks havoc on some vars
3413
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3413
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
3414 3414
         }
3415 3415
         // we're adding some hooks and filters in here for processing any things just before redirects
3416 3416
         // (example: an admin page has done an insert or update and we want to run something after that).
3417
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3417
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
3418 3418
         $redirect_url = apply_filters(
3419
-            'FHEE_redirect_' . $classname . $this->_req_action,
3419
+            'FHEE_redirect_'.$classname.$this->_req_action,
3420 3420
             self::add_query_args_and_nonce($query_args, $redirect_url),
3421 3421
             $query_args
3422 3422
         );
3423 3423
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3424 3424
         if ($this->request->isAjax()) {
3425
-            $default_data                    = [
3425
+            $default_data = [
3426 3426
                 'close'        => true,
3427 3427
                 'redirect_url' => $redirect_url,
3428 3428
                 'where'        => 'main',
@@ -3469,7 +3469,7 @@  discard block
 block discarded – undo
3469 3469
         }
3470 3470
         $this->_template_args['notices'] = EE_Error::get_notices();
3471 3471
         // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3472
-        if (! $this->request->isAjax() || $sticky_notices) {
3472
+        if ( ! $this->request->isAjax() || $sticky_notices) {
3473 3473
             $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3474 3474
             $this->_add_transient(
3475 3475
                 $route,
@@ -3509,7 +3509,7 @@  discard block
 block discarded – undo
3509 3509
         $exclude_nonce = false
3510 3510
     ) {
3511 3511
         // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3512
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3512
+        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3513 3513
             throw new EE_Error(
3514 3514
                 sprintf(
3515 3515
                     esc_html__(
@@ -3520,7 +3520,7 @@  discard block
 block discarded – undo
3520 3520
                 )
3521 3521
             );
3522 3522
         }
3523
-        if (! isset($this->_labels['buttons'][ $type ])) {
3523
+        if ( ! isset($this->_labels['buttons'][$type])) {
3524 3524
             throw new EE_Error(
3525 3525
                 sprintf(
3526 3526
                     esc_html__(
@@ -3533,7 +3533,7 @@  discard block
 block discarded – undo
3533 3533
         }
3534 3534
         // finally check user access for this button.
3535 3535
         $has_access = $this->check_user_access($action, true);
3536
-        if (! $has_access) {
3536
+        if ( ! $has_access) {
3537 3537
             return '';
3538 3538
         }
3539 3539
         $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
@@ -3541,11 +3541,11 @@  discard block
 block discarded – undo
3541 3541
             'action' => $action,
3542 3542
         ];
3543 3543
         // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3544
-        if (! empty($extra_request)) {
3544
+        if ( ! empty($extra_request)) {
3545 3545
             $query_args = array_merge($extra_request, $query_args);
3546 3546
         }
3547 3547
         $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3548
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3548
+        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3549 3549
     }
3550 3550
 
3551 3551
 
@@ -3571,7 +3571,7 @@  discard block
 block discarded – undo
3571 3571
                 'FHEE__EE_Admin_Page___per_page_screen_options__default',
3572 3572
                 20
3573 3573
             ),
3574
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3574
+            'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3575 3575
         ];
3576 3576
         // ONLY add the screen option if the user has access to it.
3577 3577
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3592,18 +3592,18 @@  discard block
 block discarded – undo
3592 3592
     {
3593 3593
         if ($this->request->requestParamIsSet('wp_screen_options')) {
3594 3594
             check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3595
-            if (! $user = wp_get_current_user()) {
3595
+            if ( ! $user = wp_get_current_user()) {
3596 3596
                 return;
3597 3597
             }
3598 3598
             $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3599
-            if (! $option) {
3599
+            if ( ! $option) {
3600 3600
                 return;
3601 3601
             }
3602
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3602
+            $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3603 3603
             $map_option = $option;
3604 3604
             $option     = str_replace('-', '_', $option);
3605 3605
             switch ($map_option) {
3606
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3606
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3607 3607
                     $max_value = apply_filters(
3608 3608
                         'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3609 3609
                         999,
@@ -3660,13 +3660,13 @@  discard block
 block discarded – undo
3660 3660
     protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3661 3661
     {
3662 3662
         $user_id = get_current_user_id();
3663
-        if (! $skip_route_verify) {
3663
+        if ( ! $skip_route_verify) {
3664 3664
             $this->_verify_route($route);
3665 3665
         }
3666 3666
         // now let's set the string for what kind of transient we're setting
3667 3667
         $transient = $notices
3668
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3669
-            : 'rte_tx_' . $route . '_' . $user_id;
3668
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3669
+            : 'rte_tx_'.$route.'_'.$user_id;
3670 3670
         $data      = $notices ? ['notices' => $data] : $data;
3671 3671
         // is there already a transient for this route?  If there is then let's ADD to that transient
3672 3672
         $existing = is_multisite() && is_network_admin()
@@ -3695,8 +3695,8 @@  discard block
 block discarded – undo
3695 3695
         $user_id   = get_current_user_id();
3696 3696
         $route     = ! $route ? $this->_req_action : $route;
3697 3697
         $transient = $notices
3698
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3699
-            : 'rte_tx_' . $route . '_' . $user_id;
3698
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3699
+            : 'rte_tx_'.$route.'_'.$user_id;
3700 3700
         $data      = is_multisite() && is_network_admin()
3701 3701
             ? get_site_transient($transient)
3702 3702
             : get_transient($transient);
@@ -3927,7 +3927,7 @@  discard block
 block discarded – undo
3927 3927
      */
3928 3928
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3929 3929
     {
3930
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3930
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3931 3931
     }
3932 3932
 
3933 3933
 
@@ -3940,7 +3940,7 @@  discard block
 block discarded – undo
3940 3940
      */
3941 3941
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3942 3942
     {
3943
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3943
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3944 3944
     }
3945 3945
 
3946 3946
 
@@ -4088,13 +4088,13 @@  discard block
 block discarded – undo
4088 4088
         callable $callback = null
4089 4089
     ) {
4090 4090
         $entity_ID = absint($entity_ID);
4091
-        if (! $entity_ID) {
4091
+        if ( ! $entity_ID) {
4092 4092
             $this->trashRestoreDeleteError($action, $entity_model);
4093 4093
         }
4094 4094
         $result = 0;
4095 4095
         try {
4096 4096
             $entity = $entity_model->get_one_by_ID($entity_ID);
4097
-            if (! $entity instanceof EE_Base_Class) {
4097
+            if ( ! $entity instanceof EE_Base_Class) {
4098 4098
                 throw new DomainException(
4099 4099
                     sprintf(
4100 4100
                         esc_html__(
@@ -4145,7 +4145,7 @@  discard block
 block discarded – undo
4145 4145
                 )
4146 4146
             );
4147 4147
         }
4148
-        if (! $entity_model->has_field($delete_column)) {
4148
+        if ( ! $entity_model->has_field($delete_column)) {
4149 4149
             throw new DomainException(
4150 4150
                 sprintf(
4151 4151
                     esc_html__(
Please login to merge, or discard this patch.
core/db_models/EEM_CPT_Base.model.php 1 patch
Indentation   +560 added lines, -560 removed lines patch added patch discarded remove patch
@@ -14,564 +14,564 @@
 block discarded – undo
14 14
  */
15 15
 abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base
16 16
 {
17
-    const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories';
18
-
19
-    /**
20
-     * @var string post_status_publish - the wp post status for published cpts
21
-     */
22
-    const post_status_publish = 'publish';
23
-
24
-    /**
25
-     * @var string post_status_future - the wp post status for scheduled cpts
26
-     */
27
-    const post_status_future = 'future';
28
-
29
-    /**
30
-     * @var string post_status_draft - the wp post status for draft cpts
31
-     */
32
-    const post_status_draft = 'draft';
33
-
34
-    /**
35
-     * @var string post_status_pending - the wp post status for pending cpts
36
-     */
37
-    const post_status_pending = 'pending';
38
-
39
-    /**
40
-     * @var string post_status_private - the wp post status for private cpts
41
-     */
42
-    const post_status_private = 'private';
43
-
44
-    /**
45
-     * @var string post_status_trashed - the wp post status for trashed cpts
46
-     */
47
-    const post_status_trashed = 'trash';
48
-
49
-    /**
50
-     * This is an array of custom statuses for the given CPT model (modified by children)
51
-     * format:
52
-     * array(
53
-     *        'status_name' => array(
54
-     *            'label' => esc_html__('Status Name', 'event_espresso'),
55
-     *            'public' => TRUE //whether a public status or not.
56
-     *        )
57
-     * )
58
-     *
59
-     * @var array
60
-     */
61
-    protected $_custom_stati = array();
62
-
63
-
64
-    /**
65
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
66
-     *
67
-     * @param string $timezone
68
-     * @throws \EE_Error
69
-     */
70
-    protected function __construct($timezone = null)
71
-    {
72
-        // adds a relationship to Term_Taxonomy for all these models. For this to work
73
-        // Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
74
-        // eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
75
-        // with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
76
-        // must also be new EE_HABTM_Relation('Term_Relationship');
77
-        $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
78
-        $primary_table_name = null;
79
-        // add  the common _status field to all CPT primary tables.
80
-        foreach ($this->_tables as $alias => $table_obj) {
81
-            if ($table_obj instanceof EE_Primary_Table) {
82
-                $primary_table_name = $alias;
83
-            }
84
-        }
85
-        // set default wp post statuses if child has not already set.
86
-        if (! isset($this->_fields[ $primary_table_name ]['status'])) {
87
-            $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field(
88
-                'post_status',
89
-                esc_html__("Event Status", "event_espresso"),
90
-                false,
91
-                'draft'
92
-            );
93
-        }
94
-        if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) {
95
-            $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field(
96
-                'to_ping',
97
-                esc_html__('To Ping', 'event_espresso'),
98
-                false,
99
-                ''
100
-            );
101
-        }
102
-        if (! isset($this->_fields[ $primary_table_name ]['pinged'])) {
103
-            $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field(
104
-                'pinged',
105
-                esc_html__('Pinged', 'event_espresso'),
106
-                false,
107
-                ''
108
-            );
109
-        }
110
-        if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) {
111
-            $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field(
112
-                'comment_status',
113
-                esc_html__('Comment Status', 'event_espresso'),
114
-                false,
115
-                'open'
116
-            );
117
-        }
118
-        if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) {
119
-            $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field(
120
-                'ping_status',
121
-                esc_html__('Ping Status', 'event_espresso'),
122
-                false,
123
-                'open'
124
-            );
125
-        }
126
-        if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) {
127
-            $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field(
128
-                'post_content_filtered',
129
-                esc_html__('Post Content Filtered', 'event_espresso'),
130
-                false,
131
-                ''
132
-            );
133
-        }
134
-        if (! isset($this->_model_relations['Post_Meta'])) {
135
-            // don't block deletes though because we want to maintain the current behaviour
136
-            $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
137
-        }
138
-        if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
139
-            // nothing was set during child constructor, so set default
140
-            $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
141
-        }
142
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
143
-            // nothing was set during child constructor, so set default
144
-            // it's ok for child classes to specify this, but generally this is more DRY
145
-            $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
146
-        }
147
-        parent::__construct($timezone);
148
-    }
149
-
150
-
151
-    /**
152
-     * @return array
153
-     */
154
-    public function public_event_stati()
155
-    {
156
-        // @see wp-includes/post.php
157
-        return get_post_stati(array('public' => true));
158
-    }
159
-
160
-
161
-    /**
162
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
163
-     * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
164
-     *
165
-     * @return string
166
-     * @throws EE_Error
167
-     */
168
-    public function deleted_field_name()
169
-    {
170
-        throw new EE_Error(
171
-            sprintf(
172
-                esc_html__(
173
-                    '%1$s should not call deleted_field_name()! It should instead use post_status_field_name',
174
-                    "event_espresso"
175
-                ),
176
-                get_called_class()
177
-            )
178
-        );
179
-    }
180
-
181
-
182
-    /**
183
-     * Gets the field's name that sets the post status
184
-     *
185
-     * @return string
186
-     * @throws EE_Error
187
-     */
188
-    public function post_status_field_name()
189
-    {
190
-        $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
191
-        if ($field) {
192
-            return $field->get_name();
193
-        } else {
194
-            throw new EE_Error(
195
-                sprintf(
196
-                    esc_html__(
197
-                        'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
198
-                        'event_espresso'
199
-                    ),
200
-                    get_called_class(),
201
-                    get_called_class()
202
-                )
203
-            );
204
-        }
205
-    }
206
-
207
-
208
-    /**
209
-     * Alters the query params so that only trashed/soft-deleted items are considered
210
-     *
211
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
212
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
213
-     */
214
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
215
-    {
216
-        $post_status_field_name = $this->post_status_field_name();
217
-        $query_params[0][ $post_status_field_name ] = self::post_status_trashed;
218
-        return $query_params;
219
-    }
220
-
221
-
222
-    /**
223
-     * Alters the query params so each item's deleted status is ignored.
224
-     *
225
-     * @param array $query_params
226
-     * @return array
227
-     */
228
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
229
-    {
230
-        $query_params['default_where_conditions'] = 'minimum';
231
-        return $query_params;
232
-    }
233
-
234
-
235
-    /**
236
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
237
-     *
238
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
239
-     * @param array $query_params
240
-     * @return boolean success
241
-     * @throws EE_Error
242
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
243
-     */
244
-    public function delete_or_restore($delete = true, $query_params = array())
245
-    {
246
-        $post_status_field_name = $this->post_status_field_name();
247
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
248
-        $new_status = $delete ? self::post_status_trashed : 'draft';
249
-        return (bool) $this->update([$post_status_field_name => $new_status], $query_params);
250
-    }
251
-
252
-
253
-    /**
254
-     * meta_table
255
-     * returns first EE_Secondary_Table table name
256
-     *
257
-     * @access public
258
-     * @return string
259
-     */
260
-    public function meta_table()
261
-    {
262
-        $meta_table = $this->_get_other_tables();
263
-        $meta_table = reset($meta_table);
264
-        return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
265
-    }
266
-
267
-
268
-    /**
269
-     * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
270
-     *
271
-     * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
272
-     *                   db only fields)
273
-     * @return array
274
-     */
275
-    public function get_meta_table_fields($all = false)
276
-    {
277
-        $all_fields = $fields_to_return = array();
278
-        foreach ($this->_tables as $alias => $table_obj) {
279
-            if ($table_obj instanceof EE_Secondary_Table) {
280
-                $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
281
-            }
282
-        }
283
-        if (! $all) {
284
-            foreach ($all_fields as $name => $obj) {
285
-                if ($obj instanceof EE_DB_Only_Field_Base) {
286
-                    continue;
287
-                }
288
-                $fields_to_return[] = $name;
289
-            }
290
-        } else {
291
-            $fields_to_return = array_keys($all_fields);
292
-        }
293
-        return $fields_to_return;
294
-    }
295
-
296
-
297
-    /**
298
-     * Adds an event category with the specified name and description to the specified
299
-     * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
300
-     * and adds an entry in the term_relationship if necessary.
301
-     *
302
-     * @param EE_CPT_Base $cpt_model_object
303
-     * @param string      $category_name (used to derive the term slug too)
304
-     * @param string      $category_description
305
-     * @param int         $parent_term_taxonomy_id
306
-     * @return EE_Term_Taxonomy
307
-     */
308
-    public function add_event_category(
309
-        EE_CPT_Base $cpt_model_object,
310
-        $category_name,
311
-        $category_description = '',
312
-        $parent_term_taxonomy_id = null
313
-    ) {
314
-        // create term
315
-        require_once(EE_MODELS . 'EEM_Term.model.php');
316
-        // first, check for a term by the same name or slug
317
-        $category_slug = sanitize_title($category_name);
318
-        $term = EEM_Term::instance()->get_one(
319
-            array(
320
-                array(
321
-                    'OR' => array(
322
-                        'name' => $category_name,
323
-                        'slug' => $category_slug,
324
-                    ),
325
-                    'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY
326
-                ),
327
-            )
328
-        );
329
-        if (! $term) {
330
-            $term = EE_Term::new_instance(
331
-                array(
332
-                    'name' => $category_name,
333
-                    'slug' => $category_slug,
334
-                )
335
-            );
336
-            $term->save();
337
-        }
338
-        // make sure there's a term-taxonomy entry too
339
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
340
-        $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(
341
-            array(
342
-                array(
343
-                    'term_id'  => $term->ID(),
344
-                    'taxonomy' => self::EVENT_CATEGORY_TAXONOMY,
345
-                ),
346
-            )
347
-        );
348
-        /** @var $term_taxonomy EE_Term_Taxonomy */
349
-        if (! $term_taxonomy) {
350
-            $term_taxonomy = EE_Term_Taxonomy::new_instance(
351
-                array(
352
-                    'term_id'     => $term->ID(),
353
-                    'taxonomy'    => self::EVENT_CATEGORY_TAXONOMY,
354
-                    'description' => $category_description,
355
-                    'term_count'       => 1,
356
-                    'parent'      => $parent_term_taxonomy_id,
357
-                )
358
-            );
359
-            $term_taxonomy->save();
360
-        } else {
361
-            $term_taxonomy->set_count($term_taxonomy->count() + 1);
362
-            $term_taxonomy->save();
363
-        }
364
-        return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
365
-    }
366
-
367
-
368
-    /**
369
-     * Removed the category specified by name as having a relation to this event.
370
-     * Does not remove the term or term_taxonomy.
371
-     *
372
-     * @param EE_CPT_Base $cpt_model_object_event
373
-     * @param string      $category_name name of the event category (term)
374
-     * @return bool
375
-     */
376
-    public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
377
-    {
378
-        // find the term_taxonomy by that name
379
-        $term_taxonomy = $this->get_first_related(
380
-            $cpt_model_object_event,
381
-            'Term_Taxonomy',
382
-            array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY))
383
-        );
384
-        /** @var $term_taxonomy EE_Term_Taxonomy */
385
-        if ($term_taxonomy) {
386
-            $term_taxonomy->set_count($term_taxonomy->count() - 1);
387
-            $term_taxonomy->save();
388
-        }
389
-        return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
390
-    }
391
-
392
-
393
-    /**
394
-     * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
395
-     * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
396
-     *
397
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
398
-     * @access public
399
-     * @param int          $id   the ID for the cpt we want the feature image for
400
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
401
-     *                           representing width and height in pixels (i.e. array(32,32) ).
402
-     * @param string|array $attr Optional. Query string or array of attributes.
403
-     * @return string HTML image element
404
-     */
405
-    public function get_feature_image($id, $size = 'thumbnail', $attr = '')
406
-    {
407
-        return get_the_post_thumbnail($id, $size, $attr);
408
-    }
409
-
410
-
411
-    /**
412
-     * Just a handy way to get the list of post statuses currently registered with WP.
413
-     *
414
-     * @global array $wp_post_statuses set in wp core for storing all the post stati
415
-     * @return array
416
-     */
417
-    public function get_post_statuses()
418
-    {
419
-        global $wp_post_statuses;
420
-        $statuses = array();
421
-        foreach ($wp_post_statuses as $post_status => $args_object) {
422
-            $statuses[ $post_status ] = $args_object->label;
423
-        }
424
-        return $statuses;
425
-    }
426
-
427
-
428
-    /**
429
-     * public method that can be used to retrieve the protected status array on the instantiated cpt model
430
-     *
431
-     * @return array array of statuses.
432
-     */
433
-    public function get_status_array()
434
-    {
435
-        $statuses = $this->get_post_statuses();
436
-        // first the global filter
437
-        $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
438
-        // now the class specific filter
439
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
440
-        return $statuses;
441
-    }
442
-
443
-
444
-    /**
445
-     * this returns the post statuses that are NOT the default wordpress status
446
-     *
447
-     * @return array
448
-     */
449
-    public function get_custom_post_statuses()
450
-    {
451
-        $new_stati = array();
452
-        foreach ($this->_custom_stati as $status => $props) {
453
-            $new_stati[ $status ] = $props['label'];
454
-        }
455
-        return $new_stati;
456
-    }
457
-
458
-
459
-    /**
460
-     * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
461
-     * are a row from the posts table. If we're missing any fields required for the model,
462
-     * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
463
-     * make sure you are attaching all the model's fields onto the post)
464
-     *
465
-     * @param WP_Post|array $post
466
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
467
-     */
468
-    public function instantiate_class_from_post_object_orig($post)
469
-    {
470
-        $post = (array) $post;
471
-        $has_all_necessary_fields_for_table = true;
472
-        // check if the post has fields on the meta table already
473
-        foreach ($this->_get_other_tables() as $table_obj) {
474
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
475
-            foreach ($fields_for_that_table as $field_obj) {
476
-                if (
477
-                    ! isset($post[ $field_obj->get_table_column() ])
478
-                    && ! isset($post[ $field_obj->get_qualified_column() ])
479
-                ) {
480
-                    $has_all_necessary_fields_for_table = false;
481
-                }
482
-            }
483
-        }
484
-        // if we don't have all the fields we need, then just fetch the proper model from the DB
485
-        if (! $has_all_necessary_fields_for_table) {
486
-            return $this->get_one_by_ID($post['ID']);
487
-        } else {
488
-            return $this->instantiate_class_from_array_or_object($post);
489
-        }
490
-    }
491
-
492
-
493
-    /**
494
-     * @param null $post
495
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
496
-     */
497
-    public function instantiate_class_from_post_object($post = null)
498
-    {
499
-        if (empty($post)) {
500
-            global $post;
501
-        }
502
-        $post = (array) $post;
503
-        $tables_needing_to_be_queried = array();
504
-        // check if the post has fields on the meta table already
505
-        foreach ($this->get_tables() as $table_obj) {
506
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
507
-            foreach ($fields_for_that_table as $field_obj) {
508
-                if (
509
-                    ! isset($post[ $field_obj->get_table_column() ])
510
-                    && ! isset($post[ $field_obj->get_qualified_column() ])
511
-                ) {
512
-                    $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj;
513
-                }
514
-            }
515
-        }
516
-        // if we don't have all the fields we need, then just fetch the proper model from the DB
517
-        if ($tables_needing_to_be_queried) {
518
-            if (
519
-                count($tables_needing_to_be_queried) == 1
520
-                && reset($tables_needing_to_be_queried)
521
-                   instanceof
522
-                   EE_Secondary_Table
523
-            ) {
524
-                // so we're only missing data from a secondary table. Well that's not too hard to query for
525
-                $table_to_query = reset($tables_needing_to_be_queried);
526
-                $missing_data = $this->_do_wpdb_query(
527
-                    'get_row',
528
-                    array(
529
-                        'SELECT * FROM '
530
-                        . $table_to_query->get_table_name()
531
-                        . ' WHERE '
532
-                        . $table_to_query->get_fk_on_table()
533
-                        . ' = '
534
-                        . $post['ID'],
535
-                        ARRAY_A,
536
-                    )
537
-                );
538
-                if (! empty($missing_data)) {
539
-                    $post = array_merge($post, $missing_data);
540
-                }
541
-            } else {
542
-                return $this->get_one_by_ID($post['ID']);
543
-            }
544
-        }
545
-        return $this->instantiate_class_from_array_or_object($post);
546
-    }
547
-
548
-
549
-    /**
550
-     * Gets the post type associated with this
551
-     *
552
-     * @throws EE_Error
553
-     * @return string
554
-     */
555
-    public function post_type()
556
-    {
557
-        $post_type_field = null;
558
-        foreach ($this->field_settings(true) as $field_obj) {
559
-            if ($field_obj instanceof EE_WP_Post_Type_Field) {
560
-                $post_type_field = $field_obj;
561
-                break;
562
-            }
563
-        }
564
-        if ($post_type_field == null) {
565
-            throw new EE_Error(
566
-                sprintf(
567
-                    esc_html__(
568
-                        "CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
569
-                        "event_espresso"
570
-                    ),
571
-                    get_class($this)
572
-                )
573
-            );
574
-        }
575
-        return $post_type_field->get_default_value();
576
-    }
17
+	const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories';
18
+
19
+	/**
20
+	 * @var string post_status_publish - the wp post status for published cpts
21
+	 */
22
+	const post_status_publish = 'publish';
23
+
24
+	/**
25
+	 * @var string post_status_future - the wp post status for scheduled cpts
26
+	 */
27
+	const post_status_future = 'future';
28
+
29
+	/**
30
+	 * @var string post_status_draft - the wp post status for draft cpts
31
+	 */
32
+	const post_status_draft = 'draft';
33
+
34
+	/**
35
+	 * @var string post_status_pending - the wp post status for pending cpts
36
+	 */
37
+	const post_status_pending = 'pending';
38
+
39
+	/**
40
+	 * @var string post_status_private - the wp post status for private cpts
41
+	 */
42
+	const post_status_private = 'private';
43
+
44
+	/**
45
+	 * @var string post_status_trashed - the wp post status for trashed cpts
46
+	 */
47
+	const post_status_trashed = 'trash';
48
+
49
+	/**
50
+	 * This is an array of custom statuses for the given CPT model (modified by children)
51
+	 * format:
52
+	 * array(
53
+	 *        'status_name' => array(
54
+	 *            'label' => esc_html__('Status Name', 'event_espresso'),
55
+	 *            'public' => TRUE //whether a public status or not.
56
+	 *        )
57
+	 * )
58
+	 *
59
+	 * @var array
60
+	 */
61
+	protected $_custom_stati = array();
62
+
63
+
64
+	/**
65
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
66
+	 *
67
+	 * @param string $timezone
68
+	 * @throws \EE_Error
69
+	 */
70
+	protected function __construct($timezone = null)
71
+	{
72
+		// adds a relationship to Term_Taxonomy for all these models. For this to work
73
+		// Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
74
+		// eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
75
+		// with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
76
+		// must also be new EE_HABTM_Relation('Term_Relationship');
77
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
78
+		$primary_table_name = null;
79
+		// add  the common _status field to all CPT primary tables.
80
+		foreach ($this->_tables as $alias => $table_obj) {
81
+			if ($table_obj instanceof EE_Primary_Table) {
82
+				$primary_table_name = $alias;
83
+			}
84
+		}
85
+		// set default wp post statuses if child has not already set.
86
+		if (! isset($this->_fields[ $primary_table_name ]['status'])) {
87
+			$this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field(
88
+				'post_status',
89
+				esc_html__("Event Status", "event_espresso"),
90
+				false,
91
+				'draft'
92
+			);
93
+		}
94
+		if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) {
95
+			$this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field(
96
+				'to_ping',
97
+				esc_html__('To Ping', 'event_espresso'),
98
+				false,
99
+				''
100
+			);
101
+		}
102
+		if (! isset($this->_fields[ $primary_table_name ]['pinged'])) {
103
+			$this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field(
104
+				'pinged',
105
+				esc_html__('Pinged', 'event_espresso'),
106
+				false,
107
+				''
108
+			);
109
+		}
110
+		if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) {
111
+			$this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field(
112
+				'comment_status',
113
+				esc_html__('Comment Status', 'event_espresso'),
114
+				false,
115
+				'open'
116
+			);
117
+		}
118
+		if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) {
119
+			$this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field(
120
+				'ping_status',
121
+				esc_html__('Ping Status', 'event_espresso'),
122
+				false,
123
+				'open'
124
+			);
125
+		}
126
+		if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) {
127
+			$this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field(
128
+				'post_content_filtered',
129
+				esc_html__('Post Content Filtered', 'event_espresso'),
130
+				false,
131
+				''
132
+			);
133
+		}
134
+		if (! isset($this->_model_relations['Post_Meta'])) {
135
+			// don't block deletes though because we want to maintain the current behaviour
136
+			$this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
137
+		}
138
+		if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
139
+			// nothing was set during child constructor, so set default
140
+			$this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
141
+		}
142
+		if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
143
+			// nothing was set during child constructor, so set default
144
+			// it's ok for child classes to specify this, but generally this is more DRY
145
+			$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
146
+		}
147
+		parent::__construct($timezone);
148
+	}
149
+
150
+
151
+	/**
152
+	 * @return array
153
+	 */
154
+	public function public_event_stati()
155
+	{
156
+		// @see wp-includes/post.php
157
+		return get_post_stati(array('public' => true));
158
+	}
159
+
160
+
161
+	/**
162
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
163
+	 * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
164
+	 *
165
+	 * @return string
166
+	 * @throws EE_Error
167
+	 */
168
+	public function deleted_field_name()
169
+	{
170
+		throw new EE_Error(
171
+			sprintf(
172
+				esc_html__(
173
+					'%1$s should not call deleted_field_name()! It should instead use post_status_field_name',
174
+					"event_espresso"
175
+				),
176
+				get_called_class()
177
+			)
178
+		);
179
+	}
180
+
181
+
182
+	/**
183
+	 * Gets the field's name that sets the post status
184
+	 *
185
+	 * @return string
186
+	 * @throws EE_Error
187
+	 */
188
+	public function post_status_field_name()
189
+	{
190
+		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
191
+		if ($field) {
192
+			return $field->get_name();
193
+		} else {
194
+			throw new EE_Error(
195
+				sprintf(
196
+					esc_html__(
197
+						'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
198
+						'event_espresso'
199
+					),
200
+					get_called_class(),
201
+					get_called_class()
202
+				)
203
+			);
204
+		}
205
+	}
206
+
207
+
208
+	/**
209
+	 * Alters the query params so that only trashed/soft-deleted items are considered
210
+	 *
211
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
212
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
213
+	 */
214
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
215
+	{
216
+		$post_status_field_name = $this->post_status_field_name();
217
+		$query_params[0][ $post_status_field_name ] = self::post_status_trashed;
218
+		return $query_params;
219
+	}
220
+
221
+
222
+	/**
223
+	 * Alters the query params so each item's deleted status is ignored.
224
+	 *
225
+	 * @param array $query_params
226
+	 * @return array
227
+	 */
228
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
229
+	{
230
+		$query_params['default_where_conditions'] = 'minimum';
231
+		return $query_params;
232
+	}
233
+
234
+
235
+	/**
236
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
237
+	 *
238
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
239
+	 * @param array $query_params
240
+	 * @return boolean success
241
+	 * @throws EE_Error
242
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
243
+	 */
244
+	public function delete_or_restore($delete = true, $query_params = array())
245
+	{
246
+		$post_status_field_name = $this->post_status_field_name();
247
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
248
+		$new_status = $delete ? self::post_status_trashed : 'draft';
249
+		return (bool) $this->update([$post_status_field_name => $new_status], $query_params);
250
+	}
251
+
252
+
253
+	/**
254
+	 * meta_table
255
+	 * returns first EE_Secondary_Table table name
256
+	 *
257
+	 * @access public
258
+	 * @return string
259
+	 */
260
+	public function meta_table()
261
+	{
262
+		$meta_table = $this->_get_other_tables();
263
+		$meta_table = reset($meta_table);
264
+		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
265
+	}
266
+
267
+
268
+	/**
269
+	 * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
270
+	 *
271
+	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
272
+	 *                   db only fields)
273
+	 * @return array
274
+	 */
275
+	public function get_meta_table_fields($all = false)
276
+	{
277
+		$all_fields = $fields_to_return = array();
278
+		foreach ($this->_tables as $alias => $table_obj) {
279
+			if ($table_obj instanceof EE_Secondary_Table) {
280
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
281
+			}
282
+		}
283
+		if (! $all) {
284
+			foreach ($all_fields as $name => $obj) {
285
+				if ($obj instanceof EE_DB_Only_Field_Base) {
286
+					continue;
287
+				}
288
+				$fields_to_return[] = $name;
289
+			}
290
+		} else {
291
+			$fields_to_return = array_keys($all_fields);
292
+		}
293
+		return $fields_to_return;
294
+	}
295
+
296
+
297
+	/**
298
+	 * Adds an event category with the specified name and description to the specified
299
+	 * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
300
+	 * and adds an entry in the term_relationship if necessary.
301
+	 *
302
+	 * @param EE_CPT_Base $cpt_model_object
303
+	 * @param string      $category_name (used to derive the term slug too)
304
+	 * @param string      $category_description
305
+	 * @param int         $parent_term_taxonomy_id
306
+	 * @return EE_Term_Taxonomy
307
+	 */
308
+	public function add_event_category(
309
+		EE_CPT_Base $cpt_model_object,
310
+		$category_name,
311
+		$category_description = '',
312
+		$parent_term_taxonomy_id = null
313
+	) {
314
+		// create term
315
+		require_once(EE_MODELS . 'EEM_Term.model.php');
316
+		// first, check for a term by the same name or slug
317
+		$category_slug = sanitize_title($category_name);
318
+		$term = EEM_Term::instance()->get_one(
319
+			array(
320
+				array(
321
+					'OR' => array(
322
+						'name' => $category_name,
323
+						'slug' => $category_slug,
324
+					),
325
+					'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY
326
+				),
327
+			)
328
+		);
329
+		if (! $term) {
330
+			$term = EE_Term::new_instance(
331
+				array(
332
+					'name' => $category_name,
333
+					'slug' => $category_slug,
334
+				)
335
+			);
336
+			$term->save();
337
+		}
338
+		// make sure there's a term-taxonomy entry too
339
+		require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
340
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(
341
+			array(
342
+				array(
343
+					'term_id'  => $term->ID(),
344
+					'taxonomy' => self::EVENT_CATEGORY_TAXONOMY,
345
+				),
346
+			)
347
+		);
348
+		/** @var $term_taxonomy EE_Term_Taxonomy */
349
+		if (! $term_taxonomy) {
350
+			$term_taxonomy = EE_Term_Taxonomy::new_instance(
351
+				array(
352
+					'term_id'     => $term->ID(),
353
+					'taxonomy'    => self::EVENT_CATEGORY_TAXONOMY,
354
+					'description' => $category_description,
355
+					'term_count'       => 1,
356
+					'parent'      => $parent_term_taxonomy_id,
357
+				)
358
+			);
359
+			$term_taxonomy->save();
360
+		} else {
361
+			$term_taxonomy->set_count($term_taxonomy->count() + 1);
362
+			$term_taxonomy->save();
363
+		}
364
+		return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
365
+	}
366
+
367
+
368
+	/**
369
+	 * Removed the category specified by name as having a relation to this event.
370
+	 * Does not remove the term or term_taxonomy.
371
+	 *
372
+	 * @param EE_CPT_Base $cpt_model_object_event
373
+	 * @param string      $category_name name of the event category (term)
374
+	 * @return bool
375
+	 */
376
+	public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
377
+	{
378
+		// find the term_taxonomy by that name
379
+		$term_taxonomy = $this->get_first_related(
380
+			$cpt_model_object_event,
381
+			'Term_Taxonomy',
382
+			array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY))
383
+		);
384
+		/** @var $term_taxonomy EE_Term_Taxonomy */
385
+		if ($term_taxonomy) {
386
+			$term_taxonomy->set_count($term_taxonomy->count() - 1);
387
+			$term_taxonomy->save();
388
+		}
389
+		return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
390
+	}
391
+
392
+
393
+	/**
394
+	 * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
395
+	 * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
396
+	 *
397
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
398
+	 * @access public
399
+	 * @param int          $id   the ID for the cpt we want the feature image for
400
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
401
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
402
+	 * @param string|array $attr Optional. Query string or array of attributes.
403
+	 * @return string HTML image element
404
+	 */
405
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '')
406
+	{
407
+		return get_the_post_thumbnail($id, $size, $attr);
408
+	}
409
+
410
+
411
+	/**
412
+	 * Just a handy way to get the list of post statuses currently registered with WP.
413
+	 *
414
+	 * @global array $wp_post_statuses set in wp core for storing all the post stati
415
+	 * @return array
416
+	 */
417
+	public function get_post_statuses()
418
+	{
419
+		global $wp_post_statuses;
420
+		$statuses = array();
421
+		foreach ($wp_post_statuses as $post_status => $args_object) {
422
+			$statuses[ $post_status ] = $args_object->label;
423
+		}
424
+		return $statuses;
425
+	}
426
+
427
+
428
+	/**
429
+	 * public method that can be used to retrieve the protected status array on the instantiated cpt model
430
+	 *
431
+	 * @return array array of statuses.
432
+	 */
433
+	public function get_status_array()
434
+	{
435
+		$statuses = $this->get_post_statuses();
436
+		// first the global filter
437
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
438
+		// now the class specific filter
439
+		$statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
440
+		return $statuses;
441
+	}
442
+
443
+
444
+	/**
445
+	 * this returns the post statuses that are NOT the default wordpress status
446
+	 *
447
+	 * @return array
448
+	 */
449
+	public function get_custom_post_statuses()
450
+	{
451
+		$new_stati = array();
452
+		foreach ($this->_custom_stati as $status => $props) {
453
+			$new_stati[ $status ] = $props['label'];
454
+		}
455
+		return $new_stati;
456
+	}
457
+
458
+
459
+	/**
460
+	 * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
461
+	 * are a row from the posts table. If we're missing any fields required for the model,
462
+	 * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
463
+	 * make sure you are attaching all the model's fields onto the post)
464
+	 *
465
+	 * @param WP_Post|array $post
466
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
467
+	 */
468
+	public function instantiate_class_from_post_object_orig($post)
469
+	{
470
+		$post = (array) $post;
471
+		$has_all_necessary_fields_for_table = true;
472
+		// check if the post has fields on the meta table already
473
+		foreach ($this->_get_other_tables() as $table_obj) {
474
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
475
+			foreach ($fields_for_that_table as $field_obj) {
476
+				if (
477
+					! isset($post[ $field_obj->get_table_column() ])
478
+					&& ! isset($post[ $field_obj->get_qualified_column() ])
479
+				) {
480
+					$has_all_necessary_fields_for_table = false;
481
+				}
482
+			}
483
+		}
484
+		// if we don't have all the fields we need, then just fetch the proper model from the DB
485
+		if (! $has_all_necessary_fields_for_table) {
486
+			return $this->get_one_by_ID($post['ID']);
487
+		} else {
488
+			return $this->instantiate_class_from_array_or_object($post);
489
+		}
490
+	}
491
+
492
+
493
+	/**
494
+	 * @param null $post
495
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
496
+	 */
497
+	public function instantiate_class_from_post_object($post = null)
498
+	{
499
+		if (empty($post)) {
500
+			global $post;
501
+		}
502
+		$post = (array) $post;
503
+		$tables_needing_to_be_queried = array();
504
+		// check if the post has fields on the meta table already
505
+		foreach ($this->get_tables() as $table_obj) {
506
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
507
+			foreach ($fields_for_that_table as $field_obj) {
508
+				if (
509
+					! isset($post[ $field_obj->get_table_column() ])
510
+					&& ! isset($post[ $field_obj->get_qualified_column() ])
511
+				) {
512
+					$tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj;
513
+				}
514
+			}
515
+		}
516
+		// if we don't have all the fields we need, then just fetch the proper model from the DB
517
+		if ($tables_needing_to_be_queried) {
518
+			if (
519
+				count($tables_needing_to_be_queried) == 1
520
+				&& reset($tables_needing_to_be_queried)
521
+				   instanceof
522
+				   EE_Secondary_Table
523
+			) {
524
+				// so we're only missing data from a secondary table. Well that's not too hard to query for
525
+				$table_to_query = reset($tables_needing_to_be_queried);
526
+				$missing_data = $this->_do_wpdb_query(
527
+					'get_row',
528
+					array(
529
+						'SELECT * FROM '
530
+						. $table_to_query->get_table_name()
531
+						. ' WHERE '
532
+						. $table_to_query->get_fk_on_table()
533
+						. ' = '
534
+						. $post['ID'],
535
+						ARRAY_A,
536
+					)
537
+				);
538
+				if (! empty($missing_data)) {
539
+					$post = array_merge($post, $missing_data);
540
+				}
541
+			} else {
542
+				return $this->get_one_by_ID($post['ID']);
543
+			}
544
+		}
545
+		return $this->instantiate_class_from_array_or_object($post);
546
+	}
547
+
548
+
549
+	/**
550
+	 * Gets the post type associated with this
551
+	 *
552
+	 * @throws EE_Error
553
+	 * @return string
554
+	 */
555
+	public function post_type()
556
+	{
557
+		$post_type_field = null;
558
+		foreach ($this->field_settings(true) as $field_obj) {
559
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
560
+				$post_type_field = $field_obj;
561
+				break;
562
+			}
563
+		}
564
+		if ($post_type_field == null) {
565
+			throw new EE_Error(
566
+				sprintf(
567
+					esc_html__(
568
+						"CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
569
+						"event_espresso"
570
+					),
571
+					get_class($this)
572
+				)
573
+			);
574
+		}
575
+		return $post_type_field->get_default_value();
576
+	}
577 577
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 1 patch
Indentation   +915 added lines, -915 removed lines patch added patch discarded remove patch
@@ -14,919 +14,919 @@
 block discarded – undo
14 14
  */
15 15
 class EEM_Event extends EEM_CPT_Base
16 16
 {
17
-    /**
18
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
19
-     * event
20
-     */
21
-    const sold_out = 'sold_out';
22
-
23
-    /**
24
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
25
-     * date)
26
-     */
27
-    const postponed = 'postponed';
28
-
29
-    /**
30
-     * constant used by status(), indicating that the event will no longer occur
31
-     */
32
-    const cancelled = 'cancelled';
33
-
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    protected static $_default_reg_status;
39
-
40
-
41
-    /**
42
-     * This is the default for the additional limit field.
43
-     * @var int
44
-     */
45
-    protected static $_default_additional_limit = 10;
46
-
47
-
48
-    /**
49
-     * private instance of the Event object
50
-     *
51
-     * @var EEM_Event
52
-     */
53
-    protected static $_instance;
54
-
55
-
56
-
57
-
58
-    /**
59
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
60
-     *
61
-     * @param string $timezone
62
-     * @throws \EE_Error
63
-     */
64
-    protected function __construct($timezone = null)
65
-    {
66
-        EE_Registry::instance()->load_model('Registration');
67
-        $this->singular_item = esc_html__('Event', 'event_espresso');
68
-        $this->plural_item = esc_html__('Events', 'event_espresso');
69
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
70
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
71
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
72
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
73
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
74
-        //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
75
-        $this->_custom_stati = apply_filters(
76
-            'AFEE__EEM_Event__construct___custom_stati',
77
-            array(
78
-                EEM_Event::cancelled => array(
79
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
80
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
81
-                ),
82
-                EEM_Event::postponed => array(
83
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
84
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
85
-                ),
86
-                EEM_Event::sold_out  => array(
87
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
88
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
89
-                ),
90
-            )
91
-        );
92
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
93
-            : self::$_default_reg_status;
94
-        $this->_tables = array(
95
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97
-        );
98
-        $this->_fields = array(
99
-            'Event_CPT'  => array(
100
-                'EVT_ID'         => new EE_Primary_Key_Int_Field(
101
-                    'ID',
102
-                    esc_html__('Post ID for Event', 'event_espresso')
103
-                ),
104
-                'EVT_name'       => new EE_Plain_Text_Field(
105
-                    'post_title',
106
-                    esc_html__('Event Name', 'event_espresso'),
107
-                    false,
108
-                    ''
109
-                ),
110
-                'EVT_desc'       => new EE_Post_Content_Field(
111
-                    'post_content',
112
-                    esc_html__('Event Description', 'event_espresso'),
113
-                    false,
114
-                    ''
115
-                ),
116
-                'EVT_slug'       => new EE_Slug_Field(
117
-                    'post_name',
118
-                    esc_html__('Event Slug', 'event_espresso'),
119
-                    false,
120
-                    ''
121
-                ),
122
-                'EVT_created'    => new EE_Datetime_Field(
123
-                    'post_date',
124
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
125
-                    false,
126
-                    EE_Datetime_Field::now
127
-                ),
128
-                'EVT_short_desc' => new EE_Simple_HTML_Field(
129
-                    'post_excerpt',
130
-                    esc_html__('Event Short Description', 'event_espresso'),
131
-                    false,
132
-                    ''
133
-                ),
134
-                'EVT_modified'   => new EE_Datetime_Field(
135
-                    'post_modified',
136
-                    esc_html__('Date/Time Event Modified', 'event_espresso'),
137
-                    false,
138
-                    EE_Datetime_Field::now
139
-                ),
140
-                'EVT_wp_user'    => new EE_WP_User_Field(
141
-                    'post_author',
142
-                    esc_html__('Event Creator ID', 'event_espresso'),
143
-                    false
144
-                ),
145
-                'parent'         => new EE_Integer_Field(
146
-                    'post_parent',
147
-                    esc_html__('Event Parent ID', 'event_espresso'),
148
-                    false,
149
-                    0
150
-                ),
151
-                'EVT_order'      => new EE_Integer_Field(
152
-                    'menu_order',
153
-                    esc_html__('Event Menu Order', 'event_espresso'),
154
-                    false,
155
-                    1
156
-                ),
157
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
158
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
159
-                'status'         => new EE_WP_Post_Status_Field(
160
-                    'post_status',
161
-                    esc_html__('Event Status', 'event_espresso'),
162
-                    false,
163
-                    'draft',
164
-                    $this->_custom_stati
165
-                ),
166
-                'password' => new EE_Password_Field(
167
-                    'post_password',
168
-                    esc_html__('Password', 'event_espresso'),
169
-                    false,
170
-                    '',
171
-                    array(
172
-                        'EVT_desc',
173
-                        'EVT_short_desc',
174
-                        'EVT_display_desc',
175
-                        'EVT_display_ticket_selector',
176
-                        'EVT_visible_on',
177
-                        'EVT_additional_limit',
178
-                        'EVT_default_registration_status',
179
-                        'EVT_member_only',
180
-                        'EVT_phone',
181
-                        'EVT_allow_overflow',
182
-                        'EVT_timezone_string',
183
-                        'EVT_external_URL',
184
-                        'EVT_donations'
185
-                    )
186
-                )
187
-            ),
188
-            'Event_Meta' => array(
189
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field(
190
-                    'EVTM_ID',
191
-                    esc_html__('Event Meta Row ID', 'event_espresso'),
192
-                    false
193
-                ),
194
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
195
-                    'EVT_ID',
196
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
197
-                    false
198
-                ),
199
-                'EVT_display_desc'                => new EE_Boolean_Field(
200
-                    'EVT_display_desc',
201
-                    esc_html__('Display Description Flag', 'event_espresso'),
202
-                    false,
203
-                    true
204
-                ),
205
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field(
206
-                    'EVT_display_ticket_selector',
207
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'),
208
-                    false,
209
-                    true
210
-                ),
211
-                'EVT_visible_on'                  => new EE_Datetime_Field(
212
-                    'EVT_visible_on',
213
-                    esc_html__('Event Visible Date', 'event_espresso'),
214
-                    true,
215
-                    EE_Datetime_Field::now
216
-                ),
217
-                'EVT_additional_limit'            => new EE_Integer_Field(
218
-                    'EVT_additional_limit',
219
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
220
-                    true,
221
-                    self::$_default_additional_limit
222
-                ),
223
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
224
-                    'EVT_default_registration_status',
225
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'),
226
-                    false,
227
-                    EEM_Event::$_default_reg_status,
228
-                    EEM_Registration::reg_status_array()
229
-                ),
230
-                'EVT_member_only'                 => new EE_Boolean_Field(
231
-                    'EVT_member_only',
232
-                    esc_html__('Member-Only Event Flag', 'event_espresso'),
233
-                    false,
234
-                    false
235
-                ),
236
-                'EVT_phone'                       => new EE_Plain_Text_Field(
237
-                    'EVT_phone',
238
-                    esc_html__('Event Phone Number', 'event_espresso'),
239
-                    false,
240
-                    ''
241
-                ),
242
-                'EVT_allow_overflow'              => new EE_Boolean_Field(
243
-                    'EVT_allow_overflow',
244
-                    esc_html__('Allow Overflow on Event', 'event_espresso'),
245
-                    false,
246
-                    false
247
-                ),
248
-                'EVT_timezone_string'             => new EE_Plain_Text_Field(
249
-                    'EVT_timezone_string',
250
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'),
251
-                    false,
252
-                    ''
253
-                ),
254
-                'EVT_external_URL'                => new EE_Plain_Text_Field(
255
-                    'EVT_external_URL',
256
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
257
-                    true
258
-                ),
259
-                'EVT_donations'                   => new EE_Boolean_Field(
260
-                    'EVT_donations',
261
-                    esc_html__('Accept Donations?', 'event_espresso'),
262
-                    false,
263
-                    false
264
-                ),
265
-            ),
266
-        );
267
-        $this->_model_relations = array(
268
-            'Registration'           => new EE_Has_Many_Relation(),
269
-            'Datetime'               => new EE_Has_Many_Relation(),
270
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
271
-            'Event_Question_Group'   => new EE_Has_Many_Relation(),
272
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
273
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
274
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
275
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
276
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
277
-            'WP_User'                => new EE_Belongs_To_Relation(),
278
-        );
279
-        // this model is generally available for reading
280
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
281
-        $this->model_chain_to_password = '';
282
-        parent::__construct($timezone);
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * @param string $default_reg_status
289
-     */
290
-    public static function set_default_reg_status($default_reg_status)
291
-    {
292
-        self::$_default_reg_status = $default_reg_status;
293
-        // if EEM_Event has already been instantiated,
294
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
295
-        if (self::$_instance instanceof EEM_Event) {
296
-            $default_reg_status = new EE_Enum_Text_Field(
297
-                'EVT_default_registration_status',
298
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
299
-                false,
300
-                $default_reg_status,
301
-                EEM_Registration::reg_status_array()
302
-            );
303
-            $default_reg_status->_construct_finalize(
304
-                'Event_Meta',
305
-                'EVT_default_registration_status',
306
-                'EEM_Event'
307
-            );
308
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
309
-        }
310
-    }
311
-
312
-
313
-    /**
314
-     * Used to override the default for the additional limit field.
315
-     * @param $additional_limit
316
-     */
317
-    public static function set_default_additional_limit($additional_limit)
318
-    {
319
-        self::$_default_additional_limit = (int) $additional_limit;
320
-        if (self::$_instance instanceof EEM_Event) {
321
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
322
-                'EVT_additional_limit',
323
-                esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
324
-                true,
325
-                self::$_default_additional_limit
326
-            );
327
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
328
-                'Event_Meta',
329
-                'EVT_additional_limit',
330
-                'EEM_Event'
331
-            );
332
-        }
333
-    }
334
-
335
-
336
-    /**
337
-     * Return what is currently set as the default additional limit for the event.
338
-     * @return int
339
-     */
340
-    public static function get_default_additional_limit()
341
-    {
342
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
343
-    }
344
-
345
-
346
-    /**
347
-     * get_question_groups
348
-     *
349
-     * @return array
350
-     * @throws \EE_Error
351
-     */
352
-    public function get_all_question_groups()
353
-    {
354
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
355
-            array(
356
-                array('QSG_deleted' => false),
357
-                'order_by' => array('QSG_order' => 'ASC'),
358
-            )
359
-        );
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * get_question_groups
366
-     *
367
-     * @param int $EVT_ID
368
-     * @return array|bool
369
-     * @throws \EE_Error
370
-     */
371
-    public function get_all_event_question_groups($EVT_ID = 0)
372
-    {
373
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
374
-            EE_Error::add_error(
375
-                esc_html__(
376
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
377
-                    'event_espresso'
378
-                ),
379
-                __FILE__,
380
-                __FUNCTION__,
381
-                __LINE__
382
-            );
383
-            return false;
384
-        }
385
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
386
-            array(
387
-                array('EVT_ID' => $EVT_ID),
388
-            )
389
-        );
390
-    }
391
-
392
-
393
-    /**
394
-     * get_question_groups
395
-     *
396
-     * @param int $EVT_ID
397
-     * @param boolean $for_primary_attendee
398
-     * @return array|bool
399
-     * @throws EE_Error
400
-     * @throws InvalidArgumentException
401
-     * @throws ReflectionException
402
-     * @throws InvalidDataTypeException
403
-     * @throws InvalidInterfaceException
404
-     */
405
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
406
-    {
407
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
408
-            EE_Error::add_error(
409
-                esc_html__(
410
-                    // @codingStandardsIgnoreStart
411
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
412
-                    // @codingStandardsIgnoreEnd
413
-                    'event_espresso'
414
-                ),
415
-                __FILE__,
416
-                __FUNCTION__,
417
-                __LINE__
418
-            );
419
-            return false;
420
-        }
421
-        $query_params = [
422
-            [
423
-                'EVT_ID' => $EVT_ID,
424
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true
425
-            ]
426
-        ];
427
-        if ($for_primary_attendee) {
428
-            $query_params[0]['EQG_primary'] = true;
429
-        } else {
430
-            $query_params[0]['EQG_additional'] = true;
431
-        }
432
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
433
-    }
434
-
435
-
436
-    /**
437
-     * get_question_groups
438
-     *
439
-     * @param int $EVT_ID
440
-     * @param EE_Registration $registration
441
-     * @return array|bool
442
-     * @throws EE_Error
443
-     * @throws InvalidArgumentException
444
-     * @throws InvalidDataTypeException
445
-     * @throws InvalidInterfaceException
446
-     * @throws ReflectionException
447
-     */
448
-    public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
449
-    {
450
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
451
-            EE_Error::add_error(
452
-                esc_html__(
453
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
454
-                    'event_espresso'
455
-                ),
456
-                __FILE__,
457
-                __FUNCTION__,
458
-                __LINE__
459
-            );
460
-            return false;
461
-        }
462
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
463
-            [
464
-                [
465
-                    'Event_Question_Group.EVT_ID'      => $EVT_ID,
466
-                    'Event_Question_Group.'
467
-                        . EEM_Event_Question_Group::instance()->fieldNameForContext(
468
-                            $registration->is_primary_registrant()
469
-                        ) => true
470
-                ],
471
-                'order_by' => ['QSG_order' => 'ASC'],
472
-            ]
473
-        );
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * get_question_target_db_column
480
-     *
481
-     * @param string $QSG_IDs csv list of $QSG IDs
482
-     * @return array|bool
483
-     * @throws \EE_Error
484
-     */
485
-    public function get_questions_in_groups($QSG_IDs = '')
486
-    {
487
-        if (empty($QSG_IDs)) {
488
-            EE_Error::add_error(
489
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
490
-                __FILE__,
491
-                __FUNCTION__,
492
-                __LINE__
493
-            );
494
-            return false;
495
-        }
496
-        return EE_Registry::instance()->load_model('Question')->get_all(
497
-            array(
498
-                array(
499
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
500
-                    'QST_deleted'           => false,
501
-                    'QST_admin_only'        => is_admin(),
502
-                ),
503
-                'order_by' => 'QST_order',
504
-            )
505
-        );
506
-    }
507
-
508
-
509
-
510
-    /**
511
-     * get_options_for_question
512
-     *
513
-     * @param string $QST_IDs csv list of $QST IDs
514
-     * @return array|bool
515
-     * @throws \EE_Error
516
-     */
517
-    public function get_options_for_question($QST_IDs)
518
-    {
519
-        if (empty($QST_IDs)) {
520
-            EE_Error::add_error(
521
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
522
-                __FILE__,
523
-                __FUNCTION__,
524
-                __LINE__
525
-            );
526
-            return false;
527
-        }
528
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
529
-            array(
530
-                array(
531
-                    'Question.QST_ID' => array('IN', $QST_IDs),
532
-                    'QSO_deleted'     => false,
533
-                ),
534
-                'order_by' => 'QSO_ID',
535
-            )
536
-        );
537
-    }
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-    /**
546
-     * Gets all events that are published
547
-     * and have event start time earlier than now and an event end time later than now
548
-     *
549
-     * @param  array $query_params An array of query params to further filter on
550
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
551
-     * @param bool   $count        whether to return the count or not (default FALSE)
552
-     * @return EE_Event[]|int
553
-     * @throws \EE_Error
554
-     */
555
-    public function get_active_events($query_params, $count = false)
556
-    {
557
-        if (array_key_exists(0, $query_params)) {
558
-            $where_params = $query_params[0];
559
-            unset($query_params[0]);
560
-        } else {
561
-            $where_params = array();
562
-        }
563
-        // if we have count make sure we don't include group by
564
-        if ($count && isset($query_params['group_by'])) {
565
-            unset($query_params['group_by']);
566
-        }
567
-        // let's add specific query_params for active_events
568
-        // keep in mind this will override any sent status in the query AND any date queries.
569
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
570
-        // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
571
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
572
-            $where_params['Datetime.DTT_EVT_start******'] = array(
573
-                '<',
574
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
575
-            );
576
-        } else {
577
-            $where_params['Datetime.DTT_EVT_start'] = array(
578
-                '<',
579
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
580
-            );
581
-        }
582
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
583
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
584
-                '>',
585
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
586
-            );
587
-        } else {
588
-            $where_params['Datetime.DTT_EVT_end'] = array(
589
-                '>',
590
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
591
-            );
592
-        }
593
-        $query_params[0] = $where_params;
594
-        // don't use $query_params with count()
595
-        // because we don't want to include additional query clauses like "GROUP BY"
596
-        return $count
597
-            ? $this->count(array($where_params), 'EVT_ID', true)
598
-            : $this->get_all($query_params);
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * get all events that are published and have an event start time later than now
605
-     *
606
-     * @param  array $query_params An array of query params to further filter on
607
-     *                             (Note that status and DTT_EVT_start will be overridden)
608
-     * @param bool   $count        whether to return the count or not (default FALSE)
609
-     * @return EE_Event[]|int
610
-     * @throws \EE_Error
611
-     */
612
-    public function get_upcoming_events($query_params, $count = false)
613
-    {
614
-        if (array_key_exists(0, $query_params)) {
615
-            $where_params = $query_params[0];
616
-            unset($query_params[0]);
617
-        } else {
618
-            $where_params = array();
619
-        }
620
-        // if we have count make sure we don't include group by
621
-        if ($count && isset($query_params['group_by'])) {
622
-            unset($query_params['group_by']);
623
-        }
624
-        // let's add specific query_params for active_events
625
-        // keep in mind this will override any sent status in the query AND any date queries.
626
-        // we need to pull events with a status of publish and sold_out
627
-        $event_status = array('publish', EEM_Event::sold_out);
628
-        // check if the user can read private events and if so add the 'private status to the were params'
629
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
630
-            $event_status[] = 'private';
631
-        }
632
-        $where_params['status'] = array('IN', $event_status);
633
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
634
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
635
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
636
-                '>',
637
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
638
-            );
639
-        } else {
640
-            $where_params['Datetime.DTT_EVT_start'] = array(
641
-                '>',
642
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
643
-            );
644
-        }
645
-        $query_params[0] = $where_params;
646
-        // don't use $query_params with count()
647
-        // because we don't want to include additional query clauses like "GROUP BY"
648
-        return $count
649
-            ? $this->count(array($where_params), 'EVT_ID', true)
650
-            : $this->get_all($query_params);
651
-    }
652
-
653
-
654
-
655
-    /**
656
-     * Gets all events that are published
657
-     * and have an event end time later than now
658
-     *
659
-     * @param  array $query_params An array of query params to further filter on
660
-     *                             (note that status and DTT_EVT_end will be overridden)
661
-     * @param bool   $count        whether to return the count or not (default FALSE)
662
-     * @return EE_Event[]|int
663
-     * @throws \EE_Error
664
-     */
665
-    public function get_active_and_upcoming_events($query_params, $count = false)
666
-    {
667
-        if (array_key_exists(0, $query_params)) {
668
-            $where_params = $query_params[0];
669
-            unset($query_params[0]);
670
-        } else {
671
-            $where_params = array();
672
-        }
673
-        // if we have count make sure we don't include group by
674
-        if ($count && isset($query_params['group_by'])) {
675
-            unset($query_params['group_by']);
676
-        }
677
-        // let's add specific query_params for active_events
678
-        // keep in mind this will override any sent status in the query AND any date queries.
679
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
680
-        // add where params for DTT_EVT_end
681
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
682
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
683
-                '>',
684
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
685
-            );
686
-        } else {
687
-            $where_params['Datetime.DTT_EVT_end'] = array(
688
-                '>',
689
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
690
-            );
691
-        }
692
-        $query_params[0] = $where_params;
693
-        // don't use $query_params with count()
694
-        // because we don't want to include additional query clauses like "GROUP BY"
695
-        return $count
696
-            ? $this->count(array($where_params), 'EVT_ID', true)
697
-            : $this->get_all($query_params);
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * This only returns events that are expired.
704
-     * They may still be published but all their datetimes have expired.
705
-     *
706
-     * @param  array $query_params An array of query params to further filter on
707
-     *                             (note that status and DTT_EVT_end will be overridden)
708
-     * @param bool   $count        whether to return the count or not (default FALSE)
709
-     * @return EE_Event[]|int
710
-     * @throws \EE_Error
711
-     */
712
-    public function get_expired_events($query_params, $count = false)
713
-    {
714
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
715
-        // if we have count make sure we don't include group by
716
-        if ($count && isset($query_params['group_by'])) {
717
-            unset($query_params['group_by']);
718
-        }
719
-        // let's add specific query_params for active_events
720
-        // keep in mind this will override any sent status in the query AND any date queries.
721
-        if (isset($where_params['status'])) {
722
-            unset($where_params['status']);
723
-        }
724
-        $exclude_query = $query_params;
725
-        if (isset($exclude_query[0])) {
726
-            unset($exclude_query[0]);
727
-        }
728
-        $exclude_query[0] = array(
729
-            'Datetime.DTT_EVT_end' => array(
730
-                '>',
731
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
732
-            ),
733
-        );
734
-        // first get all events that have datetimes where its not expired.
735
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
736
-        $event_ids = array_keys($event_ids);
737
-        // if we have any additional query_params, let's add them to the 'AND' condition
738
-        $and_condition = array(
739
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
740
-            'EVT_ID'               => array('NOT IN', $event_ids),
741
-        );
742
-        if (isset($where_params['OR'])) {
743
-            $and_condition['OR'] = $where_params['OR'];
744
-            unset($where_params['OR']);
745
-        }
746
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
747
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
748
-            unset($where_params['Datetime.DTT_EVT_end']);
749
-        }
750
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
751
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
752
-            unset($where_params['Datetime.DTT_EVT_start']);
753
-        }
754
-        // merge remaining $where params with the and conditions.
755
-        $where_params['AND'] = array_merge($and_condition, $where_params);
756
-        $query_params[0] = $where_params;
757
-        // don't use $query_params with count()
758
-        // because we don't want to include additional query clauses like "GROUP BY"
759
-        return $count
760
-            ? $this->count(array($where_params), 'EVT_ID', true)
761
-            : $this->get_all($query_params);
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * This basically just returns the events that do not have the publish status.
768
-     *
769
-     * @param  array   $query_params An array of query params to further filter on
770
-     *                               (note that status will be overwritten)
771
-     * @param  boolean $count        whether to return the count or not (default FALSE)
772
-     * @return EE_Event[]|int
773
-     * @throws \EE_Error
774
-     */
775
-    public function get_inactive_events($query_params, $count = false)
776
-    {
777
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
778
-        // let's add in specific query_params for inactive events.
779
-        if (isset($where_params['status'])) {
780
-            unset($where_params['status']);
781
-        }
782
-        // if we have count make sure we don't include group by
783
-        if ($count && isset($query_params['group_by'])) {
784
-            unset($query_params['group_by']);
785
-        }
786
-        // if we have any additional query_params, let's add them to the 'AND' condition
787
-        $where_params['AND']['status'] = array('!=', 'publish');
788
-        if (isset($where_params['OR'])) {
789
-            $where_params['AND']['OR'] = $where_params['OR'];
790
-            unset($where_params['OR']);
791
-        }
792
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
793
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
794
-            unset($where_params['Datetime.DTT_EVT_end']);
795
-        }
796
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
797
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
798
-            unset($where_params['Datetime.DTT_EVT_start']);
799
-        }
800
-        $query_params[0] = $where_params;
801
-        // don't use $query_params with count()
802
-        // because we don't want to include additional query clauses like "GROUP BY"
803
-        return $count
804
-            ? $this->count(array($where_params), 'EVT_ID', true)
805
-            : $this->get_all($query_params);
806
-    }
807
-
808
-
809
-
810
-    /**
811
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
812
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
813
-     * attached to the event. See parent for param descriptions
814
-     *
815
-     * @param        $id_or_obj
816
-     * @param        $other_model_id_or_obj
817
-     * @param string $relationName
818
-     * @param array  $where_query
819
-     * @return EE_Base_Class
820
-     * @throws EE_Error
821
-     */
822
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
823
-    {
824
-        if ($relationName === 'Price') {
825
-            // let's get the PRC object for the given ID to make sure that we aren't dealing with a default
826
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
827
-            // if EVT_ID = 0, then this is a default
828
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
829
-                // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
830
-                $prc_chk->set('PRC_ID', 0);
831
-            }
832
-            // run parent
833
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
834
-        }
835
-        // otherwise carry on as normal
836
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
837
-    }
838
-
839
-
840
-
841
-    /******************** DEPRECATED METHODS ********************/
842
-
843
-
844
-
845
-    /**
846
-     * _get_question_target_db_column
847
-     *
848
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
849
-     *             EE_Registration_Custom_Questions_Form located in
850
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
851
-     * @access     public
852
-     * @param    EE_Registration $registration (so existing answers for registration are included)
853
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
854
-     *                                         registration).
855
-     * @throws EE_Error
856
-     * @return    array
857
-     */
858
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
859
-    {
860
-        if (empty($EVT_ID)) {
861
-            throw new EE_Error(esc_html__(
862
-                'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
863
-                'event_espresso'
864
-            ));
865
-        }
866
-        $questions = array();
867
-        // get all question groups for event
868
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
869
-        if (! empty($qgs)) {
870
-            foreach ($qgs as $qg) {
871
-                $qsts = $qg->questions();
872
-                $questions[ $qg->ID() ] = $qg->model_field_array();
873
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
874
-                foreach ($qsts as $qst) {
875
-                    if ($qst->is_system_question()) {
876
-                        continue;
877
-                    }
878
-                    $answer = EEM_Answer::instance()->get_one(array(
879
-                        array(
880
-                            'QST_ID' => $qst->ID(),
881
-                            'REG_ID' => $registration->ID(),
882
-                        ),
883
-                    ));
884
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
885
-                    $qst_name = $qstn_id = $qst->ID();
886
-                    $ans_id = $answer->ID();
887
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
888
-                    $input_name = '';
889
-                    $input_id = sanitize_key($qst->display_text());
890
-                    $input_class = '';
891
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
892
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
893
-                                                                                           . $input_name
894
-                                                                                           . $qst_name;
895
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
896
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
897
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
898
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
899
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
900
-                    // leave responses as-is, don't convert stuff into html entities please!
901
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
902
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
903
-                        $QSOs = $qst->options(true, $answer->value());
904
-                        if (is_array($QSOs)) {
905
-                            foreach ($QSOs as $QSO_ID => $QSO) {
906
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
907
-                            }
908
-                        }
909
-                    }
910
-                }
911
-            }
912
-        }
913
-        return $questions;
914
-    }
915
-
916
-
917
-    /**
918
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
919
-     *                             or an stdClass where each property is the name of a column,
920
-     * @return EE_Base_Class
921
-     * @throws \EE_Error
922
-     */
923
-    public function instantiate_class_from_array_or_object($cols_n_values)
924
-    {
925
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
926
-        if ($classInstance instanceof EE_Event) {
927
-            // events have their timezone defined in the DB, so use it immediately
928
-            $this->set_timezone($classInstance->get_timezone());
929
-        }
930
-        return $classInstance;
931
-    }
17
+	/**
18
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
19
+	 * event
20
+	 */
21
+	const sold_out = 'sold_out';
22
+
23
+	/**
24
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
25
+	 * date)
26
+	 */
27
+	const postponed = 'postponed';
28
+
29
+	/**
30
+	 * constant used by status(), indicating that the event will no longer occur
31
+	 */
32
+	const cancelled = 'cancelled';
33
+
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	protected static $_default_reg_status;
39
+
40
+
41
+	/**
42
+	 * This is the default for the additional limit field.
43
+	 * @var int
44
+	 */
45
+	protected static $_default_additional_limit = 10;
46
+
47
+
48
+	/**
49
+	 * private instance of the Event object
50
+	 *
51
+	 * @var EEM_Event
52
+	 */
53
+	protected static $_instance;
54
+
55
+
56
+
57
+
58
+	/**
59
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
60
+	 *
61
+	 * @param string $timezone
62
+	 * @throws \EE_Error
63
+	 */
64
+	protected function __construct($timezone = null)
65
+	{
66
+		EE_Registry::instance()->load_model('Registration');
67
+		$this->singular_item = esc_html__('Event', 'event_espresso');
68
+		$this->plural_item = esc_html__('Events', 'event_espresso');
69
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
70
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
71
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
72
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
73
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
74
+		//  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
75
+		$this->_custom_stati = apply_filters(
76
+			'AFEE__EEM_Event__construct___custom_stati',
77
+			array(
78
+				EEM_Event::cancelled => array(
79
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
80
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
81
+				),
82
+				EEM_Event::postponed => array(
83
+					'label'  => esc_html__('Postponed', 'event_espresso'),
84
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
85
+				),
86
+				EEM_Event::sold_out  => array(
87
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
88
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
89
+				),
90
+			)
91
+		);
92
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
93
+			: self::$_default_reg_status;
94
+		$this->_tables = array(
95
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97
+		);
98
+		$this->_fields = array(
99
+			'Event_CPT'  => array(
100
+				'EVT_ID'         => new EE_Primary_Key_Int_Field(
101
+					'ID',
102
+					esc_html__('Post ID for Event', 'event_espresso')
103
+				),
104
+				'EVT_name'       => new EE_Plain_Text_Field(
105
+					'post_title',
106
+					esc_html__('Event Name', 'event_espresso'),
107
+					false,
108
+					''
109
+				),
110
+				'EVT_desc'       => new EE_Post_Content_Field(
111
+					'post_content',
112
+					esc_html__('Event Description', 'event_espresso'),
113
+					false,
114
+					''
115
+				),
116
+				'EVT_slug'       => new EE_Slug_Field(
117
+					'post_name',
118
+					esc_html__('Event Slug', 'event_espresso'),
119
+					false,
120
+					''
121
+				),
122
+				'EVT_created'    => new EE_Datetime_Field(
123
+					'post_date',
124
+					esc_html__('Date/Time Event Created', 'event_espresso'),
125
+					false,
126
+					EE_Datetime_Field::now
127
+				),
128
+				'EVT_short_desc' => new EE_Simple_HTML_Field(
129
+					'post_excerpt',
130
+					esc_html__('Event Short Description', 'event_espresso'),
131
+					false,
132
+					''
133
+				),
134
+				'EVT_modified'   => new EE_Datetime_Field(
135
+					'post_modified',
136
+					esc_html__('Date/Time Event Modified', 'event_espresso'),
137
+					false,
138
+					EE_Datetime_Field::now
139
+				),
140
+				'EVT_wp_user'    => new EE_WP_User_Field(
141
+					'post_author',
142
+					esc_html__('Event Creator ID', 'event_espresso'),
143
+					false
144
+				),
145
+				'parent'         => new EE_Integer_Field(
146
+					'post_parent',
147
+					esc_html__('Event Parent ID', 'event_espresso'),
148
+					false,
149
+					0
150
+				),
151
+				'EVT_order'      => new EE_Integer_Field(
152
+					'menu_order',
153
+					esc_html__('Event Menu Order', 'event_espresso'),
154
+					false,
155
+					1
156
+				),
157
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
158
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
159
+				'status'         => new EE_WP_Post_Status_Field(
160
+					'post_status',
161
+					esc_html__('Event Status', 'event_espresso'),
162
+					false,
163
+					'draft',
164
+					$this->_custom_stati
165
+				),
166
+				'password' => new EE_Password_Field(
167
+					'post_password',
168
+					esc_html__('Password', 'event_espresso'),
169
+					false,
170
+					'',
171
+					array(
172
+						'EVT_desc',
173
+						'EVT_short_desc',
174
+						'EVT_display_desc',
175
+						'EVT_display_ticket_selector',
176
+						'EVT_visible_on',
177
+						'EVT_additional_limit',
178
+						'EVT_default_registration_status',
179
+						'EVT_member_only',
180
+						'EVT_phone',
181
+						'EVT_allow_overflow',
182
+						'EVT_timezone_string',
183
+						'EVT_external_URL',
184
+						'EVT_donations'
185
+					)
186
+				)
187
+			),
188
+			'Event_Meta' => array(
189
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field(
190
+					'EVTM_ID',
191
+					esc_html__('Event Meta Row ID', 'event_espresso'),
192
+					false
193
+				),
194
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
195
+					'EVT_ID',
196
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
197
+					false
198
+				),
199
+				'EVT_display_desc'                => new EE_Boolean_Field(
200
+					'EVT_display_desc',
201
+					esc_html__('Display Description Flag', 'event_espresso'),
202
+					false,
203
+					true
204
+				),
205
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field(
206
+					'EVT_display_ticket_selector',
207
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'),
208
+					false,
209
+					true
210
+				),
211
+				'EVT_visible_on'                  => new EE_Datetime_Field(
212
+					'EVT_visible_on',
213
+					esc_html__('Event Visible Date', 'event_espresso'),
214
+					true,
215
+					EE_Datetime_Field::now
216
+				),
217
+				'EVT_additional_limit'            => new EE_Integer_Field(
218
+					'EVT_additional_limit',
219
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
220
+					true,
221
+					self::$_default_additional_limit
222
+				),
223
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
224
+					'EVT_default_registration_status',
225
+					esc_html__('Default Registration Status on this Event', 'event_espresso'),
226
+					false,
227
+					EEM_Event::$_default_reg_status,
228
+					EEM_Registration::reg_status_array()
229
+				),
230
+				'EVT_member_only'                 => new EE_Boolean_Field(
231
+					'EVT_member_only',
232
+					esc_html__('Member-Only Event Flag', 'event_espresso'),
233
+					false,
234
+					false
235
+				),
236
+				'EVT_phone'                       => new EE_Plain_Text_Field(
237
+					'EVT_phone',
238
+					esc_html__('Event Phone Number', 'event_espresso'),
239
+					false,
240
+					''
241
+				),
242
+				'EVT_allow_overflow'              => new EE_Boolean_Field(
243
+					'EVT_allow_overflow',
244
+					esc_html__('Allow Overflow on Event', 'event_espresso'),
245
+					false,
246
+					false
247
+				),
248
+				'EVT_timezone_string'             => new EE_Plain_Text_Field(
249
+					'EVT_timezone_string',
250
+					esc_html__('Timezone (name) for Event times', 'event_espresso'),
251
+					false,
252
+					''
253
+				),
254
+				'EVT_external_URL'                => new EE_Plain_Text_Field(
255
+					'EVT_external_URL',
256
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
257
+					true
258
+				),
259
+				'EVT_donations'                   => new EE_Boolean_Field(
260
+					'EVT_donations',
261
+					esc_html__('Accept Donations?', 'event_espresso'),
262
+					false,
263
+					false
264
+				),
265
+			),
266
+		);
267
+		$this->_model_relations = array(
268
+			'Registration'           => new EE_Has_Many_Relation(),
269
+			'Datetime'               => new EE_Has_Many_Relation(),
270
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
271
+			'Event_Question_Group'   => new EE_Has_Many_Relation(),
272
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
273
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
274
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
275
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
276
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
277
+			'WP_User'                => new EE_Belongs_To_Relation(),
278
+		);
279
+		// this model is generally available for reading
280
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
281
+		$this->model_chain_to_password = '';
282
+		parent::__construct($timezone);
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * @param string $default_reg_status
289
+	 */
290
+	public static function set_default_reg_status($default_reg_status)
291
+	{
292
+		self::$_default_reg_status = $default_reg_status;
293
+		// if EEM_Event has already been instantiated,
294
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
295
+		if (self::$_instance instanceof EEM_Event) {
296
+			$default_reg_status = new EE_Enum_Text_Field(
297
+				'EVT_default_registration_status',
298
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
299
+				false,
300
+				$default_reg_status,
301
+				EEM_Registration::reg_status_array()
302
+			);
303
+			$default_reg_status->_construct_finalize(
304
+				'Event_Meta',
305
+				'EVT_default_registration_status',
306
+				'EEM_Event'
307
+			);
308
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
309
+		}
310
+	}
311
+
312
+
313
+	/**
314
+	 * Used to override the default for the additional limit field.
315
+	 * @param $additional_limit
316
+	 */
317
+	public static function set_default_additional_limit($additional_limit)
318
+	{
319
+		self::$_default_additional_limit = (int) $additional_limit;
320
+		if (self::$_instance instanceof EEM_Event) {
321
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
322
+				'EVT_additional_limit',
323
+				esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
324
+				true,
325
+				self::$_default_additional_limit
326
+			);
327
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
328
+				'Event_Meta',
329
+				'EVT_additional_limit',
330
+				'EEM_Event'
331
+			);
332
+		}
333
+	}
334
+
335
+
336
+	/**
337
+	 * Return what is currently set as the default additional limit for the event.
338
+	 * @return int
339
+	 */
340
+	public static function get_default_additional_limit()
341
+	{
342
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
343
+	}
344
+
345
+
346
+	/**
347
+	 * get_question_groups
348
+	 *
349
+	 * @return array
350
+	 * @throws \EE_Error
351
+	 */
352
+	public function get_all_question_groups()
353
+	{
354
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
355
+			array(
356
+				array('QSG_deleted' => false),
357
+				'order_by' => array('QSG_order' => 'ASC'),
358
+			)
359
+		);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * get_question_groups
366
+	 *
367
+	 * @param int $EVT_ID
368
+	 * @return array|bool
369
+	 * @throws \EE_Error
370
+	 */
371
+	public function get_all_event_question_groups($EVT_ID = 0)
372
+	{
373
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
374
+			EE_Error::add_error(
375
+				esc_html__(
376
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
377
+					'event_espresso'
378
+				),
379
+				__FILE__,
380
+				__FUNCTION__,
381
+				__LINE__
382
+			);
383
+			return false;
384
+		}
385
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
386
+			array(
387
+				array('EVT_ID' => $EVT_ID),
388
+			)
389
+		);
390
+	}
391
+
392
+
393
+	/**
394
+	 * get_question_groups
395
+	 *
396
+	 * @param int $EVT_ID
397
+	 * @param boolean $for_primary_attendee
398
+	 * @return array|bool
399
+	 * @throws EE_Error
400
+	 * @throws InvalidArgumentException
401
+	 * @throws ReflectionException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws InvalidInterfaceException
404
+	 */
405
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
406
+	{
407
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
408
+			EE_Error::add_error(
409
+				esc_html__(
410
+					// @codingStandardsIgnoreStart
411
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
412
+					// @codingStandardsIgnoreEnd
413
+					'event_espresso'
414
+				),
415
+				__FILE__,
416
+				__FUNCTION__,
417
+				__LINE__
418
+			);
419
+			return false;
420
+		}
421
+		$query_params = [
422
+			[
423
+				'EVT_ID' => $EVT_ID,
424
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true
425
+			]
426
+		];
427
+		if ($for_primary_attendee) {
428
+			$query_params[0]['EQG_primary'] = true;
429
+		} else {
430
+			$query_params[0]['EQG_additional'] = true;
431
+		}
432
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
433
+	}
434
+
435
+
436
+	/**
437
+	 * get_question_groups
438
+	 *
439
+	 * @param int $EVT_ID
440
+	 * @param EE_Registration $registration
441
+	 * @return array|bool
442
+	 * @throws EE_Error
443
+	 * @throws InvalidArgumentException
444
+	 * @throws InvalidDataTypeException
445
+	 * @throws InvalidInterfaceException
446
+	 * @throws ReflectionException
447
+	 */
448
+	public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
449
+	{
450
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
451
+			EE_Error::add_error(
452
+				esc_html__(
453
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
454
+					'event_espresso'
455
+				),
456
+				__FILE__,
457
+				__FUNCTION__,
458
+				__LINE__
459
+			);
460
+			return false;
461
+		}
462
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
463
+			[
464
+				[
465
+					'Event_Question_Group.EVT_ID'      => $EVT_ID,
466
+					'Event_Question_Group.'
467
+						. EEM_Event_Question_Group::instance()->fieldNameForContext(
468
+							$registration->is_primary_registrant()
469
+						) => true
470
+				],
471
+				'order_by' => ['QSG_order' => 'ASC'],
472
+			]
473
+		);
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * get_question_target_db_column
480
+	 *
481
+	 * @param string $QSG_IDs csv list of $QSG IDs
482
+	 * @return array|bool
483
+	 * @throws \EE_Error
484
+	 */
485
+	public function get_questions_in_groups($QSG_IDs = '')
486
+	{
487
+		if (empty($QSG_IDs)) {
488
+			EE_Error::add_error(
489
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
490
+				__FILE__,
491
+				__FUNCTION__,
492
+				__LINE__
493
+			);
494
+			return false;
495
+		}
496
+		return EE_Registry::instance()->load_model('Question')->get_all(
497
+			array(
498
+				array(
499
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
500
+					'QST_deleted'           => false,
501
+					'QST_admin_only'        => is_admin(),
502
+				),
503
+				'order_by' => 'QST_order',
504
+			)
505
+		);
506
+	}
507
+
508
+
509
+
510
+	/**
511
+	 * get_options_for_question
512
+	 *
513
+	 * @param string $QST_IDs csv list of $QST IDs
514
+	 * @return array|bool
515
+	 * @throws \EE_Error
516
+	 */
517
+	public function get_options_for_question($QST_IDs)
518
+	{
519
+		if (empty($QST_IDs)) {
520
+			EE_Error::add_error(
521
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
522
+				__FILE__,
523
+				__FUNCTION__,
524
+				__LINE__
525
+			);
526
+			return false;
527
+		}
528
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
529
+			array(
530
+				array(
531
+					'Question.QST_ID' => array('IN', $QST_IDs),
532
+					'QSO_deleted'     => false,
533
+				),
534
+				'order_by' => 'QSO_ID',
535
+			)
536
+		);
537
+	}
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+	/**
546
+	 * Gets all events that are published
547
+	 * and have event start time earlier than now and an event end time later than now
548
+	 *
549
+	 * @param  array $query_params An array of query params to further filter on
550
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
551
+	 * @param bool   $count        whether to return the count or not (default FALSE)
552
+	 * @return EE_Event[]|int
553
+	 * @throws \EE_Error
554
+	 */
555
+	public function get_active_events($query_params, $count = false)
556
+	{
557
+		if (array_key_exists(0, $query_params)) {
558
+			$where_params = $query_params[0];
559
+			unset($query_params[0]);
560
+		} else {
561
+			$where_params = array();
562
+		}
563
+		// if we have count make sure we don't include group by
564
+		if ($count && isset($query_params['group_by'])) {
565
+			unset($query_params['group_by']);
566
+		}
567
+		// let's add specific query_params for active_events
568
+		// keep in mind this will override any sent status in the query AND any date queries.
569
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
570
+		// if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
571
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
572
+			$where_params['Datetime.DTT_EVT_start******'] = array(
573
+				'<',
574
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
575
+			);
576
+		} else {
577
+			$where_params['Datetime.DTT_EVT_start'] = array(
578
+				'<',
579
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
580
+			);
581
+		}
582
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
583
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
584
+				'>',
585
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
586
+			);
587
+		} else {
588
+			$where_params['Datetime.DTT_EVT_end'] = array(
589
+				'>',
590
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
591
+			);
592
+		}
593
+		$query_params[0] = $where_params;
594
+		// don't use $query_params with count()
595
+		// because we don't want to include additional query clauses like "GROUP BY"
596
+		return $count
597
+			? $this->count(array($where_params), 'EVT_ID', true)
598
+			: $this->get_all($query_params);
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * get all events that are published and have an event start time later than now
605
+	 *
606
+	 * @param  array $query_params An array of query params to further filter on
607
+	 *                             (Note that status and DTT_EVT_start will be overridden)
608
+	 * @param bool   $count        whether to return the count or not (default FALSE)
609
+	 * @return EE_Event[]|int
610
+	 * @throws \EE_Error
611
+	 */
612
+	public function get_upcoming_events($query_params, $count = false)
613
+	{
614
+		if (array_key_exists(0, $query_params)) {
615
+			$where_params = $query_params[0];
616
+			unset($query_params[0]);
617
+		} else {
618
+			$where_params = array();
619
+		}
620
+		// if we have count make sure we don't include group by
621
+		if ($count && isset($query_params['group_by'])) {
622
+			unset($query_params['group_by']);
623
+		}
624
+		// let's add specific query_params for active_events
625
+		// keep in mind this will override any sent status in the query AND any date queries.
626
+		// we need to pull events with a status of publish and sold_out
627
+		$event_status = array('publish', EEM_Event::sold_out);
628
+		// check if the user can read private events and if so add the 'private status to the were params'
629
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
630
+			$event_status[] = 'private';
631
+		}
632
+		$where_params['status'] = array('IN', $event_status);
633
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
634
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
635
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
636
+				'>',
637
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
638
+			);
639
+		} else {
640
+			$where_params['Datetime.DTT_EVT_start'] = array(
641
+				'>',
642
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
643
+			);
644
+		}
645
+		$query_params[0] = $where_params;
646
+		// don't use $query_params with count()
647
+		// because we don't want to include additional query clauses like "GROUP BY"
648
+		return $count
649
+			? $this->count(array($where_params), 'EVT_ID', true)
650
+			: $this->get_all($query_params);
651
+	}
652
+
653
+
654
+
655
+	/**
656
+	 * Gets all events that are published
657
+	 * and have an event end time later than now
658
+	 *
659
+	 * @param  array $query_params An array of query params to further filter on
660
+	 *                             (note that status and DTT_EVT_end will be overridden)
661
+	 * @param bool   $count        whether to return the count or not (default FALSE)
662
+	 * @return EE_Event[]|int
663
+	 * @throws \EE_Error
664
+	 */
665
+	public function get_active_and_upcoming_events($query_params, $count = false)
666
+	{
667
+		if (array_key_exists(0, $query_params)) {
668
+			$where_params = $query_params[0];
669
+			unset($query_params[0]);
670
+		} else {
671
+			$where_params = array();
672
+		}
673
+		// if we have count make sure we don't include group by
674
+		if ($count && isset($query_params['group_by'])) {
675
+			unset($query_params['group_by']);
676
+		}
677
+		// let's add specific query_params for active_events
678
+		// keep in mind this will override any sent status in the query AND any date queries.
679
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
680
+		// add where params for DTT_EVT_end
681
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
682
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
683
+				'>',
684
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
685
+			);
686
+		} else {
687
+			$where_params['Datetime.DTT_EVT_end'] = array(
688
+				'>',
689
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
690
+			);
691
+		}
692
+		$query_params[0] = $where_params;
693
+		// don't use $query_params with count()
694
+		// because we don't want to include additional query clauses like "GROUP BY"
695
+		return $count
696
+			? $this->count(array($where_params), 'EVT_ID', true)
697
+			: $this->get_all($query_params);
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * This only returns events that are expired.
704
+	 * They may still be published but all their datetimes have expired.
705
+	 *
706
+	 * @param  array $query_params An array of query params to further filter on
707
+	 *                             (note that status and DTT_EVT_end will be overridden)
708
+	 * @param bool   $count        whether to return the count or not (default FALSE)
709
+	 * @return EE_Event[]|int
710
+	 * @throws \EE_Error
711
+	 */
712
+	public function get_expired_events($query_params, $count = false)
713
+	{
714
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
715
+		// if we have count make sure we don't include group by
716
+		if ($count && isset($query_params['group_by'])) {
717
+			unset($query_params['group_by']);
718
+		}
719
+		// let's add specific query_params for active_events
720
+		// keep in mind this will override any sent status in the query AND any date queries.
721
+		if (isset($where_params['status'])) {
722
+			unset($where_params['status']);
723
+		}
724
+		$exclude_query = $query_params;
725
+		if (isset($exclude_query[0])) {
726
+			unset($exclude_query[0]);
727
+		}
728
+		$exclude_query[0] = array(
729
+			'Datetime.DTT_EVT_end' => array(
730
+				'>',
731
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
732
+			),
733
+		);
734
+		// first get all events that have datetimes where its not expired.
735
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
736
+		$event_ids = array_keys($event_ids);
737
+		// if we have any additional query_params, let's add them to the 'AND' condition
738
+		$and_condition = array(
739
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
740
+			'EVT_ID'               => array('NOT IN', $event_ids),
741
+		);
742
+		if (isset($where_params['OR'])) {
743
+			$and_condition['OR'] = $where_params['OR'];
744
+			unset($where_params['OR']);
745
+		}
746
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
747
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
748
+			unset($where_params['Datetime.DTT_EVT_end']);
749
+		}
750
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
751
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
752
+			unset($where_params['Datetime.DTT_EVT_start']);
753
+		}
754
+		// merge remaining $where params with the and conditions.
755
+		$where_params['AND'] = array_merge($and_condition, $where_params);
756
+		$query_params[0] = $where_params;
757
+		// don't use $query_params with count()
758
+		// because we don't want to include additional query clauses like "GROUP BY"
759
+		return $count
760
+			? $this->count(array($where_params), 'EVT_ID', true)
761
+			: $this->get_all($query_params);
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * This basically just returns the events that do not have the publish status.
768
+	 *
769
+	 * @param  array   $query_params An array of query params to further filter on
770
+	 *                               (note that status will be overwritten)
771
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
772
+	 * @return EE_Event[]|int
773
+	 * @throws \EE_Error
774
+	 */
775
+	public function get_inactive_events($query_params, $count = false)
776
+	{
777
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
778
+		// let's add in specific query_params for inactive events.
779
+		if (isset($where_params['status'])) {
780
+			unset($where_params['status']);
781
+		}
782
+		// if we have count make sure we don't include group by
783
+		if ($count && isset($query_params['group_by'])) {
784
+			unset($query_params['group_by']);
785
+		}
786
+		// if we have any additional query_params, let's add them to the 'AND' condition
787
+		$where_params['AND']['status'] = array('!=', 'publish');
788
+		if (isset($where_params['OR'])) {
789
+			$where_params['AND']['OR'] = $where_params['OR'];
790
+			unset($where_params['OR']);
791
+		}
792
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
793
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
794
+			unset($where_params['Datetime.DTT_EVT_end']);
795
+		}
796
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
797
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
798
+			unset($where_params['Datetime.DTT_EVT_start']);
799
+		}
800
+		$query_params[0] = $where_params;
801
+		// don't use $query_params with count()
802
+		// because we don't want to include additional query clauses like "GROUP BY"
803
+		return $count
804
+			? $this->count(array($where_params), 'EVT_ID', true)
805
+			: $this->get_all($query_params);
806
+	}
807
+
808
+
809
+
810
+	/**
811
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
812
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
813
+	 * attached to the event. See parent for param descriptions
814
+	 *
815
+	 * @param        $id_or_obj
816
+	 * @param        $other_model_id_or_obj
817
+	 * @param string $relationName
818
+	 * @param array  $where_query
819
+	 * @return EE_Base_Class
820
+	 * @throws EE_Error
821
+	 */
822
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
823
+	{
824
+		if ($relationName === 'Price') {
825
+			// let's get the PRC object for the given ID to make sure that we aren't dealing with a default
826
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
827
+			// if EVT_ID = 0, then this is a default
828
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
829
+				// let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
830
+				$prc_chk->set('PRC_ID', 0);
831
+			}
832
+			// run parent
833
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
834
+		}
835
+		// otherwise carry on as normal
836
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
837
+	}
838
+
839
+
840
+
841
+	/******************** DEPRECATED METHODS ********************/
842
+
843
+
844
+
845
+	/**
846
+	 * _get_question_target_db_column
847
+	 *
848
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
849
+	 *             EE_Registration_Custom_Questions_Form located in
850
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
851
+	 * @access     public
852
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
853
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
854
+	 *                                         registration).
855
+	 * @throws EE_Error
856
+	 * @return    array
857
+	 */
858
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
859
+	{
860
+		if (empty($EVT_ID)) {
861
+			throw new EE_Error(esc_html__(
862
+				'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
863
+				'event_espresso'
864
+			));
865
+		}
866
+		$questions = array();
867
+		// get all question groups for event
868
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
869
+		if (! empty($qgs)) {
870
+			foreach ($qgs as $qg) {
871
+				$qsts = $qg->questions();
872
+				$questions[ $qg->ID() ] = $qg->model_field_array();
873
+				$questions[ $qg->ID() ]['QSG_questions'] = array();
874
+				foreach ($qsts as $qst) {
875
+					if ($qst->is_system_question()) {
876
+						continue;
877
+					}
878
+					$answer = EEM_Answer::instance()->get_one(array(
879
+						array(
880
+							'QST_ID' => $qst->ID(),
881
+							'REG_ID' => $registration->ID(),
882
+						),
883
+					));
884
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
885
+					$qst_name = $qstn_id = $qst->ID();
886
+					$ans_id = $answer->ID();
887
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
888
+					$input_name = '';
889
+					$input_id = sanitize_key($qst->display_text());
890
+					$input_class = '';
891
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
892
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
893
+																						   . $input_name
894
+																						   . $qst_name;
895
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
896
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
897
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
898
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
899
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
900
+					// leave responses as-is, don't convert stuff into html entities please!
901
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
902
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
903
+						$QSOs = $qst->options(true, $answer->value());
904
+						if (is_array($QSOs)) {
905
+							foreach ($QSOs as $QSO_ID => $QSO) {
906
+								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
907
+							}
908
+						}
909
+					}
910
+				}
911
+			}
912
+		}
913
+		return $questions;
914
+	}
915
+
916
+
917
+	/**
918
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
919
+	 *                             or an stdClass where each property is the name of a column,
920
+	 * @return EE_Base_Class
921
+	 * @throws \EE_Error
922
+	 */
923
+	public function instantiate_class_from_array_or_object($cols_n_values)
924
+	{
925
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
926
+		if ($classInstance instanceof EE_Event) {
927
+			// events have their timezone defined in the DB, so use it immediately
928
+			$this->set_timezone($classInstance->get_timezone());
929
+		}
930
+		return $classInstance;
931
+	}
932 932
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 2 patches
Indentation   +1573 added lines, -1573 removed lines patch added patch discarded remove patch
@@ -16,236 +16,236 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class EEH_Activation implements ResettableInterface
18 18
 {
19
-    /**
20
-     * constant used to indicate a cron task is no longer in use
21
-     */
22
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
23
-
24
-    /**
25
-     * WP_User->ID
26
-     *
27
-     * @var int
28
-     */
29
-    private static $_default_creator_id;
30
-
31
-    /**
32
-     * indicates whether or not we've already verified core's default data during this request,
33
-     * because after migrations are done, any addons activated while in maintenance mode
34
-     * will want to setup their own default data, and they might hook into core's default data
35
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
36
-     * This prevents doing that for EVERY single addon.
37
-     *
38
-     * @var boolean
39
-     */
40
-    protected static $_initialized_db_content_already_in_this_request = false;
41
-
42
-    /**
43
-     * @var TableAnalysis $table_analysis
44
-     */
45
-    private static $table_analysis;
46
-
47
-    /**
48
-     * @var TableManager $table_manager
49
-     */
50
-    private static $table_manager;
51
-
52
-
53
-    /**
54
-     * @return TableAnalysis
55
-     * @throws EE_Error
56
-     * @throws ReflectionException
57
-     */
58
-    public static function getTableAnalysis()
59
-    {
60
-        if (! self::$table_analysis instanceof TableAnalysis) {
61
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
62
-        }
63
-        return self::$table_analysis;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return TableManager
69
-     * @throws EE_Error
70
-     * @throws ReflectionException
71
-     */
72
-    public static function getTableManager()
73
-    {
74
-        if (! self::$table_manager instanceof TableManager) {
75
-            self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
76
-        }
77
-        return self::$table_manager;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param $table_name
83
-     * @return string
84
-     * @throws EE_Error
85
-     * @throws ReflectionException
86
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
-     */
88
-    public static function ensure_table_name_has_prefix($table_name)
89
-    {
90
-        return EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
91
-    }
92
-
93
-
94
-    /**
95
-     * ensures the EE configuration settings are loaded with at least default options set
96
-     * and that all critical EE pages have been generated with the appropriate shortcodes in place
97
-     *
98
-     * @return void
99
-     */
100
-    public static function system_initialization()
101
-    {
102
-        EEH_Activation::reset_and_update_config();
103
-        // which is fired BEFORE activation of plugin anyways
104
-        EEH_Activation::verify_default_pages_exist();
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets the database schema and creates folders. This should
110
-     * be called on plugin activation and reactivation
111
-     *
112
-     * @return boolean success, whether the database and folders are setup properly
113
-     * @throws EE_Error
114
-     * @throws ReflectionException
115
-     */
116
-    public static function initialize_db_and_folders()
117
-    {
118
-        return EEH_Activation::create_database_tables();
119
-    }
120
-
121
-
122
-    /**
123
-     * assuming we have an up-to-date database schema, this will populate it
124
-     * with default and initial data. This should be called
125
-     * upon activation of a new plugin, reactivation, and at the end
126
-     * of running migration scripts
127
-     *
128
-     * @throws EE_Error
129
-     * @throws ReflectionException
130
-     */
131
-    public static function initialize_db_content()
132
-    {
133
-        // let's avoid doing all this logic repeatedly, especially when addons are requesting it
134
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
135
-            return;
136
-        }
137
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
138
-
139
-        EEH_Activation::initialize_system_questions();
140
-        EEH_Activation::insert_default_status_codes();
141
-        EEH_Activation::generate_default_message_templates();
142
-        EEH_Activation::removeEmailConfirmFromAddressGroup();
143
-
144
-        EEH_Activation::validate_messages_system();
145
-        EEH_Activation::insert_default_payment_methods();
146
-        // in case we've
147
-        EEH_Activation::remove_cron_tasks();
148
-        EEH_Activation::create_cron_tasks();
149
-        // remove all TXN locks since that is being done via extra meta now
150
-        delete_option('ee_locked_transactions');
151
-        // also, check for CAF default db content
152
-        do_action('AHEE__EEH_Activation__initialize_db_content');
153
-        // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
154
-        // which users really won't care about on initial activation
155
-        EE_Error::overwrite_success();
156
-    }
157
-
158
-
159
-    /**
160
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
161
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
162
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
163
-     * (null)
164
-     *
165
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
166
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
167
-     * @return array
168
-     * @throws EE_Error
169
-     */
170
-    public static function get_cron_tasks($which_to_include)
171
-    {
172
-        $cron_tasks = apply_filters(
173
-            'FHEE__EEH_Activation__get_cron_tasks',
174
-            [
175
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
176
-                // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' =>
177
-                // EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
178
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
179
-                // there may have been a bug which prevented from these cron tasks from getting unscheduled,
180
-                // so we might want to remove these for a few updates
181
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
182
-            ]
183
-        );
184
-        if ($which_to_include === 'old') {
185
-            $cron_tasks = array_filter(
186
-                $cron_tasks,
187
-                function ($value) {
188
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
189
-                }
190
-            );
191
-        } elseif ($which_to_include === 'current') {
192
-            $cron_tasks = array_filter($cron_tasks);
193
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
194
-            throw new EE_Error(
195
-                sprintf(
196
-                    esc_html__(
197
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
198
-                        'event_espresso'
199
-                    ),
200
-                    $which_to_include
201
-                )
202
-            );
203
-        }
204
-        return $cron_tasks;
205
-    }
206
-
207
-
208
-    /**
209
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
210
-     *
211
-     * @throws EE_Error
212
-     */
213
-    public static function create_cron_tasks()
214
-    {
215
-
216
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
217
-            if (! wp_next_scheduled($hook_name)) {
218
-                /**
219
-                 * This allows client code to define the initial start timestamp for this schedule.
220
-                 */
221
-                if (
222
-                    is_array($frequency)
223
-                    && count($frequency) === 2
224
-                    && isset($frequency[0], $frequency[1])
225
-                ) {
226
-                    $start_timestamp = $frequency[0];
227
-                    $frequency       = $frequency[1];
228
-                } else {
229
-                    $start_timestamp = time();
230
-                }
231
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
232
-            }
233
-        }
234
-    }
235
-
236
-
237
-    /**
238
-     * Remove the currently-existing and now-removed cron tasks.
239
-     *
240
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
241
-     * @throws EE_Error
242
-     */
243
-    public static function remove_cron_tasks($remove_all = true)
244
-    {
245
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
246
-        $crons                = _get_cron_array();
247
-        $crons                = is_array($crons) ? $crons : [];
248
-        /* reminder of what $crons look like:
19
+	/**
20
+	 * constant used to indicate a cron task is no longer in use
21
+	 */
22
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
23
+
24
+	/**
25
+	 * WP_User->ID
26
+	 *
27
+	 * @var int
28
+	 */
29
+	private static $_default_creator_id;
30
+
31
+	/**
32
+	 * indicates whether or not we've already verified core's default data during this request,
33
+	 * because after migrations are done, any addons activated while in maintenance mode
34
+	 * will want to setup their own default data, and they might hook into core's default data
35
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
36
+	 * This prevents doing that for EVERY single addon.
37
+	 *
38
+	 * @var boolean
39
+	 */
40
+	protected static $_initialized_db_content_already_in_this_request = false;
41
+
42
+	/**
43
+	 * @var TableAnalysis $table_analysis
44
+	 */
45
+	private static $table_analysis;
46
+
47
+	/**
48
+	 * @var TableManager $table_manager
49
+	 */
50
+	private static $table_manager;
51
+
52
+
53
+	/**
54
+	 * @return TableAnalysis
55
+	 * @throws EE_Error
56
+	 * @throws ReflectionException
57
+	 */
58
+	public static function getTableAnalysis()
59
+	{
60
+		if (! self::$table_analysis instanceof TableAnalysis) {
61
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
62
+		}
63
+		return self::$table_analysis;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return TableManager
69
+	 * @throws EE_Error
70
+	 * @throws ReflectionException
71
+	 */
72
+	public static function getTableManager()
73
+	{
74
+		if (! self::$table_manager instanceof TableManager) {
75
+			self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
76
+		}
77
+		return self::$table_manager;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param $table_name
83
+	 * @return string
84
+	 * @throws EE_Error
85
+	 * @throws ReflectionException
86
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
+	 */
88
+	public static function ensure_table_name_has_prefix($table_name)
89
+	{
90
+		return EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
91
+	}
92
+
93
+
94
+	/**
95
+	 * ensures the EE configuration settings are loaded with at least default options set
96
+	 * and that all critical EE pages have been generated with the appropriate shortcodes in place
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public static function system_initialization()
101
+	{
102
+		EEH_Activation::reset_and_update_config();
103
+		// which is fired BEFORE activation of plugin anyways
104
+		EEH_Activation::verify_default_pages_exist();
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets the database schema and creates folders. This should
110
+	 * be called on plugin activation and reactivation
111
+	 *
112
+	 * @return boolean success, whether the database and folders are setup properly
113
+	 * @throws EE_Error
114
+	 * @throws ReflectionException
115
+	 */
116
+	public static function initialize_db_and_folders()
117
+	{
118
+		return EEH_Activation::create_database_tables();
119
+	}
120
+
121
+
122
+	/**
123
+	 * assuming we have an up-to-date database schema, this will populate it
124
+	 * with default and initial data. This should be called
125
+	 * upon activation of a new plugin, reactivation, and at the end
126
+	 * of running migration scripts
127
+	 *
128
+	 * @throws EE_Error
129
+	 * @throws ReflectionException
130
+	 */
131
+	public static function initialize_db_content()
132
+	{
133
+		// let's avoid doing all this logic repeatedly, especially when addons are requesting it
134
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
135
+			return;
136
+		}
137
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
138
+
139
+		EEH_Activation::initialize_system_questions();
140
+		EEH_Activation::insert_default_status_codes();
141
+		EEH_Activation::generate_default_message_templates();
142
+		EEH_Activation::removeEmailConfirmFromAddressGroup();
143
+
144
+		EEH_Activation::validate_messages_system();
145
+		EEH_Activation::insert_default_payment_methods();
146
+		// in case we've
147
+		EEH_Activation::remove_cron_tasks();
148
+		EEH_Activation::create_cron_tasks();
149
+		// remove all TXN locks since that is being done via extra meta now
150
+		delete_option('ee_locked_transactions');
151
+		// also, check for CAF default db content
152
+		do_action('AHEE__EEH_Activation__initialize_db_content');
153
+		// also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
154
+		// which users really won't care about on initial activation
155
+		EE_Error::overwrite_success();
156
+	}
157
+
158
+
159
+	/**
160
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
161
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
162
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
163
+	 * (null)
164
+	 *
165
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
166
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
167
+	 * @return array
168
+	 * @throws EE_Error
169
+	 */
170
+	public static function get_cron_tasks($which_to_include)
171
+	{
172
+		$cron_tasks = apply_filters(
173
+			'FHEE__EEH_Activation__get_cron_tasks',
174
+			[
175
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
176
+				// 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' =>
177
+				// EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
178
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
179
+				// there may have been a bug which prevented from these cron tasks from getting unscheduled,
180
+				// so we might want to remove these for a few updates
181
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
182
+			]
183
+		);
184
+		if ($which_to_include === 'old') {
185
+			$cron_tasks = array_filter(
186
+				$cron_tasks,
187
+				function ($value) {
188
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
189
+				}
190
+			);
191
+		} elseif ($which_to_include === 'current') {
192
+			$cron_tasks = array_filter($cron_tasks);
193
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
194
+			throw new EE_Error(
195
+				sprintf(
196
+					esc_html__(
197
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
198
+						'event_espresso'
199
+					),
200
+					$which_to_include
201
+				)
202
+			);
203
+		}
204
+		return $cron_tasks;
205
+	}
206
+
207
+
208
+	/**
209
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
210
+	 *
211
+	 * @throws EE_Error
212
+	 */
213
+	public static function create_cron_tasks()
214
+	{
215
+
216
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
217
+			if (! wp_next_scheduled($hook_name)) {
218
+				/**
219
+				 * This allows client code to define the initial start timestamp for this schedule.
220
+				 */
221
+				if (
222
+					is_array($frequency)
223
+					&& count($frequency) === 2
224
+					&& isset($frequency[0], $frequency[1])
225
+				) {
226
+					$start_timestamp = $frequency[0];
227
+					$frequency       = $frequency[1];
228
+				} else {
229
+					$start_timestamp = time();
230
+				}
231
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
232
+			}
233
+		}
234
+	}
235
+
236
+
237
+	/**
238
+	 * Remove the currently-existing and now-removed cron tasks.
239
+	 *
240
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
241
+	 * @throws EE_Error
242
+	 */
243
+	public static function remove_cron_tasks($remove_all = true)
244
+	{
245
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
246
+		$crons                = _get_cron_array();
247
+		$crons                = is_array($crons) ? $crons : [];
248
+		/* reminder of what $crons look like:
249 249
          * Top-level keys are timestamps, and their values are arrays.
250 250
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
251 251
          * and their values are arrays.
@@ -262,893 +262,893 @@  discard block
 block discarded – undo
262 262
          *                  ...
263 263
          *      ...
264 264
          */
265
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
266
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
267
-            if (is_array($hooks_to_fire_at_time)) {
268
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
269
-                    if (
270
-                        isset($ee_cron_tasks_to_remove[ $hook_name ])
271
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
272
-                    ) {
273
-                        unset($crons[ $timestamp ][ $hook_name ]);
274
-                    }
275
-                }
276
-                // also take care of any empty cron timestamps.
277
-                if (empty($hooks_to_fire_at_time)) {
278
-                    unset($crons[ $timestamp ]);
279
-                }
280
-            }
281
-        }
282
-        _set_cron_array($crons);
283
-    }
284
-
285
-
286
-    /**
287
-     * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
288
-     *
289
-     * @return void
290
-     * @throws EE_Error
291
-     * @throws ReflectionException
292
-     */
293
-    public static function CPT_initialization()
294
-    {
295
-        // register Custom Post Types
296
-        EE_Registry::instance()->load_core('Register_CPTs');
297
-        flush_rewrite_rules();
298
-    }
299
-
300
-
301
-    /**
302
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
303
-     * If there is old calendar config data saved, then it will get converted on activation.
304
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
305
-     *
306
-     * @return void
307
-     */
308
-    public static function reset_and_update_config()
309
-    {
310
-        do_action('AHEE__EE_Config___load_core_config__start', ['EEH_Activation', 'load_calendar_config']);
311
-        add_filter(
312
-            'FHEE__EE_Config___load_core_config__config_settings',
313
-            ['EEH_Activation', 'migrate_old_config_data'],
314
-            10,
315
-            3
316
-        );
317
-        if (! EE_Config::logging_enabled()) {
318
-            delete_option(EE_Config::LOG_NAME);
319
-        }
320
-    }
321
-
322
-
323
-    /**
324
-     * @return    void
325
-     */
326
-    public static function load_calendar_config()
327
-    {
328
-        // grab array of all plugin folders and loop thru it
329
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
330
-        if (empty($plugins)) {
331
-            return;
332
-        }
333
-        foreach ($plugins as $plugin_path) {
334
-            // grab plugin folder name from path
335
-            $plugin = basename($plugin_path);
336
-            // drill down to Espresso plugins
337
-            // then to calendar related plugins
338
-            if (
339
-                strpos($plugin, 'espresso') !== false
340
-                || strpos($plugin, 'Espresso') !== false
341
-                || strpos($plugin, 'ee4') !== false
342
-                || strpos($plugin, 'EE4') !== false
343
-                || strpos($plugin, 'calendar') !== false
344
-            ) {
345
-                // this is what we are looking for
346
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
347
-                // does it exist in this folder ?
348
-                if (is_readable($calendar_config)) {
349
-                    // YEAH! let's load it
350
-                    require_once($calendar_config);
351
-                }
352
-            }
353
-        }
354
-    }
355
-
356
-
357
-    /**
358
-     * @param array|stdClass $settings
359
-     * @param string         $config
360
-     * @param EE_Config      $EE_Config
361
-     * @return stdClass
362
-     */
363
-    public static function migrate_old_config_data($settings, $config, EE_Config $EE_Config)
364
-    {
365
-        $convert_from_array = ['addons'];
366
-        // in case old settings were saved as an array
367
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
368
-            // convert existing settings to an object
369
-            $config_array = $settings;
370
-            $settings     = new stdClass();
371
-            foreach ($config_array as $key => $value) {
372
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
373
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
374
-                } else {
375
-                    $settings->{$key} = $value;
376
-                }
377
-            }
378
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
379
-        }
380
-        return $settings;
381
-    }
382
-
383
-
384
-    /**
385
-     * @return void
386
-     */
387
-    public static function deactivate_event_espresso()
388
-    {
389
-        // check permissions
390
-        if (current_user_can('activate_plugins')) {
391
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
392
-        }
393
-    }
394
-
395
-
396
-    /**
397
-     * @return void
398
-     * @throws InvalidDataTypeException
399
-     */
400
-    public static function verify_default_pages_exist()
401
-    {
402
-        $critical_page_problem = false;
403
-        $critical_pages        = [
404
-            [
405
-                'id'   => 'reg_page_id',
406
-                'name' => esc_html__('Registration Checkout', 'event_espresso'),
407
-                'post' => null,
408
-                'code' => 'ESPRESSO_CHECKOUT',
409
-            ],
410
-            [
411
-                'id'   => 'txn_page_id',
412
-                'name' => esc_html__('Transactions', 'event_espresso'),
413
-                'post' => null,
414
-                'code' => 'ESPRESSO_TXN_PAGE',
415
-            ],
416
-            [
417
-                'id'   => 'thank_you_page_id',
418
-                'name' => esc_html__('Thank You', 'event_espresso'),
419
-                'post' => null,
420
-                'code' => 'ESPRESSO_THANK_YOU',
421
-            ],
422
-            [
423
-                'id'   => 'cancel_page_id',
424
-                'name' => esc_html__('Registration Cancelled', 'event_espresso'),
425
-                'post' => null,
426
-                'code' => 'ESPRESSO_CANCELLED',
427
-            ],
428
-        ];
429
-        $EE_Core_Config        = EE_Registry::instance()->CFG->core;
430
-        foreach ($critical_pages as $critical_page) {
431
-            // is critical page ID set in config ?
432
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
433
-                // attempt to find post by ID
434
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
435
-            }
436
-            // no dice?
437
-            if ($critical_page['post'] === null) {
438
-                // attempt to find post by title
439
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
440
-                // still nothing?
441
-                if ($critical_page['post'] === null) {
442
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
443
-                    // REALLY? Still nothing ??!?!?
444
-                    if ($critical_page['post'] === null) {
445
-                        $msg = esc_html__(
446
-                            'The Event Espresso critical page configuration settings could not be updated.',
447
-                            'event_espresso'
448
-                        );
449
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
450
-                        break;
451
-                    }
452
-                }
453
-            }
454
-            // check that Post ID matches critical page ID in config
455
-            if (
456
-                isset($critical_page['post']->ID)
457
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
458
-            ) {
459
-                // update Config with post ID
460
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
461
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
462
-                    $msg = esc_html__(
463
-                        'The Event Espresso critical page configuration settings could not be updated.',
464
-                        'event_espresso'
465
-                    );
466
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
467
-                }
468
-            }
469
-            $critical_page_problem =
470
-                ! isset($critical_page['post']->post_status)
471
-                || $critical_page['post']->post_status !== 'publish'
472
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
473
-                    ? true
474
-                    : $critical_page_problem;
475
-        }
476
-        if ($critical_page_problem) {
477
-            new PersistentAdminNotice(
478
-                'critical_page_problem',
479
-                sprintf(
480
-                    esc_html__(
481
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
482
-                        'event_espresso'
483
-                    ),
484
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
485
-                    . esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
486
-                    . '</a>'
487
-                )
488
-            );
489
-        }
490
-        if (EE_Error::has_notices()) {
491
-            EE_Error::get_notices(false, true);
492
-        }
493
-    }
494
-
495
-
496
-    /**
497
-     * Returns the first post which uses the specified shortcode
498
-     *
499
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
500
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
501
-     *                             "[ESPRESSO_THANK_YOU"
502
-     *                             (we don't search for the closing shortcode bracket because they might have added
503
-     *                             parameter to the shortcode
504
-     * @return WP_Post or NULl
505
-     */
506
-    public static function get_page_by_ee_shortcode($ee_shortcode)
507
-    {
508
-        global $wpdb;
509
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
510
-        $post_id                       =
511
-            $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
512
-        if ($post_id) {
513
-            return get_post($post_id);
514
-        } else {
515
-            return null;
516
-        }
517
-    }
518
-
519
-
520
-    /**
521
-     * This function generates a post for critical espresso pages
522
-     *
523
-     * @param array $critical_page
524
-     * @return array
525
-     */
526
-    public static function create_critical_page($critical_page)
527
-    {
528
-
529
-        $post_args = [
530
-            'post_title'     => $critical_page['name'],
531
-            'post_status'    => 'publish',
532
-            'post_type'      => 'page',
533
-            'comment_status' => 'closed',
534
-            'post_content'   => '[' . $critical_page['code'] . ']',
535
-        ];
536
-
537
-        $post_id = wp_insert_post($post_args);
538
-        if (! $post_id) {
539
-            $msg = sprintf(
540
-                esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
541
-                $critical_page['name']
542
-            );
543
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
544
-            return $critical_page;
545
-        }
546
-        // get newly created post's details
547
-        if (! $critical_page['post'] = get_post($post_id)) {
548
-            $msg = sprintf(
549
-                esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
550
-                $critical_page['name']
551
-            );
552
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
553
-        }
554
-
555
-        return $critical_page;
556
-    }
557
-
558
-
559
-    /**
560
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
561
-     * The role being used to check is filterable.
562
-     *
563
-     * @return int|null WP_user ID or NULL
564
-     * @throws EE_Error
565
-     * @throws ReflectionException
566
-     * @since  4.6.0
567
-     * @global WPDB $wpdb
568
-     */
569
-    public static function get_default_creator_id()
570
-    {
571
-        global $wpdb;
572
-        if (! empty(self::$_default_creator_id)) {
573
-            return self::$_default_creator_id;
574
-        }/**/
575
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
576
-        // let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
577
-        $pre_filtered_id = apply_filters(
578
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
579
-            false,
580
-            $role_to_check
581
-        );
582
-        if ($pre_filtered_id !== false) {
583
-            return (int) $pre_filtered_id;
584
-        }
585
-        $capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
586
-        $query            = $wpdb->prepare(
587
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
588
-            '%' . $role_to_check . '%'
589
-        );
590
-        $user_id          = $wpdb->get_var($query);
591
-        $user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
592
-        if ($user_id && (int) $user_id) {
593
-            self::$_default_creator_id = (int) $user_id;
594
-            return self::$_default_creator_id;
595
-        } else {
596
-            return null;
597
-        }
598
-    }
599
-
600
-
601
-    /**
602
-     * used by EE and EE addons during plugin activation to create tables.
603
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
604
-     * but includes extra logic regarding activations.
605
-     *
606
-     * @param string  $table_name              without the $wpdb->prefix
607
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
608
-     *                                         table query)
609
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
610
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
611
-     *                                         and new once this function is done (ie, you really do want to CREATE a
612
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
613
-     *                                         you just want to verify the table exists and matches this definition
614
-     *                                         (and if it HAS data in it you want to leave it be)
615
-     * @return void
616
-     * @throws EE_Error if there are database errors
617
-     * @throws ReflectionException
618
-     */
619
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
620
-    {
621
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
622
-            return;
623
-        }
624
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
625
-        if (! function_exists('dbDelta')) {
626
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
627
-        }
628
-        $tableAnalysis = EEH_Activation::getTableAnalysis();
629
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
630
-        // do we need to first delete an existing version of this table ?
631
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
632
-            // ok, delete the table... but ONLY if it's empty
633
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
634
-            // table is NOT empty, are you SURE you want to delete this table ???
635
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
636
-                EEH_Activation::getTableManager()->dropTable($wp_table_name);
637
-            } elseif (! $deleted_safely) {
638
-                // so we should be more cautious rather than just dropping tables so easily
639
-                error_log(
640
-                    sprintf(
641
-                        esc_html__(
642
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
643
-                            'event_espresso'
644
-                        ),
645
-                        $wp_table_name,
646
-                        '<br/>',
647
-                        'espresso_db_update'
648
-                    )
649
-                );
650
-            }
651
-        }
652
-        $engine = str_replace('ENGINE=', '', $engine);
653
-        EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
654
-    }
655
-
656
-
657
-    /**
658
-     * Checks if this column already exists on the specified table. Handy for addons which want to add a column
659
-     *
660
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
661
-     * @param string $column_name
662
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
663
-     *                            'VARCHAR(10)'
664
-     * @return bool|int
665
-     * @throws EE_Error
666
-     * @throws ReflectionException
667
-     * @deprecated instead use TableManager::addColumn()
668
-     */
669
-    public static function add_column_if_it_doesnt_exist(
670
-        $table_name,
671
-        $column_name,
672
-        $column_info = 'INT UNSIGNED NOT NULL'
673
-    ) {
674
-        return EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
675
-    }
676
-
677
-
678
-    /**
679
-     * Gets all the fields on the database table.
680
-     *
681
-     * @param string $table_name , without prefixed $wpdb->prefix
682
-     * @return array of database column names
683
-     * @throws EE_Error
684
-     * @throws ReflectionException
685
-     * @deprecated instead use TableManager::getTableColumns()
686
-     */
687
-    public static function get_fields_on_table($table_name = null)
688
-    {
689
-        return EEH_Activation::getTableManager()->getTableColumns($table_name);
690
-    }
691
-
692
-
693
-    /**
694
-     * @param string $table_name
695
-     * @return bool
696
-     * @throws EE_Error
697
-     * @throws ReflectionException
698
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
699
-     */
700
-    public static function db_table_is_empty($table_name)
701
-    {
702
-        return EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
703
-    }
704
-
705
-
706
-    /**
707
-     * @param string $table_name
708
-     * @return bool | int
709
-     * @throws EE_Error
710
-     * @throws ReflectionException
711
-     */
712
-    public static function delete_db_table_if_empty($table_name)
713
-    {
714
-        if (EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
715
-            return EEH_Activation::getTableManager()->dropTable($table_name);
716
-        }
717
-        return false;
718
-    }
719
-
720
-
721
-    /**
722
-     * @param string $table_name
723
-     * @return int
724
-     * @throws EE_Error
725
-     * @throws ReflectionException
726
-     * @deprecated instead use TableManager::dropTable()
727
-     */
728
-    public static function delete_unused_db_table($table_name)
729
-    {
730
-        return EEH_Activation::getTableManager()->dropTable($table_name);
731
-    }
732
-
733
-
734
-    /**
735
-     * @param string $table_name
736
-     * @param string $index_name
737
-     * @return int
738
-     * @throws EE_Error
739
-     * @throws ReflectionException
740
-     * @deprecated instead use TableManager::dropIndex()
741
-     */
742
-    public static function drop_index($table_name, $index_name)
743
-    {
744
-        return EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
745
-    }
746
-
747
-
748
-    /**
749
-     * @return boolean success (whether database is setup properly or not)
750
-     * @throws EE_Error
751
-     * @throws ReflectionException
752
-     */
753
-    public static function create_database_tables()
754
-    {
755
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
756
-        // find the migration script that sets the database to be compatible with the code
757
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
758
-        if (! $dms_name) {
759
-            EE_Error::add_error(
760
-                esc_html__(
761
-                    'Could not determine most up-to-date data migration script from which to pull database schema
265
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
266
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
267
+			if (is_array($hooks_to_fire_at_time)) {
268
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
269
+					if (
270
+						isset($ee_cron_tasks_to_remove[ $hook_name ])
271
+						&& is_array($ee_cron_tasks_to_remove[ $hook_name ])
272
+					) {
273
+						unset($crons[ $timestamp ][ $hook_name ]);
274
+					}
275
+				}
276
+				// also take care of any empty cron timestamps.
277
+				if (empty($hooks_to_fire_at_time)) {
278
+					unset($crons[ $timestamp ]);
279
+				}
280
+			}
281
+		}
282
+		_set_cron_array($crons);
283
+	}
284
+
285
+
286
+	/**
287
+	 * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
288
+	 *
289
+	 * @return void
290
+	 * @throws EE_Error
291
+	 * @throws ReflectionException
292
+	 */
293
+	public static function CPT_initialization()
294
+	{
295
+		// register Custom Post Types
296
+		EE_Registry::instance()->load_core('Register_CPTs');
297
+		flush_rewrite_rules();
298
+	}
299
+
300
+
301
+	/**
302
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
303
+	 * If there is old calendar config data saved, then it will get converted on activation.
304
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
305
+	 *
306
+	 * @return void
307
+	 */
308
+	public static function reset_and_update_config()
309
+	{
310
+		do_action('AHEE__EE_Config___load_core_config__start', ['EEH_Activation', 'load_calendar_config']);
311
+		add_filter(
312
+			'FHEE__EE_Config___load_core_config__config_settings',
313
+			['EEH_Activation', 'migrate_old_config_data'],
314
+			10,
315
+			3
316
+		);
317
+		if (! EE_Config::logging_enabled()) {
318
+			delete_option(EE_Config::LOG_NAME);
319
+		}
320
+	}
321
+
322
+
323
+	/**
324
+	 * @return    void
325
+	 */
326
+	public static function load_calendar_config()
327
+	{
328
+		// grab array of all plugin folders and loop thru it
329
+		$plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
330
+		if (empty($plugins)) {
331
+			return;
332
+		}
333
+		foreach ($plugins as $plugin_path) {
334
+			// grab plugin folder name from path
335
+			$plugin = basename($plugin_path);
336
+			// drill down to Espresso plugins
337
+			// then to calendar related plugins
338
+			if (
339
+				strpos($plugin, 'espresso') !== false
340
+				|| strpos($plugin, 'Espresso') !== false
341
+				|| strpos($plugin, 'ee4') !== false
342
+				|| strpos($plugin, 'EE4') !== false
343
+				|| strpos($plugin, 'calendar') !== false
344
+			) {
345
+				// this is what we are looking for
346
+				$calendar_config = $plugin_path . '/EE_Calendar_Config.php';
347
+				// does it exist in this folder ?
348
+				if (is_readable($calendar_config)) {
349
+					// YEAH! let's load it
350
+					require_once($calendar_config);
351
+				}
352
+			}
353
+		}
354
+	}
355
+
356
+
357
+	/**
358
+	 * @param array|stdClass $settings
359
+	 * @param string         $config
360
+	 * @param EE_Config      $EE_Config
361
+	 * @return stdClass
362
+	 */
363
+	public static function migrate_old_config_data($settings, $config, EE_Config $EE_Config)
364
+	{
365
+		$convert_from_array = ['addons'];
366
+		// in case old settings were saved as an array
367
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
368
+			// convert existing settings to an object
369
+			$config_array = $settings;
370
+			$settings     = new stdClass();
371
+			foreach ($config_array as $key => $value) {
372
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
373
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
374
+				} else {
375
+					$settings->{$key} = $value;
376
+				}
377
+			}
378
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
379
+		}
380
+		return $settings;
381
+	}
382
+
383
+
384
+	/**
385
+	 * @return void
386
+	 */
387
+	public static function deactivate_event_espresso()
388
+	{
389
+		// check permissions
390
+		if (current_user_can('activate_plugins')) {
391
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
392
+		}
393
+	}
394
+
395
+
396
+	/**
397
+	 * @return void
398
+	 * @throws InvalidDataTypeException
399
+	 */
400
+	public static function verify_default_pages_exist()
401
+	{
402
+		$critical_page_problem = false;
403
+		$critical_pages        = [
404
+			[
405
+				'id'   => 'reg_page_id',
406
+				'name' => esc_html__('Registration Checkout', 'event_espresso'),
407
+				'post' => null,
408
+				'code' => 'ESPRESSO_CHECKOUT',
409
+			],
410
+			[
411
+				'id'   => 'txn_page_id',
412
+				'name' => esc_html__('Transactions', 'event_espresso'),
413
+				'post' => null,
414
+				'code' => 'ESPRESSO_TXN_PAGE',
415
+			],
416
+			[
417
+				'id'   => 'thank_you_page_id',
418
+				'name' => esc_html__('Thank You', 'event_espresso'),
419
+				'post' => null,
420
+				'code' => 'ESPRESSO_THANK_YOU',
421
+			],
422
+			[
423
+				'id'   => 'cancel_page_id',
424
+				'name' => esc_html__('Registration Cancelled', 'event_espresso'),
425
+				'post' => null,
426
+				'code' => 'ESPRESSO_CANCELLED',
427
+			],
428
+		];
429
+		$EE_Core_Config        = EE_Registry::instance()->CFG->core;
430
+		foreach ($critical_pages as $critical_page) {
431
+			// is critical page ID set in config ?
432
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
433
+				// attempt to find post by ID
434
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
435
+			}
436
+			// no dice?
437
+			if ($critical_page['post'] === null) {
438
+				// attempt to find post by title
439
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
440
+				// still nothing?
441
+				if ($critical_page['post'] === null) {
442
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
443
+					// REALLY? Still nothing ??!?!?
444
+					if ($critical_page['post'] === null) {
445
+						$msg = esc_html__(
446
+							'The Event Espresso critical page configuration settings could not be updated.',
447
+							'event_espresso'
448
+						);
449
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
450
+						break;
451
+					}
452
+				}
453
+			}
454
+			// check that Post ID matches critical page ID in config
455
+			if (
456
+				isset($critical_page['post']->ID)
457
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
458
+			) {
459
+				// update Config with post ID
460
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
461
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
462
+					$msg = esc_html__(
463
+						'The Event Espresso critical page configuration settings could not be updated.',
464
+						'event_espresso'
465
+					);
466
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
467
+				}
468
+			}
469
+			$critical_page_problem =
470
+				! isset($critical_page['post']->post_status)
471
+				|| $critical_page['post']->post_status !== 'publish'
472
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
473
+					? true
474
+					: $critical_page_problem;
475
+		}
476
+		if ($critical_page_problem) {
477
+			new PersistentAdminNotice(
478
+				'critical_page_problem',
479
+				sprintf(
480
+					esc_html__(
481
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
482
+						'event_espresso'
483
+					),
484
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
485
+					. esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
486
+					. '</a>'
487
+				)
488
+			);
489
+		}
490
+		if (EE_Error::has_notices()) {
491
+			EE_Error::get_notices(false, true);
492
+		}
493
+	}
494
+
495
+
496
+	/**
497
+	 * Returns the first post which uses the specified shortcode
498
+	 *
499
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
500
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
501
+	 *                             "[ESPRESSO_THANK_YOU"
502
+	 *                             (we don't search for the closing shortcode bracket because they might have added
503
+	 *                             parameter to the shortcode
504
+	 * @return WP_Post or NULl
505
+	 */
506
+	public static function get_page_by_ee_shortcode($ee_shortcode)
507
+	{
508
+		global $wpdb;
509
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
510
+		$post_id                       =
511
+			$wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
512
+		if ($post_id) {
513
+			return get_post($post_id);
514
+		} else {
515
+			return null;
516
+		}
517
+	}
518
+
519
+
520
+	/**
521
+	 * This function generates a post for critical espresso pages
522
+	 *
523
+	 * @param array $critical_page
524
+	 * @return array
525
+	 */
526
+	public static function create_critical_page($critical_page)
527
+	{
528
+
529
+		$post_args = [
530
+			'post_title'     => $critical_page['name'],
531
+			'post_status'    => 'publish',
532
+			'post_type'      => 'page',
533
+			'comment_status' => 'closed',
534
+			'post_content'   => '[' . $critical_page['code'] . ']',
535
+		];
536
+
537
+		$post_id = wp_insert_post($post_args);
538
+		if (! $post_id) {
539
+			$msg = sprintf(
540
+				esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
541
+				$critical_page['name']
542
+			);
543
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
544
+			return $critical_page;
545
+		}
546
+		// get newly created post's details
547
+		if (! $critical_page['post'] = get_post($post_id)) {
548
+			$msg = sprintf(
549
+				esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
550
+				$critical_page['name']
551
+			);
552
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
553
+		}
554
+
555
+		return $critical_page;
556
+	}
557
+
558
+
559
+	/**
560
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
561
+	 * The role being used to check is filterable.
562
+	 *
563
+	 * @return int|null WP_user ID or NULL
564
+	 * @throws EE_Error
565
+	 * @throws ReflectionException
566
+	 * @since  4.6.0
567
+	 * @global WPDB $wpdb
568
+	 */
569
+	public static function get_default_creator_id()
570
+	{
571
+		global $wpdb;
572
+		if (! empty(self::$_default_creator_id)) {
573
+			return self::$_default_creator_id;
574
+		}/**/
575
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
576
+		// let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
577
+		$pre_filtered_id = apply_filters(
578
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
579
+			false,
580
+			$role_to_check
581
+		);
582
+		if ($pre_filtered_id !== false) {
583
+			return (int) $pre_filtered_id;
584
+		}
585
+		$capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
586
+		$query            = $wpdb->prepare(
587
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
588
+			'%' . $role_to_check . '%'
589
+		);
590
+		$user_id          = $wpdb->get_var($query);
591
+		$user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
592
+		if ($user_id && (int) $user_id) {
593
+			self::$_default_creator_id = (int) $user_id;
594
+			return self::$_default_creator_id;
595
+		} else {
596
+			return null;
597
+		}
598
+	}
599
+
600
+
601
+	/**
602
+	 * used by EE and EE addons during plugin activation to create tables.
603
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
604
+	 * but includes extra logic regarding activations.
605
+	 *
606
+	 * @param string  $table_name              without the $wpdb->prefix
607
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
608
+	 *                                         table query)
609
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
610
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
611
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
612
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
613
+	 *                                         you just want to verify the table exists and matches this definition
614
+	 *                                         (and if it HAS data in it you want to leave it be)
615
+	 * @return void
616
+	 * @throws EE_Error if there are database errors
617
+	 * @throws ReflectionException
618
+	 */
619
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
620
+	{
621
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
622
+			return;
623
+		}
624
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
625
+		if (! function_exists('dbDelta')) {
626
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
627
+		}
628
+		$tableAnalysis = EEH_Activation::getTableAnalysis();
629
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
630
+		// do we need to first delete an existing version of this table ?
631
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
632
+			// ok, delete the table... but ONLY if it's empty
633
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
634
+			// table is NOT empty, are you SURE you want to delete this table ???
635
+			if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
636
+				EEH_Activation::getTableManager()->dropTable($wp_table_name);
637
+			} elseif (! $deleted_safely) {
638
+				// so we should be more cautious rather than just dropping tables so easily
639
+				error_log(
640
+					sprintf(
641
+						esc_html__(
642
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
643
+							'event_espresso'
644
+						),
645
+						$wp_table_name,
646
+						'<br/>',
647
+						'espresso_db_update'
648
+					)
649
+				);
650
+			}
651
+		}
652
+		$engine = str_replace('ENGINE=', '', $engine);
653
+		EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
654
+	}
655
+
656
+
657
+	/**
658
+	 * Checks if this column already exists on the specified table. Handy for addons which want to add a column
659
+	 *
660
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
661
+	 * @param string $column_name
662
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
663
+	 *                            'VARCHAR(10)'
664
+	 * @return bool|int
665
+	 * @throws EE_Error
666
+	 * @throws ReflectionException
667
+	 * @deprecated instead use TableManager::addColumn()
668
+	 */
669
+	public static function add_column_if_it_doesnt_exist(
670
+		$table_name,
671
+		$column_name,
672
+		$column_info = 'INT UNSIGNED NOT NULL'
673
+	) {
674
+		return EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
675
+	}
676
+
677
+
678
+	/**
679
+	 * Gets all the fields on the database table.
680
+	 *
681
+	 * @param string $table_name , without prefixed $wpdb->prefix
682
+	 * @return array of database column names
683
+	 * @throws EE_Error
684
+	 * @throws ReflectionException
685
+	 * @deprecated instead use TableManager::getTableColumns()
686
+	 */
687
+	public static function get_fields_on_table($table_name = null)
688
+	{
689
+		return EEH_Activation::getTableManager()->getTableColumns($table_name);
690
+	}
691
+
692
+
693
+	/**
694
+	 * @param string $table_name
695
+	 * @return bool
696
+	 * @throws EE_Error
697
+	 * @throws ReflectionException
698
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
699
+	 */
700
+	public static function db_table_is_empty($table_name)
701
+	{
702
+		return EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
703
+	}
704
+
705
+
706
+	/**
707
+	 * @param string $table_name
708
+	 * @return bool | int
709
+	 * @throws EE_Error
710
+	 * @throws ReflectionException
711
+	 */
712
+	public static function delete_db_table_if_empty($table_name)
713
+	{
714
+		if (EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
715
+			return EEH_Activation::getTableManager()->dropTable($table_name);
716
+		}
717
+		return false;
718
+	}
719
+
720
+
721
+	/**
722
+	 * @param string $table_name
723
+	 * @return int
724
+	 * @throws EE_Error
725
+	 * @throws ReflectionException
726
+	 * @deprecated instead use TableManager::dropTable()
727
+	 */
728
+	public static function delete_unused_db_table($table_name)
729
+	{
730
+		return EEH_Activation::getTableManager()->dropTable($table_name);
731
+	}
732
+
733
+
734
+	/**
735
+	 * @param string $table_name
736
+	 * @param string $index_name
737
+	 * @return int
738
+	 * @throws EE_Error
739
+	 * @throws ReflectionException
740
+	 * @deprecated instead use TableManager::dropIndex()
741
+	 */
742
+	public static function drop_index($table_name, $index_name)
743
+	{
744
+		return EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
745
+	}
746
+
747
+
748
+	/**
749
+	 * @return boolean success (whether database is setup properly or not)
750
+	 * @throws EE_Error
751
+	 * @throws ReflectionException
752
+	 */
753
+	public static function create_database_tables()
754
+	{
755
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
756
+		// find the migration script that sets the database to be compatible with the code
757
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
758
+		if (! $dms_name) {
759
+			EE_Error::add_error(
760
+				esc_html__(
761
+					'Could not determine most up-to-date data migration script from which to pull database schema
762 762
                      structure. So database is probably not setup properly',
763
-                    'event_espresso'
764
-                ),
765
-                __FILE__,
766
-                __FUNCTION__,
767
-                __LINE__
768
-            );
769
-            return false;
770
-        }
771
-        $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
772
-        $current_data_migration_script->set_migrating(false);
773
-        $current_data_migration_script->schema_changes_before_migration();
774
-        $current_data_migration_script->schema_changes_after_migration();
775
-        if ($current_data_migration_script->get_errors()) {
776
-            if (WP_DEBUG) {
777
-                foreach ($current_data_migration_script->get_errors() as $error) {
778
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
779
-                }
780
-            } else {
781
-                EE_Error::add_error(
782
-                    esc_html__(
783
-                        'There were errors creating the Event Espresso database tables and Event Espresso has been 
763
+					'event_espresso'
764
+				),
765
+				__FILE__,
766
+				__FUNCTION__,
767
+				__LINE__
768
+			);
769
+			return false;
770
+		}
771
+		$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
772
+		$current_data_migration_script->set_migrating(false);
773
+		$current_data_migration_script->schema_changes_before_migration();
774
+		$current_data_migration_script->schema_changes_after_migration();
775
+		if ($current_data_migration_script->get_errors()) {
776
+			if (WP_DEBUG) {
777
+				foreach ($current_data_migration_script->get_errors() as $error) {
778
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
779
+				}
780
+			} else {
781
+				EE_Error::add_error(
782
+					esc_html__(
783
+						'There were errors creating the Event Espresso database tables and Event Espresso has been 
784 784
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
785
-                        'event_espresso'
786
-                    )
787
-                );
788
-            }
789
-            return false;
790
-        }
791
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to();
792
-        return true;
793
-    }
794
-
795
-
796
-    /**
797
-     * @return void
798
-     * @throws EE_Error
799
-     * @throws ReflectionException
800
-     */
801
-    public static function initialize_system_questions()
802
-    {
803
-        // QUESTION GROUPS
804
-        global $wpdb;
805
-        $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
806
-        $SQL        = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
807
-        // what we have
808
-        $question_groups = $wpdb->get_col($SQL);
809
-        // check the response
810
-        $question_groups = is_array($question_groups) ? $question_groups : [];
811
-        // what we should have
812
-        $QSG_systems = [1, 2];
813
-        // loop thru what we should have and compare to what we have
814
-        foreach ($QSG_systems as $QSG_system) {
815
-            // reset values array
816
-            $QSG_values = [];
817
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
818
-            if (! in_array("$QSG_system", $question_groups)) {
819
-                // add it
820
-                switch ($QSG_system) {
821
-                    case 1:
822
-                        $QSG_values = [
823
-                            'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
824
-                            'QSG_identifier'      => 'personal-information-' . time(),
825
-                            'QSG_desc'            => '',
826
-                            'QSG_order'           => 1,
827
-                            'QSG_show_group_name' => 1,
828
-                            'QSG_show_group_desc' => 1,
829
-                            'QSG_system'          => EEM_Question_Group::system_personal,
830
-                            'QSG_deleted'         => 0,
831
-                        ];
832
-                        break;
833
-                    case 2:
834
-                        $QSG_values = [
835
-                            'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
836
-                            'QSG_identifier'      => 'address-information-' . time(),
837
-                            'QSG_desc'            => '',
838
-                            'QSG_order'           => 2,
839
-                            'QSG_show_group_name' => 1,
840
-                            'QSG_show_group_desc' => 1,
841
-                            'QSG_system'          => EEM_Question_Group::system_address,
842
-                            'QSG_deleted'         => 0,
843
-                        ];
844
-                        break;
845
-                }
846
-                // make sure we have some values before inserting them
847
-                if (! empty($QSG_values)) {
848
-                    // insert system question
849
-                    $wpdb->insert(
850
-                        $table_name,
851
-                        $QSG_values,
852
-                        ['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
853
-                    );
854
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
855
-                }
856
-            }
857
-        }
858
-        // QUESTIONS
859
-        global $wpdb;
860
-        $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
861
-        $SQL        = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
862
-        // what we have
863
-        $questions = $wpdb->get_col($SQL);
864
-        // all system questions
865
-        $personal_system_group_questions = ['fname', 'lname', 'email'];
866
-        $address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
867
-        $system_questions_not_in_group   = ['email_confirm'];
868
-        // merge all of the system questions we should have
869
-        $QST_systems       = array_merge(
870
-            $personal_system_group_questions,
871
-            $address_system_group_questions,
872
-            $system_questions_not_in_group
873
-        );
874
-        $order_for_group_1 = 1;
875
-        $order_for_group_2 = 1;
876
-        // loop thru what we should have and compare to what we have
877
-        foreach ($QST_systems as $QST_system) {
878
-            // reset values array
879
-            $QST_values = [];
880
-            // if we don't have what we should have
881
-            if (! in_array($QST_system, $questions)) {
882
-                // add it
883
-                switch ($QST_system) {
884
-                    case 'fname':
885
-                        $QST_values = [
886
-                            'QST_display_text'  => esc_html__('First Name', 'event_espresso'),
887
-                            'QST_admin_label'   => esc_html__('First Name - System Question', 'event_espresso'),
888
-                            'QST_system'        => 'fname',
889
-                            'QST_type'          => 'TEXT',
890
-                            'QST_required'      => 1,
891
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
892
-                            'QST_order'         => 1,
893
-                            'QST_admin_only'    => 0,
894
-                            'QST_max'           => EEM_Question::instance()
895
-                                                               ->absolute_max_for_system_question($QST_system),
896
-                            'QST_wp_user'       => self::get_default_creator_id(),
897
-                            'QST_deleted'       => 0,
898
-                        ];
899
-                        break;
900
-                    case 'lname':
901
-                        $QST_values = [
902
-                            'QST_display_text'  => esc_html__('Last Name', 'event_espresso'),
903
-                            'QST_admin_label'   => esc_html__('Last Name - System Question', 'event_espresso'),
904
-                            'QST_system'        => 'lname',
905
-                            'QST_type'          => 'TEXT',
906
-                            'QST_required'      => 1,
907
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
908
-                            'QST_order'         => 2,
909
-                            'QST_admin_only'    => 0,
910
-                            'QST_max'           => EEM_Question::instance()
911
-                                                               ->absolute_max_for_system_question($QST_system),
912
-                            'QST_wp_user'       => self::get_default_creator_id(),
913
-                            'QST_deleted'       => 0,
914
-                        ];
915
-                        break;
916
-                    case 'email':
917
-                        $QST_values = [
918
-                            'QST_display_text'  => esc_html__('Email Address', 'event_espresso'),
919
-                            'QST_admin_label'   => esc_html__('Email Address - System Question', 'event_espresso'),
920
-                            'QST_system'        => 'email',
921
-                            'QST_type'          => 'EMAIL',
922
-                            'QST_required'      => 1,
923
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
924
-                            'QST_order'         => 3,
925
-                            'QST_admin_only'    => 0,
926
-                            'QST_max'           => EEM_Question::instance()
927
-                                                               ->absolute_max_for_system_question($QST_system),
928
-                            'QST_wp_user'       => self::get_default_creator_id(),
929
-                            'QST_deleted'       => 0,
930
-                        ];
931
-                        break;
932
-                    case 'email_confirm':
933
-                        $QST_values = [
934
-                            'QST_display_text'  => esc_html__('Confirm Email Address', 'event_espresso'),
935
-                            'QST_admin_label'   => esc_html__('Confirm Email Address - System Question', 'event_espresso'),
936
-                            'QST_system'        => 'email_confirm',
937
-                            'QST_type'          => 'EMAIL_CONFIRM',
938
-                            'QST_required'      => 1,
939
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
940
-                            'QST_order'         => 4,
941
-                            'QST_admin_only'    => 0,
942
-                            'QST_max'           => EEM_Question::instance()
943
-                                                               ->absolute_max_for_system_question($QST_system),
944
-                            'QST_wp_user'       => self::get_default_creator_id(),
945
-                            'QST_deleted'       => 0,
946
-                        ];
947
-                        break;
948
-                    case 'address':
949
-                        $QST_values = [
950
-                            'QST_display_text'  => esc_html__('Address', 'event_espresso'),
951
-                            'QST_admin_label'   => esc_html__('Address - System Question', 'event_espresso'),
952
-                            'QST_system'        => 'address',
953
-                            'QST_type'          => 'TEXT',
954
-                            'QST_required'      => 0,
955
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
956
-                            'QST_order'         => 5,
957
-                            'QST_admin_only'    => 0,
958
-                            'QST_max'           => EEM_Question::instance()
959
-                                                               ->absolute_max_for_system_question($QST_system),
960
-                            'QST_wp_user'       => self::get_default_creator_id(),
961
-                            'QST_deleted'       => 0,
962
-                        ];
963
-                        break;
964
-                    case 'address2':
965
-                        $QST_values = [
966
-                            'QST_display_text'  => esc_html__('Address2', 'event_espresso'),
967
-                            'QST_admin_label'   => esc_html__('Address2 - System Question', 'event_espresso'),
968
-                            'QST_system'        => 'address2',
969
-                            'QST_type'          => 'TEXT',
970
-                            'QST_required'      => 0,
971
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
972
-                            'QST_order'         => 6,
973
-                            'QST_admin_only'    => 0,
974
-                            'QST_max'           => EEM_Question::instance()
975
-                                                               ->absolute_max_for_system_question($QST_system),
976
-                            'QST_wp_user'       => self::get_default_creator_id(),
977
-                            'QST_deleted'       => 0,
978
-                        ];
979
-                        break;
980
-                    case 'city':
981
-                        $QST_values = [
982
-                            'QST_display_text'  => esc_html__('City', 'event_espresso'),
983
-                            'QST_admin_label'   => esc_html__('City - System Question', 'event_espresso'),
984
-                            'QST_system'        => 'city',
985
-                            'QST_type'          => 'TEXT',
986
-                            'QST_required'      => 0,
987
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
988
-                            'QST_order'         => 7,
989
-                            'QST_admin_only'    => 0,
990
-                            'QST_max'           => EEM_Question::instance()
991
-                                                               ->absolute_max_for_system_question($QST_system),
992
-                            'QST_wp_user'       => self::get_default_creator_id(),
993
-                            'QST_deleted'       => 0,
994
-                        ];
995
-                        break;
996
-                    case 'country':
997
-                        $QST_values = [
998
-                            'QST_display_text'  => esc_html__('Country', 'event_espresso'),
999
-                            'QST_admin_label'   => esc_html__('Country - System Question', 'event_espresso'),
1000
-                            'QST_system'        => 'country',
1001
-                            'QST_type'          => 'COUNTRY',
1002
-                            'QST_required'      => 0,
1003
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1004
-                            'QST_order'         => 8,
1005
-                            'QST_admin_only'    => 0,
1006
-                            'QST_wp_user'       => self::get_default_creator_id(),
1007
-                            'QST_deleted'       => 0,
1008
-                        ];
1009
-                        break;
1010
-                    case 'state':
1011
-                        $QST_values = [
1012
-                            'QST_display_text'  => esc_html__('State/Province', 'event_espresso'),
1013
-                            'QST_admin_label'   => esc_html__('State/Province - System Question', 'event_espresso'),
1014
-                            'QST_system'        => 'state',
1015
-                            'QST_type'          => 'STATE',
1016
-                            'QST_required'      => 0,
1017
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1018
-                            'QST_order'         => 9,
1019
-                            'QST_admin_only'    => 0,
1020
-                            'QST_wp_user'       => self::get_default_creator_id(),
1021
-                            'QST_deleted'       => 0,
1022
-                        ];
1023
-                        break;
1024
-                    case 'zip':
1025
-                        $QST_values = [
1026
-                            'QST_display_text'  => esc_html__('Zip/Postal Code', 'event_espresso'),
1027
-                            'QST_admin_label'   => esc_html__('Zip/Postal Code - System Question', 'event_espresso'),
1028
-                            'QST_system'        => 'zip',
1029
-                            'QST_type'          => 'TEXT',
1030
-                            'QST_required'      => 0,
1031
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1032
-                            'QST_order'         => 10,
1033
-                            'QST_admin_only'    => 0,
1034
-                            'QST_max'           => EEM_Question::instance()
1035
-                                                               ->absolute_max_for_system_question($QST_system),
1036
-                            'QST_wp_user'       => self::get_default_creator_id(),
1037
-                            'QST_deleted'       => 0,
1038
-                        ];
1039
-                        break;
1040
-                    case 'phone':
1041
-                        $QST_values = [
1042
-                            'QST_display_text'  => esc_html__('Phone Number', 'event_espresso'),
1043
-                            'QST_admin_label'   => esc_html__('Phone Number - System Question', 'event_espresso'),
1044
-                            'QST_system'        => 'phone',
1045
-                            'QST_type'          => 'TEXT',
1046
-                            'QST_required'      => 0,
1047
-                            'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1048
-                            'QST_order'         => 11,
1049
-                            'QST_admin_only'    => 0,
1050
-                            'QST_max'           => EEM_Question::instance()
1051
-                                                               ->absolute_max_for_system_question($QST_system),
1052
-                            'QST_wp_user'       => self::get_default_creator_id(),
1053
-                            'QST_deleted'       => 0,
1054
-                        ];
1055
-                        break;
1056
-                }
1057
-                if (! empty($QST_values)) {
1058
-                    // insert system question
1059
-                    $wpdb->insert(
1060
-                        $table_name,
1061
-                        $QST_values,
1062
-                        ['%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d']
1063
-                    );
1064
-                    $QST_ID = $wpdb->insert_id;
1065
-
1066
-                    // QUESTION GROUP QUESTIONS
1067
-                    if (in_array($QST_system, $personal_system_group_questions)) {
1068
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1069
-                    } elseif (in_array($QST_system, $address_system_group_questions)) {
1070
-                        $system_question_we_want = EEM_Question_Group::system_address;
1071
-                    } else {
1072
-                        // QST_system should not be assigned to any group
1073
-                        continue;
1074
-                    }
1075
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1076
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1077
-                    } else {
1078
-                        $id_col = EEM_Question_Group::instance()
1079
-                                                    ->get_col([['QSG_system' => $system_question_we_want]]);
1080
-                        if (is_array($id_col)) {
1081
-                            $QSG_ID = reset($id_col);
1082
-                        } else {
1083
-                            // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1084
-                            EE_Log::instance()->log(
1085
-                                __FILE__,
1086
-                                __FUNCTION__,
1087
-                                sprintf(
1088
-                                    esc_html__(
1089
-                                        'Could not associate question %1$s to a question group because no system question
785
+						'event_espresso'
786
+					)
787
+				);
788
+			}
789
+			return false;
790
+		}
791
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to();
792
+		return true;
793
+	}
794
+
795
+
796
+	/**
797
+	 * @return void
798
+	 * @throws EE_Error
799
+	 * @throws ReflectionException
800
+	 */
801
+	public static function initialize_system_questions()
802
+	{
803
+		// QUESTION GROUPS
804
+		global $wpdb;
805
+		$table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
806
+		$SQL        = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
807
+		// what we have
808
+		$question_groups = $wpdb->get_col($SQL);
809
+		// check the response
810
+		$question_groups = is_array($question_groups) ? $question_groups : [];
811
+		// what we should have
812
+		$QSG_systems = [1, 2];
813
+		// loop thru what we should have and compare to what we have
814
+		foreach ($QSG_systems as $QSG_system) {
815
+			// reset values array
816
+			$QSG_values = [];
817
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
818
+			if (! in_array("$QSG_system", $question_groups)) {
819
+				// add it
820
+				switch ($QSG_system) {
821
+					case 1:
822
+						$QSG_values = [
823
+							'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
824
+							'QSG_identifier'      => 'personal-information-' . time(),
825
+							'QSG_desc'            => '',
826
+							'QSG_order'           => 1,
827
+							'QSG_show_group_name' => 1,
828
+							'QSG_show_group_desc' => 1,
829
+							'QSG_system'          => EEM_Question_Group::system_personal,
830
+							'QSG_deleted'         => 0,
831
+						];
832
+						break;
833
+					case 2:
834
+						$QSG_values = [
835
+							'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
836
+							'QSG_identifier'      => 'address-information-' . time(),
837
+							'QSG_desc'            => '',
838
+							'QSG_order'           => 2,
839
+							'QSG_show_group_name' => 1,
840
+							'QSG_show_group_desc' => 1,
841
+							'QSG_system'          => EEM_Question_Group::system_address,
842
+							'QSG_deleted'         => 0,
843
+						];
844
+						break;
845
+				}
846
+				// make sure we have some values before inserting them
847
+				if (! empty($QSG_values)) {
848
+					// insert system question
849
+					$wpdb->insert(
850
+						$table_name,
851
+						$QSG_values,
852
+						['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
853
+					);
854
+					$QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
855
+				}
856
+			}
857
+		}
858
+		// QUESTIONS
859
+		global $wpdb;
860
+		$table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
861
+		$SQL        = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
862
+		// what we have
863
+		$questions = $wpdb->get_col($SQL);
864
+		// all system questions
865
+		$personal_system_group_questions = ['fname', 'lname', 'email'];
866
+		$address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
867
+		$system_questions_not_in_group   = ['email_confirm'];
868
+		// merge all of the system questions we should have
869
+		$QST_systems       = array_merge(
870
+			$personal_system_group_questions,
871
+			$address_system_group_questions,
872
+			$system_questions_not_in_group
873
+		);
874
+		$order_for_group_1 = 1;
875
+		$order_for_group_2 = 1;
876
+		// loop thru what we should have and compare to what we have
877
+		foreach ($QST_systems as $QST_system) {
878
+			// reset values array
879
+			$QST_values = [];
880
+			// if we don't have what we should have
881
+			if (! in_array($QST_system, $questions)) {
882
+				// add it
883
+				switch ($QST_system) {
884
+					case 'fname':
885
+						$QST_values = [
886
+							'QST_display_text'  => esc_html__('First Name', 'event_espresso'),
887
+							'QST_admin_label'   => esc_html__('First Name - System Question', 'event_espresso'),
888
+							'QST_system'        => 'fname',
889
+							'QST_type'          => 'TEXT',
890
+							'QST_required'      => 1,
891
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
892
+							'QST_order'         => 1,
893
+							'QST_admin_only'    => 0,
894
+							'QST_max'           => EEM_Question::instance()
895
+															   ->absolute_max_for_system_question($QST_system),
896
+							'QST_wp_user'       => self::get_default_creator_id(),
897
+							'QST_deleted'       => 0,
898
+						];
899
+						break;
900
+					case 'lname':
901
+						$QST_values = [
902
+							'QST_display_text'  => esc_html__('Last Name', 'event_espresso'),
903
+							'QST_admin_label'   => esc_html__('Last Name - System Question', 'event_espresso'),
904
+							'QST_system'        => 'lname',
905
+							'QST_type'          => 'TEXT',
906
+							'QST_required'      => 1,
907
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
908
+							'QST_order'         => 2,
909
+							'QST_admin_only'    => 0,
910
+							'QST_max'           => EEM_Question::instance()
911
+															   ->absolute_max_for_system_question($QST_system),
912
+							'QST_wp_user'       => self::get_default_creator_id(),
913
+							'QST_deleted'       => 0,
914
+						];
915
+						break;
916
+					case 'email':
917
+						$QST_values = [
918
+							'QST_display_text'  => esc_html__('Email Address', 'event_espresso'),
919
+							'QST_admin_label'   => esc_html__('Email Address - System Question', 'event_espresso'),
920
+							'QST_system'        => 'email',
921
+							'QST_type'          => 'EMAIL',
922
+							'QST_required'      => 1,
923
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
924
+							'QST_order'         => 3,
925
+							'QST_admin_only'    => 0,
926
+							'QST_max'           => EEM_Question::instance()
927
+															   ->absolute_max_for_system_question($QST_system),
928
+							'QST_wp_user'       => self::get_default_creator_id(),
929
+							'QST_deleted'       => 0,
930
+						];
931
+						break;
932
+					case 'email_confirm':
933
+						$QST_values = [
934
+							'QST_display_text'  => esc_html__('Confirm Email Address', 'event_espresso'),
935
+							'QST_admin_label'   => esc_html__('Confirm Email Address - System Question', 'event_espresso'),
936
+							'QST_system'        => 'email_confirm',
937
+							'QST_type'          => 'EMAIL_CONFIRM',
938
+							'QST_required'      => 1,
939
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
940
+							'QST_order'         => 4,
941
+							'QST_admin_only'    => 0,
942
+							'QST_max'           => EEM_Question::instance()
943
+															   ->absolute_max_for_system_question($QST_system),
944
+							'QST_wp_user'       => self::get_default_creator_id(),
945
+							'QST_deleted'       => 0,
946
+						];
947
+						break;
948
+					case 'address':
949
+						$QST_values = [
950
+							'QST_display_text'  => esc_html__('Address', 'event_espresso'),
951
+							'QST_admin_label'   => esc_html__('Address - System Question', 'event_espresso'),
952
+							'QST_system'        => 'address',
953
+							'QST_type'          => 'TEXT',
954
+							'QST_required'      => 0,
955
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
956
+							'QST_order'         => 5,
957
+							'QST_admin_only'    => 0,
958
+							'QST_max'           => EEM_Question::instance()
959
+															   ->absolute_max_for_system_question($QST_system),
960
+							'QST_wp_user'       => self::get_default_creator_id(),
961
+							'QST_deleted'       => 0,
962
+						];
963
+						break;
964
+					case 'address2':
965
+						$QST_values = [
966
+							'QST_display_text'  => esc_html__('Address2', 'event_espresso'),
967
+							'QST_admin_label'   => esc_html__('Address2 - System Question', 'event_espresso'),
968
+							'QST_system'        => 'address2',
969
+							'QST_type'          => 'TEXT',
970
+							'QST_required'      => 0,
971
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
972
+							'QST_order'         => 6,
973
+							'QST_admin_only'    => 0,
974
+							'QST_max'           => EEM_Question::instance()
975
+															   ->absolute_max_for_system_question($QST_system),
976
+							'QST_wp_user'       => self::get_default_creator_id(),
977
+							'QST_deleted'       => 0,
978
+						];
979
+						break;
980
+					case 'city':
981
+						$QST_values = [
982
+							'QST_display_text'  => esc_html__('City', 'event_espresso'),
983
+							'QST_admin_label'   => esc_html__('City - System Question', 'event_espresso'),
984
+							'QST_system'        => 'city',
985
+							'QST_type'          => 'TEXT',
986
+							'QST_required'      => 0,
987
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
988
+							'QST_order'         => 7,
989
+							'QST_admin_only'    => 0,
990
+							'QST_max'           => EEM_Question::instance()
991
+															   ->absolute_max_for_system_question($QST_system),
992
+							'QST_wp_user'       => self::get_default_creator_id(),
993
+							'QST_deleted'       => 0,
994
+						];
995
+						break;
996
+					case 'country':
997
+						$QST_values = [
998
+							'QST_display_text'  => esc_html__('Country', 'event_espresso'),
999
+							'QST_admin_label'   => esc_html__('Country - System Question', 'event_espresso'),
1000
+							'QST_system'        => 'country',
1001
+							'QST_type'          => 'COUNTRY',
1002
+							'QST_required'      => 0,
1003
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1004
+							'QST_order'         => 8,
1005
+							'QST_admin_only'    => 0,
1006
+							'QST_wp_user'       => self::get_default_creator_id(),
1007
+							'QST_deleted'       => 0,
1008
+						];
1009
+						break;
1010
+					case 'state':
1011
+						$QST_values = [
1012
+							'QST_display_text'  => esc_html__('State/Province', 'event_espresso'),
1013
+							'QST_admin_label'   => esc_html__('State/Province - System Question', 'event_espresso'),
1014
+							'QST_system'        => 'state',
1015
+							'QST_type'          => 'STATE',
1016
+							'QST_required'      => 0,
1017
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1018
+							'QST_order'         => 9,
1019
+							'QST_admin_only'    => 0,
1020
+							'QST_wp_user'       => self::get_default_creator_id(),
1021
+							'QST_deleted'       => 0,
1022
+						];
1023
+						break;
1024
+					case 'zip':
1025
+						$QST_values = [
1026
+							'QST_display_text'  => esc_html__('Zip/Postal Code', 'event_espresso'),
1027
+							'QST_admin_label'   => esc_html__('Zip/Postal Code - System Question', 'event_espresso'),
1028
+							'QST_system'        => 'zip',
1029
+							'QST_type'          => 'TEXT',
1030
+							'QST_required'      => 0,
1031
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1032
+							'QST_order'         => 10,
1033
+							'QST_admin_only'    => 0,
1034
+							'QST_max'           => EEM_Question::instance()
1035
+															   ->absolute_max_for_system_question($QST_system),
1036
+							'QST_wp_user'       => self::get_default_creator_id(),
1037
+							'QST_deleted'       => 0,
1038
+						];
1039
+						break;
1040
+					case 'phone':
1041
+						$QST_values = [
1042
+							'QST_display_text'  => esc_html__('Phone Number', 'event_espresso'),
1043
+							'QST_admin_label'   => esc_html__('Phone Number - System Question', 'event_espresso'),
1044
+							'QST_system'        => 'phone',
1045
+							'QST_type'          => 'TEXT',
1046
+							'QST_required'      => 0,
1047
+							'QST_required_text' => esc_html__('This field is required', 'event_espresso'),
1048
+							'QST_order'         => 11,
1049
+							'QST_admin_only'    => 0,
1050
+							'QST_max'           => EEM_Question::instance()
1051
+															   ->absolute_max_for_system_question($QST_system),
1052
+							'QST_wp_user'       => self::get_default_creator_id(),
1053
+							'QST_deleted'       => 0,
1054
+						];
1055
+						break;
1056
+				}
1057
+				if (! empty($QST_values)) {
1058
+					// insert system question
1059
+					$wpdb->insert(
1060
+						$table_name,
1061
+						$QST_values,
1062
+						['%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d']
1063
+					);
1064
+					$QST_ID = $wpdb->insert_id;
1065
+
1066
+					// QUESTION GROUP QUESTIONS
1067
+					if (in_array($QST_system, $personal_system_group_questions)) {
1068
+						$system_question_we_want = EEM_Question_Group::system_personal;
1069
+					} elseif (in_array($QST_system, $address_system_group_questions)) {
1070
+						$system_question_we_want = EEM_Question_Group::system_address;
1071
+					} else {
1072
+						// QST_system should not be assigned to any group
1073
+						continue;
1074
+					}
1075
+					if (isset($QSG_IDs[ $system_question_we_want ])) {
1076
+						$QSG_ID = $QSG_IDs[ $system_question_we_want ];
1077
+					} else {
1078
+						$id_col = EEM_Question_Group::instance()
1079
+													->get_col([['QSG_system' => $system_question_we_want]]);
1080
+						if (is_array($id_col)) {
1081
+							$QSG_ID = reset($id_col);
1082
+						} else {
1083
+							// ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1084
+							EE_Log::instance()->log(
1085
+								__FILE__,
1086
+								__FUNCTION__,
1087
+								sprintf(
1088
+									esc_html__(
1089
+										'Could not associate question %1$s to a question group because no system question
1090 1090
                                          group existed',
1091
-                                        'event_espresso'
1092
-                                    ),
1093
-                                    $QST_ID
1094
-                                ),
1095
-                                'error'
1096
-                            );
1097
-                            continue;
1098
-                        }
1099
-                    }
1100
-                    // add system questions to groups
1101
-                    $wpdb->insert(
1102
-                        EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1103
-                        [
1104
-                            'QSG_ID'    => $QSG_ID,
1105
-                            'QST_ID'    => $QST_ID,
1106
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1107
-                        ],
1108
-                        ['%d', '%d', '%d']
1109
-                    );
1110
-                }
1111
-            }
1112
-        }
1113
-    }
1114
-
1115
-
1116
-    /**
1117
-     * Makes sure the default payment method (Invoice) is active.
1118
-     * This used to be done automatically as part of constructing the old gateways config
1119
-     *
1120
-     * @throws EE_Error
1121
-     * @throws ReflectionException
1122
-     */
1123
-    public static function insert_default_payment_methods()
1124
-    {
1125
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1126
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1127
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1128
-        } else {
1129
-            EEM_Payment_Method::instance()->verify_button_urls();
1130
-        }
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * @return void
1136
-     * @throws EE_Error
1137
-     * @throws ReflectionException
1138
-     */
1139
-    public static function insert_default_status_codes()
1140
-    {
1141
-
1142
-        global $wpdb;
1143
-
1144
-        if (EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1145
-            $table_name = EEM_Status::instance()->table();
1146
-
1147
-            $SQL =
1148
-                "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1149
-            $wpdb->query($SQL);
1150
-
1151
-            $SQL = "INSERT INTO $table_name
1091
+										'event_espresso'
1092
+									),
1093
+									$QST_ID
1094
+								),
1095
+								'error'
1096
+							);
1097
+							continue;
1098
+						}
1099
+					}
1100
+					// add system questions to groups
1101
+					$wpdb->insert(
1102
+						EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1103
+						[
1104
+							'QSG_ID'    => $QSG_ID,
1105
+							'QST_ID'    => $QST_ID,
1106
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1107
+						],
1108
+						['%d', '%d', '%d']
1109
+					);
1110
+				}
1111
+			}
1112
+		}
1113
+	}
1114
+
1115
+
1116
+	/**
1117
+	 * Makes sure the default payment method (Invoice) is active.
1118
+	 * This used to be done automatically as part of constructing the old gateways config
1119
+	 *
1120
+	 * @throws EE_Error
1121
+	 * @throws ReflectionException
1122
+	 */
1123
+	public static function insert_default_payment_methods()
1124
+	{
1125
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1126
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1127
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1128
+		} else {
1129
+			EEM_Payment_Method::instance()->verify_button_urls();
1130
+		}
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * @return void
1136
+	 * @throws EE_Error
1137
+	 * @throws ReflectionException
1138
+	 */
1139
+	public static function insert_default_status_codes()
1140
+	{
1141
+
1142
+		global $wpdb;
1143
+
1144
+		if (EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1145
+			$table_name = EEM_Status::instance()->table();
1146
+
1147
+			$SQL =
1148
+				"DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1149
+			$wpdb->query($SQL);
1150
+
1151
+			$SQL = "INSERT INTO $table_name
1152 1152
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1153 1153
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1154 1154
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1188,466 +1188,466 @@  discard block
 block discarded – undo
1188 1188
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1189 1189
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1190 1190
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1191
-            $wpdb->query($SQL);
1192
-        }
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * @return bool     true means new templates were created.
1198
-     *                  false means no templates were created.
1199
-     *                  This is NOT an error flag. To check for errors you will want
1200
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1201
-     * @throws EE_Error
1202
-     * @throws ReflectionException
1203
-     */
1204
-    public static function generate_default_message_templates()
1205
-    {
1206
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1207
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1208
-        /*
1191
+			$wpdb->query($SQL);
1192
+		}
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * @return bool     true means new templates were created.
1198
+	 *                  false means no templates were created.
1199
+	 *                  This is NOT an error flag. To check for errors you will want
1200
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1201
+	 * @throws EE_Error
1202
+	 * @throws ReflectionException
1203
+	 */
1204
+	public static function generate_default_message_templates()
1205
+	{
1206
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1207
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1208
+		/*
1209 1209
          * This first method is taking care of ensuring any default messengers
1210 1210
          * that should be made active and have templates generated are done.
1211 1211
          */
1212
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1213
-            $message_resource_manager
1214
-        );
1215
-        /**
1216
-         * This method is verifying there are no NEW default message types
1217
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1218
-         */
1219
-        $new_templates_created_for_message_type =
1220
-            self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1221
-                $message_resource_manager
1222
-            );
1223
-        // after all is done, let's persist these changes to the db.
1224
-        $message_resource_manager->update_has_activated_messengers_option();
1225
-        $message_resource_manager->update_active_messengers_option();
1226
-        // will return true if either of these are true.  Otherwise will return false.
1227
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1228
-    }
1229
-
1230
-
1231
-    /**
1232
-     * @param EE_Message_Resource_Manager $message_resource_manager
1233
-     * @return array|bool
1234
-     * @throws EE_Error
1235
-     * @throws ReflectionException
1236
-     */
1237
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1238
-        EE_Message_Resource_Manager $message_resource_manager
1239
-    ) {
1240
-        $active_messengers       = $message_resource_manager->active_messengers();
1241
-        $installed_message_types = $message_resource_manager->installed_message_types();
1242
-        $templates_created       = false;
1243
-        foreach ($active_messengers as $active_messenger) {
1244
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1245
-            $default_message_type_names_to_activate   = [];
1246
-            // looping through each default message type reported by the messenger
1247
-            // and setup the actual message types to activate.
1248
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1249
-                // if already active or has already been activated before we skip
1250
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1251
-                // we also skip if the message type is not installed.
1252
-                if (
1253
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1254
-                        $default_message_type_name_for_messenger,
1255
-                        $active_messenger->name
1256
-                    )
1257
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1258
-                        $active_messenger->name,
1259
-                        $default_message_type_name_for_messenger
1260
-                    )
1261
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1262
-                ) {
1263
-                    continue;
1264
-                }
1265
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1266
-            }
1267
-            // let's activate!
1268
-            $message_resource_manager->ensure_message_types_are_active(
1269
-                $default_message_type_names_to_activate,
1270
-                $active_messenger->name,
1271
-                false
1272
-            );
1273
-            // activate the templates for these message types
1274
-            if (! empty($default_message_type_names_to_activate)) {
1275
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1276
-                    $active_messenger->name,
1277
-                    $default_message_type_names_for_messenger,
1278
-                    '',
1279
-                    true
1280
-                );
1281
-            }
1282
-        }
1283
-        return $templates_created;
1284
-    }
1285
-
1286
-
1287
-    /**
1288
-     * This will activate and generate default messengers and default message types for those messengers.
1289
-     *
1290
-     * @param EE_message_Resource_Manager $message_resource_manager
1291
-     * @return array|bool  True means there were default messengers and message type templates generated.
1292
-     *                     False means that there were no templates generated
1293
-     *                     (which could simply mean there are no default message types for a messenger).
1294
-     * @throws EE_Error
1295
-     * @throws ReflectionException
1296
-     */
1297
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1298
-        EE_Message_Resource_Manager $message_resource_manager
1299
-    ) {
1300
-        $messengers_to_generate  = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1301
-        $installed_message_types = $message_resource_manager->installed_message_types();
1302
-        $templates_generated     = false;
1303
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1304
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1305
-            // verify the default message types match an installed message type.
1306
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1307
-                if (
1308
-                    ! isset($installed_message_types[ $name ])
1309
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1310
-                        $name,
1311
-                        $messenger_to_generate->name
1312
-                    )
1313
-                ) {
1314
-                    unset($default_message_type_names_for_messenger[ $key ]);
1315
-                }
1316
-            }
1317
-            // in previous iterations, the active_messengers option in the db
1318
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1319
-            // This comment is left here just in case we discover that we _do_ need to update before
1320
-            // passing off to create templates (after the refactor is done).
1321
-            // @todo remove this comment when determined not necessary.
1322
-            $message_resource_manager->activate_messenger(
1323
-                $messenger_to_generate,
1324
-                $default_message_type_names_for_messenger,
1325
-                false
1326
-            );
1327
-            // create any templates needing created (or will reactivate templates already generated as necessary).
1328
-            if (! empty($default_message_type_names_for_messenger)) {
1329
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1330
-                    $messenger_to_generate->name,
1331
-                    $default_message_type_names_for_messenger,
1332
-                    '',
1333
-                    true
1334
-                );
1335
-            }
1336
-        }
1337
-        return $templates_generated;
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * This returns the default messengers to generate templates for on activation of EE.
1343
-     * It considers:
1344
-     * - whether a messenger is already active in the db.
1345
-     * - whether a messenger has been made active at any time in the past.
1346
-     *
1347
-     * @param EE_Message_Resource_Manager $message_resource_manager
1348
-     * @return EE_messenger[]
1349
-     */
1350
-    protected static function _get_default_messengers_to_generate_on_activation(
1351
-        EE_Message_Resource_Manager $message_resource_manager
1352
-    ) {
1353
-        $active_messengers    = $message_resource_manager->active_messengers();
1354
-        $installed_messengers = $message_resource_manager->installed_messengers();
1355
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1356
-
1357
-        $messengers_to_generate = [];
1358
-        foreach ($installed_messengers as $installed_messenger) {
1359
-            // if installed messenger is a messenger that should be activated on install
1360
-            // and is not already active
1361
-            // and has never been activated
1362
-            if (
1363
-                ! $installed_messenger->activate_on_install
1364
-                || isset($active_messengers[ $installed_messenger->name ])
1365
-                || isset($has_activated[ $installed_messenger->name ])
1366
-            ) {
1367
-                continue;
1368
-            }
1369
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1370
-        }
1371
-        return $messengers_to_generate;
1372
-    }
1373
-
1374
-
1375
-    /**
1376
-     * This simply validates active message types to ensure they actually match installed
1377
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1378
-     * rows are set inactive.
1379
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1380
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1381
-     * are still handled in here.
1382
-     *
1383
-     * @return void
1384
-     * @throws EE_Error
1385
-     * @throws ReflectionException
1386
-     * @since 4.3.1
1387
-     */
1388
-    public static function validate_messages_system()
1389
-    {
1390
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1391
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1392
-        $message_resource_manager->validate_active_message_types_are_installed();
1393
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1394
-    }
1395
-
1396
-
1397
-    /**
1398
-     * @return void
1399
-     */
1400
-    public static function plugin_deactivation()
1401
-    {
1402
-    }
1403
-
1404
-
1405
-    /**
1406
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1407
-     * (like post meta or term relations)
1408
-     *
1409
-     * @throws EE_Error
1410
-     * @global wpdb $wpdb
1411
-     */
1412
-    public static function delete_all_espresso_cpt_data()
1413
-    {
1414
-        global $wpdb;
1415
-        // get all the CPT post_types
1416
-        $ee_post_types = [];
1417
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1418
-            if (method_exists($model_name, 'instance')) {
1419
-                $model_obj = call_user_func([$model_name, 'instance']);
1420
-                if ($model_obj instanceof EEM_CPT_Base) {
1421
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1422
-                }
1423
-            }
1424
-        }
1425
-        // get all our CPTs
1426
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1427
-        $cpt_ids = $wpdb->get_col($query);
1428
-        // delete each post meta and term relations too
1429
-        foreach ($cpt_ids as $post_id) {
1430
-            wp_delete_post($post_id, true);
1431
-        }
1432
-    }
1433
-
1434
-
1435
-    /**
1436
-     * Deletes all EE custom tables
1437
-     *
1438
-     * @return array
1439
-     * @throws EE_Error
1440
-     * @throws ReflectionException
1441
-     */
1442
-    public static function drop_espresso_tables()
1443
-    {
1444
-        $tables = [];
1445
-        // load registry
1446
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1447
-            if (method_exists($model_name, 'instance')) {
1448
-                $model_obj = call_user_func([$model_name, 'instance']);
1449
-                if ($model_obj instanceof EEM_Base) {
1450
-                    foreach ($model_obj->get_tables() as $table) {
1451
-                        if (
1452
-                            strpos($table->get_table_name(), 'esp_')
1453
-                            && (
1454
-                                is_main_site()// main site? nuke them all
1455
-                                || ! $table->is_global()// not main site,but not global either. nuke it
1456
-                            )
1457
-                        ) {
1458
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1459
-                        }
1460
-                    }
1461
-                }
1462
-            }
1463
-        }
1464
-
1465
-        // there are some tables whose models were removed.
1466
-        // they should be removed when removing all EE core's data
1467
-        $tables_without_models = [
1468
-            'esp_promotion',
1469
-            'esp_promotion_applied',
1470
-            'esp_promotion_object',
1471
-            'esp_promotion_rule',
1472
-            'esp_rule',
1473
-        ];
1474
-        foreach ($tables_without_models as $table) {
1475
-            $tables[ $table ] = $table;
1476
-        }
1477
-        return EEH_Activation::getTableManager()->dropTables($tables);
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1483
-     * each table name provided has a wpdb prefix attached, and that it exists.
1484
-     * Returns the list actually deleted
1485
-     *
1486
-     * @param array $table_names
1487
-     * @return array of table names which we deleted
1488
-     * @throws EE_Error
1489
-     * @throws ReflectionException
1490
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1491
-     * @global WPDB $wpdb
1492
-     */
1493
-    public static function drop_tables($table_names)
1494
-    {
1495
-        return EEH_Activation::getTableManager()->dropTables($table_names);
1496
-    }
1497
-
1498
-
1499
-    /**
1500
-     * plugin_uninstall
1501
-     *
1502
-     * @param bool $remove_all
1503
-     * @return void
1504
-     * @throws EE_Error
1505
-     * @throws ReflectionException
1506
-     */
1507
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1508
-    {
1509
-        global $wpdb;
1510
-        self::drop_espresso_tables();
1511
-        $wp_options_to_delete = [
1512
-            'ee_no_ticket_prices'                        => true,
1513
-            'ee_active_messengers'                       => true,
1514
-            'ee_has_activated_messenger'                 => true,
1515
-            RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1516
-            'ee_config'                                  => false,
1517
-            'ee_data_migration_current_db_state'         => true,
1518
-            'ee_data_migration_mapping_'                 => false,
1519
-            'ee_data_migration_script_'                  => false,
1520
-            'ee_data_migrations'                         => true,
1521
-            'ee_dms_map'                                 => false,
1522
-            'ee_notices'                                 => true,
1523
-            'lang_file_check_'                           => false,
1524
-            'ee_maintenance_mode'                        => true,
1525
-            'ee_ueip_optin'                              => true,
1526
-            'ee_ueip_has_notified'                       => true,
1527
-            'ee_plugin_activation_errors'                => true,
1528
-            'ee_id_mapping_from'                         => false,
1529
-            'espresso_persistent_admin_notices'          => true,
1530
-            'ee_encryption_key'                          => true,
1531
-            'pue_force_upgrade_'                         => false,
1532
-            'pue_json_error_'                            => false,
1533
-            'pue_install_key_'                           => false,
1534
-            'pue_verification_error_'                    => false,
1535
-            'pu_dismissed_upgrade_'                      => false,
1536
-            'external_updates-'                          => false,
1537
-            'ee_extra_data'                              => true,
1538
-            'ee_ssn_'                                    => false,
1539
-            'ee_rss_'                                    => false,
1540
-            'ee_rte_n_tx_'                               => false,
1541
-            'ee_pers_admin_notices'                      => true,
1542
-            'ee_job_parameters_'                         => false,
1543
-            'ee_upload_directories_incomplete'           => true,
1544
-            'ee_verified_db_collations'                  => true,
1545
-        ];
1546
-        if (is_main_site()) {
1547
-            $wp_options_to_delete['ee_network_config'] = true;
1548
-        }
1549
-        $undeleted_options = [];
1550
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1551
-            if ($no_wildcard) {
1552
-                if (! delete_option($option_name)) {
1553
-                    $undeleted_options[] = $option_name;
1554
-                }
1555
-            } else {
1556
-                $option_names_to_delete_from_wildcard =
1557
-                    $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1558
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1559
-                    if (! delete_option($option_name_from_wildcard)) {
1560
-                        $undeleted_options[] = $option_name_from_wildcard;
1561
-                    }
1562
-                }
1563
-            }
1564
-        }
1565
-        // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1566
-        remove_action('shutdown', [EE_Config::instance(), 'shutdown']);
1567
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1568
-            $db_update_sans_ee4 = [];
1569
-            foreach ($espresso_db_update as $version => $times_activated) {
1570
-                if ((string) $version[0] === '3') {// if its NON EE4
1571
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1572
-                }
1573
-            }
1574
-            update_option('espresso_db_update', $db_update_sans_ee4);
1575
-        }
1576
-        $errors = '';
1577
-        if (! empty($undeleted_options)) {
1578
-            $errors .= sprintf(
1579
-                esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1580
-                '<br/>',
1581
-                implode(',<br/>', $undeleted_options)
1582
-            );
1583
-        }
1584
-        if (! empty($errors)) {
1585
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1586
-        }
1587
-    }
1588
-
1589
-
1590
-    /**
1591
-     * Gets the mysql error code from the last used query by wpdb
1592
-     *
1593
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1594
-     */
1595
-    public static function last_wpdb_error_code()
1596
-    {
1597
-        // phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
1598
-        global $wpdb;
1599
-        return $wpdb->use_mysqli ? mysqli_errno($wpdb->dbh) : mysql_errno($wpdb->dbh);
1600
-        // phpcs:enable
1601
-    }
1602
-
1603
-
1604
-    /**
1605
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1606
-     *
1607
-     * @param string $table_name with or without $wpdb->prefix
1608
-     * @return boolean
1609
-     * @throws EE_Error
1610
-     * @throws ReflectionException
1611
-     * @global wpdb  $wpdb
1612
-     * @deprecated instead use TableAnalysis::tableExists()
1613
-     */
1614
-    public static function table_exists($table_name)
1615
-    {
1616
-        return EEH_Activation::getTableAnalysis()->tableExists($table_name);
1617
-    }
1618
-
1619
-
1620
-    /**
1621
-     * Resets the cache on EEH_Activation
1622
-     */
1623
-    public static function reset()
1624
-    {
1625
-        self::$_default_creator_id                             = null;
1626
-        self::$_initialized_db_content_already_in_this_request = false;
1627
-    }
1628
-
1629
-
1630
-    /**
1631
-     * Removes 'email_confirm' from the Address info question group on activation
1632
-     *
1633
-     * @return void
1634
-     * @throws EE_Error
1635
-     */
1636
-    public static function removeEmailConfirmFromAddressGroup()
1637
-    {
1638
-
1639
-        // Pull the email_confirm question ID.
1640
-        $email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
1641
-            EEM_Attendee::system_question_email_confirm
1642
-        );
1643
-        // Remove the email_confirm question group from the address group questions.
1644
-        EEM_Question_Group_Question::instance()->delete(
1645
-            [
1646
-                [
1647
-                    'QST_ID'                    => $email_confirm_question_id,
1648
-                    'Question_Group.QSG_system' => EEM_Question_Group::system_address,
1649
-                ],
1650
-            ]
1651
-        );
1652
-    }
1212
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1213
+			$message_resource_manager
1214
+		);
1215
+		/**
1216
+		 * This method is verifying there are no NEW default message types
1217
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1218
+		 */
1219
+		$new_templates_created_for_message_type =
1220
+			self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1221
+				$message_resource_manager
1222
+			);
1223
+		// after all is done, let's persist these changes to the db.
1224
+		$message_resource_manager->update_has_activated_messengers_option();
1225
+		$message_resource_manager->update_active_messengers_option();
1226
+		// will return true if either of these are true.  Otherwise will return false.
1227
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1228
+	}
1229
+
1230
+
1231
+	/**
1232
+	 * @param EE_Message_Resource_Manager $message_resource_manager
1233
+	 * @return array|bool
1234
+	 * @throws EE_Error
1235
+	 * @throws ReflectionException
1236
+	 */
1237
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1238
+		EE_Message_Resource_Manager $message_resource_manager
1239
+	) {
1240
+		$active_messengers       = $message_resource_manager->active_messengers();
1241
+		$installed_message_types = $message_resource_manager->installed_message_types();
1242
+		$templates_created       = false;
1243
+		foreach ($active_messengers as $active_messenger) {
1244
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1245
+			$default_message_type_names_to_activate   = [];
1246
+			// looping through each default message type reported by the messenger
1247
+			// and setup the actual message types to activate.
1248
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1249
+				// if already active or has already been activated before we skip
1250
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1251
+				// we also skip if the message type is not installed.
1252
+				if (
1253
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1254
+						$default_message_type_name_for_messenger,
1255
+						$active_messenger->name
1256
+					)
1257
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1258
+						$active_messenger->name,
1259
+						$default_message_type_name_for_messenger
1260
+					)
1261
+					|| ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1262
+				) {
1263
+					continue;
1264
+				}
1265
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1266
+			}
1267
+			// let's activate!
1268
+			$message_resource_manager->ensure_message_types_are_active(
1269
+				$default_message_type_names_to_activate,
1270
+				$active_messenger->name,
1271
+				false
1272
+			);
1273
+			// activate the templates for these message types
1274
+			if (! empty($default_message_type_names_to_activate)) {
1275
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1276
+					$active_messenger->name,
1277
+					$default_message_type_names_for_messenger,
1278
+					'',
1279
+					true
1280
+				);
1281
+			}
1282
+		}
1283
+		return $templates_created;
1284
+	}
1285
+
1286
+
1287
+	/**
1288
+	 * This will activate and generate default messengers and default message types for those messengers.
1289
+	 *
1290
+	 * @param EE_message_Resource_Manager $message_resource_manager
1291
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1292
+	 *                     False means that there were no templates generated
1293
+	 *                     (which could simply mean there are no default message types for a messenger).
1294
+	 * @throws EE_Error
1295
+	 * @throws ReflectionException
1296
+	 */
1297
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1298
+		EE_Message_Resource_Manager $message_resource_manager
1299
+	) {
1300
+		$messengers_to_generate  = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1301
+		$installed_message_types = $message_resource_manager->installed_message_types();
1302
+		$templates_generated     = false;
1303
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1304
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1305
+			// verify the default message types match an installed message type.
1306
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1307
+				if (
1308
+					! isset($installed_message_types[ $name ])
1309
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1310
+						$name,
1311
+						$messenger_to_generate->name
1312
+					)
1313
+				) {
1314
+					unset($default_message_type_names_for_messenger[ $key ]);
1315
+				}
1316
+			}
1317
+			// in previous iterations, the active_messengers option in the db
1318
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1319
+			// This comment is left here just in case we discover that we _do_ need to update before
1320
+			// passing off to create templates (after the refactor is done).
1321
+			// @todo remove this comment when determined not necessary.
1322
+			$message_resource_manager->activate_messenger(
1323
+				$messenger_to_generate,
1324
+				$default_message_type_names_for_messenger,
1325
+				false
1326
+			);
1327
+			// create any templates needing created (or will reactivate templates already generated as necessary).
1328
+			if (! empty($default_message_type_names_for_messenger)) {
1329
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1330
+					$messenger_to_generate->name,
1331
+					$default_message_type_names_for_messenger,
1332
+					'',
1333
+					true
1334
+				);
1335
+			}
1336
+		}
1337
+		return $templates_generated;
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * This returns the default messengers to generate templates for on activation of EE.
1343
+	 * It considers:
1344
+	 * - whether a messenger is already active in the db.
1345
+	 * - whether a messenger has been made active at any time in the past.
1346
+	 *
1347
+	 * @param EE_Message_Resource_Manager $message_resource_manager
1348
+	 * @return EE_messenger[]
1349
+	 */
1350
+	protected static function _get_default_messengers_to_generate_on_activation(
1351
+		EE_Message_Resource_Manager $message_resource_manager
1352
+	) {
1353
+		$active_messengers    = $message_resource_manager->active_messengers();
1354
+		$installed_messengers = $message_resource_manager->installed_messengers();
1355
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1356
+
1357
+		$messengers_to_generate = [];
1358
+		foreach ($installed_messengers as $installed_messenger) {
1359
+			// if installed messenger is a messenger that should be activated on install
1360
+			// and is not already active
1361
+			// and has never been activated
1362
+			if (
1363
+				! $installed_messenger->activate_on_install
1364
+				|| isset($active_messengers[ $installed_messenger->name ])
1365
+				|| isset($has_activated[ $installed_messenger->name ])
1366
+			) {
1367
+				continue;
1368
+			}
1369
+			$messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1370
+		}
1371
+		return $messengers_to_generate;
1372
+	}
1373
+
1374
+
1375
+	/**
1376
+	 * This simply validates active message types to ensure they actually match installed
1377
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1378
+	 * rows are set inactive.
1379
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1380
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1381
+	 * are still handled in here.
1382
+	 *
1383
+	 * @return void
1384
+	 * @throws EE_Error
1385
+	 * @throws ReflectionException
1386
+	 * @since 4.3.1
1387
+	 */
1388
+	public static function validate_messages_system()
1389
+	{
1390
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1391
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1392
+		$message_resource_manager->validate_active_message_types_are_installed();
1393
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1394
+	}
1395
+
1396
+
1397
+	/**
1398
+	 * @return void
1399
+	 */
1400
+	public static function plugin_deactivation()
1401
+	{
1402
+	}
1403
+
1404
+
1405
+	/**
1406
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1407
+	 * (like post meta or term relations)
1408
+	 *
1409
+	 * @throws EE_Error
1410
+	 * @global wpdb $wpdb
1411
+	 */
1412
+	public static function delete_all_espresso_cpt_data()
1413
+	{
1414
+		global $wpdb;
1415
+		// get all the CPT post_types
1416
+		$ee_post_types = [];
1417
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1418
+			if (method_exists($model_name, 'instance')) {
1419
+				$model_obj = call_user_func([$model_name, 'instance']);
1420
+				if ($model_obj instanceof EEM_CPT_Base) {
1421
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1422
+				}
1423
+			}
1424
+		}
1425
+		// get all our CPTs
1426
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1427
+		$cpt_ids = $wpdb->get_col($query);
1428
+		// delete each post meta and term relations too
1429
+		foreach ($cpt_ids as $post_id) {
1430
+			wp_delete_post($post_id, true);
1431
+		}
1432
+	}
1433
+
1434
+
1435
+	/**
1436
+	 * Deletes all EE custom tables
1437
+	 *
1438
+	 * @return array
1439
+	 * @throws EE_Error
1440
+	 * @throws ReflectionException
1441
+	 */
1442
+	public static function drop_espresso_tables()
1443
+	{
1444
+		$tables = [];
1445
+		// load registry
1446
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1447
+			if (method_exists($model_name, 'instance')) {
1448
+				$model_obj = call_user_func([$model_name, 'instance']);
1449
+				if ($model_obj instanceof EEM_Base) {
1450
+					foreach ($model_obj->get_tables() as $table) {
1451
+						if (
1452
+							strpos($table->get_table_name(), 'esp_')
1453
+							&& (
1454
+								is_main_site()// main site? nuke them all
1455
+								|| ! $table->is_global()// not main site,but not global either. nuke it
1456
+							)
1457
+						) {
1458
+							$tables[ $table->get_table_name() ] = $table->get_table_name();
1459
+						}
1460
+					}
1461
+				}
1462
+			}
1463
+		}
1464
+
1465
+		// there are some tables whose models were removed.
1466
+		// they should be removed when removing all EE core's data
1467
+		$tables_without_models = [
1468
+			'esp_promotion',
1469
+			'esp_promotion_applied',
1470
+			'esp_promotion_object',
1471
+			'esp_promotion_rule',
1472
+			'esp_rule',
1473
+		];
1474
+		foreach ($tables_without_models as $table) {
1475
+			$tables[ $table ] = $table;
1476
+		}
1477
+		return EEH_Activation::getTableManager()->dropTables($tables);
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1483
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1484
+	 * Returns the list actually deleted
1485
+	 *
1486
+	 * @param array $table_names
1487
+	 * @return array of table names which we deleted
1488
+	 * @throws EE_Error
1489
+	 * @throws ReflectionException
1490
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1491
+	 * @global WPDB $wpdb
1492
+	 */
1493
+	public static function drop_tables($table_names)
1494
+	{
1495
+		return EEH_Activation::getTableManager()->dropTables($table_names);
1496
+	}
1497
+
1498
+
1499
+	/**
1500
+	 * plugin_uninstall
1501
+	 *
1502
+	 * @param bool $remove_all
1503
+	 * @return void
1504
+	 * @throws EE_Error
1505
+	 * @throws ReflectionException
1506
+	 */
1507
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1508
+	{
1509
+		global $wpdb;
1510
+		self::drop_espresso_tables();
1511
+		$wp_options_to_delete = [
1512
+			'ee_no_ticket_prices'                        => true,
1513
+			'ee_active_messengers'                       => true,
1514
+			'ee_has_activated_messenger'                 => true,
1515
+			RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1516
+			'ee_config'                                  => false,
1517
+			'ee_data_migration_current_db_state'         => true,
1518
+			'ee_data_migration_mapping_'                 => false,
1519
+			'ee_data_migration_script_'                  => false,
1520
+			'ee_data_migrations'                         => true,
1521
+			'ee_dms_map'                                 => false,
1522
+			'ee_notices'                                 => true,
1523
+			'lang_file_check_'                           => false,
1524
+			'ee_maintenance_mode'                        => true,
1525
+			'ee_ueip_optin'                              => true,
1526
+			'ee_ueip_has_notified'                       => true,
1527
+			'ee_plugin_activation_errors'                => true,
1528
+			'ee_id_mapping_from'                         => false,
1529
+			'espresso_persistent_admin_notices'          => true,
1530
+			'ee_encryption_key'                          => true,
1531
+			'pue_force_upgrade_'                         => false,
1532
+			'pue_json_error_'                            => false,
1533
+			'pue_install_key_'                           => false,
1534
+			'pue_verification_error_'                    => false,
1535
+			'pu_dismissed_upgrade_'                      => false,
1536
+			'external_updates-'                          => false,
1537
+			'ee_extra_data'                              => true,
1538
+			'ee_ssn_'                                    => false,
1539
+			'ee_rss_'                                    => false,
1540
+			'ee_rte_n_tx_'                               => false,
1541
+			'ee_pers_admin_notices'                      => true,
1542
+			'ee_job_parameters_'                         => false,
1543
+			'ee_upload_directories_incomplete'           => true,
1544
+			'ee_verified_db_collations'                  => true,
1545
+		];
1546
+		if (is_main_site()) {
1547
+			$wp_options_to_delete['ee_network_config'] = true;
1548
+		}
1549
+		$undeleted_options = [];
1550
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1551
+			if ($no_wildcard) {
1552
+				if (! delete_option($option_name)) {
1553
+					$undeleted_options[] = $option_name;
1554
+				}
1555
+			} else {
1556
+				$option_names_to_delete_from_wildcard =
1557
+					$wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1558
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1559
+					if (! delete_option($option_name_from_wildcard)) {
1560
+						$undeleted_options[] = $option_name_from_wildcard;
1561
+					}
1562
+				}
1563
+			}
1564
+		}
1565
+		// also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1566
+		remove_action('shutdown', [EE_Config::instance(), 'shutdown']);
1567
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1568
+			$db_update_sans_ee4 = [];
1569
+			foreach ($espresso_db_update as $version => $times_activated) {
1570
+				if ((string) $version[0] === '3') {// if its NON EE4
1571
+					$db_update_sans_ee4[ $version ] = $times_activated;
1572
+				}
1573
+			}
1574
+			update_option('espresso_db_update', $db_update_sans_ee4);
1575
+		}
1576
+		$errors = '';
1577
+		if (! empty($undeleted_options)) {
1578
+			$errors .= sprintf(
1579
+				esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1580
+				'<br/>',
1581
+				implode(',<br/>', $undeleted_options)
1582
+			);
1583
+		}
1584
+		if (! empty($errors)) {
1585
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1586
+		}
1587
+	}
1588
+
1589
+
1590
+	/**
1591
+	 * Gets the mysql error code from the last used query by wpdb
1592
+	 *
1593
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1594
+	 */
1595
+	public static function last_wpdb_error_code()
1596
+	{
1597
+		// phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
1598
+		global $wpdb;
1599
+		return $wpdb->use_mysqli ? mysqli_errno($wpdb->dbh) : mysql_errno($wpdb->dbh);
1600
+		// phpcs:enable
1601
+	}
1602
+
1603
+
1604
+	/**
1605
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1606
+	 *
1607
+	 * @param string $table_name with or without $wpdb->prefix
1608
+	 * @return boolean
1609
+	 * @throws EE_Error
1610
+	 * @throws ReflectionException
1611
+	 * @global wpdb  $wpdb
1612
+	 * @deprecated instead use TableAnalysis::tableExists()
1613
+	 */
1614
+	public static function table_exists($table_name)
1615
+	{
1616
+		return EEH_Activation::getTableAnalysis()->tableExists($table_name);
1617
+	}
1618
+
1619
+
1620
+	/**
1621
+	 * Resets the cache on EEH_Activation
1622
+	 */
1623
+	public static function reset()
1624
+	{
1625
+		self::$_default_creator_id                             = null;
1626
+		self::$_initialized_db_content_already_in_this_request = false;
1627
+	}
1628
+
1629
+
1630
+	/**
1631
+	 * Removes 'email_confirm' from the Address info question group on activation
1632
+	 *
1633
+	 * @return void
1634
+	 * @throws EE_Error
1635
+	 */
1636
+	public static function removeEmailConfirmFromAddressGroup()
1637
+	{
1638
+
1639
+		// Pull the email_confirm question ID.
1640
+		$email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
1641
+			EEM_Attendee::system_question_email_confirm
1642
+		);
1643
+		// Remove the email_confirm question group from the address group questions.
1644
+		EEM_Question_Group_Question::instance()->delete(
1645
+			[
1646
+				[
1647
+					'QST_ID'                    => $email_confirm_question_id,
1648
+					'Question_Group.QSG_system' => EEM_Question_Group::system_address,
1649
+				],
1650
+			]
1651
+		);
1652
+	}
1653 1653
 }
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public static function getTableAnalysis()
59 59
     {
60
-        if (! self::$table_analysis instanceof TableAnalysis) {
60
+        if ( ! self::$table_analysis instanceof TableAnalysis) {
61 61
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true);
62 62
         }
63 63
         return self::$table_analysis;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public static function getTableManager()
73 73
     {
74
-        if (! self::$table_manager instanceof TableManager) {
74
+        if ( ! self::$table_manager instanceof TableManager) {
75 75
             self::$table_manager = EE_Registry::instance()->create('TableManager', [], true);
76 76
         }
77 77
         return self::$table_manager;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         if ($which_to_include === 'old') {
185 185
             $cron_tasks = array_filter(
186 186
                 $cron_tasks,
187
-                function ($value) {
187
+                function($value) {
188 188
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
189 189
                 }
190 190
             );
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     {
215 215
 
216 216
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
217
-            if (! wp_next_scheduled($hook_name)) {
217
+            if ( ! wp_next_scheduled($hook_name)) {
218 218
                 /**
219 219
                  * This allows client code to define the initial start timestamp for this schedule.
220 220
                  */
@@ -267,15 +267,15 @@  discard block
 block discarded – undo
267 267
             if (is_array($hooks_to_fire_at_time)) {
268 268
                 foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
269 269
                     if (
270
-                        isset($ee_cron_tasks_to_remove[ $hook_name ])
271
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
270
+                        isset($ee_cron_tasks_to_remove[$hook_name])
271
+                        && is_array($ee_cron_tasks_to_remove[$hook_name])
272 272
                     ) {
273
-                        unset($crons[ $timestamp ][ $hook_name ]);
273
+                        unset($crons[$timestamp][$hook_name]);
274 274
                     }
275 275
                 }
276 276
                 // also take care of any empty cron timestamps.
277 277
                 if (empty($hooks_to_fire_at_time)) {
278
-                    unset($crons[ $timestamp ]);
278
+                    unset($crons[$timestamp]);
279 279
                 }
280 280
             }
281 281
         }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             10,
315 315
             3
316 316
         );
317
-        if (! EE_Config::logging_enabled()) {
317
+        if ( ! EE_Config::logging_enabled()) {
318 318
             delete_option(EE_Config::LOG_NAME);
319 319
         }
320 320
     }
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
     public static function load_calendar_config()
327 327
     {
328 328
         // grab array of all plugin folders and loop thru it
329
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
329
+        $plugins = glob(WP_PLUGIN_DIR.'/*', GLOB_ONLYDIR);
330 330
         if (empty($plugins)) {
331 331
             return;
332 332
         }
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
                 || strpos($plugin, 'calendar') !== false
344 344
             ) {
345 345
                 // this is what we are looking for
346
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
346
+                $calendar_config = $plugin_path.'/EE_Calendar_Config.php';
347 347
                 // does it exist in this folder ?
348 348
                 if (is_readable($calendar_config)) {
349 349
                     // YEAH! let's load it
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
                 'code' => 'ESPRESSO_CANCELLED',
427 427
             ],
428 428
         ];
429
-        $EE_Core_Config        = EE_Registry::instance()->CFG->core;
429
+        $EE_Core_Config = EE_Registry::instance()->CFG->core;
430 430
         foreach ($critical_pages as $critical_page) {
431 431
             // is critical page ID set in config ?
432 432
             if ($EE_Core_Config->{$critical_page['id']} !== false) {
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
             ) {
459 459
                 // update Config with post ID
460 460
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
461
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
461
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
462 462
                     $msg = esc_html__(
463 463
                         'The Event Espresso critical page configuration settings could not be updated.',
464 464
                         'event_espresso'
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
482 482
                         'event_espresso'
483 483
                     ),
484
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
484
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
485 485
                     . esc_html__('Event Espresso Critical Pages Settings', 'event_espresso')
486 486
                     . '</a>'
487 487
                 )
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
     public static function get_page_by_ee_shortcode($ee_shortcode)
507 507
     {
508 508
         global $wpdb;
509
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
509
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
510 510
         $post_id                       =
511 511
             $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
512 512
         if ($post_id) {
@@ -531,11 +531,11 @@  discard block
 block discarded – undo
531 531
             'post_status'    => 'publish',
532 532
             'post_type'      => 'page',
533 533
             'comment_status' => 'closed',
534
-            'post_content'   => '[' . $critical_page['code'] . ']',
534
+            'post_content'   => '['.$critical_page['code'].']',
535 535
         ];
536 536
 
537 537
         $post_id = wp_insert_post($post_args);
538
-        if (! $post_id) {
538
+        if ( ! $post_id) {
539 539
             $msg = sprintf(
540 540
                 esc_html__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
541 541
                 $critical_page['name']
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
             return $critical_page;
545 545
         }
546 546
         // get newly created post's details
547
-        if (! $critical_page['post'] = get_post($post_id)) {
547
+        if ( ! $critical_page['post'] = get_post($post_id)) {
548 548
             $msg = sprintf(
549 549
                 esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
550 550
                 $critical_page['name']
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
     public static function get_default_creator_id()
570 570
     {
571 571
         global $wpdb;
572
-        if (! empty(self::$_default_creator_id)) {
572
+        if ( ! empty(self::$_default_creator_id)) {
573 573
             return self::$_default_creator_id;
574 574
         }/**/
575 575
         $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         $capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
586 586
         $query            = $wpdb->prepare(
587 587
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
588
-            '%' . $role_to_check . '%'
588
+            '%'.$role_to_check.'%'
589 589
         );
590 590
         $user_id          = $wpdb->get_var($query);
591 591
         $user_id          = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
@@ -622,8 +622,8 @@  discard block
 block discarded – undo
622 622
             return;
623 623
         }
624 624
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
625
-        if (! function_exists('dbDelta')) {
626
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
625
+        if ( ! function_exists('dbDelta')) {
626
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
627 627
         }
628 628
         $tableAnalysis = EEH_Activation::getTableAnalysis();
629 629
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -632,9 +632,9 @@  discard block
 block discarded – undo
632 632
             // ok, delete the table... but ONLY if it's empty
633 633
             $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
634 634
             // table is NOT empty, are you SURE you want to delete this table ???
635
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
635
+            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
636 636
                 EEH_Activation::getTableManager()->dropTable($wp_table_name);
637
-            } elseif (! $deleted_safely) {
637
+            } elseif ( ! $deleted_safely) {
638 638
                 // so we should be more cautious rather than just dropping tables so easily
639 639
                 error_log(
640 640
                     sprintf(
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
         EE_Registry::instance()->load_core('Data_Migration_Manager');
756 756
         // find the migration script that sets the database to be compatible with the code
757 757
         $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
758
-        if (! $dms_name) {
758
+        if ( ! $dms_name) {
759 759
             EE_Error::add_error(
760 760
                 esc_html__(
761 761
                     'Could not determine most up-to-date data migration script from which to pull database schema
@@ -815,13 +815,13 @@  discard block
 block discarded – undo
815 815
             // reset values array
816 816
             $QSG_values = [];
817 817
             // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
818
-            if (! in_array("$QSG_system", $question_groups)) {
818
+            if ( ! in_array("$QSG_system", $question_groups)) {
819 819
                 // add it
820 820
                 switch ($QSG_system) {
821 821
                     case 1:
822 822
                         $QSG_values = [
823 823
                             'QSG_name'            => esc_html__('Personal Information', 'event_espresso'),
824
-                            'QSG_identifier'      => 'personal-information-' . time(),
824
+                            'QSG_identifier'      => 'personal-information-'.time(),
825 825
                             'QSG_desc'            => '',
826 826
                             'QSG_order'           => 1,
827 827
                             'QSG_show_group_name' => 1,
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
                     case 2:
834 834
                         $QSG_values = [
835 835
                             'QSG_name'            => esc_html__('Address Information', 'event_espresso'),
836
-                            'QSG_identifier'      => 'address-information-' . time(),
836
+                            'QSG_identifier'      => 'address-information-'.time(),
837 837
                             'QSG_desc'            => '',
838 838
                             'QSG_order'           => 2,
839 839
                             'QSG_show_group_name' => 1,
@@ -844,14 +844,14 @@  discard block
 block discarded – undo
844 844
                         break;
845 845
                 }
846 846
                 // make sure we have some values before inserting them
847
-                if (! empty($QSG_values)) {
847
+                if ( ! empty($QSG_values)) {
848 848
                     // insert system question
849 849
                     $wpdb->insert(
850 850
                         $table_name,
851 851
                         $QSG_values,
852 852
                         ['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d']
853 853
                     );
854
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
854
+                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
855 855
                 }
856 856
             }
857 857
         }
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
         $address_system_group_questions  = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
867 867
         $system_questions_not_in_group   = ['email_confirm'];
868 868
         // merge all of the system questions we should have
869
-        $QST_systems       = array_merge(
869
+        $QST_systems = array_merge(
870 870
             $personal_system_group_questions,
871 871
             $address_system_group_questions,
872 872
             $system_questions_not_in_group
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
             // reset values array
879 879
             $QST_values = [];
880 880
             // if we don't have what we should have
881
-            if (! in_array($QST_system, $questions)) {
881
+            if ( ! in_array($QST_system, $questions)) {
882 882
                 // add it
883 883
                 switch ($QST_system) {
884 884
                     case 'fname':
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
                         ];
1055 1055
                         break;
1056 1056
                 }
1057
-                if (! empty($QST_values)) {
1057
+                if ( ! empty($QST_values)) {
1058 1058
                     // insert system question
1059 1059
                     $wpdb->insert(
1060 1060
                         $table_name,
@@ -1072,8 +1072,8 @@  discard block
 block discarded – undo
1072 1072
                         // QST_system should not be assigned to any group
1073 1073
                         continue;
1074 1074
                     }
1075
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1076
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1075
+                    if (isset($QSG_IDs[$system_question_we_want])) {
1076
+                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1077 1077
                     } else {
1078 1078
                         $id_col = EEM_Question_Group::instance()
1079 1079
                                                     ->get_col([['QSG_system' => $system_question_we_want]]);
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
      */
1123 1123
     public static function insert_default_payment_methods()
1124 1124
     {
1125
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1125
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1126 1126
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1127 1127
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1128 1128
         } else {
@@ -1258,7 +1258,7 @@  discard block
 block discarded – undo
1258 1258
                         $active_messenger->name,
1259 1259
                         $default_message_type_name_for_messenger
1260 1260
                     )
1261
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1261
+                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1262 1262
                 ) {
1263 1263
                     continue;
1264 1264
                 }
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
                 false
1272 1272
             );
1273 1273
             // activate the templates for these message types
1274
-            if (! empty($default_message_type_names_to_activate)) {
1274
+            if ( ! empty($default_message_type_names_to_activate)) {
1275 1275
                 $templates_created = EEH_MSG_Template::generate_new_templates(
1276 1276
                     $active_messenger->name,
1277 1277
                     $default_message_type_names_for_messenger,
@@ -1305,13 +1305,13 @@  discard block
 block discarded – undo
1305 1305
             // verify the default message types match an installed message type.
1306 1306
             foreach ($default_message_type_names_for_messenger as $key => $name) {
1307 1307
                 if (
1308
-                    ! isset($installed_message_types[ $name ])
1308
+                    ! isset($installed_message_types[$name])
1309 1309
                     || $message_resource_manager->has_message_type_been_activated_for_messenger(
1310 1310
                         $name,
1311 1311
                         $messenger_to_generate->name
1312 1312
                     )
1313 1313
                 ) {
1314
-                    unset($default_message_type_names_for_messenger[ $key ]);
1314
+                    unset($default_message_type_names_for_messenger[$key]);
1315 1315
                 }
1316 1316
             }
1317 1317
             // in previous iterations, the active_messengers option in the db
@@ -1325,7 +1325,7 @@  discard block
 block discarded – undo
1325 1325
                 false
1326 1326
             );
1327 1327
             // create any templates needing created (or will reactivate templates already generated as necessary).
1328
-            if (! empty($default_message_type_names_for_messenger)) {
1328
+            if ( ! empty($default_message_type_names_for_messenger)) {
1329 1329
                 $templates_generated = EEH_MSG_Template::generate_new_templates(
1330 1330
                     $messenger_to_generate->name,
1331 1331
                     $default_message_type_names_for_messenger,
@@ -1361,12 +1361,12 @@  discard block
 block discarded – undo
1361 1361
             // and has never been activated
1362 1362
             if (
1363 1363
                 ! $installed_messenger->activate_on_install
1364
-                || isset($active_messengers[ $installed_messenger->name ])
1365
-                || isset($has_activated[ $installed_messenger->name ])
1364
+                || isset($active_messengers[$installed_messenger->name])
1365
+                || isset($has_activated[$installed_messenger->name])
1366 1366
             ) {
1367 1367
                 continue;
1368 1368
             }
1369
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1369
+            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1370 1370
         }
1371 1371
         return $messengers_to_generate;
1372 1372
     }
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
             }
1424 1424
         }
1425 1425
         // get all our CPTs
1426
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1426
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1427 1427
         $cpt_ids = $wpdb->get_col($query);
1428 1428
         // delete each post meta and term relations too
1429 1429
         foreach ($cpt_ids as $post_id) {
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
                                 || ! $table->is_global()// not main site,but not global either. nuke it
1456 1456
                             )
1457 1457
                         ) {
1458
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1458
+                            $tables[$table->get_table_name()] = $table->get_table_name();
1459 1459
                         }
1460 1460
                     }
1461 1461
                 }
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
             'esp_rule',
1473 1473
         ];
1474 1474
         foreach ($tables_without_models as $table) {
1475
-            $tables[ $table ] = $table;
1475
+            $tables[$table] = $table;
1476 1476
         }
1477 1477
         return EEH_Activation::getTableManager()->dropTables($tables);
1478 1478
     }
@@ -1549,14 +1549,14 @@  discard block
 block discarded – undo
1549 1549
         $undeleted_options = [];
1550 1550
         foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1551 1551
             if ($no_wildcard) {
1552
-                if (! delete_option($option_name)) {
1552
+                if ( ! delete_option($option_name)) {
1553 1553
                     $undeleted_options[] = $option_name;
1554 1554
                 }
1555 1555
             } else {
1556 1556
                 $option_names_to_delete_from_wildcard =
1557 1557
                     $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1558 1558
                 foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1559
-                    if (! delete_option($option_name_from_wildcard)) {
1559
+                    if ( ! delete_option($option_name_from_wildcard)) {
1560 1560
                         $undeleted_options[] = $option_name_from_wildcard;
1561 1561
                     }
1562 1562
                 }
@@ -1568,20 +1568,20 @@  discard block
 block discarded – undo
1568 1568
             $db_update_sans_ee4 = [];
1569 1569
             foreach ($espresso_db_update as $version => $times_activated) {
1570 1570
                 if ((string) $version[0] === '3') {// if its NON EE4
1571
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1571
+                    $db_update_sans_ee4[$version] = $times_activated;
1572 1572
                 }
1573 1573
             }
1574 1574
             update_option('espresso_db_update', $db_update_sans_ee4);
1575 1575
         }
1576 1576
         $errors = '';
1577
-        if (! empty($undeleted_options)) {
1577
+        if ( ! empty($undeleted_options)) {
1578 1578
             $errors .= sprintf(
1579 1579
                 esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1580 1580
                 '<br/>',
1581 1581
                 implode(',<br/>', $undeleted_options)
1582 1582
             );
1583 1583
         }
1584
-        if (! empty($errors)) {
1584
+        if ( ! empty($errors)) {
1585 1585
             EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1586 1586
         }
1587 1587
     }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.39.rc.000');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.39.rc.000');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/events/Event_Categories_Admin_List_Table.class.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -11,179 +11,179 @@
 block discarded – undo
11 11
  */
12 12
 class Event_Categories_Admin_List_Table extends EE_Admin_List_Table
13 13
 {
14
-    /**
15
-     * @var Events_Admin_Page $_admin_page
16
-     */
17
-    protected $_admin_page;
18
-
19
-
20
-    /**
21
-     * @throws EE_Error
22
-     */
23
-    protected function _setup_data()
24
-    {
25
-        $this->_data           = $this->_admin_page->get_categories($this->_per_page, $this->_current_page);
26
-        $this->_all_data_count = EEM_Term_Taxonomy::instance()->count(
27
-            [['taxonomy' => 'espresso_event_categories']]
28
-        );
29
-    }
30
-
31
-
32
-    protected function _set_properties()
33
-    {
34
-        $this->_wp_list_args = [
35
-            'singular' => esc_html__('event category', 'event_espresso'),
36
-            'plural'   => esc_html__('event categories', 'event_espresso'),
37
-            'ajax'     => true, // for now,
38
-            'screen'   => $this->_admin_page->get_current_screen()->id,
39
-        ];
40
-
41
-        $this->_columns = [
42
-            'cb'        => '<input type="checkbox" />',
43
-            'id'        => esc_html__('ID', 'event_espresso'),
44
-            'name'      => esc_html__('Name', 'event_espresso'),
45
-            'shortcode' => esc_html__('Shortcode', 'event_espresso'),
46
-            'count'     => esc_html__('Events', 'event_espresso'),
47
-        ];
48
-
49
-        $this->_sortable_columns = [
50
-            'id'    => ['Term.term_id' => true],
51
-            'name'  => ['Term.slug' => false],
52
-            'count' => ['term_count' => false],
53
-        ];
54
-
55
-        $this->_primary_column = 'id';
56
-
57
-        $this->_hidden_columns = [];
58
-    }
59
-
60
-
61
-    protected function _get_table_filters()
62
-    {
63
-        return [];
64
-    }
65
-
66
-
67
-    protected function _add_view_counts()
68
-    {
69
-        $this->_views['all']['count'] = $this->_all_data_count;
70
-    }
71
-
72
-
73
-    public function column_cb($item)
74
-    {
75
-        return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id'));
76
-    }
77
-
78
-
79
-    /**
80
-     * @param EE_Term_Taxonomy $item
81
-     * @return string
82
-     * @throws EE_Error
83
-     * @throws ReflectionException
84
-     */
85
-    public function column_id(EE_Term_Taxonomy $item)
86
-    {
87
-        $category_name = $item->get_first_related('Term')->get('name');
88
-        $content       = $item->get('term_id');
89
-        $content       .= ' <span class="show-on-mobile-view-only">' . $category_name . '</span>';
90
-        return $content;
91
-    }
92
-
93
-
94
-    /**
95
-     * @param EE_Term_Taxonomy $item
96
-     * @return string
97
-     * @throws EE_Error
98
-     * @throws ReflectionException
99
-     */
100
-    public function column_name(EE_Term_Taxonomy $item)
101
-    {
102
-        $edit_query_args = [
103
-            'action'     => 'edit_category',
104
-            'EVT_CAT_ID' => $item->get('term_id'),
105
-        ];
106
-
107
-        $delete_query_args = [
108
-            'action'     => 'delete_category',
109
-            'EVT_CAT_ID' => $item->get('term_id'),
110
-        ];
111
-
112
-        $edit_link   = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
113
-        $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL);
114
-        $view_link   = get_term_link($item->get('term_id'));
115
-
116
-        $term_name = $item->get_first_related('Term')->get('name');
117
-
118
-        $edit_category_label = sprintf(
119
-            /* translators: The name of the event category */
120
-            esc_attr__(
121
-                'Edit Category (%s)',
122
-                'event_espresso'
123
-            ),
124
-            $term_name
125
-        );
126
-        $actions['edit']     = '
14
+	/**
15
+	 * @var Events_Admin_Page $_admin_page
16
+	 */
17
+	protected $_admin_page;
18
+
19
+
20
+	/**
21
+	 * @throws EE_Error
22
+	 */
23
+	protected function _setup_data()
24
+	{
25
+		$this->_data           = $this->_admin_page->get_categories($this->_per_page, $this->_current_page);
26
+		$this->_all_data_count = EEM_Term_Taxonomy::instance()->count(
27
+			[['taxonomy' => 'espresso_event_categories']]
28
+		);
29
+	}
30
+
31
+
32
+	protected function _set_properties()
33
+	{
34
+		$this->_wp_list_args = [
35
+			'singular' => esc_html__('event category', 'event_espresso'),
36
+			'plural'   => esc_html__('event categories', 'event_espresso'),
37
+			'ajax'     => true, // for now,
38
+			'screen'   => $this->_admin_page->get_current_screen()->id,
39
+		];
40
+
41
+		$this->_columns = [
42
+			'cb'        => '<input type="checkbox" />',
43
+			'id'        => esc_html__('ID', 'event_espresso'),
44
+			'name'      => esc_html__('Name', 'event_espresso'),
45
+			'shortcode' => esc_html__('Shortcode', 'event_espresso'),
46
+			'count'     => esc_html__('Events', 'event_espresso'),
47
+		];
48
+
49
+		$this->_sortable_columns = [
50
+			'id'    => ['Term.term_id' => true],
51
+			'name'  => ['Term.slug' => false],
52
+			'count' => ['term_count' => false],
53
+		];
54
+
55
+		$this->_primary_column = 'id';
56
+
57
+		$this->_hidden_columns = [];
58
+	}
59
+
60
+
61
+	protected function _get_table_filters()
62
+	{
63
+		return [];
64
+	}
65
+
66
+
67
+	protected function _add_view_counts()
68
+	{
69
+		$this->_views['all']['count'] = $this->_all_data_count;
70
+	}
71
+
72
+
73
+	public function column_cb($item)
74
+	{
75
+		return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id'));
76
+	}
77
+
78
+
79
+	/**
80
+	 * @param EE_Term_Taxonomy $item
81
+	 * @return string
82
+	 * @throws EE_Error
83
+	 * @throws ReflectionException
84
+	 */
85
+	public function column_id(EE_Term_Taxonomy $item)
86
+	{
87
+		$category_name = $item->get_first_related('Term')->get('name');
88
+		$content       = $item->get('term_id');
89
+		$content       .= ' <span class="show-on-mobile-view-only">' . $category_name . '</span>';
90
+		return $content;
91
+	}
92
+
93
+
94
+	/**
95
+	 * @param EE_Term_Taxonomy $item
96
+	 * @return string
97
+	 * @throws EE_Error
98
+	 * @throws ReflectionException
99
+	 */
100
+	public function column_name(EE_Term_Taxonomy $item)
101
+	{
102
+		$edit_query_args = [
103
+			'action'     => 'edit_category',
104
+			'EVT_CAT_ID' => $item->get('term_id'),
105
+		];
106
+
107
+		$delete_query_args = [
108
+			'action'     => 'delete_category',
109
+			'EVT_CAT_ID' => $item->get('term_id'),
110
+		];
111
+
112
+		$edit_link   = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
113
+		$delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL);
114
+		$view_link   = get_term_link($item->get('term_id'));
115
+
116
+		$term_name = $item->get_first_related('Term')->get('name');
117
+
118
+		$edit_category_label = sprintf(
119
+			/* translators: The name of the event category */
120
+			esc_attr__(
121
+				'Edit Category (%s)',
122
+				'event_espresso'
123
+			),
124
+			$term_name
125
+		);
126
+		$actions['edit']     = '
127 127
             <a href="' . $edit_link . '" aria-label="' . $edit_category_label . '">
128 128
                 ' . esc_html__('Edit', 'event_espresso') . '
129 129
             </a>';
130 130
 
131
-        $delete_category_label = sprintf(
132
-            /* translators: The name of the event category */
133
-            esc_attr__(
134
-                'Delete Category (%s)',
135
-                'event_espresso'
136
-            ),
137
-            $term_name
138
-        );
139
-        $actions['delete']     = '
131
+		$delete_category_label = sprintf(
132
+			/* translators: The name of the event category */
133
+			esc_attr__(
134
+				'Delete Category (%s)',
135
+				'event_espresso'
136
+			),
137
+			$term_name
138
+		);
139
+		$actions['delete']     = '
140 140
             <a href="' . $delete_link . '" aria-label="' . $delete_category_label . '">
141 141
                 ' . esc_html__('Delete', 'event_espresso') . '
142 142
             </a>';
143 143
 
144
-        $view_category_label = sprintf(
145
-            /* translators: %s: event category name */
146
-            esc_html__('View &#8220;%s&#8221; archive', 'event_espresso'),
147
-            $item->get_first_related('Term')->get('name')
148
-        );
149
-        $actions['view']     = '
144
+		$view_category_label = sprintf(
145
+			/* translators: %s: event category name */
146
+			esc_html__('View &#8220;%s&#8221; archive', 'event_espresso'),
147
+			$item->get_first_related('Term')->get('name')
148
+		);
149
+		$actions['view']     = '
150 150
             <a href="' . $view_link . '" aria-label="' . $view_category_label . '">
151 151
                 ' . esc_html__('View', 'event_espresso') . '
152 152
             </a>';
153 153
 
154
-        $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $term_name . '</a></strong>';
155
-        $content .= $this->row_actions($actions);
156
-        return $content;
157
-    }
158
-
159
-
160
-    /**
161
-     * @param EE_Term_Taxonomy $item
162
-     * @return string
163
-     * @throws EE_Error
164
-     * @throws ReflectionException
165
-     */
166
-    public function column_shortcode(EE_Term_Taxonomy $item)
167
-    {
168
-        return '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']';
169
-    }
170
-
171
-
172
-    /**
173
-     * @param EE_Term_Taxonomy $item
174
-     * @return string
175
-     * @throws EE_Error
176
-     * @throws ReflectionException
177
-     */
178
-    public function column_count(EE_Term_Taxonomy $item)
179
-    {
180
-        $category_url = EE_Admin_Page::add_query_args_and_nonce(
181
-            [
182
-                'action'  => 'default',
183
-                'EVT_CAT' => $item->get_first_related('Term')->ID(),
184
-            ],
185
-            EVENTS_ADMIN_URL
186
-        );
187
-        return '<a href="' . $category_url . '">' . $item->get('term_count') . '</a>';
188
-    }
154
+		$content = '<strong><a class="row-title" href="' . $edit_link . '">' . $term_name . '</a></strong>';
155
+		$content .= $this->row_actions($actions);
156
+		return $content;
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param EE_Term_Taxonomy $item
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 * @throws ReflectionException
165
+	 */
166
+	public function column_shortcode(EE_Term_Taxonomy $item)
167
+	{
168
+		return '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']';
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param EE_Term_Taxonomy $item
174
+	 * @return string
175
+	 * @throws EE_Error
176
+	 * @throws ReflectionException
177
+	 */
178
+	public function column_count(EE_Term_Taxonomy $item)
179
+	{
180
+		$category_url = EE_Admin_Page::add_query_args_and_nonce(
181
+			[
182
+				'action'  => 'default',
183
+				'EVT_CAT' => $item->get_first_related('Term')->ID(),
184
+			],
185
+			EVENTS_ADMIN_URL
186
+		);
187
+		return '<a href="' . $category_url . '">' . $item->get('term_count') . '</a>';
188
+	}
189 189
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     {
87 87
         $category_name = $item->get_first_related('Term')->get('name');
88 88
         $content       = $item->get('term_id');
89
-        $content       .= ' <span class="show-on-mobile-view-only">' . $category_name . '</span>';
89
+        $content .= ' <span class="show-on-mobile-view-only">'.$category_name.'</span>';
90 90
         return $content;
91 91
     }
92 92
 
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
             ),
124 124
             $term_name
125 125
         );
126
-        $actions['edit']     = '
127
-            <a href="' . $edit_link . '" aria-label="' . $edit_category_label . '">
128
-                ' . esc_html__('Edit', 'event_espresso') . '
126
+        $actions['edit'] = '
127
+            <a href="' . $edit_link.'" aria-label="'.$edit_category_label.'">
128
+                ' . esc_html__('Edit', 'event_espresso').'
129 129
             </a>';
130 130
 
131 131
         $delete_category_label = sprintf(
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
             ),
137 137
             $term_name
138 138
         );
139
-        $actions['delete']     = '
140
-            <a href="' . $delete_link . '" aria-label="' . $delete_category_label . '">
141
-                ' . esc_html__('Delete', 'event_espresso') . '
139
+        $actions['delete'] = '
140
+            <a href="' . $delete_link.'" aria-label="'.$delete_category_label.'">
141
+                ' . esc_html__('Delete', 'event_espresso').'
142 142
             </a>';
143 143
 
144 144
         $view_category_label = sprintf(
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
             esc_html__('View &#8220;%s&#8221; archive', 'event_espresso'),
147 147
             $item->get_first_related('Term')->get('name')
148 148
         );
149
-        $actions['view']     = '
150
-            <a href="' . $view_link . '" aria-label="' . $view_category_label . '">
151
-                ' . esc_html__('View', 'event_espresso') . '
149
+        $actions['view'] = '
150
+            <a href="' . $view_link.'" aria-label="'.$view_category_label.'">
151
+                ' . esc_html__('View', 'event_espresso').'
152 152
             </a>';
153 153
 
154
-        $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $term_name . '</a></strong>';
154
+        $content = '<strong><a class="row-title" href="'.$edit_link.'">'.$term_name.'</a></strong>';
155 155
         $content .= $this->row_actions($actions);
156 156
         return $content;
157 157
     }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      */
166 166
     public function column_shortcode(EE_Term_Taxonomy $item)
167 167
     {
168
-        return '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']';
168
+        return '[ESPRESSO_EVENTS category_slug='.$item->get_first_related('Term')->get('slug').']';
169 169
     }
170 170
 
171 171
 
@@ -184,6 +184,6 @@  discard block
 block discarded – undo
184 184
             ],
185 185
             EVENTS_ADMIN_URL
186 186
         );
187
-        return '<a href="' . $category_url . '">' . $item->get('term_count') . '</a>';
187
+        return '<a href="'.$category_url.'">'.$item->get('term_count').'</a>';
188 188
     }
189 189
 }
Please login to merge, or discard this patch.