Completed
Branch master (fda5c4)
by
unknown
06:58 queued 04:53
created
modules/ticket_selector/TicketSelectorRowStandard.php 2 patches
Indentation   +365 added lines, -365 removed lines patch added patch discarded remove patch
@@ -19,370 +19,370 @@
 block discarded – undo
19 19
  */
20 20
 class TicketSelectorRowStandard extends TicketSelectorRow
21 21
 {
22
-    /**
23
-     * @var TicketDetails
24
-     */
25
-    protected $ticket_details;
26
-
27
-    /**
28
-     * @var EE_Ticket_Selector_Config
29
-     */
30
-    protected $template_settings;
31
-
32
-    /**
33
-     * @var EE_Tax_Config
34
-     */
35
-    protected $tax_settings;
36
-
37
-    /**
38
-     * @var bool
39
-     */
40
-    protected $prices_displayed_including_taxes;
41
-
42
-    /**
43
-     * @var int
44
-     */
45
-    protected $row;
46
-
47
-    /**
48
-     * @var int
49
-     */
50
-    protected $cols;
51
-
52
-    /**
53
-     * @var boolean
54
-     */
55
-    protected $hidden_input_qty = false;
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    protected $ticket_datetime_classes;
61
-
62
-
63
-    /**
64
-     * TicketDetails constructor.
65
-     *
66
-     * @param TicketDetails $ticket_details
67
-     * @param EE_Tax_Config $tax_settings
68
-     * @param int           $total_tickets
69
-     * @param int           $max_attendees
70
-     * @param int           $row
71
-     * @param int           $cols
72
-     * @param boolean       $required_ticket_sold_out
73
-     * @param string        $event_status
74
-     * @param string        $ticket_datetime_classes
75
-     * @throws EE_Error
76
-     * @throws UnexpectedEntityException
77
-     */
78
-    public function __construct(
79
-        TicketDetails $ticket_details,
80
-        EE_Tax_Config $tax_settings,
81
-        $total_tickets,
82
-        $max_attendees,
83
-        $row,
84
-        $cols,
85
-        $required_ticket_sold_out,
86
-        $event_status,
87
-        $ticket_datetime_classes
88
-    ) {
89
-        $this->ticket_details = $ticket_details;
90
-        $this->template_settings = $ticket_details->getTemplateSettings();
91
-        $this->tax_settings = $tax_settings;
92
-        $this->row = $row;
93
-        $this->cols = $cols;
94
-        $this->ticket_datetime_classes = $ticket_datetime_classes;
95
-        parent::__construct(
96
-            $ticket_details->getTicket(),
97
-            $max_attendees,
98
-            $ticket_details->getDateFormat(),
99
-            $event_status,
100
-            $required_ticket_sold_out,
101
-            $total_tickets
102
-        );
103
-    }
104
-
105
-
106
-    /**
107
-     * other ticket rows will need to know if a required ticket is sold out,
108
-     * so that they are not offered for sale
109
-     *
110
-     * @return boolean
111
-     */
112
-    public function getRequiredTicketSoldOut()
113
-    {
114
-        return $this->required_ticket_sold_out;
115
-    }
116
-
117
-
118
-    /**
119
-     * @return int
120
-     */
121
-    public function getCols()
122
-    {
123
-        return $this->cols;
124
-    }
125
-
126
-
127
-    /**
128
-     * getHtml
129
-     *
130
-     * @return string
131
-     * @throws EE_Error
132
-     * @throws ReflectionException
133
-     */
134
-    public function getHtml()
135
-    {
136
-        $this->min = 0;
137
-        $this->max = $this->ticket->max();
138
-        $remaining = $this->ticket->remaining();
139
-        $this->setTicketMinAndMax($remaining);
140
-        // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
141
-        $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
142
-            ? $this->ticket->start_date()
143
-            : $this->required_ticket_sold_out;
144
-        $this->setTicketPriceDetails();
145
-        $this->setTicketStatusClasses($remaining);
146
-        $filtered_row_html = $this->getFilteredRowHtml();
147
-        if ($filtered_row_html !== false) {
148
-            return $filtered_row_html;
149
-        }
150
-        $ticket_selector_row_html = EEH_HTML::tr(
151
-            '',
152
-            '',
153
-            "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} "
154
-            . espresso_get_object_css_class($this->ticket)
155
-        );
156
-        $filtered_row_content = $this->getFilteredRowContents();
157
-        if ($filtered_row_content !== false) {
158
-            if ($this->max_attendees === 1) {
159
-                return $ticket_selector_row_html
160
-                       . $filtered_row_content
161
-                       . $this->ticketQtyAndIdHiddenInputs()
162
-                       . EEH_HTML::trx();
163
-            }
164
-            return $ticket_selector_row_html
165
-                   . $filtered_row_content
166
-                   . EEH_HTML::trx();
167
-        }
168
-        $this->hidden_input_qty = $this->max_attendees > 1;
169
-
170
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
171
-        $ticket_selector_row_html .= $this->ticketPriceTableCell();
172
-        $ticket_selector_row_html .= EEH_HTML::td(
173
-            '',
174
-            '',
175
-            'tckt-slctr-tbl-td-qty cntr',
176
-            '',
177
-            'headers="quantity-' . $this->EVT_ID . '"'
178
-        );
179
-        $this->setTicketStatusDisplay($remaining);
180
-        if (empty($this->ticket_status_display)) {
181
-            if ($this->max_attendees === 1) {
182
-                // only ONE attendee is allowed to register at a time
183
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
184
-            } elseif ($this->max > 0) {
185
-                $ticket_selector_row_html .= $this->ticketQuantitySelector();
186
-            }
187
-        }
188
-        $ticket_selector_row_html .= $this->ticket_status_display;
189
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
190
-        $ticket_selector_row_html .= $this->ticket_details->display(
191
-            $this->ticket_price,
192
-            $remaining,
193
-            $this->cols
194
-        );
195
-        $ticket_selector_row_html .= EEH_HTML::tdx();
196
-        $ticket_selector_row_html .= EEH_HTML::trx();
197
-
198
-
199
-        $this->row++;
200
-        return $ticket_selector_row_html;
201
-    }
202
-
203
-
204
-    /**
205
-     * getTicketPriceDetails
206
-     *
207
-     * @return void
208
-     * @throws EE_Error
209
-     * @throws ReflectionException
210
-     */
211
-    protected function setTicketPriceDetails()
212
-    {
213
-        $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes
214
-            ? $this->ticket->get_ticket_total_with_taxes()
215
-            : $this->ticket->get_ticket_subtotal();
216
-        $this->ticket_bundle = false;
217
-        $ticket_min = $this->ticket->min();
218
-        // for ticket bundles, set min and max qty the same
219
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
220
-            $this->ticket_price *= $ticket_min;
221
-            $this->ticket_bundle = true;
222
-        }
223
-        $this->ticket_price = apply_filters(
224
-            'FHEE__ticket_selector_chart_template__ticket_price',
225
-            $this->ticket_price,
226
-            $this->ticket
227
-        );
228
-    }
229
-
230
-
231
-    /**
232
-     * ticketNameTableCell
233
-     *
234
-     * @return string
235
-     * @throws EE_Error
236
-     * @throws ReflectionException
237
-     */
238
-    protected function ticketNameTableCell()
239
-    {
240
-        $html = EEH_HTML::td(
241
-            '',
242
-            '',
243
-            'tckt-slctr-tbl-td-name',
244
-            '',
245
-            'headers="details-' . $this->EVT_ID . '"'
246
-        );
247
-        $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
248
-        $html .= $this->ticket_details->getShowHideLinks();
249
-        if ($this->ticket->required()) {
250
-            $html .= EEH_HTML::p(
251
-                apply_filters(
252
-                    'FHEE__ticket_selector_chart_template__ticket_required_message',
253
-                    esc_html__('This ticket is required and must be purchased.', 'event_espresso')
254
-                ),
255
-                '',
256
-                'ticket-required-pg'
257
-            );
258
-        }
259
-        $html .= EEH_HTML::tdx();
260
-        return $html;
261
-    }
262
-
263
-
264
-    /**
265
-     * ticketPriceTableCell
266
-     *
267
-     * @return string
268
-     * @throws EE_Error
269
-     * @throws ReflectionException
270
-     */
271
-    protected function ticketPriceTableCell()
272
-    {
273
-        $html = '';
274
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
275
-            $html .= EEH_HTML::td(
276
-                '',
277
-                '',
278
-                'tckt-slctr-tbl-td-price jst-rght',
279
-                '',
280
-                'headers="price-' . $this->EVT_ID . '"'
281
-            );
282
-            $html .= EEH_Template::format_currency($this->ticket_price);
283
-            $html .= $this->ticket->taxable()
284
-                ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text')
285
-                : '';
286
-            $html .= ' ';
287
-            // phpcs:disable WordPress.WP.I18n.NoEmptyStrings
288
-            $html .= EEH_HTML::span(
289
-                $this->ticket_bundle
290
-                    ? apply_filters(
291
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
292
-                        esc_html__(' / bundle', 'event_espresso')
293
-                    )
294
-                    : apply_filters(
295
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
296
-                        esc_html__('', 'event_espresso')
297
-                    ),
298
-                '',
299
-                'smaller-text no-bold'
300
-            );
301
-            $html .= ' ';
302
-            $html .= EEH_HTML::tdx();
303
-            $this->cols++;
304
-        }
305
-        return $html;
306
-    }
307
-
308
-
309
-    /**
310
-     * onlyOneAttendeeCanRegister
311
-     *
312
-     * @return string
313
-     * @throws EE_Error
314
-     * @throws ReflectionException
315
-     */
316
-    protected function onlyOneAttendeeCanRegister()
317
-    {
318
-        $this->hidden_input_qty = false;
319
-        // display submit button since we have tickets available
320
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
321
-
322
-        $TKT   = $this->ticket->ID();
323
-        $name  = "tkt-slctr-qty-{$this->EVT_ID}";
324
-        $class = "ticket-selector-tbl-qty-slct";
325
-        $id    = "{$class}-{$this->EVT_ID}-{$this->row}";
326
-        $checked = $this->total_tickets === 1 ? ' checked' : '';
327
-
328
-        $html = "<label class='ee-a11y-screen-reader-text' for='" . esc_attr($id) . "'>"
329
-                . esc_html__('Select this ticket', 'event_espresso') . "</label>";
330
-        $html .= "<input type='radio' {$checked} name='" . esc_attr($name) . "' id='" . esc_attr($id) . "'
22
+	/**
23
+	 * @var TicketDetails
24
+	 */
25
+	protected $ticket_details;
26
+
27
+	/**
28
+	 * @var EE_Ticket_Selector_Config
29
+	 */
30
+	protected $template_settings;
31
+
32
+	/**
33
+	 * @var EE_Tax_Config
34
+	 */
35
+	protected $tax_settings;
36
+
37
+	/**
38
+	 * @var bool
39
+	 */
40
+	protected $prices_displayed_including_taxes;
41
+
42
+	/**
43
+	 * @var int
44
+	 */
45
+	protected $row;
46
+
47
+	/**
48
+	 * @var int
49
+	 */
50
+	protected $cols;
51
+
52
+	/**
53
+	 * @var boolean
54
+	 */
55
+	protected $hidden_input_qty = false;
56
+
57
+	/**
58
+	 * @var string
59
+	 */
60
+	protected $ticket_datetime_classes;
61
+
62
+
63
+	/**
64
+	 * TicketDetails constructor.
65
+	 *
66
+	 * @param TicketDetails $ticket_details
67
+	 * @param EE_Tax_Config $tax_settings
68
+	 * @param int           $total_tickets
69
+	 * @param int           $max_attendees
70
+	 * @param int           $row
71
+	 * @param int           $cols
72
+	 * @param boolean       $required_ticket_sold_out
73
+	 * @param string        $event_status
74
+	 * @param string        $ticket_datetime_classes
75
+	 * @throws EE_Error
76
+	 * @throws UnexpectedEntityException
77
+	 */
78
+	public function __construct(
79
+		TicketDetails $ticket_details,
80
+		EE_Tax_Config $tax_settings,
81
+		$total_tickets,
82
+		$max_attendees,
83
+		$row,
84
+		$cols,
85
+		$required_ticket_sold_out,
86
+		$event_status,
87
+		$ticket_datetime_classes
88
+	) {
89
+		$this->ticket_details = $ticket_details;
90
+		$this->template_settings = $ticket_details->getTemplateSettings();
91
+		$this->tax_settings = $tax_settings;
92
+		$this->row = $row;
93
+		$this->cols = $cols;
94
+		$this->ticket_datetime_classes = $ticket_datetime_classes;
95
+		parent::__construct(
96
+			$ticket_details->getTicket(),
97
+			$max_attendees,
98
+			$ticket_details->getDateFormat(),
99
+			$event_status,
100
+			$required_ticket_sold_out,
101
+			$total_tickets
102
+		);
103
+	}
104
+
105
+
106
+	/**
107
+	 * other ticket rows will need to know if a required ticket is sold out,
108
+	 * so that they are not offered for sale
109
+	 *
110
+	 * @return boolean
111
+	 */
112
+	public function getRequiredTicketSoldOut()
113
+	{
114
+		return $this->required_ticket_sold_out;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function getCols()
122
+	{
123
+		return $this->cols;
124
+	}
125
+
126
+
127
+	/**
128
+	 * getHtml
129
+	 *
130
+	 * @return string
131
+	 * @throws EE_Error
132
+	 * @throws ReflectionException
133
+	 */
134
+	public function getHtml()
135
+	{
136
+		$this->min = 0;
137
+		$this->max = $this->ticket->max();
138
+		$remaining = $this->ticket->remaining();
139
+		$this->setTicketMinAndMax($remaining);
140
+		// set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
141
+		$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
142
+			? $this->ticket->start_date()
143
+			: $this->required_ticket_sold_out;
144
+		$this->setTicketPriceDetails();
145
+		$this->setTicketStatusClasses($remaining);
146
+		$filtered_row_html = $this->getFilteredRowHtml();
147
+		if ($filtered_row_html !== false) {
148
+			return $filtered_row_html;
149
+		}
150
+		$ticket_selector_row_html = EEH_HTML::tr(
151
+			'',
152
+			'',
153
+			"tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} "
154
+			. espresso_get_object_css_class($this->ticket)
155
+		);
156
+		$filtered_row_content = $this->getFilteredRowContents();
157
+		if ($filtered_row_content !== false) {
158
+			if ($this->max_attendees === 1) {
159
+				return $ticket_selector_row_html
160
+					   . $filtered_row_content
161
+					   . $this->ticketQtyAndIdHiddenInputs()
162
+					   . EEH_HTML::trx();
163
+			}
164
+			return $ticket_selector_row_html
165
+				   . $filtered_row_content
166
+				   . EEH_HTML::trx();
167
+		}
168
+		$this->hidden_input_qty = $this->max_attendees > 1;
169
+
170
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
171
+		$ticket_selector_row_html .= $this->ticketPriceTableCell();
172
+		$ticket_selector_row_html .= EEH_HTML::td(
173
+			'',
174
+			'',
175
+			'tckt-slctr-tbl-td-qty cntr',
176
+			'',
177
+			'headers="quantity-' . $this->EVT_ID . '"'
178
+		);
179
+		$this->setTicketStatusDisplay($remaining);
180
+		if (empty($this->ticket_status_display)) {
181
+			if ($this->max_attendees === 1) {
182
+				// only ONE attendee is allowed to register at a time
183
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
184
+			} elseif ($this->max > 0) {
185
+				$ticket_selector_row_html .= $this->ticketQuantitySelector();
186
+			}
187
+		}
188
+		$ticket_selector_row_html .= $this->ticket_status_display;
189
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
190
+		$ticket_selector_row_html .= $this->ticket_details->display(
191
+			$this->ticket_price,
192
+			$remaining,
193
+			$this->cols
194
+		);
195
+		$ticket_selector_row_html .= EEH_HTML::tdx();
196
+		$ticket_selector_row_html .= EEH_HTML::trx();
197
+
198
+
199
+		$this->row++;
200
+		return $ticket_selector_row_html;
201
+	}
202
+
203
+
204
+	/**
205
+	 * getTicketPriceDetails
206
+	 *
207
+	 * @return void
208
+	 * @throws EE_Error
209
+	 * @throws ReflectionException
210
+	 */
211
+	protected function setTicketPriceDetails()
212
+	{
213
+		$this->ticket_price = $this->tax_settings->prices_displayed_including_taxes
214
+			? $this->ticket->get_ticket_total_with_taxes()
215
+			: $this->ticket->get_ticket_subtotal();
216
+		$this->ticket_bundle = false;
217
+		$ticket_min = $this->ticket->min();
218
+		// for ticket bundles, set min and max qty the same
219
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
220
+			$this->ticket_price *= $ticket_min;
221
+			$this->ticket_bundle = true;
222
+		}
223
+		$this->ticket_price = apply_filters(
224
+			'FHEE__ticket_selector_chart_template__ticket_price',
225
+			$this->ticket_price,
226
+			$this->ticket
227
+		);
228
+	}
229
+
230
+
231
+	/**
232
+	 * ticketNameTableCell
233
+	 *
234
+	 * @return string
235
+	 * @throws EE_Error
236
+	 * @throws ReflectionException
237
+	 */
238
+	protected function ticketNameTableCell()
239
+	{
240
+		$html = EEH_HTML::td(
241
+			'',
242
+			'',
243
+			'tckt-slctr-tbl-td-name',
244
+			'',
245
+			'headers="details-' . $this->EVT_ID . '"'
246
+		);
247
+		$html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
248
+		$html .= $this->ticket_details->getShowHideLinks();
249
+		if ($this->ticket->required()) {
250
+			$html .= EEH_HTML::p(
251
+				apply_filters(
252
+					'FHEE__ticket_selector_chart_template__ticket_required_message',
253
+					esc_html__('This ticket is required and must be purchased.', 'event_espresso')
254
+				),
255
+				'',
256
+				'ticket-required-pg'
257
+			);
258
+		}
259
+		$html .= EEH_HTML::tdx();
260
+		return $html;
261
+	}
262
+
263
+
264
+	/**
265
+	 * ticketPriceTableCell
266
+	 *
267
+	 * @return string
268
+	 * @throws EE_Error
269
+	 * @throws ReflectionException
270
+	 */
271
+	protected function ticketPriceTableCell()
272
+	{
273
+		$html = '';
274
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
275
+			$html .= EEH_HTML::td(
276
+				'',
277
+				'',
278
+				'tckt-slctr-tbl-td-price jst-rght',
279
+				'',
280
+				'headers="price-' . $this->EVT_ID . '"'
281
+			);
282
+			$html .= EEH_Template::format_currency($this->ticket_price);
283
+			$html .= $this->ticket->taxable()
284
+				? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text')
285
+				: '';
286
+			$html .= '&nbsp;';
287
+			// phpcs:disable WordPress.WP.I18n.NoEmptyStrings
288
+			$html .= EEH_HTML::span(
289
+				$this->ticket_bundle
290
+					? apply_filters(
291
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
292
+						esc_html__(' / bundle', 'event_espresso')
293
+					)
294
+					: apply_filters(
295
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
296
+						esc_html__('', 'event_espresso')
297
+					),
298
+				'',
299
+				'smaller-text no-bold'
300
+			);
301
+			$html .= '&nbsp;';
302
+			$html .= EEH_HTML::tdx();
303
+			$this->cols++;
304
+		}
305
+		return $html;
306
+	}
307
+
308
+
309
+	/**
310
+	 * onlyOneAttendeeCanRegister
311
+	 *
312
+	 * @return string
313
+	 * @throws EE_Error
314
+	 * @throws ReflectionException
315
+	 */
316
+	protected function onlyOneAttendeeCanRegister()
317
+	{
318
+		$this->hidden_input_qty = false;
319
+		// display submit button since we have tickets available
320
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
321
+
322
+		$TKT   = $this->ticket->ID();
323
+		$name  = "tkt-slctr-qty-{$this->EVT_ID}";
324
+		$class = "ticket-selector-tbl-qty-slct";
325
+		$id    = "{$class}-{$this->EVT_ID}-{$this->row}";
326
+		$checked = $this->total_tickets === 1 ? ' checked' : '';
327
+
328
+		$html = "<label class='ee-a11y-screen-reader-text' for='" . esc_attr($id) . "'>"
329
+				. esc_html__('Select this ticket', 'event_espresso') . "</label>";
330
+		$html .= "<input type='radio' {$checked} name='" . esc_attr($name) . "' id='" . esc_attr($id) . "'
331 331
         class='" . esc_attr($class) . "' value='" . esc_attr($TKT) . "-1' title='' />";
332
-        return $html;
333
-    }
334
-
335
-
336
-    /**
337
-     * ticketQuantitySelector
338
-     *
339
-     * @return string
340
-     * @throws EE_Error
341
-     * @throws ReflectionException
342
-     */
343
-    protected function ticketQuantitySelector()
344
-    {
345
-        $this->hidden_input_qty = false;
346
-        // display submit button since we have tickets available
347
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
348
-
349
-        $TKT = $this->ticket->ID();
350
-        $label = esc_html__('Quantity', 'event_espresso');
351
-        $class = 'ticket-selector-tbl-qty-slct';
352
-        $id = "{$class}-{$this->EVT_ID}-{$this->row}";
353
-
354
-        $html = "<label class='ee-a11y-screen-reader-text' for='" . esc_attr($id) . "'>" . esc_html($label) . "</label>";
355
-        $html .= "<select name='tkt-slctr-qty-" . esc_attr($this->EVT_ID) . "[" . esc_attr($TKT) . "]' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "'>";
356
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
357
-        if ($this->min !== 0 && ! $this->ticket->required()) {
358
-            $html .= "<option value='0'>&nbsp;0&nbsp;</option>";
359
-        }
360
-        // offer ticket quantities from the min to the max
361
-        for ($i = $this->min; $i <= $this->max; $i++) {
362
-            $html .= "<option value='" . esc_attr($i) . "'>&nbsp;" . esc_html($i) . "&nbsp;</option>";
363
-        }
364
-        $html .= "</select>";
365
-        return $html;
366
-    }
367
-
368
-
369
-    /**
370
-     * getHiddenInputs
371
-     *
372
-     * @return string
373
-     * @throws EE_Error
374
-     * @throws ReflectionException
375
-     */
376
-    protected function ticketQtyAndIdHiddenInputs()
377
-    {
378
-        $html = '';
379
-        $EVT = $this->EVT_ID;
380
-        $TKT = $this->ticket->ID();
381
-        // depending on group reg we need to change the format for qty
382
-        if ($this->hidden_input_qty) {
383
-            $html .= "<input type='hidden' name='tkt-slctr-qty-" . esc_attr($EVT) . "[]' value='0' />";
384
-        }
385
-        $html .= "<input type='hidden' name='tkt-slctr-ticket-id-" . esc_attr($EVT) . "[]' value='" . esc_attr($TKT) . "' />";
386
-        return $html;
387
-    }
332
+		return $html;
333
+	}
334
+
335
+
336
+	/**
337
+	 * ticketQuantitySelector
338
+	 *
339
+	 * @return string
340
+	 * @throws EE_Error
341
+	 * @throws ReflectionException
342
+	 */
343
+	protected function ticketQuantitySelector()
344
+	{
345
+		$this->hidden_input_qty = false;
346
+		// display submit button since we have tickets available
347
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
348
+
349
+		$TKT = $this->ticket->ID();
350
+		$label = esc_html__('Quantity', 'event_espresso');
351
+		$class = 'ticket-selector-tbl-qty-slct';
352
+		$id = "{$class}-{$this->EVT_ID}-{$this->row}";
353
+
354
+		$html = "<label class='ee-a11y-screen-reader-text' for='" . esc_attr($id) . "'>" . esc_html($label) . "</label>";
355
+		$html .= "<select name='tkt-slctr-qty-" . esc_attr($this->EVT_ID) . "[" . esc_attr($TKT) . "]' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "'>";
356
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
357
+		if ($this->min !== 0 && ! $this->ticket->required()) {
358
+			$html .= "<option value='0'>&nbsp;0&nbsp;</option>";
359
+		}
360
+		// offer ticket quantities from the min to the max
361
+		for ($i = $this->min; $i <= $this->max; $i++) {
362
+			$html .= "<option value='" . esc_attr($i) . "'>&nbsp;" . esc_html($i) . "&nbsp;</option>";
363
+		}
364
+		$html .= "</select>";
365
+		return $html;
366
+	}
367
+
368
+
369
+	/**
370
+	 * getHiddenInputs
371
+	 *
372
+	 * @return string
373
+	 * @throws EE_Error
374
+	 * @throws ReflectionException
375
+	 */
376
+	protected function ticketQtyAndIdHiddenInputs()
377
+	{
378
+		$html = '';
379
+		$EVT = $this->EVT_ID;
380
+		$TKT = $this->ticket->ID();
381
+		// depending on group reg we need to change the format for qty
382
+		if ($this->hidden_input_qty) {
383
+			$html .= "<input type='hidden' name='tkt-slctr-qty-" . esc_attr($EVT) . "[]' value='0' />";
384
+		}
385
+		$html .= "<input type='hidden' name='tkt-slctr-ticket-id-" . esc_attr($EVT) . "[]' value='" . esc_attr($TKT) . "' />";
386
+		return $html;
387
+	}
388 388
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             '',
175 175
             'tckt-slctr-tbl-td-qty cntr',
176 176
             '',
177
-            'headers="quantity-' . $this->EVT_ID . '"'
177
+            'headers="quantity-'.$this->EVT_ID.'"'
178 178
         );
179 179
         $this->setTicketStatusDisplay($remaining);
180 180
         if (empty($this->ticket_status_display)) {
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
             '',
243 243
             'tckt-slctr-tbl-td-name',
244 244
             '',
245
-            'headers="details-' . $this->EVT_ID . '"'
245
+            'headers="details-'.$this->EVT_ID.'"'
246 246
         );
247 247
         $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
248 248
         $html .= $this->ticket_details->getShowHideLinks();
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
                 '',
278 278
                 'tckt-slctr-tbl-td-price jst-rght',
279 279
                 '',
280
-                'headers="price-' . $this->EVT_ID . '"'
280
+                'headers="price-'.$this->EVT_ID.'"'
281 281
             );
282 282
             $html .= EEH_Template::format_currency($this->ticket_price);
283 283
             $html .= $this->ticket->taxable()
@@ -325,10 +325,10 @@  discard block
 block discarded – undo
325 325
         $id    = "{$class}-{$this->EVT_ID}-{$this->row}";
326 326
         $checked = $this->total_tickets === 1 ? ' checked' : '';
327 327
 
328
-        $html = "<label class='ee-a11y-screen-reader-text' for='" . esc_attr($id) . "'>"
329
-                . esc_html__('Select this ticket', 'event_espresso') . "</label>";
330
-        $html .= "<input type='radio' {$checked} name='" . esc_attr($name) . "' id='" . esc_attr($id) . "'
331
-        class='" . esc_attr($class) . "' value='" . esc_attr($TKT) . "-1' title='' />";
328
+        $html = "<label class='ee-a11y-screen-reader-text' for='".esc_attr($id)."'>"
329
+                . esc_html__('Select this ticket', 'event_espresso')."</label>";
330
+        $html .= "<input type='radio' {$checked} name='".esc_attr($name)."' id='".esc_attr($id)."'
331
+        class='" . esc_attr($class)."' value='".esc_attr($TKT)."-1' title='' />";
332 332
         return $html;
333 333
     }
334 334
 
@@ -351,15 +351,15 @@  discard block
 block discarded – undo
351 351
         $class = 'ticket-selector-tbl-qty-slct';
352 352
         $id = "{$class}-{$this->EVT_ID}-{$this->row}";
353 353
 
354
-        $html = "<label class='ee-a11y-screen-reader-text' for='" . esc_attr($id) . "'>" . esc_html($label) . "</label>";
355
-        $html .= "<select name='tkt-slctr-qty-" . esc_attr($this->EVT_ID) . "[" . esc_attr($TKT) . "]' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "'>";
354
+        $html = "<label class='ee-a11y-screen-reader-text' for='".esc_attr($id)."'>".esc_html($label)."</label>";
355
+        $html .= "<select name='tkt-slctr-qty-".esc_attr($this->EVT_ID)."[".esc_attr($TKT)."]' id='".esc_attr($id)."' class='".esc_attr($class)."'>";
356 356
         // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
357 357
         if ($this->min !== 0 && ! $this->ticket->required()) {
358 358
             $html .= "<option value='0'>&nbsp;0&nbsp;</option>";
359 359
         }
360 360
         // offer ticket quantities from the min to the max
361 361
         for ($i = $this->min; $i <= $this->max; $i++) {
362
-            $html .= "<option value='" . esc_attr($i) . "'>&nbsp;" . esc_html($i) . "&nbsp;</option>";
362
+            $html .= "<option value='".esc_attr($i)."'>&nbsp;".esc_html($i)."&nbsp;</option>";
363 363
         }
364 364
         $html .= "</select>";
365 365
         return $html;
@@ -380,9 +380,9 @@  discard block
 block discarded – undo
380 380
         $TKT = $this->ticket->ID();
381 381
         // depending on group reg we need to change the format for qty
382 382
         if ($this->hidden_input_qty) {
383
-            $html .= "<input type='hidden' name='tkt-slctr-qty-" . esc_attr($EVT) . "[]' value='0' />";
383
+            $html .= "<input type='hidden' name='tkt-slctr-qty-".esc_attr($EVT)."[]' value='0' />";
384 384
         }
385
-        $html .= "<input type='hidden' name='tkt-slctr-ticket-id-" . esc_attr($EVT) . "[]' value='" . esc_attr($TKT) . "' />";
385
+        $html .= "<input type='hidden' name='tkt-slctr-ticket-id-".esc_attr($EVT)."[]' value='".esc_attr($TKT)."' />";
386 386
         return $html;
387 387
     }
388 388
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4640 added lines, -4640 removed lines patch added patch discarded remove patch
@@ -17,2682 +17,2682 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Messages_Admin_Page extends EE_Admin_Page
19 19
 {
20
-    /**
21
-     * @var EEM_Message
22
-     */
23
-    private $MSG_MODEL;
24
-
25
-    /**
26
-     * @var EEM_Message_Template
27
-     */
28
-    private $MTP_MODEL;
29
-
30
-    /**
31
-     * @var EEM_Message_Template_Group
32
-     */
33
-    private $MTG_MODEL;
34
-
35
-    /**
36
-     * @var EE_Message_Resource_Manager $_message_resource_manager
37
-     */
38
-    protected $_message_resource_manager;
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $_active_message_type_name = '';
44
-
45
-    /**
46
-     * @var string
47
-     */
48
-    protected $_active_messenger_name = '';
49
-
50
-    /**
51
-     * @var EE_messenger $_active_messenger
52
-     */
53
-    protected $_active_messenger;
54
-
55
-    protected $_activate_meta_box_type;
56
-
57
-    protected $_current_message_meta_box;
58
-
59
-    protected $_current_message_meta_box_object;
60
-
61
-    protected $_context_switcher;
62
-
63
-    protected $_shortcodes           = [];
64
-
65
-    protected $_active_messengers    = [];
66
-
67
-    protected $_active_message_types = [];
68
-
69
-    /**
70
-     * @var EE_Message_Template_Group $_message_template_group
71
-     */
72
-    protected $_message_template_group;
73
-
74
-    protected $_m_mt_settings = [];
75
-
76
-
77
-    /**
78
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
-     * IF there is no group then it gets automatically set to the Default template pack.
80
-     *
81
-     * @since 4.5.0
82
-     *
83
-     * @var EE_Messages_Template_Pack
84
-     */
85
-    protected $_template_pack;
86
-
87
-
88
-    /**
89
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
-     * group is.  If there is no group then it automatically gets set to default.
91
-     *
92
-     * @since 4.5.0
93
-     *
94
-     * @var string
95
-     */
96
-    protected $_variation;
97
-
98
-
99
-    /**
100
-     * @param bool $routing
101
-     * @throws EE_Error
102
-     * @throws ReflectionException
103
-     */
104
-    public function __construct($routing = true)
105
-    {
106
-        // make sure messages autoloader is running
107
-        EED_Messages::set_autoloaders();
108
-        parent::__construct($routing);
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Message
114
-     * @throws EE_Error
115
-     */
116
-    public function getMsgModel()
117
-    {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
119
-            $this->MSG_MODEL = EEM_Message::instance();
120
-        }
121
-        return $this->MSG_MODEL;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return EEM_Message_Template
127
-     * @throws EE_Error
128
-     */
129
-    public function getMtpModel()
130
-    {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
-            $this->MTP_MODEL = EEM_Message_Template::instance();
133
-        }
134
-        return $this->MTP_MODEL;
135
-    }
136
-
137
-
138
-    /**
139
-     * @return EEM_Message_Template_Group
140
-     * @throws EE_Error
141
-     */
142
-    public function getMtgModel()
143
-    {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
-        }
147
-        return $this->MTG_MODEL;
148
-    }
149
-
150
-
151
-    /**
152
-     * @throws EE_Error
153
-     * @throws ReflectionException
154
-     */
155
-    protected function _init_page_props()
156
-    {
157
-        $this->page_slug        = EE_MSG_PG_SLUG;
158
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
-        $this->_admin_base_path = EE_MSG_ADMIN;
161
-
162
-        $messenger    = $this->request->getRequestParam('messenger', '');
163
-        $message_type = $this->request->getRequestParam('message_type', '');
164
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
-
167
-        $this->_load_message_resource_manager();
168
-    }
169
-
170
-
171
-    /**
172
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
-     *
174
-     * @throws EE_Error
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     * @throws InvalidArgumentException
178
-     * @throws ReflectionException
179
-     */
180
-    protected function _load_message_resource_manager()
181
-    {
182
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
-    }
184
-
185
-
186
-    /**
187
-     * @return array
188
-     * @throws EE_Error
189
-     * @throws InvalidArgumentException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     * @deprecated 4.9.9.rc.014
193
-     */
194
-    public function get_messengers_for_list_table()
195
-    {
196
-        EE_Error::doing_it_wrong(
197
-            __METHOD__,
198
-            sprintf(
199
-                esc_html__(
200
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
201
-                    'event_espresso'
202
-                ),
203
-                'Messages_Admin_Page::get_messengers_select_input()'
204
-            ),
205
-            '4.9.9.rc.014'
206
-        );
207
-
208
-        $m_values          = [];
209
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
-        // setup messengers for selects
211
-        $i = 1;
212
-        foreach ($active_messengers as $active_messenger) {
213
-            if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
-                $i++;
217
-            }
218
-        }
219
-
220
-        return $m_values;
221
-    }
222
-
223
-
224
-    /**
225
-     * @return array
226
-     * @throws EE_Error
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     * @deprecated 4.9.9.rc.014
231
-     */
232
-    public function get_message_types_for_list_table()
233
-    {
234
-        EE_Error::doing_it_wrong(
235
-            __METHOD__,
236
-            sprintf(
237
-                esc_html__(
238
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
239
-                    'event_espresso'
240
-                ),
241
-                'Messages_Admin_Page::get_message_types_select_input()'
242
-            ),
243
-            '4.9.9.rc.014'
244
-        );
245
-
246
-        $mt_values       = [];
247
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
-        $i               = 1;
249
-        foreach ($active_messages as $active_message) {
250
-            if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
-                $i++;
254
-            }
255
-        }
256
-
257
-        return $mt_values;
258
-    }
259
-
260
-
261
-    /**
262
-     * @return array
263
-     * @throws EE_Error
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     * @deprecated 4.9.9.rc.014
268
-     */
269
-    public function get_contexts_for_message_types_for_list_table()
270
-    {
271
-        EE_Error::doing_it_wrong(
272
-            __METHOD__,
273
-            sprintf(
274
-                esc_html__(
275
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
276
-                    'event_espresso'
277
-                ),
278
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
-            ),
280
-            '4.9.9.rc.014'
281
-        );
282
-
283
-        $contexts                = [];
284
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
-        foreach ($active_message_contexts as $active_message) {
286
-            if ($active_message instanceof EE_Message) {
287
-                $message_type = $active_message->message_type_object();
288
-                if ($message_type instanceof EE_message_type) {
289
-                    $message_type_contexts = $message_type->get_contexts();
290
-                    foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
292
-                    }
293
-                }
294
-            }
295
-        }
296
-
297
-        return $contexts;
298
-    }
299
-
300
-
301
-    /**
302
-     * Generate select input with provided messenger options array.
303
-     *
304
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
-     *                                 labels.
306
-     * @return string
307
-     * @throws EE_Error
308
-     */
309
-    public function get_messengers_select_input($messenger_options)
310
-    {
311
-        // if empty or just one value then just return an empty string
312
-        if (
313
-            empty($messenger_options)
314
-            || ! is_array($messenger_options)
315
-            || count($messenger_options) === 1
316
-        ) {
317
-            return '';
318
-        }
319
-        // merge in default
320
-        $messenger_options = array_merge(
321
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
-            $messenger_options
323
-        );
324
-        $input             = new EE_Select_Input(
325
-            $messenger_options,
326
-            [
327
-                'html_name'  => 'ee_messenger_filter_by',
328
-                'html_id'    => 'ee_messenger_filter_by',
329
-                'html_class' => 'wide',
330
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
-            ]
332
-        );
333
-
334
-        return $input->get_html_for_input();
335
-    }
336
-
337
-
338
-    /**
339
-     * Generate select input with provided message type options array.
340
-     *
341
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
-     *                                    message type labels
343
-     * @return string
344
-     * @throws EE_Error
345
-     */
346
-    public function get_message_types_select_input($message_type_options)
347
-    {
348
-        // if empty or count of options is 1 then just return an empty string
349
-        if (
350
-            empty($message_type_options)
351
-            || ! is_array($message_type_options)
352
-            || count($message_type_options) === 1
353
-        ) {
354
-            return '';
355
-        }
356
-        // merge in default
357
-        $message_type_options = array_merge(
358
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
-            $message_type_options
360
-        );
361
-        $input                = new EE_Select_Input(
362
-            $message_type_options,
363
-            [
364
-                'html_name'  => 'ee_message_type_filter_by',
365
-                'html_id'    => 'ee_message_type_filter_by',
366
-                'html_class' => 'wide',
367
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
-            ]
369
-        );
370
-
371
-        return $input->get_html_for_input();
372
-    }
373
-
374
-
375
-    /**
376
-     * Generate select input with provide message type contexts array.
377
-     *
378
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
-     *                               context label.
380
-     * @return string
381
-     * @throws EE_Error
382
-     */
383
-    public function get_contexts_for_message_types_select_input($context_options)
384
-    {
385
-        // if empty or count of options is one then just return empty string
386
-        if (
387
-            empty($context_options)
388
-            || ! is_array($context_options)
389
-            || count($context_options) === 1
390
-        ) {
391
-            return '';
392
-        }
393
-        // merge in default
394
-        $context_options = array_merge(
395
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
-            $context_options
397
-        );
398
-        $input           = new EE_Select_Input(
399
-            $context_options,
400
-            [
401
-                'html_name'  => 'ee_context_filter_by',
402
-                'html_id'    => 'ee_context_filter_by',
403
-                'html_class' => 'wide',
404
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
-            ]
406
-        );
407
-
408
-        return $input->get_html_for_input();
409
-    }
410
-
411
-
412
-    protected function _ajax_hooks()
413
-    {
414
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
-    }
421
-
422
-
423
-    protected function _define_page_props()
424
-    {
425
-        $this->_admin_page_title = $this->page_label;
426
-        $this->_labels           = [
427
-            'buttons'    => [
428
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
-            ],
432
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
-        ];
434
-    }
435
-
436
-
437
-    /**
438
-     *        an array for storing key => value pairs of request actions and their corresponding methods
439
-     *
440
-     * @access protected
441
-     * @return void
442
-     */
443
-    protected function _set_page_routes()
444
-    {
445
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
-
449
-        $this->_page_routes = [
450
-            'default'                          => [
451
-                'func'       => '_message_queue_list_table',
452
-                'capability' => 'ee_read_global_messages',
453
-            ],
454
-            'global_mtps'                      => [
455
-                'func'       => '_ee_default_messages_overview_list_table',
456
-                'capability' => 'ee_read_global_messages',
457
-            ],
458
-            'custom_mtps'                      => [
459
-                'func'       => '_custom_mtps_preview',
460
-                'capability' => 'ee_read_messages',
461
-            ],
462
-            'add_new_message_template'         => [
463
-                'func'       => 'add_message_template',
464
-                'capability' => 'ee_edit_messages',
465
-                'noheader'   => true,
466
-            ],
467
-            'edit_message_template'            => [
468
-                'func'       => '_edit_message_template',
469
-                'capability' => 'ee_edit_message',
470
-                'obj_id'     => $GRP_ID,
471
-            ],
472
-            'preview_message'                  => [
473
-                'func'               => '_preview_message',
474
-                'capability'         => 'ee_read_message',
475
-                'obj_id'             => $GRP_ID,
476
-                'noheader'           => true,
477
-                'headers_sent_route' => 'display_preview_message',
478
-            ],
479
-            'display_preview_message'          => [
480
-                'func'       => '_display_preview_message',
481
-                'capability' => 'ee_read_message',
482
-                'obj_id'     => $GRP_ID,
483
-            ],
484
-            'insert_message_template'          => [
485
-                'func'       => '_insert_or_update_message_template',
486
-                'capability' => 'ee_edit_messages',
487
-                'args'       => ['new' => true],
488
-                'noheader'   => true,
489
-            ],
490
-            'update_message_template'          => [
491
-                'func'       => '_insert_or_update_message_template',
492
-                'capability' => 'ee_edit_message',
493
-                'obj_id'     => $GRP_ID,
494
-                'args'       => ['new' => false],
495
-                'noheader'   => true,
496
-            ],
497
-            'trash_message_template'           => [
498
-                'func'       => '_trash_or_restore_message_template',
499
-                'capability' => 'ee_delete_message',
500
-                'obj_id'     => $GRP_ID,
501
-                'args'       => ['trash' => true, 'all' => true],
502
-                'noheader'   => true,
503
-            ],
504
-            'trash_message_template_context'   => [
505
-                'func'       => '_trash_or_restore_message_template',
506
-                'capability' => 'ee_delete_message',
507
-                'obj_id'     => $GRP_ID,
508
-                'args'       => ['trash' => true],
509
-                'noheader'   => true,
510
-            ],
511
-            'restore_message_template'         => [
512
-                'func'       => '_trash_or_restore_message_template',
513
-                'capability' => 'ee_delete_message',
514
-                'obj_id'     => $GRP_ID,
515
-                'args'       => ['trash' => false, 'all' => true],
516
-                'noheader'   => true,
517
-            ],
518
-            'restore_message_template_context' => [
519
-                'func'       => '_trash_or_restore_message_template',
520
-                'capability' => 'ee_delete_message',
521
-                'obj_id'     => $GRP_ID,
522
-                'args'       => ['trash' => false],
523
-                'noheader'   => true,
524
-            ],
525
-            'delete_message_template'          => [
526
-                'func'       => '_delete_message_template',
527
-                'capability' => 'ee_delete_message',
528
-                'obj_id'     => $GRP_ID,
529
-                'noheader'   => true,
530
-            ],
531
-            'reset_to_default'                 => [
532
-                'func'       => '_reset_to_default_template',
533
-                'capability' => 'ee_edit_message',
534
-                'obj_id'     => $GRP_ID,
535
-                'noheader'   => true,
536
-            ],
537
-            'settings'                         => [
538
-                'func'       => '_settings',
539
-                'capability' => 'manage_options',
540
-            ],
541
-            'update_global_settings'           => [
542
-                'func'       => '_update_global_settings',
543
-                'capability' => 'manage_options',
544
-                'noheader'   => true,
545
-            ],
546
-            'generate_now'                     => [
547
-                'func'       => '_generate_now',
548
-                'capability' => 'ee_send_message',
549
-                'noheader'   => true,
550
-            ],
551
-            'generate_and_send_now'            => [
552
-                'func'       => '_generate_and_send_now',
553
-                'capability' => 'ee_send_message',
554
-                'noheader'   => true,
555
-            ],
556
-            'queue_for_resending'              => [
557
-                'func'       => '_queue_for_resending',
558
-                'capability' => 'ee_send_message',
559
-                'noheader'   => true,
560
-            ],
561
-            'send_now'                         => [
562
-                'func'       => '_send_now',
563
-                'capability' => 'ee_send_message',
564
-                'noheader'   => true,
565
-            ],
566
-            'delete_ee_message'                => [
567
-                'func'       => '_delete_ee_messages',
568
-                'capability' => 'ee_delete_messages',
569
-                'noheader'   => true,
570
-            ],
571
-            'delete_ee_messages'               => [
572
-                'func'       => '_delete_ee_messages',
573
-                'capability' => 'ee_delete_messages',
574
-                'noheader'   => true,
575
-                'obj_id'     => $MSG_ID,
576
-            ],
577
-        ];
578
-    }
579
-
580
-
581
-    protected function _set_page_config()
582
-    {
583
-        $this->_page_config = [
584
-            'default'                  => [
585
-                'nav'           => [
586
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
587
-                    'order' => 10,
588
-                ],
589
-                'list_table'    => 'EE_Message_List_Table',
590
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
-                'require_nonce' => false,
592
-            ],
593
-            'global_mtps'              => [
594
-                'nav'           => [
595
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
-                    'order' => 20,
597
-                ],
598
-                'list_table'    => 'Messages_Template_List_Table',
599
-                'help_tabs'     => [
600
-                    'messages_overview_help_tab'                                => [
601
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
-                        'filename' => 'messages_overview',
603
-                    ],
604
-                    'messages_overview_messages_table_column_headings_help_tab' => [
605
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
-                        'filename' => 'messages_overview_table_column_headings',
607
-                    ],
608
-                    'messages_overview_messages_filters_help_tab'               => [
609
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
610
-                        'filename' => 'messages_overview_filters',
611
-                    ],
612
-                    'messages_overview_messages_views_help_tab'                 => [
613
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
614
-                        'filename' => 'messages_overview_views',
615
-                    ],
616
-                    'message_overview_message_types_help_tab'                   => [
617
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
618
-                        'filename' => 'messages_overview_types',
619
-                    ],
620
-                    'messages_overview_messengers_help_tab'                     => [
621
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
622
-                        'filename' => 'messages_overview_messengers',
623
-                    ],
624
-                ],
625
-                'require_nonce' => false,
626
-            ],
627
-            'custom_mtps'              => [
628
-                'nav'           => [
629
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
-                    'order' => 30,
631
-                ],
632
-                'help_tabs'     => [],
633
-                'require_nonce' => false,
634
-            ],
635
-            'add_new_message_template' => [
636
-                'nav'           => [
637
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
-                    'order'      => 5,
639
-                    'persistent' => false,
640
-                ],
641
-                'require_nonce' => false,
642
-            ],
643
-            'edit_message_template'    => [
644
-                'labels'        => [
645
-                    'buttons'    => [
646
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
-                    ],
648
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
-                ],
650
-                'nav'           => [
651
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
-                    'order'      => 5,
653
-                    'persistent' => false,
654
-                    'url'        => '',
655
-                ],
656
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
-                'has_metaboxes' => true,
658
-                'help_tabs'     => [
659
-                    'edit_message_template'            => [
660
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
-                        'callback' => 'edit_message_template_help_tab',
662
-                    ],
663
-                    'message_templates_help_tab'       => [
664
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
665
-                        'filename' => 'messages_templates',
666
-                    ],
667
-                    'message_template_shortcodes'      => [
668
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
-                        'callback' => 'message_template_shortcodes_help_tab',
670
-                    ],
671
-                    'message_preview_help_tab'         => [
672
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
673
-                        'filename' => 'messages_preview',
674
-                    ],
675
-                    'messages_overview_other_help_tab' => [
676
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
677
-                        'filename' => 'messages_overview_other',
678
-                    ],
679
-                ],
680
-                'require_nonce' => false,
681
-            ],
682
-            'display_preview_message'  => [
683
-                'nav'           => [
684
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
685
-                    'order'      => 5,
686
-                    'url'        => '',
687
-                    'persistent' => false,
688
-                ],
689
-                'help_tabs'     => [
690
-                    'preview_message' => [
691
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
692
-                        'callback' => 'preview_message_help_tab',
693
-                    ],
694
-                ],
695
-                'require_nonce' => false,
696
-            ],
697
-            'settings'                 => [
698
-                'nav'           => [
699
-                    'label' => esc_html__('Settings', 'event_espresso'),
700
-                    'order' => 40,
701
-                ],
702
-                'metaboxes'     => ['_messages_settings_metaboxes'],
703
-                'help_tabs'     => [
704
-                    'messages_settings_help_tab'               => [
705
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
-                        'filename' => 'messages_settings',
707
-                    ],
708
-                    'messages_settings_message_types_help_tab' => [
709
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
-                        'filename' => 'messages_settings_message_types',
711
-                    ],
712
-                    'messages_settings_messengers_help_tab'    => [
713
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
-                        'filename' => 'messages_settings_messengers',
715
-                    ],
716
-                ],
717
-                'require_nonce' => false,
718
-            ],
719
-        ];
720
-    }
721
-
722
-
723
-    protected function _add_screen_options()
724
-    {
725
-        // todo
726
-    }
727
-
728
-
729
-    protected function _add_screen_options_global_mtps()
730
-    {
731
-        /**
732
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
734
-         */
735
-        $page_title              = $this->_admin_page_title;
736
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
-        $this->_per_page_screen_option();
738
-        $this->_admin_page_title = $page_title;
739
-    }
740
-
741
-
742
-    protected function _add_screen_options_default()
743
-    {
744
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
-        $this->_per_page_screen_option();
746
-    }
747
-
748
-
749
-    // none of the below group are currently used for Messages
750
-    protected function _add_feature_pointers()
751
-    {
752
-    }
753
-
754
-
755
-    public function admin_init()
756
-    {
757
-    }
758
-
759
-
760
-    public function admin_notices()
761
-    {
762
-    }
763
-
764
-
765
-    public function admin_footer_scripts()
766
-    {
767
-    }
768
-
769
-
770
-    public function messages_help_tab()
771
-    {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
-    }
774
-
775
-
776
-    public function messengers_help_tab()
777
-    {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
-    }
780
-
781
-
782
-    public function message_types_help_tab()
783
-    {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
-    }
786
-
787
-
788
-    public function messages_overview_help_tab()
789
-    {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
-    }
792
-
793
-
794
-    public function message_templates_help_tab()
795
-    {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
-    }
798
-
799
-
800
-    public function edit_message_template_help_tab()
801
-    {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
-                        . esc_attr__('Editor Title', 'event_espresso')
804
-                        . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
807
-                        . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
810
-                        . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
813
-                        . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
-                        . esc_attr__('Publish Metabox', 'event_espresso')
816
-                        . '" />';
817
-        EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
-            $args
820
-        );
821
-    }
822
-
823
-
824
-    /**
825
-     * @throws ReflectionException
826
-     * @throws EE_Error
827
-     */
828
-    public function message_template_shortcodes_help_tab()
829
-    {
830
-        $this->_set_shortcodes();
831
-        $args['shortcodes'] = $this->_shortcodes;
832
-        EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
-            $args
835
-        );
836
-    }
837
-
838
-
839
-    public function preview_message_help_tab()
840
-    {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
-    }
843
-
844
-
845
-    public function settings_help_tab()
846
-    {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
-        $args['img3'] = '<div class="switch">'
852
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
-                        . ' type="checkbox" checked>'
854
-                        . '<label for="ee-on-off-toggle-on"></label>'
855
-                        . '</div>';
856
-        $args['img4'] = '<div class="switch">'
857
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
-                        . ' type="checkbox">'
859
-                        . '<label for="ee-on-off-toggle-on"></label>'
860
-                        . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
-    }
863
-
864
-
865
-    public function load_scripts_styles()
866
-    {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
-        wp_enqueue_style('espresso_ee_msg');
869
-
870
-        wp_register_script(
871
-            'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
874
-            EVENT_ESPRESSO_VERSION,
875
-            true
876
-        );
877
-        wp_register_script(
878
-            'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
-            ['ee-dialog'],
881
-            EVENT_ESPRESSO_VERSION
882
-        );
883
-    }
884
-
885
-
886
-    public function load_scripts_styles_default()
887
-    {
888
-        wp_enqueue_script('ee-msg-list-table-js');
889
-    }
890
-
891
-
892
-    public function wp_editor_css($mce_css)
893
-    {
894
-        // if we're on the edit_message_template route
895
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
-            $message_type_name = $this->_active_message_type_name;
897
-
898
-            // we're going to REPLACE the existing mce css
899
-            // we need to get the css file location from the active messenger
900
-            $mce_css = $this->_active_messenger->get_variation(
901
-                $this->_template_pack,
902
-                $message_type_name,
903
-                true,
904
-                'wpeditor',
905
-                $this->_variation
906
-            );
907
-        }
908
-
909
-        return $mce_css;
910
-    }
911
-
912
-
913
-    /**
914
-     * @throws EE_Error
915
-     * @throws ReflectionException
916
-     */
917
-    public function load_scripts_styles_edit_message_template()
918
-    {
919
-
920
-        $this->_set_shortcodes();
921
-
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
-            esc_html__(
924
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925
-                'event_espresso'
926
-            ),
927
-            $this->_message_template_group->messenger_obj()->label['singular'],
928
-            $this->_message_template_group->message_type_obj()->label['singular']
929
-        );
930
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932
-            'event_espresso'
933
-        );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
-            'event_espresso'
937
-        );
938
-
939
-        wp_register_script(
940
-            'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
-            ['jquery'],
943
-            EVENT_ESPRESSO_VERSION
944
-        );
945
-
946
-        wp_enqueue_script('ee_admin_js');
947
-        wp_enqueue_script('ee_msgs_edit_js');
948
-
949
-        // add in special css for tiny_mce
950
-        add_filter('mce_css', [$this, 'wp_editor_css']);
951
-    }
952
-
953
-
954
-    /**
955
-     * @throws EE_Error
956
-     * @throws ReflectionException
957
-     */
958
-    public function load_scripts_styles_display_preview_message()
959
-    {
960
-        $this->_set_message_template_group();
961
-        if ($this->_active_messenger_name) {
962
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
-                $this->_active_messenger_name
964
-            );
965
-        }
966
-
967
-        wp_enqueue_style(
968
-            'espresso_preview_css',
969
-            $this->_active_messenger->get_variation(
970
-                $this->_template_pack,
971
-                $this->_active_message_type_name,
972
-                true,
973
-                'preview',
974
-                $this->_variation
975
-            )
976
-        );
977
-    }
978
-
979
-
980
-    public function load_scripts_styles_settings()
981
-    {
982
-        wp_register_style(
983
-            'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
-            [],
986
-            EVENT_ESPRESSO_VERSION
987
-        );
988
-        wp_enqueue_style('ee-text-links');
989
-        wp_enqueue_style('ee-message-settings');
990
-        wp_enqueue_script('ee-messages-settings');
991
-    }
992
-
993
-
994
-    /**
995
-     * set views array for List Table
996
-     */
997
-    public function _set_list_table_views_global_mtps()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'  => 'in_use',
1002
-                'label' => esc_html__('In Use', 'event_espresso'),
1003
-                'count' => 0,
1004
-            ],
1005
-        ];
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * Set views array for the Custom Template List Table
1011
-     */
1012
-    public function _set_list_table_views_custom_mtps()
1013
-    {
1014
-        $this->_set_list_table_views_global_mtps();
1015
-        $this->_views['in_use']['bulk_action'] = [
1016
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
-        ];
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * set views array for message queue list table
1023
-     *
1024
-     * @throws InvalidDataTypeException
1025
-     * @throws InvalidInterfaceException
1026
-     * @throws InvalidArgumentException
1027
-     * @throws EE_Error
1028
-     * @throws ReflectionException
1029
-     */
1030
-    public function _set_list_table_views_default()
1031
-    {
1032
-        EE_Registry::instance()->load_helper('Template');
1033
-
1034
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
-            'ee_send_message',
1036
-            'message_list_table_bulk_actions'
1037
-        )
1038
-            ? [
1039
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
-            ]
1044
-            : [];
1045
-
1046
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
-            'ee_delete_messages',
1048
-            'message_list_table_bulk_actions'
1049
-        )
1050
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
-            : [];
1052
-
1053
-
1054
-        $this->_views = [
1055
-            'all' => [
1056
-                'slug'        => 'all',
1057
-                'label'       => esc_html__('All', 'event_espresso'),
1058
-                'count'       => 0,
1059
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
-            ],
1061
-        ];
1062
-
1063
-
1064
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
-                continue;
1067
-            }
1068
-            $status_bulk_actions = $common_bulk_actions;
1069
-            // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1071
-                switch ($status) {
1072
-                    case EEM_Message::status_idle:
1073
-                    case EEM_Message::status_resend:
1074
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
-                        break;
1076
-
1077
-                    case EEM_Message::status_failed:
1078
-                    case EEM_Message::status_debug_only:
1079
-                    case EEM_Message::status_messenger_executing:
1080
-                        $status_bulk_actions = [];
1081
-                        break;
1082
-
1083
-                    case EEM_Message::status_incomplete:
1084
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
-                        break;
1086
-
1087
-                    case EEM_Message::status_retry:
1088
-                    case EEM_Message::status_sent:
1089
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
-                        break;
1091
-                }
1092
-            }
1093
-
1094
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1095
-            if ($status === EEM_Message::status_messenger_executing) {
1096
-                continue;
1097
-            }
1098
-
1099
-            $this->_views[ strtolower($status) ] = [
1100
-                'slug'        => strtolower($status),
1101
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
-                'count'       => 0,
1103
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
-            ];
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * @throws EE_Error
1111
-     */
1112
-    protected function _ee_default_messages_overview_list_table()
1113
-    {
1114
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * @throws EE_Error
1121
-     * @throws ReflectionException
1122
-     */
1123
-    protected function _message_queue_list_table()
1124
-    {
1125
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
-        $this->_template_args['per_column']        = 6;
1127
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
-        $this->_template_args['before_list_table'] = '<h3>'
1129
-                                                     . $this->getMsgModel()->get_pretty_label_for_results()
1130
-                                                     . '</h3>';
1131
-        $this->display_admin_list_table_page_with_no_sidebar();
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * @throws EE_Error
1137
-     */
1138
-    protected function _message_legend_items()
1139
-    {
1140
-
1141
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1142
-        $action_items       = [];
1143
-
1144
-        foreach ($action_css_classes as $action_item => $action_details) {
1145
-            if ($action_item === 'see_notifications_for') {
1146
-                continue;
1147
-            }
1148
-            $action_items[ $action_item ] = [
1149
-                'class' => $action_details['css_class'],
1150
-                'desc'  => $action_details['label'],
1151
-            ];
1152
-        }
1153
-
1154
-        /** @var array $status_items status legend setup */
1155
-        $status_items = [
1156
-            'sent_status'                => [
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1158
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159
-            ],
1160
-            'idle_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1162
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163
-            ],
1164
-            'failed_status'              => [
1165
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1166
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167
-            ],
1168
-            'messenger_executing_status' => [
1169
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1170
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171
-            ],
1172
-            'resend_status'              => [
1173
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1174
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175
-            ],
1176
-            'incomplete_status'          => [
1177
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1178
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179
-            ],
1180
-            'retry_status'               => [
1181
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1182
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183
-            ],
1184
-        ];
1185
-        if (EEM_Message::debug()) {
1186
-            $status_items['debug_only_status'] = [
1187
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1188
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189
-            ];
1190
-        }
1191
-
1192
-        return array_merge($action_items, $status_items);
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * @throws EE_Error
1198
-     */
1199
-    protected function _custom_mtps_preview()
1200
-    {
1201
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
-                                                . ' alt="' . esc_attr__(
1204
-                                                    'Preview Custom Message Templates screenshot',
1205
-                                                    'event_espresso'
1206
-                                                ) . '" />';
1207
-        $this->_template_args['preview_text'] = '<strong>'
1208
-                                                . esc_html__(
1209
-                                                    'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1210
-                                                    'event_espresso'
1211
-                                                )
1212
-                                                . '</strong>';
1213
-
1214
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * get_message_templates
1220
-     * This gets all the message templates for listing on the overview list.
1221
-     *
1222
-     * @access public
1223
-     * @param int    $per_page the amount of templates groups to show per page
1224
-     * @param string $type     the current _view we're getting templates for
1225
-     * @param bool   $count    return count?
1226
-     * @param bool   $all      disregard any paging info (get all data);
1227
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1228
-     * @return array
1229
-     * @throws EE_Error
1230
-     * @throws InvalidArgumentException
1231
-     * @throws InvalidDataTypeException
1232
-     * @throws InvalidInterfaceException
1233
-     */
1234
-    public function get_message_templates(
1235
-        $per_page = 10,
1236
-        $type = 'in_use',
1237
-        $count = false,
1238
-        $all = false,
1239
-        $global = true
1240
-    ) {
1241
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1242
-        $this->request->setRequestParam('orderby', $orderby);
1243
-
1244
-        $order        = $this->request->getRequestParam('order', 'ASC');
1245
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1246
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1247
-
1248
-        $offset = ($current_page - 1) * $per_page;
1249
-        $limit  = $all ? null : [$offset, $per_page];
1250
-
1251
-        // options will match what is in the _views array property
1252
-        return $type === 'in_use'
1253
-            ? $this->getMtgModel()->get_all_active_message_templates(
1254
-                $orderby,
1255
-                $order,
1256
-                $limit,
1257
-                $count,
1258
-                $global,
1259
-                true
1260
-            )
1261
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1262
-                $orderby,
1263
-                $order,
1264
-                $limit,
1265
-                $count,
1266
-                $global
1267
-            );
1268
-    }
1269
-
1270
-
1271
-    /**
1272
-     * filters etc might need a list of installed message_types
1273
-     *
1274
-     * @return array an array of message type objects
1275
-     */
1276
-    public function get_installed_message_types()
1277
-    {
1278
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1279
-        $installed               = [];
1280
-
1281
-        foreach ($installed_message_types as $message_type) {
1282
-            $installed[ $message_type->name ] = $message_type;
1283
-        }
1284
-
1285
-        return $installed;
1286
-    }
1287
-
1288
-
1289
-    /**
1290
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1291
-     *
1292
-     * @param string $message_type
1293
-     * @param string $messenger
1294
-     * @param string $GRP_ID
1295
-     *
1296
-     * @throws EE_error
1297
-     * @throws ReflectionException
1298
-     */
1299
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1300
-    {
1301
-        // set values override any request data
1302
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1303
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1304
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1305
-
1306
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1307
-        if (empty($message_type) || empty($messenger)) {
1308
-            throw new EE_Error(
1309
-                esc_html__(
1310
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1311
-                    'event_espresso'
1312
-                )
1313
-            );
1314
-        }
1315
-
1316
-        // we need the GRP_ID for the template being used as the base for the new template
1317
-        if (empty($GRP_ID)) {
1318
-            throw new EE_Error(
1319
-                esc_html__(
1320
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1321
-                    'event_espresso'
1322
-                )
1323
-            );
1324
-        }
1325
-
1326
-        // let's just make sure the template gets generated!
1327
-
1328
-        // we need to reassign some variables for what the insert is expecting
1329
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1330
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1331
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1332
-
1333
-        $this->_insert_or_update_message_template(true);
1334
-    }
1335
-
1336
-
1337
-    /**
1338
-     * @param string $message_type     message type slug
1339
-     * @param string $messenger        messenger slug
1340
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1341
-     *                                 off of.
1342
-     * @throws EE_error
1343
-     * @throws ReflectionException
1344
-     * @deprecated 4.10.29.p
1345
-     */
1346
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1347
-    {
1348
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1349
-    }
1350
-
1351
-
1352
-    /**
1353
-     * _edit_message_template
1354
-     *
1355
-     * @access protected
1356
-     * @return void
1357
-     * @throws InvalidIdentifierException
1358
-     * @throws DomainException
1359
-     * @throws EE_Error
1360
-     * @throws InvalidArgumentException
1361
-     * @throws ReflectionException
1362
-     * @throws InvalidDataTypeException
1363
-     * @throws InvalidInterfaceException
1364
-     */
1365
-    protected function _edit_message_template()
1366
-    {
1367
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1368
-        $template_fields = '';
1369
-        $sidebar_fields  = '';
1370
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1371
-        // valid html in the templates.
1372
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1373
-
1374
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1375
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1376
-
1377
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1378
-        $message_template_group = $this->_message_template_group;
1379
-        $c_label                = $message_template_group->context_label();
1380
-        $c_config               = $message_template_group->contexts_config();
1381
-
1382
-        reset($c_config);
1383
-        $context = $this->request->getRequestParam('context', key($c_config));
1384
-        $context = strtolower($context);
1385
-
1386
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1387
-
1388
-        $edit_message_template_form_url = add_query_arg(
1389
-            ['action' => $action, 'noheader' => true],
1390
-            EE_MSG_ADMIN_URL
1391
-        );
1392
-
1393
-        // set active messenger for this view
1394
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1395
-            $message_template_group->messenger()
1396
-        );
1397
-        $this->_active_message_type_name = $message_template_group->message_type();
1398
-
1399
-
1400
-        // Do we have any validation errors?
1401
-        $validators = $this->_get_transient();
1402
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1403
-
1404
-
1405
-        // we need to assemble the title from Various details
1406
-        $context_label = sprintf(
1407
-            esc_html__('(%s %s)', 'event_espresso'),
1408
-            $c_config[ $context ]['label'],
1409
-            ucwords($c_label['label'])
1410
-        );
1411
-
1412
-        $title = sprintf(
1413
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1414
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1415
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1416
-            $context_label
1417
-        );
1418
-
1419
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1420
-        $this->_template_args['message_template'] = $message_template_group;
1421
-        $this->_template_args['is_extra_fields']  = false;
1422
-
1423
-
1424
-        // let's get EEH_MSG_Template so we can get template form fields
1425
-        $template_field_structure = EEH_MSG_Template::get_fields(
1426
-            $message_template_group->messenger(),
1427
-            $message_template_group->message_type()
1428
-        );
1429
-
1430
-        if (! $template_field_structure) {
1431
-            $template_field_structure = false;
1432
-            $template_fields          = esc_html__(
1433
-                'There was an error in assembling the fields for this display (you should see an error message)',
1434
-                'event_espresso'
1435
-            );
1436
-        }
1437
-
1438
-
1439
-        $message_templates = $message_template_group->context_templates();
1440
-
1441
-
1442
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443
-        // will get handled in the "extra" array.
1444
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
-                unset($template_field_structure[ $context ][ $reference_field ]);
1447
-            }
1448
-        }
1449
-
1450
-        // let's loop through the template_field_structure and actually assemble the input fields!
1451
-        if (! empty($template_field_structure)) {
1452
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454
-                // the extra array and reset them.
1455
-                if ($template_field === 'extra') {
1456
-                    $this->_template_args['is_extra_fields'] = true;
1457
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1459
-                        $content          = $message_template instanceof EE_Message_Template
1460
-                            ? $message_template->get('MTP_content')
1461
-                            : '';
1462
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1463
-                            // let's verify if we need this extra field via the shortcodes parameter.
1464
-                            $continue = false;
1465
-                            if (isset($extra_array['shortcodes_required'])) {
1466
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1468
-                                        $continue = true;
1469
-                                    }
1470
-                                }
1471
-                                if ($continue) {
1472
-                                    continue;
1473
-                                }
1474
-                            }
1475
-
1476
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1477
-
1478
-                            $template_form_fields[ $field_id ]         = $extra_array;
1479
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
-                                                                         . $reference_field
1481
-                                                                         . '][content]['
1482
-                                                                         . $extra_field . ']';
1483
-                            $css_class                                 = isset($extra_array['css_class'])
1484
-                                ? $extra_array['css_class']
1485
-                                : '';
1486
-
1487
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1488
-                                                                              && in_array($extra_field, $v_fields, true)
1489
-                                                                              && (
1490
-                                                                                  is_array($validators[ $extra_field ])
1491
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1492
-                                                                              )
1493
-                                ? 'validate-error ' . $css_class
1494
-                                : $css_class;
1495
-
1496
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
-                                                                          && isset($content[ $extra_field ])
1498
-                                ? $content[ $extra_field ]
1499
-                                : '';
1500
-
1501
-                            // do we have a validation error?  if we do then let's use that value instead
1502
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
-                                ? $validators[ $extra_field ]['value']
1504
-                                : $template_form_fields[ $field_id ]['value'];
1505
-
1506
-
1507
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1508
-
1509
-                            // shortcode selector
1510
-                            $field_name_to_use                                   = $extra_field === 'main'
1511
-                                ? 'content'
1512
-                                : $extra_field;
1513
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1514
-                                $field_name_to_use,
1515
-                                $field_id
1516
-                            );
1517
-                        }
1518
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
-                        $template_field_template_name_id = $reference_field . '-name';
1520
-
1521
-                        $template_form_fields[ $template_field_MTP_id ] = [
1522
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
-                            'label'      => null,
1524
-                            'input'      => 'hidden',
1525
-                            'type'       => 'int',
1526
-                            'required'   => false,
1527
-                            'validation' => false,
1528
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1529
-                            'css_class'  => '',
1530
-                            'format'     => '%d',
1531
-                            'db-col'     => 'MTP_ID',
1532
-                        ];
1533
-
1534
-                        $template_form_fields[ $template_field_template_name_id ] = [
1535
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
-                            'label'      => null,
1537
-                            'input'      => 'hidden',
1538
-                            'type'       => 'string',
1539
-                            'required'   => false,
1540
-                            'validation' => true,
1541
-                            'value'      => $reference_field,
1542
-                            'css_class'  => '',
1543
-                            'format'     => '%s',
1544
-                            'db-col'     => 'MTP_template_field',
1545
-                        ];
1546
-                    }
1547
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548
-                } else {
1549
-                    $field_id                                   = $template_field . '-content';
1550
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1551
-                    $template_form_fields[ $field_id ]['name']  =
1552
-                        'MTP_template_fields[' . $template_field . '][content]';
1553
-                    $message_template                           =
1554
-                        isset($message_templates[ $context ][ $template_field ])
1555
-                            ? $message_templates[ $context ][ $template_field ]
1556
-                            : null;
1557
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
-                                                                  && is_array($message_templates[ $context ])
1559
-                                                                  && $message_template instanceof EE_Message_Template
1560
-                        ? $message_template->get('MTP_content')
1561
-                        : '';
1562
-
1563
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1564
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
-                        ? $validators[ $template_field ]['value']
1566
-                        : $template_form_fields[ $field_id ]['value'];
1567
-
1568
-
1569
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1570
-                    $css_class                                      = isset($field_setup_array['css_class'])
1571
-                        ? $field_setup_array['css_class']
1572
-                        : '';
1573
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1574
-                                                                      && in_array($template_field, $v_fields, true)
1575
-                                                                      && isset($validators[ $template_field ]['msg'])
1576
-                        ? 'validate-error ' . $css_class
1577
-                        : $css_class;
1578
-
1579
-                    // shortcode selector
1580
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1581
-                        $template_field,
1582
-                        $field_id
1583
-                    );
1584
-                }
1585
-
1586
-                // k took care of content field(s) now let's take care of others.
1587
-
1588
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
-                $template_field_field_template_name_id = $template_field . '-name';
1590
-
1591
-                // foreach template field there are actually two form fields created
1592
-                $template_form_fields[ $template_field_MTP_id ] = [
1593
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
-                    'label'      => null,
1595
-                    'input'      => 'hidden',
1596
-                    'type'       => 'int',
1597
-                    'required'   => false,
1598
-                    'validation' => true,
1599
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1600
-                    'css_class'  => '',
1601
-                    'format'     => '%d',
1602
-                    'db-col'     => 'MTP_ID',
1603
-                ];
1604
-
1605
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1606
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
-                    'label'      => null,
1608
-                    'input'      => 'hidden',
1609
-                    'type'       => 'string',
1610
-                    'required'   => false,
1611
-                    'validation' => true,
1612
-                    'value'      => $template_field,
1613
-                    'css_class'  => '',
1614
-                    'format'     => '%s',
1615
-                    'db-col'     => 'MTP_template_field',
1616
-                ];
1617
-            }
1618
-
1619
-            // add other fields
1620
-            $template_form_fields['ee-msg-current-context'] = [
1621
-                'name'       => 'MTP_context',
1622
-                'label'      => null,
1623
-                'input'      => 'hidden',
1624
-                'type'       => 'string',
1625
-                'required'   => false,
1626
-                'validation' => true,
1627
-                'value'      => $context,
1628
-                'css_class'  => '',
1629
-                'format'     => '%s',
1630
-                'db-col'     => 'MTP_context',
1631
-            ];
1632
-
1633
-            $template_form_fields['ee-msg-grp-id'] = [
1634
-                'name'       => 'GRP_ID',
1635
-                'label'      => null,
1636
-                'input'      => 'hidden',
1637
-                'type'       => 'int',
1638
-                'required'   => false,
1639
-                'validation' => true,
1640
-                'value'      => $GRP_ID,
1641
-                'css_class'  => '',
1642
-                'format'     => '%d',
1643
-                'db-col'     => 'GRP_ID',
1644
-            ];
1645
-
1646
-            $template_form_fields['ee-msg-messenger'] = [
1647
-                'name'       => 'MTP_messenger',
1648
-                'label'      => null,
1649
-                'input'      => 'hidden',
1650
-                'type'       => 'string',
1651
-                'required'   => false,
1652
-                'validation' => true,
1653
-                'value'      => $message_template_group->messenger(),
1654
-                'css_class'  => '',
1655
-                'format'     => '%s',
1656
-                'db-col'     => 'MTP_messenger',
1657
-            ];
1658
-
1659
-            $template_form_fields['ee-msg-message-type'] = [
1660
-                'name'       => 'MTP_message_type',
1661
-                'label'      => null,
1662
-                'input'      => 'hidden',
1663
-                'type'       => 'string',
1664
-                'required'   => false,
1665
-                'validation' => true,
1666
-                'value'      => $message_template_group->message_type(),
1667
-                'css_class'  => '',
1668
-                'format'     => '%s',
1669
-                'db-col'     => 'MTP_message_type',
1670
-            ];
1671
-
1672
-            $sidebar_form_fields['ee-msg-is-global'] = [
1673
-                'name'       => 'MTP_is_global',
1674
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1675
-                'input'      => 'hidden',
1676
-                'type'       => 'int',
1677
-                'required'   => false,
1678
-                'validation' => true,
1679
-                'value'      => $message_template_group->get('MTP_is_global'),
1680
-                'css_class'  => '',
1681
-                'format'     => '%d',
1682
-                'db-col'     => 'MTP_is_global',
1683
-            ];
1684
-
1685
-            $sidebar_form_fields['ee-msg-is-override'] = [
1686
-                'name'       => 'MTP_is_override',
1687
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1688
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1689
-                'type'       => 'int',
1690
-                'required'   => false,
1691
-                'validation' => true,
1692
-                'value'      => $message_template_group->get('MTP_is_override'),
1693
-                'css_class'  => '',
1694
-                'format'     => '%d',
1695
-                'db-col'     => 'MTP_is_override',
1696
-            ];
1697
-
1698
-            $sidebar_form_fields['ee-msg-is-active'] = [
1699
-                'name'       => 'MTP_is_active',
1700
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1701
-                'input'      => 'hidden',
1702
-                'type'       => 'int',
1703
-                'required'   => false,
1704
-                'validation' => true,
1705
-                'value'      => $message_template_group->is_active(),
1706
-                'css_class'  => '',
1707
-                'format'     => '%d',
1708
-                'db-col'     => 'MTP_is_active',
1709
-            ];
1710
-
1711
-            $sidebar_form_fields['ee-msg-deleted'] = [
1712
-                'name'       => 'MTP_deleted',
1713
-                'label'      => null,
1714
-                'input'      => 'hidden',
1715
-                'type'       => 'int',
1716
-                'required'   => false,
1717
-                'validation' => true,
1718
-                'value'      => $message_template_group->get('MTP_deleted'),
1719
-                'css_class'  => '',
1720
-                'format'     => '%d',
1721
-                'db-col'     => 'MTP_deleted',
1722
-            ];
1723
-            $sidebar_form_fields['ee-msg-author']  = [
1724
-                'name'       => 'MTP_user_id',
1725
-                'label'      => esc_html__('Author', 'event_espresso'),
1726
-                'input'      => 'hidden',
1727
-                'type'       => 'int',
1728
-                'required'   => false,
1729
-                'validation' => false,
1730
-                'value'      => $message_template_group->user(),
1731
-                'format'     => '%d',
1732
-                'db-col'     => 'MTP_user_id',
1733
-            ];
1734
-
1735
-            $sidebar_form_fields['ee-msg-route'] = [
1736
-                'name'  => 'action',
1737
-                'input' => 'hidden',
1738
-                'type'  => 'string',
1739
-                'value' => $action,
1740
-            ];
1741
-
1742
-            $sidebar_form_fields['ee-msg-id']        = [
1743
-                'name'  => 'id',
1744
-                'input' => 'hidden',
1745
-                'type'  => 'int',
1746
-                'value' => $GRP_ID,
1747
-            ];
1748
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
-                'name'  => $action . '_nonce',
1750
-                'input' => 'hidden',
1751
-                'type'  => 'string',
1752
-                'value' => wp_create_nonce($action . '_nonce'),
1753
-            ];
1754
-
1755
-            $template_switch = $this->request->getRequestParam('template_switch');
1756
-            if ($template_switch) {
1757
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1758
-                    'name'  => 'template_switch',
1759
-                    'input' => 'hidden',
1760
-                    'type'  => 'int',
1761
-                    'value' => 1,
1762
-                ];
1763
-            }
1764
-
1765
-
1766
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1767
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1768
-        } //end if ( !empty($template_field_structure) )
1769
-
1770
-        // set extra content for publish box
1771
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1772
-        $this->_set_publish_post_box_vars(
1773
-            'id',
1774
-            $GRP_ID,
1775
-            false,
1776
-            add_query_arg(
1777
-                ['action' => 'global_mtps'],
1778
-                $this->_admin_base_url
1779
-            )
1780
-        );
1781
-
1782
-        // add preview button
1783
-        $preview_url    = parent::add_query_args_and_nonce(
1784
-            [
1785
-                'message_type' => $message_template_group->message_type(),
1786
-                'messenger'    => $message_template_group->messenger(),
1787
-                'context'      => $context,
1788
-                'GRP_ID'       => $GRP_ID,
1789
-                'evt_id'       => $EVT_ID ?: false,
1790
-                'action'       => 'preview_message',
1791
-            ],
1792
-            $this->_admin_base_url
1793
-        );
1794
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1795
-                          . esc_html__('Preview', 'event_espresso')
1796
-                          . '</a>';
1797
-
1798
-
1799
-        // setup context switcher
1800
-        $this->_set_context_switcher(
1801
-            $message_template_group,
1802
-            [
1803
-                'page'    => 'espresso_messages',
1804
-                'action'  => 'edit_message_template',
1805
-                'id'      => $GRP_ID,
1806
-                'evt_id'  => $EVT_ID,
1807
-                'context' => $context,
1808
-                'extra'   => $preview_button,
1809
-            ]
1810
-        );
1811
-
1812
-
1813
-        // main box
1814
-        $this->_template_args['template_fields']                         = $template_fields;
1815
-        $this->_template_args['sidebar_box_id']                          = 'details';
1816
-        $this->_template_args['action']                                  = $action;
1817
-        $this->_template_args['context']                                 = $context;
1818
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1819
-        $this->_template_args['learn_more_about_message_templates_link'] =
1820
-            $this->_learn_more_about_message_templates_link();
1821
-
1822
-
1823
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1824
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1825
-            $message_template_group,
1826
-            $context,
1827
-            $context_label
1828
-        );
1829
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
-
1832
-        $this->_template_path = $this->_template_args['GRP_ID']
1833
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
-
1836
-        // send along EE_Message_Template_Group object for further template use.
1837
-        $this->_template_args['MTP'] = $message_template_group;
1838
-
1839
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1840
-            $this->_template_path,
1841
-            $this->_template_args,
1842
-            true
1843
-        );
1844
-
1845
-
1846
-        // finally, let's set the admin_page title
1847
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1848
-
1849
-
1850
-        // we need to take care of setting the shortcodes property for use elsewhere.
1851
-        $this->_set_shortcodes();
1852
-
1853
-
1854
-        // final template wrapper
1855
-        $this->display_admin_page_with_sidebar();
1856
-    }
1857
-
1858
-
1859
-    public function filter_tinymce_init($mceInit, $editor_id)
1860
-    {
1861
-        return $mceInit;
1862
-    }
1863
-
1864
-
1865
-    public function add_context_switcher()
1866
-    {
1867
-        return $this->_context_switcher;
1868
-    }
1869
-
1870
-
1871
-    /**
1872
-     * Adds the activation/deactivation toggle for the message template context.
1873
-     *
1874
-     * @param EE_Message_Template_Group $message_template_group
1875
-     * @param string                    $context
1876
-     * @param string                    $context_label
1877
-     * @return string
1878
-     * @throws DomainException
1879
-     * @throws EE_Error
1880
-     * @throws InvalidIdentifierException
1881
-     * @throws ReflectionException
1882
-     */
1883
-    protected function add_active_context_element(
1884
-        EE_Message_Template_Group $message_template_group,
1885
-        $context,
1886
-        $context_label
1887
-    ) {
1888
-        $template_args = [
1889
-            'context'                   => $context,
1890
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
-            'is_active'                 => $message_template_group->is_context_active($context),
1892
-            'on_off_action'             => $message_template_group->is_context_active($context)
1893
-                ? 'context-off'
1894
-                : 'context-on',
1895
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
-            'message_template_group_id' => $message_template_group->ID(),
1897
-        ];
1898
-        return EEH_Template::display_template(
1899
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
-            $template_args,
1901
-            true
1902
-        );
1903
-    }
1904
-
1905
-
1906
-    /**
1907
-     * Ajax callback for `toggle_context_template` ajax action.
1908
-     * Handles toggling the message context on or off.
1909
-     *
1910
-     * @throws EE_Error
1911
-     * @throws InvalidArgumentException
1912
-     * @throws InvalidDataTypeException
1913
-     * @throws InvalidIdentifierException
1914
-     * @throws InvalidInterfaceException
1915
-     */
1916
-    public function toggle_context_template()
1917
-    {
1918
-        $success = true;
1919
-        // check for required data
1920
-        if (
1921
-            ! (
1922
-                $this->request->requestParamIsSet('message_template_group_id')
1923
-                && $this->request->requestParamIsSet('context')
1924
-                && $this->request->requestParamIsSet('status')
1925
-            )
1926
-        ) {
1927
-            EE_Error::add_error(
1928
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1929
-                __FILE__,
1930
-                __FUNCTION__,
1931
-                __LINE__
1932
-            );
1933
-            $success = false;
1934
-        }
1935
-
1936
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1937
-        $context = $this->request->getRequestParam('context', '');
1938
-        $status  = $this->request->getRequestParam('status', '');
1939
-
1940
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1941
-
1942
-        if ($status !== 'off' && $status !== 'on') {
1943
-            EE_Error::add_error(
1944
-                sprintf(
1945
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1946
-                    $status
1947
-                ),
1948
-                __FILE__,
1949
-                __FUNCTION__,
1950
-                __LINE__
1951
-            );
1952
-            $success = false;
1953
-        }
1954
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
-            EE_Error::add_error(
1958
-                sprintf(
1959
-                    esc_html__(
1960
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1961
-                        'event_espresso'
1962
-                    ),
1963
-                    $message_template_group_id,
1964
-                    'EE_Message_Template_Group'
1965
-                ),
1966
-                __FILE__,
1967
-                __FUNCTION__,
1968
-                __LINE__
1969
-            );
1970
-            $success = false;
1971
-        }
1972
-        if ($success) {
1973
-            $success = $status === 'off'
1974
-                ? $message_template_group->deactivate_context($context)
1975
-                : $message_template_group->activate_context($context);
1976
-        }
1977
-        $this->_template_args['success'] = $success;
1978
-        $this->_return_json();
1979
-    }
1980
-
1981
-
1982
-    public function _add_form_element_before()
1983
-    {
1984
-        return '<form method="post" action="'
1985
-               . $this->_template_args['edit_message_template_form_url']
1986
-               . '" id="ee-msg-edit-frm">';
1987
-    }
1988
-
1989
-
1990
-    public function _add_form_element_after()
1991
-    {
1992
-        return '</form>';
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * This executes switching the template pack for a message template.
1998
-     *
1999
-     * @throws EE_Error
2000
-     * @throws InvalidDataTypeException
2001
-     * @throws InvalidInterfaceException
2002
-     * @throws InvalidArgumentException
2003
-     * @throws ReflectionException
2004
-     * @since 4.5.0
2005
-     */
2006
-    public function switch_template_pack()
2007
-    {
2008
-
2009
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2010
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2011
-
2012
-        // verify we have needed values.
2013
-        if (empty($GRP_ID) || empty($template_pack)) {
2014
-            $this->_template_args['error'] = true;
2015
-            EE_Error::add_error(
2016
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2017
-                __FILE__,
2018
-                __FUNCTION__,
2019
-                __LINE__
2020
-            );
2021
-        } else {
2022
-            // get template, set the new template_pack and then reset to default
2023
-            /** @var EE_Message_Template_Group $message_template_group */
2024
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2025
-
2026
-            $message_template_group->set_template_pack_name($template_pack);
2027
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2028
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2029
-
2030
-            $query_args = $this->_reset_to_default_template();
2031
-
2032
-            if (empty($query_args['id'])) {
2033
-                EE_Error::add_error(
2034
-                    esc_html__(
2035
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2036
-                        'event_espresso'
2037
-                    ),
2038
-                    __FILE__,
2039
-                    __FUNCTION__,
2040
-                    __LINE__
2041
-                );
2042
-                $this->_template_args['error'] = true;
2043
-            } else {
2044
-                $template_label       = $message_template_group->get_template_pack()->label;
2045
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2046
-                EE_Error::add_success(
2047
-                    sprintf(
2048
-                        esc_html__(
2049
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2050
-                            'event_espresso'
2051
-                        ),
2052
-                        $template_label,
2053
-                        $template_pack_labels->template_pack
2054
-                    )
2055
-                );
2056
-                // generate the redirect url for js.
2057
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2058
-
2059
-                $this->_template_args['data']['redirect_url'] = $url;
2060
-                $this->_template_args['success']              = true;
2061
-            }
2062
-
2063
-            $this->_return_json();
2064
-        }
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2070
-     * they want.
2071
-     *
2072
-     * @access protected
2073
-     * @return array|void
2074
-     * @throws EE_Error
2075
-     * @throws InvalidArgumentException
2076
-     * @throws InvalidDataTypeException
2077
-     * @throws InvalidInterfaceException
2078
-     * @throws ReflectionException
2079
-     */
2080
-    protected function _reset_to_default_template()
2081
-    {
2082
-        $templates    = [];
2083
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2084
-        $messenger    = $this->request->getRequestParam('msgr');
2085
-        $message_type = $this->request->getRequestParam('mt');
2086
-        // we need to make sure we've got the info we need.
2087
-        if (! ($GRP_ID && $messenger && $message_type)) {
2088
-            EE_Error::add_error(
2089
-                esc_html__(
2090
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2091
-                    'event_espresso'
2092
-                ),
2093
-                __FILE__,
2094
-                __FUNCTION__,
2095
-                __LINE__
2096
-            );
2097
-        }
2098
-
2099
-        // all templates will be reset to whatever the defaults are
2100
-        // for the global template matching the messenger and message type.
2101
-        $success = ! empty($GRP_ID);
2102
-
2103
-        if ($success) {
2104
-            // let's first determine if the incoming template is a global template,
2105
-            // if it isn't then we need to get the global template matching messenger and message type.
2106
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2107
-
2108
-
2109
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2110
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2111
-
2112
-            if ($success) {
2113
-                // if successfully deleted, lets generate the new ones.
2114
-                // Note. We set GLOBAL to true, because resets on ANY template
2115
-                // will use the related global template defaults for regeneration.
2116
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2117
-                // HOWEVER, we DO keep the template pack and template variation set
2118
-                // for the current custom template when resetting.
2119
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2120
-            }
2121
-        }
2122
-
2123
-        // any error messages?
2124
-        if (! $success) {
2125
-            EE_Error::add_error(
2126
-                esc_html__(
2127
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2128
-                    'event_espresso'
2129
-                ),
2130
-                __FILE__,
2131
-                __FUNCTION__,
2132
-                __LINE__
2133
-            );
2134
-        }
2135
-
2136
-        // all good, let's add a success message!
2137
-        if ($success && ! empty($templates)) {
2138
-            // the info for the template we generated is the first element in the returned array
2139
-            EE_Error::overwrite_success();
2140
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2141
-        }
2142
-
2143
-
2144
-        $query_args = [
2145
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2146
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2147
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2148
-        ];
2149
-
2150
-        // if called via ajax then we return query args otherwise redirect
2151
-        if ($this->request->isAjax()) {
2152
-            return $query_args;
2153
-        }
2154
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2155
-    }
2156
-
2157
-
2158
-    /**
2159
-     * Retrieve and set the message preview for display.
2160
-     *
2161
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2162
-     * @return string
2163
-     * @throws ReflectionException
2164
-     * @throws EE_Error
2165
-     * @throws InvalidArgumentException
2166
-     * @throws InvalidDataTypeException
2167
-     * @throws InvalidInterfaceException
2168
-     */
2169
-    public function _preview_message($send = false)
2170
-    {
2171
-        // first make sure we've got the necessary parameters
2172
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
-            EE_Error::add_error(
2175
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176
-                __FILE__,
2177
-                __FUNCTION__,
2178
-                __LINE__
2179
-            );
2180
-        }
2181
-
2182
-        $context = $this->request->getRequestParam('context');
2183
-        // get the preview!
2184
-        $preview = EED_Messages::preview_message(
2185
-            $this->_active_message_type_name,
2186
-            $context,
2187
-            $this->_active_messenger_name,
2188
-            $send
2189
-        );
2190
-
2191
-        if ($send) {
2192
-            return $preview;
2193
-        }
2194
-
2195
-        // if we have an evt_id set on the request, use it.
2196
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197
-
2198
-        // let's add a button to go back to the edit view
2199
-        $query_args             = [
2200
-            'id'      => $GRP_ID,
2201
-            'evt_id'  => $EVT_ID,
2202
-            'context' => $context,
2203
-            'action'  => 'edit_message_template',
2204
-        ];
2205
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2206
-        $preview_button         = '<a href="'
2207
-                                  . $go_back_url
2208
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2209
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2210
-                                  . '</a>';
2211
-        $message_types          = $this->get_installed_message_types();
2212
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2213
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2214
-            ? ucwords($active_messenger->label['singular'])
2215
-            : esc_html__('Unknown Messenger', 'event_espresso');
2216
-        // let's provide a helpful title for context
2217
-        $preview_title = sprintf(
2218
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219
-            $active_messenger_label,
2220
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
-        );
2222
-        if (empty($preview)) {
2223
-            $this->noEventsErrorMessage();
2224
-        }
2225
-        // setup display of preview.
2226
-        $this->_admin_page_title                    = $preview_title;
2227
-        $this->_template_args['admin_page_title']   = $preview_title;
2228
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
-        $this->_template_args['data']['force_json'] = true;
2230
-
2231
-        return '';
2232
-    }
2233
-
2234
-
2235
-    /**
2236
-     * Used to set an error if there are no events available for generating a preview/test send.
2237
-     *
2238
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2239
-     */
2240
-    protected function noEventsErrorMessage($test_send = false)
2241
-    {
2242
-        $events_url = parent::add_query_args_and_nonce(
2243
-            [
2244
-                'action' => 'default',
2245
-                'page'   => 'espresso_events',
2246
-            ],
2247
-            admin_url('admin.php')
2248
-        );
2249
-        $message    = $test_send
2250
-            ? esc_html__(
2251
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252
-                'event_espresso'
2253
-            )
2254
-            : esc_html__(
2255
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2256
-                'event_espresso'
2257
-            );
2258
-
2259
-        EE_Error::add_attention(
2260
-            sprintf(
2261
-                $message,
2262
-                "<a href='" . esc_url_raw($events_url) . "'>",
2263
-                '</a>'
2264
-            )
2265
-        );
2266
-    }
2267
-
2268
-
2269
-    /**
2270
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2271
-     * gets called automatically.
2272
-     *
2273
-     * @return void
2274
-     * @throws EE_Error
2275
-     * @since 4.5.0
2276
-     *
2277
-     */
2278
-    protected function _display_preview_message()
2279
-    {
2280
-        $this->display_admin_page_with_no_sidebar();
2281
-    }
2282
-
2283
-
2284
-    /**
2285
-     * registers metaboxes that should show up on the "edit_message_template" page
2286
-     *
2287
-     * @access protected
2288
-     * @return void
2289
-     */
2290
-    protected function _register_edit_meta_boxes()
2291
-    {
2292
-        add_meta_box(
2293
-            'mtp_valid_shortcodes',
2294
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2295
-            [$this, 'shortcode_meta_box'],
2296
-            $this->_current_screen->id,
2297
-            'side'
2298
-        );
2299
-        add_meta_box(
2300
-            'mtp_extra_actions',
2301
-            esc_html__('Extra Actions', 'event_espresso'),
2302
-            [$this, 'extra_actions_meta_box'],
2303
-            $this->_current_screen->id,
2304
-            'side',
2305
-            'high'
2306
-        );
2307
-        add_meta_box(
2308
-            'mtp_templates',
2309
-            esc_html__('Template Styles', 'event_espresso'),
2310
-            [$this, 'template_pack_meta_box'],
2311
-            $this->_current_screen->id,
2312
-            'side',
2313
-            'high'
2314
-        );
2315
-    }
2316
-
2317
-
2318
-    /**
2319
-     * metabox content for all template pack and variation selection.
2320
-     *
2321
-     * @return void
2322
-     * @throws DomainException
2323
-     * @throws EE_Error
2324
-     * @throws InvalidArgumentException
2325
-     * @throws ReflectionException
2326
-     * @throws InvalidDataTypeException
2327
-     * @throws InvalidInterfaceException
2328
-     * @since 4.5.0
2329
-     */
2330
-    public function template_pack_meta_box()
2331
-    {
2332
-        $this->_set_message_template_group();
2333
-
2334
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2335
-
2336
-        $tp_select_values = [];
2337
-
2338
-        foreach ($tp_collection as $tp) {
2339
-            // only include template packs that support this messenger and message type!
2340
-            $supports = $tp->get_supports();
2341
-            if (
2342
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2343
-                || ! in_array(
2344
-                    $this->_message_template_group->message_type(),
2345
-                    $supports[ $this->_message_template_group->messenger() ],
2346
-                    true
2347
-                )
2348
-            ) {
2349
-                // not supported
2350
-                continue;
2351
-            }
2352
-
2353
-            $tp_select_values[] = [
2354
-                'text' => $tp->label,
2355
-                'id'   => $tp->dbref,
2356
-            ];
2357
-        }
2358
-
2359
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2360
-        // the default template pack.  This still allows for the odd template pack to override.
2361
-        if (empty($tp_select_values)) {
2362
-            $tp_select_values[] = [
2363
-                'text' => esc_html__('Default', 'event_espresso'),
2364
-                'id'   => 'default',
2365
-            ];
2366
-        }
2367
-
2368
-        // setup variation select values for the currently selected template.
2369
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
-            $this->_message_template_group->messenger(),
2371
-            $this->_message_template_group->message_type()
2372
-        );
2373
-        $variations_select_values = [];
2374
-        foreach ($variations as $variation => $label) {
2375
-            $variations_select_values[] = [
2376
-                'text' => $label,
2377
-                'id'   => $variation,
2378
-            ];
2379
-        }
2380
-
2381
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382
-
2383
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
-            'MTP_template_pack',
2385
-            $tp_select_values,
2386
-            $this->_message_template_group->get_template_pack_name()
2387
-        );
2388
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
-            'MTP_template_variation',
2390
-            $variations_select_values,
2391
-            $this->_message_template_group->get_template_pack_variation()
2392
-        );
2393
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2394
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2395
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397
-
2398
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
-
2400
-        EEH_Template::display_template($template, $template_args);
2401
-    }
2402
-
2403
-
2404
-    /**
2405
-     * This meta box holds any extra actions related to Message Templates
2406
-     * For now, this includes Resetting templates to defaults and sending a test email.
2407
-     *
2408
-     * @access  public
2409
-     * @return void
2410
-     * @throws EE_Error
2411
-     */
2412
-    public function extra_actions_meta_box()
2413
-    {
2414
-        $template_form_fields = [];
2415
-
2416
-        $extra_args = [
2417
-            'msgr'   => $this->_message_template_group->messenger(),
2418
-            'mt'     => $this->_message_template_group->message_type(),
2419
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2420
-        ];
2421
-        // first we need to see if there are any fields
2422
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423
-
2424
-        if (! empty($fields)) {
2425
-            // yup there be fields
2426
-            foreach ($fields as $field => $config) {
2427
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429
-                $default  = isset($config['default']) ? $config['default'] : '';
2430
-                $default  = isset($config['value']) ? $config['value'] : $default;
2431
-
2432
-                // if type is hidden and the value is empty
2433
-                // something may have gone wrong so let's correct with the defaults
2434
-                $fix                = $config['input'] === 'hidden'
2435
-                                      && isset($existing[ $field ])
2436
-                                      && empty($existing[ $field ])
2437
-                    ? $default
2438
-                    : '';
2439
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
-                    ? $existing[ $field ]
2441
-                    : $fix;
2442
-
2443
-                $template_form_fields[ $field_id ] = [
2444
-                    'name'       => 'test_settings_fld[' . $field . ']',
2445
-                    'label'      => $config['label'],
2446
-                    'input'      => $config['input'],
2447
-                    'type'       => $config['type'],
2448
-                    'required'   => $config['required'],
2449
-                    'validation' => $config['validation'],
2450
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
-                    'css_class'  => $config['css_class'],
2452
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2453
-                    'default'    => $default,
2454
-                    'format'     => $config['format'],
2455
-                ];
2456
-            }
2457
-        }
2458
-
2459
-        $test_settings_html = ! empty($template_form_fields)
2460
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2461
-            : '';
2462
-
2463
-        // print out $test_settings_fields
2464
-        if (! empty($test_settings_html)) {
2465
-            $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466
-            $test_settings_html .= 'name="test_button" value="';
2467
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2468
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2469
-        }
2470
-
2471
-        // and button
2472
-        $test_settings_html .= '<p>';
2473
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2474
-        $test_settings_html .= '</p>';
2475
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2476
-        $test_settings_html .= $this->get_action_link_or_button(
2477
-            'reset_to_default',
2478
-            'reset',
2479
-            $extra_args,
2480
-            'button-primary reset-default-button'
2481
-        );
2482
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2483
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2484
-    }
2485
-
2486
-
2487
-    /**
2488
-     * This returns the shortcode selector skeleton for a given context and field.
2489
-     *
2490
-     * @param string $field           The name of the field retrieving shortcodes for.
2491
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2492
-     * @return string
2493
-     * @throws DomainException
2494
-     * @throws EE_Error
2495
-     * @throws InvalidArgumentException
2496
-     * @throws ReflectionException
2497
-     * @throws InvalidDataTypeException
2498
-     * @throws InvalidInterfaceException
2499
-     * @since 4.9.rc.000
2500
-     */
2501
-    protected function _get_shortcode_selector($field, $linked_input_id)
2502
-    {
2503
-        $template_args = [
2504
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2505
-            'fieldname'       => $field,
2506
-            'linked_input_id' => $linked_input_id,
2507
-        ];
2508
-
2509
-        return EEH_Template::display_template(
2510
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
-            $template_args,
2512
-            true
2513
-        );
2514
-    }
2515
-
2516
-
2517
-    /**
2518
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2519
-     * page)
2520
-     *
2521
-     * @access public
2522
-     * @return void
2523
-     * @throws EE_Error
2524
-     * @throws InvalidArgumentException
2525
-     * @throws ReflectionException
2526
-     * @throws InvalidDataTypeException
2527
-     * @throws InvalidInterfaceException
2528
-     */
2529
-    public function shortcode_meta_box()
2530
-    {
2531
-        $shortcodes = $this->_get_shortcodes([], false);
2532
-        // just make sure the shortcodes property is set
2533
-        // $messenger = $this->_message_template_group->messenger_obj();
2534
-        // now let's set the content depending on the status of the shortcodes array
2535
-        if (empty($shortcodes)) {
2536
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
-            return;
2538
-        }
2539
-        ?>
20
+	/**
21
+	 * @var EEM_Message
22
+	 */
23
+	private $MSG_MODEL;
24
+
25
+	/**
26
+	 * @var EEM_Message_Template
27
+	 */
28
+	private $MTP_MODEL;
29
+
30
+	/**
31
+	 * @var EEM_Message_Template_Group
32
+	 */
33
+	private $MTG_MODEL;
34
+
35
+	/**
36
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
37
+	 */
38
+	protected $_message_resource_manager;
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $_active_message_type_name = '';
44
+
45
+	/**
46
+	 * @var string
47
+	 */
48
+	protected $_active_messenger_name = '';
49
+
50
+	/**
51
+	 * @var EE_messenger $_active_messenger
52
+	 */
53
+	protected $_active_messenger;
54
+
55
+	protected $_activate_meta_box_type;
56
+
57
+	protected $_current_message_meta_box;
58
+
59
+	protected $_current_message_meta_box_object;
60
+
61
+	protected $_context_switcher;
62
+
63
+	protected $_shortcodes           = [];
64
+
65
+	protected $_active_messengers    = [];
66
+
67
+	protected $_active_message_types = [];
68
+
69
+	/**
70
+	 * @var EE_Message_Template_Group $_message_template_group
71
+	 */
72
+	protected $_message_template_group;
73
+
74
+	protected $_m_mt_settings = [];
75
+
76
+
77
+	/**
78
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
+	 * IF there is no group then it gets automatically set to the Default template pack.
80
+	 *
81
+	 * @since 4.5.0
82
+	 *
83
+	 * @var EE_Messages_Template_Pack
84
+	 */
85
+	protected $_template_pack;
86
+
87
+
88
+	/**
89
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
+	 * group is.  If there is no group then it automatically gets set to default.
91
+	 *
92
+	 * @since 4.5.0
93
+	 *
94
+	 * @var string
95
+	 */
96
+	protected $_variation;
97
+
98
+
99
+	/**
100
+	 * @param bool $routing
101
+	 * @throws EE_Error
102
+	 * @throws ReflectionException
103
+	 */
104
+	public function __construct($routing = true)
105
+	{
106
+		// make sure messages autoloader is running
107
+		EED_Messages::set_autoloaders();
108
+		parent::__construct($routing);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Message
114
+	 * @throws EE_Error
115
+	 */
116
+	public function getMsgModel()
117
+	{
118
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
119
+			$this->MSG_MODEL = EEM_Message::instance();
120
+		}
121
+		return $this->MSG_MODEL;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return EEM_Message_Template
127
+	 * @throws EE_Error
128
+	 */
129
+	public function getMtpModel()
130
+	{
131
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
+			$this->MTP_MODEL = EEM_Message_Template::instance();
133
+		}
134
+		return $this->MTP_MODEL;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return EEM_Message_Template_Group
140
+	 * @throws EE_Error
141
+	 */
142
+	public function getMtgModel()
143
+	{
144
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
+		}
147
+		return $this->MTG_MODEL;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @throws EE_Error
153
+	 * @throws ReflectionException
154
+	 */
155
+	protected function _init_page_props()
156
+	{
157
+		$this->page_slug        = EE_MSG_PG_SLUG;
158
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
+		$this->_admin_base_path = EE_MSG_ADMIN;
161
+
162
+		$messenger    = $this->request->getRequestParam('messenger', '');
163
+		$message_type = $this->request->getRequestParam('message_type', '');
164
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
+
167
+		$this->_load_message_resource_manager();
168
+	}
169
+
170
+
171
+	/**
172
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
+	 *
174
+	 * @throws EE_Error
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws ReflectionException
179
+	 */
180
+	protected function _load_message_resource_manager()
181
+	{
182
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return array
188
+	 * @throws EE_Error
189
+	 * @throws InvalidArgumentException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 * @deprecated 4.9.9.rc.014
193
+	 */
194
+	public function get_messengers_for_list_table()
195
+	{
196
+		EE_Error::doing_it_wrong(
197
+			__METHOD__,
198
+			sprintf(
199
+				esc_html__(
200
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
201
+					'event_espresso'
202
+				),
203
+				'Messages_Admin_Page::get_messengers_select_input()'
204
+			),
205
+			'4.9.9.rc.014'
206
+		);
207
+
208
+		$m_values          = [];
209
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
+		// setup messengers for selects
211
+		$i = 1;
212
+		foreach ($active_messengers as $active_messenger) {
213
+			if ($active_messenger instanceof EE_Message) {
214
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
215
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
+				$i++;
217
+			}
218
+		}
219
+
220
+		return $m_values;
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return array
226
+	 * @throws EE_Error
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 * @deprecated 4.9.9.rc.014
231
+	 */
232
+	public function get_message_types_for_list_table()
233
+	{
234
+		EE_Error::doing_it_wrong(
235
+			__METHOD__,
236
+			sprintf(
237
+				esc_html__(
238
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
239
+					'event_espresso'
240
+				),
241
+				'Messages_Admin_Page::get_message_types_select_input()'
242
+			),
243
+			'4.9.9.rc.014'
244
+		);
245
+
246
+		$mt_values       = [];
247
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
+		$i               = 1;
249
+		foreach ($active_messages as $active_message) {
250
+			if ($active_message instanceof EE_Message) {
251
+				$mt_values[ $i ]['id']   = $active_message->message_type();
252
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
+				$i++;
254
+			}
255
+		}
256
+
257
+		return $mt_values;
258
+	}
259
+
260
+
261
+	/**
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 * @deprecated 4.9.9.rc.014
268
+	 */
269
+	public function get_contexts_for_message_types_for_list_table()
270
+	{
271
+		EE_Error::doing_it_wrong(
272
+			__METHOD__,
273
+			sprintf(
274
+				esc_html__(
275
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
276
+					'event_espresso'
277
+				),
278
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
+			),
280
+			'4.9.9.rc.014'
281
+		);
282
+
283
+		$contexts                = [];
284
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
+		foreach ($active_message_contexts as $active_message) {
286
+			if ($active_message instanceof EE_Message) {
287
+				$message_type = $active_message->message_type_object();
288
+				if ($message_type instanceof EE_message_type) {
289
+					$message_type_contexts = $message_type->get_contexts();
290
+					foreach ($message_type_contexts as $context => $context_details) {
291
+						$contexts[ $context ] = $context_details['label'];
292
+					}
293
+				}
294
+			}
295
+		}
296
+
297
+		return $contexts;
298
+	}
299
+
300
+
301
+	/**
302
+	 * Generate select input with provided messenger options array.
303
+	 *
304
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
+	 *                                 labels.
306
+	 * @return string
307
+	 * @throws EE_Error
308
+	 */
309
+	public function get_messengers_select_input($messenger_options)
310
+	{
311
+		// if empty or just one value then just return an empty string
312
+		if (
313
+			empty($messenger_options)
314
+			|| ! is_array($messenger_options)
315
+			|| count($messenger_options) === 1
316
+		) {
317
+			return '';
318
+		}
319
+		// merge in default
320
+		$messenger_options = array_merge(
321
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
+			$messenger_options
323
+		);
324
+		$input             = new EE_Select_Input(
325
+			$messenger_options,
326
+			[
327
+				'html_name'  => 'ee_messenger_filter_by',
328
+				'html_id'    => 'ee_messenger_filter_by',
329
+				'html_class' => 'wide',
330
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
+			]
332
+		);
333
+
334
+		return $input->get_html_for_input();
335
+	}
336
+
337
+
338
+	/**
339
+	 * Generate select input with provided message type options array.
340
+	 *
341
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
+	 *                                    message type labels
343
+	 * @return string
344
+	 * @throws EE_Error
345
+	 */
346
+	public function get_message_types_select_input($message_type_options)
347
+	{
348
+		// if empty or count of options is 1 then just return an empty string
349
+		if (
350
+			empty($message_type_options)
351
+			|| ! is_array($message_type_options)
352
+			|| count($message_type_options) === 1
353
+		) {
354
+			return '';
355
+		}
356
+		// merge in default
357
+		$message_type_options = array_merge(
358
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
+			$message_type_options
360
+		);
361
+		$input                = new EE_Select_Input(
362
+			$message_type_options,
363
+			[
364
+				'html_name'  => 'ee_message_type_filter_by',
365
+				'html_id'    => 'ee_message_type_filter_by',
366
+				'html_class' => 'wide',
367
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
+			]
369
+		);
370
+
371
+		return $input->get_html_for_input();
372
+	}
373
+
374
+
375
+	/**
376
+	 * Generate select input with provide message type contexts array.
377
+	 *
378
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
+	 *                               context label.
380
+	 * @return string
381
+	 * @throws EE_Error
382
+	 */
383
+	public function get_contexts_for_message_types_select_input($context_options)
384
+	{
385
+		// if empty or count of options is one then just return empty string
386
+		if (
387
+			empty($context_options)
388
+			|| ! is_array($context_options)
389
+			|| count($context_options) === 1
390
+		) {
391
+			return '';
392
+		}
393
+		// merge in default
394
+		$context_options = array_merge(
395
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
+			$context_options
397
+		);
398
+		$input           = new EE_Select_Input(
399
+			$context_options,
400
+			[
401
+				'html_name'  => 'ee_context_filter_by',
402
+				'html_id'    => 'ee_context_filter_by',
403
+				'html_class' => 'wide',
404
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
+			]
406
+		);
407
+
408
+		return $input->get_html_for_input();
409
+	}
410
+
411
+
412
+	protected function _ajax_hooks()
413
+	{
414
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
+	}
421
+
422
+
423
+	protected function _define_page_props()
424
+	{
425
+		$this->_admin_page_title = $this->page_label;
426
+		$this->_labels           = [
427
+			'buttons'    => [
428
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
+			],
432
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
+		];
434
+	}
435
+
436
+
437
+	/**
438
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
439
+	 *
440
+	 * @access protected
441
+	 * @return void
442
+	 */
443
+	protected function _set_page_routes()
444
+	{
445
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
+
449
+		$this->_page_routes = [
450
+			'default'                          => [
451
+				'func'       => '_message_queue_list_table',
452
+				'capability' => 'ee_read_global_messages',
453
+			],
454
+			'global_mtps'                      => [
455
+				'func'       => '_ee_default_messages_overview_list_table',
456
+				'capability' => 'ee_read_global_messages',
457
+			],
458
+			'custom_mtps'                      => [
459
+				'func'       => '_custom_mtps_preview',
460
+				'capability' => 'ee_read_messages',
461
+			],
462
+			'add_new_message_template'         => [
463
+				'func'       => 'add_message_template',
464
+				'capability' => 'ee_edit_messages',
465
+				'noheader'   => true,
466
+			],
467
+			'edit_message_template'            => [
468
+				'func'       => '_edit_message_template',
469
+				'capability' => 'ee_edit_message',
470
+				'obj_id'     => $GRP_ID,
471
+			],
472
+			'preview_message'                  => [
473
+				'func'               => '_preview_message',
474
+				'capability'         => 'ee_read_message',
475
+				'obj_id'             => $GRP_ID,
476
+				'noheader'           => true,
477
+				'headers_sent_route' => 'display_preview_message',
478
+			],
479
+			'display_preview_message'          => [
480
+				'func'       => '_display_preview_message',
481
+				'capability' => 'ee_read_message',
482
+				'obj_id'     => $GRP_ID,
483
+			],
484
+			'insert_message_template'          => [
485
+				'func'       => '_insert_or_update_message_template',
486
+				'capability' => 'ee_edit_messages',
487
+				'args'       => ['new' => true],
488
+				'noheader'   => true,
489
+			],
490
+			'update_message_template'          => [
491
+				'func'       => '_insert_or_update_message_template',
492
+				'capability' => 'ee_edit_message',
493
+				'obj_id'     => $GRP_ID,
494
+				'args'       => ['new' => false],
495
+				'noheader'   => true,
496
+			],
497
+			'trash_message_template'           => [
498
+				'func'       => '_trash_or_restore_message_template',
499
+				'capability' => 'ee_delete_message',
500
+				'obj_id'     => $GRP_ID,
501
+				'args'       => ['trash' => true, 'all' => true],
502
+				'noheader'   => true,
503
+			],
504
+			'trash_message_template_context'   => [
505
+				'func'       => '_trash_or_restore_message_template',
506
+				'capability' => 'ee_delete_message',
507
+				'obj_id'     => $GRP_ID,
508
+				'args'       => ['trash' => true],
509
+				'noheader'   => true,
510
+			],
511
+			'restore_message_template'         => [
512
+				'func'       => '_trash_or_restore_message_template',
513
+				'capability' => 'ee_delete_message',
514
+				'obj_id'     => $GRP_ID,
515
+				'args'       => ['trash' => false, 'all' => true],
516
+				'noheader'   => true,
517
+			],
518
+			'restore_message_template_context' => [
519
+				'func'       => '_trash_or_restore_message_template',
520
+				'capability' => 'ee_delete_message',
521
+				'obj_id'     => $GRP_ID,
522
+				'args'       => ['trash' => false],
523
+				'noheader'   => true,
524
+			],
525
+			'delete_message_template'          => [
526
+				'func'       => '_delete_message_template',
527
+				'capability' => 'ee_delete_message',
528
+				'obj_id'     => $GRP_ID,
529
+				'noheader'   => true,
530
+			],
531
+			'reset_to_default'                 => [
532
+				'func'       => '_reset_to_default_template',
533
+				'capability' => 'ee_edit_message',
534
+				'obj_id'     => $GRP_ID,
535
+				'noheader'   => true,
536
+			],
537
+			'settings'                         => [
538
+				'func'       => '_settings',
539
+				'capability' => 'manage_options',
540
+			],
541
+			'update_global_settings'           => [
542
+				'func'       => '_update_global_settings',
543
+				'capability' => 'manage_options',
544
+				'noheader'   => true,
545
+			],
546
+			'generate_now'                     => [
547
+				'func'       => '_generate_now',
548
+				'capability' => 'ee_send_message',
549
+				'noheader'   => true,
550
+			],
551
+			'generate_and_send_now'            => [
552
+				'func'       => '_generate_and_send_now',
553
+				'capability' => 'ee_send_message',
554
+				'noheader'   => true,
555
+			],
556
+			'queue_for_resending'              => [
557
+				'func'       => '_queue_for_resending',
558
+				'capability' => 'ee_send_message',
559
+				'noheader'   => true,
560
+			],
561
+			'send_now'                         => [
562
+				'func'       => '_send_now',
563
+				'capability' => 'ee_send_message',
564
+				'noheader'   => true,
565
+			],
566
+			'delete_ee_message'                => [
567
+				'func'       => '_delete_ee_messages',
568
+				'capability' => 'ee_delete_messages',
569
+				'noheader'   => true,
570
+			],
571
+			'delete_ee_messages'               => [
572
+				'func'       => '_delete_ee_messages',
573
+				'capability' => 'ee_delete_messages',
574
+				'noheader'   => true,
575
+				'obj_id'     => $MSG_ID,
576
+			],
577
+		];
578
+	}
579
+
580
+
581
+	protected function _set_page_config()
582
+	{
583
+		$this->_page_config = [
584
+			'default'                  => [
585
+				'nav'           => [
586
+					'label' => esc_html__('Message Activity', 'event_espresso'),
587
+					'order' => 10,
588
+				],
589
+				'list_table'    => 'EE_Message_List_Table',
590
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
+				'require_nonce' => false,
592
+			],
593
+			'global_mtps'              => [
594
+				'nav'           => [
595
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
+					'order' => 20,
597
+				],
598
+				'list_table'    => 'Messages_Template_List_Table',
599
+				'help_tabs'     => [
600
+					'messages_overview_help_tab'                                => [
601
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
+						'filename' => 'messages_overview',
603
+					],
604
+					'messages_overview_messages_table_column_headings_help_tab' => [
605
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
+						'filename' => 'messages_overview_table_column_headings',
607
+					],
608
+					'messages_overview_messages_filters_help_tab'               => [
609
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
610
+						'filename' => 'messages_overview_filters',
611
+					],
612
+					'messages_overview_messages_views_help_tab'                 => [
613
+						'title'    => esc_html__('Message Views', 'event_espresso'),
614
+						'filename' => 'messages_overview_views',
615
+					],
616
+					'message_overview_message_types_help_tab'                   => [
617
+						'title'    => esc_html__('Message Types', 'event_espresso'),
618
+						'filename' => 'messages_overview_types',
619
+					],
620
+					'messages_overview_messengers_help_tab'                     => [
621
+						'title'    => esc_html__('Messengers', 'event_espresso'),
622
+						'filename' => 'messages_overview_messengers',
623
+					],
624
+				],
625
+				'require_nonce' => false,
626
+			],
627
+			'custom_mtps'              => [
628
+				'nav'           => [
629
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
+					'order' => 30,
631
+				],
632
+				'help_tabs'     => [],
633
+				'require_nonce' => false,
634
+			],
635
+			'add_new_message_template' => [
636
+				'nav'           => [
637
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
+					'order'      => 5,
639
+					'persistent' => false,
640
+				],
641
+				'require_nonce' => false,
642
+			],
643
+			'edit_message_template'    => [
644
+				'labels'        => [
645
+					'buttons'    => [
646
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
+					],
648
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
+				],
650
+				'nav'           => [
651
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
+					'order'      => 5,
653
+					'persistent' => false,
654
+					'url'        => '',
655
+				],
656
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
+				'has_metaboxes' => true,
658
+				'help_tabs'     => [
659
+					'edit_message_template'            => [
660
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
+						'callback' => 'edit_message_template_help_tab',
662
+					],
663
+					'message_templates_help_tab'       => [
664
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
665
+						'filename' => 'messages_templates',
666
+					],
667
+					'message_template_shortcodes'      => [
668
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
+						'callback' => 'message_template_shortcodes_help_tab',
670
+					],
671
+					'message_preview_help_tab'         => [
672
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
673
+						'filename' => 'messages_preview',
674
+					],
675
+					'messages_overview_other_help_tab' => [
676
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
677
+						'filename' => 'messages_overview_other',
678
+					],
679
+				],
680
+				'require_nonce' => false,
681
+			],
682
+			'display_preview_message'  => [
683
+				'nav'           => [
684
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
685
+					'order'      => 5,
686
+					'url'        => '',
687
+					'persistent' => false,
688
+				],
689
+				'help_tabs'     => [
690
+					'preview_message' => [
691
+						'title'    => esc_html__('About Previews', 'event_espresso'),
692
+						'callback' => 'preview_message_help_tab',
693
+					],
694
+				],
695
+				'require_nonce' => false,
696
+			],
697
+			'settings'                 => [
698
+				'nav'           => [
699
+					'label' => esc_html__('Settings', 'event_espresso'),
700
+					'order' => 40,
701
+				],
702
+				'metaboxes'     => ['_messages_settings_metaboxes'],
703
+				'help_tabs'     => [
704
+					'messages_settings_help_tab'               => [
705
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
+						'filename' => 'messages_settings',
707
+					],
708
+					'messages_settings_message_types_help_tab' => [
709
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
+						'filename' => 'messages_settings_message_types',
711
+					],
712
+					'messages_settings_messengers_help_tab'    => [
713
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
+						'filename' => 'messages_settings_messengers',
715
+					],
716
+				],
717
+				'require_nonce' => false,
718
+			],
719
+		];
720
+	}
721
+
722
+
723
+	protected function _add_screen_options()
724
+	{
725
+		// todo
726
+	}
727
+
728
+
729
+	protected function _add_screen_options_global_mtps()
730
+	{
731
+		/**
732
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
734
+		 */
735
+		$page_title              = $this->_admin_page_title;
736
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
+		$this->_per_page_screen_option();
738
+		$this->_admin_page_title = $page_title;
739
+	}
740
+
741
+
742
+	protected function _add_screen_options_default()
743
+	{
744
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
+		$this->_per_page_screen_option();
746
+	}
747
+
748
+
749
+	// none of the below group are currently used for Messages
750
+	protected function _add_feature_pointers()
751
+	{
752
+	}
753
+
754
+
755
+	public function admin_init()
756
+	{
757
+	}
758
+
759
+
760
+	public function admin_notices()
761
+	{
762
+	}
763
+
764
+
765
+	public function admin_footer_scripts()
766
+	{
767
+	}
768
+
769
+
770
+	public function messages_help_tab()
771
+	{
772
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
+	}
774
+
775
+
776
+	public function messengers_help_tab()
777
+	{
778
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
+	}
780
+
781
+
782
+	public function message_types_help_tab()
783
+	{
784
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
+	}
786
+
787
+
788
+	public function messages_overview_help_tab()
789
+	{
790
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
+	}
792
+
793
+
794
+	public function message_templates_help_tab()
795
+	{
796
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
+	}
798
+
799
+
800
+	public function edit_message_template_help_tab()
801
+	{
802
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
+						. esc_attr__('Editor Title', 'event_espresso')
804
+						. '" />';
805
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
807
+						. '" />';
808
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
810
+						. '" />';
811
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
813
+						. '" />';
814
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
+						. esc_attr__('Publish Metabox', 'event_espresso')
816
+						. '" />';
817
+		EEH_Template::display_template(
818
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
+			$args
820
+		);
821
+	}
822
+
823
+
824
+	/**
825
+	 * @throws ReflectionException
826
+	 * @throws EE_Error
827
+	 */
828
+	public function message_template_shortcodes_help_tab()
829
+	{
830
+		$this->_set_shortcodes();
831
+		$args['shortcodes'] = $this->_shortcodes;
832
+		EEH_Template::display_template(
833
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
+			$args
835
+		);
836
+	}
837
+
838
+
839
+	public function preview_message_help_tab()
840
+	{
841
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
+	}
843
+
844
+
845
+	public function settings_help_tab()
846
+	{
847
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
+		$args['img3'] = '<div class="switch">'
852
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
+						. ' type="checkbox" checked>'
854
+						. '<label for="ee-on-off-toggle-on"></label>'
855
+						. '</div>';
856
+		$args['img4'] = '<div class="switch">'
857
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
+						. ' type="checkbox">'
859
+						. '<label for="ee-on-off-toggle-on"></label>'
860
+						. '</div>';
861
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
+	}
863
+
864
+
865
+	public function load_scripts_styles()
866
+	{
867
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
+		wp_enqueue_style('espresso_ee_msg');
869
+
870
+		wp_register_script(
871
+			'ee-messages-settings',
872
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
874
+			EVENT_ESPRESSO_VERSION,
875
+			true
876
+		);
877
+		wp_register_script(
878
+			'ee-msg-list-table-js',
879
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
+			['ee-dialog'],
881
+			EVENT_ESPRESSO_VERSION
882
+		);
883
+	}
884
+
885
+
886
+	public function load_scripts_styles_default()
887
+	{
888
+		wp_enqueue_script('ee-msg-list-table-js');
889
+	}
890
+
891
+
892
+	public function wp_editor_css($mce_css)
893
+	{
894
+		// if we're on the edit_message_template route
895
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
+			$message_type_name = $this->_active_message_type_name;
897
+
898
+			// we're going to REPLACE the existing mce css
899
+			// we need to get the css file location from the active messenger
900
+			$mce_css = $this->_active_messenger->get_variation(
901
+				$this->_template_pack,
902
+				$message_type_name,
903
+				true,
904
+				'wpeditor',
905
+				$this->_variation
906
+			);
907
+		}
908
+
909
+		return $mce_css;
910
+	}
911
+
912
+
913
+	/**
914
+	 * @throws EE_Error
915
+	 * @throws ReflectionException
916
+	 */
917
+	public function load_scripts_styles_edit_message_template()
918
+	{
919
+
920
+		$this->_set_shortcodes();
921
+
922
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
+			esc_html__(
924
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925
+				'event_espresso'
926
+			),
927
+			$this->_message_template_group->messenger_obj()->label['singular'],
928
+			$this->_message_template_group->message_type_obj()->label['singular']
929
+		);
930
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932
+			'event_espresso'
933
+		);
934
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
+			'event_espresso'
937
+		);
938
+
939
+		wp_register_script(
940
+			'ee_msgs_edit_js',
941
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
+			['jquery'],
943
+			EVENT_ESPRESSO_VERSION
944
+		);
945
+
946
+		wp_enqueue_script('ee_admin_js');
947
+		wp_enqueue_script('ee_msgs_edit_js');
948
+
949
+		// add in special css for tiny_mce
950
+		add_filter('mce_css', [$this, 'wp_editor_css']);
951
+	}
952
+
953
+
954
+	/**
955
+	 * @throws EE_Error
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function load_scripts_styles_display_preview_message()
959
+	{
960
+		$this->_set_message_template_group();
961
+		if ($this->_active_messenger_name) {
962
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
+				$this->_active_messenger_name
964
+			);
965
+		}
966
+
967
+		wp_enqueue_style(
968
+			'espresso_preview_css',
969
+			$this->_active_messenger->get_variation(
970
+				$this->_template_pack,
971
+				$this->_active_message_type_name,
972
+				true,
973
+				'preview',
974
+				$this->_variation
975
+			)
976
+		);
977
+	}
978
+
979
+
980
+	public function load_scripts_styles_settings()
981
+	{
982
+		wp_register_style(
983
+			'ee-message-settings',
984
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
+			[],
986
+			EVENT_ESPRESSO_VERSION
987
+		);
988
+		wp_enqueue_style('ee-text-links');
989
+		wp_enqueue_style('ee-message-settings');
990
+		wp_enqueue_script('ee-messages-settings');
991
+	}
992
+
993
+
994
+	/**
995
+	 * set views array for List Table
996
+	 */
997
+	public function _set_list_table_views_global_mtps()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'  => 'in_use',
1002
+				'label' => esc_html__('In Use', 'event_espresso'),
1003
+				'count' => 0,
1004
+			],
1005
+		];
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * Set views array for the Custom Template List Table
1011
+	 */
1012
+	public function _set_list_table_views_custom_mtps()
1013
+	{
1014
+		$this->_set_list_table_views_global_mtps();
1015
+		$this->_views['in_use']['bulk_action'] = [
1016
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
+		];
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * set views array for message queue list table
1023
+	 *
1024
+	 * @throws InvalidDataTypeException
1025
+	 * @throws InvalidInterfaceException
1026
+	 * @throws InvalidArgumentException
1027
+	 * @throws EE_Error
1028
+	 * @throws ReflectionException
1029
+	 */
1030
+	public function _set_list_table_views_default()
1031
+	{
1032
+		EE_Registry::instance()->load_helper('Template');
1033
+
1034
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
+			'ee_send_message',
1036
+			'message_list_table_bulk_actions'
1037
+		)
1038
+			? [
1039
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
+			]
1044
+			: [];
1045
+
1046
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
+			'ee_delete_messages',
1048
+			'message_list_table_bulk_actions'
1049
+		)
1050
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
+			: [];
1052
+
1053
+
1054
+		$this->_views = [
1055
+			'all' => [
1056
+				'slug'        => 'all',
1057
+				'label'       => esc_html__('All', 'event_espresso'),
1058
+				'count'       => 0,
1059
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
+			],
1061
+		];
1062
+
1063
+
1064
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
+				continue;
1067
+			}
1068
+			$status_bulk_actions = $common_bulk_actions;
1069
+			// unset bulk actions not applying to status
1070
+			if (! empty($status_bulk_actions)) {
1071
+				switch ($status) {
1072
+					case EEM_Message::status_idle:
1073
+					case EEM_Message::status_resend:
1074
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
+						break;
1076
+
1077
+					case EEM_Message::status_failed:
1078
+					case EEM_Message::status_debug_only:
1079
+					case EEM_Message::status_messenger_executing:
1080
+						$status_bulk_actions = [];
1081
+						break;
1082
+
1083
+					case EEM_Message::status_incomplete:
1084
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
+						break;
1086
+
1087
+					case EEM_Message::status_retry:
1088
+					case EEM_Message::status_sent:
1089
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
+						break;
1091
+				}
1092
+			}
1093
+
1094
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1095
+			if ($status === EEM_Message::status_messenger_executing) {
1096
+				continue;
1097
+			}
1098
+
1099
+			$this->_views[ strtolower($status) ] = [
1100
+				'slug'        => strtolower($status),
1101
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
+				'count'       => 0,
1103
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
+			];
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * @throws EE_Error
1111
+	 */
1112
+	protected function _ee_default_messages_overview_list_table()
1113
+	{
1114
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * @throws EE_Error
1121
+	 * @throws ReflectionException
1122
+	 */
1123
+	protected function _message_queue_list_table()
1124
+	{
1125
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
+		$this->_template_args['per_column']        = 6;
1127
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
+		$this->_template_args['before_list_table'] = '<h3>'
1129
+													 . $this->getMsgModel()->get_pretty_label_for_results()
1130
+													 . '</h3>';
1131
+		$this->display_admin_list_table_page_with_no_sidebar();
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * @throws EE_Error
1137
+	 */
1138
+	protected function _message_legend_items()
1139
+	{
1140
+
1141
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1142
+		$action_items       = [];
1143
+
1144
+		foreach ($action_css_classes as $action_item => $action_details) {
1145
+			if ($action_item === 'see_notifications_for') {
1146
+				continue;
1147
+			}
1148
+			$action_items[ $action_item ] = [
1149
+				'class' => $action_details['css_class'],
1150
+				'desc'  => $action_details['label'],
1151
+			];
1152
+		}
1153
+
1154
+		/** @var array $status_items status legend setup */
1155
+		$status_items = [
1156
+			'sent_status'                => [
1157
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1158
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159
+			],
1160
+			'idle_status'                => [
1161
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1162
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163
+			],
1164
+			'failed_status'              => [
1165
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1166
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167
+			],
1168
+			'messenger_executing_status' => [
1169
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1170
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171
+			],
1172
+			'resend_status'              => [
1173
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1174
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175
+			],
1176
+			'incomplete_status'          => [
1177
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1178
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179
+			],
1180
+			'retry_status'               => [
1181
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1182
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183
+			],
1184
+		];
1185
+		if (EEM_Message::debug()) {
1186
+			$status_items['debug_only_status'] = [
1187
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1188
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189
+			];
1190
+		}
1191
+
1192
+		return array_merge($action_items, $status_items);
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * @throws EE_Error
1198
+	 */
1199
+	protected function _custom_mtps_preview()
1200
+	{
1201
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
+												. ' alt="' . esc_attr__(
1204
+													'Preview Custom Message Templates screenshot',
1205
+													'event_espresso'
1206
+												) . '" />';
1207
+		$this->_template_args['preview_text'] = '<strong>'
1208
+												. esc_html__(
1209
+													'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1210
+													'event_espresso'
1211
+												)
1212
+												. '</strong>';
1213
+
1214
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * get_message_templates
1220
+	 * This gets all the message templates for listing on the overview list.
1221
+	 *
1222
+	 * @access public
1223
+	 * @param int    $per_page the amount of templates groups to show per page
1224
+	 * @param string $type     the current _view we're getting templates for
1225
+	 * @param bool   $count    return count?
1226
+	 * @param bool   $all      disregard any paging info (get all data);
1227
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1228
+	 * @return array
1229
+	 * @throws EE_Error
1230
+	 * @throws InvalidArgumentException
1231
+	 * @throws InvalidDataTypeException
1232
+	 * @throws InvalidInterfaceException
1233
+	 */
1234
+	public function get_message_templates(
1235
+		$per_page = 10,
1236
+		$type = 'in_use',
1237
+		$count = false,
1238
+		$all = false,
1239
+		$global = true
1240
+	) {
1241
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1242
+		$this->request->setRequestParam('orderby', $orderby);
1243
+
1244
+		$order        = $this->request->getRequestParam('order', 'ASC');
1245
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1246
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1247
+
1248
+		$offset = ($current_page - 1) * $per_page;
1249
+		$limit  = $all ? null : [$offset, $per_page];
1250
+
1251
+		// options will match what is in the _views array property
1252
+		return $type === 'in_use'
1253
+			? $this->getMtgModel()->get_all_active_message_templates(
1254
+				$orderby,
1255
+				$order,
1256
+				$limit,
1257
+				$count,
1258
+				$global,
1259
+				true
1260
+			)
1261
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1262
+				$orderby,
1263
+				$order,
1264
+				$limit,
1265
+				$count,
1266
+				$global
1267
+			);
1268
+	}
1269
+
1270
+
1271
+	/**
1272
+	 * filters etc might need a list of installed message_types
1273
+	 *
1274
+	 * @return array an array of message type objects
1275
+	 */
1276
+	public function get_installed_message_types()
1277
+	{
1278
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1279
+		$installed               = [];
1280
+
1281
+		foreach ($installed_message_types as $message_type) {
1282
+			$installed[ $message_type->name ] = $message_type;
1283
+		}
1284
+
1285
+		return $installed;
1286
+	}
1287
+
1288
+
1289
+	/**
1290
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1291
+	 *
1292
+	 * @param string $message_type
1293
+	 * @param string $messenger
1294
+	 * @param string $GRP_ID
1295
+	 *
1296
+	 * @throws EE_error
1297
+	 * @throws ReflectionException
1298
+	 */
1299
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1300
+	{
1301
+		// set values override any request data
1302
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1303
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1304
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1305
+
1306
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1307
+		if (empty($message_type) || empty($messenger)) {
1308
+			throw new EE_Error(
1309
+				esc_html__(
1310
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1311
+					'event_espresso'
1312
+				)
1313
+			);
1314
+		}
1315
+
1316
+		// we need the GRP_ID for the template being used as the base for the new template
1317
+		if (empty($GRP_ID)) {
1318
+			throw new EE_Error(
1319
+				esc_html__(
1320
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1321
+					'event_espresso'
1322
+				)
1323
+			);
1324
+		}
1325
+
1326
+		// let's just make sure the template gets generated!
1327
+
1328
+		// we need to reassign some variables for what the insert is expecting
1329
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1330
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1331
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1332
+
1333
+		$this->_insert_or_update_message_template(true);
1334
+	}
1335
+
1336
+
1337
+	/**
1338
+	 * @param string $message_type     message type slug
1339
+	 * @param string $messenger        messenger slug
1340
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1341
+	 *                                 off of.
1342
+	 * @throws EE_error
1343
+	 * @throws ReflectionException
1344
+	 * @deprecated 4.10.29.p
1345
+	 */
1346
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1347
+	{
1348
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1349
+	}
1350
+
1351
+
1352
+	/**
1353
+	 * _edit_message_template
1354
+	 *
1355
+	 * @access protected
1356
+	 * @return void
1357
+	 * @throws InvalidIdentifierException
1358
+	 * @throws DomainException
1359
+	 * @throws EE_Error
1360
+	 * @throws InvalidArgumentException
1361
+	 * @throws ReflectionException
1362
+	 * @throws InvalidDataTypeException
1363
+	 * @throws InvalidInterfaceException
1364
+	 */
1365
+	protected function _edit_message_template()
1366
+	{
1367
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1368
+		$template_fields = '';
1369
+		$sidebar_fields  = '';
1370
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1371
+		// valid html in the templates.
1372
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1373
+
1374
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1375
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1376
+
1377
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1378
+		$message_template_group = $this->_message_template_group;
1379
+		$c_label                = $message_template_group->context_label();
1380
+		$c_config               = $message_template_group->contexts_config();
1381
+
1382
+		reset($c_config);
1383
+		$context = $this->request->getRequestParam('context', key($c_config));
1384
+		$context = strtolower($context);
1385
+
1386
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1387
+
1388
+		$edit_message_template_form_url = add_query_arg(
1389
+			['action' => $action, 'noheader' => true],
1390
+			EE_MSG_ADMIN_URL
1391
+		);
1392
+
1393
+		// set active messenger for this view
1394
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1395
+			$message_template_group->messenger()
1396
+		);
1397
+		$this->_active_message_type_name = $message_template_group->message_type();
1398
+
1399
+
1400
+		// Do we have any validation errors?
1401
+		$validators = $this->_get_transient();
1402
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1403
+
1404
+
1405
+		// we need to assemble the title from Various details
1406
+		$context_label = sprintf(
1407
+			esc_html__('(%s %s)', 'event_espresso'),
1408
+			$c_config[ $context ]['label'],
1409
+			ucwords($c_label['label'])
1410
+		);
1411
+
1412
+		$title = sprintf(
1413
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1414
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1415
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1416
+			$context_label
1417
+		);
1418
+
1419
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1420
+		$this->_template_args['message_template'] = $message_template_group;
1421
+		$this->_template_args['is_extra_fields']  = false;
1422
+
1423
+
1424
+		// let's get EEH_MSG_Template so we can get template form fields
1425
+		$template_field_structure = EEH_MSG_Template::get_fields(
1426
+			$message_template_group->messenger(),
1427
+			$message_template_group->message_type()
1428
+		);
1429
+
1430
+		if (! $template_field_structure) {
1431
+			$template_field_structure = false;
1432
+			$template_fields          = esc_html__(
1433
+				'There was an error in assembling the fields for this display (you should see an error message)',
1434
+				'event_espresso'
1435
+			);
1436
+		}
1437
+
1438
+
1439
+		$message_templates = $message_template_group->context_templates();
1440
+
1441
+
1442
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443
+		// will get handled in the "extra" array.
1444
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
+				unset($template_field_structure[ $context ][ $reference_field ]);
1447
+			}
1448
+		}
1449
+
1450
+		// let's loop through the template_field_structure and actually assemble the input fields!
1451
+		if (! empty($template_field_structure)) {
1452
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454
+				// the extra array and reset them.
1455
+				if ($template_field === 'extra') {
1456
+					$this->_template_args['is_extra_fields'] = true;
1457
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
+						$message_template = $message_templates[ $context ][ $reference_field ];
1459
+						$content          = $message_template instanceof EE_Message_Template
1460
+							? $message_template->get('MTP_content')
1461
+							: '';
1462
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1463
+							// let's verify if we need this extra field via the shortcodes parameter.
1464
+							$continue = false;
1465
+							if (isset($extra_array['shortcodes_required'])) {
1466
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1468
+										$continue = true;
1469
+									}
1470
+								}
1471
+								if ($continue) {
1472
+									continue;
1473
+								}
1474
+							}
1475
+
1476
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1477
+
1478
+							$template_form_fields[ $field_id ]         = $extra_array;
1479
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
+																		 . $reference_field
1481
+																		 . '][content]['
1482
+																		 . $extra_field . ']';
1483
+							$css_class                                 = isset($extra_array['css_class'])
1484
+								? $extra_array['css_class']
1485
+								: '';
1486
+
1487
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1488
+																			  && in_array($extra_field, $v_fields, true)
1489
+																			  && (
1490
+																				  is_array($validators[ $extra_field ])
1491
+																				  && isset($validators[ $extra_field ]['msg'])
1492
+																			  )
1493
+								? 'validate-error ' . $css_class
1494
+								: $css_class;
1495
+
1496
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
+																		  && isset($content[ $extra_field ])
1498
+								? $content[ $extra_field ]
1499
+								: '';
1500
+
1501
+							// do we have a validation error?  if we do then let's use that value instead
1502
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
+								? $validators[ $extra_field ]['value']
1504
+								: $template_form_fields[ $field_id ]['value'];
1505
+
1506
+
1507
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1508
+
1509
+							// shortcode selector
1510
+							$field_name_to_use                                   = $extra_field === 'main'
1511
+								? 'content'
1512
+								: $extra_field;
1513
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1514
+								$field_name_to_use,
1515
+								$field_id
1516
+							);
1517
+						}
1518
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
+						$template_field_template_name_id = $reference_field . '-name';
1520
+
1521
+						$template_form_fields[ $template_field_MTP_id ] = [
1522
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
+							'label'      => null,
1524
+							'input'      => 'hidden',
1525
+							'type'       => 'int',
1526
+							'required'   => false,
1527
+							'validation' => false,
1528
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1529
+							'css_class'  => '',
1530
+							'format'     => '%d',
1531
+							'db-col'     => 'MTP_ID',
1532
+						];
1533
+
1534
+						$template_form_fields[ $template_field_template_name_id ] = [
1535
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
+							'label'      => null,
1537
+							'input'      => 'hidden',
1538
+							'type'       => 'string',
1539
+							'required'   => false,
1540
+							'validation' => true,
1541
+							'value'      => $reference_field,
1542
+							'css_class'  => '',
1543
+							'format'     => '%s',
1544
+							'db-col'     => 'MTP_template_field',
1545
+						];
1546
+					}
1547
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548
+				} else {
1549
+					$field_id                                   = $template_field . '-content';
1550
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1551
+					$template_form_fields[ $field_id ]['name']  =
1552
+						'MTP_template_fields[' . $template_field . '][content]';
1553
+					$message_template                           =
1554
+						isset($message_templates[ $context ][ $template_field ])
1555
+							? $message_templates[ $context ][ $template_field ]
1556
+							: null;
1557
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
+																  && is_array($message_templates[ $context ])
1559
+																  && $message_template instanceof EE_Message_Template
1560
+						? $message_template->get('MTP_content')
1561
+						: '';
1562
+
1563
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1564
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
+						? $validators[ $template_field ]['value']
1566
+						: $template_form_fields[ $field_id ]['value'];
1567
+
1568
+
1569
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1570
+					$css_class                                      = isset($field_setup_array['css_class'])
1571
+						? $field_setup_array['css_class']
1572
+						: '';
1573
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1574
+																	  && in_array($template_field, $v_fields, true)
1575
+																	  && isset($validators[ $template_field ]['msg'])
1576
+						? 'validate-error ' . $css_class
1577
+						: $css_class;
1578
+
1579
+					// shortcode selector
1580
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1581
+						$template_field,
1582
+						$field_id
1583
+					);
1584
+				}
1585
+
1586
+				// k took care of content field(s) now let's take care of others.
1587
+
1588
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
+				$template_field_field_template_name_id = $template_field . '-name';
1590
+
1591
+				// foreach template field there are actually two form fields created
1592
+				$template_form_fields[ $template_field_MTP_id ] = [
1593
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
+					'label'      => null,
1595
+					'input'      => 'hidden',
1596
+					'type'       => 'int',
1597
+					'required'   => false,
1598
+					'validation' => true,
1599
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1600
+					'css_class'  => '',
1601
+					'format'     => '%d',
1602
+					'db-col'     => 'MTP_ID',
1603
+				];
1604
+
1605
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1606
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
+					'label'      => null,
1608
+					'input'      => 'hidden',
1609
+					'type'       => 'string',
1610
+					'required'   => false,
1611
+					'validation' => true,
1612
+					'value'      => $template_field,
1613
+					'css_class'  => '',
1614
+					'format'     => '%s',
1615
+					'db-col'     => 'MTP_template_field',
1616
+				];
1617
+			}
1618
+
1619
+			// add other fields
1620
+			$template_form_fields['ee-msg-current-context'] = [
1621
+				'name'       => 'MTP_context',
1622
+				'label'      => null,
1623
+				'input'      => 'hidden',
1624
+				'type'       => 'string',
1625
+				'required'   => false,
1626
+				'validation' => true,
1627
+				'value'      => $context,
1628
+				'css_class'  => '',
1629
+				'format'     => '%s',
1630
+				'db-col'     => 'MTP_context',
1631
+			];
1632
+
1633
+			$template_form_fields['ee-msg-grp-id'] = [
1634
+				'name'       => 'GRP_ID',
1635
+				'label'      => null,
1636
+				'input'      => 'hidden',
1637
+				'type'       => 'int',
1638
+				'required'   => false,
1639
+				'validation' => true,
1640
+				'value'      => $GRP_ID,
1641
+				'css_class'  => '',
1642
+				'format'     => '%d',
1643
+				'db-col'     => 'GRP_ID',
1644
+			];
1645
+
1646
+			$template_form_fields['ee-msg-messenger'] = [
1647
+				'name'       => 'MTP_messenger',
1648
+				'label'      => null,
1649
+				'input'      => 'hidden',
1650
+				'type'       => 'string',
1651
+				'required'   => false,
1652
+				'validation' => true,
1653
+				'value'      => $message_template_group->messenger(),
1654
+				'css_class'  => '',
1655
+				'format'     => '%s',
1656
+				'db-col'     => 'MTP_messenger',
1657
+			];
1658
+
1659
+			$template_form_fields['ee-msg-message-type'] = [
1660
+				'name'       => 'MTP_message_type',
1661
+				'label'      => null,
1662
+				'input'      => 'hidden',
1663
+				'type'       => 'string',
1664
+				'required'   => false,
1665
+				'validation' => true,
1666
+				'value'      => $message_template_group->message_type(),
1667
+				'css_class'  => '',
1668
+				'format'     => '%s',
1669
+				'db-col'     => 'MTP_message_type',
1670
+			];
1671
+
1672
+			$sidebar_form_fields['ee-msg-is-global'] = [
1673
+				'name'       => 'MTP_is_global',
1674
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1675
+				'input'      => 'hidden',
1676
+				'type'       => 'int',
1677
+				'required'   => false,
1678
+				'validation' => true,
1679
+				'value'      => $message_template_group->get('MTP_is_global'),
1680
+				'css_class'  => '',
1681
+				'format'     => '%d',
1682
+				'db-col'     => 'MTP_is_global',
1683
+			];
1684
+
1685
+			$sidebar_form_fields['ee-msg-is-override'] = [
1686
+				'name'       => 'MTP_is_override',
1687
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1688
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1689
+				'type'       => 'int',
1690
+				'required'   => false,
1691
+				'validation' => true,
1692
+				'value'      => $message_template_group->get('MTP_is_override'),
1693
+				'css_class'  => '',
1694
+				'format'     => '%d',
1695
+				'db-col'     => 'MTP_is_override',
1696
+			];
1697
+
1698
+			$sidebar_form_fields['ee-msg-is-active'] = [
1699
+				'name'       => 'MTP_is_active',
1700
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1701
+				'input'      => 'hidden',
1702
+				'type'       => 'int',
1703
+				'required'   => false,
1704
+				'validation' => true,
1705
+				'value'      => $message_template_group->is_active(),
1706
+				'css_class'  => '',
1707
+				'format'     => '%d',
1708
+				'db-col'     => 'MTP_is_active',
1709
+			];
1710
+
1711
+			$sidebar_form_fields['ee-msg-deleted'] = [
1712
+				'name'       => 'MTP_deleted',
1713
+				'label'      => null,
1714
+				'input'      => 'hidden',
1715
+				'type'       => 'int',
1716
+				'required'   => false,
1717
+				'validation' => true,
1718
+				'value'      => $message_template_group->get('MTP_deleted'),
1719
+				'css_class'  => '',
1720
+				'format'     => '%d',
1721
+				'db-col'     => 'MTP_deleted',
1722
+			];
1723
+			$sidebar_form_fields['ee-msg-author']  = [
1724
+				'name'       => 'MTP_user_id',
1725
+				'label'      => esc_html__('Author', 'event_espresso'),
1726
+				'input'      => 'hidden',
1727
+				'type'       => 'int',
1728
+				'required'   => false,
1729
+				'validation' => false,
1730
+				'value'      => $message_template_group->user(),
1731
+				'format'     => '%d',
1732
+				'db-col'     => 'MTP_user_id',
1733
+			];
1734
+
1735
+			$sidebar_form_fields['ee-msg-route'] = [
1736
+				'name'  => 'action',
1737
+				'input' => 'hidden',
1738
+				'type'  => 'string',
1739
+				'value' => $action,
1740
+			];
1741
+
1742
+			$sidebar_form_fields['ee-msg-id']        = [
1743
+				'name'  => 'id',
1744
+				'input' => 'hidden',
1745
+				'type'  => 'int',
1746
+				'value' => $GRP_ID,
1747
+			];
1748
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
+				'name'  => $action . '_nonce',
1750
+				'input' => 'hidden',
1751
+				'type'  => 'string',
1752
+				'value' => wp_create_nonce($action . '_nonce'),
1753
+			];
1754
+
1755
+			$template_switch = $this->request->getRequestParam('template_switch');
1756
+			if ($template_switch) {
1757
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1758
+					'name'  => 'template_switch',
1759
+					'input' => 'hidden',
1760
+					'type'  => 'int',
1761
+					'value' => 1,
1762
+				];
1763
+			}
1764
+
1765
+
1766
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1767
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1768
+		} //end if ( !empty($template_field_structure) )
1769
+
1770
+		// set extra content for publish box
1771
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1772
+		$this->_set_publish_post_box_vars(
1773
+			'id',
1774
+			$GRP_ID,
1775
+			false,
1776
+			add_query_arg(
1777
+				['action' => 'global_mtps'],
1778
+				$this->_admin_base_url
1779
+			)
1780
+		);
1781
+
1782
+		// add preview button
1783
+		$preview_url    = parent::add_query_args_and_nonce(
1784
+			[
1785
+				'message_type' => $message_template_group->message_type(),
1786
+				'messenger'    => $message_template_group->messenger(),
1787
+				'context'      => $context,
1788
+				'GRP_ID'       => $GRP_ID,
1789
+				'evt_id'       => $EVT_ID ?: false,
1790
+				'action'       => 'preview_message',
1791
+			],
1792
+			$this->_admin_base_url
1793
+		);
1794
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1795
+						  . esc_html__('Preview', 'event_espresso')
1796
+						  . '</a>';
1797
+
1798
+
1799
+		// setup context switcher
1800
+		$this->_set_context_switcher(
1801
+			$message_template_group,
1802
+			[
1803
+				'page'    => 'espresso_messages',
1804
+				'action'  => 'edit_message_template',
1805
+				'id'      => $GRP_ID,
1806
+				'evt_id'  => $EVT_ID,
1807
+				'context' => $context,
1808
+				'extra'   => $preview_button,
1809
+			]
1810
+		);
1811
+
1812
+
1813
+		// main box
1814
+		$this->_template_args['template_fields']                         = $template_fields;
1815
+		$this->_template_args['sidebar_box_id']                          = 'details';
1816
+		$this->_template_args['action']                                  = $action;
1817
+		$this->_template_args['context']                                 = $context;
1818
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1819
+		$this->_template_args['learn_more_about_message_templates_link'] =
1820
+			$this->_learn_more_about_message_templates_link();
1821
+
1822
+
1823
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1824
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1825
+			$message_template_group,
1826
+			$context,
1827
+			$context_label
1828
+		);
1829
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
+
1832
+		$this->_template_path = $this->_template_args['GRP_ID']
1833
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
+
1836
+		// send along EE_Message_Template_Group object for further template use.
1837
+		$this->_template_args['MTP'] = $message_template_group;
1838
+
1839
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1840
+			$this->_template_path,
1841
+			$this->_template_args,
1842
+			true
1843
+		);
1844
+
1845
+
1846
+		// finally, let's set the admin_page title
1847
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1848
+
1849
+
1850
+		// we need to take care of setting the shortcodes property for use elsewhere.
1851
+		$this->_set_shortcodes();
1852
+
1853
+
1854
+		// final template wrapper
1855
+		$this->display_admin_page_with_sidebar();
1856
+	}
1857
+
1858
+
1859
+	public function filter_tinymce_init($mceInit, $editor_id)
1860
+	{
1861
+		return $mceInit;
1862
+	}
1863
+
1864
+
1865
+	public function add_context_switcher()
1866
+	{
1867
+		return $this->_context_switcher;
1868
+	}
1869
+
1870
+
1871
+	/**
1872
+	 * Adds the activation/deactivation toggle for the message template context.
1873
+	 *
1874
+	 * @param EE_Message_Template_Group $message_template_group
1875
+	 * @param string                    $context
1876
+	 * @param string                    $context_label
1877
+	 * @return string
1878
+	 * @throws DomainException
1879
+	 * @throws EE_Error
1880
+	 * @throws InvalidIdentifierException
1881
+	 * @throws ReflectionException
1882
+	 */
1883
+	protected function add_active_context_element(
1884
+		EE_Message_Template_Group $message_template_group,
1885
+		$context,
1886
+		$context_label
1887
+	) {
1888
+		$template_args = [
1889
+			'context'                   => $context,
1890
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
+			'is_active'                 => $message_template_group->is_context_active($context),
1892
+			'on_off_action'             => $message_template_group->is_context_active($context)
1893
+				? 'context-off'
1894
+				: 'context-on',
1895
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
+			'message_template_group_id' => $message_template_group->ID(),
1897
+		];
1898
+		return EEH_Template::display_template(
1899
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
+			$template_args,
1901
+			true
1902
+		);
1903
+	}
1904
+
1905
+
1906
+	/**
1907
+	 * Ajax callback for `toggle_context_template` ajax action.
1908
+	 * Handles toggling the message context on or off.
1909
+	 *
1910
+	 * @throws EE_Error
1911
+	 * @throws InvalidArgumentException
1912
+	 * @throws InvalidDataTypeException
1913
+	 * @throws InvalidIdentifierException
1914
+	 * @throws InvalidInterfaceException
1915
+	 */
1916
+	public function toggle_context_template()
1917
+	{
1918
+		$success = true;
1919
+		// check for required data
1920
+		if (
1921
+			! (
1922
+				$this->request->requestParamIsSet('message_template_group_id')
1923
+				&& $this->request->requestParamIsSet('context')
1924
+				&& $this->request->requestParamIsSet('status')
1925
+			)
1926
+		) {
1927
+			EE_Error::add_error(
1928
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1929
+				__FILE__,
1930
+				__FUNCTION__,
1931
+				__LINE__
1932
+			);
1933
+			$success = false;
1934
+		}
1935
+
1936
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1937
+		$context = $this->request->getRequestParam('context', '');
1938
+		$status  = $this->request->getRequestParam('status', '');
1939
+
1940
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1941
+
1942
+		if ($status !== 'off' && $status !== 'on') {
1943
+			EE_Error::add_error(
1944
+				sprintf(
1945
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1946
+					$status
1947
+				),
1948
+				__FILE__,
1949
+				__FUNCTION__,
1950
+				__LINE__
1951
+			);
1952
+			$success = false;
1953
+		}
1954
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
+			EE_Error::add_error(
1958
+				sprintf(
1959
+					esc_html__(
1960
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1961
+						'event_espresso'
1962
+					),
1963
+					$message_template_group_id,
1964
+					'EE_Message_Template_Group'
1965
+				),
1966
+				__FILE__,
1967
+				__FUNCTION__,
1968
+				__LINE__
1969
+			);
1970
+			$success = false;
1971
+		}
1972
+		if ($success) {
1973
+			$success = $status === 'off'
1974
+				? $message_template_group->deactivate_context($context)
1975
+				: $message_template_group->activate_context($context);
1976
+		}
1977
+		$this->_template_args['success'] = $success;
1978
+		$this->_return_json();
1979
+	}
1980
+
1981
+
1982
+	public function _add_form_element_before()
1983
+	{
1984
+		return '<form method="post" action="'
1985
+			   . $this->_template_args['edit_message_template_form_url']
1986
+			   . '" id="ee-msg-edit-frm">';
1987
+	}
1988
+
1989
+
1990
+	public function _add_form_element_after()
1991
+	{
1992
+		return '</form>';
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * This executes switching the template pack for a message template.
1998
+	 *
1999
+	 * @throws EE_Error
2000
+	 * @throws InvalidDataTypeException
2001
+	 * @throws InvalidInterfaceException
2002
+	 * @throws InvalidArgumentException
2003
+	 * @throws ReflectionException
2004
+	 * @since 4.5.0
2005
+	 */
2006
+	public function switch_template_pack()
2007
+	{
2008
+
2009
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2010
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2011
+
2012
+		// verify we have needed values.
2013
+		if (empty($GRP_ID) || empty($template_pack)) {
2014
+			$this->_template_args['error'] = true;
2015
+			EE_Error::add_error(
2016
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2017
+				__FILE__,
2018
+				__FUNCTION__,
2019
+				__LINE__
2020
+			);
2021
+		} else {
2022
+			// get template, set the new template_pack and then reset to default
2023
+			/** @var EE_Message_Template_Group $message_template_group */
2024
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2025
+
2026
+			$message_template_group->set_template_pack_name($template_pack);
2027
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2028
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2029
+
2030
+			$query_args = $this->_reset_to_default_template();
2031
+
2032
+			if (empty($query_args['id'])) {
2033
+				EE_Error::add_error(
2034
+					esc_html__(
2035
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2036
+						'event_espresso'
2037
+					),
2038
+					__FILE__,
2039
+					__FUNCTION__,
2040
+					__LINE__
2041
+				);
2042
+				$this->_template_args['error'] = true;
2043
+			} else {
2044
+				$template_label       = $message_template_group->get_template_pack()->label;
2045
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2046
+				EE_Error::add_success(
2047
+					sprintf(
2048
+						esc_html__(
2049
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2050
+							'event_espresso'
2051
+						),
2052
+						$template_label,
2053
+						$template_pack_labels->template_pack
2054
+					)
2055
+				);
2056
+				// generate the redirect url for js.
2057
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2058
+
2059
+				$this->_template_args['data']['redirect_url'] = $url;
2060
+				$this->_template_args['success']              = true;
2061
+			}
2062
+
2063
+			$this->_return_json();
2064
+		}
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2070
+	 * they want.
2071
+	 *
2072
+	 * @access protected
2073
+	 * @return array|void
2074
+	 * @throws EE_Error
2075
+	 * @throws InvalidArgumentException
2076
+	 * @throws InvalidDataTypeException
2077
+	 * @throws InvalidInterfaceException
2078
+	 * @throws ReflectionException
2079
+	 */
2080
+	protected function _reset_to_default_template()
2081
+	{
2082
+		$templates    = [];
2083
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2084
+		$messenger    = $this->request->getRequestParam('msgr');
2085
+		$message_type = $this->request->getRequestParam('mt');
2086
+		// we need to make sure we've got the info we need.
2087
+		if (! ($GRP_ID && $messenger && $message_type)) {
2088
+			EE_Error::add_error(
2089
+				esc_html__(
2090
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2091
+					'event_espresso'
2092
+				),
2093
+				__FILE__,
2094
+				__FUNCTION__,
2095
+				__LINE__
2096
+			);
2097
+		}
2098
+
2099
+		// all templates will be reset to whatever the defaults are
2100
+		// for the global template matching the messenger and message type.
2101
+		$success = ! empty($GRP_ID);
2102
+
2103
+		if ($success) {
2104
+			// let's first determine if the incoming template is a global template,
2105
+			// if it isn't then we need to get the global template matching messenger and message type.
2106
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2107
+
2108
+
2109
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2110
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2111
+
2112
+			if ($success) {
2113
+				// if successfully deleted, lets generate the new ones.
2114
+				// Note. We set GLOBAL to true, because resets on ANY template
2115
+				// will use the related global template defaults for regeneration.
2116
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2117
+				// HOWEVER, we DO keep the template pack and template variation set
2118
+				// for the current custom template when resetting.
2119
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2120
+			}
2121
+		}
2122
+
2123
+		// any error messages?
2124
+		if (! $success) {
2125
+			EE_Error::add_error(
2126
+				esc_html__(
2127
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2128
+					'event_espresso'
2129
+				),
2130
+				__FILE__,
2131
+				__FUNCTION__,
2132
+				__LINE__
2133
+			);
2134
+		}
2135
+
2136
+		// all good, let's add a success message!
2137
+		if ($success && ! empty($templates)) {
2138
+			// the info for the template we generated is the first element in the returned array
2139
+			EE_Error::overwrite_success();
2140
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2141
+		}
2142
+
2143
+
2144
+		$query_args = [
2145
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2146
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2147
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2148
+		];
2149
+
2150
+		// if called via ajax then we return query args otherwise redirect
2151
+		if ($this->request->isAjax()) {
2152
+			return $query_args;
2153
+		}
2154
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2155
+	}
2156
+
2157
+
2158
+	/**
2159
+	 * Retrieve and set the message preview for display.
2160
+	 *
2161
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2162
+	 * @return string
2163
+	 * @throws ReflectionException
2164
+	 * @throws EE_Error
2165
+	 * @throws InvalidArgumentException
2166
+	 * @throws InvalidDataTypeException
2167
+	 * @throws InvalidInterfaceException
2168
+	 */
2169
+	public function _preview_message($send = false)
2170
+	{
2171
+		// first make sure we've got the necessary parameters
2172
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
+			EE_Error::add_error(
2175
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176
+				__FILE__,
2177
+				__FUNCTION__,
2178
+				__LINE__
2179
+			);
2180
+		}
2181
+
2182
+		$context = $this->request->getRequestParam('context');
2183
+		// get the preview!
2184
+		$preview = EED_Messages::preview_message(
2185
+			$this->_active_message_type_name,
2186
+			$context,
2187
+			$this->_active_messenger_name,
2188
+			$send
2189
+		);
2190
+
2191
+		if ($send) {
2192
+			return $preview;
2193
+		}
2194
+
2195
+		// if we have an evt_id set on the request, use it.
2196
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197
+
2198
+		// let's add a button to go back to the edit view
2199
+		$query_args             = [
2200
+			'id'      => $GRP_ID,
2201
+			'evt_id'  => $EVT_ID,
2202
+			'context' => $context,
2203
+			'action'  => 'edit_message_template',
2204
+		];
2205
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2206
+		$preview_button         = '<a href="'
2207
+								  . $go_back_url
2208
+								  . '" class="button-secondary messages-preview-go-back-button">'
2209
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2210
+								  . '</a>';
2211
+		$message_types          = $this->get_installed_message_types();
2212
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2213
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2214
+			? ucwords($active_messenger->label['singular'])
2215
+			: esc_html__('Unknown Messenger', 'event_espresso');
2216
+		// let's provide a helpful title for context
2217
+		$preview_title = sprintf(
2218
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219
+			$active_messenger_label,
2220
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
+		);
2222
+		if (empty($preview)) {
2223
+			$this->noEventsErrorMessage();
2224
+		}
2225
+		// setup display of preview.
2226
+		$this->_admin_page_title                    = $preview_title;
2227
+		$this->_template_args['admin_page_title']   = $preview_title;
2228
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
+		$this->_template_args['data']['force_json'] = true;
2230
+
2231
+		return '';
2232
+	}
2233
+
2234
+
2235
+	/**
2236
+	 * Used to set an error if there are no events available for generating a preview/test send.
2237
+	 *
2238
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2239
+	 */
2240
+	protected function noEventsErrorMessage($test_send = false)
2241
+	{
2242
+		$events_url = parent::add_query_args_and_nonce(
2243
+			[
2244
+				'action' => 'default',
2245
+				'page'   => 'espresso_events',
2246
+			],
2247
+			admin_url('admin.php')
2248
+		);
2249
+		$message    = $test_send
2250
+			? esc_html__(
2251
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252
+				'event_espresso'
2253
+			)
2254
+			: esc_html__(
2255
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2256
+				'event_espresso'
2257
+			);
2258
+
2259
+		EE_Error::add_attention(
2260
+			sprintf(
2261
+				$message,
2262
+				"<a href='" . esc_url_raw($events_url) . "'>",
2263
+				'</a>'
2264
+			)
2265
+		);
2266
+	}
2267
+
2268
+
2269
+	/**
2270
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2271
+	 * gets called automatically.
2272
+	 *
2273
+	 * @return void
2274
+	 * @throws EE_Error
2275
+	 * @since 4.5.0
2276
+	 *
2277
+	 */
2278
+	protected function _display_preview_message()
2279
+	{
2280
+		$this->display_admin_page_with_no_sidebar();
2281
+	}
2282
+
2283
+
2284
+	/**
2285
+	 * registers metaboxes that should show up on the "edit_message_template" page
2286
+	 *
2287
+	 * @access protected
2288
+	 * @return void
2289
+	 */
2290
+	protected function _register_edit_meta_boxes()
2291
+	{
2292
+		add_meta_box(
2293
+			'mtp_valid_shortcodes',
2294
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2295
+			[$this, 'shortcode_meta_box'],
2296
+			$this->_current_screen->id,
2297
+			'side'
2298
+		);
2299
+		add_meta_box(
2300
+			'mtp_extra_actions',
2301
+			esc_html__('Extra Actions', 'event_espresso'),
2302
+			[$this, 'extra_actions_meta_box'],
2303
+			$this->_current_screen->id,
2304
+			'side',
2305
+			'high'
2306
+		);
2307
+		add_meta_box(
2308
+			'mtp_templates',
2309
+			esc_html__('Template Styles', 'event_espresso'),
2310
+			[$this, 'template_pack_meta_box'],
2311
+			$this->_current_screen->id,
2312
+			'side',
2313
+			'high'
2314
+		);
2315
+	}
2316
+
2317
+
2318
+	/**
2319
+	 * metabox content for all template pack and variation selection.
2320
+	 *
2321
+	 * @return void
2322
+	 * @throws DomainException
2323
+	 * @throws EE_Error
2324
+	 * @throws InvalidArgumentException
2325
+	 * @throws ReflectionException
2326
+	 * @throws InvalidDataTypeException
2327
+	 * @throws InvalidInterfaceException
2328
+	 * @since 4.5.0
2329
+	 */
2330
+	public function template_pack_meta_box()
2331
+	{
2332
+		$this->_set_message_template_group();
2333
+
2334
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2335
+
2336
+		$tp_select_values = [];
2337
+
2338
+		foreach ($tp_collection as $tp) {
2339
+			// only include template packs that support this messenger and message type!
2340
+			$supports = $tp->get_supports();
2341
+			if (
2342
+				! isset($supports[ $this->_message_template_group->messenger() ])
2343
+				|| ! in_array(
2344
+					$this->_message_template_group->message_type(),
2345
+					$supports[ $this->_message_template_group->messenger() ],
2346
+					true
2347
+				)
2348
+			) {
2349
+				// not supported
2350
+				continue;
2351
+			}
2352
+
2353
+			$tp_select_values[] = [
2354
+				'text' => $tp->label,
2355
+				'id'   => $tp->dbref,
2356
+			];
2357
+		}
2358
+
2359
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2360
+		// the default template pack.  This still allows for the odd template pack to override.
2361
+		if (empty($tp_select_values)) {
2362
+			$tp_select_values[] = [
2363
+				'text' => esc_html__('Default', 'event_espresso'),
2364
+				'id'   => 'default',
2365
+			];
2366
+		}
2367
+
2368
+		// setup variation select values for the currently selected template.
2369
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
+			$this->_message_template_group->messenger(),
2371
+			$this->_message_template_group->message_type()
2372
+		);
2373
+		$variations_select_values = [];
2374
+		foreach ($variations as $variation => $label) {
2375
+			$variations_select_values[] = [
2376
+				'text' => $label,
2377
+				'id'   => $variation,
2378
+			];
2379
+		}
2380
+
2381
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382
+
2383
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
+			'MTP_template_pack',
2385
+			$tp_select_values,
2386
+			$this->_message_template_group->get_template_pack_name()
2387
+		);
2388
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
+			'MTP_template_variation',
2390
+			$variations_select_values,
2391
+			$this->_message_template_group->get_template_pack_variation()
2392
+		);
2393
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2394
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2395
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397
+
2398
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
+
2400
+		EEH_Template::display_template($template, $template_args);
2401
+	}
2402
+
2403
+
2404
+	/**
2405
+	 * This meta box holds any extra actions related to Message Templates
2406
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2407
+	 *
2408
+	 * @access  public
2409
+	 * @return void
2410
+	 * @throws EE_Error
2411
+	 */
2412
+	public function extra_actions_meta_box()
2413
+	{
2414
+		$template_form_fields = [];
2415
+
2416
+		$extra_args = [
2417
+			'msgr'   => $this->_message_template_group->messenger(),
2418
+			'mt'     => $this->_message_template_group->message_type(),
2419
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2420
+		];
2421
+		// first we need to see if there are any fields
2422
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423
+
2424
+		if (! empty($fields)) {
2425
+			// yup there be fields
2426
+			foreach ($fields as $field => $config) {
2427
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429
+				$default  = isset($config['default']) ? $config['default'] : '';
2430
+				$default  = isset($config['value']) ? $config['value'] : $default;
2431
+
2432
+				// if type is hidden and the value is empty
2433
+				// something may have gone wrong so let's correct with the defaults
2434
+				$fix                = $config['input'] === 'hidden'
2435
+									  && isset($existing[ $field ])
2436
+									  && empty($existing[ $field ])
2437
+					? $default
2438
+					: '';
2439
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
+					? $existing[ $field ]
2441
+					: $fix;
2442
+
2443
+				$template_form_fields[ $field_id ] = [
2444
+					'name'       => 'test_settings_fld[' . $field . ']',
2445
+					'label'      => $config['label'],
2446
+					'input'      => $config['input'],
2447
+					'type'       => $config['type'],
2448
+					'required'   => $config['required'],
2449
+					'validation' => $config['validation'],
2450
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
+					'css_class'  => $config['css_class'],
2452
+					'options'    => isset($config['options']) ? $config['options'] : [],
2453
+					'default'    => $default,
2454
+					'format'     => $config['format'],
2455
+				];
2456
+			}
2457
+		}
2458
+
2459
+		$test_settings_html = ! empty($template_form_fields)
2460
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2461
+			: '';
2462
+
2463
+		// print out $test_settings_fields
2464
+		if (! empty($test_settings_html)) {
2465
+			$test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466
+			$test_settings_html .= 'name="test_button" value="';
2467
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2468
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2469
+		}
2470
+
2471
+		// and button
2472
+		$test_settings_html .= '<p>';
2473
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2474
+		$test_settings_html .= '</p>';
2475
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2476
+		$test_settings_html .= $this->get_action_link_or_button(
2477
+			'reset_to_default',
2478
+			'reset',
2479
+			$extra_args,
2480
+			'button-primary reset-default-button'
2481
+		);
2482
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2483
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2484
+	}
2485
+
2486
+
2487
+	/**
2488
+	 * This returns the shortcode selector skeleton for a given context and field.
2489
+	 *
2490
+	 * @param string $field           The name of the field retrieving shortcodes for.
2491
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2492
+	 * @return string
2493
+	 * @throws DomainException
2494
+	 * @throws EE_Error
2495
+	 * @throws InvalidArgumentException
2496
+	 * @throws ReflectionException
2497
+	 * @throws InvalidDataTypeException
2498
+	 * @throws InvalidInterfaceException
2499
+	 * @since 4.9.rc.000
2500
+	 */
2501
+	protected function _get_shortcode_selector($field, $linked_input_id)
2502
+	{
2503
+		$template_args = [
2504
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2505
+			'fieldname'       => $field,
2506
+			'linked_input_id' => $linked_input_id,
2507
+		];
2508
+
2509
+		return EEH_Template::display_template(
2510
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
+			$template_args,
2512
+			true
2513
+		);
2514
+	}
2515
+
2516
+
2517
+	/**
2518
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2519
+	 * page)
2520
+	 *
2521
+	 * @access public
2522
+	 * @return void
2523
+	 * @throws EE_Error
2524
+	 * @throws InvalidArgumentException
2525
+	 * @throws ReflectionException
2526
+	 * @throws InvalidDataTypeException
2527
+	 * @throws InvalidInterfaceException
2528
+	 */
2529
+	public function shortcode_meta_box()
2530
+	{
2531
+		$shortcodes = $this->_get_shortcodes([], false);
2532
+		// just make sure the shortcodes property is set
2533
+		// $messenger = $this->_message_template_group->messenger_obj();
2534
+		// now let's set the content depending on the status of the shortcodes array
2535
+		if (empty($shortcodes)) {
2536
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
+			return;
2538
+		}
2539
+		?>
2540 2540
         <div style="float:right; margin-top:10px">
2541 2541
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2542
-            ?>
2542
+			?>
2543 2543
         </div>
2544 2544
         <p class="small-text">
2545 2545
             <?php printf(
2546
-                esc_html__(
2547
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2548
-                    'event_espresso'
2549
-                ),
2550
-                '<span class="dashicons dashicons-menu"></span>'
2551
-            ); ?>
2546
+				esc_html__(
2547
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2548
+					'event_espresso'
2549
+				),
2550
+				'<span class="dashicons dashicons-menu"></span>'
2551
+			); ?>
2552 2552
         </p>
2553 2553
         <?php
2554
-    }
2555
-
2556
-
2557
-    /**
2558
-     * used to set the $_shortcodes property for when its needed elsewhere.
2559
-     *
2560
-     * @access protected
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     * @throws InvalidArgumentException
2564
-     * @throws ReflectionException
2565
-     * @throws InvalidDataTypeException
2566
-     * @throws InvalidInterfaceException
2567
-     */
2568
-    protected function _set_shortcodes()
2569
-    {
2570
-
2571
-        // no need to run this if the property is already set
2572
-        if (! empty($this->_shortcodes)) {
2573
-            return;
2574
-        }
2575
-
2576
-        $this->_shortcodes = $this->_get_shortcodes();
2577
-    }
2578
-
2579
-
2580
-    /**
2581
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2582
-     * property)
2583
-     *
2584
-     * @access  protected
2585
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2586
-     *                         for. Defaults to all (for the given context)
2587
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2588
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2589
-     *                         true just an array of shortcode/label pairs.
2590
-     * @throws EE_Error
2591
-     * @throws InvalidArgumentException
2592
-     * @throws ReflectionException
2593
-     * @throws InvalidDataTypeException
2594
-     * @throws InvalidInterfaceException
2595
-     */
2596
-    protected function _get_shortcodes($fields = [], $merged = true)
2597
-    {
2598
-        $this->_set_message_template_group();
2599
-
2600
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2601
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2602
-        if (empty($GRP_ID)) {
2603
-            return [];
2604
-        }
2605
-        $context = $this->request->getRequestParam(
2606
-            'messenger',
2607
-            key($this->_message_template_group->contexts_config())
2608
-        );
2609
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2610
-    }
2611
-
2612
-
2613
-    /**
2614
-     * This sets the _message_template property (containing the called message_template object)
2615
-     *
2616
-     * @access protected
2617
-     * @return void
2618
-     * @throws EE_Error
2619
-     * @throws InvalidArgumentException
2620
-     * @throws ReflectionException
2621
-     * @throws InvalidDataTypeException
2622
-     * @throws InvalidInterfaceException
2623
-     */
2624
-    protected function _set_message_template_group()
2625
-    {
2626
-        // get out if this is already set.
2627
-        if (! empty($this->_message_template_group)) {
2628
-            return;
2629
-        }
2630
-
2631
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2632
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2633
-
2634
-        // let's get the message templates
2635
-        $this->_message_template_group = ! empty($GRP_ID)
2636
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2637
-            : $this->getMtgModel()->create_default_object();
2638
-
2639
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2640
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * sets up a context switcher for edit forms
2646
-     *
2647
-     * @access  protected
2648
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2649
-     * @param array                     $args                  various things the context switcher needs.
2650
-     * @throws EE_Error
2651
-     */
2652
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2653
-    {
2654
-        $context_details = $template_group_object->contexts_config();
2655
-        $context_label   = $template_group_object->context_label();
2656
-        ob_start();
2657
-        ?>
2554
+	}
2555
+
2556
+
2557
+	/**
2558
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2559
+	 *
2560
+	 * @access protected
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 * @throws InvalidArgumentException
2564
+	 * @throws ReflectionException
2565
+	 * @throws InvalidDataTypeException
2566
+	 * @throws InvalidInterfaceException
2567
+	 */
2568
+	protected function _set_shortcodes()
2569
+	{
2570
+
2571
+		// no need to run this if the property is already set
2572
+		if (! empty($this->_shortcodes)) {
2573
+			return;
2574
+		}
2575
+
2576
+		$this->_shortcodes = $this->_get_shortcodes();
2577
+	}
2578
+
2579
+
2580
+	/**
2581
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2582
+	 * property)
2583
+	 *
2584
+	 * @access  protected
2585
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2586
+	 *                         for. Defaults to all (for the given context)
2587
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2588
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2589
+	 *                         true just an array of shortcode/label pairs.
2590
+	 * @throws EE_Error
2591
+	 * @throws InvalidArgumentException
2592
+	 * @throws ReflectionException
2593
+	 * @throws InvalidDataTypeException
2594
+	 * @throws InvalidInterfaceException
2595
+	 */
2596
+	protected function _get_shortcodes($fields = [], $merged = true)
2597
+	{
2598
+		$this->_set_message_template_group();
2599
+
2600
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2601
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2602
+		if (empty($GRP_ID)) {
2603
+			return [];
2604
+		}
2605
+		$context = $this->request->getRequestParam(
2606
+			'messenger',
2607
+			key($this->_message_template_group->contexts_config())
2608
+		);
2609
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2610
+	}
2611
+
2612
+
2613
+	/**
2614
+	 * This sets the _message_template property (containing the called message_template object)
2615
+	 *
2616
+	 * @access protected
2617
+	 * @return void
2618
+	 * @throws EE_Error
2619
+	 * @throws InvalidArgumentException
2620
+	 * @throws ReflectionException
2621
+	 * @throws InvalidDataTypeException
2622
+	 * @throws InvalidInterfaceException
2623
+	 */
2624
+	protected function _set_message_template_group()
2625
+	{
2626
+		// get out if this is already set.
2627
+		if (! empty($this->_message_template_group)) {
2628
+			return;
2629
+		}
2630
+
2631
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2632
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2633
+
2634
+		// let's get the message templates
2635
+		$this->_message_template_group = ! empty($GRP_ID)
2636
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2637
+			: $this->getMtgModel()->create_default_object();
2638
+
2639
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2640
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * sets up a context switcher for edit forms
2646
+	 *
2647
+	 * @access  protected
2648
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2649
+	 * @param array                     $args                  various things the context switcher needs.
2650
+	 * @throws EE_Error
2651
+	 */
2652
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2653
+	{
2654
+		$context_details = $template_group_object->contexts_config();
2655
+		$context_label   = $template_group_object->context_label();
2656
+		ob_start();
2657
+		?>
2658 2658
         <div class="ee-msg-switcher-container">
2659 2659
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2660 2660
                 <?php
2661
-                foreach ($args as $name => $value) {
2662
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2663
-                        continue;
2664
-                    }
2665
-                    ?>
2661
+				foreach ($args as $name => $value) {
2662
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2663
+						continue;
2664
+					}
2665
+					?>
2666 2666
                     <input type="hidden"
2667 2667
                            name="<?php echo esc_attr($name); ?>"
2668 2668
                            value="<?php echo esc_attr($value); ?>"
2669 2669
                     />
2670 2670
                     <?php
2671
-                }
2672
-                // setup nonce_url
2673
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2675
-                ?>
2671
+				}
2672
+				// setup nonce_url
2673
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2675
+				?>
2676 2676
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2677 2677
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2678 2678
                 </label>
2679 2679
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2680 2680
                     <?php
2681
-                    $context_templates = $template_group_object->context_templates();
2682
-                    if (is_array($context_templates)) :
2683
-                        foreach ($context_templates as $context => $template_fields) :
2684
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2685
-                            ?>
2681
+					$context_templates = $template_group_object->context_templates();
2682
+					if (is_array($context_templates)) :
2683
+						foreach ($context_templates as $context => $template_fields) :
2684
+							$checked = ($context === $args['context']) ? 'selected' : '';
2685
+							?>
2686 2686
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2687 2687
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
2690
-                    endif; ?>
2690
+					endif; ?>
2691 2691
                 </select>
2692 2692
                 <?php $button_text = sprintf(
2693
-                    esc_html__('Switch %s', 'event_espresso'),
2694
-                    ucwords($context_label['label'])
2695
-                ); ?>
2693
+					esc_html__('Switch %s', 'event_espresso'),
2694
+					ucwords($context_label['label'])
2695
+				); ?>
2696 2696
                 <input class='button-secondary'
2697 2697
                        id="submit-msg-context-switcher-sbmt"
2698 2698
                        type="submit"
@@ -2702,1994 +2702,1994 @@  discard block
 block discarded – undo
2702 2702
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2703 2703
         </div> <!-- end .ee-msg-switcher-container -->
2704 2704
         <?php
2705
-        $this->_context_switcher = ob_get_clean();
2706
-    }
2707
-
2708
-
2709
-    /**
2710
-     * @param bool $new
2711
-     * @throws EE_Error
2712
-     * @throws ReflectionException
2713
-     */
2714
-    protected function _insert_or_update_message_template($new = false)
2715
-    {
2716
-        $form_data    = $this->getMessageTemplateFormData();
2717
-        $GRP_ID       = $form_data['GRP_ID'];
2718
-        $messenger    = $form_data['MTP_messenger'];
2719
-        $message_type = $form_data['MTP_message_type'];
2720
-        $context      = $form_data['MTP_context'];
2721
-
2722
-        // if this is "new" then we need to generate the default contexts
2723
-        // for the selected messenger/message_type for user to edit.
2724
-        list($success, $query_args) = $new
2725
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
-
2728
-        $success     = $success ? 1 : 0;
2729
-        $action_desc = $new ? 'created' : 'updated';
2730
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
-
2733
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
-    }
2735
-
2736
-
2737
-    /**
2738
-     * retrieve and sanitize form data
2739
-     *
2740
-     * @return array
2741
-     * @since 4.10.29.p
2742
-     */
2743
-    protected function getMessageTemplateFormData()
2744
-    {
2745
-        return [
2746
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
-        ];
2756
-    }
2757
-
2758
-
2759
-    /**
2760
-     * @param int    $GRP_ID
2761
-     * @param string $messenger
2762
-     * @param string $message_type
2763
-     * @return array no return on AJAX requests
2764
-     * @throws EE_Error
2765
-     * @throws ReflectionException
2766
-     * @since 4.10.29.p
2767
-     */
2768
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
-    {
2770
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
-        $success       = ! empty($new_templates);
2772
-
2773
-        // we return things differently if doing ajax
2774
-        if ($this->request->isAjax()) {
2775
-            $this->_template_args['success'] = $success;
2776
-            $this->_template_args['error']   = ! $success;
2777
-            $this->_template_args['content'] = '';
2778
-            $this->_template_args['data']    = [
2779
-                'grpID'        => $new_templates['GRP_ID'],
2780
-                'templateName' => $new_templates['template_name'],
2781
-            ];
2782
-            if ($success) {
2783
-                EE_Error::overwrite_success();
2784
-                EE_Error::add_success(
2785
-                    esc_html__(
2786
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2787
-                        'event_espresso'
2788
-                    )
2789
-                );
2790
-            }
2791
-            $this->_return_json();
2792
-        }
2793
-        return [
2794
-            $success,
2795
-            // 'query_args'
2796
-            [
2797
-                'id'      => $new_templates['GRP_ID'],
2798
-                'context' => $new_templates['MTP_context'],
2799
-                'action'  => 'edit_message_template',
2800
-            ],
2801
-        ];
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * @param int    $GRP_ID
2807
-     * @param string $messenger
2808
-     * @param string $message_type
2809
-     * @param string $context
2810
-     * @param array  $form_data
2811
-     * @return array
2812
-     * @throws EE_Error
2813
-     * @since 4.10.29.p
2814
-     */
2815
-    private function updateExistingTemplates(
2816
-        $GRP_ID,
2817
-        $messenger,
2818
-        $message_type,
2819
-        $context,
2820
-        array $form_data
2821
-    ) {
2822
-        $success         = false;
2823
-        $template_fields = $this->getTemplateFields();
2824
-        if ($template_fields) {
2825
-            // if field data is valid, then success will be true
2826
-            $success = $this->validateTemplateFields(
2827
-                $messenger,
2828
-                $message_type,
2829
-                $context,
2830
-                $template_fields
2831
-            );
2832
-            if ($success) {
2833
-                $field_data = [];
2834
-                foreach ($template_fields as $template_field => $content) {
2835
-                    // combine top-level form data with content for this field
2836
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
-                }
2839
-                // we can use the last set_column_values for the MTPG update
2840
-                // (because its the same for all of these specific MTPs)
2841
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
-            }
2843
-        }
2844
-
2845
-        return [
2846
-            $success,
2847
-            // 'query_args'
2848
-            [
2849
-                'id'      => $GRP_ID,
2850
-                'context' => $context,
2851
-                'action'  => 'edit_message_template',
2852
-            ],
2853
-        ];
2854
-    }
2855
-
2856
-
2857
-    /**
2858
-     * @return array
2859
-     * @since 4.10.29.p
2860
-     */
2861
-    private function getTemplateFields()
2862
-    {
2863
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
-        if (empty($template_fields)) {
2865
-            EE_Error::add_error(
2866
-                esc_html__(
2867
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
-                    'event_espresso'
2869
-                ),
2870
-                __FILE__,
2871
-                __FUNCTION__,
2872
-                __LINE__
2873
-            );
2874
-            return null;
2875
-        }
2876
-        // messages content is expected to be escaped
2877
-        return EEH_Array::addSlashesRecursively($template_fields);
2878
-    }
2879
-
2880
-
2881
-    /**
2882
-     * @param string $messenger
2883
-     * @param string $message_type
2884
-     * @param string $context
2885
-     * @param array  $template_fields
2886
-     * @return bool
2887
-     * @throws EE_Error
2888
-     * @since   4.10.29.p
2889
-     */
2890
-    private function validateTemplateFields(
2891
-        $messenger,
2892
-        $message_type,
2893
-        $context,
2894
-        array $template_fields
2895
-    ) {
2896
-        // first validate all fields!
2897
-        // this filter allows client code to add its own validation to the template fields as well.
2898
-        // returning an empty array means everything passed validation.
2899
-        // errors in validation should be represented in an array with the following shape:
2900
-        // array(
2901
-        //   'fieldname' => array(
2902
-        //          'msg' => 'error message'
2903
-        //          'value' => 'value for field producing error'
2904
-        // )
2905
-        $custom_validation = (array) apply_filters(
2906
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
-            [],
2908
-            $template_fields,
2909
-            $context,
2910
-            $messenger,
2911
-            $message_type
2912
-        );
2913
-
2914
-        $system_validation = $this->getMtgModel()->validate(
2915
-            $template_fields,
2916
-            $context,
2917
-            $messenger,
2918
-            $message_type
2919
-        );
2920
-
2921
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
-        $validates         = array_merge($custom_validation, $system_validation);
2923
-
2924
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
-        //  WE need to make sure there is no actual error messages in validates.
2927
-        if (empty($validates)) {
2928
-            return true;
2929
-        }
2930
-
2931
-        // add the transient so when the form loads we know which fields to highlight
2932
-        $this->_add_transient('edit_message_template', $validates);
2933
-        // setup notices
2934
-        foreach ($validates as $error) {
2935
-            if (isset($error['msg'])) {
2936
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
-            }
2938
-        }
2939
-        return false;
2940
-    }
2941
-
2942
-
2943
-    /**
2944
-     * @param array $field_data
2945
-     * @param array $form_data
2946
-     * @return array
2947
-     * @since   4.10.29.p
2948
-     */
2949
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
-    {
2951
-        return $form_data + [
2952
-                'MTP_ID'             => $field_data['MTP_ID'],
2953
-                'MTP_template_field' => $field_data['name'],
2954
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2956
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
-                    : $field_data['content'],
2958
-            ];
2959
-    }
2960
-
2961
-
2962
-    /**
2963
-     * @param string $template_field
2964
-     * @param array  $form_data
2965
-     * @return bool
2966
-     * @throws EE_Error
2967
-     * @since 4.10.29.p
2968
-     */
2969
-    private function updateMessageTemplates($template_field, array $form_data)
2970
-    {
2971
-        $MTP_ID                  = $form_data['MTP_ID'];
2972
-        $message_template_fields = [
2973
-            'GRP_ID'             => $form_data['GRP_ID'],
2974
-            'MTP_template_field' => $form_data['MTP_template_field'],
2975
-            'MTP_context'        => $form_data['MTP_context'],
2976
-            'MTP_content'        => $form_data['MTP_content'],
2977
-        ];
2978
-
2979
-        $hasMtpID = ! empty($MTP_ID);
2980
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2981
-        // this has already been through the template field validator and sanitized, so it will be
2982
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
-        // message template field in a messenger/message type and existing users don't have the
2984
-        // default setup for it.
2985
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
-        $updated = $hasMtpID
2987
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
-            : $this->getMtpModel()->insert($message_template_fields);
2989
-
2990
-        $insert_failed = ! $hasMtpID && ! $updated;
2991
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
-        $update_failed = $hasMtpID && $updated === false;
2994
-
2995
-        if ($insert_failed || $update_failed) {
2996
-            EE_Error::add_error(
2997
-                sprintf(
2998
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
-                    $template_field
3000
-                ),
3001
-                __FILE__,
3002
-                __FUNCTION__,
3003
-                __LINE__
3004
-            );
3005
-            return false;
3006
-        }
3007
-        return true;
3008
-    }
3009
-
3010
-
3011
-    /**
3012
-     * @param array $form_data
3013
-     * @return bool
3014
-     * @throws EE_Error
3015
-     * @since 4.10.29.p
3016
-     */
3017
-    private function updateMessageTemplateGroup(array $form_data)
3018
-    {
3019
-        $GRP_ID  = $form_data['GRP_ID'];
3020
-        $updated = $this->getMtgModel()->update(
3021
-        // fields and values
3022
-            [
3023
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3024
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3025
-                'MTP_message_type' => $form_data['MTP_message_type'],
3026
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3027
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3028
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3029
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3030
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
-                'MTP_description'  => $this->request->getRequestParam(
3032
-                    'ee_msg_non_global_fields[MTP_description]',
3033
-                    ''
3034
-                ),
3035
-            ],
3036
-            // where
3037
-            [['GRP_ID' => $GRP_ID]]
3038
-        );
3039
-
3040
-        if ($updated === false) {
3041
-            EE_Error::add_error(
3042
-                sprintf(
3043
-                    esc_html__(
3044
-                        'The Message Template Group (%d) was NOT updated for some reason',
3045
-                        'event_espresso'
3046
-                    ),
3047
-                    $form_data['GRP_ID']
3048
-                ),
3049
-                __FILE__,
3050
-                __FUNCTION__,
3051
-                __LINE__
3052
-            );
3053
-            return false;
3054
-        }
3055
-        // k now we need to ensure the template_pack and template_variation fields are set.
3056
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
-
3059
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3061
-            $message_template_group->set_template_pack_name($template_pack);
3062
-            $message_template_group->set_template_pack_variation($template_variation);
3063
-        }
3064
-        return true;
3065
-    }
3066
-
3067
-
3068
-    /**
3069
-     * recursively runs wp_kses() on message template content in a model safe manner
3070
-     *
3071
-     * @param array|string $content
3072
-     * @return array|string
3073
-     * @since   4.10.29.p
3074
-     */
3075
-    private function sanitizeMessageTemplateContent($content)
3076
-    {
3077
-        if (is_array($content)) {
3078
-            foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
-            }
3081
-            return $content;
3082
-        }
3083
-        // remove slashes so wp_kses() works properly
3084
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3085
-        // so attributes using single quotes always appear invalid.
3086
-        $content = stripslashes($content);
3087
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3088
-        // But currently the models expect slashed data, so after wp_kses()
3089
-        // runs we need to re-slash the data. Sheesh.
3090
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
-        return addslashes($content);
3092
-    }
3093
-
3094
-
3095
-    /**
3096
-     * @param string $messenger
3097
-     * @param string $message_type
3098
-     * @param string $context
3099
-     * @return string
3100
-     * @since 4.10.29.p
3101
-     */
3102
-    private function generateUpdateDescription($messenger, $message_type, $context)
3103
-    {
3104
-        // need the message type and messenger objects to be able to use the labels for the notices
3105
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
-        $messenger_label  = $messenger_object instanceof EE_messenger
3107
-            ? ucwords($messenger_object->label['singular'])
3108
-            : '';
3109
-
3110
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
-        $message_type_label  = $message_type_object instanceof EE_message_type
3112
-            ? ucwords($message_type_object->label['singular'])
3113
-            : '';
3114
-
3115
-        $context   = ucwords(str_replace('_', ' ', $context));
3116
-        $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
-            : '';
3119
-        $item_desc .= 'Message Template';
3120
-        return $item_desc;
3121
-    }
3122
-
3123
-
3124
-    /**
3125
-     * @param string $messenger
3126
-     * @param string $message_type
3127
-     * @param string $context
3128
-     * @return bool
3129
-     * @throws EE_Error
3130
-     * @throws ReflectionException
3131
-     * @since 4.10.29.p
3132
-     */
3133
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
-    {
3135
-        // was a test send triggered?
3136
-        if ($this->request->requestParamIsSet('test_button')) {
3137
-            EE_Error::overwrite_success();
3138
-            $this->_do_test_send($context, $messenger, $message_type);
3139
-            return true;
3140
-        }
3141
-        return false;
3142
-    }
3143
-
3144
-
3145
-    /**
3146
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
-     *
3148
-     * @param string $context      what context being tested
3149
-     * @param string $messenger    messenger being tested
3150
-     * @param string $message_type message type being tested
3151
-     * @throws EE_Error
3152
-     * @throws InvalidArgumentException
3153
-     * @throws InvalidDataTypeException
3154
-     * @throws InvalidInterfaceException
3155
-     * @throws ReflectionException
3156
-     */
3157
-    protected function _do_test_send($context, $messenger, $message_type)
3158
-    {
3159
-        // set things up for preview
3160
-        $this->request->setRequestParam('messenger', $messenger);
3161
-        $this->request->setRequestParam('message_type', $message_type);
3162
-        $this->request->setRequestParam('context', $context);
3163
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
-
3166
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
-
3169
-        // let's save any existing fields that might be required by the messenger
3170
-        if (
3171
-            ! empty($test_settings_fld)
3172
-            && $active_messenger instanceof EE_messenger
3173
-            && apply_filters(
3174
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
-                true,
3176
-                $test_settings_fld,
3177
-                $active_messenger
3178
-            )
3179
-        ) {
3180
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3181
-        }
3182
-
3183
-        /**
3184
-         * Use filter to add additional controls on whether message can send or not
3185
-         */
3186
-        if (
3187
-            apply_filters(
3188
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
-                true,
3190
-                $context,
3191
-                $this->request->requestParams(),
3192
-                $messenger,
3193
-                $message_type
3194
-            )
3195
-        ) {
3196
-            if (EEM_Event::instance()->count() > 0) {
3197
-                $success = $this->_preview_message(true);
3198
-                if ($success) {
3199
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
-                } else {
3201
-                    EE_Error::add_error(
3202
-                        esc_html__('The test message was not sent', 'event_espresso'),
3203
-                        __FILE__,
3204
-                        __FUNCTION__,
3205
-                        __LINE__
3206
-                    );
3207
-                }
3208
-            } else {
3209
-                $this->noEventsErrorMessage(true);
3210
-            }
3211
-        }
3212
-    }
3213
-
3214
-
3215
-    /**
3216
-     * _generate_new_templates
3217
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
-     * for the event.
3220
-     *
3221
-     *
3222
-     * @param string $messenger      the messenger we are generating templates for
3223
-     * @param array  $message_types  array of message types that the templates are generated for.
3224
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
-     *                               indicate the message_template_group being used as the base.
3226
-     *
3227
-     * @param bool   $global
3228
-     *
3229
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
-     *                               encountering problems.
3231
-     * @throws EE_Error
3232
-     * @throws ReflectionException
3233
-     */
3234
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
-    {
3236
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
-        // just don't generate any templates.
3238
-        if (empty($message_types)) {
3239
-            return [];
3240
-        }
3241
-
3242
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
-        return $templates[0];
3244
-    }
3245
-
3246
-
3247
-    /**
3248
-     * [_trash_or_restore_message_template]
3249
-     *
3250
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
-     *                        an individual context (FALSE).
3253
-     * @return void
3254
-     * @throws EE_Error
3255
-     * @throws InvalidArgumentException
3256
-     * @throws InvalidDataTypeException
3257
-     * @throws InvalidInterfaceException
3258
-     */
3259
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
-    {
3261
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
-
3263
-        $success = 1;
3264
-
3265
-        // incoming GRP_IDs
3266
-        if ($all) {
3267
-            // Checkboxes
3268
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3270
-                // if array has more than one element then success message should be plural.
3271
-                // todo: what about nonce?
3272
-                $success = count($checkboxes) > 1 ? 2 : 1;
3273
-
3274
-                // cycle through checkboxes
3275
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3276
-                    $trashed_or_restored = $trash
3277
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3280
-                        $success = 0;
3281
-                    }
3282
-                }
3283
-            } else {
3284
-                // grab single GRP_ID and handle
3285
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3287
-                    $trashed_or_restored = $trash
3288
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3291
-                        $success = 0;
3292
-                    }
3293
-                } else {
3294
-                    $success = 0;
3295
-                }
3296
-            }
3297
-        }
3298
-
3299
-        $action_desc = $trash
3300
-            ? esc_html__('moved to the trash', 'event_espresso')
3301
-            : esc_html__('restored', 'event_espresso');
3302
-
3303
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
-
3306
-        $item_desc = $all ? _n(
3307
-            'Message Template Group',
3308
-            'Message Template Groups',
3309
-            $success,
3310
-            'event_espresso'
3311
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
-
3313
-        $item_desc = $template_switch
3314
-            ? _n('template', 'templates', $success, 'event_espresso')
3315
-            : $item_desc;
3316
-
3317
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
-    }
3319
-
3320
-
3321
-    /**
3322
-     * [_delete_message_template]
3323
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
-     *
3325
-     * @return void
3326
-     * @throws EE_Error
3327
-     * @throws InvalidArgumentException
3328
-     * @throws InvalidDataTypeException
3329
-     * @throws InvalidInterfaceException
3330
-     * @throws ReflectionException
3331
-     */
3332
-    protected function _delete_message_template()
3333
-    {
3334
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
-
3336
-        // checkboxes
3337
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3339
-            // if array has more than one element then success message should be plural
3340
-            $success = count($checkboxes) > 1 ? 2 : 1;
3341
-
3342
-            // cycle through bulk action checkboxes
3343
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3344
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
-            }
3346
-        } else {
3347
-            // grab single grp_id and delete
3348
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3350
-        }
3351
-
3352
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
-    }
3354
-
3355
-
3356
-    /**
3357
-     * helper for permanently deleting a mtP group and all related message_templates
3358
-     *
3359
-     * @param int  $GRP_ID        The group being deleted
3360
-     * @param bool $include_group whether to delete the Message Template Group as well.
3361
-     * @return bool boolean to indicate the success of the deletes or not.
3362
-     * @throws EE_Error
3363
-     * @throws InvalidArgumentException
3364
-     * @throws InvalidDataTypeException
3365
-     * @throws InvalidInterfaceException
3366
-     * @throws ReflectionException
3367
-     * @throws ReflectionException
3368
-     */
3369
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
-    {
3371
-        $success = true;
3372
-        // first let's GET this group
3373
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
-        // then delete permanently all the related Message Templates
3375
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3376
-
3377
-        if ($deleted === 0) {
3378
-            $success = false;
3379
-        }
3380
-
3381
-        // now delete permanently this particular group
3382
-
3383
-        if ($include_group && ! $MTG->delete_permanently()) {
3384
-            $success = false;
3385
-        }
3386
-
3387
-        return $success;
3388
-    }
3389
-
3390
-
3391
-    /**
3392
-     *    _learn_more_about_message_templates_link
3393
-     *
3394
-     * @access protected
3395
-     * @return string
3396
-     */
3397
-    protected function _learn_more_about_message_templates_link()
3398
-    {
3399
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3401
-               . '</a>';
3402
-    }
3403
-
3404
-
3405
-    /**
3406
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
-     * ajax and other routes.
3408
-     *
3409
-     * @return void
3410
-     * @throws DomainException
3411
-     * @throws EE_Error
3412
-     */
3413
-    protected function _settings()
3414
-    {
3415
-        $this->_set_m_mt_settings();
3416
-
3417
-        // let's setup the messenger tabs
3418
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
-            $this->_m_mt_settings['messenger_tabs'],
3420
-            'messenger_links',
3421
-            '|',
3422
-            $this->request->getRequestParam('selected_messenger', 'email')
3423
-        );
3424
-
3425
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
-
3428
-        $this->display_admin_page_with_sidebar();
3429
-    }
3430
-
3431
-
3432
-    /**
3433
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
-     *
3435
-     * @access protected
3436
-     * @return void
3437
-     * @throws DomainException
3438
-     */
3439
-    protected function _set_m_mt_settings()
3440
-    {
3441
-        // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3443
-            return;
3444
-        }
3445
-
3446
-        // get all installed messengers and message_types
3447
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3448
-        $message_types = $this->_message_resource_manager->installed_message_types();
3449
-
3450
-
3451
-        // assemble the array for the _tab_text_links helper
3452
-
3453
-        foreach ($messengers as $messenger) {
3454
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
-                'label' => ucwords($messenger->label['singular']),
3456
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457
-                    ? 'messenger-active'
3458
-                    : '',
3459
-                'href'  => $messenger->name,
3460
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
-                'slug'  => $messenger->name,
3462
-                'obj'   => $messenger,
3463
-            ];
3464
-
3465
-
3466
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3467
-
3468
-            foreach ($message_types as $message_type) {
3469
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470
-                // it shouldn't show in either the inactive OR active metabox.
3471
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
-                    continue;
3473
-                }
3474
-
3475
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3476
-                    $messenger->name,
3477
-                    $message_type->name
3478
-                )
3479
-                    ? 'active'
3480
-                    : 'inactive';
3481
-
3482
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
-                    'label'    => ucwords($message_type->label['singular']),
3484
-                    'class'    => 'message-type-' . $a_or_i,
3485
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3488
-                    'title'    => $a_or_i === 'active'
3489
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3491
-                    'content'  => $a_or_i === 'active'
3492
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3493
-                        : $this->_message_type_settings_content($message_type, $messenger),
3494
-                    'slug'     => $message_type->name,
3495
-                    'active'   => $a_or_i === 'active',
3496
-                    'obj'      => $message_type,
3497
-                ];
3498
-            }
3499
-        }
3500
-    }
3501
-
3502
-
3503
-    /**
3504
-     * This just prepares the content for the message type settings
3505
-     *
3506
-     * @param EE_message_type $message_type The message type object
3507
-     * @param EE_messenger    $messenger    The messenger object
3508
-     * @param boolean         $active       Whether the message type is active or not
3509
-     * @return string html output for the content
3510
-     * @throws DomainException
3511
-     */
3512
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3513
-    {
3514
-        // get message type fields
3515
-        $fields                                         = $message_type->get_admin_settings_fields();
3516
-        $settings_template_args['template_form_fields'] = '';
3517
-
3518
-        if (! empty($fields) && $active) {
3519
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520
-            foreach ($fields as $fldname => $fldprops) {
3521
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
-                $template_form_field[ $field_id ] = [
3523
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3524
-                    'label'      => $fldprops['label'],
3525
-                    'input'      => $fldprops['field_type'],
3526
-                    'type'       => $fldprops['value_type'],
3527
-                    'required'   => $fldprops['required'],
3528
-                    'validation' => $fldprops['validation'],
3529
-                    'value'      => isset($existing_settings[ $fldname ])
3530
-                        ? $existing_settings[ $fldname ]
3531
-                        : $fldprops['default'],
3532
-                    'options'    => isset($fldprops['options'])
3533
-                        ? $fldprops['options']
3534
-                        : [],
3535
-                    'default'    => isset($existing_settings[ $fldname ])
3536
-                        ? $existing_settings[ $fldname ]
3537
-                        : $fldprops['default'],
3538
-                    'css_class'  => 'no-drag',
3539
-                    'format'     => $fldprops['format'],
3540
-                ];
3541
-            }
3542
-
3543
-
3544
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3545
-                ? $this->_generate_admin_form_fields(
3546
-                    $template_form_field,
3547
-                    'string',
3548
-                    'ee_mt_activate_form'
3549
-                )
3550
-                : '';
3551
-        }
3552
-
3553
-        $settings_template_args['description'] = $message_type->description;
3554
-        // we also need some hidden fields
3555
-        $hidden_fields = [
3556
-            'message_type_settings[messenger]' . $message_type->name    => [
3557
-                'type'  => 'hidden',
3558
-                'value' => $messenger->name,
3559
-            ],
3560
-            'message_type_settings[message_type]' . $message_type->name => [
3561
-                'type'  => 'hidden',
3562
-                'value' => $message_type->name,
3563
-            ],
3564
-            'type' . $message_type->name                                => [
3565
-                'type'  => 'hidden',
3566
-                'value' => 'message_type',
3567
-            ],
3568
-        ];
3569
-
3570
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3571
-            $hidden_fields,
3572
-            'array'
3573
-        );
3574
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
-            ? ' hidden'
3576
-            : '';
3577
-
3578
-
3579
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
-        return EEH_Template::display_template($template, $settings_template_args, true);
3581
-    }
3582
-
3583
-
3584
-    /**
3585
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3586
-     *
3587
-     * @access protected
3588
-     * @return void
3589
-     * @throws DomainException
3590
-     */
3591
-    protected function _messages_settings_metaboxes()
3592
-    {
3593
-        $this->_set_m_mt_settings();
3594
-        $m_boxes         = $mt_boxes = [];
3595
-        $m_template_args = $mt_template_args = [];
3596
-
3597
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3598
-
3599
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3600
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3601
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3602
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3603
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3604
-
3605
-                // messenger meta boxes
3606
-                $active         = $selected_messenger === $messenger;
3607
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3609
-                    : '';
3610
-
3611
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
-                    esc_html__('%s Settings', 'event_espresso'),
3613
-                    $tab_array['label']
3614
-                );
3615
-
3616
-                $m_template_args[ $messenger . '_a_box' ] = [
3617
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618
-                    'inactive_message_types' => isset(
3619
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
-                    )
3621
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
-                        : '',
3623
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624
-                    'hidden'                 => $active ? '' : ' hidden',
3625
-                    'hide_on_message'        => $hide_on_message,
3626
-                    'messenger'              => $messenger,
3627
-                    'active'                 => $active,
3628
-                ];
3629
-
3630
-                // message type meta boxes
3631
-                // (which is really just the inactive container for each messenger
3632
-                // showing inactive message types for that messenger)
3633
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
-                $mt_template_args[ $messenger . '_i_box' ] = [
3635
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636
-                    'inactive_message_types' => isset(
3637
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
-                    )
3639
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
-                        : '',
3641
-                    'hidden'                 => $active ? '' : ' hidden',
3642
-                    'hide_on_message'        => $hide_on_message,
3643
-                    'hide_off_message'       => $hide_off_message,
3644
-                    'messenger'              => $messenger,
3645
-                    'active'                 => $active,
3646
-                ];
3647
-            }
3648
-        }
3649
-
3650
-
3651
-        // register messenger metaboxes
3652
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
-        foreach ($m_boxes as $box => $label) {
3654
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
-            $msgr          = str_replace('_a_box', '', $box);
3656
-            add_meta_box(
3657
-                'espresso_' . $msgr . '_settings',
3658
-                $label,
3659
-                function ($post, $metabox) {
3660
-                    EEH_Template::display_template(
3661
-                        $metabox['args']['template_path'],
3662
-                        $metabox['args']['template_args']
3663
-                    );
3664
-                },
3665
-                $this->_current_screen->id,
3666
-                'normal',
3667
-                'high',
3668
-                $callback_args
3669
-            );
3670
-        }
3671
-
3672
-        // register message type metaboxes
3673
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
-        foreach ($mt_boxes as $box => $label) {
3675
-            $callback_args = [
3676
-                'template_path' => $mt_template_path,
3677
-                'template_args' => $mt_template_args[ $box ],
3678
-            ];
3679
-            $mt            = str_replace('_i_box', '', $box);
3680
-            add_meta_box(
3681
-                'espresso_' . $mt . '_inactive_mts',
3682
-                $label,
3683
-                function ($post, $metabox) {
3684
-                    EEH_Template::display_template(
3685
-                        $metabox['args']['template_path'],
3686
-                        $metabox['args']['template_args']
3687
-                    );
3688
-                },
3689
-                $this->_current_screen->id,
3690
-                'side',
3691
-                'high',
3692
-                $callback_args
3693
-            );
3694
-        }
3695
-
3696
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3697
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3698
-        if (is_main_site()) {
3699
-            add_meta_box(
3700
-                'espresso_global_message_settings',
3701
-                esc_html__('Global Message Settings', 'event_espresso'),
3702
-                [$this, 'global_messages_settings_metabox_content'],
3703
-                $this->_current_screen->id,
3704
-                'normal',
3705
-                'low',
3706
-                []
3707
-            );
3708
-        }
3709
-    }
3710
-
3711
-
3712
-    /**
3713
-     *  This generates the content for the global messages settings metabox.
3714
-     *
3715
-     * @return void
3716
-     * @throws EE_Error
3717
-     * @throws InvalidArgumentException
3718
-     * @throws ReflectionException
3719
-     * @throws InvalidDataTypeException
3720
-     * @throws InvalidInterfaceException
3721
-     */
3722
-    public function global_messages_settings_metabox_content()
3723
-    {
3724
-        $form = $this->_generate_global_settings_form();
3725
-        echo wp_kses(
3726
-            $form->form_open(
3727
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3728
-                'POST'
3729
-            ),
3730
-            AllowedTags::getWithFormTags()
3731
-        );
3732
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3733
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3734
-    }
3735
-
3736
-
3737
-    /**
3738
-     * This generates and returns the form object for the global messages settings.
3739
-     *
3740
-     * @return EE_Form_Section_Proper
3741
-     * @throws EE_Error
3742
-     * @throws InvalidArgumentException
3743
-     * @throws ReflectionException
3744
-     * @throws InvalidDataTypeException
3745
-     * @throws InvalidInterfaceException
3746
-     */
3747
-    protected function _generate_global_settings_form()
3748
-    {
3749
-        /** @var EE_Network_Core_Config $network_config */
3750
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3751
-
3752
-        return new EE_Form_Section_Proper(
3753
-            [
3754
-                'name'            => 'global_messages_settings',
3755
-                'html_id'         => 'global_messages_settings',
3756
-                'html_class'      => 'form-table',
3757
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3758
-                'subsections'     => apply_filters(
3759
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3760
-                    [
3761
-                        'do_messages_on_same_request' => new EE_Select_Input(
3762
-                            [
3763
-                                true  => esc_html__('On the same request', 'event_espresso'),
3764
-                                false => esc_html__('On a separate request', 'event_espresso'),
3765
-                            ],
3766
-                            [
3767
-                                'default'         => $network_config->do_messages_on_same_request,
3768
-                                'html_label_text' => esc_html__(
3769
-                                    'Generate and send all messages:',
3770
-                                    'event_espresso'
3771
-                                ),
3772
-                                'html_help_text'  => esc_html__(
3773
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3774
-                                    'event_espresso'
3775
-                                ),
3776
-                            ]
3777
-                        ),
3778
-                        'delete_threshold'            => new EE_Select_Input(
3779
-                            [
3780
-                                0  => esc_html__('Forever', 'event_espresso'),
3781
-                                3  => esc_html__('3 Months', 'event_espresso'),
3782
-                                6  => esc_html__('6 Months', 'event_espresso'),
3783
-                                9  => esc_html__('9 Months', 'event_espresso'),
3784
-                                12 => esc_html__('12 Months', 'event_espresso'),
3785
-                                24 => esc_html__('24 Months', 'event_espresso'),
3786
-                                36 => esc_html__('36 Months', 'event_espresso'),
3787
-                            ],
3788
-                            [
3789
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3790
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3791
-                                'html_help_text'  => esc_html__(
3792
-                                    'You can control how long a record of processed messages is kept via this option.',
3793
-                                    'event_espresso'
3794
-                                ),
3795
-                            ]
3796
-                        ),
3797
-                        'update_settings'             => new EE_Submit_Input(
3798
-                            [
3799
-                                'default'         => esc_html__('Update', 'event_espresso'),
3800
-                                'html_label_text' => '',
3801
-                            ]
3802
-                        ),
3803
-                    ]
3804
-                ),
3805
-            ]
3806
-        );
3807
-    }
3808
-
3809
-
3810
-    /**
3811
-     * This handles updating the global settings set on the admin page.
3812
-     *
3813
-     * @throws EE_Error
3814
-     * @throws InvalidDataTypeException
3815
-     * @throws InvalidInterfaceException
3816
-     * @throws InvalidArgumentException
3817
-     * @throws ReflectionException
3818
-     */
3819
-    protected function _update_global_settings()
3820
-    {
3821
-        /** @var EE_Network_Core_Config $network_config */
3822
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3823
-        $messages_config = EE_Registry::instance()->CFG->messages;
3824
-        $form            = $this->_generate_global_settings_form();
3825
-        if ($form->was_submitted()) {
3826
-            $form->receive_form_submission();
3827
-            if ($form->is_valid()) {
3828
-                $valid_data = $form->valid_data();
3829
-                foreach ($valid_data as $property => $value) {
3830
-                    $setter = 'set_' . $property;
3831
-                    if (method_exists($network_config, $setter)) {
3832
-                        $network_config->{$setter}($value);
3833
-                    } elseif (
3834
-                        property_exists($network_config, $property)
3835
-                        && $network_config->{$property} !== $value
3836
-                    ) {
3837
-                        $network_config->{$property} = $value;
3838
-                    } elseif (
3839
-                        property_exists($messages_config, $property)
3840
-                        && $messages_config->{$property} !== $value
3841
-                    ) {
3842
-                        $messages_config->{$property} = $value;
3843
-                    }
3844
-                }
3845
-                // only update if the form submission was valid!
3846
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3847
-                EE_Registry::instance()->CFG->update_espresso_config();
3848
-                EE_Error::overwrite_success();
3849
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3850
-            }
3851
-        }
3852
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3853
-    }
3854
-
3855
-
3856
-    /**
3857
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3858
-     *
3859
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3860
-     * @return string html formatted tabs
3861
-     * @throws DomainException
3862
-     */
3863
-    protected function _get_mt_tabs($tab_array)
3864
-    {
3865
-        $tab_array = (array) $tab_array;
3866
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3867
-        $tabs      = '';
3868
-
3869
-        foreach ($tab_array as $tab) {
3870
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3871
-        }
3872
-
3873
-        return $tabs;
3874
-    }
3875
-
3876
-
3877
-    /**
3878
-     * This prepares the content of the messenger meta box admin settings
3879
-     *
3880
-     * @param EE_messenger $messenger The messenger we're setting up content for
3881
-     * @return string html formatted content
3882
-     * @throws DomainException
3883
-     */
3884
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3885
-    {
3886
-
3887
-        $fields                                         = $messenger->get_admin_settings_fields();
3888
-        $settings_template_args['template_form_fields'] = '';
3889
-
3890
-        // is $messenger active?
3891
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892
-
3893
-
3894
-        if (! empty($fields)) {
3895
-            $existing_settings = $messenger->get_existing_admin_settings();
3896
-
3897
-            foreach ($fields as $fldname => $fldprops) {
3898
-                $field_id                         = $messenger->name . '-' . $fldname;
3899
-                $template_form_field[ $field_id ] = [
3900
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3901
-                    'label'      => $fldprops['label'],
3902
-                    'input'      => $fldprops['field_type'],
3903
-                    'type'       => $fldprops['value_type'],
3904
-                    'required'   => $fldprops['required'],
3905
-                    'validation' => $fldprops['validation'],
3906
-                    'value'      => isset($existing_settings[ $field_id ])
3907
-                        ? $existing_settings[ $field_id ]
3908
-                        : $fldprops['default'],
3909
-                    'css_class'  => '',
3910
-                    'format'     => $fldprops['format'],
3911
-                ];
3912
-            }
3913
-
3914
-
3915
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3916
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3917
-                : '';
3918
-        }
3919
-
3920
-        // we also need some hidden fields
3921
-        $settings_template_args['hidden_fields'] = [
3922
-            'messenger_settings[messenger]' . $messenger->name => [
3923
-                'type'  => 'hidden',
3924
-                'value' => $messenger->name,
3925
-            ],
3926
-            'type' . $messenger->name                          => [
3927
-                'type'  => 'hidden',
3928
-                'value' => 'messenger',
3929
-            ],
3930
-        ];
3931
-
3932
-        // make sure any active message types that are existing are included in the hidden fields
3933
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
-                    'type'  => 'hidden',
3937
-                    'value' => $mt,
3938
-                ];
3939
-            }
3940
-        }
3941
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3942
-            $settings_template_args['hidden_fields'],
3943
-            'array'
3944
-        );
3945
-        $active                                  =
3946
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3947
-
3948
-        $settings_template_args['messenger']           = $messenger->name;
3949
-        $settings_template_args['description']         = $messenger->description;
3950
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3951
-
3952
-
3953
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3954
-            $messenger->name
3955
-        )
3956
-            ? $settings_template_args['show_hide_edit_form']
3957
-            : ' hidden';
3958
-
3959
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3960
-            ? ' hidden'
3961
-            : $settings_template_args['show_hide_edit_form'];
3962
-
3963
-
3964
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3966
-        $settings_template_args['on_off_status'] = $active;
3967
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3968
-        return EEH_Template::display_template(
3969
-            $template,
3970
-            $settings_template_args,
3971
-            true
3972
-        );
3973
-    }
3974
-
3975
-
3976
-    /**
3977
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3978
-     *
3979
-     * @throws DomainException
3980
-     * @throws EE_Error
3981
-     * @throws InvalidDataTypeException
3982
-     * @throws InvalidInterfaceException
3983
-     * @throws InvalidArgumentException
3984
-     * @throws ReflectionException
3985
-     */
3986
-    public function activate_messenger_toggle()
3987
-    {
3988
-        $success = true;
3989
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3990
-        // let's check that we have required data
3991
-
3992
-        if (! $this->_active_messenger_name) {
3993
-            EE_Error::add_error(
3994
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995
-                __FILE__,
3996
-                __FUNCTION__,
3997
-                __LINE__
3998
-            );
3999
-            $success = false;
4000
-        }
4001
-
4002
-        // do a nonce check here since we're not arriving via a normal route
4003
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4004
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4005
-
4006
-        $this->_verify_nonce($nonce, $nonce_ref);
4007
-
4008
-
4009
-        $status = $this->request->getRequestParam('status');
4010
-        if (! $status) {
4011
-            EE_Error::add_error(
4012
-                esc_html__(
4013
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4014
-                    'event_espresso'
4015
-                ),
4016
-                __FILE__,
4017
-                __FUNCTION__,
4018
-                __LINE__
4019
-            );
4020
-            $success = false;
4021
-        }
4022
-
4023
-        // do check to verify we have a valid status.
4024
-        if ($status !== 'off' && $status !== 'on') {
4025
-            EE_Error::add_error(
4026
-                sprintf(
4027
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4028
-                    $status
4029
-                ),
4030
-                __FILE__,
4031
-                __FUNCTION__,
4032
-                __LINE__
4033
-            );
4034
-            $success = false;
4035
-        }
4036
-
4037
-        if ($success) {
4038
-            // made it here?  Stop dawdling then!!
4039
-            $success = $status === 'off'
4040
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4041
-                : $this->_activate_messenger($this->_active_messenger_name);
4042
-        }
4043
-
4044
-        $this->_template_args['success'] = $success;
4045
-
4046
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4047
-        $this->_return_json();
4048
-    }
4049
-
4050
-
4051
-    /**
4052
-     * used by ajax from the messages settings page to activate|deactivate a message type
4053
-     *
4054
-     * @throws DomainException
4055
-     * @throws EE_Error
4056
-     * @throws ReflectionException
4057
-     * @throws InvalidDataTypeException
4058
-     * @throws InvalidInterfaceException
4059
-     * @throws InvalidArgumentException
4060
-     */
4061
-    public function activate_mt_toggle()
4062
-    {
4063
-        $success = true;
4064
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4065
-
4066
-        // let's make sure we have the necessary data
4067
-        if (! $this->_active_message_type_name) {
4068
-            EE_Error::add_error(
4069
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070
-                __FILE__,
4071
-                __FUNCTION__,
4072
-                __LINE__
4073
-            );
4074
-            $success = false;
4075
-        }
4076
-
4077
-        if (! $this->_active_messenger_name) {
4078
-            EE_Error::add_error(
4079
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080
-                __FILE__,
4081
-                __FUNCTION__,
4082
-                __LINE__
4083
-            );
4084
-            $success = false;
4085
-        }
4086
-
4087
-        $status = $this->request->getRequestParam('status');
4088
-        if (! $status) {
4089
-            EE_Error::add_error(
4090
-                esc_html__(
4091
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4092
-                    'event_espresso'
4093
-                ),
4094
-                __FILE__,
4095
-                __FUNCTION__,
4096
-                __LINE__
4097
-            );
4098
-            $success = false;
4099
-        }
4100
-
4101
-
4102
-        // do check to verify we have a valid status.
4103
-        if ($status !== 'activate' && $status !== 'deactivate') {
4104
-            EE_Error::add_error(
4105
-                sprintf(
4106
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4107
-                    $status
4108
-                ),
4109
-                __FILE__,
4110
-                __FUNCTION__,
4111
-                __LINE__
4112
-            );
4113
-            $success = false;
4114
-        }
4115
-
4116
-
4117
-        // do a nonce check here since we're not arriving via a normal route
4118
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4119
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4120
-
4121
-        if ($success) {
4122
-            // made it here? um, what are you waiting for then?
4123
-            $success = $status === 'deactivate'
4124
-                ? $this->_deactivate_message_type_for_messenger(
4125
-                    $this->_active_messenger_name,
4126
-                    $this->_active_message_type_name
4127
-                )
4128
-                : $this->_activate_message_type_for_messenger(
4129
-                    $this->_active_messenger_name,
4130
-                    $this->_active_message_type_name
4131
-                );
4132
-        }
4133
-
4134
-        $this->_template_args['success'] = $success;
4135
-        $this->_return_json();
4136
-    }
4137
-
4138
-
4139
-    /**
4140
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4141
-     *
4142
-     * @param string $messenger_name The name of the messenger being activated
4143
-     * @return bool
4144
-     * @throws DomainException
4145
-     * @throws EE_Error
4146
-     * @throws InvalidArgumentException
4147
-     * @throws ReflectionException
4148
-     * @throws InvalidDataTypeException
4149
-     * @throws InvalidInterfaceException
4150
-     */
4151
-    protected function _activate_messenger($messenger_name)
4152
-    {
4153
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4154
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4155
-            ? $active_messenger->get_default_message_types()
4156
-            : [];
4157
-
4158
-        // ensure is active
4159
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4160
-
4161
-        // set response_data for reload
4162
-        foreach ($message_types_to_activate as $message_type_name) {
4163
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4164
-            if (
4165
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4166
-                    $messenger_name,
4167
-                    $message_type_name
4168
-                )
4169
-                && $message_type instanceof EE_message_type
4170
-            ) {
4171
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4172
-                if ($message_type->get_admin_settings_fields()) {
4173
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4174
-                }
4175
-            }
4176
-        }
4177
-
4178
-        // add success message for activating messenger
4179
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4180
-    }
4181
-
4182
-
4183
-    /**
4184
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4185
-     *
4186
-     * @param string $messenger_name The name of the messenger being activated
4187
-     * @return bool
4188
-     * @throws DomainException
4189
-     * @throws EE_Error
4190
-     * @throws InvalidArgumentException
4191
-     * @throws ReflectionException
4192
-     * @throws InvalidDataTypeException
4193
-     * @throws InvalidInterfaceException
4194
-     */
4195
-    protected function _deactivate_messenger($messenger_name)
4196
-    {
4197
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4198
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4199
-
4200
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4201
-    }
4202
-
4203
-
4204
-    /**
4205
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4206
-     *
4207
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4208
-     * @param string $message_type_name The name of the message type being activated for the messenger
4209
-     * @return bool
4210
-     * @throws DomainException
4211
-     * @throws EE_Error
4212
-     * @throws InvalidArgumentException
4213
-     * @throws ReflectionException
4214
-     * @throws InvalidDataTypeException
4215
-     * @throws InvalidInterfaceException
4216
-     */
4217
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4218
-    {
4219
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4220
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4221
-
4222
-        // ensure is active
4223
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4224
-
4225
-        // set response for load
4226
-        if (
4227
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4228
-                $messenger_name,
4229
-                $message_type_name
4230
-            )
4231
-        ) {
4232
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4233
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4234
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4235
-            }
4236
-        }
4237
-
4238
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4239
-            $active_messenger,
4240
-            $message_type_to_activate
4241
-        );
4242
-    }
4243
-
4244
-
4245
-    /**
4246
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4247
-     *
4248
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4249
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4250
-     * @return bool
4251
-     * @throws DomainException
4252
-     * @throws EE_Error
4253
-     * @throws InvalidArgumentException
4254
-     * @throws ReflectionException
4255
-     * @throws InvalidDataTypeException
4256
-     * @throws InvalidInterfaceException
4257
-     */
4258
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4259
-    {
4260
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4261
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4262
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4263
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4264
-
4265
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4266
-            $active_messenger,
4267
-            $message_type_to_deactivate
4268
-        );
4269
-    }
4270
-
4271
-
4272
-    /**
4273
-     * This just initializes the defaults for activating messenger and message type responses.
4274
-     */
4275
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4276
-    {
4277
-        $this->_template_args['data']['active_mts'] = [];
4278
-        $this->_template_args['data']['mt_reload']  = [];
4279
-    }
4280
-
4281
-
4282
-    /**
4283
-     * Setup appropriate response for activating a messenger and/or message types
4284
-     *
4285
-     * @param EE_messenger         $messenger
4286
-     * @param EE_message_type|null $message_type
4287
-     * @return bool
4288
-     * @throws DomainException
4289
-     * @throws EE_Error
4290
-     * @throws InvalidArgumentException
4291
-     * @throws ReflectionException
4292
-     * @throws InvalidDataTypeException
4293
-     * @throws InvalidInterfaceException
4294
-     */
4295
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4296
-        $messenger,
4297
-        EE_Message_Type $message_type = null
4298
-    ) {
4299
-        // if $messenger isn't a valid messenger object then get out.
4300
-        if (! $messenger instanceof EE_Messenger) {
4301
-            EE_Error::add_error(
4302
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303
-                __FILE__,
4304
-                __FUNCTION__,
4305
-                __LINE__
4306
-            );
4307
-            return false;
4308
-        }
4309
-        // activated
4310
-        if ($this->_template_args['data']['active_mts']) {
4311
-            EE_Error::overwrite_success();
4312
-            // activated a message type with the messenger
4313
-            if ($message_type instanceof EE_message_type) {
4314
-                EE_Error::add_success(
4315
-                    sprintf(
4316
-                        esc_html__(
4317
-                            '%s message type has been successfully activated with the %s messenger',
4318
-                            'event_espresso'
4319
-                        ),
4320
-                        ucwords($message_type->label['singular']),
4321
-                        ucwords($messenger->label['singular'])
4322
-                    )
4323
-                );
4324
-
4325
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4326
-                if ($message_type->name === 'invoice') {
4327
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4328
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4329
-                    if ($pm instanceof EE_Payment_Method) {
4330
-                        EE_Error::add_attention(
4331
-                            esc_html__(
4332
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4333
-                                'event_espresso'
4334
-                            )
4335
-                        );
4336
-                    }
4337
-                }
4338
-                // just toggles the entire messenger
4339
-            } else {
4340
-                EE_Error::add_success(
4341
-                    sprintf(
4342
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4343
-                        ucwords($messenger->label['singular'])
4344
-                    )
4345
-                );
4346
-            }
4347
-
4348
-            return true;
4349
-
4350
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4351
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352
-            // in which case we just give a success message for the messenger being successfully activated.
4353
-        } else {
4354
-            if (! $messenger->get_default_message_types()) {
4355
-                // messenger doesn't have any default message types so still a success.
4356
-                EE_Error::add_success(
4357
-                    sprintf(
4358
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4359
-                        ucwords($messenger->label['singular'])
4360
-                    )
4361
-                );
4362
-
4363
-                return true;
4364
-            } else {
4365
-                EE_Error::add_error(
4366
-                    $message_type instanceof EE_message_type
4367
-                    ? sprintf(
4368
-                        esc_html__(
4369
-                            '%s message type was not successfully activated with the %s messenger',
4370
-                            'event_espresso'
4371
-                        ),
4372
-                        ucwords($message_type->label['singular']),
4373
-                        ucwords($messenger->label['singular'])
4374
-                    )
4375
-                    : sprintf(
4376
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4377
-                        ucwords($messenger->label['singular'])
4378
-                    ),
4379
-                    __FILE__,
4380
-                    __FUNCTION__,
4381
-                    __LINE__
4382
-                );
4383
-
4384
-                return false;
4385
-            }
4386
-        }
4387
-    }
4388
-
4389
-
4390
-    /**
4391
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4392
-     *
4393
-     * @param EE_messenger         $messenger
4394
-     * @param EE_message_type|null $message_type
4395
-     * @return bool
4396
-     * @throws DomainException
4397
-     * @throws EE_Error
4398
-     * @throws InvalidArgumentException
4399
-     * @throws ReflectionException
4400
-     * @throws InvalidDataTypeException
4401
-     * @throws InvalidInterfaceException
4402
-     */
4403
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4404
-        $messenger,
4405
-        EE_message_type $message_type = null
4406
-    ) {
4407
-        EE_Error::overwrite_success();
4408
-
4409
-        // if $messenger isn't a valid messenger object then get out.
4410
-        if (! $messenger instanceof EE_Messenger) {
4411
-            EE_Error::add_error(
4412
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413
-                __FILE__,
4414
-                __FUNCTION__,
4415
-                __LINE__
4416
-            );
4417
-
4418
-            return false;
4419
-        }
4420
-
4421
-        if ($message_type instanceof EE_message_type) {
4422
-            $message_type_name = $message_type->name;
4423
-            EE_Error::add_success(
4424
-                sprintf(
4425
-                    esc_html__(
4426
-                        '%s message type has been successfully deactivated for the %s messenger.',
4427
-                        'event_espresso'
4428
-                    ),
4429
-                    ucwords($message_type->label['singular']),
4430
-                    ucwords($messenger->label['singular'])
4431
-                )
4432
-            );
4433
-        } else {
4434
-            $message_type_name = '';
4435
-            EE_Error::add_success(
4436
-                sprintf(
4437
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4438
-                    ucwords($messenger->label['singular'])
4439
-                )
4440
-            );
4441
-        }
4442
-
4443
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4444
-        if (
4445
-            $messenger->name === 'html'
4446
-            && (
4447
-                is_null($message_type)
4448
-                || $message_type_name === 'invoice'
4449
-            )
4450
-        ) {
4451
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4452
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4453
-            if ($count_updated > 0) {
4454
-                $msg = $message_type_name === 'invoice'
4455
-                    ? esc_html__(
4456
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4457
-                        'event_espresso'
4458
-                    )
4459
-                    : esc_html__(
4460
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4461
-                        'event_espresso'
4462
-                    );
4463
-                EE_Error::add_attention($msg);
4464
-            }
4465
-        }
4466
-
4467
-        return true;
4468
-    }
4469
-
4470
-
4471
-    /**
4472
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4473
-     *
4474
-     * @throws DomainException
4475
-     * @throws EE_Error
4476
-     * @throws EE_Error
4477
-     */
4478
-    public function update_mt_form()
4479
-    {
4480
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481
-            EE_Error::add_error(
4482
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483
-                __FILE__,
4484
-                __FUNCTION__,
4485
-                __LINE__
4486
-            );
4487
-            $this->_return_json();
4488
-        }
4489
-
4490
-        $message_types = $this->get_installed_message_types();
4491
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4492
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494
-
4495
-        $this->_template_args['success'] = true;
4496
-        $this->_template_args['content'] = $content;
4497
-        $this->_return_json();
4498
-    }
4499
-
4500
-
4501
-    /**
4502
-     * this handles saving the settings for a messenger or message type
4503
-     *
4504
-     * @throws EE_Error
4505
-     * @throws EE_Error
4506
-     */
4507
-    public function save_settings()
4508
-    {
4509
-        $type = $this->request->getRequestParam('type');
4510
-        if (! $type) {
4511
-            EE_Error::add_error(
4512
-                esc_html__(
4513
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4514
-                    'event_espresso'
4515
-                ),
4516
-                __FILE__,
4517
-                __FUNCTION__,
4518
-                __LINE__
4519
-            );
4520
-            $this->_template_args['error'] = true;
4521
-            $this->_return_json();
4522
-        }
4523
-
4524
-
4525
-        if ($type === 'messenger') {
4526
-            // this should be an array.
4527
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4528
-            $messenger = $settings['messenger'];
4529
-            // remove messenger and message_types from settings array
4530
-            unset($settings['messenger'], $settings['message_types']);
4531
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4532
-        } elseif ($type === 'message_type') {
4533
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4534
-            $messenger    = $settings['messenger'];
4535
-            $message_type = $settings['message_type'];
4536
-            // remove messenger and message_types from settings array
4537
-            unset($settings['messenger'], $settings['message_types']);
4538
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4539
-        }
4540
-
4541
-        // okay we should have the data all setup.  Now we just update!
4542
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4543
-
4544
-        if ($success) {
4545
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4546
-        } else {
4547
-            EE_Error::add_error(
4548
-                esc_html__('Settings did not get updated', 'event_espresso'),
4549
-                __FILE__,
4550
-                __FUNCTION__,
4551
-                __LINE__
4552
-            );
4553
-        }
4554
-
4555
-        $this->_template_args['success'] = $success;
4556
-        $this->_return_json();
4557
-    }
4558
-
4559
-
4560
-
4561
-
4562
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4563
-
4564
-
4565
-    /**
4566
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4567
-     * However, this does not send immediately, it just queues for sending.
4568
-     *
4569
-     * @throws EE_Error
4570
-     * @throws InvalidDataTypeException
4571
-     * @throws InvalidInterfaceException
4572
-     * @throws InvalidArgumentException
4573
-     * @throws ReflectionException
4574
-     * @since 4.9.0
4575
-     */
4576
-    protected function _generate_now()
4577
-    {
4578
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4579
-        $this->_redirect_after_action(false, '', '', [], true);
4580
-    }
4581
-
4582
-
4583
-    /**
4584
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4585
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4586
-     *
4587
-     * @throws EE_Error
4588
-     * @throws InvalidDataTypeException
4589
-     * @throws InvalidInterfaceException
4590
-     * @throws InvalidArgumentException
4591
-     * @throws ReflectionException
4592
-     * @since 4.9.0
4593
-     */
4594
-    protected function _generate_and_send_now()
4595
-    {
4596
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4597
-        $this->_redirect_after_action(false, '', '', [], true);
4598
-    }
4599
-
4600
-
4601
-    /**
4602
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4603
-     *
4604
-     * @throws EE_Error
4605
-     * @throws InvalidDataTypeException
4606
-     * @throws InvalidInterfaceException
4607
-     * @throws InvalidArgumentException
4608
-     * @throws ReflectionException
4609
-     * @since 4.9.0
4610
-     */
4611
-    protected function _queue_for_resending()
4612
-    {
4613
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4614
-        $this->_redirect_after_action(false, '', '', [], true);
4615
-    }
4616
-
4617
-
4618
-    /**
4619
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4620
-     *
4621
-     * @throws EE_Error
4622
-     * @throws InvalidDataTypeException
4623
-     * @throws InvalidInterfaceException
4624
-     * @throws InvalidArgumentException
4625
-     * @throws ReflectionException
4626
-     * @since 4.9.0
4627
-     */
4628
-    protected function _send_now()
4629
-    {
4630
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4631
-        $this->_redirect_after_action(false, '', '', [], true);
4632
-    }
4633
-
4634
-
4635
-    /**
4636
-     * Deletes EE_messages for IDs in the request.
4637
-     *
4638
-     * @throws EE_Error
4639
-     * @throws InvalidDataTypeException
4640
-     * @throws InvalidInterfaceException
4641
-     * @throws InvalidArgumentException
4642
-     * @since 4.9.0
4643
-     */
4644
-    protected function _delete_ee_messages()
4645
-    {
4646
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4647
-        $deleted_count = 0;
4648
-        foreach ($MSG_IDs as $MSG_ID) {
4649
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4650
-                $deleted_count++;
4651
-            }
4652
-        }
4653
-        if ($deleted_count) {
4654
-            EE_Error::add_success(
4655
-                esc_html(
4656
-                    _n(
4657
-                        'Message successfully deleted',
4658
-                        'Messages successfully deleted',
4659
-                        $deleted_count,
4660
-                        'event_espresso'
4661
-                    )
4662
-                )
4663
-            );
4664
-        } else {
4665
-            EE_Error::add_error(
4666
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4667
-                __FILE__,
4668
-                __FUNCTION__,
4669
-                __LINE__
4670
-            );
4671
-        }
4672
-        $this->_redirect_after_action(false, '', '', [], true);
4673
-    }
4674
-
4675
-
4676
-    /**
4677
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4678
-     *
4679
-     * @return array
4680
-     * @since 4.9.0
4681
-     */
4682
-    protected function _get_msg_ids_from_request()
4683
-    {
4684
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4685
-        if (empty($MSG_IDs)) {
4686
-            return [];
4687
-        }
4688
-        // if 'MSG_ID' was just a single ID (not an array)
4689
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4690
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4691
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4692
-            ? $MSG_IDs
4693
-            : array_keys($MSG_IDs);
4694
-    }
2705
+		$this->_context_switcher = ob_get_clean();
2706
+	}
2707
+
2708
+
2709
+	/**
2710
+	 * @param bool $new
2711
+	 * @throws EE_Error
2712
+	 * @throws ReflectionException
2713
+	 */
2714
+	protected function _insert_or_update_message_template($new = false)
2715
+	{
2716
+		$form_data    = $this->getMessageTemplateFormData();
2717
+		$GRP_ID       = $form_data['GRP_ID'];
2718
+		$messenger    = $form_data['MTP_messenger'];
2719
+		$message_type = $form_data['MTP_message_type'];
2720
+		$context      = $form_data['MTP_context'];
2721
+
2722
+		// if this is "new" then we need to generate the default contexts
2723
+		// for the selected messenger/message_type for user to edit.
2724
+		list($success, $query_args) = $new
2725
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
+
2728
+		$success     = $success ? 1 : 0;
2729
+		$action_desc = $new ? 'created' : 'updated';
2730
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
+
2733
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
+	}
2735
+
2736
+
2737
+	/**
2738
+	 * retrieve and sanitize form data
2739
+	 *
2740
+	 * @return array
2741
+	 * @since 4.10.29.p
2742
+	 */
2743
+	protected function getMessageTemplateFormData()
2744
+	{
2745
+		return [
2746
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
+		];
2756
+	}
2757
+
2758
+
2759
+	/**
2760
+	 * @param int    $GRP_ID
2761
+	 * @param string $messenger
2762
+	 * @param string $message_type
2763
+	 * @return array no return on AJAX requests
2764
+	 * @throws EE_Error
2765
+	 * @throws ReflectionException
2766
+	 * @since 4.10.29.p
2767
+	 */
2768
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
+	{
2770
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
+		$success       = ! empty($new_templates);
2772
+
2773
+		// we return things differently if doing ajax
2774
+		if ($this->request->isAjax()) {
2775
+			$this->_template_args['success'] = $success;
2776
+			$this->_template_args['error']   = ! $success;
2777
+			$this->_template_args['content'] = '';
2778
+			$this->_template_args['data']    = [
2779
+				'grpID'        => $new_templates['GRP_ID'],
2780
+				'templateName' => $new_templates['template_name'],
2781
+			];
2782
+			if ($success) {
2783
+				EE_Error::overwrite_success();
2784
+				EE_Error::add_success(
2785
+					esc_html__(
2786
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2787
+						'event_espresso'
2788
+					)
2789
+				);
2790
+			}
2791
+			$this->_return_json();
2792
+		}
2793
+		return [
2794
+			$success,
2795
+			// 'query_args'
2796
+			[
2797
+				'id'      => $new_templates['GRP_ID'],
2798
+				'context' => $new_templates['MTP_context'],
2799
+				'action'  => 'edit_message_template',
2800
+			],
2801
+		];
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * @param int    $GRP_ID
2807
+	 * @param string $messenger
2808
+	 * @param string $message_type
2809
+	 * @param string $context
2810
+	 * @param array  $form_data
2811
+	 * @return array
2812
+	 * @throws EE_Error
2813
+	 * @since 4.10.29.p
2814
+	 */
2815
+	private function updateExistingTemplates(
2816
+		$GRP_ID,
2817
+		$messenger,
2818
+		$message_type,
2819
+		$context,
2820
+		array $form_data
2821
+	) {
2822
+		$success         = false;
2823
+		$template_fields = $this->getTemplateFields();
2824
+		if ($template_fields) {
2825
+			// if field data is valid, then success will be true
2826
+			$success = $this->validateTemplateFields(
2827
+				$messenger,
2828
+				$message_type,
2829
+				$context,
2830
+				$template_fields
2831
+			);
2832
+			if ($success) {
2833
+				$field_data = [];
2834
+				foreach ($template_fields as $template_field => $content) {
2835
+					// combine top-level form data with content for this field
2836
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
+				}
2839
+				// we can use the last set_column_values for the MTPG update
2840
+				// (because its the same for all of these specific MTPs)
2841
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
+			}
2843
+		}
2844
+
2845
+		return [
2846
+			$success,
2847
+			// 'query_args'
2848
+			[
2849
+				'id'      => $GRP_ID,
2850
+				'context' => $context,
2851
+				'action'  => 'edit_message_template',
2852
+			],
2853
+		];
2854
+	}
2855
+
2856
+
2857
+	/**
2858
+	 * @return array
2859
+	 * @since 4.10.29.p
2860
+	 */
2861
+	private function getTemplateFields()
2862
+	{
2863
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
+		if (empty($template_fields)) {
2865
+			EE_Error::add_error(
2866
+				esc_html__(
2867
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
+					'event_espresso'
2869
+				),
2870
+				__FILE__,
2871
+				__FUNCTION__,
2872
+				__LINE__
2873
+			);
2874
+			return null;
2875
+		}
2876
+		// messages content is expected to be escaped
2877
+		return EEH_Array::addSlashesRecursively($template_fields);
2878
+	}
2879
+
2880
+
2881
+	/**
2882
+	 * @param string $messenger
2883
+	 * @param string $message_type
2884
+	 * @param string $context
2885
+	 * @param array  $template_fields
2886
+	 * @return bool
2887
+	 * @throws EE_Error
2888
+	 * @since   4.10.29.p
2889
+	 */
2890
+	private function validateTemplateFields(
2891
+		$messenger,
2892
+		$message_type,
2893
+		$context,
2894
+		array $template_fields
2895
+	) {
2896
+		// first validate all fields!
2897
+		// this filter allows client code to add its own validation to the template fields as well.
2898
+		// returning an empty array means everything passed validation.
2899
+		// errors in validation should be represented in an array with the following shape:
2900
+		// array(
2901
+		//   'fieldname' => array(
2902
+		//          'msg' => 'error message'
2903
+		//          'value' => 'value for field producing error'
2904
+		// )
2905
+		$custom_validation = (array) apply_filters(
2906
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
+			[],
2908
+			$template_fields,
2909
+			$context,
2910
+			$messenger,
2911
+			$message_type
2912
+		);
2913
+
2914
+		$system_validation = $this->getMtgModel()->validate(
2915
+			$template_fields,
2916
+			$context,
2917
+			$messenger,
2918
+			$message_type
2919
+		);
2920
+
2921
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
+		$validates         = array_merge($custom_validation, $system_validation);
2923
+
2924
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
+		//  WE need to make sure there is no actual error messages in validates.
2927
+		if (empty($validates)) {
2928
+			return true;
2929
+		}
2930
+
2931
+		// add the transient so when the form loads we know which fields to highlight
2932
+		$this->_add_transient('edit_message_template', $validates);
2933
+		// setup notices
2934
+		foreach ($validates as $error) {
2935
+			if (isset($error['msg'])) {
2936
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
+			}
2938
+		}
2939
+		return false;
2940
+	}
2941
+
2942
+
2943
+	/**
2944
+	 * @param array $field_data
2945
+	 * @param array $form_data
2946
+	 * @return array
2947
+	 * @since   4.10.29.p
2948
+	 */
2949
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
+	{
2951
+		return $form_data + [
2952
+				'MTP_ID'             => $field_data['MTP_ID'],
2953
+				'MTP_template_field' => $field_data['name'],
2954
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2956
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
+					: $field_data['content'],
2958
+			];
2959
+	}
2960
+
2961
+
2962
+	/**
2963
+	 * @param string $template_field
2964
+	 * @param array  $form_data
2965
+	 * @return bool
2966
+	 * @throws EE_Error
2967
+	 * @since 4.10.29.p
2968
+	 */
2969
+	private function updateMessageTemplates($template_field, array $form_data)
2970
+	{
2971
+		$MTP_ID                  = $form_data['MTP_ID'];
2972
+		$message_template_fields = [
2973
+			'GRP_ID'             => $form_data['GRP_ID'],
2974
+			'MTP_template_field' => $form_data['MTP_template_field'],
2975
+			'MTP_context'        => $form_data['MTP_context'],
2976
+			'MTP_content'        => $form_data['MTP_content'],
2977
+		];
2978
+
2979
+		$hasMtpID = ! empty($MTP_ID);
2980
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2981
+		// this has already been through the template field validator and sanitized, so it will be
2982
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
+		// message template field in a messenger/message type and existing users don't have the
2984
+		// default setup for it.
2985
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
+		$updated = $hasMtpID
2987
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
+			: $this->getMtpModel()->insert($message_template_fields);
2989
+
2990
+		$insert_failed = ! $hasMtpID && ! $updated;
2991
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
+		$update_failed = $hasMtpID && $updated === false;
2994
+
2995
+		if ($insert_failed || $update_failed) {
2996
+			EE_Error::add_error(
2997
+				sprintf(
2998
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
+					$template_field
3000
+				),
3001
+				__FILE__,
3002
+				__FUNCTION__,
3003
+				__LINE__
3004
+			);
3005
+			return false;
3006
+		}
3007
+		return true;
3008
+	}
3009
+
3010
+
3011
+	/**
3012
+	 * @param array $form_data
3013
+	 * @return bool
3014
+	 * @throws EE_Error
3015
+	 * @since 4.10.29.p
3016
+	 */
3017
+	private function updateMessageTemplateGroup(array $form_data)
3018
+	{
3019
+		$GRP_ID  = $form_data['GRP_ID'];
3020
+		$updated = $this->getMtgModel()->update(
3021
+		// fields and values
3022
+			[
3023
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3024
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3025
+				'MTP_message_type' => $form_data['MTP_message_type'],
3026
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3027
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3028
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3029
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3030
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
+				'MTP_description'  => $this->request->getRequestParam(
3032
+					'ee_msg_non_global_fields[MTP_description]',
3033
+					''
3034
+				),
3035
+			],
3036
+			// where
3037
+			[['GRP_ID' => $GRP_ID]]
3038
+		);
3039
+
3040
+		if ($updated === false) {
3041
+			EE_Error::add_error(
3042
+				sprintf(
3043
+					esc_html__(
3044
+						'The Message Template Group (%d) was NOT updated for some reason',
3045
+						'event_espresso'
3046
+					),
3047
+					$form_data['GRP_ID']
3048
+				),
3049
+				__FILE__,
3050
+				__FUNCTION__,
3051
+				__LINE__
3052
+			);
3053
+			return false;
3054
+		}
3055
+		// k now we need to ensure the template_pack and template_variation fields are set.
3056
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
+
3059
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3061
+			$message_template_group->set_template_pack_name($template_pack);
3062
+			$message_template_group->set_template_pack_variation($template_variation);
3063
+		}
3064
+		return true;
3065
+	}
3066
+
3067
+
3068
+	/**
3069
+	 * recursively runs wp_kses() on message template content in a model safe manner
3070
+	 *
3071
+	 * @param array|string $content
3072
+	 * @return array|string
3073
+	 * @since   4.10.29.p
3074
+	 */
3075
+	private function sanitizeMessageTemplateContent($content)
3076
+	{
3077
+		if (is_array($content)) {
3078
+			foreach ($content as $key => $value) {
3079
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
+			}
3081
+			return $content;
3082
+		}
3083
+		// remove slashes so wp_kses() works properly
3084
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3085
+		// so attributes using single quotes always appear invalid.
3086
+		$content = stripslashes($content);
3087
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3088
+		// But currently the models expect slashed data, so after wp_kses()
3089
+		// runs we need to re-slash the data. Sheesh.
3090
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
+		return addslashes($content);
3092
+	}
3093
+
3094
+
3095
+	/**
3096
+	 * @param string $messenger
3097
+	 * @param string $message_type
3098
+	 * @param string $context
3099
+	 * @return string
3100
+	 * @since 4.10.29.p
3101
+	 */
3102
+	private function generateUpdateDescription($messenger, $message_type, $context)
3103
+	{
3104
+		// need the message type and messenger objects to be able to use the labels for the notices
3105
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
+		$messenger_label  = $messenger_object instanceof EE_messenger
3107
+			? ucwords($messenger_object->label['singular'])
3108
+			: '';
3109
+
3110
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
+		$message_type_label  = $message_type_object instanceof EE_message_type
3112
+			? ucwords($message_type_object->label['singular'])
3113
+			: '';
3114
+
3115
+		$context   = ucwords(str_replace('_', ' ', $context));
3116
+		$item_desc = $messenger_label && $message_type_label
3117
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
+			: '';
3119
+		$item_desc .= 'Message Template';
3120
+		return $item_desc;
3121
+	}
3122
+
3123
+
3124
+	/**
3125
+	 * @param string $messenger
3126
+	 * @param string $message_type
3127
+	 * @param string $context
3128
+	 * @return bool
3129
+	 * @throws EE_Error
3130
+	 * @throws ReflectionException
3131
+	 * @since 4.10.29.p
3132
+	 */
3133
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
+	{
3135
+		// was a test send triggered?
3136
+		if ($this->request->requestParamIsSet('test_button')) {
3137
+			EE_Error::overwrite_success();
3138
+			$this->_do_test_send($context, $messenger, $message_type);
3139
+			return true;
3140
+		}
3141
+		return false;
3142
+	}
3143
+
3144
+
3145
+	/**
3146
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
+	 *
3148
+	 * @param string $context      what context being tested
3149
+	 * @param string $messenger    messenger being tested
3150
+	 * @param string $message_type message type being tested
3151
+	 * @throws EE_Error
3152
+	 * @throws InvalidArgumentException
3153
+	 * @throws InvalidDataTypeException
3154
+	 * @throws InvalidInterfaceException
3155
+	 * @throws ReflectionException
3156
+	 */
3157
+	protected function _do_test_send($context, $messenger, $message_type)
3158
+	{
3159
+		// set things up for preview
3160
+		$this->request->setRequestParam('messenger', $messenger);
3161
+		$this->request->setRequestParam('message_type', $message_type);
3162
+		$this->request->setRequestParam('context', $context);
3163
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
+
3166
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
+
3169
+		// let's save any existing fields that might be required by the messenger
3170
+		if (
3171
+			! empty($test_settings_fld)
3172
+			&& $active_messenger instanceof EE_messenger
3173
+			&& apply_filters(
3174
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
+				true,
3176
+				$test_settings_fld,
3177
+				$active_messenger
3178
+			)
3179
+		) {
3180
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3181
+		}
3182
+
3183
+		/**
3184
+		 * Use filter to add additional controls on whether message can send or not
3185
+		 */
3186
+		if (
3187
+			apply_filters(
3188
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
+				true,
3190
+				$context,
3191
+				$this->request->requestParams(),
3192
+				$messenger,
3193
+				$message_type
3194
+			)
3195
+		) {
3196
+			if (EEM_Event::instance()->count() > 0) {
3197
+				$success = $this->_preview_message(true);
3198
+				if ($success) {
3199
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
+				} else {
3201
+					EE_Error::add_error(
3202
+						esc_html__('The test message was not sent', 'event_espresso'),
3203
+						__FILE__,
3204
+						__FUNCTION__,
3205
+						__LINE__
3206
+					);
3207
+				}
3208
+			} else {
3209
+				$this->noEventsErrorMessage(true);
3210
+			}
3211
+		}
3212
+	}
3213
+
3214
+
3215
+	/**
3216
+	 * _generate_new_templates
3217
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
+	 * for the event.
3220
+	 *
3221
+	 *
3222
+	 * @param string $messenger      the messenger we are generating templates for
3223
+	 * @param array  $message_types  array of message types that the templates are generated for.
3224
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
+	 *                               indicate the message_template_group being used as the base.
3226
+	 *
3227
+	 * @param bool   $global
3228
+	 *
3229
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
+	 *                               encountering problems.
3231
+	 * @throws EE_Error
3232
+	 * @throws ReflectionException
3233
+	 */
3234
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
+	{
3236
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
+		// just don't generate any templates.
3238
+		if (empty($message_types)) {
3239
+			return [];
3240
+		}
3241
+
3242
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
+		return $templates[0];
3244
+	}
3245
+
3246
+
3247
+	/**
3248
+	 * [_trash_or_restore_message_template]
3249
+	 *
3250
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
+	 *                        an individual context (FALSE).
3253
+	 * @return void
3254
+	 * @throws EE_Error
3255
+	 * @throws InvalidArgumentException
3256
+	 * @throws InvalidDataTypeException
3257
+	 * @throws InvalidInterfaceException
3258
+	 */
3259
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
+	{
3261
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
+
3263
+		$success = 1;
3264
+
3265
+		// incoming GRP_IDs
3266
+		if ($all) {
3267
+			// Checkboxes
3268
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
+			if (! empty($checkboxes)) {
3270
+				// if array has more than one element then success message should be plural.
3271
+				// todo: what about nonce?
3272
+				$success = count($checkboxes) > 1 ? 2 : 1;
3273
+
3274
+				// cycle through checkboxes
3275
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3276
+					$trashed_or_restored = $trash
3277
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
+					if (! $trashed_or_restored) {
3280
+						$success = 0;
3281
+					}
3282
+				}
3283
+			} else {
3284
+				// grab single GRP_ID and handle
3285
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
+				if (! empty($GRP_ID)) {
3287
+					$trashed_or_restored = $trash
3288
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
+					if (! $trashed_or_restored) {
3291
+						$success = 0;
3292
+					}
3293
+				} else {
3294
+					$success = 0;
3295
+				}
3296
+			}
3297
+		}
3298
+
3299
+		$action_desc = $trash
3300
+			? esc_html__('moved to the trash', 'event_espresso')
3301
+			: esc_html__('restored', 'event_espresso');
3302
+
3303
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
+
3306
+		$item_desc = $all ? _n(
3307
+			'Message Template Group',
3308
+			'Message Template Groups',
3309
+			$success,
3310
+			'event_espresso'
3311
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
+
3313
+		$item_desc = $template_switch
3314
+			? _n('template', 'templates', $success, 'event_espresso')
3315
+			: $item_desc;
3316
+
3317
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
+	}
3319
+
3320
+
3321
+	/**
3322
+	 * [_delete_message_template]
3323
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
+	 *
3325
+	 * @return void
3326
+	 * @throws EE_Error
3327
+	 * @throws InvalidArgumentException
3328
+	 * @throws InvalidDataTypeException
3329
+	 * @throws InvalidInterfaceException
3330
+	 * @throws ReflectionException
3331
+	 */
3332
+	protected function _delete_message_template()
3333
+	{
3334
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
+
3336
+		// checkboxes
3337
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
+		if (! empty($checkboxes)) {
3339
+			// if array has more than one element then success message should be plural
3340
+			$success = count($checkboxes) > 1 ? 2 : 1;
3341
+
3342
+			// cycle through bulk action checkboxes
3343
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3344
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
+			}
3346
+		} else {
3347
+			// grab single grp_id and delete
3348
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3350
+		}
3351
+
3352
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
+	}
3354
+
3355
+
3356
+	/**
3357
+	 * helper for permanently deleting a mtP group and all related message_templates
3358
+	 *
3359
+	 * @param int  $GRP_ID        The group being deleted
3360
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3361
+	 * @return bool boolean to indicate the success of the deletes or not.
3362
+	 * @throws EE_Error
3363
+	 * @throws InvalidArgumentException
3364
+	 * @throws InvalidDataTypeException
3365
+	 * @throws InvalidInterfaceException
3366
+	 * @throws ReflectionException
3367
+	 * @throws ReflectionException
3368
+	 */
3369
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
+	{
3371
+		$success = true;
3372
+		// first let's GET this group
3373
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
+		// then delete permanently all the related Message Templates
3375
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3376
+
3377
+		if ($deleted === 0) {
3378
+			$success = false;
3379
+		}
3380
+
3381
+		// now delete permanently this particular group
3382
+
3383
+		if ($include_group && ! $MTG->delete_permanently()) {
3384
+			$success = false;
3385
+		}
3386
+
3387
+		return $success;
3388
+	}
3389
+
3390
+
3391
+	/**
3392
+	 *    _learn_more_about_message_templates_link
3393
+	 *
3394
+	 * @access protected
3395
+	 * @return string
3396
+	 */
3397
+	protected function _learn_more_about_message_templates_link()
3398
+	{
3399
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3401
+			   . '</a>';
3402
+	}
3403
+
3404
+
3405
+	/**
3406
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
+	 * ajax and other routes.
3408
+	 *
3409
+	 * @return void
3410
+	 * @throws DomainException
3411
+	 * @throws EE_Error
3412
+	 */
3413
+	protected function _settings()
3414
+	{
3415
+		$this->_set_m_mt_settings();
3416
+
3417
+		// let's setup the messenger tabs
3418
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
+			$this->_m_mt_settings['messenger_tabs'],
3420
+			'messenger_links',
3421
+			'|',
3422
+			$this->request->getRequestParam('selected_messenger', 'email')
3423
+		);
3424
+
3425
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
+
3428
+		$this->display_admin_page_with_sidebar();
3429
+	}
3430
+
3431
+
3432
+	/**
3433
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
+	 *
3435
+	 * @access protected
3436
+	 * @return void
3437
+	 * @throws DomainException
3438
+	 */
3439
+	protected function _set_m_mt_settings()
3440
+	{
3441
+		// first if this is already set then lets get out no need to regenerate data.
3442
+		if (! empty($this->_m_mt_settings)) {
3443
+			return;
3444
+		}
3445
+
3446
+		// get all installed messengers and message_types
3447
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3448
+		$message_types = $this->_message_resource_manager->installed_message_types();
3449
+
3450
+
3451
+		// assemble the array for the _tab_text_links helper
3452
+
3453
+		foreach ($messengers as $messenger) {
3454
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
+				'label' => ucwords($messenger->label['singular']),
3456
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457
+					? 'messenger-active'
3458
+					: '',
3459
+				'href'  => $messenger->name,
3460
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
+				'slug'  => $messenger->name,
3462
+				'obj'   => $messenger,
3463
+			];
3464
+
3465
+
3466
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3467
+
3468
+			foreach ($message_types as $message_type) {
3469
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470
+				// it shouldn't show in either the inactive OR active metabox.
3471
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
+					continue;
3473
+				}
3474
+
3475
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3476
+					$messenger->name,
3477
+					$message_type->name
3478
+				)
3479
+					? 'active'
3480
+					: 'inactive';
3481
+
3482
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
+					'label'    => ucwords($message_type->label['singular']),
3484
+					'class'    => 'message-type-' . $a_or_i,
3485
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3488
+					'title'    => $a_or_i === 'active'
3489
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3491
+					'content'  => $a_or_i === 'active'
3492
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3493
+						: $this->_message_type_settings_content($message_type, $messenger),
3494
+					'slug'     => $message_type->name,
3495
+					'active'   => $a_or_i === 'active',
3496
+					'obj'      => $message_type,
3497
+				];
3498
+			}
3499
+		}
3500
+	}
3501
+
3502
+
3503
+	/**
3504
+	 * This just prepares the content for the message type settings
3505
+	 *
3506
+	 * @param EE_message_type $message_type The message type object
3507
+	 * @param EE_messenger    $messenger    The messenger object
3508
+	 * @param boolean         $active       Whether the message type is active or not
3509
+	 * @return string html output for the content
3510
+	 * @throws DomainException
3511
+	 */
3512
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3513
+	{
3514
+		// get message type fields
3515
+		$fields                                         = $message_type->get_admin_settings_fields();
3516
+		$settings_template_args['template_form_fields'] = '';
3517
+
3518
+		if (! empty($fields) && $active) {
3519
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520
+			foreach ($fields as $fldname => $fldprops) {
3521
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
+				$template_form_field[ $field_id ] = [
3523
+					'name'       => 'message_type_settings[' . $fldname . ']',
3524
+					'label'      => $fldprops['label'],
3525
+					'input'      => $fldprops['field_type'],
3526
+					'type'       => $fldprops['value_type'],
3527
+					'required'   => $fldprops['required'],
3528
+					'validation' => $fldprops['validation'],
3529
+					'value'      => isset($existing_settings[ $fldname ])
3530
+						? $existing_settings[ $fldname ]
3531
+						: $fldprops['default'],
3532
+					'options'    => isset($fldprops['options'])
3533
+						? $fldprops['options']
3534
+						: [],
3535
+					'default'    => isset($existing_settings[ $fldname ])
3536
+						? $existing_settings[ $fldname ]
3537
+						: $fldprops['default'],
3538
+					'css_class'  => 'no-drag',
3539
+					'format'     => $fldprops['format'],
3540
+				];
3541
+			}
3542
+
3543
+
3544
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3545
+				? $this->_generate_admin_form_fields(
3546
+					$template_form_field,
3547
+					'string',
3548
+					'ee_mt_activate_form'
3549
+				)
3550
+				: '';
3551
+		}
3552
+
3553
+		$settings_template_args['description'] = $message_type->description;
3554
+		// we also need some hidden fields
3555
+		$hidden_fields = [
3556
+			'message_type_settings[messenger]' . $message_type->name    => [
3557
+				'type'  => 'hidden',
3558
+				'value' => $messenger->name,
3559
+			],
3560
+			'message_type_settings[message_type]' . $message_type->name => [
3561
+				'type'  => 'hidden',
3562
+				'value' => $message_type->name,
3563
+			],
3564
+			'type' . $message_type->name                                => [
3565
+				'type'  => 'hidden',
3566
+				'value' => 'message_type',
3567
+			],
3568
+		];
3569
+
3570
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3571
+			$hidden_fields,
3572
+			'array'
3573
+		);
3574
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
+			? ' hidden'
3576
+			: '';
3577
+
3578
+
3579
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
+		return EEH_Template::display_template($template, $settings_template_args, true);
3581
+	}
3582
+
3583
+
3584
+	/**
3585
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3586
+	 *
3587
+	 * @access protected
3588
+	 * @return void
3589
+	 * @throws DomainException
3590
+	 */
3591
+	protected function _messages_settings_metaboxes()
3592
+	{
3593
+		$this->_set_m_mt_settings();
3594
+		$m_boxes         = $mt_boxes = [];
3595
+		$m_template_args = $mt_template_args = [];
3596
+
3597
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3598
+
3599
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3600
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3601
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3602
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3603
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3604
+
3605
+				// messenger meta boxes
3606
+				$active         = $selected_messenger === $messenger;
3607
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3609
+					: '';
3610
+
3611
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
+					esc_html__('%s Settings', 'event_espresso'),
3613
+					$tab_array['label']
3614
+				);
3615
+
3616
+				$m_template_args[ $messenger . '_a_box' ] = [
3617
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618
+					'inactive_message_types' => isset(
3619
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
+					)
3621
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
+						: '',
3623
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624
+					'hidden'                 => $active ? '' : ' hidden',
3625
+					'hide_on_message'        => $hide_on_message,
3626
+					'messenger'              => $messenger,
3627
+					'active'                 => $active,
3628
+				];
3629
+
3630
+				// message type meta boxes
3631
+				// (which is really just the inactive container for each messenger
3632
+				// showing inactive message types for that messenger)
3633
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
+				$mt_template_args[ $messenger . '_i_box' ] = [
3635
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636
+					'inactive_message_types' => isset(
3637
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
+					)
3639
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
+						: '',
3641
+					'hidden'                 => $active ? '' : ' hidden',
3642
+					'hide_on_message'        => $hide_on_message,
3643
+					'hide_off_message'       => $hide_off_message,
3644
+					'messenger'              => $messenger,
3645
+					'active'                 => $active,
3646
+				];
3647
+			}
3648
+		}
3649
+
3650
+
3651
+		// register messenger metaboxes
3652
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
+		foreach ($m_boxes as $box => $label) {
3654
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
+			$msgr          = str_replace('_a_box', '', $box);
3656
+			add_meta_box(
3657
+				'espresso_' . $msgr . '_settings',
3658
+				$label,
3659
+				function ($post, $metabox) {
3660
+					EEH_Template::display_template(
3661
+						$metabox['args']['template_path'],
3662
+						$metabox['args']['template_args']
3663
+					);
3664
+				},
3665
+				$this->_current_screen->id,
3666
+				'normal',
3667
+				'high',
3668
+				$callback_args
3669
+			);
3670
+		}
3671
+
3672
+		// register message type metaboxes
3673
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
+		foreach ($mt_boxes as $box => $label) {
3675
+			$callback_args = [
3676
+				'template_path' => $mt_template_path,
3677
+				'template_args' => $mt_template_args[ $box ],
3678
+			];
3679
+			$mt            = str_replace('_i_box', '', $box);
3680
+			add_meta_box(
3681
+				'espresso_' . $mt . '_inactive_mts',
3682
+				$label,
3683
+				function ($post, $metabox) {
3684
+					EEH_Template::display_template(
3685
+						$metabox['args']['template_path'],
3686
+						$metabox['args']['template_args']
3687
+					);
3688
+				},
3689
+				$this->_current_screen->id,
3690
+				'side',
3691
+				'high',
3692
+				$callback_args
3693
+			);
3694
+		}
3695
+
3696
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3697
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3698
+		if (is_main_site()) {
3699
+			add_meta_box(
3700
+				'espresso_global_message_settings',
3701
+				esc_html__('Global Message Settings', 'event_espresso'),
3702
+				[$this, 'global_messages_settings_metabox_content'],
3703
+				$this->_current_screen->id,
3704
+				'normal',
3705
+				'low',
3706
+				[]
3707
+			);
3708
+		}
3709
+	}
3710
+
3711
+
3712
+	/**
3713
+	 *  This generates the content for the global messages settings metabox.
3714
+	 *
3715
+	 * @return void
3716
+	 * @throws EE_Error
3717
+	 * @throws InvalidArgumentException
3718
+	 * @throws ReflectionException
3719
+	 * @throws InvalidDataTypeException
3720
+	 * @throws InvalidInterfaceException
3721
+	 */
3722
+	public function global_messages_settings_metabox_content()
3723
+	{
3724
+		$form = $this->_generate_global_settings_form();
3725
+		echo wp_kses(
3726
+			$form->form_open(
3727
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3728
+				'POST'
3729
+			),
3730
+			AllowedTags::getWithFormTags()
3731
+		);
3732
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3733
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3734
+	}
3735
+
3736
+
3737
+	/**
3738
+	 * This generates and returns the form object for the global messages settings.
3739
+	 *
3740
+	 * @return EE_Form_Section_Proper
3741
+	 * @throws EE_Error
3742
+	 * @throws InvalidArgumentException
3743
+	 * @throws ReflectionException
3744
+	 * @throws InvalidDataTypeException
3745
+	 * @throws InvalidInterfaceException
3746
+	 */
3747
+	protected function _generate_global_settings_form()
3748
+	{
3749
+		/** @var EE_Network_Core_Config $network_config */
3750
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3751
+
3752
+		return new EE_Form_Section_Proper(
3753
+			[
3754
+				'name'            => 'global_messages_settings',
3755
+				'html_id'         => 'global_messages_settings',
3756
+				'html_class'      => 'form-table',
3757
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3758
+				'subsections'     => apply_filters(
3759
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3760
+					[
3761
+						'do_messages_on_same_request' => new EE_Select_Input(
3762
+							[
3763
+								true  => esc_html__('On the same request', 'event_espresso'),
3764
+								false => esc_html__('On a separate request', 'event_espresso'),
3765
+							],
3766
+							[
3767
+								'default'         => $network_config->do_messages_on_same_request,
3768
+								'html_label_text' => esc_html__(
3769
+									'Generate and send all messages:',
3770
+									'event_espresso'
3771
+								),
3772
+								'html_help_text'  => esc_html__(
3773
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3774
+									'event_espresso'
3775
+								),
3776
+							]
3777
+						),
3778
+						'delete_threshold'            => new EE_Select_Input(
3779
+							[
3780
+								0  => esc_html__('Forever', 'event_espresso'),
3781
+								3  => esc_html__('3 Months', 'event_espresso'),
3782
+								6  => esc_html__('6 Months', 'event_espresso'),
3783
+								9  => esc_html__('9 Months', 'event_espresso'),
3784
+								12 => esc_html__('12 Months', 'event_espresso'),
3785
+								24 => esc_html__('24 Months', 'event_espresso'),
3786
+								36 => esc_html__('36 Months', 'event_espresso'),
3787
+							],
3788
+							[
3789
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3790
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3791
+								'html_help_text'  => esc_html__(
3792
+									'You can control how long a record of processed messages is kept via this option.',
3793
+									'event_espresso'
3794
+								),
3795
+							]
3796
+						),
3797
+						'update_settings'             => new EE_Submit_Input(
3798
+							[
3799
+								'default'         => esc_html__('Update', 'event_espresso'),
3800
+								'html_label_text' => '',
3801
+							]
3802
+						),
3803
+					]
3804
+				),
3805
+			]
3806
+		);
3807
+	}
3808
+
3809
+
3810
+	/**
3811
+	 * This handles updating the global settings set on the admin page.
3812
+	 *
3813
+	 * @throws EE_Error
3814
+	 * @throws InvalidDataTypeException
3815
+	 * @throws InvalidInterfaceException
3816
+	 * @throws InvalidArgumentException
3817
+	 * @throws ReflectionException
3818
+	 */
3819
+	protected function _update_global_settings()
3820
+	{
3821
+		/** @var EE_Network_Core_Config $network_config */
3822
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3823
+		$messages_config = EE_Registry::instance()->CFG->messages;
3824
+		$form            = $this->_generate_global_settings_form();
3825
+		if ($form->was_submitted()) {
3826
+			$form->receive_form_submission();
3827
+			if ($form->is_valid()) {
3828
+				$valid_data = $form->valid_data();
3829
+				foreach ($valid_data as $property => $value) {
3830
+					$setter = 'set_' . $property;
3831
+					if (method_exists($network_config, $setter)) {
3832
+						$network_config->{$setter}($value);
3833
+					} elseif (
3834
+						property_exists($network_config, $property)
3835
+						&& $network_config->{$property} !== $value
3836
+					) {
3837
+						$network_config->{$property} = $value;
3838
+					} elseif (
3839
+						property_exists($messages_config, $property)
3840
+						&& $messages_config->{$property} !== $value
3841
+					) {
3842
+						$messages_config->{$property} = $value;
3843
+					}
3844
+				}
3845
+				// only update if the form submission was valid!
3846
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3847
+				EE_Registry::instance()->CFG->update_espresso_config();
3848
+				EE_Error::overwrite_success();
3849
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3850
+			}
3851
+		}
3852
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3853
+	}
3854
+
3855
+
3856
+	/**
3857
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3858
+	 *
3859
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3860
+	 * @return string html formatted tabs
3861
+	 * @throws DomainException
3862
+	 */
3863
+	protected function _get_mt_tabs($tab_array)
3864
+	{
3865
+		$tab_array = (array) $tab_array;
3866
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3867
+		$tabs      = '';
3868
+
3869
+		foreach ($tab_array as $tab) {
3870
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3871
+		}
3872
+
3873
+		return $tabs;
3874
+	}
3875
+
3876
+
3877
+	/**
3878
+	 * This prepares the content of the messenger meta box admin settings
3879
+	 *
3880
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3881
+	 * @return string html formatted content
3882
+	 * @throws DomainException
3883
+	 */
3884
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3885
+	{
3886
+
3887
+		$fields                                         = $messenger->get_admin_settings_fields();
3888
+		$settings_template_args['template_form_fields'] = '';
3889
+
3890
+		// is $messenger active?
3891
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892
+
3893
+
3894
+		if (! empty($fields)) {
3895
+			$existing_settings = $messenger->get_existing_admin_settings();
3896
+
3897
+			foreach ($fields as $fldname => $fldprops) {
3898
+				$field_id                         = $messenger->name . '-' . $fldname;
3899
+				$template_form_field[ $field_id ] = [
3900
+					'name'       => 'messenger_settings[' . $field_id . ']',
3901
+					'label'      => $fldprops['label'],
3902
+					'input'      => $fldprops['field_type'],
3903
+					'type'       => $fldprops['value_type'],
3904
+					'required'   => $fldprops['required'],
3905
+					'validation' => $fldprops['validation'],
3906
+					'value'      => isset($existing_settings[ $field_id ])
3907
+						? $existing_settings[ $field_id ]
3908
+						: $fldprops['default'],
3909
+					'css_class'  => '',
3910
+					'format'     => $fldprops['format'],
3911
+				];
3912
+			}
3913
+
3914
+
3915
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3916
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3917
+				: '';
3918
+		}
3919
+
3920
+		// we also need some hidden fields
3921
+		$settings_template_args['hidden_fields'] = [
3922
+			'messenger_settings[messenger]' . $messenger->name => [
3923
+				'type'  => 'hidden',
3924
+				'value' => $messenger->name,
3925
+			],
3926
+			'type' . $messenger->name                          => [
3927
+				'type'  => 'hidden',
3928
+				'value' => 'messenger',
3929
+			],
3930
+		];
3931
+
3932
+		// make sure any active message types that are existing are included in the hidden fields
3933
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
+					'type'  => 'hidden',
3937
+					'value' => $mt,
3938
+				];
3939
+			}
3940
+		}
3941
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3942
+			$settings_template_args['hidden_fields'],
3943
+			'array'
3944
+		);
3945
+		$active                                  =
3946
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3947
+
3948
+		$settings_template_args['messenger']           = $messenger->name;
3949
+		$settings_template_args['description']         = $messenger->description;
3950
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3951
+
3952
+
3953
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3954
+			$messenger->name
3955
+		)
3956
+			? $settings_template_args['show_hide_edit_form']
3957
+			: ' hidden';
3958
+
3959
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3960
+			? ' hidden'
3961
+			: $settings_template_args['show_hide_edit_form'];
3962
+
3963
+
3964
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3966
+		$settings_template_args['on_off_status'] = $active;
3967
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3968
+		return EEH_Template::display_template(
3969
+			$template,
3970
+			$settings_template_args,
3971
+			true
3972
+		);
3973
+	}
3974
+
3975
+
3976
+	/**
3977
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3978
+	 *
3979
+	 * @throws DomainException
3980
+	 * @throws EE_Error
3981
+	 * @throws InvalidDataTypeException
3982
+	 * @throws InvalidInterfaceException
3983
+	 * @throws InvalidArgumentException
3984
+	 * @throws ReflectionException
3985
+	 */
3986
+	public function activate_messenger_toggle()
3987
+	{
3988
+		$success = true;
3989
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3990
+		// let's check that we have required data
3991
+
3992
+		if (! $this->_active_messenger_name) {
3993
+			EE_Error::add_error(
3994
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995
+				__FILE__,
3996
+				__FUNCTION__,
3997
+				__LINE__
3998
+			);
3999
+			$success = false;
4000
+		}
4001
+
4002
+		// do a nonce check here since we're not arriving via a normal route
4003
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4004
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4005
+
4006
+		$this->_verify_nonce($nonce, $nonce_ref);
4007
+
4008
+
4009
+		$status = $this->request->getRequestParam('status');
4010
+		if (! $status) {
4011
+			EE_Error::add_error(
4012
+				esc_html__(
4013
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4014
+					'event_espresso'
4015
+				),
4016
+				__FILE__,
4017
+				__FUNCTION__,
4018
+				__LINE__
4019
+			);
4020
+			$success = false;
4021
+		}
4022
+
4023
+		// do check to verify we have a valid status.
4024
+		if ($status !== 'off' && $status !== 'on') {
4025
+			EE_Error::add_error(
4026
+				sprintf(
4027
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4028
+					$status
4029
+				),
4030
+				__FILE__,
4031
+				__FUNCTION__,
4032
+				__LINE__
4033
+			);
4034
+			$success = false;
4035
+		}
4036
+
4037
+		if ($success) {
4038
+			// made it here?  Stop dawdling then!!
4039
+			$success = $status === 'off'
4040
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4041
+				: $this->_activate_messenger($this->_active_messenger_name);
4042
+		}
4043
+
4044
+		$this->_template_args['success'] = $success;
4045
+
4046
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4047
+		$this->_return_json();
4048
+	}
4049
+
4050
+
4051
+	/**
4052
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4053
+	 *
4054
+	 * @throws DomainException
4055
+	 * @throws EE_Error
4056
+	 * @throws ReflectionException
4057
+	 * @throws InvalidDataTypeException
4058
+	 * @throws InvalidInterfaceException
4059
+	 * @throws InvalidArgumentException
4060
+	 */
4061
+	public function activate_mt_toggle()
4062
+	{
4063
+		$success = true;
4064
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4065
+
4066
+		// let's make sure we have the necessary data
4067
+		if (! $this->_active_message_type_name) {
4068
+			EE_Error::add_error(
4069
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070
+				__FILE__,
4071
+				__FUNCTION__,
4072
+				__LINE__
4073
+			);
4074
+			$success = false;
4075
+		}
4076
+
4077
+		if (! $this->_active_messenger_name) {
4078
+			EE_Error::add_error(
4079
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080
+				__FILE__,
4081
+				__FUNCTION__,
4082
+				__LINE__
4083
+			);
4084
+			$success = false;
4085
+		}
4086
+
4087
+		$status = $this->request->getRequestParam('status');
4088
+		if (! $status) {
4089
+			EE_Error::add_error(
4090
+				esc_html__(
4091
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4092
+					'event_espresso'
4093
+				),
4094
+				__FILE__,
4095
+				__FUNCTION__,
4096
+				__LINE__
4097
+			);
4098
+			$success = false;
4099
+		}
4100
+
4101
+
4102
+		// do check to verify we have a valid status.
4103
+		if ($status !== 'activate' && $status !== 'deactivate') {
4104
+			EE_Error::add_error(
4105
+				sprintf(
4106
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4107
+					$status
4108
+				),
4109
+				__FILE__,
4110
+				__FUNCTION__,
4111
+				__LINE__
4112
+			);
4113
+			$success = false;
4114
+		}
4115
+
4116
+
4117
+		// do a nonce check here since we're not arriving via a normal route
4118
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4119
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4120
+
4121
+		if ($success) {
4122
+			// made it here? um, what are you waiting for then?
4123
+			$success = $status === 'deactivate'
4124
+				? $this->_deactivate_message_type_for_messenger(
4125
+					$this->_active_messenger_name,
4126
+					$this->_active_message_type_name
4127
+				)
4128
+				: $this->_activate_message_type_for_messenger(
4129
+					$this->_active_messenger_name,
4130
+					$this->_active_message_type_name
4131
+				);
4132
+		}
4133
+
4134
+		$this->_template_args['success'] = $success;
4135
+		$this->_return_json();
4136
+	}
4137
+
4138
+
4139
+	/**
4140
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4141
+	 *
4142
+	 * @param string $messenger_name The name of the messenger being activated
4143
+	 * @return bool
4144
+	 * @throws DomainException
4145
+	 * @throws EE_Error
4146
+	 * @throws InvalidArgumentException
4147
+	 * @throws ReflectionException
4148
+	 * @throws InvalidDataTypeException
4149
+	 * @throws InvalidInterfaceException
4150
+	 */
4151
+	protected function _activate_messenger($messenger_name)
4152
+	{
4153
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4154
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4155
+			? $active_messenger->get_default_message_types()
4156
+			: [];
4157
+
4158
+		// ensure is active
4159
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4160
+
4161
+		// set response_data for reload
4162
+		foreach ($message_types_to_activate as $message_type_name) {
4163
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4164
+			if (
4165
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4166
+					$messenger_name,
4167
+					$message_type_name
4168
+				)
4169
+				&& $message_type instanceof EE_message_type
4170
+			) {
4171
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4172
+				if ($message_type->get_admin_settings_fields()) {
4173
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4174
+				}
4175
+			}
4176
+		}
4177
+
4178
+		// add success message for activating messenger
4179
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4180
+	}
4181
+
4182
+
4183
+	/**
4184
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4185
+	 *
4186
+	 * @param string $messenger_name The name of the messenger being activated
4187
+	 * @return bool
4188
+	 * @throws DomainException
4189
+	 * @throws EE_Error
4190
+	 * @throws InvalidArgumentException
4191
+	 * @throws ReflectionException
4192
+	 * @throws InvalidDataTypeException
4193
+	 * @throws InvalidInterfaceException
4194
+	 */
4195
+	protected function _deactivate_messenger($messenger_name)
4196
+	{
4197
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4198
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4199
+
4200
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4201
+	}
4202
+
4203
+
4204
+	/**
4205
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4206
+	 *
4207
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4208
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4209
+	 * @return bool
4210
+	 * @throws DomainException
4211
+	 * @throws EE_Error
4212
+	 * @throws InvalidArgumentException
4213
+	 * @throws ReflectionException
4214
+	 * @throws InvalidDataTypeException
4215
+	 * @throws InvalidInterfaceException
4216
+	 */
4217
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4218
+	{
4219
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4220
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4221
+
4222
+		// ensure is active
4223
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4224
+
4225
+		// set response for load
4226
+		if (
4227
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4228
+				$messenger_name,
4229
+				$message_type_name
4230
+			)
4231
+		) {
4232
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4233
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4234
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4235
+			}
4236
+		}
4237
+
4238
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4239
+			$active_messenger,
4240
+			$message_type_to_activate
4241
+		);
4242
+	}
4243
+
4244
+
4245
+	/**
4246
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4247
+	 *
4248
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4249
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4250
+	 * @return bool
4251
+	 * @throws DomainException
4252
+	 * @throws EE_Error
4253
+	 * @throws InvalidArgumentException
4254
+	 * @throws ReflectionException
4255
+	 * @throws InvalidDataTypeException
4256
+	 * @throws InvalidInterfaceException
4257
+	 */
4258
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4259
+	{
4260
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4261
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4262
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4263
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4264
+
4265
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4266
+			$active_messenger,
4267
+			$message_type_to_deactivate
4268
+		);
4269
+	}
4270
+
4271
+
4272
+	/**
4273
+	 * This just initializes the defaults for activating messenger and message type responses.
4274
+	 */
4275
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4276
+	{
4277
+		$this->_template_args['data']['active_mts'] = [];
4278
+		$this->_template_args['data']['mt_reload']  = [];
4279
+	}
4280
+
4281
+
4282
+	/**
4283
+	 * Setup appropriate response for activating a messenger and/or message types
4284
+	 *
4285
+	 * @param EE_messenger         $messenger
4286
+	 * @param EE_message_type|null $message_type
4287
+	 * @return bool
4288
+	 * @throws DomainException
4289
+	 * @throws EE_Error
4290
+	 * @throws InvalidArgumentException
4291
+	 * @throws ReflectionException
4292
+	 * @throws InvalidDataTypeException
4293
+	 * @throws InvalidInterfaceException
4294
+	 */
4295
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4296
+		$messenger,
4297
+		EE_Message_Type $message_type = null
4298
+	) {
4299
+		// if $messenger isn't a valid messenger object then get out.
4300
+		if (! $messenger instanceof EE_Messenger) {
4301
+			EE_Error::add_error(
4302
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303
+				__FILE__,
4304
+				__FUNCTION__,
4305
+				__LINE__
4306
+			);
4307
+			return false;
4308
+		}
4309
+		// activated
4310
+		if ($this->_template_args['data']['active_mts']) {
4311
+			EE_Error::overwrite_success();
4312
+			// activated a message type with the messenger
4313
+			if ($message_type instanceof EE_message_type) {
4314
+				EE_Error::add_success(
4315
+					sprintf(
4316
+						esc_html__(
4317
+							'%s message type has been successfully activated with the %s messenger',
4318
+							'event_espresso'
4319
+						),
4320
+						ucwords($message_type->label['singular']),
4321
+						ucwords($messenger->label['singular'])
4322
+					)
4323
+				);
4324
+
4325
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4326
+				if ($message_type->name === 'invoice') {
4327
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4328
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4329
+					if ($pm instanceof EE_Payment_Method) {
4330
+						EE_Error::add_attention(
4331
+							esc_html__(
4332
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4333
+								'event_espresso'
4334
+							)
4335
+						);
4336
+					}
4337
+				}
4338
+				// just toggles the entire messenger
4339
+			} else {
4340
+				EE_Error::add_success(
4341
+					sprintf(
4342
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4343
+						ucwords($messenger->label['singular'])
4344
+					)
4345
+				);
4346
+			}
4347
+
4348
+			return true;
4349
+
4350
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4351
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352
+			// in which case we just give a success message for the messenger being successfully activated.
4353
+		} else {
4354
+			if (! $messenger->get_default_message_types()) {
4355
+				// messenger doesn't have any default message types so still a success.
4356
+				EE_Error::add_success(
4357
+					sprintf(
4358
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4359
+						ucwords($messenger->label['singular'])
4360
+					)
4361
+				);
4362
+
4363
+				return true;
4364
+			} else {
4365
+				EE_Error::add_error(
4366
+					$message_type instanceof EE_message_type
4367
+					? sprintf(
4368
+						esc_html__(
4369
+							'%s message type was not successfully activated with the %s messenger',
4370
+							'event_espresso'
4371
+						),
4372
+						ucwords($message_type->label['singular']),
4373
+						ucwords($messenger->label['singular'])
4374
+					)
4375
+					: sprintf(
4376
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4377
+						ucwords($messenger->label['singular'])
4378
+					),
4379
+					__FILE__,
4380
+					__FUNCTION__,
4381
+					__LINE__
4382
+				);
4383
+
4384
+				return false;
4385
+			}
4386
+		}
4387
+	}
4388
+
4389
+
4390
+	/**
4391
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4392
+	 *
4393
+	 * @param EE_messenger         $messenger
4394
+	 * @param EE_message_type|null $message_type
4395
+	 * @return bool
4396
+	 * @throws DomainException
4397
+	 * @throws EE_Error
4398
+	 * @throws InvalidArgumentException
4399
+	 * @throws ReflectionException
4400
+	 * @throws InvalidDataTypeException
4401
+	 * @throws InvalidInterfaceException
4402
+	 */
4403
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4404
+		$messenger,
4405
+		EE_message_type $message_type = null
4406
+	) {
4407
+		EE_Error::overwrite_success();
4408
+
4409
+		// if $messenger isn't a valid messenger object then get out.
4410
+		if (! $messenger instanceof EE_Messenger) {
4411
+			EE_Error::add_error(
4412
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413
+				__FILE__,
4414
+				__FUNCTION__,
4415
+				__LINE__
4416
+			);
4417
+
4418
+			return false;
4419
+		}
4420
+
4421
+		if ($message_type instanceof EE_message_type) {
4422
+			$message_type_name = $message_type->name;
4423
+			EE_Error::add_success(
4424
+				sprintf(
4425
+					esc_html__(
4426
+						'%s message type has been successfully deactivated for the %s messenger.',
4427
+						'event_espresso'
4428
+					),
4429
+					ucwords($message_type->label['singular']),
4430
+					ucwords($messenger->label['singular'])
4431
+				)
4432
+			);
4433
+		} else {
4434
+			$message_type_name = '';
4435
+			EE_Error::add_success(
4436
+				sprintf(
4437
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4438
+					ucwords($messenger->label['singular'])
4439
+				)
4440
+			);
4441
+		}
4442
+
4443
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4444
+		if (
4445
+			$messenger->name === 'html'
4446
+			&& (
4447
+				is_null($message_type)
4448
+				|| $message_type_name === 'invoice'
4449
+			)
4450
+		) {
4451
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4452
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4453
+			if ($count_updated > 0) {
4454
+				$msg = $message_type_name === 'invoice'
4455
+					? esc_html__(
4456
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4457
+						'event_espresso'
4458
+					)
4459
+					: esc_html__(
4460
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4461
+						'event_espresso'
4462
+					);
4463
+				EE_Error::add_attention($msg);
4464
+			}
4465
+		}
4466
+
4467
+		return true;
4468
+	}
4469
+
4470
+
4471
+	/**
4472
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4473
+	 *
4474
+	 * @throws DomainException
4475
+	 * @throws EE_Error
4476
+	 * @throws EE_Error
4477
+	 */
4478
+	public function update_mt_form()
4479
+	{
4480
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481
+			EE_Error::add_error(
4482
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483
+				__FILE__,
4484
+				__FUNCTION__,
4485
+				__LINE__
4486
+			);
4487
+			$this->_return_json();
4488
+		}
4489
+
4490
+		$message_types = $this->get_installed_message_types();
4491
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4492
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494
+
4495
+		$this->_template_args['success'] = true;
4496
+		$this->_template_args['content'] = $content;
4497
+		$this->_return_json();
4498
+	}
4499
+
4500
+
4501
+	/**
4502
+	 * this handles saving the settings for a messenger or message type
4503
+	 *
4504
+	 * @throws EE_Error
4505
+	 * @throws EE_Error
4506
+	 */
4507
+	public function save_settings()
4508
+	{
4509
+		$type = $this->request->getRequestParam('type');
4510
+		if (! $type) {
4511
+			EE_Error::add_error(
4512
+				esc_html__(
4513
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4514
+					'event_espresso'
4515
+				),
4516
+				__FILE__,
4517
+				__FUNCTION__,
4518
+				__LINE__
4519
+			);
4520
+			$this->_template_args['error'] = true;
4521
+			$this->_return_json();
4522
+		}
4523
+
4524
+
4525
+		if ($type === 'messenger') {
4526
+			// this should be an array.
4527
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4528
+			$messenger = $settings['messenger'];
4529
+			// remove messenger and message_types from settings array
4530
+			unset($settings['messenger'], $settings['message_types']);
4531
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4532
+		} elseif ($type === 'message_type') {
4533
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4534
+			$messenger    = $settings['messenger'];
4535
+			$message_type = $settings['message_type'];
4536
+			// remove messenger and message_types from settings array
4537
+			unset($settings['messenger'], $settings['message_types']);
4538
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4539
+		}
4540
+
4541
+		// okay we should have the data all setup.  Now we just update!
4542
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4543
+
4544
+		if ($success) {
4545
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4546
+		} else {
4547
+			EE_Error::add_error(
4548
+				esc_html__('Settings did not get updated', 'event_espresso'),
4549
+				__FILE__,
4550
+				__FUNCTION__,
4551
+				__LINE__
4552
+			);
4553
+		}
4554
+
4555
+		$this->_template_args['success'] = $success;
4556
+		$this->_return_json();
4557
+	}
4558
+
4559
+
4560
+
4561
+
4562
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4563
+
4564
+
4565
+	/**
4566
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4567
+	 * However, this does not send immediately, it just queues for sending.
4568
+	 *
4569
+	 * @throws EE_Error
4570
+	 * @throws InvalidDataTypeException
4571
+	 * @throws InvalidInterfaceException
4572
+	 * @throws InvalidArgumentException
4573
+	 * @throws ReflectionException
4574
+	 * @since 4.9.0
4575
+	 */
4576
+	protected function _generate_now()
4577
+	{
4578
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4579
+		$this->_redirect_after_action(false, '', '', [], true);
4580
+	}
4581
+
4582
+
4583
+	/**
4584
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4585
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4586
+	 *
4587
+	 * @throws EE_Error
4588
+	 * @throws InvalidDataTypeException
4589
+	 * @throws InvalidInterfaceException
4590
+	 * @throws InvalidArgumentException
4591
+	 * @throws ReflectionException
4592
+	 * @since 4.9.0
4593
+	 */
4594
+	protected function _generate_and_send_now()
4595
+	{
4596
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4597
+		$this->_redirect_after_action(false, '', '', [], true);
4598
+	}
4599
+
4600
+
4601
+	/**
4602
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4603
+	 *
4604
+	 * @throws EE_Error
4605
+	 * @throws InvalidDataTypeException
4606
+	 * @throws InvalidInterfaceException
4607
+	 * @throws InvalidArgumentException
4608
+	 * @throws ReflectionException
4609
+	 * @since 4.9.0
4610
+	 */
4611
+	protected function _queue_for_resending()
4612
+	{
4613
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4614
+		$this->_redirect_after_action(false, '', '', [], true);
4615
+	}
4616
+
4617
+
4618
+	/**
4619
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4620
+	 *
4621
+	 * @throws EE_Error
4622
+	 * @throws InvalidDataTypeException
4623
+	 * @throws InvalidInterfaceException
4624
+	 * @throws InvalidArgumentException
4625
+	 * @throws ReflectionException
4626
+	 * @since 4.9.0
4627
+	 */
4628
+	protected function _send_now()
4629
+	{
4630
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4631
+		$this->_redirect_after_action(false, '', '', [], true);
4632
+	}
4633
+
4634
+
4635
+	/**
4636
+	 * Deletes EE_messages for IDs in the request.
4637
+	 *
4638
+	 * @throws EE_Error
4639
+	 * @throws InvalidDataTypeException
4640
+	 * @throws InvalidInterfaceException
4641
+	 * @throws InvalidArgumentException
4642
+	 * @since 4.9.0
4643
+	 */
4644
+	protected function _delete_ee_messages()
4645
+	{
4646
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4647
+		$deleted_count = 0;
4648
+		foreach ($MSG_IDs as $MSG_ID) {
4649
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4650
+				$deleted_count++;
4651
+			}
4652
+		}
4653
+		if ($deleted_count) {
4654
+			EE_Error::add_success(
4655
+				esc_html(
4656
+					_n(
4657
+						'Message successfully deleted',
4658
+						'Messages successfully deleted',
4659
+						$deleted_count,
4660
+						'event_espresso'
4661
+					)
4662
+				)
4663
+			);
4664
+		} else {
4665
+			EE_Error::add_error(
4666
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4667
+				__FILE__,
4668
+				__FUNCTION__,
4669
+				__LINE__
4670
+			);
4671
+		}
4672
+		$this->_redirect_after_action(false, '', '', [], true);
4673
+	}
4674
+
4675
+
4676
+	/**
4677
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4678
+	 *
4679
+	 * @return array
4680
+	 * @since 4.9.0
4681
+	 */
4682
+	protected function _get_msg_ids_from_request()
4683
+	{
4684
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4685
+		if (empty($MSG_IDs)) {
4686
+			return [];
4687
+		}
4688
+		// if 'MSG_ID' was just a single ID (not an array)
4689
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4690
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4691
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4692
+			? $MSG_IDs
4693
+			: array_keys($MSG_IDs);
4694
+	}
4695 4695
 }
Please login to merge, or discard this patch.
Spacing   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      */
116 116
     public function getMsgModel()
117 117
     {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
118
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
119 119
             $this->MSG_MODEL = EEM_Message::instance();
120 120
         }
121 121
         return $this->MSG_MODEL;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function getMtpModel()
130 130
     {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
132 132
             $this->MTP_MODEL = EEM_Message_Template::instance();
133 133
         }
134 134
         return $this->MTP_MODEL;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function getMtgModel()
143 143
     {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145 145
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146 146
         }
147 147
         return $this->MTG_MODEL;
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
         $i = 1;
212 212
         foreach ($active_messengers as $active_messenger) {
213 213
             if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
214
+                $m_values[$i]['id']   = $active_messenger->messenger();
215
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
216 216
                 $i++;
217 217
             }
218 218
         }
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
         $i               = 1;
249 249
         foreach ($active_messages as $active_message) {
250 250
             if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
251
+                $mt_values[$i]['id']   = $active_message->message_type();
252
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
253 253
                 $i++;
254 254
             }
255 255
         }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 if ($message_type instanceof EE_message_type) {
289 289
                     $message_type_contexts = $message_type->get_contexts();
290 290
                     foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
291
+                        $contexts[$context] = $context_details['label'];
292 292
                     }
293 293
                 }
294 294
             }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322 322
             $messenger_options
323 323
         );
324
-        $input             = new EE_Select_Input(
324
+        $input = new EE_Select_Input(
325 325
             $messenger_options,
326 326
             [
327 327
                 'html_name'  => 'ee_messenger_filter_by',
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359 359
             $message_type_options
360 360
         );
361
-        $input                = new EE_Select_Input(
361
+        $input = new EE_Select_Input(
362 362
             $message_type_options,
363 363
             [
364 364
                 'html_name'  => 'ee_message_type_filter_by',
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396 396
             $context_options
397 397
         );
398
-        $input           = new EE_Select_Input(
398
+        $input = new EE_Select_Input(
399 399
             $context_options,
400 400
             [
401 401
                 'html_name'  => 'ee_context_filter_by',
@@ -769,53 +769,53 @@  discard block
 block discarded – undo
769 769
 
770 770
     public function messages_help_tab()
771 771
     {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
773 773
     }
774 774
 
775 775
 
776 776
     public function messengers_help_tab()
777 777
     {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
779 779
     }
780 780
 
781 781
 
782 782
     public function message_types_help_tab()
783 783
     {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
785 785
     }
786 786
 
787 787
 
788 788
     public function messages_overview_help_tab()
789 789
     {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
791 791
     }
792 792
 
793 793
 
794 794
     public function message_templates_help_tab()
795 795
     {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
797 797
     }
798 798
 
799 799
 
800 800
     public function edit_message_template_help_tab()
801 801
     {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
803 803
                         . esc_attr__('Editor Title', 'event_espresso')
804 804
                         . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
806 806
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
807 807
                         . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
809 809
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
810 810
                         . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
812 812
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
813 813
                         . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
815 815
                         . esc_attr__('Publish Metabox', 'event_espresso')
816 816
                         . '" />';
817 817
         EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
819 819
             $args
820 820
         );
821 821
     }
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
         $this->_set_shortcodes();
831 831
         $args['shortcodes'] = $this->_shortcodes;
832 832
         EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
834 834
             $args
835 835
         );
836 836
     }
@@ -838,16 +838,16 @@  discard block
 block discarded – undo
838 838
 
839 839
     public function preview_message_help_tab()
840 840
     {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
842 842
     }
843 843
 
844 844
 
845 845
     public function settings_help_tab()
846 846
     {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
847
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
848
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
849
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
850
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
851 851
         $args['img3'] = '<div class="switch">'
852 852
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853 853
                         . ' type="checkbox" checked>'
@@ -858,25 +858,25 @@  discard block
 block discarded – undo
858 858
                         . ' type="checkbox">'
859 859
                         . '<label for="ee-on-off-toggle-on"></label>'
860 860
                         . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
862 862
     }
863 863
 
864 864
 
865 865
     public function load_scripts_styles()
866 866
     {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868 868
         wp_enqueue_style('espresso_ee_msg');
869 869
 
870 870
         wp_register_script(
871 871
             'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
873 873
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
874 874
             EVENT_ESPRESSO_VERSION,
875 875
             true
876 876
         );
877 877
         wp_register_script(
878 878
             'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
880 880
             ['ee-dialog'],
881 881
             EVENT_ESPRESSO_VERSION
882 882
         );
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 
920 920
         $this->_set_shortcodes();
921 921
 
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
923 923
             esc_html__(
924 924
                 'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925 925
                 'event_espresso'
@@ -931,14 +931,14 @@  discard block
 block discarded – undo
931 931
             'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932 932
             'event_espresso'
933 933
         );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
935 935
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936 936
             'event_espresso'
937 937
         );
938 938
 
939 939
         wp_register_script(
940 940
             'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
942 942
             ['jquery'],
943 943
             EVENT_ESPRESSO_VERSION
944 944
         );
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
     {
982 982
         wp_register_style(
983 983
             'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
985 985
             [],
986 986
             EVENT_ESPRESSO_VERSION
987 987
         );
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
             }
1068 1068
             $status_bulk_actions = $common_bulk_actions;
1069 1069
             // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1070
+            if ( ! empty($status_bulk_actions)) {
1071 1071
                 switch ($status) {
1072 1072
                     case EEM_Message::status_idle:
1073 1073
                     case EEM_Message::status_resend:
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
                 continue;
1097 1097
             }
1098 1098
 
1099
-            $this->_views[ strtolower($status) ] = [
1099
+            $this->_views[strtolower($status)] = [
1100 1100
                 'slug'        => strtolower($status),
1101 1101
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102 1102
                 'count'       => 0,
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
             if ($action_item === 'see_notifications_for') {
1146 1146
                 continue;
1147 1147
             }
1148
-            $action_items[ $action_item ] = [
1148
+            $action_items[$action_item] = [
1149 1149
                 'class' => $action_details['css_class'],
1150 1150
                 'desc'  => $action_details['label'],
1151 1151
             ];
@@ -1154,37 +1154,37 @@  discard block
 block discarded – undo
1154 1154
         /** @var array $status_items status legend setup */
1155 1155
         $status_items = [
1156 1156
             'sent_status'                => [
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1157
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1158 1158
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159 1159
             ],
1160 1160
             'idle_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1161
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1162 1162
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163 1163
             ],
1164 1164
             'failed_status'              => [
1165
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1165
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1166 1166
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167 1167
             ],
1168 1168
             'messenger_executing_status' => [
1169
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1169
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1170 1170
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171 1171
             ],
1172 1172
             'resend_status'              => [
1173
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1173
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1174 1174
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175 1175
             ],
1176 1176
             'incomplete_status'          => [
1177
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1177
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1178 1178
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179 1179
             ],
1180 1180
             'retry_status'               => [
1181
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1181
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1182 1182
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183 1183
             ],
1184 1184
         ];
1185 1185
         if (EEM_Message::debug()) {
1186 1186
             $status_items['debug_only_status'] = [
1187
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1187
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1188 1188
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189 1189
             ];
1190 1190
         }
@@ -1199,11 +1199,11 @@  discard block
 block discarded – undo
1199 1199
     protected function _custom_mtps_preview()
1200 1200
     {
1201 1201
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
-                                                . ' alt="' . esc_attr__(
1202
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1203
+                                                . ' alt="'.esc_attr__(
1204 1204
                                                     'Preview Custom Message Templates screenshot',
1205 1205
                                                     'event_espresso'
1206
-                                                ) . '" />';
1206
+                                                ).'" />';
1207 1207
         $this->_template_args['preview_text'] = '<strong>'
1208 1208
                                                 . esc_html__(
1209 1209
                                                     'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
@@ -1279,7 +1279,7 @@  discard block
 block discarded – undo
1279 1279
         $installed               = [];
1280 1280
 
1281 1281
         foreach ($installed_message_types as $message_type) {
1282
-            $installed[ $message_type->name ] = $message_type;
1282
+            $installed[$message_type->name] = $message_type;
1283 1283
         }
1284 1284
 
1285 1285
         return $installed;
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
         // we need to assemble the title from Various details
1406 1406
         $context_label = sprintf(
1407 1407
             esc_html__('(%s %s)', 'event_espresso'),
1408
-            $c_config[ $context ]['label'],
1408
+            $c_config[$context]['label'],
1409 1409
             ucwords($c_label['label'])
1410 1410
         );
1411 1411
 
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
             $message_template_group->message_type()
1428 1428
         );
1429 1429
 
1430
-        if (! $template_field_structure) {
1430
+        if ( ! $template_field_structure) {
1431 1431
             $template_field_structure = false;
1432 1432
             $template_fields          = esc_html__(
1433 1433
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1441,21 +1441,21 @@  discard block
 block discarded – undo
1441 1441
 
1442 1442
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443 1443
         // will get handled in the "extra" array.
1444
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
-                unset($template_field_structure[ $context ][ $reference_field ]);
1444
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1445
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1446
+                unset($template_field_structure[$context][$reference_field]);
1447 1447
             }
1448 1448
         }
1449 1449
 
1450 1450
         // let's loop through the template_field_structure and actually assemble the input fields!
1451
-        if (! empty($template_field_structure)) {
1452
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1451
+        if ( ! empty($template_field_structure)) {
1452
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1453 1453
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454 1454
                 // the extra array and reset them.
1455 1455
                 if ($template_field === 'extra') {
1456 1456
                     $this->_template_args['is_extra_fields'] = true;
1457 1457
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1458
+                        $message_template = $message_templates[$context][$reference_field];
1459 1459
                         $content          = $message_template instanceof EE_Message_Template
1460 1460
                             ? $message_template->get('MTP_content')
1461 1461
                             : '';
@@ -1464,7 +1464,7 @@  discard block
 block discarded – undo
1464 1464
                             $continue = false;
1465 1465
                             if (isset($extra_array['shortcodes_required'])) {
1466 1466
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1468 1468
                                         $continue = true;
1469 1469
                                     }
1470 1470
                                 }
@@ -1473,53 +1473,53 @@  discard block
 block discarded – undo
1473 1473
                                 }
1474 1474
                             }
1475 1475
 
1476
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1476
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1477 1477
 
1478
-                            $template_form_fields[ $field_id ]         = $extra_array;
1479
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1478
+                            $template_form_fields[$field_id]         = $extra_array;
1479
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1480 1480
                                                                          . $reference_field
1481 1481
                                                                          . '][content]['
1482
-                                                                         . $extra_field . ']';
1483
-                            $css_class                                 = isset($extra_array['css_class'])
1482
+                                                                         . $extra_field.']';
1483
+                            $css_class = isset($extra_array['css_class'])
1484 1484
                                 ? $extra_array['css_class']
1485 1485
                                 : '';
1486 1486
 
1487
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1488 1488
                                                                               && in_array($extra_field, $v_fields, true)
1489 1489
                                                                               && (
1490
-                                                                                  is_array($validators[ $extra_field ])
1491
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1490
+                                                                                  is_array($validators[$extra_field])
1491
+                                                                                  && isset($validators[$extra_field]['msg'])
1492 1492
                                                                               )
1493
-                                ? 'validate-error ' . $css_class
1493
+                                ? 'validate-error '.$css_class
1494 1494
                                 : $css_class;
1495 1495
 
1496
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
-                                                                          && isset($content[ $extra_field ])
1498
-                                ? $content[ $extra_field ]
1496
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1497
+                                                                          && isset($content[$extra_field])
1498
+                                ? $content[$extra_field]
1499 1499
                                 : '';
1500 1500
 
1501 1501
                             // do we have a validation error?  if we do then let's use that value instead
1502
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
-                                ? $validators[ $extra_field ]['value']
1504
-                                : $template_form_fields[ $field_id ]['value'];
1502
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1503
+                                ? $validators[$extra_field]['value']
1504
+                                : $template_form_fields[$field_id]['value'];
1505 1505
 
1506 1506
 
1507
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1508 1508
 
1509 1509
                             // shortcode selector
1510 1510
                             $field_name_to_use                                   = $extra_field === 'main'
1511 1511
                                 ? 'content'
1512 1512
                                 : $extra_field;
1513
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1514 1514
                                 $field_name_to_use,
1515 1515
                                 $field_id
1516 1516
                             );
1517 1517
                         }
1518
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
-                        $template_field_template_name_id = $reference_field . '-name';
1518
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1519
+                        $template_field_template_name_id = $reference_field.'-name';
1520 1520
 
1521
-                        $template_form_fields[ $template_field_MTP_id ] = [
1522
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1521
+                        $template_form_fields[$template_field_MTP_id] = [
1522
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1523 1523
                             'label'      => null,
1524 1524
                             'input'      => 'hidden',
1525 1525
                             'type'       => 'int',
@@ -1531,8 +1531,8 @@  discard block
 block discarded – undo
1531 1531
                             'db-col'     => 'MTP_ID',
1532 1532
                         ];
1533 1533
 
1534
-                        $template_form_fields[ $template_field_template_name_id ] = [
1535
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1534
+                        $template_form_fields[$template_field_template_name_id] = [
1535
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1536 1536
                             'label'      => null,
1537 1537
                             'input'      => 'hidden',
1538 1538
                             'type'       => 'string',
@@ -1546,38 +1546,38 @@  discard block
 block discarded – undo
1546 1546
                     }
1547 1547
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548 1548
                 } else {
1549
-                    $field_id                                   = $template_field . '-content';
1550
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1551
-                    $template_form_fields[ $field_id ]['name']  =
1552
-                        'MTP_template_fields[' . $template_field . '][content]';
1549
+                    $field_id                                   = $template_field.'-content';
1550
+                    $template_form_fields[$field_id]          = $field_setup_array;
1551
+                    $template_form_fields[$field_id]['name']  =
1552
+                        'MTP_template_fields['.$template_field.'][content]';
1553 1553
                     $message_template                           =
1554
-                        isset($message_templates[ $context ][ $template_field ])
1555
-                            ? $message_templates[ $context ][ $template_field ]
1554
+                        isset($message_templates[$context][$template_field])
1555
+                            ? $message_templates[$context][$template_field]
1556 1556
                             : null;
1557
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
-                                                                  && is_array($message_templates[ $context ])
1557
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1558
+                                                                  && is_array($message_templates[$context])
1559 1559
                                                                   && $message_template instanceof EE_Message_Template
1560 1560
                         ? $message_template->get('MTP_content')
1561 1561
                         : '';
1562 1562
 
1563 1563
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1564
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
-                        ? $validators[ $template_field ]['value']
1566
-                        : $template_form_fields[ $field_id ]['value'];
1564
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1565
+                        ? $validators[$template_field]['value']
1566
+                        : $template_form_fields[$field_id]['value'];
1567 1567
 
1568 1568
 
1569
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1570 1570
                     $css_class                                      = isset($field_setup_array['css_class'])
1571 1571
                         ? $field_setup_array['css_class']
1572 1572
                         : '';
1573
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1574 1574
                                                                       && in_array($template_field, $v_fields, true)
1575
-                                                                      && isset($validators[ $template_field ]['msg'])
1576
-                        ? 'validate-error ' . $css_class
1575
+                                                                      && isset($validators[$template_field]['msg'])
1576
+                        ? 'validate-error '.$css_class
1577 1577
                         : $css_class;
1578 1578
 
1579 1579
                     // shortcode selector
1580
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1581 1581
                         $template_field,
1582 1582
                         $field_id
1583 1583
                     );
@@ -1585,12 +1585,12 @@  discard block
 block discarded – undo
1585 1585
 
1586 1586
                 // k took care of content field(s) now let's take care of others.
1587 1587
 
1588
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
-                $template_field_field_template_name_id = $template_field . '-name';
1588
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1589
+                $template_field_field_template_name_id = $template_field.'-name';
1590 1590
 
1591 1591
                 // foreach template field there are actually two form fields created
1592
-                $template_form_fields[ $template_field_MTP_id ] = [
1593
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1592
+                $template_form_fields[$template_field_MTP_id] = [
1593
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1594 1594
                     'label'      => null,
1595 1595
                     'input'      => 'hidden',
1596 1596
                     'type'       => 'int',
@@ -1602,8 +1602,8 @@  discard block
 block discarded – undo
1602 1602
                     'db-col'     => 'MTP_ID',
1603 1603
                 ];
1604 1604
 
1605
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1606
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1605
+                $template_form_fields[$template_field_field_template_name_id] = [
1606
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1607 1607
                     'label'      => null,
1608 1608
                     'input'      => 'hidden',
1609 1609
                     'type'       => 'string',
@@ -1720,7 +1720,7 @@  discard block
 block discarded – undo
1720 1720
                 'format'     => '%d',
1721 1721
                 'db-col'     => 'MTP_deleted',
1722 1722
             ];
1723
-            $sidebar_form_fields['ee-msg-author']  = [
1723
+            $sidebar_form_fields['ee-msg-author'] = [
1724 1724
                 'name'       => 'MTP_user_id',
1725 1725
                 'label'      => esc_html__('Author', 'event_espresso'),
1726 1726
                 'input'      => 'hidden',
@@ -1739,17 +1739,17 @@  discard block
 block discarded – undo
1739 1739
                 'value' => $action,
1740 1740
             ];
1741 1741
 
1742
-            $sidebar_form_fields['ee-msg-id']        = [
1742
+            $sidebar_form_fields['ee-msg-id'] = [
1743 1743
                 'name'  => 'id',
1744 1744
                 'input' => 'hidden',
1745 1745
                 'type'  => 'int',
1746 1746
                 'value' => $GRP_ID,
1747 1747
             ];
1748 1748
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
-                'name'  => $action . '_nonce',
1749
+                'name'  => $action.'_nonce',
1750 1750
                 'input' => 'hidden',
1751 1751
                 'type'  => 'string',
1752
-                'value' => wp_create_nonce($action . '_nonce'),
1752
+                'value' => wp_create_nonce($action.'_nonce'),
1753 1753
             ];
1754 1754
 
1755 1755
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1780,7 +1780,7 @@  discard block
 block discarded – undo
1780 1780
         );
1781 1781
 
1782 1782
         // add preview button
1783
-        $preview_url    = parent::add_query_args_and_nonce(
1783
+        $preview_url = parent::add_query_args_and_nonce(
1784 1784
             [
1785 1785
                 'message_type' => $message_template_group->message_type(),
1786 1786
                 'messenger'    => $message_template_group->messenger(),
@@ -1791,7 +1791,7 @@  discard block
 block discarded – undo
1791 1791
             ],
1792 1792
             $this->_admin_base_url
1793 1793
         );
1794
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1794
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1795 1795
                           . esc_html__('Preview', 'event_espresso')
1796 1796
                           . '</a>';
1797 1797
 
@@ -1827,11 +1827,11 @@  discard block
 block discarded – undo
1827 1827
             $context_label
1828 1828
         );
1829 1829
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1830
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1831 1831
 
1832 1832
         $this->_template_path = $this->_template_args['GRP_ID']
1833 1833
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1834
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1835 1835
 
1836 1836
         // send along EE_Message_Template_Group object for further template use.
1837 1837
         $this->_template_args['MTP'] = $message_template_group;
@@ -1887,7 +1887,7 @@  discard block
 block discarded – undo
1887 1887
     ) {
1888 1888
         $template_args = [
1889 1889
             'context'                   => $context,
1890
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1890
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1891 1891
             'is_active'                 => $message_template_group->is_context_active($context),
1892 1892
             'on_off_action'             => $message_template_group->is_context_active($context)
1893 1893
                 ? 'context-off'
@@ -1896,7 +1896,7 @@  discard block
 block discarded – undo
1896 1896
             'message_template_group_id' => $message_template_group->ID(),
1897 1897
         ];
1898 1898
         return EEH_Template::display_template(
1899
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1899
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1900 1900
             $template_args,
1901 1901
             true
1902 1902
         );
@@ -1953,7 +1953,7 @@  discard block
 block discarded – undo
1953 1953
         }
1954 1954
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955 1955
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1956
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1957 1957
             EE_Error::add_error(
1958 1958
                 sprintf(
1959 1959
                     esc_html__(
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
         $messenger    = $this->request->getRequestParam('msgr');
2085 2085
         $message_type = $this->request->getRequestParam('mt');
2086 2086
         // we need to make sure we've got the info we need.
2087
-        if (! ($GRP_ID && $messenger && $message_type)) {
2087
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2088 2088
             EE_Error::add_error(
2089 2089
                 esc_html__(
2090 2090
                     'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
@@ -2121,7 +2121,7 @@  discard block
 block discarded – undo
2121 2121
         }
2122 2122
 
2123 2123
         // any error messages?
2124
-        if (! $success) {
2124
+        if ( ! $success) {
2125 2125
             EE_Error::add_error(
2126 2126
                 esc_html__(
2127 2127
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2170,7 +2170,7 @@  discard block
 block discarded – undo
2170 2170
     {
2171 2171
         // first make sure we've got the necessary parameters
2172 2172
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174 2174
             EE_Error::add_error(
2175 2175
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176 2176
                 __FILE__,
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197 2197
 
2198 2198
         // let's add a button to go back to the edit view
2199
-        $query_args             = [
2199
+        $query_args = [
2200 2200
             'id'      => $GRP_ID,
2201 2201
             'evt_id'  => $EVT_ID,
2202 2202
             'context' => $context,
@@ -2217,7 +2217,7 @@  discard block
 block discarded – undo
2217 2217
         $preview_title = sprintf(
2218 2218
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219 2219
             $active_messenger_label,
2220
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2220
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2221 2221
         );
2222 2222
         if (empty($preview)) {
2223 2223
             $this->noEventsErrorMessage();
@@ -2225,7 +2225,7 @@  discard block
 block discarded – undo
2225 2225
         // setup display of preview.
2226 2226
         $this->_admin_page_title                    = $preview_title;
2227 2227
         $this->_template_args['admin_page_title']   = $preview_title;
2228
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2228
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2229 2229
         $this->_template_args['data']['force_json'] = true;
2230 2230
 
2231 2231
         return '';
@@ -2246,7 +2246,7 @@  discard block
 block discarded – undo
2246 2246
             ],
2247 2247
             admin_url('admin.php')
2248 2248
         );
2249
-        $message    = $test_send
2249
+        $message = $test_send
2250 2250
             ? esc_html__(
2251 2251
                 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252 2252
                 'event_espresso'
@@ -2259,7 +2259,7 @@  discard block
 block discarded – undo
2259 2259
         EE_Error::add_attention(
2260 2260
             sprintf(
2261 2261
                 $message,
2262
-                "<a href='" . esc_url_raw($events_url) . "'>",
2262
+                "<a href='".esc_url_raw($events_url)."'>",
2263 2263
                 '</a>'
2264 2264
             )
2265 2265
         );
@@ -2339,10 +2339,10 @@  discard block
 block discarded – undo
2339 2339
             // only include template packs that support this messenger and message type!
2340 2340
             $supports = $tp->get_supports();
2341 2341
             if (
2342
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2342
+                ! isset($supports[$this->_message_template_group->messenger()])
2343 2343
                 || ! in_array(
2344 2344
                     $this->_message_template_group->message_type(),
2345
-                    $supports[ $this->_message_template_group->messenger() ],
2345
+                    $supports[$this->_message_template_group->messenger()],
2346 2346
                     true
2347 2347
                 )
2348 2348
             ) {
@@ -2366,7 +2366,7 @@  discard block
 block discarded – undo
2366 2366
         }
2367 2367
 
2368 2368
         // setup variation select values for the currently selected template.
2369
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2369
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2370 2370
             $this->_message_template_group->messenger(),
2371 2371
             $this->_message_template_group->message_type()
2372 2372
         );
@@ -2380,12 +2380,12 @@  discard block
 block discarded – undo
2380 2380
 
2381 2381
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382 2382
 
2383
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2383
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2384 2384
             'MTP_template_pack',
2385 2385
             $tp_select_values,
2386 2386
             $this->_message_template_group->get_template_pack_name()
2387 2387
         );
2388
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2388
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2389 2389
             'MTP_template_variation',
2390 2390
             $variations_select_values,
2391 2391
             $this->_message_template_group->get_template_pack_variation()
@@ -2395,7 +2395,7 @@  discard block
 block discarded – undo
2395 2395
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396 2396
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397 2397
 
2398
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2398
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2399 2399
 
2400 2400
         EEH_Template::display_template($template, $template_args);
2401 2401
     }
@@ -2421,33 +2421,33 @@  discard block
 block discarded – undo
2421 2421
         // first we need to see if there are any fields
2422 2422
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423 2423
 
2424
-        if (! empty($fields)) {
2424
+        if ( ! empty($fields)) {
2425 2425
             // yup there be fields
2426 2426
             foreach ($fields as $field => $config) {
2427
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2427
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2428 2428
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429 2429
                 $default  = isset($config['default']) ? $config['default'] : '';
2430 2430
                 $default  = isset($config['value']) ? $config['value'] : $default;
2431 2431
 
2432 2432
                 // if type is hidden and the value is empty
2433 2433
                 // something may have gone wrong so let's correct with the defaults
2434
-                $fix                = $config['input'] === 'hidden'
2435
-                                      && isset($existing[ $field ])
2436
-                                      && empty($existing[ $field ])
2434
+                $fix = $config['input'] === 'hidden'
2435
+                                      && isset($existing[$field])
2436
+                                      && empty($existing[$field])
2437 2437
                     ? $default
2438 2438
                     : '';
2439
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
-                    ? $existing[ $field ]
2439
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2440
+                    ? $existing[$field]
2441 2441
                     : $fix;
2442 2442
 
2443
-                $template_form_fields[ $field_id ] = [
2444
-                    'name'       => 'test_settings_fld[' . $field . ']',
2443
+                $template_form_fields[$field_id] = [
2444
+                    'name'       => 'test_settings_fld['.$field.']',
2445 2445
                     'label'      => $config['label'],
2446 2446
                     'input'      => $config['input'],
2447 2447
                     'type'       => $config['type'],
2448 2448
                     'required'   => $config['required'],
2449 2449
                     'validation' => $config['validation'],
2450
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2450
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2451 2451
                     'css_class'  => $config['css_class'],
2452 2452
                     'options'    => isset($config['options']) ? $config['options'] : [],
2453 2453
                     'default'    => $default,
@@ -2461,7 +2461,7 @@  discard block
 block discarded – undo
2461 2461
             : '';
2462 2462
 
2463 2463
         // print out $test_settings_fields
2464
-        if (! empty($test_settings_html)) {
2464
+        if ( ! empty($test_settings_html)) {
2465 2465
             $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466 2466
             $test_settings_html .= 'name="test_button" value="';
2467 2467
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2507,7 +2507,7 @@  discard block
 block discarded – undo
2507 2507
         ];
2508 2508
 
2509 2509
         return EEH_Template::display_template(
2510
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2510
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2511 2511
             $template_args,
2512 2512
             true
2513 2513
         );
@@ -2533,7 +2533,7 @@  discard block
 block discarded – undo
2533 2533
         // $messenger = $this->_message_template_group->messenger_obj();
2534 2534
         // now let's set the content depending on the status of the shortcodes array
2535 2535
         if (empty($shortcodes)) {
2536
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2536
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2537 2537
             return;
2538 2538
         }
2539 2539
         ?>
@@ -2569,7 +2569,7 @@  discard block
 block discarded – undo
2569 2569
     {
2570 2570
 
2571 2571
         // no need to run this if the property is already set
2572
-        if (! empty($this->_shortcodes)) {
2572
+        if ( ! empty($this->_shortcodes)) {
2573 2573
             return;
2574 2574
         }
2575 2575
 
@@ -2624,7 +2624,7 @@  discard block
 block discarded – undo
2624 2624
     protected function _set_message_template_group()
2625 2625
     {
2626 2626
         // get out if this is already set.
2627
-        if (! empty($this->_message_template_group)) {
2627
+        if ( ! empty($this->_message_template_group)) {
2628 2628
             return;
2629 2629
         }
2630 2630
 
@@ -2670,8 +2670,8 @@  discard block
 block discarded – undo
2670 2670
                     <?php
2671 2671
                 }
2672 2672
                 // setup nonce_url
2673
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2673
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2674
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2675 2675
                 ?>
2676 2676
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2677 2677
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2684,7 +2684,7 @@  discard block
 block discarded – undo
2684 2684
                             $checked = ($context === $args['context']) ? 'selected' : '';
2685 2685
                             ?>
2686 2686
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2687
-                                <?php echo esc_html($context_details[ $context ]['label']); ?>
2687
+                                <?php echo esc_html($context_details[$context]['label']); ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
2690 2690
                     endif; ?>
@@ -3076,7 +3076,7 @@  discard block
 block discarded – undo
3076 3076
     {
3077 3077
         if (is_array($content)) {
3078 3078
             foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3079
+                $content[$key] = $this->sanitizeMessageTemplateContent($value);
3080 3080
             }
3081 3081
             return $content;
3082 3082
         }
@@ -3114,7 +3114,7 @@  discard block
 block discarded – undo
3114 3114
 
3115 3115
         $context   = ucwords(str_replace('_', ' ', $context));
3116 3116
         $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3117
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
3118 3118
             : '';
3119 3119
         $item_desc .= 'Message Template';
3120 3120
         return $item_desc;
@@ -3266,7 +3266,7 @@  discard block
 block discarded – undo
3266 3266
         if ($all) {
3267 3267
             // Checkboxes
3268 3268
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3269
+            if ( ! empty($checkboxes)) {
3270 3270
                 // if array has more than one element then success message should be plural.
3271 3271
                 // todo: what about nonce?
3272 3272
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3276,18 +3276,18 @@  discard block
 block discarded – undo
3276 3276
                     $trashed_or_restored = $trash
3277 3277
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278 3278
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3279
+                    if ( ! $trashed_or_restored) {
3280 3280
                         $success = 0;
3281 3281
                     }
3282 3282
                 }
3283 3283
             } else {
3284 3284
                 // grab single GRP_ID and handle
3285 3285
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3286
+                if ( ! empty($GRP_ID)) {
3287 3287
                     $trashed_or_restored = $trash
3288 3288
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289 3289
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3290
+                    if ( ! $trashed_or_restored) {
3291 3291
                         $success = 0;
3292 3292
                     }
3293 3293
                 } else {
@@ -3335,7 +3335,7 @@  discard block
 block discarded – undo
3335 3335
 
3336 3336
         // checkboxes
3337 3337
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3338
+        if ( ! empty($checkboxes)) {
3339 3339
             // if array has more than one element then success message should be plural
3340 3340
             $success = count($checkboxes) > 1 ? 2 : 1;
3341 3341
 
@@ -3439,7 +3439,7 @@  discard block
 block discarded – undo
3439 3439
     protected function _set_m_mt_settings()
3440 3440
     {
3441 3441
         // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3442
+        if ( ! empty($this->_m_mt_settings)) {
3443 3443
             return;
3444 3444
         }
3445 3445
 
@@ -3451,7 +3451,7 @@  discard block
 block discarded – undo
3451 3451
         // assemble the array for the _tab_text_links helper
3452 3452
 
3453 3453
         foreach ($messengers as $messenger) {
3454
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3454
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3455 3455
                 'label' => ucwords($messenger->label['singular']),
3456 3456
                 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457 3457
                     ? 'messenger-active'
@@ -3468,7 +3468,7 @@  discard block
 block discarded – undo
3468 3468
             foreach ($message_types as $message_type) {
3469 3469
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470 3470
                 // it shouldn't show in either the inactive OR active metabox.
3471
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3471
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3472 3472
                     continue;
3473 3473
                 }
3474 3474
 
@@ -3479,12 +3479,12 @@  discard block
 block discarded – undo
3479 3479
                     ? 'active'
3480 3480
                     : 'inactive';
3481 3481
 
3482
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3482
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3483 3483
                     'label'    => ucwords($message_type->label['singular']),
3484
-                    'class'    => 'message-type-' . $a_or_i,
3485
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3484
+                    'class'    => 'message-type-'.$a_or_i,
3485
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3486
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3487
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3488 3488
                     'title'    => $a_or_i === 'active'
3489 3489
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490 3490
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3515,25 +3515,25 @@  discard block
 block discarded – undo
3515 3515
         $fields                                         = $message_type->get_admin_settings_fields();
3516 3516
         $settings_template_args['template_form_fields'] = '';
3517 3517
 
3518
-        if (! empty($fields) && $active) {
3518
+        if ( ! empty($fields) && $active) {
3519 3519
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520 3520
             foreach ($fields as $fldname => $fldprops) {
3521
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
-                $template_form_field[ $field_id ] = [
3523
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3521
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3522
+                $template_form_field[$field_id] = [
3523
+                    'name'       => 'message_type_settings['.$fldname.']',
3524 3524
                     'label'      => $fldprops['label'],
3525 3525
                     'input'      => $fldprops['field_type'],
3526 3526
                     'type'       => $fldprops['value_type'],
3527 3527
                     'required'   => $fldprops['required'],
3528 3528
                     'validation' => $fldprops['validation'],
3529
-                    'value'      => isset($existing_settings[ $fldname ])
3530
-                        ? $existing_settings[ $fldname ]
3529
+                    'value'      => isset($existing_settings[$fldname])
3530
+                        ? $existing_settings[$fldname]
3531 3531
                         : $fldprops['default'],
3532 3532
                     'options'    => isset($fldprops['options'])
3533 3533
                         ? $fldprops['options']
3534 3534
                         : [],
3535
-                    'default'    => isset($existing_settings[ $fldname ])
3536
-                        ? $existing_settings[ $fldname ]
3535
+                    'default'    => isset($existing_settings[$fldname])
3536
+                        ? $existing_settings[$fldname]
3537 3537
                         : $fldprops['default'],
3538 3538
                     'css_class'  => 'no-drag',
3539 3539
                     'format'     => $fldprops['format'],
@@ -3553,15 +3553,15 @@  discard block
 block discarded – undo
3553 3553
         $settings_template_args['description'] = $message_type->description;
3554 3554
         // we also need some hidden fields
3555 3555
         $hidden_fields = [
3556
-            'message_type_settings[messenger]' . $message_type->name    => [
3556
+            'message_type_settings[messenger]'.$message_type->name    => [
3557 3557
                 'type'  => 'hidden',
3558 3558
                 'value' => $messenger->name,
3559 3559
             ],
3560
-            'message_type_settings[message_type]' . $message_type->name => [
3560
+            'message_type_settings[message_type]'.$message_type->name => [
3561 3561
                 'type'  => 'hidden',
3562 3562
                 'value' => $message_type->name,
3563 3563
             ],
3564
-            'type' . $message_type->name                                => [
3564
+            'type'.$message_type->name                                => [
3565 3565
                 'type'  => 'hidden',
3566 3566
                 'value' => 'message_type',
3567 3567
             ],
@@ -3571,12 +3571,12 @@  discard block
 block discarded – undo
3571 3571
             $hidden_fields,
3572 3572
             'array'
3573 3573
         );
3574
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3574
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3575 3575
             ? ' hidden'
3576 3576
             : '';
3577 3577
 
3578 3578
 
3579
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3579
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3580 3580
         return EEH_Template::display_template($template, $settings_template_args, true);
3581 3581
     }
3582 3582
 
@@ -3604,21 +3604,21 @@  discard block
 block discarded – undo
3604 3604
 
3605 3605
                 // messenger meta boxes
3606 3606
                 $active         = $selected_messenger === $messenger;
3607
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3607
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3608
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3609 3609
                     : '';
3610 3610
 
3611
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3611
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3612 3612
                     esc_html__('%s Settings', 'event_espresso'),
3613 3613
                     $tab_array['label']
3614 3614
                 );
3615 3615
 
3616
-                $m_template_args[ $messenger . '_a_box' ] = [
3616
+                $m_template_args[$messenger.'_a_box'] = [
3617 3617
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618 3618
                     'inactive_message_types' => isset(
3619
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3619
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3620 3620
                     )
3621
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3621
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3622 3622
                         : '',
3623 3623
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624 3624
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3630,13 +3630,13 @@  discard block
 block discarded – undo
3630 3630
                 // message type meta boxes
3631 3631
                 // (which is really just the inactive container for each messenger
3632 3632
                 // showing inactive message types for that messenger)
3633
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
-                $mt_template_args[ $messenger . '_i_box' ] = [
3633
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3634
+                $mt_template_args[$messenger.'_i_box'] = [
3635 3635
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636 3636
                     'inactive_message_types' => isset(
3637
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3637
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3638 3638
                     )
3639
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3639
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3640 3640
                         : '',
3641 3641
                     'hidden'                 => $active ? '' : ' hidden',
3642 3642
                     'hide_on_message'        => $hide_on_message,
@@ -3649,14 +3649,14 @@  discard block
 block discarded – undo
3649 3649
 
3650 3650
 
3651 3651
         // register messenger metaboxes
3652
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3652
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3653 3653
         foreach ($m_boxes as $box => $label) {
3654
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3654
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3655 3655
             $msgr          = str_replace('_a_box', '', $box);
3656 3656
             add_meta_box(
3657
-                'espresso_' . $msgr . '_settings',
3657
+                'espresso_'.$msgr.'_settings',
3658 3658
                 $label,
3659
-                function ($post, $metabox) {
3659
+                function($post, $metabox) {
3660 3660
                     EEH_Template::display_template(
3661 3661
                         $metabox['args']['template_path'],
3662 3662
                         $metabox['args']['template_args']
@@ -3670,17 +3670,17 @@  discard block
 block discarded – undo
3670 3670
         }
3671 3671
 
3672 3672
         // register message type metaboxes
3673
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3673
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3674 3674
         foreach ($mt_boxes as $box => $label) {
3675 3675
             $callback_args = [
3676 3676
                 'template_path' => $mt_template_path,
3677
-                'template_args' => $mt_template_args[ $box ],
3677
+                'template_args' => $mt_template_args[$box],
3678 3678
             ];
3679
-            $mt            = str_replace('_i_box', '', $box);
3679
+            $mt = str_replace('_i_box', '', $box);
3680 3680
             add_meta_box(
3681
-                'espresso_' . $mt . '_inactive_mts',
3681
+                'espresso_'.$mt.'_inactive_mts',
3682 3682
                 $label,
3683
-                function ($post, $metabox) {
3683
+                function($post, $metabox) {
3684 3684
                     EEH_Template::display_template(
3685 3685
                         $metabox['args']['template_path'],
3686 3686
                         $metabox['args']['template_args']
@@ -3827,7 +3827,7 @@  discard block
 block discarded – undo
3827 3827
             if ($form->is_valid()) {
3828 3828
                 $valid_data = $form->valid_data();
3829 3829
                 foreach ($valid_data as $property => $value) {
3830
-                    $setter = 'set_' . $property;
3830
+                    $setter = 'set_'.$property;
3831 3831
                     if (method_exists($network_config, $setter)) {
3832 3832
                         $network_config->{$setter}($value);
3833 3833
                     } elseif (
@@ -3863,7 +3863,7 @@  discard block
 block discarded – undo
3863 3863
     protected function _get_mt_tabs($tab_array)
3864 3864
     {
3865 3865
         $tab_array = (array) $tab_array;
3866
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3866
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3867 3867
         $tabs      = '';
3868 3868
 
3869 3869
         foreach ($tab_array as $tab) {
@@ -3891,20 +3891,20 @@  discard block
 block discarded – undo
3891 3891
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892 3892
 
3893 3893
 
3894
-        if (! empty($fields)) {
3894
+        if ( ! empty($fields)) {
3895 3895
             $existing_settings = $messenger->get_existing_admin_settings();
3896 3896
 
3897 3897
             foreach ($fields as $fldname => $fldprops) {
3898
-                $field_id                         = $messenger->name . '-' . $fldname;
3899
-                $template_form_field[ $field_id ] = [
3900
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3898
+                $field_id                         = $messenger->name.'-'.$fldname;
3899
+                $template_form_field[$field_id] = [
3900
+                    'name'       => 'messenger_settings['.$field_id.']',
3901 3901
                     'label'      => $fldprops['label'],
3902 3902
                     'input'      => $fldprops['field_type'],
3903 3903
                     'type'       => $fldprops['value_type'],
3904 3904
                     'required'   => $fldprops['required'],
3905 3905
                     'validation' => $fldprops['validation'],
3906
-                    'value'      => isset($existing_settings[ $field_id ])
3907
-                        ? $existing_settings[ $field_id ]
3906
+                    'value'      => isset($existing_settings[$field_id])
3907
+                        ? $existing_settings[$field_id]
3908 3908
                         : $fldprops['default'],
3909 3909
                     'css_class'  => '',
3910 3910
                     'format'     => $fldprops['format'],
@@ -3919,20 +3919,20 @@  discard block
 block discarded – undo
3919 3919
 
3920 3920
         // we also need some hidden fields
3921 3921
         $settings_template_args['hidden_fields'] = [
3922
-            'messenger_settings[messenger]' . $messenger->name => [
3922
+            'messenger_settings[messenger]'.$messenger->name => [
3923 3923
                 'type'  => 'hidden',
3924 3924
                 'value' => $messenger->name,
3925 3925
             ],
3926
-            'type' . $messenger->name                          => [
3926
+            'type'.$messenger->name                          => [
3927 3927
                 'type'  => 'hidden',
3928 3928
                 'value' => 'messenger',
3929 3929
             ],
3930 3930
         ];
3931 3931
 
3932 3932
         // make sure any active message types that are existing are included in the hidden fields
3933
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3933
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3934
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3935
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3936 3936
                     'type'  => 'hidden',
3937 3937
                     'value' => $mt,
3938 3938
                 ];
@@ -3942,7 +3942,7 @@  discard block
 block discarded – undo
3942 3942
             $settings_template_args['hidden_fields'],
3943 3943
             'array'
3944 3944
         );
3945
-        $active                                  =
3945
+        $active =
3946 3946
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3947 3947
 
3948 3948
         $settings_template_args['messenger']           = $messenger->name;
@@ -3962,9 +3962,9 @@  discard block
 block discarded – undo
3962 3962
 
3963 3963
 
3964 3964
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3965
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3966 3966
         $settings_template_args['on_off_status'] = $active;
3967
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3967
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3968 3968
         return EEH_Template::display_template(
3969 3969
             $template,
3970 3970
             $settings_template_args,
@@ -3989,7 +3989,7 @@  discard block
 block discarded – undo
3989 3989
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3990 3990
         // let's check that we have required data
3991 3991
 
3992
-        if (! $this->_active_messenger_name) {
3992
+        if ( ! $this->_active_messenger_name) {
3993 3993
             EE_Error::add_error(
3994 3994
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995 3995
                 __FILE__,
@@ -4007,7 +4007,7 @@  discard block
 block discarded – undo
4007 4007
 
4008 4008
 
4009 4009
         $status = $this->request->getRequestParam('status');
4010
-        if (! $status) {
4010
+        if ( ! $status) {
4011 4011
             EE_Error::add_error(
4012 4012
                 esc_html__(
4013 4013
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4064,7 +4064,7 @@  discard block
 block discarded – undo
4064 4064
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4065 4065
 
4066 4066
         // let's make sure we have the necessary data
4067
-        if (! $this->_active_message_type_name) {
4067
+        if ( ! $this->_active_message_type_name) {
4068 4068
             EE_Error::add_error(
4069 4069
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070 4070
                 __FILE__,
@@ -4074,7 +4074,7 @@  discard block
 block discarded – undo
4074 4074
             $success = false;
4075 4075
         }
4076 4076
 
4077
-        if (! $this->_active_messenger_name) {
4077
+        if ( ! $this->_active_messenger_name) {
4078 4078
             EE_Error::add_error(
4079 4079
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080 4080
                 __FILE__,
@@ -4085,7 +4085,7 @@  discard block
 block discarded – undo
4085 4085
         }
4086 4086
 
4087 4087
         $status = $this->request->getRequestParam('status');
4088
-        if (! $status) {
4088
+        if ( ! $status) {
4089 4089
             EE_Error::add_error(
4090 4090
                 esc_html__(
4091 4091
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4297,7 +4297,7 @@  discard block
 block discarded – undo
4297 4297
         EE_Message_Type $message_type = null
4298 4298
     ) {
4299 4299
         // if $messenger isn't a valid messenger object then get out.
4300
-        if (! $messenger instanceof EE_Messenger) {
4300
+        if ( ! $messenger instanceof EE_Messenger) {
4301 4301
             EE_Error::add_error(
4302 4302
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303 4303
                 __FILE__,
@@ -4351,7 +4351,7 @@  discard block
 block discarded – undo
4351 4351
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352 4352
             // in which case we just give a success message for the messenger being successfully activated.
4353 4353
         } else {
4354
-            if (! $messenger->get_default_message_types()) {
4354
+            if ( ! $messenger->get_default_message_types()) {
4355 4355
                 // messenger doesn't have any default message types so still a success.
4356 4356
                 EE_Error::add_success(
4357 4357
                     sprintf(
@@ -4407,7 +4407,7 @@  discard block
 block discarded – undo
4407 4407
         EE_Error::overwrite_success();
4408 4408
 
4409 4409
         // if $messenger isn't a valid messenger object then get out.
4410
-        if (! $messenger instanceof EE_Messenger) {
4410
+        if ( ! $messenger instanceof EE_Messenger) {
4411 4411
             EE_Error::add_error(
4412 4412
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413 4413
                 __FILE__,
@@ -4477,7 +4477,7 @@  discard block
 block discarded – undo
4477 4477
      */
4478 4478
     public function update_mt_form()
4479 4479
     {
4480
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4480
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481 4481
             EE_Error::add_error(
4482 4482
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483 4483
                 __FILE__,
@@ -4488,7 +4488,7 @@  discard block
 block discarded – undo
4488 4488
         }
4489 4489
 
4490 4490
         $message_types = $this->get_installed_message_types();
4491
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4491
+        $message_type  = $message_types[$this->_active_message_type_name];
4492 4492
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493 4493
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494 4494
 
@@ -4507,7 +4507,7 @@  discard block
 block discarded – undo
4507 4507
     public function save_settings()
4508 4508
     {
4509 4509
         $type = $this->request->getRequestParam('type');
4510
-        if (! $type) {
4510
+        if ( ! $type) {
4511 4511
             EE_Error::add_error(
4512 4512
                 esc_html__(
4513 4513
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.
admin_pages/about/templates/credits.template.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <p class="about-description">
2 2
     <?php esc_html_e(
3
-        'Event Espresso is created by an international team of passionate individuals with a drive to empower your events!',
4
-        'event_espresso'
5
-    ); ?>
3
+		'Event Espresso is created by an international team of passionate individuals with a drive to empower your events!',
4
+		'event_espresso'
5
+	); ?>
6 6
 </p>
7 7
 <h3 class="wp-people-group"><?php esc_html_e('Founders', 'event_espresso'); ?></h3>
8 8
 <ul class="wp-people-group" id="ee-people-group-owners">
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     </li>
48 48
     <li class='wp-person' id='ee-person-mwani'>
49 49
         <a href="<?php
50
-        esp_gravatar_profile('[email protected]'); ?>" target='_blank'>
50
+		esp_gravatar_profile('[email protected]'); ?>" target='_blank'>
51 51
             <?php esp_gravatar_image('[email protected]', 'Manzoor Ahmad Wani'); ?>
52 52
         </a>
53 53
         <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>" target='_blank'>
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
 <h3 class="wp-people-group"><?php esc_html_e('Contributor Recognition', 'event_espresso'); ?></h3>
88 88
 <p class="description">
89 89
     <?php
90
-    printf(
91
-        esc_html__(
92
-            'For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.',
93
-            'event_espresso'
94
-        ),
95
-        '<a href="https://github.com/eventespresso/event-espresso-core" aria-label="Contribute to Event Espresso by making a pull request via GitHub" target="_blank">',
96
-        '</a>'
97
-    );
98
-    ?>
90
+	printf(
91
+		esc_html__(
92
+			'For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.',
93
+			'event_espresso'
94
+		),
95
+		'<a href="https://github.com/eventespresso/event-espresso-core" aria-label="Contribute to Event Espresso by making a pull request via GitHub" target="_blank">',
96
+		'</a>'
97
+	);
98
+	?>
99 99
 </p>
100 100
 <p class="wp-credits-list">
101 101
 <ul>
@@ -110,15 +110,15 @@  discard block
 block discarded – undo
110 110
 <h3 class="wp-people-group"><?php esc_html_e('External Libraries', 'event_espresso'); ?></h3>
111 111
 <p class="description">
112 112
     <?php
113
-    printf(
114
-        esc_html__(
115
-            'Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:',
116
-            'event_espresso'
117
-        ),
118
-        '<a href="credits.php">',
119
-        '</a>'
120
-    );
121
-    ?>
113
+	printf(
114
+		esc_html__(
115
+			'Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:',
116
+			'event_espresso'
117
+		),
118
+		'<a href="credits.php">',
119
+		'</a>'
120
+	);
121
+	?>
122 122
 </p>
123 123
 <p class="wp-credits-list">
124 124
     <a href="https://openexchangerates.github.io/accounting.js/" target='_blank'>accounting.js</a>,
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
 <?php
135 135
 function esp_gravatar_profile($email)
136 136
 {
137
-    echo esc_url_raw('https://www.gravatar.com/' . md5($email));
137
+	echo esc_url_raw('https://www.gravatar.com/' . md5($email));
138 138
 }
139 139
 
140 140
 function esp_gravatar_image($email, $name)
141 141
 {
142
-    $email = md5($email);
143
-    $url = "https://0.gravatar.com/avatar/{$email}?s=60";
144
-    echo "<img src='" . esc_url_raw($url) . "' class='gravatar' alt='" . esc_attr($name) . "'/>";
142
+	$email = md5($email);
143
+	$url = "https://0.gravatar.com/avatar/{$email}?s=60";
144
+	echo "<img src='" . esc_url_raw($url) . "' class='gravatar' alt='" . esc_attr($name) . "'/>";
145 145
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -134,12 +134,12 @@
 block discarded – undo
134 134
 <?php
135 135
 function esp_gravatar_profile($email)
136 136
 {
137
-    echo esc_url_raw('https://www.gravatar.com/' . md5($email));
137
+    echo esc_url_raw('https://www.gravatar.com/'.md5($email));
138 138
 }
139 139
 
140 140
 function esp_gravatar_image($email, $name)
141 141
 {
142 142
     $email = md5($email);
143 143
     $url = "https://0.gravatar.com/avatar/{$email}?s=60";
144
-    echo "<img src='" . esc_url_raw($url) . "' class='gravatar' alt='" . esc_attr($name) . "'/>";
144
+    echo "<img src='".esc_url_raw($url)."' class='gravatar' alt='".esc_attr($name)."'/>";
145 145
 }
Please login to merge, or discard this patch.
registration_form/templates/question_groups_main_meta_box.template.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 /* @var EE_Question[] $all_questions */
16 16
 assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions)));// list of unused questions
17 17
 foreach ($all_questions as $unused_question) {
18
-    assert($unused_question);
19
-    assert($unused_question instanceof EE_Question);
18
+	assert($unused_question);
19
+	assert($unused_question instanceof EE_Question);
20 20
 }
21 21
 /* @var array $values . Array of arrays, where each sub-array contains 2 keys: 'id' (internal value) and 'name' (label for displaying) */
22 22
 assert(is_array($values));
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
             <th>
36 36
                 <label for="QSG_name">
37 37
                     <?php esc_html_e('Group Name', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
38
-                        'group_name_info'
39
-                    ); ?>
38
+						'group_name_info'
39
+					); ?>
40 40
                 </label>
41 41
             </th>
42 42
             <td>
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
             <th>
51 51
                 <label for="QSG_identifier">
52 52
                     <?php esc_html_e('Group Identifier', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
53
-                        'group_identifier_info'
54
-                    ); ?>
53
+						'group_identifier_info'
54
+					); ?>
55 55
                 </label>
56 56
             </th>
57 57
             <td>
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
             <th>
71 71
                 <label for="QSG_desc">
72 72
                     <?php esc_html_e('Description', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
73
-                        'group_description_info'
74
-                    ); ?>
73
+						'group_description_info'
74
+					); ?>
75 75
                 </label>
76 76
             </th>
77 77
             <td>
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
             <th>
85 85
                 <label for="QSG_order">
86 86
                     <?php esc_html_e('Question Group Order', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
87
-                        'group_order_info'
88
-                    ); ?>
87
+						'group_order_info'
88
+					); ?>
89 89
                 </label>
90 90
             </th>
91 91
             <td>
@@ -98,17 +98,17 @@  discard block
 block discarded – undo
98 98
             <th>
99 99
                 <label>
100 100
                     <?php esc_html_e('Show Name', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
101
-                        'show_group_name_info'
102
-                    ); ?>
101
+						'show_group_name_info'
102
+					); ?>
103 103
                 </label>
104 104
             </th>
105 105
             <td>
106 106
                 <label for="QSG_show_group_name">
107 107
                     <?php echo EEH_Form_Fields::select_input(
108
-                        'QSG_show_group_name',
109
-                        $values,
110
-                        $question_group->show_group_name()
111
-                    ); ?>
108
+						'QSG_show_group_name',
109
+						$values,
110
+						$question_group->show_group_name()
111
+					); ?>
112 112
                     <p class="description"><?php esc_html_e('Show Group Name on Registration Page?', 'event_espresso'); ?></p>
113 113
                 </label>
114 114
             </td>
@@ -118,20 +118,20 @@  discard block
 block discarded – undo
118 118
             <th>
119 119
                 <label>
120 120
                     <?php esc_html_e(' Show Description', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
121
-                        'show_group_description_info'
122
-                    ); ?>
121
+						'show_group_description_info'
122
+					); ?>
123 123
                 </label>
124 124
             </th>
125 125
             <td>
126 126
                 <label for="QSG_show_group_order">
127 127
                     <?php echo EEH_Form_Fields::select_input(
128
-                        'QSG_show_group_desc',
129
-                        $values,
130
-                        $question_group->show_group_desc()
131
-                    ); ?>
128
+						'QSG_show_group_desc',
129
+						$values,
130
+						$question_group->show_group_desc()
131
+					); ?>
132 132
                     <p class="description"><?php
133
-                        esc_html_e(' Show Group Description on Registration Page?', 'event_espresso');
134
-                    ?></p>
133
+						esc_html_e(' Show Group Description on Registration Page?', 'event_espresso');
134
+					?></p>
135 135
                 </label>
136 136
                 <input type="hidden" name="QSG_system" value="<?php echo esc_attr($question_group->system_group()); ?>">
137 137
             </td>
@@ -147,85 +147,85 @@  discard block
 block discarded – undo
147 147
     <div class="form-table question-group-questions inside">
148 148
         <div class="padding">
149 149
             <p><span class="description"><?php
150
-                    esc_html_e(
151
-                        'Select which questions should be shown in this group by checking or unchecking boxes. You can drag and drop questions to reorder them. Your changes will be updated when you save.',
152
-                        'event_espresso'
153
-                    ); ?></span></p>
150
+					esc_html_e(
151
+						'Select which questions should be shown in this group by checking or unchecking boxes. You can drag and drop questions to reorder them. Your changes will be updated when you save.',
152
+						'event_espresso'
153
+					); ?></span></p>
154 154
             <div>
155 155
                 <ul class="question-list-sortable">
156 156
                     <?php
157
-                    $question_order = 0;
158
-                    $question_group_questions = $question_group->questions();
159
-                    foreach ($all_questions as $question_ID => $question) {
160
-                        if ($question instanceof EE_Question) {
161
-                            /*@var $question EE_Question*/
162
-                            $checked = isset($question_group_questions[ $question_ID ]) ? 'checked' : '';
163
-                            // disable questions from the personal information question group
164
-                            // is it required in the current question group? if so don't allow admins to remove it
165
-                            $disabled = in_array(
166
-                                $question->system_ID(),
167
-                                EEM_Question::instance()->required_system_questions_in_system_question_group(
168
-                                    $QSG_system
169
-                                )
170
-                            ) ? 'disabled' : '';
171
-                            // limit where system questions can appear
172
-                            if (
173
-                                $question->system_ID() &&
174
-                                ! in_array(
175
-                                    $question->system_ID(),
176
-                                    EEM_Question::instance()->allowed_system_questions_in_system_question_group(
177
-                                        $QSG_system
178
-                                    )
179
-                                )
180
-                            ) {
181
-                                continue; // skip over system question not assigned to this group except for the address system group cause we want the address questions to display even if they aren't selected (but still not show the personal system questions).  The third condition checks if we're displaying a non system question group and the question is a system question, then we skip because for non-system question groups we only want to show non-system questions.
182
-                            }
183
-                            ?>
157
+					$question_order = 0;
158
+					$question_group_questions = $question_group->questions();
159
+					foreach ($all_questions as $question_ID => $question) {
160
+						if ($question instanceof EE_Question) {
161
+							/*@var $question EE_Question*/
162
+							$checked = isset($question_group_questions[ $question_ID ]) ? 'checked' : '';
163
+							// disable questions from the personal information question group
164
+							// is it required in the current question group? if so don't allow admins to remove it
165
+							$disabled = in_array(
166
+								$question->system_ID(),
167
+								EEM_Question::instance()->required_system_questions_in_system_question_group(
168
+									$QSG_system
169
+								)
170
+							) ? 'disabled' : '';
171
+							// limit where system questions can appear
172
+							if (
173
+								$question->system_ID() &&
174
+								! in_array(
175
+									$question->system_ID(),
176
+									EEM_Question::instance()->allowed_system_questions_in_system_question_group(
177
+										$QSG_system
178
+									)
179
+								)
180
+							) {
181
+								continue; // skip over system question not assigned to this group except for the address system group cause we want the address questions to display even if they aren't selected (but still not show the personal system questions).  The third condition checks if we're displaying a non system question group and the question is a system question, then we skip because for non-system question groups we only want to show non-system questions.
182
+							}
183
+							?>
184 184
                             <li class="ee-question-sortable">
185 185
                                 <label for="question-<?php echo absint($question_ID); ?>">
186 186
                                     <input type="checkbox" name="questions[<?php echo absint($question_ID); ?>]"
187 187
                                            id="question-<?php echo absint($question_ID); ?>"
188 188
                                            value="<?php echo absint($question_ID); ?>" <?php echo esc_attr($disabled); ?> <?php echo esc_attr($checked); ?>>
189 189
                                     <span class="question-text"><?php
190
-                                        echo wp_kses(trim($question->display_text()), AllowedTags::getAllowedTags())
191
-                                             . (95 <= strlen(trim($question->display_text()))
192
-                                                ? "&hellip;"
193
-                                                : '');
194
-                                                                ?>
190
+										echo wp_kses(trim($question->display_text()), AllowedTags::getAllowedTags())
191
+											 . (95 <= strlen(trim($question->display_text()))
192
+												? "&hellip;"
193
+												: '');
194
+																?>
195 195
                                     </span>
196 196
                                     <input class="question-group-QGQ_order" type="hidden"
197 197
                                            name="question_orders[<?php echo absint($question_ID); ?>]"
198 198
                                            value="<?php echo esc_attr($question_order); ?>">
199 199
                                 </label>
200 200
                                 <?php
201
-                                if (
202
-                                    EE_Registry::instance()->CAP->current_user_can(
203
-                                        'ee_edit_question',
204
-                                        'espresso_registration_form_edit_question',
205
-                                        $question->ID()
206
-                                    )
207
-                                ) {
208
-                                    $edit_query_args = array(
209
-                                        'action' => 'edit_question',
210
-                                        'QST_ID' => $question->ID(),
211
-                                    );
212
-                                    $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_FORMS_ADMIN_URL);
213
-
214
-                                    echo '<a href="' . $edit_link . '" target="_blank" aria-label="' .
215
-                                        sprintf(
216
-                                            esc_attr__('Edit %s', 'event_espresso'),
217
-                                            $question->admin_label()
218
-                                        )
219
-                                        . '"><span class="dashicons dashicons-edit"></span>
201
+								if (
202
+									EE_Registry::instance()->CAP->current_user_can(
203
+										'ee_edit_question',
204
+										'espresso_registration_form_edit_question',
205
+										$question->ID()
206
+									)
207
+								) {
208
+									$edit_query_args = array(
209
+										'action' => 'edit_question',
210
+										'QST_ID' => $question->ID(),
211
+									);
212
+									$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_FORMS_ADMIN_URL);
213
+
214
+									echo '<a href="' . $edit_link . '" target="_blank" aria-label="' .
215
+										sprintf(
216
+											esc_attr__('Edit %s', 'event_espresso'),
217
+											$question->admin_label()
218
+										)
219
+										. '"><span class="dashicons dashicons-edit"></span>
220 220
                                         </a>';
221
-                                }
222
-                                ?>
221
+								}
222
+								?>
223 223
                             </li>
224 224
                             <?php
225
-                            $question_order++;
226
-                        }
227
-                    }
228
-                    ?>
225
+							$question_order++;
226
+						}
227
+					}
228
+					?>
229 229
                 </ul>
230 230
             </div>
231 231
         </div>
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4104 added lines, -4104 removed lines patch added patch discarded remove patch
@@ -18,4180 +18,4180 @@
 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->_current_page = $this->request->getRequestParam('current_page', $this->_current_page, 'key');
510
-
511
-        $this->page_folder   = strtolower(
512
-            str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
513
-        );
514
-        global $ee_menu_slugs;
515
-        $ee_menu_slugs = (array) $ee_menu_slugs;
516
-        if (
517
-            ! $this->request->isAjax()
518
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
519
-        ) {
520
-            return;
521
-        }
522
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
523
-        // we need to copy the action from the second to the first
524
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
525
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
526
-        $action     = $action !== '-1' ? $action : $action2;
527
-        $req_action = $action !== '-1' ? $action : 'default';
528
-
529
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
530
-        // then let's use the route as the action.
531
-        // This covers cases where we're coming in from a list table that isn't on the default route.
532
-        $route = $this->request->getRequestParam('route');
533
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
534
-            ? $route
535
-            : $req_action;
536
-
537
-        $this->_current_view = $this->_req_action;
538
-        $this->_req_nonce    = $this->_req_action . '_nonce';
539
-        $this->_define_page_props();
540
-        $this->_current_page_view_url = add_query_arg(
541
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
542
-            $this->_admin_base_url
543
-        );
544
-        // default things
545
-        $this->_default_espresso_metaboxes = [
546
-            '_espresso_news_post_box',
547
-            '_espresso_links_post_box',
548
-            '_espresso_ratings_request',
549
-            '_espresso_sponsors_post_box',
550
-        ];
551
-        // set page configs
552
-        $this->_set_page_routes();
553
-        $this->_set_page_config();
554
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
555
-        if ($this->request->requestParamIsSet('wp_referer')) {
556
-            $wp_referer = $this->request->getRequestParam('wp_referer');
557
-            if ($wp_referer) {
558
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
559
-            }
560
-        }
561
-        // for caffeinated and other extended functionality.
562
-        //  If there is a _extend_page_config method
563
-        // then let's run that to modify the all the various page configuration arrays
564
-        if (method_exists($this, '_extend_page_config')) {
565
-            $this->_extend_page_config();
566
-        }
567
-        // for CPT and other extended functionality.
568
-        // If there is an _extend_page_config_for_cpt
569
-        // then let's run that to modify all the various page configuration arrays.
570
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
571
-            $this->_extend_page_config_for_cpt();
572
-        }
573
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
574
-        $this->_page_routes = apply_filters(
575
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
576
-            $this->_page_routes,
577
-            $this
578
-        );
579
-        $this->_page_config = apply_filters(
580
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
581
-            $this->_page_config,
582
-            $this
583
-        );
584
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
585
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
586
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
587
-            add_action(
588
-                'AHEE__EE_Admin_Page__route_admin_request',
589
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
590
-                10,
591
-                2
592
-            );
593
-        }
594
-        // next route only if routing enabled
595
-        if ($this->_routing && ! $this->request->isAjax()) {
596
-            $this->_verify_routes();
597
-            // next let's just check user_access and kill if no access
598
-            $this->check_user_access();
599
-            if ($this->_is_UI_request) {
600
-                // admin_init stuff - global, all views for this page class, specific view
601
-                add_action('admin_init', [$this, 'admin_init'], 10);
602
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
603
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
604
-                }
605
-            } else {
606
-                // hijack regular WP loading and route admin request immediately
607
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
608
-                $this->route_admin_request();
609
-            }
610
-        }
611
-    }
612
-
613
-
614
-    /**
615
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
616
-     *
617
-     * @return void
618
-     * @throws EE_Error
619
-     */
620
-    private function _do_other_page_hooks()
621
-    {
622
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
623
-        foreach ($registered_pages as $page) {
624
-            // now let's setup the file name and class that should be present
625
-            $classname = str_replace('.class.php', '', $page);
626
-            // autoloaders should take care of loading file
627
-            if (! class_exists($classname)) {
628
-                $error_msg[] = sprintf(
629
-                    esc_html__(
630
-                        'Something went wrong with loading the %s admin hooks page.',
631
-                        'event_espresso'
632
-                    ),
633
-                    $page
634
-                );
635
-                $error_msg[] = $error_msg[0]
636
-                               . "\r\n"
637
-                               . sprintf(
638
-                                   esc_html__(
639
-                                       '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',
640
-                                       'event_espresso'
641
-                                   ),
642
-                                   $page,
643
-                                   '<br />',
644
-                                   '<strong>' . $classname . '</strong>'
645
-                               );
646
-                throw new EE_Error(implode('||', $error_msg));
647
-            }
648
-            // notice we are passing the instance of this class to the hook object.
649
-            $this->loader->getShared($classname, [$this]);
650
-        }
651
-    }
652
-
653
-
654
-    /**
655
-     * @throws ReflectionException
656
-     * @throws EE_Error
657
-     */
658
-    public function load_page_dependencies()
659
-    {
660
-        try {
661
-            $this->_load_page_dependencies();
662
-        } catch (EE_Error $e) {
663
-            $e->get_error();
664
-        }
665
-    }
666
-
667
-
668
-    /**
669
-     * load_page_dependencies
670
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
671
-     *
672
-     * @return void
673
-     * @throws DomainException
674
-     * @throws EE_Error
675
-     * @throws InvalidArgumentException
676
-     * @throws InvalidDataTypeException
677
-     * @throws InvalidInterfaceException
678
-     */
679
-    protected function _load_page_dependencies()
680
-    {
681
-        // let's set the current_screen and screen options to override what WP set
682
-        $this->_current_screen = get_current_screen();
683
-        // load admin_notices - global, page class, and view specific
684
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
685
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
686
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
687
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
688
-        }
689
-        // load network admin_notices - global, page class, and view specific
690
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
691
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
692
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
693
-        }
694
-        // this will save any per_page screen options if they are present
695
-        $this->_set_per_page_screen_options();
696
-        // setup list table properties
697
-        $this->_set_list_table();
698
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
699
-        // However in some cases the metaboxes will need to be added within a route handling callback.
700
-        $this->_add_registered_meta_boxes();
701
-        $this->_add_screen_columns();
702
-        // add screen options - global, page child class, and view specific
703
-        $this->_add_global_screen_options();
704
-        $this->_add_screen_options();
705
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
706
-        if (method_exists($this, $add_screen_options)) {
707
-            $this->{$add_screen_options}();
708
-        }
709
-        // add help tab(s) - set via page_config and qtips.
710
-        $this->_add_help_tabs();
711
-        $this->_add_qtips();
712
-        // add feature_pointers - global, page child class, and view specific
713
-        $this->_add_feature_pointers();
714
-        $this->_add_global_feature_pointers();
715
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
716
-        if (method_exists($this, $add_feature_pointer)) {
717
-            $this->{$add_feature_pointer}();
718
-        }
719
-        // enqueue scripts/styles - global, page class, and view specific
720
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
721
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
722
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
723
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
724
-        }
725
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
726
-        // admin_print_footer_scripts - global, page child class, and view specific.
727
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
728
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
729
-        // is a good use case. Notice the late priority we're giving these
730
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
731
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
732
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
733
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
734
-        }
735
-        // admin footer scripts
736
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
737
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
738
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
739
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
740
-        }
741
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
742
-        // targeted hook
743
-        do_action(
744
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
745
-        );
746
-    }
747
-
748
-
749
-    /**
750
-     * _set_defaults
751
-     * This sets some global defaults for class properties.
752
-     */
753
-    private function _set_defaults()
754
-    {
755
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
756
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
757
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
758
-        $this->_page_config          = $this->_default_route_query_args = [];
759
-        $this->_default_nav_tab_name = 'overview';
760
-        // init template args
761
-        $this->_template_args = [
762
-            'admin_page_header'  => '',
763
-            'admin_page_content' => '',
764
-            'post_body_content'  => '',
765
-            'before_list_table'  => '',
766
-            'after_list_table'   => '',
767
-        ];
768
-    }
769
-
770
-
771
-    /**
772
-     * route_admin_request
773
-     *
774
-     * @return void
775
-     * @throws InvalidArgumentException
776
-     * @throws InvalidInterfaceException
777
-     * @throws InvalidDataTypeException
778
-     * @throws EE_Error
779
-     * @throws ReflectionException
780
-     * @see    _route_admin_request()
781
-     */
782
-    public function route_admin_request()
783
-    {
784
-        try {
785
-            $this->_route_admin_request();
786
-        } catch (EE_Error $e) {
787
-            $e->get_error();
788
-        }
789
-    }
790
-
791
-
792
-    public function set_wp_page_slug($wp_page_slug)
793
-    {
794
-        $this->_wp_page_slug = $wp_page_slug;
795
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
796
-        if (is_network_admin()) {
797
-            $this->_wp_page_slug .= '-network';
798
-        }
799
-    }
800
-
801
-
802
-    /**
803
-     * _verify_routes
804
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
805
-     * we know if we need to drop out.
806
-     *
807
-     * @return bool
808
-     * @throws EE_Error
809
-     */
810
-    protected function _verify_routes()
811
-    {
812
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
813
-        if (! $this->_current_page && ! $this->request->isAjax()) {
814
-            return false;
815
-        }
816
-        $this->_route = false;
817
-        // check that the page_routes array is not empty
818
-        if (empty($this->_page_routes)) {
819
-            // user error msg
820
-            $error_msg = sprintf(
821
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
822
-                $this->_admin_page_title
823
-            );
824
-            // developer error msg
825
-            $error_msg .= '||' . $error_msg
826
-                          . esc_html__(
827
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
828
-                              'event_espresso'
829
-                          );
830
-            throw new EE_Error($error_msg);
831
-        }
832
-        // and that the requested page route exists
833
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
834
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
835
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
836
-                ? $this->_page_config[ $this->_req_action ]
837
-                : [];
838
-        } else {
839
-            // user error msg
840
-            $error_msg = sprintf(
841
-                esc_html__(
842
-                    'The requested page route does not exist for the %s admin page.',
843
-                    'event_espresso'
844
-                ),
845
-                $this->_admin_page_title
846
-            );
847
-            // developer error msg
848
-            $error_msg .= '||' . $error_msg
849
-                          . sprintf(
850
-                              esc_html__(
851
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
852
-                                  'event_espresso'
853
-                              ),
854
-                              $this->_req_action
855
-                          );
856
-            throw new EE_Error($error_msg);
857
-        }
858
-        // and that a default route exists
859
-        if (! array_key_exists('default', $this->_page_routes)) {
860
-            // user error msg
861
-            $error_msg = sprintf(
862
-                esc_html__(
863
-                    'A default page route has not been set for the % admin page.',
864
-                    'event_espresso'
865
-                ),
866
-                $this->_admin_page_title
867
-            );
868
-            // developer error msg
869
-            $error_msg .= '||' . $error_msg
870
-                          . esc_html__(
871
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
872
-                              'event_espresso'
873
-                          );
874
-            throw new EE_Error($error_msg);
875
-        }
876
-        // first lets' catch if the UI request has EVER been set.
877
-        if ($this->_is_UI_request === null) {
878
-            // lets set if this is a UI request or not.
879
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
880
-            // wait a minute... we might have a noheader in the route array
881
-            $this->_is_UI_request = ! (
882
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
883
-            )
884
-                ? $this->_is_UI_request
885
-                : false;
886
-        }
887
-        $this->_set_current_labels();
888
-        return true;
889
-    }
890
-
891
-
892
-    /**
893
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
894
-     *
895
-     * @param string $route the route name we're verifying
896
-     * @return bool we'll throw an exception if this isn't a valid route.
897
-     * @throws EE_Error
898
-     */
899
-    protected function _verify_route($route)
900
-    {
901
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
902
-            return true;
903
-        }
904
-        // user error msg
905
-        $error_msg = sprintf(
906
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
907
-            $this->_admin_page_title
908
-        );
909
-        // developer error msg
910
-        $error_msg .= '||' . $error_msg
911
-                      . sprintf(
912
-                          esc_html__(
913
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
914
-                              'event_espresso'
915
-                          ),
916
-                          $route
917
-                      );
918
-        throw new EE_Error($error_msg);
919
-    }
920
-
921
-
922
-    /**
923
-     * perform nonce verification
924
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
925
-     * using this method (and save retyping!)
926
-     *
927
-     * @param string $nonce     The nonce sent
928
-     * @param string $nonce_ref The nonce reference string (name0)
929
-     * @return void
930
-     * @throws EE_Error
931
-     */
932
-    protected function _verify_nonce($nonce, $nonce_ref)
933
-    {
934
-        // verify nonce against expected value
935
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
936
-            // these are not the droids you are looking for !!!
937
-            $msg = sprintf(
938
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
939
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
940
-                '</a>'
941
-            );
942
-            if (WP_DEBUG) {
943
-                $msg .= "\n  ";
944
-                $msg .= sprintf(
945
-                    esc_html__(
946
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
947
-                        'event_espresso'
948
-                    ),
949
-                    __CLASS__
950
-                );
951
-            }
952
-            if (! $this->request->isAjax()) {
953
-                wp_die($msg);
954
-            }
955
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
956
-            $this->_return_json();
957
-        }
958
-    }
959
-
960
-
961
-    /**
962
-     * _route_admin_request()
963
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
964
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
965
-     * in the page routes and then will try to load the corresponding method.
966
-     *
967
-     * @return void
968
-     * @throws EE_Error
969
-     * @throws InvalidArgumentException
970
-     * @throws InvalidDataTypeException
971
-     * @throws InvalidInterfaceException
972
-     * @throws ReflectionException
973
-     */
974
-    protected function _route_admin_request()
975
-    {
976
-        if (! $this->_is_UI_request) {
977
-            $this->_verify_routes();
978
-        }
979
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
980
-        if ($this->_req_action !== 'default' && $nonce_check) {
981
-            // set nonce from post data
982
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
983
-            $this->_verify_nonce($nonce, $this->_req_nonce);
984
-        }
985
-        // set the nav_tabs array but ONLY if this is  UI_request
986
-        if ($this->_is_UI_request) {
987
-            $this->_set_nav_tabs();
988
-        }
989
-        // grab callback function
990
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
991
-        // check if callback has args
992
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
993
-        $error_msg = '';
994
-        // action right before calling route
995
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
996
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
997
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
998
-        }
999
-        // right before calling the route, let's clean the _wp_http_referer
1000
-        $this->request->unSetRequestParam('_wp_http_referer');
1001
-        $this->request->unSetServerParam('_wp_http_referer');
1002
-        $cleaner_request_uri = remove_query_arg(
1003
-            '_wp_http_referer',
1004
-            wp_unslash($this->request->getServerParam('REQUEST_URI'))
1005
-        );
1006
-        $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri);
1007
-        $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri);
1008
-        if (! empty($func)) {
1009
-            if (is_array($func)) {
1010
-                [$class, $method] = $func;
1011
-            } elseif (strpos($func, '::') !== false) {
1012
-                [$class, $method] = explode('::', $func);
1013
-            } else {
1014
-                $class  = $this;
1015
-                $method = $func;
1016
-            }
1017
-            if (! (is_object($class) && $class === $this)) {
1018
-                // send along this admin page object for access by addons.
1019
-                $args['admin_page_object'] = $this;
1020
-            }
1021
-            if (
1022
-                // is it a method on a class that doesn't work?
1023
-                (
1024
-                    (
1025
-                        method_exists($class, $method)
1026
-                        && call_user_func_array([$class, $method], $args) === false
1027
-                    )
1028
-                    && (
1029
-                        // is it a standalone function that doesn't work?
1030
-                        function_exists($method)
1031
-                        && call_user_func_array(
1032
-                            $func,
1033
-                            array_merge(['admin_page_object' => $this], $args)
1034
-                        ) === false
1035
-                    )
1036
-                )
1037
-                || (
1038
-                    // is it neither a class method NOR a standalone function?
1039
-                    ! method_exists($class, $method)
1040
-                    && ! function_exists($method)
1041
-                )
1042
-            ) {
1043
-                // user error msg
1044
-                $error_msg = esc_html__(
1045
-                    'An error occurred. The  requested page route could not be found.',
1046
-                    'event_espresso'
1047
-                );
1048
-                // developer error msg
1049
-                $error_msg .= '||';
1050
-                $error_msg .= sprintf(
1051
-                    esc_html__(
1052
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1053
-                        'event_espresso'
1054
-                    ),
1055
-                    $method
1056
-                );
1057
-            }
1058
-            if (! empty($error_msg)) {
1059
-                throw new EE_Error($error_msg);
1060
-            }
1061
-        }
1062
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1063
-        // then we need to reset the routing properties to the new route.
1064
-        // 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.
1065
-        if (
1066
-            $this->_is_UI_request === false
1067
-            && is_array($this->_route)
1068
-            && ! empty($this->_route['headers_sent_route'])
1069
-        ) {
1070
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1071
-        }
1072
-    }
1073
-
1074
-
1075
-    /**
1076
-     * This method just allows the resetting of page properties in the case where a no headers
1077
-     * route redirects to a headers route in its route config.
1078
-     *
1079
-     * @param string $new_route New (non header) route to redirect to.
1080
-     * @return   void
1081
-     * @throws ReflectionException
1082
-     * @throws InvalidArgumentException
1083
-     * @throws InvalidInterfaceException
1084
-     * @throws InvalidDataTypeException
1085
-     * @throws EE_Error
1086
-     * @since   4.3.0
1087
-     */
1088
-    protected function _reset_routing_properties($new_route)
1089
-    {
1090
-        $this->_is_UI_request = true;
1091
-        // now we set the current route to whatever the headers_sent_route is set at
1092
-        $this->request->setRequestParam('action', $new_route);
1093
-        // rerun page setup
1094
-        $this->_page_setup();
1095
-    }
1096
-
1097
-
1098
-    /**
1099
-     * _add_query_arg
1100
-     * adds nonce to array of arguments then calls WP add_query_arg function
1101
-     *(internally just uses EEH_URL's function with the same name)
1102
-     *
1103
-     * @param array  $args
1104
-     * @param string $url
1105
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1106
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1107
-     *                                        Example usage: If the current page is:
1108
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1109
-     *                                        &action=default&event_id=20&month_range=March%202015
1110
-     *                                        &_wpnonce=5467821
1111
-     *                                        and you call:
1112
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1113
-     *                                        array(
1114
-     *                                        'action' => 'resend_something',
1115
-     *                                        'page=>espresso_registrations'
1116
-     *                                        ),
1117
-     *                                        $some_url,
1118
-     *                                        true
1119
-     *                                        );
1120
-     *                                        It will produce a url in this structure:
1121
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1122
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1123
-     *                                        month_range]=March%202015
1124
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1125
-     * @return string
1126
-     */
1127
-    public static function add_query_args_and_nonce(
1128
-        $args = [],
1129
-        $url = false,
1130
-        $sticky = false,
1131
-        $exclude_nonce = false
1132
-    ) {
1133
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1134
-        if ($sticky) {
1135
-            /** @var RequestInterface $request */
1136
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1137
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1138
-            foreach ($request->requestParams() as $key => $value) {
1139
-                // do not add nonces
1140
-                if (strpos($key, 'nonce') !== false) {
1141
-                    continue;
1142
-                }
1143
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1144
-            }
1145
-        }
1146
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1147
-    }
1148
-
1149
-
1150
-    /**
1151
-     * This returns a generated link that will load the related help tab.
1152
-     *
1153
-     * @param string $help_tab_id the id for the connected help tab
1154
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1155
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1156
-     * @return string              generated link
1157
-     * @uses EEH_Template::get_help_tab_link()
1158
-     */
1159
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1160
-    {
1161
-        return EEH_Template::get_help_tab_link(
1162
-            $help_tab_id,
1163
-            $this->page_slug,
1164
-            $this->_req_action,
1165
-            $icon_style,
1166
-            $help_text
1167
-        );
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * _add_help_tabs
1173
-     * Note child classes define their help tabs within the page_config array.
1174
-     *
1175
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1176
-     * @return void
1177
-     * @throws DomainException
1178
-     * @throws EE_Error
1179
-     */
1180
-    protected function _add_help_tabs()
1181
-    {
1182
-        if (isset($this->_page_config[ $this->_req_action ])) {
1183
-            $config = $this->_page_config[ $this->_req_action ];
1184
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1185
-            if (is_array($config) && isset($config['help_sidebar'])) {
1186
-                // check that the callback given is valid
1187
-                if (! method_exists($this, $config['help_sidebar'])) {
1188
-                    throw new EE_Error(
1189
-                        sprintf(
1190
-                            esc_html__(
1191
-                                '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',
1192
-                                'event_espresso'
1193
-                            ),
1194
-                            $config['help_sidebar'],
1195
-                            get_class($this)
1196
-                        )
1197
-                    );
1198
-                }
1199
-                $content = apply_filters(
1200
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1201
-                    $this->{$config['help_sidebar']}()
1202
-                );
1203
-                $this->_current_screen->set_help_sidebar($content);
1204
-            }
1205
-            if (! isset($config['help_tabs'])) {
1206
-                return;
1207
-            } //no help tabs for this route
1208
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1209
-                // we're here so there ARE help tabs!
1210
-                // make sure we've got what we need
1211
-                if (! isset($cfg['title'])) {
1212
-                    throw new EE_Error(
1213
-                        esc_html__(
1214
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1215
-                            'event_espresso'
1216
-                        )
1217
-                    );
1218
-                }
1219
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1220
-                    throw new EE_Error(
1221
-                        esc_html__(
1222
-                            '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
-                            'event_espresso'
1224
-                        )
1225
-                    );
1226
-                }
1227
-                // first priority goes to content.
1228
-                if (! empty($cfg['content'])) {
1229
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1230
-                    // second priority goes to filename
1231
-                } elseif (! empty($cfg['filename'])) {
1232
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1233
-                    // 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)
1234
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1235
-                                                             . basename($this->_get_dir())
1236
-                                                             . '/help_tabs/'
1237
-                                                             . $cfg['filename']
1238
-                                                             . '.help_tab.php' : $file_path;
1239
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1240
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1241
-                        EE_Error::add_error(
1242
-                            sprintf(
1243
-                                esc_html__(
1244
-                                    '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',
1245
-                                    'event_espresso'
1246
-                                ),
1247
-                                $tab_id,
1248
-                                key($config),
1249
-                                $file_path
1250
-                            ),
1251
-                            __FILE__,
1252
-                            __FUNCTION__,
1253
-                            __LINE__
1254
-                        );
1255
-                        return;
1256
-                    }
1257
-                    $template_args['admin_page_obj'] = $this;
1258
-                    $content                         = EEH_Template::display_template(
1259
-                        $file_path,
1260
-                        $template_args,
1261
-                        true
1262
-                    );
1263
-                } else {
1264
-                    $content = '';
1265
-                }
1266
-                // check if callback is valid
1267
-                if (
1268
-                    empty($content)
1269
-                    && (
1270
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1271
-                    )
1272
-                ) {
1273
-                    EE_Error::add_error(
1274
-                        sprintf(
1275
-                            esc_html__(
1276
-                                '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.',
1277
-                                'event_espresso'
1278
-                            ),
1279
-                            $cfg['title']
1280
-                        ),
1281
-                        __FILE__,
1282
-                        __FUNCTION__,
1283
-                        __LINE__
1284
-                    );
1285
-                    return;
1286
-                }
1287
-                // setup config array for help tab method
1288
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1289
-                $_ht = [
1290
-                    'id'       => $id,
1291
-                    'title'    => $cfg['title'],
1292
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1293
-                    'content'  => $content,
1294
-                ];
1295
-                $this->_current_screen->add_help_tab($_ht);
1296
-            }
1297
-        }
1298
-    }
1299
-
1300
-
1301
-    /**
1302
-     * This simply sets up any qtips that have been defined in the page config
1303
-     *
1304
-     * @return void
1305
-     */
1306
-    protected function _add_qtips()
1307
-    {
1308
-        if (isset($this->_route_config['qtips'])) {
1309
-            $qtips = (array) $this->_route_config['qtips'];
1310
-            // load qtip loader
1311
-            $path = [
1312
-                $this->_get_dir() . '/qtips/',
1313
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1314
-            ];
1315
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1316
-        }
1317
-    }
1318
-
1319
-
1320
-    /**
1321
-     * _set_nav_tabs
1322
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1323
-     * wish to add additional tabs or modify accordingly.
1324
-     *
1325
-     * @return void
1326
-     * @throws InvalidArgumentException
1327
-     * @throws InvalidInterfaceException
1328
-     * @throws InvalidDataTypeException
1329
-     */
1330
-    protected function _set_nav_tabs()
1331
-    {
1332
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1333
-        $i = 0;
1334
-        foreach ($this->_page_config as $slug => $config) {
1335
-            if (! is_array($config) || empty($config['nav'])) {
1336
-                continue;
1337
-            }
1338
-            // no nav tab for this config
1339
-            // check for persistent flag
1340
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1341
-                // nav tab is only to appear when route requested.
1342
-                continue;
1343
-            }
1344
-            if (! $this->check_user_access($slug, true)) {
1345
-                // no nav tab because current user does not have access.
1346
-                continue;
1347
-            }
1348
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1349
-            $this->_nav_tabs[ $slug ] = [
1350
-                'url'       => isset($config['nav']['url'])
1351
-                    ? $config['nav']['url']
1352
-                    : self::add_query_args_and_nonce(
1353
-                        ['action' => $slug],
1354
-                        $this->_admin_base_url
1355
-                    ),
1356
-                'link_text' => isset($config['nav']['label'])
1357
-                    ? $config['nav']['label']
1358
-                    : ucwords(
1359
-                        str_replace('_', ' ', $slug)
1360
-                    ),
1361
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1362
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1363
-            ];
1364
-            $i++;
1365
-        }
1366
-        // if $this->_nav_tabs is empty then lets set the default
1367
-        if (empty($this->_nav_tabs)) {
1368
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1369
-                'url'       => $this->_admin_base_url,
1370
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1371
-                'css_class' => 'nav-tab-active',
1372
-                'order'     => 10,
1373
-            ];
1374
-        }
1375
-        // now let's sort the tabs according to order
1376
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1377
-    }
1378
-
1379
-
1380
-    /**
1381
-     * _set_current_labels
1382
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1383
-     * property array
1384
-     *
1385
-     * @return void
1386
-     */
1387
-    private function _set_current_labels()
1388
-    {
1389
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1390
-            foreach ($this->_route_config['labels'] as $label => $text) {
1391
-                if (is_array($text)) {
1392
-                    foreach ($text as $sublabel => $subtext) {
1393
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1394
-                    }
1395
-                } else {
1396
-                    $this->_labels[ $label ] = $text;
1397
-                }
1398
-            }
1399
-        }
1400
-    }
1401
-
1402
-
1403
-    /**
1404
-     *        verifies user access for this admin page
1405
-     *
1406
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1407
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1408
-     *                               return false if verify fail.
1409
-     * @return bool
1410
-     * @throws InvalidArgumentException
1411
-     * @throws InvalidDataTypeException
1412
-     * @throws InvalidInterfaceException
1413
-     */
1414
-    public function check_user_access($route_to_check = '', $verify_only = false)
1415
-    {
1416
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1417
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1418
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1419
-                          && is_array(
1420
-                              $this->_page_routes[ $route_to_check ]
1421
-                          )
1422
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1423
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1424
-        if (empty($capability) && empty($route_to_check)) {
1425
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1426
-                : $this->_route['capability'];
1427
-        } else {
1428
-            $capability = empty($capability) ? 'manage_options' : $capability;
1429
-        }
1430
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1431
-        if (
1432
-            ! $this->request->isAjax()
1433
-            && (
1434
-                ! function_exists('is_admin')
1435
-                || ! EE_Registry::instance()->CAP->current_user_can(
1436
-                    $capability,
1437
-                    $this->page_slug
1438
-                    . '_'
1439
-                    . $route_to_check,
1440
-                    $id
1441
-                )
1442
-            )
1443
-        ) {
1444
-            if ($verify_only) {
1445
-                return false;
1446
-            }
1447
-            if (is_user_logged_in()) {
1448
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1449
-            } else {
1450
-                return false;
1451
-            }
1452
-        }
1453
-        return true;
1454
-    }
1455
-
1456
-
1457
-    /**
1458
-     * admin_init_global
1459
-     * This runs all the code that we want executed within the WP admin_init hook.
1460
-     * This method executes for ALL EE Admin pages.
1461
-     *
1462
-     * @return void
1463
-     */
1464
-    public function admin_init_global()
1465
-    {
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * wp_loaded_global
1471
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1472
-     * EE_Admin page and will execute on every EE Admin Page load
1473
-     *
1474
-     * @return void
1475
-     */
1476
-    public function wp_loaded()
1477
-    {
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * admin_notices
1483
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1484
-     * ALL EE_Admin pages.
1485
-     *
1486
-     * @return void
1487
-     */
1488
-    public function admin_notices_global()
1489
-    {
1490
-        $this->_display_no_javascript_warning();
1491
-        $this->_display_espresso_notices();
1492
-    }
1493
-
1494
-
1495
-    public function network_admin_notices_global()
1496
-    {
1497
-        $this->_display_no_javascript_warning();
1498
-        $this->_display_espresso_notices();
1499
-    }
1500
-
1501
-
1502
-    /**
1503
-     * admin_footer_scripts_global
1504
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1505
-     * will apply on ALL EE_Admin pages.
1506
-     *
1507
-     * @return void
1508
-     */
1509
-    public function admin_footer_scripts_global()
1510
-    {
1511
-        $this->_add_admin_page_ajax_loading_img();
1512
-        $this->_add_admin_page_overlay();
1513
-        // if metaboxes are present we need to add the nonce field
1514
-        if (
1515
-            isset($this->_route_config['metaboxes'])
1516
-            || isset($this->_route_config['list_table'])
1517
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1518
-        ) {
1519
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1520
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1521
-        }
1522
-    }
1523
-
1524
-
1525
-    /**
1526
-     * admin_footer_global
1527
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1528
-     * ALL EE_Admin Pages.
1529
-     *
1530
-     * @return void
1531
-     */
1532
-    public function admin_footer_global()
1533
-    {
1534
-        // dialog container for dialog helper
1535
-        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->_current_page = $this->request->getRequestParam('current_page', $this->_current_page, 'key');
510
+
511
+		$this->page_folder   = strtolower(
512
+			str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
513
+		);
514
+		global $ee_menu_slugs;
515
+		$ee_menu_slugs = (array) $ee_menu_slugs;
516
+		if (
517
+			! $this->request->isAjax()
518
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
519
+		) {
520
+			return;
521
+		}
522
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
523
+		// we need to copy the action from the second to the first
524
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
525
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
526
+		$action     = $action !== '-1' ? $action : $action2;
527
+		$req_action = $action !== '-1' ? $action : 'default';
528
+
529
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
530
+		// then let's use the route as the action.
531
+		// This covers cases where we're coming in from a list table that isn't on the default route.
532
+		$route = $this->request->getRequestParam('route');
533
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
534
+			? $route
535
+			: $req_action;
536
+
537
+		$this->_current_view = $this->_req_action;
538
+		$this->_req_nonce    = $this->_req_action . '_nonce';
539
+		$this->_define_page_props();
540
+		$this->_current_page_view_url = add_query_arg(
541
+			['page' => $this->_current_page, 'action' => $this->_current_view],
542
+			$this->_admin_base_url
543
+		);
544
+		// default things
545
+		$this->_default_espresso_metaboxes = [
546
+			'_espresso_news_post_box',
547
+			'_espresso_links_post_box',
548
+			'_espresso_ratings_request',
549
+			'_espresso_sponsors_post_box',
550
+		];
551
+		// set page configs
552
+		$this->_set_page_routes();
553
+		$this->_set_page_config();
554
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
555
+		if ($this->request->requestParamIsSet('wp_referer')) {
556
+			$wp_referer = $this->request->getRequestParam('wp_referer');
557
+			if ($wp_referer) {
558
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
559
+			}
560
+		}
561
+		// for caffeinated and other extended functionality.
562
+		//  If there is a _extend_page_config method
563
+		// then let's run that to modify the all the various page configuration arrays
564
+		if (method_exists($this, '_extend_page_config')) {
565
+			$this->_extend_page_config();
566
+		}
567
+		// for CPT and other extended functionality.
568
+		// If there is an _extend_page_config_for_cpt
569
+		// then let's run that to modify all the various page configuration arrays.
570
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
571
+			$this->_extend_page_config_for_cpt();
572
+		}
573
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
574
+		$this->_page_routes = apply_filters(
575
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
576
+			$this->_page_routes,
577
+			$this
578
+		);
579
+		$this->_page_config = apply_filters(
580
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
581
+			$this->_page_config,
582
+			$this
583
+		);
584
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
585
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
586
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
587
+			add_action(
588
+				'AHEE__EE_Admin_Page__route_admin_request',
589
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
590
+				10,
591
+				2
592
+			);
593
+		}
594
+		// next route only if routing enabled
595
+		if ($this->_routing && ! $this->request->isAjax()) {
596
+			$this->_verify_routes();
597
+			// next let's just check user_access and kill if no access
598
+			$this->check_user_access();
599
+			if ($this->_is_UI_request) {
600
+				// admin_init stuff - global, all views for this page class, specific view
601
+				add_action('admin_init', [$this, 'admin_init'], 10);
602
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
603
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
604
+				}
605
+			} else {
606
+				// hijack regular WP loading and route admin request immediately
607
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
608
+				$this->route_admin_request();
609
+			}
610
+		}
611
+	}
612
+
613
+
614
+	/**
615
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
616
+	 *
617
+	 * @return void
618
+	 * @throws EE_Error
619
+	 */
620
+	private function _do_other_page_hooks()
621
+	{
622
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
623
+		foreach ($registered_pages as $page) {
624
+			// now let's setup the file name and class that should be present
625
+			$classname = str_replace('.class.php', '', $page);
626
+			// autoloaders should take care of loading file
627
+			if (! class_exists($classname)) {
628
+				$error_msg[] = sprintf(
629
+					esc_html__(
630
+						'Something went wrong with loading the %s admin hooks page.',
631
+						'event_espresso'
632
+					),
633
+					$page
634
+				);
635
+				$error_msg[] = $error_msg[0]
636
+							   . "\r\n"
637
+							   . sprintf(
638
+								   esc_html__(
639
+									   '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',
640
+									   'event_espresso'
641
+								   ),
642
+								   $page,
643
+								   '<br />',
644
+								   '<strong>' . $classname . '</strong>'
645
+							   );
646
+				throw new EE_Error(implode('||', $error_msg));
647
+			}
648
+			// notice we are passing the instance of this class to the hook object.
649
+			$this->loader->getShared($classname, [$this]);
650
+		}
651
+	}
652
+
653
+
654
+	/**
655
+	 * @throws ReflectionException
656
+	 * @throws EE_Error
657
+	 */
658
+	public function load_page_dependencies()
659
+	{
660
+		try {
661
+			$this->_load_page_dependencies();
662
+		} catch (EE_Error $e) {
663
+			$e->get_error();
664
+		}
665
+	}
666
+
667
+
668
+	/**
669
+	 * load_page_dependencies
670
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
671
+	 *
672
+	 * @return void
673
+	 * @throws DomainException
674
+	 * @throws EE_Error
675
+	 * @throws InvalidArgumentException
676
+	 * @throws InvalidDataTypeException
677
+	 * @throws InvalidInterfaceException
678
+	 */
679
+	protected function _load_page_dependencies()
680
+	{
681
+		// let's set the current_screen and screen options to override what WP set
682
+		$this->_current_screen = get_current_screen();
683
+		// load admin_notices - global, page class, and view specific
684
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
685
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
686
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
687
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
688
+		}
689
+		// load network admin_notices - global, page class, and view specific
690
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
691
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
692
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
693
+		}
694
+		// this will save any per_page screen options if they are present
695
+		$this->_set_per_page_screen_options();
696
+		// setup list table properties
697
+		$this->_set_list_table();
698
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
699
+		// However in some cases the metaboxes will need to be added within a route handling callback.
700
+		$this->_add_registered_meta_boxes();
701
+		$this->_add_screen_columns();
702
+		// add screen options - global, page child class, and view specific
703
+		$this->_add_global_screen_options();
704
+		$this->_add_screen_options();
705
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
706
+		if (method_exists($this, $add_screen_options)) {
707
+			$this->{$add_screen_options}();
708
+		}
709
+		// add help tab(s) - set via page_config and qtips.
710
+		$this->_add_help_tabs();
711
+		$this->_add_qtips();
712
+		// add feature_pointers - global, page child class, and view specific
713
+		$this->_add_feature_pointers();
714
+		$this->_add_global_feature_pointers();
715
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
716
+		if (method_exists($this, $add_feature_pointer)) {
717
+			$this->{$add_feature_pointer}();
718
+		}
719
+		// enqueue scripts/styles - global, page class, and view specific
720
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
721
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
722
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
723
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
724
+		}
725
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
726
+		// admin_print_footer_scripts - global, page child class, and view specific.
727
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
728
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
729
+		// is a good use case. Notice the late priority we're giving these
730
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
731
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
732
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
733
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
734
+		}
735
+		// admin footer scripts
736
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
737
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
738
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
739
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
740
+		}
741
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
742
+		// targeted hook
743
+		do_action(
744
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
745
+		);
746
+	}
747
+
748
+
749
+	/**
750
+	 * _set_defaults
751
+	 * This sets some global defaults for class properties.
752
+	 */
753
+	private function _set_defaults()
754
+	{
755
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
756
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
757
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
758
+		$this->_page_config          = $this->_default_route_query_args = [];
759
+		$this->_default_nav_tab_name = 'overview';
760
+		// init template args
761
+		$this->_template_args = [
762
+			'admin_page_header'  => '',
763
+			'admin_page_content' => '',
764
+			'post_body_content'  => '',
765
+			'before_list_table'  => '',
766
+			'after_list_table'   => '',
767
+		];
768
+	}
769
+
770
+
771
+	/**
772
+	 * route_admin_request
773
+	 *
774
+	 * @return void
775
+	 * @throws InvalidArgumentException
776
+	 * @throws InvalidInterfaceException
777
+	 * @throws InvalidDataTypeException
778
+	 * @throws EE_Error
779
+	 * @throws ReflectionException
780
+	 * @see    _route_admin_request()
781
+	 */
782
+	public function route_admin_request()
783
+	{
784
+		try {
785
+			$this->_route_admin_request();
786
+		} catch (EE_Error $e) {
787
+			$e->get_error();
788
+		}
789
+	}
790
+
791
+
792
+	public function set_wp_page_slug($wp_page_slug)
793
+	{
794
+		$this->_wp_page_slug = $wp_page_slug;
795
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
796
+		if (is_network_admin()) {
797
+			$this->_wp_page_slug .= '-network';
798
+		}
799
+	}
800
+
801
+
802
+	/**
803
+	 * _verify_routes
804
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
805
+	 * we know if we need to drop out.
806
+	 *
807
+	 * @return bool
808
+	 * @throws EE_Error
809
+	 */
810
+	protected function _verify_routes()
811
+	{
812
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
813
+		if (! $this->_current_page && ! $this->request->isAjax()) {
814
+			return false;
815
+		}
816
+		$this->_route = false;
817
+		// check that the page_routes array is not empty
818
+		if (empty($this->_page_routes)) {
819
+			// user error msg
820
+			$error_msg = sprintf(
821
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
822
+				$this->_admin_page_title
823
+			);
824
+			// developer error msg
825
+			$error_msg .= '||' . $error_msg
826
+						  . esc_html__(
827
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
828
+							  'event_espresso'
829
+						  );
830
+			throw new EE_Error($error_msg);
831
+		}
832
+		// and that the requested page route exists
833
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
834
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
835
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
836
+				? $this->_page_config[ $this->_req_action ]
837
+				: [];
838
+		} else {
839
+			// user error msg
840
+			$error_msg = sprintf(
841
+				esc_html__(
842
+					'The requested page route does not exist for the %s admin page.',
843
+					'event_espresso'
844
+				),
845
+				$this->_admin_page_title
846
+			);
847
+			// developer error msg
848
+			$error_msg .= '||' . $error_msg
849
+						  . sprintf(
850
+							  esc_html__(
851
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
852
+								  'event_espresso'
853
+							  ),
854
+							  $this->_req_action
855
+						  );
856
+			throw new EE_Error($error_msg);
857
+		}
858
+		// and that a default route exists
859
+		if (! array_key_exists('default', $this->_page_routes)) {
860
+			// user error msg
861
+			$error_msg = sprintf(
862
+				esc_html__(
863
+					'A default page route has not been set for the % admin page.',
864
+					'event_espresso'
865
+				),
866
+				$this->_admin_page_title
867
+			);
868
+			// developer error msg
869
+			$error_msg .= '||' . $error_msg
870
+						  . esc_html__(
871
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
872
+							  'event_espresso'
873
+						  );
874
+			throw new EE_Error($error_msg);
875
+		}
876
+		// first lets' catch if the UI request has EVER been set.
877
+		if ($this->_is_UI_request === null) {
878
+			// lets set if this is a UI request or not.
879
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
880
+			// wait a minute... we might have a noheader in the route array
881
+			$this->_is_UI_request = ! (
882
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
883
+			)
884
+				? $this->_is_UI_request
885
+				: false;
886
+		}
887
+		$this->_set_current_labels();
888
+		return true;
889
+	}
890
+
891
+
892
+	/**
893
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
894
+	 *
895
+	 * @param string $route the route name we're verifying
896
+	 * @return bool we'll throw an exception if this isn't a valid route.
897
+	 * @throws EE_Error
898
+	 */
899
+	protected function _verify_route($route)
900
+	{
901
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
902
+			return true;
903
+		}
904
+		// user error msg
905
+		$error_msg = sprintf(
906
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
907
+			$this->_admin_page_title
908
+		);
909
+		// developer error msg
910
+		$error_msg .= '||' . $error_msg
911
+					  . sprintf(
912
+						  esc_html__(
913
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
914
+							  'event_espresso'
915
+						  ),
916
+						  $route
917
+					  );
918
+		throw new EE_Error($error_msg);
919
+	}
920
+
921
+
922
+	/**
923
+	 * perform nonce verification
924
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
925
+	 * using this method (and save retyping!)
926
+	 *
927
+	 * @param string $nonce     The nonce sent
928
+	 * @param string $nonce_ref The nonce reference string (name0)
929
+	 * @return void
930
+	 * @throws EE_Error
931
+	 */
932
+	protected function _verify_nonce($nonce, $nonce_ref)
933
+	{
934
+		// verify nonce against expected value
935
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
936
+			// these are not the droids you are looking for !!!
937
+			$msg = sprintf(
938
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
939
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
940
+				'</a>'
941
+			);
942
+			if (WP_DEBUG) {
943
+				$msg .= "\n  ";
944
+				$msg .= sprintf(
945
+					esc_html__(
946
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
947
+						'event_espresso'
948
+					),
949
+					__CLASS__
950
+				);
951
+			}
952
+			if (! $this->request->isAjax()) {
953
+				wp_die($msg);
954
+			}
955
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
956
+			$this->_return_json();
957
+		}
958
+	}
959
+
960
+
961
+	/**
962
+	 * _route_admin_request()
963
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
964
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
965
+	 * in the page routes and then will try to load the corresponding method.
966
+	 *
967
+	 * @return void
968
+	 * @throws EE_Error
969
+	 * @throws InvalidArgumentException
970
+	 * @throws InvalidDataTypeException
971
+	 * @throws InvalidInterfaceException
972
+	 * @throws ReflectionException
973
+	 */
974
+	protected function _route_admin_request()
975
+	{
976
+		if (! $this->_is_UI_request) {
977
+			$this->_verify_routes();
978
+		}
979
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
980
+		if ($this->_req_action !== 'default' && $nonce_check) {
981
+			// set nonce from post data
982
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
983
+			$this->_verify_nonce($nonce, $this->_req_nonce);
984
+		}
985
+		// set the nav_tabs array but ONLY if this is  UI_request
986
+		if ($this->_is_UI_request) {
987
+			$this->_set_nav_tabs();
988
+		}
989
+		// grab callback function
990
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
991
+		// check if callback has args
992
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
993
+		$error_msg = '';
994
+		// action right before calling route
995
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
996
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
997
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
998
+		}
999
+		// right before calling the route, let's clean the _wp_http_referer
1000
+		$this->request->unSetRequestParam('_wp_http_referer');
1001
+		$this->request->unSetServerParam('_wp_http_referer');
1002
+		$cleaner_request_uri = remove_query_arg(
1003
+			'_wp_http_referer',
1004
+			wp_unslash($this->request->getServerParam('REQUEST_URI'))
1005
+		);
1006
+		$this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri);
1007
+		$this->request->setServerParam('REQUEST_URI', $cleaner_request_uri);
1008
+		if (! empty($func)) {
1009
+			if (is_array($func)) {
1010
+				[$class, $method] = $func;
1011
+			} elseif (strpos($func, '::') !== false) {
1012
+				[$class, $method] = explode('::', $func);
1013
+			} else {
1014
+				$class  = $this;
1015
+				$method = $func;
1016
+			}
1017
+			if (! (is_object($class) && $class === $this)) {
1018
+				// send along this admin page object for access by addons.
1019
+				$args['admin_page_object'] = $this;
1020
+			}
1021
+			if (
1022
+				// is it a method on a class that doesn't work?
1023
+				(
1024
+					(
1025
+						method_exists($class, $method)
1026
+						&& call_user_func_array([$class, $method], $args) === false
1027
+					)
1028
+					&& (
1029
+						// is it a standalone function that doesn't work?
1030
+						function_exists($method)
1031
+						&& call_user_func_array(
1032
+							$func,
1033
+							array_merge(['admin_page_object' => $this], $args)
1034
+						) === false
1035
+					)
1036
+				)
1037
+				|| (
1038
+					// is it neither a class method NOR a standalone function?
1039
+					! method_exists($class, $method)
1040
+					&& ! function_exists($method)
1041
+				)
1042
+			) {
1043
+				// user error msg
1044
+				$error_msg = esc_html__(
1045
+					'An error occurred. The  requested page route could not be found.',
1046
+					'event_espresso'
1047
+				);
1048
+				// developer error msg
1049
+				$error_msg .= '||';
1050
+				$error_msg .= sprintf(
1051
+					esc_html__(
1052
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1053
+						'event_espresso'
1054
+					),
1055
+					$method
1056
+				);
1057
+			}
1058
+			if (! empty($error_msg)) {
1059
+				throw new EE_Error($error_msg);
1060
+			}
1061
+		}
1062
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1063
+		// then we need to reset the routing properties to the new route.
1064
+		// 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.
1065
+		if (
1066
+			$this->_is_UI_request === false
1067
+			&& is_array($this->_route)
1068
+			&& ! empty($this->_route['headers_sent_route'])
1069
+		) {
1070
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1071
+		}
1072
+	}
1073
+
1074
+
1075
+	/**
1076
+	 * This method just allows the resetting of page properties in the case where a no headers
1077
+	 * route redirects to a headers route in its route config.
1078
+	 *
1079
+	 * @param string $new_route New (non header) route to redirect to.
1080
+	 * @return   void
1081
+	 * @throws ReflectionException
1082
+	 * @throws InvalidArgumentException
1083
+	 * @throws InvalidInterfaceException
1084
+	 * @throws InvalidDataTypeException
1085
+	 * @throws EE_Error
1086
+	 * @since   4.3.0
1087
+	 */
1088
+	protected function _reset_routing_properties($new_route)
1089
+	{
1090
+		$this->_is_UI_request = true;
1091
+		// now we set the current route to whatever the headers_sent_route is set at
1092
+		$this->request->setRequestParam('action', $new_route);
1093
+		// rerun page setup
1094
+		$this->_page_setup();
1095
+	}
1096
+
1097
+
1098
+	/**
1099
+	 * _add_query_arg
1100
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1101
+	 *(internally just uses EEH_URL's function with the same name)
1102
+	 *
1103
+	 * @param array  $args
1104
+	 * @param string $url
1105
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1106
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1107
+	 *                                        Example usage: If the current page is:
1108
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1109
+	 *                                        &action=default&event_id=20&month_range=March%202015
1110
+	 *                                        &_wpnonce=5467821
1111
+	 *                                        and you call:
1112
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1113
+	 *                                        array(
1114
+	 *                                        'action' => 'resend_something',
1115
+	 *                                        'page=>espresso_registrations'
1116
+	 *                                        ),
1117
+	 *                                        $some_url,
1118
+	 *                                        true
1119
+	 *                                        );
1120
+	 *                                        It will produce a url in this structure:
1121
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1122
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1123
+	 *                                        month_range]=March%202015
1124
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1125
+	 * @return string
1126
+	 */
1127
+	public static function add_query_args_and_nonce(
1128
+		$args = [],
1129
+		$url = false,
1130
+		$sticky = false,
1131
+		$exclude_nonce = false
1132
+	) {
1133
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1134
+		if ($sticky) {
1135
+			/** @var RequestInterface $request */
1136
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1137
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1138
+			foreach ($request->requestParams() as $key => $value) {
1139
+				// do not add nonces
1140
+				if (strpos($key, 'nonce') !== false) {
1141
+					continue;
1142
+				}
1143
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1144
+			}
1145
+		}
1146
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1147
+	}
1148
+
1149
+
1150
+	/**
1151
+	 * This returns a generated link that will load the related help tab.
1152
+	 *
1153
+	 * @param string $help_tab_id the id for the connected help tab
1154
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1155
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1156
+	 * @return string              generated link
1157
+	 * @uses EEH_Template::get_help_tab_link()
1158
+	 */
1159
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1160
+	{
1161
+		return EEH_Template::get_help_tab_link(
1162
+			$help_tab_id,
1163
+			$this->page_slug,
1164
+			$this->_req_action,
1165
+			$icon_style,
1166
+			$help_text
1167
+		);
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * _add_help_tabs
1173
+	 * Note child classes define their help tabs within the page_config array.
1174
+	 *
1175
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1176
+	 * @return void
1177
+	 * @throws DomainException
1178
+	 * @throws EE_Error
1179
+	 */
1180
+	protected function _add_help_tabs()
1181
+	{
1182
+		if (isset($this->_page_config[ $this->_req_action ])) {
1183
+			$config = $this->_page_config[ $this->_req_action ];
1184
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1185
+			if (is_array($config) && isset($config['help_sidebar'])) {
1186
+				// check that the callback given is valid
1187
+				if (! method_exists($this, $config['help_sidebar'])) {
1188
+					throw new EE_Error(
1189
+						sprintf(
1190
+							esc_html__(
1191
+								'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',
1192
+								'event_espresso'
1193
+							),
1194
+							$config['help_sidebar'],
1195
+							get_class($this)
1196
+						)
1197
+					);
1198
+				}
1199
+				$content = apply_filters(
1200
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1201
+					$this->{$config['help_sidebar']}()
1202
+				);
1203
+				$this->_current_screen->set_help_sidebar($content);
1204
+			}
1205
+			if (! isset($config['help_tabs'])) {
1206
+				return;
1207
+			} //no help tabs for this route
1208
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1209
+				// we're here so there ARE help tabs!
1210
+				// make sure we've got what we need
1211
+				if (! isset($cfg['title'])) {
1212
+					throw new EE_Error(
1213
+						esc_html__(
1214
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1215
+							'event_espresso'
1216
+						)
1217
+					);
1218
+				}
1219
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1220
+					throw new EE_Error(
1221
+						esc_html__(
1222
+							'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
+							'event_espresso'
1224
+						)
1225
+					);
1226
+				}
1227
+				// first priority goes to content.
1228
+				if (! empty($cfg['content'])) {
1229
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1230
+					// second priority goes to filename
1231
+				} elseif (! empty($cfg['filename'])) {
1232
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1233
+					// 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)
1234
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1235
+															 . basename($this->_get_dir())
1236
+															 . '/help_tabs/'
1237
+															 . $cfg['filename']
1238
+															 . '.help_tab.php' : $file_path;
1239
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1240
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1241
+						EE_Error::add_error(
1242
+							sprintf(
1243
+								esc_html__(
1244
+									'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',
1245
+									'event_espresso'
1246
+								),
1247
+								$tab_id,
1248
+								key($config),
1249
+								$file_path
1250
+							),
1251
+							__FILE__,
1252
+							__FUNCTION__,
1253
+							__LINE__
1254
+						);
1255
+						return;
1256
+					}
1257
+					$template_args['admin_page_obj'] = $this;
1258
+					$content                         = EEH_Template::display_template(
1259
+						$file_path,
1260
+						$template_args,
1261
+						true
1262
+					);
1263
+				} else {
1264
+					$content = '';
1265
+				}
1266
+				// check if callback is valid
1267
+				if (
1268
+					empty($content)
1269
+					&& (
1270
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1271
+					)
1272
+				) {
1273
+					EE_Error::add_error(
1274
+						sprintf(
1275
+							esc_html__(
1276
+								'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.',
1277
+								'event_espresso'
1278
+							),
1279
+							$cfg['title']
1280
+						),
1281
+						__FILE__,
1282
+						__FUNCTION__,
1283
+						__LINE__
1284
+					);
1285
+					return;
1286
+				}
1287
+				// setup config array for help tab method
1288
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1289
+				$_ht = [
1290
+					'id'       => $id,
1291
+					'title'    => $cfg['title'],
1292
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1293
+					'content'  => $content,
1294
+				];
1295
+				$this->_current_screen->add_help_tab($_ht);
1296
+			}
1297
+		}
1298
+	}
1299
+
1300
+
1301
+	/**
1302
+	 * This simply sets up any qtips that have been defined in the page config
1303
+	 *
1304
+	 * @return void
1305
+	 */
1306
+	protected function _add_qtips()
1307
+	{
1308
+		if (isset($this->_route_config['qtips'])) {
1309
+			$qtips = (array) $this->_route_config['qtips'];
1310
+			// load qtip loader
1311
+			$path = [
1312
+				$this->_get_dir() . '/qtips/',
1313
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1314
+			];
1315
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1316
+		}
1317
+	}
1318
+
1319
+
1320
+	/**
1321
+	 * _set_nav_tabs
1322
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1323
+	 * wish to add additional tabs or modify accordingly.
1324
+	 *
1325
+	 * @return void
1326
+	 * @throws InvalidArgumentException
1327
+	 * @throws InvalidInterfaceException
1328
+	 * @throws InvalidDataTypeException
1329
+	 */
1330
+	protected function _set_nav_tabs()
1331
+	{
1332
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1333
+		$i = 0;
1334
+		foreach ($this->_page_config as $slug => $config) {
1335
+			if (! is_array($config) || empty($config['nav'])) {
1336
+				continue;
1337
+			}
1338
+			// no nav tab for this config
1339
+			// check for persistent flag
1340
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1341
+				// nav tab is only to appear when route requested.
1342
+				continue;
1343
+			}
1344
+			if (! $this->check_user_access($slug, true)) {
1345
+				// no nav tab because current user does not have access.
1346
+				continue;
1347
+			}
1348
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1349
+			$this->_nav_tabs[ $slug ] = [
1350
+				'url'       => isset($config['nav']['url'])
1351
+					? $config['nav']['url']
1352
+					: self::add_query_args_and_nonce(
1353
+						['action' => $slug],
1354
+						$this->_admin_base_url
1355
+					),
1356
+				'link_text' => isset($config['nav']['label'])
1357
+					? $config['nav']['label']
1358
+					: ucwords(
1359
+						str_replace('_', ' ', $slug)
1360
+					),
1361
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1362
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1363
+			];
1364
+			$i++;
1365
+		}
1366
+		// if $this->_nav_tabs is empty then lets set the default
1367
+		if (empty($this->_nav_tabs)) {
1368
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1369
+				'url'       => $this->_admin_base_url,
1370
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1371
+				'css_class' => 'nav-tab-active',
1372
+				'order'     => 10,
1373
+			];
1374
+		}
1375
+		// now let's sort the tabs according to order
1376
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1377
+	}
1378
+
1379
+
1380
+	/**
1381
+	 * _set_current_labels
1382
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1383
+	 * property array
1384
+	 *
1385
+	 * @return void
1386
+	 */
1387
+	private function _set_current_labels()
1388
+	{
1389
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1390
+			foreach ($this->_route_config['labels'] as $label => $text) {
1391
+				if (is_array($text)) {
1392
+					foreach ($text as $sublabel => $subtext) {
1393
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1394
+					}
1395
+				} else {
1396
+					$this->_labels[ $label ] = $text;
1397
+				}
1398
+			}
1399
+		}
1400
+	}
1401
+
1402
+
1403
+	/**
1404
+	 *        verifies user access for this admin page
1405
+	 *
1406
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1407
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1408
+	 *                               return false if verify fail.
1409
+	 * @return bool
1410
+	 * @throws InvalidArgumentException
1411
+	 * @throws InvalidDataTypeException
1412
+	 * @throws InvalidInterfaceException
1413
+	 */
1414
+	public function check_user_access($route_to_check = '', $verify_only = false)
1415
+	{
1416
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1417
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1418
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1419
+						  && is_array(
1420
+							  $this->_page_routes[ $route_to_check ]
1421
+						  )
1422
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1423
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1424
+		if (empty($capability) && empty($route_to_check)) {
1425
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1426
+				: $this->_route['capability'];
1427
+		} else {
1428
+			$capability = empty($capability) ? 'manage_options' : $capability;
1429
+		}
1430
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1431
+		if (
1432
+			! $this->request->isAjax()
1433
+			&& (
1434
+				! function_exists('is_admin')
1435
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1436
+					$capability,
1437
+					$this->page_slug
1438
+					. '_'
1439
+					. $route_to_check,
1440
+					$id
1441
+				)
1442
+			)
1443
+		) {
1444
+			if ($verify_only) {
1445
+				return false;
1446
+			}
1447
+			if (is_user_logged_in()) {
1448
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1449
+			} else {
1450
+				return false;
1451
+			}
1452
+		}
1453
+		return true;
1454
+	}
1455
+
1456
+
1457
+	/**
1458
+	 * admin_init_global
1459
+	 * This runs all the code that we want executed within the WP admin_init hook.
1460
+	 * This method executes for ALL EE Admin pages.
1461
+	 *
1462
+	 * @return void
1463
+	 */
1464
+	public function admin_init_global()
1465
+	{
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * wp_loaded_global
1471
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1472
+	 * EE_Admin page and will execute on every EE Admin Page load
1473
+	 *
1474
+	 * @return void
1475
+	 */
1476
+	public function wp_loaded()
1477
+	{
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * admin_notices
1483
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1484
+	 * ALL EE_Admin pages.
1485
+	 *
1486
+	 * @return void
1487
+	 */
1488
+	public function admin_notices_global()
1489
+	{
1490
+		$this->_display_no_javascript_warning();
1491
+		$this->_display_espresso_notices();
1492
+	}
1493
+
1494
+
1495
+	public function network_admin_notices_global()
1496
+	{
1497
+		$this->_display_no_javascript_warning();
1498
+		$this->_display_espresso_notices();
1499
+	}
1500
+
1501
+
1502
+	/**
1503
+	 * admin_footer_scripts_global
1504
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1505
+	 * will apply on ALL EE_Admin pages.
1506
+	 *
1507
+	 * @return void
1508
+	 */
1509
+	public function admin_footer_scripts_global()
1510
+	{
1511
+		$this->_add_admin_page_ajax_loading_img();
1512
+		$this->_add_admin_page_overlay();
1513
+		// if metaboxes are present we need to add the nonce field
1514
+		if (
1515
+			isset($this->_route_config['metaboxes'])
1516
+			|| isset($this->_route_config['list_table'])
1517
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1518
+		) {
1519
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1520
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1521
+		}
1522
+	}
1523
+
1524
+
1525
+	/**
1526
+	 * admin_footer_global
1527
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1528
+	 * ALL EE_Admin Pages.
1529
+	 *
1530
+	 * @return void
1531
+	 */
1532
+	public function admin_footer_global()
1533
+	{
1534
+		// dialog container for dialog helper
1535
+		echo '
1536 1536
         <div class="ee-admin-dialog-container auto-hide hidden">
1537 1537
             <div class="ee-notices"></div>
1538 1538
             <div class="ee-admin-dialog-container-inner-content"></div>
1539 1539
         </div>
1540 1540
         ';
1541 1541
 
1542
-        // current set timezone for timezone js
1543
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1544
-    }
1545
-
1546
-
1547
-    /**
1548
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1549
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1550
-     * help popups then in your templates or your content you set "triggers" for the content using the
1551
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1552
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1553
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1554
-     * for the
1555
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1556
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1557
-     *    'help_trigger_id' => array(
1558
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1559
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1560
-     *    )
1561
-     * );
1562
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1563
-     *
1564
-     * @param array $help_array
1565
-     * @param bool  $display
1566
-     * @return string content
1567
-     * @throws DomainException
1568
-     * @throws EE_Error
1569
-     */
1570
-    protected function _set_help_popup_content($help_array = [], $display = false)
1571
-    {
1572
-        $content    = '';
1573
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1574
-        // loop through the array and setup content
1575
-        foreach ($help_array as $trigger => $help) {
1576
-            // make sure the array is setup properly
1577
-            if (! isset($help['title']) || ! isset($help['content'])) {
1578
-                throw new EE_Error(
1579
-                    esc_html__(
1580
-                        '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',
1581
-                        'event_espresso'
1582
-                    )
1583
-                );
1584
-            }
1585
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1586
-            $template_args = [
1587
-                'help_popup_id'      => $trigger,
1588
-                'help_popup_title'   => $help['title'],
1589
-                'help_popup_content' => $help['content'],
1590
-            ];
1591
-            $content       .= EEH_Template::display_template(
1592
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1593
-                $template_args,
1594
-                true
1595
-            );
1596
-        }
1597
-        if ($display) {
1598
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1599
-            return '';
1600
-        }
1601
-        return $content;
1602
-    }
1603
-
1604
-
1605
-    /**
1606
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1607
-     *
1608
-     * @return array properly formatted array for help popup content
1609
-     * @throws EE_Error
1610
-     */
1611
-    private function _get_help_content()
1612
-    {
1613
-        // what is the method we're looking for?
1614
-        $method_name = '_help_popup_content_' . $this->_req_action;
1615
-        // if method doesn't exist let's get out.
1616
-        if (! method_exists($this, $method_name)) {
1617
-            return [];
1618
-        }
1619
-        // k we're good to go let's retrieve the help array
1620
-        $help_array = call_user_func([$this, $method_name]);
1621
-        // make sure we've got an array!
1622
-        if (! is_array($help_array)) {
1623
-            throw new EE_Error(
1624
-                esc_html__(
1625
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1626
-                    'event_espresso'
1627
-                )
1628
-            );
1629
-        }
1630
-        return $help_array;
1631
-    }
1632
-
1633
-
1634
-    /**
1635
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1636
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1637
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1638
-     *
1639
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1640
-     * @param boolean $display    if false then we return the trigger string
1641
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1642
-     * @return string
1643
-     * @throws DomainException
1644
-     * @throws EE_Error
1645
-     */
1646
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1647
-    {
1648
-        if ($this->request->isAjax()) {
1649
-            return '';
1650
-        }
1651
-        // 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
1652
-        $help_array   = $this->_get_help_content();
1653
-        $help_content = '';
1654
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1655
-            $help_array[ $trigger_id ] = [
1656
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1657
-                'content' => esc_html__(
1658
-                    '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.)',
1659
-                    'event_espresso'
1660
-                ),
1661
-            ];
1662
-            $help_content              = $this->_set_help_popup_content($help_array);
1663
-        }
1664
-        // let's setup the trigger
1665
-        $content = '<a class="ee-dialog" href="?height='
1666
-                   . esc_attr($dimensions[0])
1667
-                   . '&width='
1668
-                   . esc_attr($dimensions[1])
1669
-                   . '&inlineId='
1670
-                   . esc_attr($trigger_id)
1671
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1672
-        $content .= $help_content;
1673
-        if ($display) {
1674
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1675
-            return '';
1676
-        }
1677
-        return $content;
1678
-    }
1679
-
1680
-
1681
-    /**
1682
-     * _add_global_screen_options
1683
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1684
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1685
-     *
1686
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1687
-     *         see also WP_Screen object documents...
1688
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1689
-     * @abstract
1690
-     * @return void
1691
-     */
1692
-    private function _add_global_screen_options()
1693
-    {
1694
-    }
1695
-
1696
-
1697
-    /**
1698
-     * _add_global_feature_pointers
1699
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1700
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1701
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1702
-     *
1703
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1704
-     *         extended) also see:
1705
-     * @link   http://eamann.com/tech/wordpress-portland/
1706
-     * @abstract
1707
-     * @return void
1708
-     */
1709
-    private function _add_global_feature_pointers()
1710
-    {
1711
-    }
1712
-
1713
-
1714
-    /**
1715
-     * load_global_scripts_styles
1716
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1717
-     *
1718
-     * @return void
1719
-     */
1720
-    public function load_global_scripts_styles()
1721
-    {
1722
-        /** STYLES **/
1723
-        // add debugging styles
1724
-        if (WP_DEBUG) {
1725
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1726
-        }
1727
-        // register all styles
1728
-        wp_register_style(
1729
-            'espresso-ui-theme',
1730
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1731
-            [],
1732
-            EVENT_ESPRESSO_VERSION
1733
-        );
1734
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1735
-        // helpers styles
1736
-        wp_register_style(
1737
-            'ee-text-links',
1738
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1739
-            [],
1740
-            EVENT_ESPRESSO_VERSION
1741
-        );
1742
-        /** SCRIPTS **/
1743
-        // register all scripts
1744
-        wp_register_script(
1745
-            'ee-dialog',
1746
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1747
-            ['jquery', 'jquery-ui-draggable'],
1748
-            EVENT_ESPRESSO_VERSION,
1749
-            true
1750
-        );
1751
-        wp_register_script(
1752
-            'ee_admin_js',
1753
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1754
-            ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1755
-            EVENT_ESPRESSO_VERSION,
1756
-            true
1757
-        );
1758
-        wp_register_script(
1759
-            'jquery-ui-timepicker-addon',
1760
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1761
-            ['jquery-ui-datepicker', 'jquery-ui-slider'],
1762
-            EVENT_ESPRESSO_VERSION,
1763
-            true
1764
-        );
1765
-        // script for sorting tables
1766
-        wp_register_script(
1767
-            'espresso_ajax_table_sorting',
1768
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1769
-            ['ee_admin_js', 'jquery-ui-sortable'],
1770
-            EVENT_ESPRESSO_VERSION,
1771
-            true
1772
-        );
1773
-        // script for parsing uri's
1774
-        wp_register_script(
1775
-            'ee-parse-uri',
1776
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1777
-            [],
1778
-            EVENT_ESPRESSO_VERSION,
1779
-            true
1780
-        );
1781
-        // and parsing associative serialized form elements
1782
-        wp_register_script(
1783
-            'ee-serialize-full-array',
1784
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1785
-            ['jquery'],
1786
-            EVENT_ESPRESSO_VERSION,
1787
-            true
1788
-        );
1789
-        // helpers scripts
1790
-        wp_register_script(
1791
-            'ee-text-links',
1792
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1793
-            ['jquery'],
1794
-            EVENT_ESPRESSO_VERSION,
1795
-            true
1796
-        );
1797
-        wp_register_script(
1798
-            'ee-moment-core',
1799
-            EE_GLOBAL_ASSETS_URL . 'moment/moment-with-locales.min.js',
1800
-            [],
1801
-            EVENT_ESPRESSO_VERSION,
1802
-            true
1803
-        );
1804
-        wp_register_script(
1805
-            'ee-moment',
1806
-            EE_GLOBAL_ASSETS_URL . 'moment/moment-timezone-with-data.min.js',
1807
-            ['ee-moment-core'],
1808
-            EVENT_ESPRESSO_VERSION,
1809
-            true
1810
-        );
1811
-        wp_register_script(
1812
-            'ee-datepicker',
1813
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1814
-            ['jquery-ui-timepicker-addon', 'ee-moment'],
1815
-            EVENT_ESPRESSO_VERSION,
1816
-            true
1817
-        );
1818
-        // google charts
1819
-        wp_register_script(
1820
-            'google-charts',
1821
-            'https://www.gstatic.com/charts/loader.js',
1822
-            [],
1823
-            EVENT_ESPRESSO_VERSION
1824
-        );
1825
-        // ENQUEUE ALL BASICS BY DEFAULT
1826
-        wp_enqueue_style('ee-admin-css');
1827
-        wp_enqueue_script('ee_admin_js');
1828
-        wp_enqueue_script('ee-accounting');
1829
-        wp_enqueue_script('jquery-validate');
1830
-        // taking care of metaboxes
1831
-        if (
1832
-            empty($this->_cpt_route)
1833
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1834
-        ) {
1835
-            wp_enqueue_script('dashboard');
1836
-        }
1837
-        // LOCALIZED DATA
1838
-        // localize script for ajax lazy loading
1839
-        $lazy_loader_container_ids = apply_filters(
1840
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1841
-            ['espresso_news_post_box_content']
1842
-        );
1843
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1844
-        add_filter(
1845
-            'admin_body_class',
1846
-            function ($classes) {
1847
-                if (strpos($classes, 'espresso-admin') === false) {
1848
-                    $classes .= ' espresso-admin';
1849
-                }
1850
-                return $classes;
1851
-            }
1852
-        );
1853
-    }
1854
-
1855
-
1856
-    /**
1857
-     *        admin_footer_scripts_eei18n_js_strings
1858
-     *
1859
-     * @return        void
1860
-     */
1861
-    public function admin_footer_scripts_eei18n_js_strings()
1862
-    {
1863
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1864
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1865
-            __(
1866
-                '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!!!',
1867
-                'event_espresso'
1868
-            )
1869
-        );
1870
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1871
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1872
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1873
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1874
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1875
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1876
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1877
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1878
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1879
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1880
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1881
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1882
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1883
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1884
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1885
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1886
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1887
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1888
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1889
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1890
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1891
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1892
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1893
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1894
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1895
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1896
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1897
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1898
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1899
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1900
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1901
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1902
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1903
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1904
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1905
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1906
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1907
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1908
-    }
1909
-
1910
-
1911
-    /**
1912
-     *        load enhanced xdebug styles for ppl with failing eyesight
1913
-     *
1914
-     * @return        void
1915
-     */
1916
-    public function add_xdebug_style()
1917
-    {
1918
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1919
-    }
1920
-
1921
-
1922
-    /************************/
1923
-    /** LIST TABLE METHODS **/
1924
-    /************************/
1925
-    /**
1926
-     * this sets up the list table if the current view requires it.
1927
-     *
1928
-     * @return void
1929
-     * @throws EE_Error
1930
-     */
1931
-    protected function _set_list_table()
1932
-    {
1933
-        // first is this a list_table view?
1934
-        if (! isset($this->_route_config['list_table'])) {
1935
-            return;
1936
-        } //not a list_table view so get out.
1937
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
1938
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
1939
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1940
-            // user error msg
1941
-            $error_msg = esc_html__(
1942
-                'An error occurred. The requested list table views could not be found.',
1943
-                'event_espresso'
1944
-            );
1945
-            // developer error msg
1946
-            $error_msg .= '||'
1947
-                          . sprintf(
1948
-                              esc_html__(
1949
-                                  '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.',
1950
-                                  'event_espresso'
1951
-                              ),
1952
-                              $this->_req_action,
1953
-                              $list_table_view
1954
-                          );
1955
-            throw new EE_Error($error_msg);
1956
-        }
1957
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1958
-        $this->_views = apply_filters(
1959
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1960
-            $this->_views
1961
-        );
1962
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1963
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1964
-        $this->_set_list_table_view();
1965
-        $this->_set_list_table_object();
1966
-    }
1967
-
1968
-
1969
-    /**
1970
-     * set current view for List Table
1971
-     *
1972
-     * @return void
1973
-     */
1974
-    protected function _set_list_table_view()
1975
-    {
1976
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1977
-        $status = $this->request->getRequestParam('status', null, 'key');
1978
-        $this->_view = $status && array_key_exists($status, $this->_views)
1979
-            ? $status
1980
-            : $this->_view;
1981
-    }
1982
-
1983
-
1984
-    /**
1985
-     * _set_list_table_object
1986
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1987
-     *
1988
-     * @throws InvalidInterfaceException
1989
-     * @throws InvalidArgumentException
1990
-     * @throws InvalidDataTypeException
1991
-     * @throws EE_Error
1992
-     * @throws InvalidInterfaceException
1993
-     */
1994
-    protected function _set_list_table_object()
1995
-    {
1996
-        if (isset($this->_route_config['list_table'])) {
1997
-            if (! class_exists($this->_route_config['list_table'])) {
1998
-                throw new EE_Error(
1999
-                    sprintf(
2000
-                        esc_html__(
2001
-                            '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.',
2002
-                            'event_espresso'
2003
-                        ),
2004
-                        $this->_route_config['list_table'],
2005
-                        get_class($this)
2006
-                    )
2007
-                );
2008
-            }
2009
-            $this->_list_table_object = $this->loader->getShared(
2010
-                $this->_route_config['list_table'],
2011
-                [$this]
2012
-            );
2013
-        }
2014
-    }
2015
-
2016
-
2017
-    /**
2018
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2019
-     *
2020
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2021
-     *                                                    urls.  The array should be indexed by the view it is being
2022
-     *                                                    added to.
2023
-     * @return array
2024
-     */
2025
-    public function get_list_table_view_RLs($extra_query_args = [])
2026
-    {
2027
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2028
-        if (empty($this->_views)) {
2029
-            $this->_views = [];
2030
-        }
2031
-        // cycle thru views
2032
-        foreach ($this->_views as $key => $view) {
2033
-            $query_args = [];
2034
-            // check for current view
2035
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2036
-            $query_args['action']                        = $this->_req_action;
2037
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2038
-            $query_args['status']                        = $view['slug'];
2039
-            // merge any other arguments sent in.
2040
-            if (isset($extra_query_args[ $view['slug'] ])) {
2041
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2042
-            }
2043
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2044
-        }
2045
-        return $this->_views;
2046
-    }
2047
-
2048
-
2049
-    /**
2050
-     * _entries_per_page_dropdown
2051
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2052
-     *
2053
-     * @param int $max_entries total number of rows in the table
2054
-     * @return string
2055
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2056
-     *         WP does it.
2057
-     */
2058
-    protected function _entries_per_page_dropdown($max_entries = 0)
2059
-    {
2060
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2061
-        $values   = [10, 25, 50, 100];
2062
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2063
-        if ($max_entries) {
2064
-            $values[] = $max_entries;
2065
-            sort($values);
2066
-        }
2067
-        $entries_per_page_dropdown = '
1542
+		// current set timezone for timezone js
1543
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1544
+	}
1545
+
1546
+
1547
+	/**
1548
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1549
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1550
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1551
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1552
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1553
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1554
+	 * for the
1555
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1556
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1557
+	 *    'help_trigger_id' => array(
1558
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1559
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1560
+	 *    )
1561
+	 * );
1562
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1563
+	 *
1564
+	 * @param array $help_array
1565
+	 * @param bool  $display
1566
+	 * @return string content
1567
+	 * @throws DomainException
1568
+	 * @throws EE_Error
1569
+	 */
1570
+	protected function _set_help_popup_content($help_array = [], $display = false)
1571
+	{
1572
+		$content    = '';
1573
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1574
+		// loop through the array and setup content
1575
+		foreach ($help_array as $trigger => $help) {
1576
+			// make sure the array is setup properly
1577
+			if (! isset($help['title']) || ! isset($help['content'])) {
1578
+				throw new EE_Error(
1579
+					esc_html__(
1580
+						'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',
1581
+						'event_espresso'
1582
+					)
1583
+				);
1584
+			}
1585
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1586
+			$template_args = [
1587
+				'help_popup_id'      => $trigger,
1588
+				'help_popup_title'   => $help['title'],
1589
+				'help_popup_content' => $help['content'],
1590
+			];
1591
+			$content       .= EEH_Template::display_template(
1592
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1593
+				$template_args,
1594
+				true
1595
+			);
1596
+		}
1597
+		if ($display) {
1598
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1599
+			return '';
1600
+		}
1601
+		return $content;
1602
+	}
1603
+
1604
+
1605
+	/**
1606
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1607
+	 *
1608
+	 * @return array properly formatted array for help popup content
1609
+	 * @throws EE_Error
1610
+	 */
1611
+	private function _get_help_content()
1612
+	{
1613
+		// what is the method we're looking for?
1614
+		$method_name = '_help_popup_content_' . $this->_req_action;
1615
+		// if method doesn't exist let's get out.
1616
+		if (! method_exists($this, $method_name)) {
1617
+			return [];
1618
+		}
1619
+		// k we're good to go let's retrieve the help array
1620
+		$help_array = call_user_func([$this, $method_name]);
1621
+		// make sure we've got an array!
1622
+		if (! is_array($help_array)) {
1623
+			throw new EE_Error(
1624
+				esc_html__(
1625
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1626
+					'event_espresso'
1627
+				)
1628
+			);
1629
+		}
1630
+		return $help_array;
1631
+	}
1632
+
1633
+
1634
+	/**
1635
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1636
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1637
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1638
+	 *
1639
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1640
+	 * @param boolean $display    if false then we return the trigger string
1641
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1642
+	 * @return string
1643
+	 * @throws DomainException
1644
+	 * @throws EE_Error
1645
+	 */
1646
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1647
+	{
1648
+		if ($this->request->isAjax()) {
1649
+			return '';
1650
+		}
1651
+		// 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
1652
+		$help_array   = $this->_get_help_content();
1653
+		$help_content = '';
1654
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1655
+			$help_array[ $trigger_id ] = [
1656
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1657
+				'content' => esc_html__(
1658
+					'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.)',
1659
+					'event_espresso'
1660
+				),
1661
+			];
1662
+			$help_content              = $this->_set_help_popup_content($help_array);
1663
+		}
1664
+		// let's setup the trigger
1665
+		$content = '<a class="ee-dialog" href="?height='
1666
+				   . esc_attr($dimensions[0])
1667
+				   . '&width='
1668
+				   . esc_attr($dimensions[1])
1669
+				   . '&inlineId='
1670
+				   . esc_attr($trigger_id)
1671
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1672
+		$content .= $help_content;
1673
+		if ($display) {
1674
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1675
+			return '';
1676
+		}
1677
+		return $content;
1678
+	}
1679
+
1680
+
1681
+	/**
1682
+	 * _add_global_screen_options
1683
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1684
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1685
+	 *
1686
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1687
+	 *         see also WP_Screen object documents...
1688
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1689
+	 * @abstract
1690
+	 * @return void
1691
+	 */
1692
+	private function _add_global_screen_options()
1693
+	{
1694
+	}
1695
+
1696
+
1697
+	/**
1698
+	 * _add_global_feature_pointers
1699
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1700
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1701
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1702
+	 *
1703
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1704
+	 *         extended) also see:
1705
+	 * @link   http://eamann.com/tech/wordpress-portland/
1706
+	 * @abstract
1707
+	 * @return void
1708
+	 */
1709
+	private function _add_global_feature_pointers()
1710
+	{
1711
+	}
1712
+
1713
+
1714
+	/**
1715
+	 * load_global_scripts_styles
1716
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1717
+	 *
1718
+	 * @return void
1719
+	 */
1720
+	public function load_global_scripts_styles()
1721
+	{
1722
+		/** STYLES **/
1723
+		// add debugging styles
1724
+		if (WP_DEBUG) {
1725
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1726
+		}
1727
+		// register all styles
1728
+		wp_register_style(
1729
+			'espresso-ui-theme',
1730
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1731
+			[],
1732
+			EVENT_ESPRESSO_VERSION
1733
+		);
1734
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1735
+		// helpers styles
1736
+		wp_register_style(
1737
+			'ee-text-links',
1738
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1739
+			[],
1740
+			EVENT_ESPRESSO_VERSION
1741
+		);
1742
+		/** SCRIPTS **/
1743
+		// register all scripts
1744
+		wp_register_script(
1745
+			'ee-dialog',
1746
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1747
+			['jquery', 'jquery-ui-draggable'],
1748
+			EVENT_ESPRESSO_VERSION,
1749
+			true
1750
+		);
1751
+		wp_register_script(
1752
+			'ee_admin_js',
1753
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1754
+			['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1755
+			EVENT_ESPRESSO_VERSION,
1756
+			true
1757
+		);
1758
+		wp_register_script(
1759
+			'jquery-ui-timepicker-addon',
1760
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1761
+			['jquery-ui-datepicker', 'jquery-ui-slider'],
1762
+			EVENT_ESPRESSO_VERSION,
1763
+			true
1764
+		);
1765
+		// script for sorting tables
1766
+		wp_register_script(
1767
+			'espresso_ajax_table_sorting',
1768
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1769
+			['ee_admin_js', 'jquery-ui-sortable'],
1770
+			EVENT_ESPRESSO_VERSION,
1771
+			true
1772
+		);
1773
+		// script for parsing uri's
1774
+		wp_register_script(
1775
+			'ee-parse-uri',
1776
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1777
+			[],
1778
+			EVENT_ESPRESSO_VERSION,
1779
+			true
1780
+		);
1781
+		// and parsing associative serialized form elements
1782
+		wp_register_script(
1783
+			'ee-serialize-full-array',
1784
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1785
+			['jquery'],
1786
+			EVENT_ESPRESSO_VERSION,
1787
+			true
1788
+		);
1789
+		// helpers scripts
1790
+		wp_register_script(
1791
+			'ee-text-links',
1792
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1793
+			['jquery'],
1794
+			EVENT_ESPRESSO_VERSION,
1795
+			true
1796
+		);
1797
+		wp_register_script(
1798
+			'ee-moment-core',
1799
+			EE_GLOBAL_ASSETS_URL . 'moment/moment-with-locales.min.js',
1800
+			[],
1801
+			EVENT_ESPRESSO_VERSION,
1802
+			true
1803
+		);
1804
+		wp_register_script(
1805
+			'ee-moment',
1806
+			EE_GLOBAL_ASSETS_URL . 'moment/moment-timezone-with-data.min.js',
1807
+			['ee-moment-core'],
1808
+			EVENT_ESPRESSO_VERSION,
1809
+			true
1810
+		);
1811
+		wp_register_script(
1812
+			'ee-datepicker',
1813
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1814
+			['jquery-ui-timepicker-addon', 'ee-moment'],
1815
+			EVENT_ESPRESSO_VERSION,
1816
+			true
1817
+		);
1818
+		// google charts
1819
+		wp_register_script(
1820
+			'google-charts',
1821
+			'https://www.gstatic.com/charts/loader.js',
1822
+			[],
1823
+			EVENT_ESPRESSO_VERSION
1824
+		);
1825
+		// ENQUEUE ALL BASICS BY DEFAULT
1826
+		wp_enqueue_style('ee-admin-css');
1827
+		wp_enqueue_script('ee_admin_js');
1828
+		wp_enqueue_script('ee-accounting');
1829
+		wp_enqueue_script('jquery-validate');
1830
+		// taking care of metaboxes
1831
+		if (
1832
+			empty($this->_cpt_route)
1833
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1834
+		) {
1835
+			wp_enqueue_script('dashboard');
1836
+		}
1837
+		// LOCALIZED DATA
1838
+		// localize script for ajax lazy loading
1839
+		$lazy_loader_container_ids = apply_filters(
1840
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1841
+			['espresso_news_post_box_content']
1842
+		);
1843
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1844
+		add_filter(
1845
+			'admin_body_class',
1846
+			function ($classes) {
1847
+				if (strpos($classes, 'espresso-admin') === false) {
1848
+					$classes .= ' espresso-admin';
1849
+				}
1850
+				return $classes;
1851
+			}
1852
+		);
1853
+	}
1854
+
1855
+
1856
+	/**
1857
+	 *        admin_footer_scripts_eei18n_js_strings
1858
+	 *
1859
+	 * @return        void
1860
+	 */
1861
+	public function admin_footer_scripts_eei18n_js_strings()
1862
+	{
1863
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1864
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1865
+			__(
1866
+				'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!!!',
1867
+				'event_espresso'
1868
+			)
1869
+		);
1870
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1871
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1872
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1873
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1874
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1875
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1876
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1877
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1878
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1879
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1880
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1881
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1882
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1883
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1884
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1885
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1886
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1887
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1888
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1889
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1890
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1891
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1892
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1893
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1894
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1895
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1896
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1897
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1898
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1899
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1900
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1901
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1902
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1903
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1904
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1905
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1906
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1907
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1908
+	}
1909
+
1910
+
1911
+	/**
1912
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1913
+	 *
1914
+	 * @return        void
1915
+	 */
1916
+	public function add_xdebug_style()
1917
+	{
1918
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1919
+	}
1920
+
1921
+
1922
+	/************************/
1923
+	/** LIST TABLE METHODS **/
1924
+	/************************/
1925
+	/**
1926
+	 * this sets up the list table if the current view requires it.
1927
+	 *
1928
+	 * @return void
1929
+	 * @throws EE_Error
1930
+	 */
1931
+	protected function _set_list_table()
1932
+	{
1933
+		// first is this a list_table view?
1934
+		if (! isset($this->_route_config['list_table'])) {
1935
+			return;
1936
+		} //not a list_table view so get out.
1937
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
1938
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
1939
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1940
+			// user error msg
1941
+			$error_msg = esc_html__(
1942
+				'An error occurred. The requested list table views could not be found.',
1943
+				'event_espresso'
1944
+			);
1945
+			// developer error msg
1946
+			$error_msg .= '||'
1947
+						  . sprintf(
1948
+							  esc_html__(
1949
+								  '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.',
1950
+								  'event_espresso'
1951
+							  ),
1952
+							  $this->_req_action,
1953
+							  $list_table_view
1954
+						  );
1955
+			throw new EE_Error($error_msg);
1956
+		}
1957
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1958
+		$this->_views = apply_filters(
1959
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1960
+			$this->_views
1961
+		);
1962
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1963
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1964
+		$this->_set_list_table_view();
1965
+		$this->_set_list_table_object();
1966
+	}
1967
+
1968
+
1969
+	/**
1970
+	 * set current view for List Table
1971
+	 *
1972
+	 * @return void
1973
+	 */
1974
+	protected function _set_list_table_view()
1975
+	{
1976
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1977
+		$status = $this->request->getRequestParam('status', null, 'key');
1978
+		$this->_view = $status && array_key_exists($status, $this->_views)
1979
+			? $status
1980
+			: $this->_view;
1981
+	}
1982
+
1983
+
1984
+	/**
1985
+	 * _set_list_table_object
1986
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1987
+	 *
1988
+	 * @throws InvalidInterfaceException
1989
+	 * @throws InvalidArgumentException
1990
+	 * @throws InvalidDataTypeException
1991
+	 * @throws EE_Error
1992
+	 * @throws InvalidInterfaceException
1993
+	 */
1994
+	protected function _set_list_table_object()
1995
+	{
1996
+		if (isset($this->_route_config['list_table'])) {
1997
+			if (! class_exists($this->_route_config['list_table'])) {
1998
+				throw new EE_Error(
1999
+					sprintf(
2000
+						esc_html__(
2001
+							'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.',
2002
+							'event_espresso'
2003
+						),
2004
+						$this->_route_config['list_table'],
2005
+						get_class($this)
2006
+					)
2007
+				);
2008
+			}
2009
+			$this->_list_table_object = $this->loader->getShared(
2010
+				$this->_route_config['list_table'],
2011
+				[$this]
2012
+			);
2013
+		}
2014
+	}
2015
+
2016
+
2017
+	/**
2018
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2019
+	 *
2020
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2021
+	 *                                                    urls.  The array should be indexed by the view it is being
2022
+	 *                                                    added to.
2023
+	 * @return array
2024
+	 */
2025
+	public function get_list_table_view_RLs($extra_query_args = [])
2026
+	{
2027
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2028
+		if (empty($this->_views)) {
2029
+			$this->_views = [];
2030
+		}
2031
+		// cycle thru views
2032
+		foreach ($this->_views as $key => $view) {
2033
+			$query_args = [];
2034
+			// check for current view
2035
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2036
+			$query_args['action']                        = $this->_req_action;
2037
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2038
+			$query_args['status']                        = $view['slug'];
2039
+			// merge any other arguments sent in.
2040
+			if (isset($extra_query_args[ $view['slug'] ])) {
2041
+				$query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2042
+			}
2043
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2044
+		}
2045
+		return $this->_views;
2046
+	}
2047
+
2048
+
2049
+	/**
2050
+	 * _entries_per_page_dropdown
2051
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2052
+	 *
2053
+	 * @param int $max_entries total number of rows in the table
2054
+	 * @return string
2055
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2056
+	 *         WP does it.
2057
+	 */
2058
+	protected function _entries_per_page_dropdown($max_entries = 0)
2059
+	{
2060
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2061
+		$values   = [10, 25, 50, 100];
2062
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2063
+		if ($max_entries) {
2064
+			$values[] = $max_entries;
2065
+			sort($values);
2066
+		}
2067
+		$entries_per_page_dropdown = '
2068 2068
 			<div id="entries-per-page-dv" class="alignleft actions">
2069 2069
 				<label class="hide-if-no-js">
2070 2070
 					Show
2071 2071
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2072
-        foreach ($values as $value) {
2073
-            if ($value < $max_entries) {
2074
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2075
-                $entries_per_page_dropdown .= '
2072
+		foreach ($values as $value) {
2073
+			if ($value < $max_entries) {
2074
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2075
+				$entries_per_page_dropdown .= '
2076 2076
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2077
-            }
2078
-        }
2079
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2080
-        $entries_per_page_dropdown .= '
2077
+			}
2078
+		}
2079
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2080
+		$entries_per_page_dropdown .= '
2081 2081
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2082
-        $entries_per_page_dropdown .= '
2082
+		$entries_per_page_dropdown .= '
2083 2083
 					</select>
2084 2084
 					entries
2085 2085
 				</label>
2086 2086
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2087 2087
 			</div>
2088 2088
 		';
2089
-        return $entries_per_page_dropdown;
2090
-    }
2091
-
2092
-
2093
-    /**
2094
-     *        _set_search_attributes
2095
-     *
2096
-     * @return        void
2097
-     */
2098
-    public function _set_search_attributes()
2099
-    {
2100
-        $this->_template_args['search']['btn_label'] = sprintf(
2101
-            esc_html__('Search %s', 'event_espresso'),
2102
-            empty($this->_search_btn_label) ? $this->page_label
2103
-                : $this->_search_btn_label
2104
-        );
2105
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2106
-    }
2107
-
2108
-
2109
-
2110
-    /*** END LIST TABLE METHODS **/
2111
-
2112
-
2113
-    /**
2114
-     * _add_registered_metaboxes
2115
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2116
-     *
2117
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2118
-     * @return void
2119
-     * @throws EE_Error
2120
-     */
2121
-    private function _add_registered_meta_boxes()
2122
-    {
2123
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2124
-        // we only add meta boxes if the page_route calls for it
2125
-        if (
2126
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2127
-            && is_array(
2128
-                $this->_route_config['metaboxes']
2129
-            )
2130
-        ) {
2131
-            // this simply loops through the callbacks provided
2132
-            // and checks if there is a corresponding callback registered by the child
2133
-            // if there is then we go ahead and process the metabox loader.
2134
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2135
-                // first check for Closures
2136
-                if ($metabox_callback instanceof Closure) {
2137
-                    $result = $metabox_callback();
2138
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2139
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2140
-                } else {
2141
-                    $result = call_user_func([$this, &$metabox_callback]);
2142
-                }
2143
-                if ($result === false) {
2144
-                    // user error msg
2145
-                    $error_msg = esc_html__(
2146
-                        'An error occurred. The  requested metabox could not be found.',
2147
-                        'event_espresso'
2148
-                    );
2149
-                    // developer error msg
2150
-                    $error_msg .= '||'
2151
-                                  . sprintf(
2152
-                                      esc_html__(
2153
-                                          '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.',
2154
-                                          'event_espresso'
2155
-                                      ),
2156
-                                      $metabox_callback
2157
-                                  );
2158
-                    throw new EE_Error($error_msg);
2159
-                }
2160
-            }
2161
-        }
2162
-    }
2163
-
2164
-
2165
-    /**
2166
-     * _add_screen_columns
2167
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2168
-     * the dynamic column template and we'll setup the column options for the page.
2169
-     *
2170
-     * @return void
2171
-     */
2172
-    private function _add_screen_columns()
2173
-    {
2174
-        if (
2175
-            is_array($this->_route_config)
2176
-            && isset($this->_route_config['columns'])
2177
-            && is_array($this->_route_config['columns'])
2178
-            && count($this->_route_config['columns']) === 2
2179
-        ) {
2180
-            add_screen_option(
2181
-                'layout_columns',
2182
-                [
2183
-                    'max'     => (int) $this->_route_config['columns'][0],
2184
-                    'default' => (int) $this->_route_config['columns'][1],
2185
-                ]
2186
-            );
2187
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2188
-            $screen_id                                           = $this->_current_screen->id;
2189
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2190
-            $total_columns                                       = ! empty($screen_columns)
2191
-                ? $screen_columns
2192
-                : $this->_route_config['columns'][1];
2193
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2194
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2195
-            $this->_template_args['screen']                      = $this->_current_screen;
2196
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2197
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2198
-            // finally if we don't have has_metaboxes set in the route config
2199
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2200
-            $this->_route_config['has_metaboxes'] = true;
2201
-        }
2202
-    }
2203
-
2204
-
2205
-
2206
-    /** GLOBALLY AVAILABLE METABOXES **/
2207
-
2208
-
2209
-    /**
2210
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2211
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2212
-     * these get loaded on.
2213
-     */
2214
-    private function _espresso_news_post_box()
2215
-    {
2216
-        $news_box_title = apply_filters(
2217
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2218
-            esc_html__('New @ Event Espresso', 'event_espresso')
2219
-        );
2220
-        add_meta_box(
2221
-            'espresso_news_post_box',
2222
-            $news_box_title,
2223
-            [
2224
-                $this,
2225
-                'espresso_news_post_box',
2226
-            ],
2227
-            $this->_wp_page_slug,
2228
-            'side'
2229
-        );
2230
-    }
2231
-
2232
-
2233
-    /**
2234
-     * Code for setting up espresso ratings request metabox.
2235
-     */
2236
-    protected function _espresso_ratings_request()
2237
-    {
2238
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2239
-            return;
2240
-        }
2241
-        $ratings_box_title = apply_filters(
2242
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2243
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2244
-        );
2245
-        add_meta_box(
2246
-            'espresso_ratings_request',
2247
-            $ratings_box_title,
2248
-            [
2249
-                $this,
2250
-                'espresso_ratings_request',
2251
-            ],
2252
-            $this->_wp_page_slug,
2253
-            'side'
2254
-        );
2255
-    }
2256
-
2257
-
2258
-    /**
2259
-     * Code for setting up espresso ratings request metabox content.
2260
-     *
2261
-     * @throws DomainException
2262
-     */
2263
-    public function espresso_ratings_request()
2264
-    {
2265
-        EEH_Template::display_template(
2266
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2267
-            []
2268
-        );
2269
-    }
2270
-
2271
-
2272
-    public static function cached_rss_display($rss_id, $url)
2273
-    {
2274
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2275
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2276
-                     . '</p><p class="hide-if-js">'
2277
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2278
-                     . '</p>';
2279
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2280
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2281
-        $post      = '</div>' . "\n";
2282
-        $cache_key = 'ee_rss_' . md5($rss_id);
2283
-        $output    = get_transient($cache_key);
2284
-        if ($output !== false) {
2285
-            echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2286
-            return true;
2287
-        }
2288
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2289
-            echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2290
-            return false;
2291
-        }
2292
-        ob_start();
2293
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2294
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2295
-        return true;
2296
-    }
2297
-
2298
-
2299
-    public function espresso_news_post_box()
2300
-    {
2301
-        ?>
2089
+		return $entries_per_page_dropdown;
2090
+	}
2091
+
2092
+
2093
+	/**
2094
+	 *        _set_search_attributes
2095
+	 *
2096
+	 * @return        void
2097
+	 */
2098
+	public function _set_search_attributes()
2099
+	{
2100
+		$this->_template_args['search']['btn_label'] = sprintf(
2101
+			esc_html__('Search %s', 'event_espresso'),
2102
+			empty($this->_search_btn_label) ? $this->page_label
2103
+				: $this->_search_btn_label
2104
+		);
2105
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2106
+	}
2107
+
2108
+
2109
+
2110
+	/*** END LIST TABLE METHODS **/
2111
+
2112
+
2113
+	/**
2114
+	 * _add_registered_metaboxes
2115
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2116
+	 *
2117
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2118
+	 * @return void
2119
+	 * @throws EE_Error
2120
+	 */
2121
+	private function _add_registered_meta_boxes()
2122
+	{
2123
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2124
+		// we only add meta boxes if the page_route calls for it
2125
+		if (
2126
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2127
+			&& is_array(
2128
+				$this->_route_config['metaboxes']
2129
+			)
2130
+		) {
2131
+			// this simply loops through the callbacks provided
2132
+			// and checks if there is a corresponding callback registered by the child
2133
+			// if there is then we go ahead and process the metabox loader.
2134
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2135
+				// first check for Closures
2136
+				if ($metabox_callback instanceof Closure) {
2137
+					$result = $metabox_callback();
2138
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2139
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2140
+				} else {
2141
+					$result = call_user_func([$this, &$metabox_callback]);
2142
+				}
2143
+				if ($result === false) {
2144
+					// user error msg
2145
+					$error_msg = esc_html__(
2146
+						'An error occurred. The  requested metabox could not be found.',
2147
+						'event_espresso'
2148
+					);
2149
+					// developer error msg
2150
+					$error_msg .= '||'
2151
+								  . sprintf(
2152
+									  esc_html__(
2153
+										  '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.',
2154
+										  'event_espresso'
2155
+									  ),
2156
+									  $metabox_callback
2157
+								  );
2158
+					throw new EE_Error($error_msg);
2159
+				}
2160
+			}
2161
+		}
2162
+	}
2163
+
2164
+
2165
+	/**
2166
+	 * _add_screen_columns
2167
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2168
+	 * the dynamic column template and we'll setup the column options for the page.
2169
+	 *
2170
+	 * @return void
2171
+	 */
2172
+	private function _add_screen_columns()
2173
+	{
2174
+		if (
2175
+			is_array($this->_route_config)
2176
+			&& isset($this->_route_config['columns'])
2177
+			&& is_array($this->_route_config['columns'])
2178
+			&& count($this->_route_config['columns']) === 2
2179
+		) {
2180
+			add_screen_option(
2181
+				'layout_columns',
2182
+				[
2183
+					'max'     => (int) $this->_route_config['columns'][0],
2184
+					'default' => (int) $this->_route_config['columns'][1],
2185
+				]
2186
+			);
2187
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2188
+			$screen_id                                           = $this->_current_screen->id;
2189
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2190
+			$total_columns                                       = ! empty($screen_columns)
2191
+				? $screen_columns
2192
+				: $this->_route_config['columns'][1];
2193
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2194
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2195
+			$this->_template_args['screen']                      = $this->_current_screen;
2196
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2197
+																   . 'admin_details_metabox_column_wrapper.template.php';
2198
+			// finally if we don't have has_metaboxes set in the route config
2199
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2200
+			$this->_route_config['has_metaboxes'] = true;
2201
+		}
2202
+	}
2203
+
2204
+
2205
+
2206
+	/** GLOBALLY AVAILABLE METABOXES **/
2207
+
2208
+
2209
+	/**
2210
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2211
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2212
+	 * these get loaded on.
2213
+	 */
2214
+	private function _espresso_news_post_box()
2215
+	{
2216
+		$news_box_title = apply_filters(
2217
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2218
+			esc_html__('New @ Event Espresso', 'event_espresso')
2219
+		);
2220
+		add_meta_box(
2221
+			'espresso_news_post_box',
2222
+			$news_box_title,
2223
+			[
2224
+				$this,
2225
+				'espresso_news_post_box',
2226
+			],
2227
+			$this->_wp_page_slug,
2228
+			'side'
2229
+		);
2230
+	}
2231
+
2232
+
2233
+	/**
2234
+	 * Code for setting up espresso ratings request metabox.
2235
+	 */
2236
+	protected function _espresso_ratings_request()
2237
+	{
2238
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2239
+			return;
2240
+		}
2241
+		$ratings_box_title = apply_filters(
2242
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2243
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2244
+		);
2245
+		add_meta_box(
2246
+			'espresso_ratings_request',
2247
+			$ratings_box_title,
2248
+			[
2249
+				$this,
2250
+				'espresso_ratings_request',
2251
+			],
2252
+			$this->_wp_page_slug,
2253
+			'side'
2254
+		);
2255
+	}
2256
+
2257
+
2258
+	/**
2259
+	 * Code for setting up espresso ratings request metabox content.
2260
+	 *
2261
+	 * @throws DomainException
2262
+	 */
2263
+	public function espresso_ratings_request()
2264
+	{
2265
+		EEH_Template::display_template(
2266
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2267
+			[]
2268
+		);
2269
+	}
2270
+
2271
+
2272
+	public static function cached_rss_display($rss_id, $url)
2273
+	{
2274
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2275
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2276
+					 . '</p><p class="hide-if-js">'
2277
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2278
+					 . '</p>';
2279
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2280
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2281
+		$post      = '</div>' . "\n";
2282
+		$cache_key = 'ee_rss_' . md5($rss_id);
2283
+		$output    = get_transient($cache_key);
2284
+		if ($output !== false) {
2285
+			echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2286
+			return true;
2287
+		}
2288
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2289
+			echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2290
+			return false;
2291
+		}
2292
+		ob_start();
2293
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2294
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2295
+		return true;
2296
+	}
2297
+
2298
+
2299
+	public function espresso_news_post_box()
2300
+	{
2301
+		?>
2302 2302
         <div class="padding">
2303 2303
             <div id="espresso_news_post_box_content" class="infolinks">
2304 2304
                 <?php
2305
-                // Get RSS Feed(s)
2306
-                self::cached_rss_display(
2307
-                    'espresso_news_post_box_content',
2308
-                    esc_url_raw(
2309
-                        apply_filters(
2310
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2311
-                            'https://eventespresso.com/feed/'
2312
-                        )
2313
-                    )
2314
-                );
2315
-                ?>
2305
+				// Get RSS Feed(s)
2306
+				self::cached_rss_display(
2307
+					'espresso_news_post_box_content',
2308
+					esc_url_raw(
2309
+						apply_filters(
2310
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2311
+							'https://eventespresso.com/feed/'
2312
+						)
2313
+					)
2314
+				);
2315
+				?>
2316 2316
             </div>
2317 2317
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2318 2318
         </div>
2319 2319
         <?php
2320
-    }
2321
-
2322
-
2323
-    private function _espresso_links_post_box()
2324
-    {
2325
-        // Hiding until we actually have content to put in here...
2326
-        // 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');
2327
-    }
2328
-
2329
-
2330
-    public function espresso_links_post_box()
2331
-    {
2332
-        // Hiding until we actually have content to put in here...
2333
-        // EEH_Template::display_template(
2334
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2335
-        // );
2336
-    }
2337
-
2338
-
2339
-    protected function _espresso_sponsors_post_box()
2340
-    {
2341
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2342
-            add_meta_box(
2343
-                'espresso_sponsors_post_box',
2344
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2345
-                [$this, 'espresso_sponsors_post_box'],
2346
-                $this->_wp_page_slug,
2347
-                'side'
2348
-            );
2349
-        }
2350
-    }
2351
-
2352
-
2353
-    public function espresso_sponsors_post_box()
2354
-    {
2355
-        EEH_Template::display_template(
2356
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2357
-        );
2358
-    }
2359
-
2360
-
2361
-    private function _publish_post_box()
2362
-    {
2363
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2364
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2365
-        // then we'll use that for the metabox label.
2366
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2367
-        if (! empty($this->_labels['publishbox'])) {
2368
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2369
-                : $this->_labels['publishbox'];
2370
-        } else {
2371
-            $box_label = esc_html__('Publish', 'event_espresso');
2372
-        }
2373
-        $box_label = apply_filters(
2374
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2375
-            $box_label,
2376
-            $this->_req_action,
2377
-            $this
2378
-        );
2379
-        add_meta_box(
2380
-            $meta_box_ref,
2381
-            $box_label,
2382
-            [$this, 'editor_overview'],
2383
-            $this->_current_screen->id,
2384
-            'side',
2385
-            'high'
2386
-        );
2387
-    }
2388
-
2389
-
2390
-    public function editor_overview()
2391
-    {
2392
-        // if we have extra content set let's add it in if not make sure its empty
2393
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2394
-            ? $this->_template_args['publish_box_extra_content']
2395
-            : '';
2396
-        echo EEH_Template::display_template(
2397
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2398
-            $this->_template_args,
2399
-            true
2400
-        );
2401
-    }
2402
-
2403
-
2404
-    /** end of globally available metaboxes section **/
2405
-
2406
-
2407
-    /**
2408
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2409
-     * protected method.
2410
-     *
2411
-     * @param string $name
2412
-     * @param int    $id
2413
-     * @param bool   $delete
2414
-     * @param string $save_close_redirect_URL
2415
-     * @param bool   $both_btns
2416
-     * @throws EE_Error
2417
-     * @throws InvalidArgumentException
2418
-     * @throws InvalidDataTypeException
2419
-     * @throws InvalidInterfaceException
2420
-     * @see   $this->_set_publish_post_box_vars for param details
2421
-     * @since 4.6.0
2422
-     */
2423
-    public function set_publish_post_box_vars(
2424
-        $name = '',
2425
-        $id = 0,
2426
-        $delete = false,
2427
-        $save_close_redirect_URL = '',
2428
-        $both_btns = true
2429
-    ) {
2430
-        $this->_set_publish_post_box_vars(
2431
-            $name,
2432
-            $id,
2433
-            $delete,
2434
-            $save_close_redirect_URL,
2435
-            $both_btns
2436
-        );
2437
-    }
2438
-
2439
-
2440
-    /**
2441
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2442
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2443
-     * save, and save and close buttons to work properly, then you will want to include a
2444
-     * values for the name and id arguments.
2445
-     *
2446
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2447
-     * @param int     $id                         id attached to the item published
2448
-     * @param string  $delete                     page route callback for the delete action
2449
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2450
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2451
-     *                                            the Save button
2452
-     * @throws EE_Error
2453
-     * @throws InvalidArgumentException
2454
-     * @throws InvalidDataTypeException
2455
-     * @throws InvalidInterfaceException
2456
-     * @todo  Add in validation for name/id arguments.
2457
-     */
2458
-    protected function _set_publish_post_box_vars(
2459
-        $name = '',
2460
-        $id = 0,
2461
-        $delete = '',
2462
-        $save_close_redirect_URL = '',
2463
-        $both_btns = true
2464
-    ) {
2465
-        // if Save & Close, use a custom redirect URL or default to the main page?
2466
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2467
-            ? $save_close_redirect_URL
2468
-            : $this->_admin_base_url;
2469
-        // create the Save & Close and Save buttons
2470
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2471
-        // if we have extra content set let's add it in if not make sure its empty
2472
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2473
-            ? $this->_template_args['publish_box_extra_content']
2474
-            : '';
2475
-        if ($delete && ! empty($id)) {
2476
-            // make sure we have a default if just true is sent.
2477
-            $delete           = ! empty($delete) ? $delete : 'delete';
2478
-            $delete_link_args = [$name => $id];
2479
-            $delete           = $this->get_action_link_or_button(
2480
-                $delete,
2481
-                $delete,
2482
-                $delete_link_args,
2483
-                'submitdelete deletion',
2484
-                '',
2485
-                false
2486
-            );
2487
-        }
2488
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2489
-        if (! empty($name) && ! empty($id)) {
2490
-            $hidden_field_arr[ $name ] = [
2491
-                'type'  => 'hidden',
2492
-                'value' => $id,
2493
-            ];
2494
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2495
-        } else {
2496
-            $hf = '';
2497
-        }
2498
-        // add hidden field
2499
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2500
-            ? $hf[ $name ]['field']
2501
-            : $hf;
2502
-    }
2503
-
2504
-
2505
-    /**
2506
-     * displays an error message to ppl who have javascript disabled
2507
-     *
2508
-     * @return void
2509
-     */
2510
-    private function _display_no_javascript_warning()
2511
-    {
2512
-        ?>
2320
+	}
2321
+
2322
+
2323
+	private function _espresso_links_post_box()
2324
+	{
2325
+		// Hiding until we actually have content to put in here...
2326
+		// 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');
2327
+	}
2328
+
2329
+
2330
+	public function espresso_links_post_box()
2331
+	{
2332
+		// Hiding until we actually have content to put in here...
2333
+		// EEH_Template::display_template(
2334
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2335
+		// );
2336
+	}
2337
+
2338
+
2339
+	protected function _espresso_sponsors_post_box()
2340
+	{
2341
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2342
+			add_meta_box(
2343
+				'espresso_sponsors_post_box',
2344
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2345
+				[$this, 'espresso_sponsors_post_box'],
2346
+				$this->_wp_page_slug,
2347
+				'side'
2348
+			);
2349
+		}
2350
+	}
2351
+
2352
+
2353
+	public function espresso_sponsors_post_box()
2354
+	{
2355
+		EEH_Template::display_template(
2356
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2357
+		);
2358
+	}
2359
+
2360
+
2361
+	private function _publish_post_box()
2362
+	{
2363
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2364
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2365
+		// then we'll use that for the metabox label.
2366
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2367
+		if (! empty($this->_labels['publishbox'])) {
2368
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2369
+				: $this->_labels['publishbox'];
2370
+		} else {
2371
+			$box_label = esc_html__('Publish', 'event_espresso');
2372
+		}
2373
+		$box_label = apply_filters(
2374
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2375
+			$box_label,
2376
+			$this->_req_action,
2377
+			$this
2378
+		);
2379
+		add_meta_box(
2380
+			$meta_box_ref,
2381
+			$box_label,
2382
+			[$this, 'editor_overview'],
2383
+			$this->_current_screen->id,
2384
+			'side',
2385
+			'high'
2386
+		);
2387
+	}
2388
+
2389
+
2390
+	public function editor_overview()
2391
+	{
2392
+		// if we have extra content set let's add it in if not make sure its empty
2393
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2394
+			? $this->_template_args['publish_box_extra_content']
2395
+			: '';
2396
+		echo EEH_Template::display_template(
2397
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2398
+			$this->_template_args,
2399
+			true
2400
+		);
2401
+	}
2402
+
2403
+
2404
+	/** end of globally available metaboxes section **/
2405
+
2406
+
2407
+	/**
2408
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2409
+	 * protected method.
2410
+	 *
2411
+	 * @param string $name
2412
+	 * @param int    $id
2413
+	 * @param bool   $delete
2414
+	 * @param string $save_close_redirect_URL
2415
+	 * @param bool   $both_btns
2416
+	 * @throws EE_Error
2417
+	 * @throws InvalidArgumentException
2418
+	 * @throws InvalidDataTypeException
2419
+	 * @throws InvalidInterfaceException
2420
+	 * @see   $this->_set_publish_post_box_vars for param details
2421
+	 * @since 4.6.0
2422
+	 */
2423
+	public function set_publish_post_box_vars(
2424
+		$name = '',
2425
+		$id = 0,
2426
+		$delete = false,
2427
+		$save_close_redirect_URL = '',
2428
+		$both_btns = true
2429
+	) {
2430
+		$this->_set_publish_post_box_vars(
2431
+			$name,
2432
+			$id,
2433
+			$delete,
2434
+			$save_close_redirect_URL,
2435
+			$both_btns
2436
+		);
2437
+	}
2438
+
2439
+
2440
+	/**
2441
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2442
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2443
+	 * save, and save and close buttons to work properly, then you will want to include a
2444
+	 * values for the name and id arguments.
2445
+	 *
2446
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2447
+	 * @param int     $id                         id attached to the item published
2448
+	 * @param string  $delete                     page route callback for the delete action
2449
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2450
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2451
+	 *                                            the Save button
2452
+	 * @throws EE_Error
2453
+	 * @throws InvalidArgumentException
2454
+	 * @throws InvalidDataTypeException
2455
+	 * @throws InvalidInterfaceException
2456
+	 * @todo  Add in validation for name/id arguments.
2457
+	 */
2458
+	protected function _set_publish_post_box_vars(
2459
+		$name = '',
2460
+		$id = 0,
2461
+		$delete = '',
2462
+		$save_close_redirect_URL = '',
2463
+		$both_btns = true
2464
+	) {
2465
+		// if Save & Close, use a custom redirect URL or default to the main page?
2466
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2467
+			? $save_close_redirect_URL
2468
+			: $this->_admin_base_url;
2469
+		// create the Save & Close and Save buttons
2470
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2471
+		// if we have extra content set let's add it in if not make sure its empty
2472
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2473
+			? $this->_template_args['publish_box_extra_content']
2474
+			: '';
2475
+		if ($delete && ! empty($id)) {
2476
+			// make sure we have a default if just true is sent.
2477
+			$delete           = ! empty($delete) ? $delete : 'delete';
2478
+			$delete_link_args = [$name => $id];
2479
+			$delete           = $this->get_action_link_or_button(
2480
+				$delete,
2481
+				$delete,
2482
+				$delete_link_args,
2483
+				'submitdelete deletion',
2484
+				'',
2485
+				false
2486
+			);
2487
+		}
2488
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2489
+		if (! empty($name) && ! empty($id)) {
2490
+			$hidden_field_arr[ $name ] = [
2491
+				'type'  => 'hidden',
2492
+				'value' => $id,
2493
+			];
2494
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2495
+		} else {
2496
+			$hf = '';
2497
+		}
2498
+		// add hidden field
2499
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2500
+			? $hf[ $name ]['field']
2501
+			: $hf;
2502
+	}
2503
+
2504
+
2505
+	/**
2506
+	 * displays an error message to ppl who have javascript disabled
2507
+	 *
2508
+	 * @return void
2509
+	 */
2510
+	private function _display_no_javascript_warning()
2511
+	{
2512
+		?>
2513 2513
         <noscript>
2514 2514
             <div id="no-js-message" class="error">
2515 2515
                 <p style="font-size:1.3em;">
2516 2516
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2517 2517
                     <?php esc_html_e(
2518
-                        '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.',
2519
-                        'event_espresso'
2520
-                    ); ?>
2518
+						'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.',
2519
+						'event_espresso'
2520
+					); ?>
2521 2521
                 </p>
2522 2522
             </div>
2523 2523
         </noscript>
2524 2524
         <?php
2525
-    }
2526
-
2527
-
2528
-    /**
2529
-     * displays espresso success and/or error notices
2530
-     *
2531
-     * @return void
2532
-     */
2533
-    protected function _display_espresso_notices()
2534
-    {
2535
-        $notices = $this->_get_transient(true);
2536
-        echo wp_kses(stripslashes($notices), AllowedTags::getWithFormTags());
2537
-    }
2538
-
2539
-
2540
-    /**
2541
-     * spinny things pacify the masses
2542
-     *
2543
-     * @return void
2544
-     */
2545
-    protected function _add_admin_page_ajax_loading_img()
2546
-    {
2547
-        ?>
2525
+	}
2526
+
2527
+
2528
+	/**
2529
+	 * displays espresso success and/or error notices
2530
+	 *
2531
+	 * @return void
2532
+	 */
2533
+	protected function _display_espresso_notices()
2534
+	{
2535
+		$notices = $this->_get_transient(true);
2536
+		echo wp_kses(stripslashes($notices), AllowedTags::getWithFormTags());
2537
+	}
2538
+
2539
+
2540
+	/**
2541
+	 * spinny things pacify the masses
2542
+	 *
2543
+	 * @return void
2544
+	 */
2545
+	protected function _add_admin_page_ajax_loading_img()
2546
+	{
2547
+		?>
2548 2548
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2549 2549
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2550
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2550
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2551 2551
         </div>
2552 2552
         <?php
2553
-    }
2553
+	}
2554 2554
 
2555 2555
 
2556
-    /**
2557
-     * add admin page overlay for modal boxes
2558
-     *
2559
-     * @return void
2560
-     */
2561
-    protected function _add_admin_page_overlay()
2562
-    {
2563
-        ?>
2556
+	/**
2557
+	 * add admin page overlay for modal boxes
2558
+	 *
2559
+	 * @return void
2560
+	 */
2561
+	protected function _add_admin_page_overlay()
2562
+	{
2563
+		?>
2564 2564
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2565 2565
         <?php
2566
-    }
2567
-
2568
-
2569
-    /**
2570
-     * facade for add_meta_box
2571
-     *
2572
-     * @param string  $action        where the metabox gets displayed
2573
-     * @param string  $title         Title of Metabox (output in metabox header)
2574
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2575
-     *                               instead of the one created in here.
2576
-     * @param array   $callback_args an array of args supplied for the metabox
2577
-     * @param string  $column        what metabox column
2578
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2579
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2580
-     *                               created but just set our own callback for wp's add_meta_box.
2581
-     * @throws DomainException
2582
-     */
2583
-    public function _add_admin_page_meta_box(
2584
-        $action,
2585
-        $title,
2586
-        $callback,
2587
-        $callback_args,
2588
-        $column = 'normal',
2589
-        $priority = 'high',
2590
-        $create_func = true
2591
-    ) {
2592
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2593
-        // 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.
2594
-        if (empty($callback_args) && $create_func) {
2595
-            $callback_args = [
2596
-                'template_path' => $this->_template_path,
2597
-                'template_args' => $this->_template_args,
2598
-            ];
2599
-        }
2600
-        // 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)
2601
-        $call_back_func = $create_func
2602
-            ? function ($post, $metabox) {
2603
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2604
-                echo EEH_Template::display_template(
2605
-                    $metabox['args']['template_path'],
2606
-                    $metabox['args']['template_args'],
2607
-                    true
2608
-                );
2609
-            }
2610
-            : $callback;
2611
-        add_meta_box(
2612
-            str_replace('_', '-', $action) . '-mbox',
2613
-            $title,
2614
-            $call_back_func,
2615
-            $this->_wp_page_slug,
2616
-            $column,
2617
-            $priority,
2618
-            $callback_args
2619
-        );
2620
-    }
2621
-
2622
-
2623
-    /**
2624
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2625
-     *
2626
-     * @throws DomainException
2627
-     * @throws EE_Error
2628
-     */
2629
-    public function display_admin_page_with_metabox_columns()
2630
-    {
2631
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2632
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2633
-            $this->_column_template_path,
2634
-            $this->_template_args,
2635
-            true
2636
-        );
2637
-        // the final wrapper
2638
-        $this->admin_page_wrapper();
2639
-    }
2640
-
2641
-
2642
-    /**
2643
-     * generates  HTML wrapper for an admin details page
2644
-     *
2645
-     * @return void
2646
-     * @throws EE_Error
2647
-     * @throws DomainException
2648
-     */
2649
-    public function display_admin_page_with_sidebar()
2650
-    {
2651
-        $this->_display_admin_page(true);
2652
-    }
2653
-
2654
-
2655
-    /**
2656
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2657
-     *
2658
-     * @return void
2659
-     * @throws EE_Error
2660
-     * @throws DomainException
2661
-     */
2662
-    public function display_admin_page_with_no_sidebar()
2663
-    {
2664
-        $this->_display_admin_page();
2665
-    }
2666
-
2667
-
2668
-    /**
2669
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2670
-     *
2671
-     * @return void
2672
-     * @throws EE_Error
2673
-     * @throws DomainException
2674
-     */
2675
-    public function display_about_admin_page()
2676
-    {
2677
-        $this->_display_admin_page(false, true);
2678
-    }
2679
-
2680
-
2681
-    /**
2682
-     * display_admin_page
2683
-     * contains the code for actually displaying an admin page
2684
-     *
2685
-     * @param boolean $sidebar true with sidebar, false without
2686
-     * @param boolean $about   use the about_admin_wrapper instead of the default.
2687
-     * @return void
2688
-     * @throws DomainException
2689
-     * @throws EE_Error
2690
-     */
2691
-    private function _display_admin_page($sidebar = false, $about = false)
2692
-    {
2693
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2694
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2695
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2696
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2697
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2698
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2699
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2700
-            ? 'poststuff'
2701
-            : 'espresso-default-admin';
2702
-        $template_path                                     = $sidebar
2703
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2704
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2705
-        if ($this->request->isAjax()) {
2706
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2707
-        }
2708
-        $template_path                                     = ! empty($this->_column_template_path)
2709
-            ? $this->_column_template_path : $template_path;
2710
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2711
-            ? $this->_template_args['admin_page_content']
2712
-            : '';
2713
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2714
-            ? $this->_template_args['before_admin_page_content']
2715
-            : '';
2716
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2717
-            ? $this->_template_args['after_admin_page_content']
2718
-            : '';
2719
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2720
-            $template_path,
2721
-            $this->_template_args,
2722
-            true
2723
-        );
2724
-        // the final template wrapper
2725
-        $this->admin_page_wrapper($about);
2726
-    }
2727
-
2728
-
2729
-    /**
2730
-     * This is used to display caf preview pages.
2731
-     *
2732
-     * @param string $utm_campaign_source what is the key used for google analytics link
2733
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2734
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2735
-     * @return void
2736
-     * @throws DomainException
2737
-     * @throws EE_Error
2738
-     * @throws InvalidArgumentException
2739
-     * @throws InvalidDataTypeException
2740
-     * @throws InvalidInterfaceException
2741
-     * @since 4.3.2
2742
-     */
2743
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2744
-    {
2745
-        // let's generate a default preview action button if there isn't one already present.
2746
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2747
-            'Upgrade to Event Espresso 4 Right Now',
2748
-            'event_espresso'
2749
-        );
2750
-        $buy_now_url                                   = add_query_arg(
2751
-            [
2752
-                'ee_ver'       => 'ee4',
2753
-                'utm_source'   => 'ee4_plugin_admin',
2754
-                'utm_medium'   => 'link',
2755
-                'utm_campaign' => $utm_campaign_source,
2756
-                'utm_content'  => 'buy_now_button',
2757
-            ],
2758
-            'https://eventespresso.com/pricing/'
2759
-        );
2760
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2761
-            ? $this->get_action_link_or_button(
2762
-                '',
2763
-                'buy_now',
2764
-                [],
2765
-                'button-primary button-large',
2766
-                esc_url_raw($buy_now_url),
2767
-                true
2768
-            )
2769
-            : $this->_template_args['preview_action_button'];
2770
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2771
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2772
-            $this->_template_args,
2773
-            true
2774
-        );
2775
-        $this->_display_admin_page($display_sidebar);
2776
-    }
2777
-
2778
-
2779
-    /**
2780
-     * display_admin_list_table_page_with_sidebar
2781
-     * generates HTML wrapper for an admin_page with list_table
2782
-     *
2783
-     * @return void
2784
-     * @throws EE_Error
2785
-     * @throws DomainException
2786
-     */
2787
-    public function display_admin_list_table_page_with_sidebar()
2788
-    {
2789
-        $this->_display_admin_list_table_page(true);
2790
-    }
2791
-
2792
-
2793
-    /**
2794
-     * display_admin_list_table_page_with_no_sidebar
2795
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2796
-     *
2797
-     * @return void
2798
-     * @throws EE_Error
2799
-     * @throws DomainException
2800
-     */
2801
-    public function display_admin_list_table_page_with_no_sidebar()
2802
-    {
2803
-        $this->_display_admin_list_table_page();
2804
-    }
2805
-
2806
-
2807
-    /**
2808
-     * generates html wrapper for an admin_list_table page
2809
-     *
2810
-     * @param boolean $sidebar whether to display with sidebar or not.
2811
-     * @return void
2812
-     * @throws DomainException
2813
-     * @throws EE_Error
2814
-     */
2815
-    private function _display_admin_list_table_page($sidebar = false)
2816
-    {
2817
-        // setup search attributes
2818
-        $this->_set_search_attributes();
2819
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2820
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2821
-        $this->_template_args['table_url']        = $this->request->isAjax()
2822
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2823
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2824
-        $this->_template_args['list_table']       = $this->_list_table_object;
2825
-        $this->_template_args['current_route']    = $this->_req_action;
2826
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2827
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2828
-        if (! empty($ajax_sorting_callback)) {
2829
-            $sortable_list_table_form_fields = wp_nonce_field(
2830
-                $ajax_sorting_callback . '_nonce',
2831
-                $ajax_sorting_callback . '_nonce',
2832
-                false,
2833
-                false
2834
-            );
2835
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2836
-                                                . $this->page_slug
2837
-                                                . '" />';
2838
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2839
-                                                . $ajax_sorting_callback
2840
-                                                . '" />';
2841
-        } else {
2842
-            $sortable_list_table_form_fields = '';
2843
-        }
2844
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2845
-        $hidden_form_fields                                      =
2846
-            isset($this->_template_args['list_table_hidden_fields'])
2847
-                ? $this->_template_args['list_table_hidden_fields']
2848
-                : '';
2849
-
2850
-        $nonce_ref          = $this->_req_action . '_nonce';
2851
-        $hidden_form_fields .= '
2566
+	}
2567
+
2568
+
2569
+	/**
2570
+	 * facade for add_meta_box
2571
+	 *
2572
+	 * @param string  $action        where the metabox gets displayed
2573
+	 * @param string  $title         Title of Metabox (output in metabox header)
2574
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2575
+	 *                               instead of the one created in here.
2576
+	 * @param array   $callback_args an array of args supplied for the metabox
2577
+	 * @param string  $column        what metabox column
2578
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2579
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2580
+	 *                               created but just set our own callback for wp's add_meta_box.
2581
+	 * @throws DomainException
2582
+	 */
2583
+	public function _add_admin_page_meta_box(
2584
+		$action,
2585
+		$title,
2586
+		$callback,
2587
+		$callback_args,
2588
+		$column = 'normal',
2589
+		$priority = 'high',
2590
+		$create_func = true
2591
+	) {
2592
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2593
+		// 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.
2594
+		if (empty($callback_args) && $create_func) {
2595
+			$callback_args = [
2596
+				'template_path' => $this->_template_path,
2597
+				'template_args' => $this->_template_args,
2598
+			];
2599
+		}
2600
+		// 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)
2601
+		$call_back_func = $create_func
2602
+			? function ($post, $metabox) {
2603
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2604
+				echo EEH_Template::display_template(
2605
+					$metabox['args']['template_path'],
2606
+					$metabox['args']['template_args'],
2607
+					true
2608
+				);
2609
+			}
2610
+			: $callback;
2611
+		add_meta_box(
2612
+			str_replace('_', '-', $action) . '-mbox',
2613
+			$title,
2614
+			$call_back_func,
2615
+			$this->_wp_page_slug,
2616
+			$column,
2617
+			$priority,
2618
+			$callback_args
2619
+		);
2620
+	}
2621
+
2622
+
2623
+	/**
2624
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2625
+	 *
2626
+	 * @throws DomainException
2627
+	 * @throws EE_Error
2628
+	 */
2629
+	public function display_admin_page_with_metabox_columns()
2630
+	{
2631
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2632
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2633
+			$this->_column_template_path,
2634
+			$this->_template_args,
2635
+			true
2636
+		);
2637
+		// the final wrapper
2638
+		$this->admin_page_wrapper();
2639
+	}
2640
+
2641
+
2642
+	/**
2643
+	 * generates  HTML wrapper for an admin details page
2644
+	 *
2645
+	 * @return void
2646
+	 * @throws EE_Error
2647
+	 * @throws DomainException
2648
+	 */
2649
+	public function display_admin_page_with_sidebar()
2650
+	{
2651
+		$this->_display_admin_page(true);
2652
+	}
2653
+
2654
+
2655
+	/**
2656
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2657
+	 *
2658
+	 * @return void
2659
+	 * @throws EE_Error
2660
+	 * @throws DomainException
2661
+	 */
2662
+	public function display_admin_page_with_no_sidebar()
2663
+	{
2664
+		$this->_display_admin_page();
2665
+	}
2666
+
2667
+
2668
+	/**
2669
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2670
+	 *
2671
+	 * @return void
2672
+	 * @throws EE_Error
2673
+	 * @throws DomainException
2674
+	 */
2675
+	public function display_about_admin_page()
2676
+	{
2677
+		$this->_display_admin_page(false, true);
2678
+	}
2679
+
2680
+
2681
+	/**
2682
+	 * display_admin_page
2683
+	 * contains the code for actually displaying an admin page
2684
+	 *
2685
+	 * @param boolean $sidebar true with sidebar, false without
2686
+	 * @param boolean $about   use the about_admin_wrapper instead of the default.
2687
+	 * @return void
2688
+	 * @throws DomainException
2689
+	 * @throws EE_Error
2690
+	 */
2691
+	private function _display_admin_page($sidebar = false, $about = false)
2692
+	{
2693
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2694
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2695
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2696
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2697
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2698
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2699
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2700
+			? 'poststuff'
2701
+			: 'espresso-default-admin';
2702
+		$template_path                                     = $sidebar
2703
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2704
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2705
+		if ($this->request->isAjax()) {
2706
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2707
+		}
2708
+		$template_path                                     = ! empty($this->_column_template_path)
2709
+			? $this->_column_template_path : $template_path;
2710
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2711
+			? $this->_template_args['admin_page_content']
2712
+			: '';
2713
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2714
+			? $this->_template_args['before_admin_page_content']
2715
+			: '';
2716
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2717
+			? $this->_template_args['after_admin_page_content']
2718
+			: '';
2719
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2720
+			$template_path,
2721
+			$this->_template_args,
2722
+			true
2723
+		);
2724
+		// the final template wrapper
2725
+		$this->admin_page_wrapper($about);
2726
+	}
2727
+
2728
+
2729
+	/**
2730
+	 * This is used to display caf preview pages.
2731
+	 *
2732
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2733
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2734
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2735
+	 * @return void
2736
+	 * @throws DomainException
2737
+	 * @throws EE_Error
2738
+	 * @throws InvalidArgumentException
2739
+	 * @throws InvalidDataTypeException
2740
+	 * @throws InvalidInterfaceException
2741
+	 * @since 4.3.2
2742
+	 */
2743
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2744
+	{
2745
+		// let's generate a default preview action button if there isn't one already present.
2746
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2747
+			'Upgrade to Event Espresso 4 Right Now',
2748
+			'event_espresso'
2749
+		);
2750
+		$buy_now_url                                   = add_query_arg(
2751
+			[
2752
+				'ee_ver'       => 'ee4',
2753
+				'utm_source'   => 'ee4_plugin_admin',
2754
+				'utm_medium'   => 'link',
2755
+				'utm_campaign' => $utm_campaign_source,
2756
+				'utm_content'  => 'buy_now_button',
2757
+			],
2758
+			'https://eventespresso.com/pricing/'
2759
+		);
2760
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2761
+			? $this->get_action_link_or_button(
2762
+				'',
2763
+				'buy_now',
2764
+				[],
2765
+				'button-primary button-large',
2766
+				esc_url_raw($buy_now_url),
2767
+				true
2768
+			)
2769
+			: $this->_template_args['preview_action_button'];
2770
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2771
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2772
+			$this->_template_args,
2773
+			true
2774
+		);
2775
+		$this->_display_admin_page($display_sidebar);
2776
+	}
2777
+
2778
+
2779
+	/**
2780
+	 * display_admin_list_table_page_with_sidebar
2781
+	 * generates HTML wrapper for an admin_page with list_table
2782
+	 *
2783
+	 * @return void
2784
+	 * @throws EE_Error
2785
+	 * @throws DomainException
2786
+	 */
2787
+	public function display_admin_list_table_page_with_sidebar()
2788
+	{
2789
+		$this->_display_admin_list_table_page(true);
2790
+	}
2791
+
2792
+
2793
+	/**
2794
+	 * display_admin_list_table_page_with_no_sidebar
2795
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2796
+	 *
2797
+	 * @return void
2798
+	 * @throws EE_Error
2799
+	 * @throws DomainException
2800
+	 */
2801
+	public function display_admin_list_table_page_with_no_sidebar()
2802
+	{
2803
+		$this->_display_admin_list_table_page();
2804
+	}
2805
+
2806
+
2807
+	/**
2808
+	 * generates html wrapper for an admin_list_table page
2809
+	 *
2810
+	 * @param boolean $sidebar whether to display with sidebar or not.
2811
+	 * @return void
2812
+	 * @throws DomainException
2813
+	 * @throws EE_Error
2814
+	 */
2815
+	private function _display_admin_list_table_page($sidebar = false)
2816
+	{
2817
+		// setup search attributes
2818
+		$this->_set_search_attributes();
2819
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2820
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2821
+		$this->_template_args['table_url']        = $this->request->isAjax()
2822
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2823
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2824
+		$this->_template_args['list_table']       = $this->_list_table_object;
2825
+		$this->_template_args['current_route']    = $this->_req_action;
2826
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2827
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2828
+		if (! empty($ajax_sorting_callback)) {
2829
+			$sortable_list_table_form_fields = wp_nonce_field(
2830
+				$ajax_sorting_callback . '_nonce',
2831
+				$ajax_sorting_callback . '_nonce',
2832
+				false,
2833
+				false
2834
+			);
2835
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2836
+												. $this->page_slug
2837
+												. '" />';
2838
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2839
+												. $ajax_sorting_callback
2840
+												. '" />';
2841
+		} else {
2842
+			$sortable_list_table_form_fields = '';
2843
+		}
2844
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2845
+		$hidden_form_fields                                      =
2846
+			isset($this->_template_args['list_table_hidden_fields'])
2847
+				? $this->_template_args['list_table_hidden_fields']
2848
+				: '';
2849
+
2850
+		$nonce_ref          = $this->_req_action . '_nonce';
2851
+		$hidden_form_fields .= '
2852 2852
             <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2853 2853
 
2854
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2855
-        // display message about search results?
2856
-        $search = $this->request->getRequestParam('s');
2857
-        $this->_template_args['before_list_table'] .= ! empty($search)
2858
-            ? '<p class="ee-search-results">' . sprintf(
2859
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2860
-                trim($search, '%')
2861
-            ) . '</p>'
2862
-            : '';
2863
-        // filter before_list_table template arg
2864
-        $this->_template_args['before_list_table'] = apply_filters(
2865
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2866
-            $this->_template_args['before_list_table'],
2867
-            $this->page_slug,
2868
-            $this->request->requestParams(),
2869
-            $this->_req_action
2870
-        );
2871
-        // convert to array and filter again
2872
-        // arrays are easier to inject new items in a specific location,
2873
-        // but would not be backwards compatible, so we have to add a new filter
2874
-        $this->_template_args['before_list_table'] = implode(
2875
-            " \n",
2876
-            (array) apply_filters(
2877
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2878
-                (array) $this->_template_args['before_list_table'],
2879
-                $this->page_slug,
2880
-                $this->request->requestParams(),
2881
-                $this->_req_action
2882
-            )
2883
-        );
2884
-        // filter after_list_table template arg
2885
-        $this->_template_args['after_list_table'] = apply_filters(
2886
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2887
-            $this->_template_args['after_list_table'],
2888
-            $this->page_slug,
2889
-            $this->request->requestParams(),
2890
-            $this->_req_action
2891
-        );
2892
-        // convert to array and filter again
2893
-        // arrays are easier to inject new items in a specific location,
2894
-        // but would not be backwards compatible, so we have to add a new filter
2895
-        $this->_template_args['after_list_table']   = implode(
2896
-            " \n",
2897
-            (array) apply_filters(
2898
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2899
-                (array) $this->_template_args['after_list_table'],
2900
-                $this->page_slug,
2901
-                $this->request->requestParams(),
2902
-                $this->_req_action
2903
-            )
2904
-        );
2905
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2906
-            $template_path,
2907
-            $this->_template_args,
2908
-            true
2909
-        );
2910
-        // the final template wrapper
2911
-        if ($sidebar) {
2912
-            $this->display_admin_page_with_sidebar();
2913
-        } else {
2914
-            $this->display_admin_page_with_no_sidebar();
2915
-        }
2916
-    }
2917
-
2918
-
2919
-    /**
2920
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2921
-     * html string for the legend.
2922
-     * $items are expected in an array in the following format:
2923
-     * $legend_items = array(
2924
-     *        'item_id' => array(
2925
-     *            'icon' => 'http://url_to_icon_being_described.png',
2926
-     *            'desc' => esc_html__('localized description of item');
2927
-     *        )
2928
-     * );
2929
-     *
2930
-     * @param array $items see above for format of array
2931
-     * @return string html string of legend
2932
-     * @throws DomainException
2933
-     */
2934
-    protected function _display_legend($items)
2935
-    {
2936
-        $this->_template_args['items'] = apply_filters(
2937
-            'FHEE__EE_Admin_Page___display_legend__items',
2938
-            (array) $items,
2939
-            $this
2940
-        );
2941
-        return EEH_Template::display_template(
2942
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2943
-            $this->_template_args,
2944
-            true
2945
-        );
2946
-    }
2947
-
2948
-
2949
-    /**
2950
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2951
-     * The returned json object is created from an array in the following format:
2952
-     * array(
2953
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2954
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2955
-     *  'notices' => '', // - contains any EE_Error formatted notices
2956
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2957
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2958
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
2959
-     *  that might be included in here)
2960
-     * )
2961
-     * The json object is populated by whatever is set in the $_template_args property.
2962
-     *
2963
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2964
-     *                                 instead of displayed.
2965
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2966
-     * @return void
2967
-     * @throws EE_Error
2968
-     */
2969
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
2970
-    {
2971
-        // make sure any EE_Error notices have been handled.
2972
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2973
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
2974
-        unset($this->_template_args['data']);
2975
-        $json = [
2976
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2977
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2978
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2979
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2980
-            'notices'   => EE_Error::get_notices(),
2981
-            'content'   => isset($this->_template_args['admin_page_content'])
2982
-                ? $this->_template_args['admin_page_content'] : '',
2983
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
2984
-            'isEEajax'  => true
2985
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2986
-        ];
2987
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2988
-        if (null === error_get_last() || ! headers_sent()) {
2989
-            header('Content-Type: application/json; charset=UTF-8');
2990
-        }
2991
-        echo wp_json_encode($json);
2992
-        exit();
2993
-    }
2994
-
2995
-
2996
-    /**
2997
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2998
-     *
2999
-     * @return void
3000
-     * @throws EE_Error
3001
-     */
3002
-    public function return_json()
3003
-    {
3004
-        if ($this->request->isAjax()) {
3005
-            $this->_return_json();
3006
-        } else {
3007
-            throw new EE_Error(
3008
-                sprintf(
3009
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3010
-                    __FUNCTION__
3011
-                )
3012
-            );
3013
-        }
3014
-    }
3015
-
3016
-
3017
-    /**
3018
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3019
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3020
-     *
3021
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3022
-     */
3023
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3024
-    {
3025
-        $this->_hook_obj = $hook_obj;
3026
-    }
3027
-
3028
-
3029
-    /**
3030
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3031
-     *
3032
-     * @param boolean $about whether to use the special about page wrapper or default.
3033
-     * @return void
3034
-     * @throws DomainException
3035
-     * @throws EE_Error
3036
-     */
3037
-    public function admin_page_wrapper($about = false)
3038
-    {
3039
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3040
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3041
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3042
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3043
-
3044
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3045
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3046
-            isset($this->_template_args['before_admin_page_content'])
3047
-                ? $this->_template_args['before_admin_page_content']
3048
-                : ''
3049
-        );
3050
-
3051
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3052
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3053
-            isset($this->_template_args['after_admin_page_content'])
3054
-                ? $this->_template_args['after_admin_page_content']
3055
-                : ''
3056
-        );
3057
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3058
-
3059
-        if ($this->request->isAjax()) {
3060
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3061
-                // $template_path,
3062
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3063
-                $this->_template_args,
3064
-                true
3065
-            );
3066
-            $this->_return_json();
3067
-        }
3068
-        // load settings page wrapper template
3069
-        $template_path = $about
3070
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3071
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3072
-
3073
-        EEH_Template::display_template($template_path, $this->_template_args);
3074
-    }
3075
-
3076
-
3077
-    /**
3078
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3079
-     *
3080
-     * @return string html
3081
-     * @throws EE_Error
3082
-     */
3083
-    protected function _get_main_nav_tabs()
3084
-    {
3085
-        // let's generate the html using the EEH_Tabbed_Content helper.
3086
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3087
-        // (rather than setting in the page_routes array)
3088
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3089
-    }
3090
-
3091
-
3092
-    /**
3093
-     *        sort nav tabs
3094
-     *
3095
-     * @param $a
3096
-     * @param $b
3097
-     * @return int
3098
-     */
3099
-    private function _sort_nav_tabs($a, $b)
3100
-    {
3101
-        if ($a['order'] === $b['order']) {
3102
-            return 0;
3103
-        }
3104
-        return ($a['order'] < $b['order']) ? -1 : 1;
3105
-    }
3106
-
3107
-
3108
-    /**
3109
-     *    generates HTML for the forms used on admin pages
3110
-     *
3111
-     * @param array  $input_vars   - array of input field details
3112
-     * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3113
-     *                             use)
3114
-     * @param bool   $id
3115
-     * @return array|string
3116
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3117
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3118
-     */
3119
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3120
-    {
3121
-        return $generator === 'string'
3122
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3123
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3124
-    }
3125
-
3126
-
3127
-    /**
3128
-     * generates the "Save" and "Save & Close" buttons for edit forms
3129
-     *
3130
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3131
-     *                                   Close" button.
3132
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3133
-     *                                   'Save', [1] => 'save & close')
3134
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3135
-     *                                   via the "name" value in the button).  We can also use this to just dump
3136
-     *                                   default actions by submitting some other value.
3137
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3138
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3139
-     *                                   close (normal form handling).
3140
-     */
3141
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3142
-    {
3143
-        // make sure $text and $actions are in an array
3144
-        $text          = (array) $text;
3145
-        $actions       = (array) $actions;
3146
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3147
-        $button_text   = ! empty($text)
3148
-            ? $text
3149
-            : [
3150
-                esc_html__('Save', 'event_espresso'),
3151
-                esc_html__('Save and Close', 'event_espresso'),
3152
-            ];
3153
-        $default_names = ['save', 'save_and_close'];
3154
-        $buttons = '';
3155
-        foreach ($button_text as $key => $button) {
3156
-            $ref     = $default_names[ $key ];
3157
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3158
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3159
-                        . 'value="' . $button . '" name="' . $name . '" '
3160
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3161
-            if (! $both) {
3162
-                break;
3163
-            }
3164
-        }
3165
-        // add in a hidden index for the current page (so save and close redirects properly)
3166
-        $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3167
-                   . $referrer_url
3168
-                   . '" />';
3169
-        $this->_template_args['save_buttons'] = $buttons;
3170
-    }
3171
-
3172
-
3173
-    /**
3174
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3175
-     *
3176
-     * @param string $route
3177
-     * @param array  $additional_hidden_fields
3178
-     * @see   $this->_set_add_edit_form_tags() for details on params
3179
-     * @since 4.6.0
3180
-     */
3181
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3182
-    {
3183
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3184
-    }
3185
-
3186
-
3187
-    /**
3188
-     * set form open and close tags on add/edit pages.
3189
-     *
3190
-     * @param string $route                    the route you want the form to direct to
3191
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3192
-     * @return void
3193
-     */
3194
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3195
-    {
3196
-        if (empty($route)) {
3197
-            $user_msg = esc_html__(
3198
-                'An error occurred. No action was set for this page\'s form.',
3199
-                'event_espresso'
3200
-            );
3201
-            $dev_msg  = $user_msg . "\n"
3202
-                        . sprintf(
3203
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3204
-                            __FUNCTION__,
3205
-                            __CLASS__
3206
-                        );
3207
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3208
-        }
3209
-        // open form
3210
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3211
-                                                             . $this->_admin_base_url
3212
-                                                             . '" id="'
3213
-                                                             . $route
3214
-                                                             . '_event_form" >';
3215
-        // add nonce
3216
-        $nonce                                             =
3217
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3218
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3219
-        // add REQUIRED form action
3220
-        $hidden_fields = [
3221
-            'action' => ['type' => 'hidden', 'value' => $route],
3222
-        ];
3223
-        // merge arrays
3224
-        $hidden_fields = is_array($additional_hidden_fields)
3225
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3226
-            : $hidden_fields;
3227
-        // generate form fields
3228
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3229
-        // add fields to form
3230
-        foreach ((array) $form_fields as $form_field) {
3231
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3232
-        }
3233
-        // close form
3234
-        $this->_template_args['after_admin_page_content'] = '</form>';
3235
-    }
3236
-
3237
-
3238
-    /**
3239
-     * Public Wrapper for _redirect_after_action() method since its
3240
-     * discovered it would be useful for external code to have access.
3241
-     *
3242
-     * @param bool   $success
3243
-     * @param string $what
3244
-     * @param string $action_desc
3245
-     * @param array  $query_args
3246
-     * @param bool   $override_overwrite
3247
-     * @throws EE_Error
3248
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3249
-     * @since 4.5.0
3250
-     */
3251
-    public function redirect_after_action(
3252
-        $success = false,
3253
-        $what = 'item',
3254
-        $action_desc = 'processed',
3255
-        $query_args = [],
3256
-        $override_overwrite = false
3257
-    ) {
3258
-        $this->_redirect_after_action(
3259
-            $success,
3260
-            $what,
3261
-            $action_desc,
3262
-            $query_args,
3263
-            $override_overwrite
3264
-        );
3265
-    }
3266
-
3267
-
3268
-    /**
3269
-     * Helper method for merging existing request data with the returned redirect url.
3270
-     *
3271
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3272
-     * filters are still applied.
3273
-     *
3274
-     * @param array $new_route_data
3275
-     * @return array
3276
-     */
3277
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3278
-    {
3279
-        foreach ($this->request->requestParams() as $ref => $value) {
3280
-            // unset nonces
3281
-            if (strpos($ref, 'nonce') !== false) {
3282
-                $this->request->unSetRequestParam($ref);
3283
-                continue;
3284
-            }
3285
-            // urlencode values.
3286
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3287
-            $this->request->setRequestParam($ref, $value);
3288
-        }
3289
-        return array_merge($this->request->requestParams(), $new_route_data);
3290
-    }
3291
-
3292
-
3293
-    /**
3294
-     *    _redirect_after_action
3295
-     *
3296
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3297
-     * @param string $what               - what the action was performed on
3298
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3299
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3300
-     *                                   action is completed
3301
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3302
-     *                                   override this so that they show.
3303
-     * @return void
3304
-     * @throws EE_Error
3305
-     */
3306
-    protected function _redirect_after_action(
3307
-        $success = 0,
3308
-        $what = 'item',
3309
-        $action_desc = 'processed',
3310
-        $query_args = [],
3311
-        $override_overwrite = false
3312
-    ) {
3313
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3314
-        // class name for actions/filters.
3315
-        $classname = get_class($this);
3316
-        // set redirect url.
3317
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3318
-        // otherwise we go with whatever is set as the _admin_base_url
3319
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3320
-        $notices      = EE_Error::get_notices(false);
3321
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3322
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3323
-            EE_Error::overwrite_success();
3324
-        }
3325
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3326
-            // how many records affected ? more than one record ? or just one ?
3327
-            if ($success > 1) {
3328
-                // set plural msg
3329
-                EE_Error::add_success(
3330
-                    sprintf(
3331
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3332
-                        $what,
3333
-                        $action_desc
3334
-                    ),
3335
-                    __FILE__,
3336
-                    __FUNCTION__,
3337
-                    __LINE__
3338
-                );
3339
-            } elseif ($success === 1) {
3340
-                // set singular msg
3341
-                EE_Error::add_success(
3342
-                    sprintf(
3343
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3344
-                        $what,
3345
-                        $action_desc
3346
-                    ),
3347
-                    __FILE__,
3348
-                    __FUNCTION__,
3349
-                    __LINE__
3350
-                );
3351
-            }
3352
-        }
3353
-        // check that $query_args isn't something crazy
3354
-        if (! is_array($query_args)) {
3355
-            $query_args = [];
3356
-        }
3357
-        /**
3358
-         * Allow injecting actions before the query_args are modified for possible different
3359
-         * redirections on save and close actions
3360
-         *
3361
-         * @param array $query_args       The original query_args array coming into the
3362
-         *                                method.
3363
-         * @since 4.2.0
3364
-         */
3365
-        do_action(
3366
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3367
-            $query_args
3368
-        );
3369
-        // calculate where we're going (if we have a "save and close" button pushed)
3370
-
3371
-        if (
3372
-            $this->request->requestParamIsSet('save_and_close')
3373
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3374
-        ) {
3375
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3376
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3377
-            // regenerate query args array from referrer URL
3378
-            parse_str($parsed_url['query'], $query_args);
3379
-            // correct page and action will be in the query args now
3380
-            $redirect_url = admin_url('admin.php');
3381
-        }
3382
-        // merge any default query_args set in _default_route_query_args property
3383
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3384
-            $args_to_merge = [];
3385
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3386
-                // is there a wp_referer array in our _default_route_query_args property?
3387
-                if ($query_param === 'wp_referer') {
3388
-                    $query_value = (array) $query_value;
3389
-                    foreach ($query_value as $reference => $value) {
3390
-                        if (strpos($reference, 'nonce') !== false) {
3391
-                            continue;
3392
-                        }
3393
-                        // finally we will override any arguments in the referer with
3394
-                        // what might be set on the _default_route_query_args array.
3395
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3396
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3397
-                        } else {
3398
-                            $args_to_merge[ $reference ] = urlencode($value);
3399
-                        }
3400
-                    }
3401
-                    continue;
3402
-                }
3403
-                $args_to_merge[ $query_param ] = $query_value;
3404
-            }
3405
-            // now let's merge these arguments but override with what was specifically sent in to the
3406
-            // redirect.
3407
-            $query_args = array_merge($args_to_merge, $query_args);
3408
-        }
3409
-        $this->_process_notices($query_args);
3410
-        // generate redirect url
3411
-        // if redirecting to anything other than the main page, add a nonce
3412
-        if (isset($query_args['action'])) {
3413
-            // manually generate wp_nonce and merge that with the query vars
3414
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3415
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3416
-        }
3417
-        // we're adding some hooks and filters in here for processing any things just before redirects
3418
-        // (example: an admin page has done an insert or update and we want to run something after that).
3419
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3420
-        $redirect_url = apply_filters(
3421
-            'FHEE_redirect_' . $classname . $this->_req_action,
3422
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3423
-            $query_args
3424
-        );
3425
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3426
-        if ($this->request->isAjax()) {
3427
-            $default_data                    = [
3428
-                'close'        => true,
3429
-                'redirect_url' => $redirect_url,
3430
-                'where'        => 'main',
3431
-                'what'         => 'append',
3432
-            ];
3433
-            $this->_template_args['success'] = $success;
3434
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3435
-                $default_data,
3436
-                $this->_template_args['data']
3437
-            ) : $default_data;
3438
-            $this->_return_json();
3439
-        }
3440
-        wp_safe_redirect($redirect_url);
3441
-        exit();
3442
-    }
3443
-
3444
-
3445
-    /**
3446
-     * process any notices before redirecting (or returning ajax request)
3447
-     * This method sets the $this->_template_args['notices'] attribute;
3448
-     *
3449
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3450
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3451
-     *                                  page_routes haven't been defined yet.
3452
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3453
-     *                                  still save a transient for the notice.
3454
-     * @return void
3455
-     * @throws EE_Error
3456
-     */
3457
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3458
-    {
3459
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3460
-        if ($this->request->isAjax()) {
3461
-            $notices = EE_Error::get_notices(false);
3462
-            if (empty($this->_template_args['success'])) {
3463
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3464
-            }
3465
-            if (empty($this->_template_args['errors'])) {
3466
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3467
-            }
3468
-            if (empty($this->_template_args['attention'])) {
3469
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3470
-            }
3471
-        }
3472
-        $this->_template_args['notices'] = EE_Error::get_notices();
3473
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3474
-        if (! $this->request->isAjax() || $sticky_notices) {
3475
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3476
-            $this->_add_transient(
3477
-                $route,
3478
-                $this->_template_args['notices'],
3479
-                true,
3480
-                $skip_route_verify
3481
-            );
3482
-        }
3483
-    }
3484
-
3485
-
3486
-    /**
3487
-     * get_action_link_or_button
3488
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3489
-     *
3490
-     * @param string $action        use this to indicate which action the url is generated with.
3491
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3492
-     *                              property.
3493
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3494
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3495
-     * @param string $base_url      If this is not provided
3496
-     *                              the _admin_base_url will be used as the default for the button base_url.
3497
-     *                              Otherwise this value will be used.
3498
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3499
-     * @return string
3500
-     * @throws InvalidArgumentException
3501
-     * @throws InvalidInterfaceException
3502
-     * @throws InvalidDataTypeException
3503
-     * @throws EE_Error
3504
-     */
3505
-    public function get_action_link_or_button(
3506
-        $action,
3507
-        $type = 'add',
3508
-        $extra_request = [],
3509
-        $class = 'button button--primary',
3510
-        $base_url = '',
3511
-        $exclude_nonce = false
3512
-    ) {
3513
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3514
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3515
-            throw new EE_Error(
3516
-                sprintf(
3517
-                    esc_html__(
3518
-                        'There is no page route for given action for the button.  This action was given: %s',
3519
-                        'event_espresso'
3520
-                    ),
3521
-                    $action
3522
-                )
3523
-            );
3524
-        }
3525
-        if (! isset($this->_labels['buttons'][ $type ])) {
3526
-            throw new EE_Error(
3527
-                sprintf(
3528
-                    esc_html__(
3529
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3530
-                        'event_espresso'
3531
-                    ),
3532
-                    $type
3533
-                )
3534
-            );
3535
-        }
3536
-        // finally check user access for this button.
3537
-        $has_access = $this->check_user_access($action, true);
3538
-        if (! $has_access) {
3539
-            return '';
3540
-        }
3541
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3542
-        $query_args = [
3543
-            'action' => $action,
3544
-        ];
3545
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3546
-        if (! empty($extra_request)) {
3547
-            $query_args = array_merge($extra_request, $query_args);
3548
-        }
3549
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3550
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3551
-    }
3552
-
3553
-
3554
-    /**
3555
-     * _per_page_screen_option
3556
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3557
-     *
3558
-     * @return void
3559
-     * @throws InvalidArgumentException
3560
-     * @throws InvalidInterfaceException
3561
-     * @throws InvalidDataTypeException
3562
-     */
3563
-    protected function _per_page_screen_option()
3564
-    {
3565
-        $option = 'per_page';
3566
-        $args   = [
3567
-            'label'   => apply_filters(
3568
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3569
-                $this->_admin_page_title,
3570
-                $this
3571
-            ),
3572
-            'default' => (int) apply_filters(
3573
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3574
-                20
3575
-            ),
3576
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3577
-        ];
3578
-        // ONLY add the screen option if the user has access to it.
3579
-        if ($this->check_user_access($this->_current_view, true)) {
3580
-            add_screen_option($option, $args);
3581
-        }
3582
-    }
3583
-
3584
-
3585
-    /**
3586
-     * set_per_page_screen_option
3587
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3588
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3589
-     * admin_menu.
3590
-     *
3591
-     * @return void
3592
-     */
3593
-    private function _set_per_page_screen_options()
3594
-    {
3595
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3596
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3597
-            if (! $user = wp_get_current_user()) {
3598
-                return;
3599
-            }
3600
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3601
-            if (! $option) {
3602
-                return;
3603
-            }
3604
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3605
-            $map_option = $option;
3606
-            $option     = str_replace('-', '_', $option);
3607
-            switch ($map_option) {
3608
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3609
-                    $max_value = apply_filters(
3610
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3611
-                        999,
3612
-                        $this->_current_page,
3613
-                        $this->_current_view
3614
-                    );
3615
-                    if ($value < 1) {
3616
-                        return;
3617
-                    }
3618
-                    $value = min($value, $max_value);
3619
-                    break;
3620
-                default:
3621
-                    $value = apply_filters(
3622
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3623
-                        false,
3624
-                        $option,
3625
-                        $value
3626
-                    );
3627
-                    if (false === $value) {
3628
-                        return;
3629
-                    }
3630
-                    break;
3631
-            }
3632
-            update_user_meta($user->ID, $option, $value);
3633
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3634
-            exit;
3635
-        }
3636
-    }
3637
-
3638
-
3639
-    /**
3640
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3641
-     *
3642
-     * @param array $data array that will be assigned to template args.
3643
-     */
3644
-    public function set_template_args($data)
3645
-    {
3646
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3647
-    }
3648
-
3649
-
3650
-    /**
3651
-     * This makes available the WP transient system for temporarily moving data between routes
3652
-     *
3653
-     * @param string $route             the route that should receive the transient
3654
-     * @param array  $data              the data that gets sent
3655
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3656
-     *                                  normal route transient.
3657
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3658
-     *                                  when we are adding a transient before page_routes have been defined.
3659
-     * @return void
3660
-     * @throws EE_Error
3661
-     */
3662
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3663
-    {
3664
-        $user_id = get_current_user_id();
3665
-        if (! $skip_route_verify) {
3666
-            $this->_verify_route($route);
3667
-        }
3668
-        // now let's set the string for what kind of transient we're setting
3669
-        $transient = $notices
3670
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3671
-            : 'rte_tx_' . $route . '_' . $user_id;
3672
-        $data      = $notices ? ['notices' => $data] : $data;
3673
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3674
-        $existing = is_multisite() && is_network_admin()
3675
-            ? get_site_transient($transient)
3676
-            : get_transient($transient);
3677
-        if ($existing) {
3678
-            $data = array_merge((array) $data, (array) $existing);
3679
-        }
3680
-        if (is_multisite() && is_network_admin()) {
3681
-            set_site_transient($transient, $data, 8);
3682
-        } else {
3683
-            set_transient($transient, $data, 8);
3684
-        }
3685
-    }
3686
-
3687
-
3688
-    /**
3689
-     * this retrieves the temporary transient that has been set for moving data between routes.
3690
-     *
3691
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3692
-     * @param string $route
3693
-     * @return mixed data
3694
-     */
3695
-    protected function _get_transient($notices = false, $route = '')
3696
-    {
3697
-        $user_id   = get_current_user_id();
3698
-        $route     = ! $route ? $this->_req_action : $route;
3699
-        $transient = $notices
3700
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3701
-            : 'rte_tx_' . $route . '_' . $user_id;
3702
-        $data      = is_multisite() && is_network_admin()
3703
-            ? get_site_transient($transient)
3704
-            : get_transient($transient);
3705
-        // delete transient after retrieval (just in case it hasn't expired);
3706
-        if (is_multisite() && is_network_admin()) {
3707
-            delete_site_transient($transient);
3708
-        } else {
3709
-            delete_transient($transient);
3710
-        }
3711
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3712
-    }
3713
-
3714
-
3715
-    /**
3716
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3717
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3718
-     * default route callback on the EE_Admin page you want it run.)
3719
-     *
3720
-     * @return void
3721
-     */
3722
-    protected function _transient_garbage_collection()
3723
-    {
3724
-        global $wpdb;
3725
-        // retrieve all existing transients
3726
-        $query =
3727
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3728
-        if ($results = $wpdb->get_results($query)) {
3729
-            foreach ($results as $result) {
3730
-                $transient = str_replace('_transient_', '', $result->option_name);
3731
-                get_transient($transient);
3732
-                if (is_multisite() && is_network_admin()) {
3733
-                    get_site_transient($transient);
3734
-                }
3735
-            }
3736
-        }
3737
-    }
3738
-
3739
-
3740
-    /**
3741
-     * get_view
3742
-     *
3743
-     * @return string content of _view property
3744
-     */
3745
-    public function get_view()
3746
-    {
3747
-        return $this->_view;
3748
-    }
3749
-
3750
-
3751
-    /**
3752
-     * getter for the protected $_views property
3753
-     *
3754
-     * @return array
3755
-     */
3756
-    public function get_views()
3757
-    {
3758
-        return $this->_views;
3759
-    }
3760
-
3761
-
3762
-    /**
3763
-     * get_current_page
3764
-     *
3765
-     * @return string _current_page property value
3766
-     */
3767
-    public function get_current_page()
3768
-    {
3769
-        return $this->_current_page;
3770
-    }
3771
-
3772
-
3773
-    /**
3774
-     * get_current_view
3775
-     *
3776
-     * @return string _current_view property value
3777
-     */
3778
-    public function get_current_view()
3779
-    {
3780
-        return $this->_current_view;
3781
-    }
3782
-
3783
-
3784
-    /**
3785
-     * get_current_screen
3786
-     *
3787
-     * @return object The current WP_Screen object
3788
-     */
3789
-    public function get_current_screen()
3790
-    {
3791
-        return $this->_current_screen;
3792
-    }
3793
-
3794
-
3795
-    /**
3796
-     * get_current_page_view_url
3797
-     *
3798
-     * @return string This returns the url for the current_page_view.
3799
-     */
3800
-    public function get_current_page_view_url()
3801
-    {
3802
-        return $this->_current_page_view_url;
3803
-    }
3804
-
3805
-
3806
-    /**
3807
-     * just returns the Request
3808
-     *
3809
-     * @return RequestInterface
3810
-     */
3811
-    public function get_request()
3812
-    {
3813
-        return $this->request;
3814
-    }
3815
-
3816
-
3817
-    /**
3818
-     * just returns the _req_data property
3819
-     *
3820
-     * @return array
3821
-     */
3822
-    public function get_request_data()
3823
-    {
3824
-        return $this->request->requestParams();
3825
-    }
3826
-
3827
-
3828
-    /**
3829
-     * returns the _req_data protected property
3830
-     *
3831
-     * @return string
3832
-     */
3833
-    public function get_req_action()
3834
-    {
3835
-        return $this->_req_action;
3836
-    }
3837
-
3838
-
3839
-    /**
3840
-     * @return bool  value of $_is_caf property
3841
-     */
3842
-    public function is_caf()
3843
-    {
3844
-        return $this->_is_caf;
3845
-    }
3846
-
3847
-
3848
-    /**
3849
-     * @return mixed
3850
-     */
3851
-    public function default_espresso_metaboxes()
3852
-    {
3853
-        return $this->_default_espresso_metaboxes;
3854
-    }
3855
-
3856
-
3857
-    /**
3858
-     * @return mixed
3859
-     */
3860
-    public function admin_base_url()
3861
-    {
3862
-        return $this->_admin_base_url;
3863
-    }
3864
-
3865
-
3866
-    /**
3867
-     * @return mixed
3868
-     */
3869
-    public function wp_page_slug()
3870
-    {
3871
-        return $this->_wp_page_slug;
3872
-    }
3873
-
3874
-
3875
-    /**
3876
-     * updates  espresso configuration settings
3877
-     *
3878
-     * @param string                   $tab
3879
-     * @param EE_Config_Base|EE_Config $config
3880
-     * @param string                   $file file where error occurred
3881
-     * @param string                   $func function  where error occurred
3882
-     * @param string                   $line line no where error occurred
3883
-     * @return boolean
3884
-     */
3885
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3886
-    {
3887
-        // remove any options that are NOT going to be saved with the config settings.
3888
-        if (isset($config->core->ee_ueip_optin)) {
3889
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3890
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3891
-            update_option('ee_ueip_has_notified', true);
3892
-        }
3893
-        // and save it (note we're also doing the network save here)
3894
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3895
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3896
-        if ($config_saved && $net_saved) {
3897
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3898
-            return true;
3899
-        }
3900
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3901
-        return false;
3902
-    }
3903
-
3904
-
3905
-    /**
3906
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3907
-     *
3908
-     * @return array
3909
-     */
3910
-    public function get_yes_no_values()
3911
-    {
3912
-        return $this->_yes_no_values;
3913
-    }
3914
-
3915
-
3916
-    protected function _get_dir()
3917
-    {
3918
-        $reflector = new ReflectionClass(get_class($this));
3919
-        return dirname($reflector->getFileName());
3920
-    }
3921
-
3922
-
3923
-    /**
3924
-     * A helper for getting a "next link".
3925
-     *
3926
-     * @param string $url   The url to link to
3927
-     * @param string $class The class to use.
3928
-     * @return string
3929
-     */
3930
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3931
-    {
3932
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3933
-    }
3934
-
3935
-
3936
-    /**
3937
-     * A helper for getting a "previous link".
3938
-     *
3939
-     * @param string $url   The url to link to
3940
-     * @param string $class The class to use.
3941
-     * @return string
3942
-     */
3943
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3944
-    {
3945
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3946
-    }
3947
-
3948
-
3949
-
3950
-
3951
-
3952
-
3953
-
3954
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3955
-
3956
-
3957
-    /**
3958
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
3959
-     * 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
3960
-     * _req_data array.
3961
-     *
3962
-     * @return bool success/fail
3963
-     * @throws EE_Error
3964
-     * @throws InvalidArgumentException
3965
-     * @throws ReflectionException
3966
-     * @throws InvalidDataTypeException
3967
-     * @throws InvalidInterfaceException
3968
-     */
3969
-    protected function _process_resend_registration()
3970
-    {
3971
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3972
-        do_action(
3973
-            'AHEE__EE_Admin_Page___process_resend_registration',
3974
-            $this->_template_args['success'],
3975
-            $this->request->requestParams()
3976
-        );
3977
-        return $this->_template_args['success'];
3978
-    }
3979
-
3980
-
3981
-    /**
3982
-     * This automatically processes any payment message notifications when manual payment has been applied.
3983
-     *
3984
-     * @param EE_Payment $payment
3985
-     * @return bool success/fail
3986
-     */
3987
-    protected function _process_payment_notification(EE_Payment $payment)
3988
-    {
3989
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3990
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3991
-        $this->_template_args['success'] = apply_filters(
3992
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
3993
-            false,
3994
-            $payment
3995
-        );
3996
-        return $this->_template_args['success'];
3997
-    }
3998
-
3999
-
4000
-    /**
4001
-     * @param EEM_Base      $entity_model
4002
-     * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4003
-     * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4004
-     * @param string        $delete_column  name of the field that denotes whether entity is trashed
4005
-     * @param callable|null $callback       called after entity is trashed, restored, or deleted
4006
-     * @return int|float
4007
-     * @throws EE_Error
4008
-     */
4009
-    protected function trashRestoreDeleteEntities(
4010
-        EEM_Base $entity_model,
4011
-        $entity_PK_name,
4012
-        $action = EE_Admin_List_Table::ACTION_DELETE,
4013
-        $delete_column = '',
4014
-        callable $callback = null
4015
-    ) {
4016
-        $entity_PK      = $entity_model->get_primary_key_field();
4017
-        $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4018
-        $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4019
-        // grab ID if deleting a single entity
4020
-        if ($this->request->requestParamIsSet($entity_PK_name)) {
4021
-            $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4022
-            return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4023
-        }
4024
-        // or grab checkbox array if bulk deleting
4025
-        $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4026
-        if (empty($checkboxes)) {
4027
-            return 0;
4028
-        }
4029
-        $success = 0;
4030
-        $IDs     = array_keys($checkboxes);
4031
-        // cycle thru bulk action checkboxes
4032
-        foreach ($IDs as $ID) {
4033
-            // increment $success
4034
-            if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4035
-                $success++;
4036
-            }
4037
-        }
4038
-        $count = (int) count($checkboxes);
4039
-        // if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4040
-        // otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4041
-        return $success === $count ? $count : $success / $count;
4042
-    }
4043
-
4044
-
4045
-    /**
4046
-     * @param EE_Primary_Key_Field_Base $entity_PK
4047
-     * @return string
4048
-     * @throws EE_Error
4049
-     * @since   4.10.30.p
4050
-     */
4051
-    private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK)
4052
-    {
4053
-        $entity_PK_type = $entity_PK->getSchemaType();
4054
-        switch ($entity_PK_type) {
4055
-            case 'boolean':
4056
-                return 'bool';
4057
-            case 'integer':
4058
-                return 'int';
4059
-            case 'number':
4060
-                return 'float';
4061
-            case 'string':
4062
-                return 'string';
4063
-        }
4064
-        throw new RuntimeException(
4065
-            sprintf(
4066
-                esc_html__(
4067
-                    '"%1$s" is an invalid schema type for the %2$s primary key.',
4068
-                    'event_espresso'
4069
-                ),
4070
-                $entity_PK_type,
4071
-                $entity_PK->get_name()
4072
-            )
4073
-        );
4074
-    }
4075
-
4076
-
4077
-    /**
4078
-     * @param EEM_Base      $entity_model
4079
-     * @param int|string    $entity_ID
4080
-     * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4081
-     * @param string        $delete_column name of the field that denotes whether entity is trashed
4082
-     * @param callable|null $callback      called after entity is trashed, restored, or deleted
4083
-     * @return bool
4084
-     */
4085
-    protected function trashRestoreDeleteEntity(
4086
-        EEM_Base $entity_model,
4087
-        $entity_ID,
4088
-        $action,
4089
-        $delete_column,
4090
-        callable $callback = null
4091
-    ) {
4092
-        $entity_ID = absint($entity_ID);
4093
-        if (! $entity_ID) {
4094
-            $this->trashRestoreDeleteError($action, $entity_model);
4095
-        }
4096
-        $result = 0;
4097
-        try {
4098
-            $entity = $entity_model->get_one_by_ID($entity_ID);
4099
-            if (! $entity instanceof EE_Base_Class) {
4100
-                throw new DomainException(
4101
-                    sprintf(
4102
-                        esc_html__(
4103
-                            'Missing or invalid %1$s entity with ID of "%2$s" returned from db.',
4104
-                            'event_espresso'
4105
-                        ),
4106
-                        str_replace('EEM_', '', $entity_model->get_this_model_name()),
4107
-                        $entity_ID
4108
-                    )
4109
-                );
4110
-            }
4111
-            switch ($action) {
4112
-                case EE_Admin_List_Table::ACTION_DELETE:
4113
-                    $result = (bool) $entity->delete_permanently();
4114
-                    break;
4115
-                case EE_Admin_List_Table::ACTION_RESTORE:
4116
-                    $result = $entity->delete_or_restore(false);
4117
-                    break;
4118
-                case EE_Admin_List_Table::ACTION_TRASH:
4119
-                    $result = $entity->delete_or_restore();
4120
-                    break;
4121
-            }
4122
-        } catch (Exception $exception) {
4123
-            $this->trashRestoreDeleteError($action, $entity_model, $exception);
4124
-        }
4125
-        if (is_callable($callback)) {
4126
-            call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4127
-        }
4128
-        return $result;
4129
-    }
4130
-
4131
-
4132
-    /**
4133
-     * @param EEM_Base $entity_model
4134
-     * @param string   $delete_column
4135
-     * @since 4.10.30.p
4136
-     */
4137
-    private function validateDeleteColumn(EEM_Base $entity_model, $delete_column)
4138
-    {
4139
-        if (empty($delete_column)) {
4140
-            throw new DomainException(
4141
-                sprintf(
4142
-                    esc_html__(
4143
-                        'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4144
-                        'event_espresso'
4145
-                    ),
4146
-                    $entity_model->get_this_model_name()
4147
-                )
4148
-            );
4149
-        }
4150
-        if (! $entity_model->has_field($delete_column)) {
4151
-            throw new DomainException(
4152
-                sprintf(
4153
-                    esc_html__(
4154
-                        'The %1$s field does not exist on the %2$s model.',
4155
-                        'event_espresso'
4156
-                    ),
4157
-                    $delete_column,
4158
-                    $entity_model->get_this_model_name()
4159
-                )
4160
-            );
4161
-        }
4162
-    }
4163
-
4164
-
4165
-    /**
4166
-     * @param EEM_Base       $entity_model
4167
-     * @param Exception|null $exception
4168
-     * @param string         $action
4169
-     * @since 4.10.30.p
4170
-     */
4171
-    private function trashRestoreDeleteError($action, EEM_Base $entity_model, Exception $exception = null)
4172
-    {
4173
-        if ($exception instanceof Exception) {
4174
-            throw new RuntimeException(
4175
-                sprintf(
4176
-                    esc_html__(
4177
-                        'Could not %1$s the %2$s because the following error occurred: %3$s',
4178
-                        'event_espresso'
4179
-                    ),
4180
-                    $action,
4181
-                    $entity_model->get_this_model_name(),
4182
-                    $exception->getMessage()
4183
-                )
4184
-            );
4185
-        }
4186
-        throw new RuntimeException(
4187
-            sprintf(
4188
-                esc_html__(
4189
-                    'Could not %1$s the %2$s because an invalid ID was received.',
4190
-                    'event_espresso'
4191
-                ),
4192
-                $action,
4193
-                $entity_model->get_this_model_name()
4194
-            )
4195
-        );
4196
-    }
2854
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2855
+		// display message about search results?
2856
+		$search = $this->request->getRequestParam('s');
2857
+		$this->_template_args['before_list_table'] .= ! empty($search)
2858
+			? '<p class="ee-search-results">' . sprintf(
2859
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2860
+				trim($search, '%')
2861
+			) . '</p>'
2862
+			: '';
2863
+		// filter before_list_table template arg
2864
+		$this->_template_args['before_list_table'] = apply_filters(
2865
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2866
+			$this->_template_args['before_list_table'],
2867
+			$this->page_slug,
2868
+			$this->request->requestParams(),
2869
+			$this->_req_action
2870
+		);
2871
+		// convert to array and filter again
2872
+		// arrays are easier to inject new items in a specific location,
2873
+		// but would not be backwards compatible, so we have to add a new filter
2874
+		$this->_template_args['before_list_table'] = implode(
2875
+			" \n",
2876
+			(array) apply_filters(
2877
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2878
+				(array) $this->_template_args['before_list_table'],
2879
+				$this->page_slug,
2880
+				$this->request->requestParams(),
2881
+				$this->_req_action
2882
+			)
2883
+		);
2884
+		// filter after_list_table template arg
2885
+		$this->_template_args['after_list_table'] = apply_filters(
2886
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2887
+			$this->_template_args['after_list_table'],
2888
+			$this->page_slug,
2889
+			$this->request->requestParams(),
2890
+			$this->_req_action
2891
+		);
2892
+		// convert to array and filter again
2893
+		// arrays are easier to inject new items in a specific location,
2894
+		// but would not be backwards compatible, so we have to add a new filter
2895
+		$this->_template_args['after_list_table']   = implode(
2896
+			" \n",
2897
+			(array) apply_filters(
2898
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2899
+				(array) $this->_template_args['after_list_table'],
2900
+				$this->page_slug,
2901
+				$this->request->requestParams(),
2902
+				$this->_req_action
2903
+			)
2904
+		);
2905
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2906
+			$template_path,
2907
+			$this->_template_args,
2908
+			true
2909
+		);
2910
+		// the final template wrapper
2911
+		if ($sidebar) {
2912
+			$this->display_admin_page_with_sidebar();
2913
+		} else {
2914
+			$this->display_admin_page_with_no_sidebar();
2915
+		}
2916
+	}
2917
+
2918
+
2919
+	/**
2920
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2921
+	 * html string for the legend.
2922
+	 * $items are expected in an array in the following format:
2923
+	 * $legend_items = array(
2924
+	 *        'item_id' => array(
2925
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2926
+	 *            'desc' => esc_html__('localized description of item');
2927
+	 *        )
2928
+	 * );
2929
+	 *
2930
+	 * @param array $items see above for format of array
2931
+	 * @return string html string of legend
2932
+	 * @throws DomainException
2933
+	 */
2934
+	protected function _display_legend($items)
2935
+	{
2936
+		$this->_template_args['items'] = apply_filters(
2937
+			'FHEE__EE_Admin_Page___display_legend__items',
2938
+			(array) $items,
2939
+			$this
2940
+		);
2941
+		return EEH_Template::display_template(
2942
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2943
+			$this->_template_args,
2944
+			true
2945
+		);
2946
+	}
2947
+
2948
+
2949
+	/**
2950
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2951
+	 * The returned json object is created from an array in the following format:
2952
+	 * array(
2953
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2954
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2955
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2956
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2957
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2958
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
2959
+	 *  that might be included in here)
2960
+	 * )
2961
+	 * The json object is populated by whatever is set in the $_template_args property.
2962
+	 *
2963
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2964
+	 *                                 instead of displayed.
2965
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2966
+	 * @return void
2967
+	 * @throws EE_Error
2968
+	 */
2969
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
2970
+	{
2971
+		// make sure any EE_Error notices have been handled.
2972
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2973
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
2974
+		unset($this->_template_args['data']);
2975
+		$json = [
2976
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2977
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2978
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2979
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2980
+			'notices'   => EE_Error::get_notices(),
2981
+			'content'   => isset($this->_template_args['admin_page_content'])
2982
+				? $this->_template_args['admin_page_content'] : '',
2983
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
2984
+			'isEEajax'  => true
2985
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2986
+		];
2987
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2988
+		if (null === error_get_last() || ! headers_sent()) {
2989
+			header('Content-Type: application/json; charset=UTF-8');
2990
+		}
2991
+		echo wp_json_encode($json);
2992
+		exit();
2993
+	}
2994
+
2995
+
2996
+	/**
2997
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2998
+	 *
2999
+	 * @return void
3000
+	 * @throws EE_Error
3001
+	 */
3002
+	public function return_json()
3003
+	{
3004
+		if ($this->request->isAjax()) {
3005
+			$this->_return_json();
3006
+		} else {
3007
+			throw new EE_Error(
3008
+				sprintf(
3009
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3010
+					__FUNCTION__
3011
+				)
3012
+			);
3013
+		}
3014
+	}
3015
+
3016
+
3017
+	/**
3018
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3019
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3020
+	 *
3021
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3022
+	 */
3023
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3024
+	{
3025
+		$this->_hook_obj = $hook_obj;
3026
+	}
3027
+
3028
+
3029
+	/**
3030
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3031
+	 *
3032
+	 * @param boolean $about whether to use the special about page wrapper or default.
3033
+	 * @return void
3034
+	 * @throws DomainException
3035
+	 * @throws EE_Error
3036
+	 */
3037
+	public function admin_page_wrapper($about = false)
3038
+	{
3039
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3040
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3041
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3042
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3043
+
3044
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3045
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3046
+			isset($this->_template_args['before_admin_page_content'])
3047
+				? $this->_template_args['before_admin_page_content']
3048
+				: ''
3049
+		);
3050
+
3051
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3052
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3053
+			isset($this->_template_args['after_admin_page_content'])
3054
+				? $this->_template_args['after_admin_page_content']
3055
+				: ''
3056
+		);
3057
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3058
+
3059
+		if ($this->request->isAjax()) {
3060
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3061
+				// $template_path,
3062
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3063
+				$this->_template_args,
3064
+				true
3065
+			);
3066
+			$this->_return_json();
3067
+		}
3068
+		// load settings page wrapper template
3069
+		$template_path = $about
3070
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3071
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3072
+
3073
+		EEH_Template::display_template($template_path, $this->_template_args);
3074
+	}
3075
+
3076
+
3077
+	/**
3078
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3079
+	 *
3080
+	 * @return string html
3081
+	 * @throws EE_Error
3082
+	 */
3083
+	protected function _get_main_nav_tabs()
3084
+	{
3085
+		// let's generate the html using the EEH_Tabbed_Content helper.
3086
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3087
+		// (rather than setting in the page_routes array)
3088
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3089
+	}
3090
+
3091
+
3092
+	/**
3093
+	 *        sort nav tabs
3094
+	 *
3095
+	 * @param $a
3096
+	 * @param $b
3097
+	 * @return int
3098
+	 */
3099
+	private function _sort_nav_tabs($a, $b)
3100
+	{
3101
+		if ($a['order'] === $b['order']) {
3102
+			return 0;
3103
+		}
3104
+		return ($a['order'] < $b['order']) ? -1 : 1;
3105
+	}
3106
+
3107
+
3108
+	/**
3109
+	 *    generates HTML for the forms used on admin pages
3110
+	 *
3111
+	 * @param array  $input_vars   - array of input field details
3112
+	 * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3113
+	 *                             use)
3114
+	 * @param bool   $id
3115
+	 * @return array|string
3116
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3117
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3118
+	 */
3119
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3120
+	{
3121
+		return $generator === 'string'
3122
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3123
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3124
+	}
3125
+
3126
+
3127
+	/**
3128
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3129
+	 *
3130
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3131
+	 *                                   Close" button.
3132
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3133
+	 *                                   'Save', [1] => 'save & close')
3134
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3135
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3136
+	 *                                   default actions by submitting some other value.
3137
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3138
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3139
+	 *                                   close (normal form handling).
3140
+	 */
3141
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3142
+	{
3143
+		// make sure $text and $actions are in an array
3144
+		$text          = (array) $text;
3145
+		$actions       = (array) $actions;
3146
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3147
+		$button_text   = ! empty($text)
3148
+			? $text
3149
+			: [
3150
+				esc_html__('Save', 'event_espresso'),
3151
+				esc_html__('Save and Close', 'event_espresso'),
3152
+			];
3153
+		$default_names = ['save', 'save_and_close'];
3154
+		$buttons = '';
3155
+		foreach ($button_text as $key => $button) {
3156
+			$ref     = $default_names[ $key ];
3157
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3158
+			$buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3159
+						. 'value="' . $button . '" name="' . $name . '" '
3160
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3161
+			if (! $both) {
3162
+				break;
3163
+			}
3164
+		}
3165
+		// add in a hidden index for the current page (so save and close redirects properly)
3166
+		$buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3167
+				   . $referrer_url
3168
+				   . '" />';
3169
+		$this->_template_args['save_buttons'] = $buttons;
3170
+	}
3171
+
3172
+
3173
+	/**
3174
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3175
+	 *
3176
+	 * @param string $route
3177
+	 * @param array  $additional_hidden_fields
3178
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3179
+	 * @since 4.6.0
3180
+	 */
3181
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3182
+	{
3183
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3184
+	}
3185
+
3186
+
3187
+	/**
3188
+	 * set form open and close tags on add/edit pages.
3189
+	 *
3190
+	 * @param string $route                    the route you want the form to direct to
3191
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3192
+	 * @return void
3193
+	 */
3194
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3195
+	{
3196
+		if (empty($route)) {
3197
+			$user_msg = esc_html__(
3198
+				'An error occurred. No action was set for this page\'s form.',
3199
+				'event_espresso'
3200
+			);
3201
+			$dev_msg  = $user_msg . "\n"
3202
+						. sprintf(
3203
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3204
+							__FUNCTION__,
3205
+							__CLASS__
3206
+						);
3207
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3208
+		}
3209
+		// open form
3210
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3211
+															 . $this->_admin_base_url
3212
+															 . '" id="'
3213
+															 . $route
3214
+															 . '_event_form" >';
3215
+		// add nonce
3216
+		$nonce                                             =
3217
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3218
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3219
+		// add REQUIRED form action
3220
+		$hidden_fields = [
3221
+			'action' => ['type' => 'hidden', 'value' => $route],
3222
+		];
3223
+		// merge arrays
3224
+		$hidden_fields = is_array($additional_hidden_fields)
3225
+			? array_merge($hidden_fields, $additional_hidden_fields)
3226
+			: $hidden_fields;
3227
+		// generate form fields
3228
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3229
+		// add fields to form
3230
+		foreach ((array) $form_fields as $form_field) {
3231
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3232
+		}
3233
+		// close form
3234
+		$this->_template_args['after_admin_page_content'] = '</form>';
3235
+	}
3236
+
3237
+
3238
+	/**
3239
+	 * Public Wrapper for _redirect_after_action() method since its
3240
+	 * discovered it would be useful for external code to have access.
3241
+	 *
3242
+	 * @param bool   $success
3243
+	 * @param string $what
3244
+	 * @param string $action_desc
3245
+	 * @param array  $query_args
3246
+	 * @param bool   $override_overwrite
3247
+	 * @throws EE_Error
3248
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3249
+	 * @since 4.5.0
3250
+	 */
3251
+	public function redirect_after_action(
3252
+		$success = false,
3253
+		$what = 'item',
3254
+		$action_desc = 'processed',
3255
+		$query_args = [],
3256
+		$override_overwrite = false
3257
+	) {
3258
+		$this->_redirect_after_action(
3259
+			$success,
3260
+			$what,
3261
+			$action_desc,
3262
+			$query_args,
3263
+			$override_overwrite
3264
+		);
3265
+	}
3266
+
3267
+
3268
+	/**
3269
+	 * Helper method for merging existing request data with the returned redirect url.
3270
+	 *
3271
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3272
+	 * filters are still applied.
3273
+	 *
3274
+	 * @param array $new_route_data
3275
+	 * @return array
3276
+	 */
3277
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3278
+	{
3279
+		foreach ($this->request->requestParams() as $ref => $value) {
3280
+			// unset nonces
3281
+			if (strpos($ref, 'nonce') !== false) {
3282
+				$this->request->unSetRequestParam($ref);
3283
+				continue;
3284
+			}
3285
+			// urlencode values.
3286
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3287
+			$this->request->setRequestParam($ref, $value);
3288
+		}
3289
+		return array_merge($this->request->requestParams(), $new_route_data);
3290
+	}
3291
+
3292
+
3293
+	/**
3294
+	 *    _redirect_after_action
3295
+	 *
3296
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3297
+	 * @param string $what               - what the action was performed on
3298
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3299
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3300
+	 *                                   action is completed
3301
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3302
+	 *                                   override this so that they show.
3303
+	 * @return void
3304
+	 * @throws EE_Error
3305
+	 */
3306
+	protected function _redirect_after_action(
3307
+		$success = 0,
3308
+		$what = 'item',
3309
+		$action_desc = 'processed',
3310
+		$query_args = [],
3311
+		$override_overwrite = false
3312
+	) {
3313
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3314
+		// class name for actions/filters.
3315
+		$classname = get_class($this);
3316
+		// set redirect url.
3317
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3318
+		// otherwise we go with whatever is set as the _admin_base_url
3319
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3320
+		$notices      = EE_Error::get_notices(false);
3321
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3322
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3323
+			EE_Error::overwrite_success();
3324
+		}
3325
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3326
+			// how many records affected ? more than one record ? or just one ?
3327
+			if ($success > 1) {
3328
+				// set plural msg
3329
+				EE_Error::add_success(
3330
+					sprintf(
3331
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3332
+						$what,
3333
+						$action_desc
3334
+					),
3335
+					__FILE__,
3336
+					__FUNCTION__,
3337
+					__LINE__
3338
+				);
3339
+			} elseif ($success === 1) {
3340
+				// set singular msg
3341
+				EE_Error::add_success(
3342
+					sprintf(
3343
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3344
+						$what,
3345
+						$action_desc
3346
+					),
3347
+					__FILE__,
3348
+					__FUNCTION__,
3349
+					__LINE__
3350
+				);
3351
+			}
3352
+		}
3353
+		// check that $query_args isn't something crazy
3354
+		if (! is_array($query_args)) {
3355
+			$query_args = [];
3356
+		}
3357
+		/**
3358
+		 * Allow injecting actions before the query_args are modified for possible different
3359
+		 * redirections on save and close actions
3360
+		 *
3361
+		 * @param array $query_args       The original query_args array coming into the
3362
+		 *                                method.
3363
+		 * @since 4.2.0
3364
+		 */
3365
+		do_action(
3366
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3367
+			$query_args
3368
+		);
3369
+		// calculate where we're going (if we have a "save and close" button pushed)
3370
+
3371
+		if (
3372
+			$this->request->requestParamIsSet('save_and_close')
3373
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3374
+		) {
3375
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3376
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3377
+			// regenerate query args array from referrer URL
3378
+			parse_str($parsed_url['query'], $query_args);
3379
+			// correct page and action will be in the query args now
3380
+			$redirect_url = admin_url('admin.php');
3381
+		}
3382
+		// merge any default query_args set in _default_route_query_args property
3383
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3384
+			$args_to_merge = [];
3385
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3386
+				// is there a wp_referer array in our _default_route_query_args property?
3387
+				if ($query_param === 'wp_referer') {
3388
+					$query_value = (array) $query_value;
3389
+					foreach ($query_value as $reference => $value) {
3390
+						if (strpos($reference, 'nonce') !== false) {
3391
+							continue;
3392
+						}
3393
+						// finally we will override any arguments in the referer with
3394
+						// what might be set on the _default_route_query_args array.
3395
+						if (isset($this->_default_route_query_args[ $reference ])) {
3396
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3397
+						} else {
3398
+							$args_to_merge[ $reference ] = urlencode($value);
3399
+						}
3400
+					}
3401
+					continue;
3402
+				}
3403
+				$args_to_merge[ $query_param ] = $query_value;
3404
+			}
3405
+			// now let's merge these arguments but override with what was specifically sent in to the
3406
+			// redirect.
3407
+			$query_args = array_merge($args_to_merge, $query_args);
3408
+		}
3409
+		$this->_process_notices($query_args);
3410
+		// generate redirect url
3411
+		// if redirecting to anything other than the main page, add a nonce
3412
+		if (isset($query_args['action'])) {
3413
+			// manually generate wp_nonce and merge that with the query vars
3414
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3415
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3416
+		}
3417
+		// we're adding some hooks and filters in here for processing any things just before redirects
3418
+		// (example: an admin page has done an insert or update and we want to run something after that).
3419
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3420
+		$redirect_url = apply_filters(
3421
+			'FHEE_redirect_' . $classname . $this->_req_action,
3422
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3423
+			$query_args
3424
+		);
3425
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3426
+		if ($this->request->isAjax()) {
3427
+			$default_data                    = [
3428
+				'close'        => true,
3429
+				'redirect_url' => $redirect_url,
3430
+				'where'        => 'main',
3431
+				'what'         => 'append',
3432
+			];
3433
+			$this->_template_args['success'] = $success;
3434
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3435
+				$default_data,
3436
+				$this->_template_args['data']
3437
+			) : $default_data;
3438
+			$this->_return_json();
3439
+		}
3440
+		wp_safe_redirect($redirect_url);
3441
+		exit();
3442
+	}
3443
+
3444
+
3445
+	/**
3446
+	 * process any notices before redirecting (or returning ajax request)
3447
+	 * This method sets the $this->_template_args['notices'] attribute;
3448
+	 *
3449
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3450
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3451
+	 *                                  page_routes haven't been defined yet.
3452
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3453
+	 *                                  still save a transient for the notice.
3454
+	 * @return void
3455
+	 * @throws EE_Error
3456
+	 */
3457
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3458
+	{
3459
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3460
+		if ($this->request->isAjax()) {
3461
+			$notices = EE_Error::get_notices(false);
3462
+			if (empty($this->_template_args['success'])) {
3463
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3464
+			}
3465
+			if (empty($this->_template_args['errors'])) {
3466
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3467
+			}
3468
+			if (empty($this->_template_args['attention'])) {
3469
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3470
+			}
3471
+		}
3472
+		$this->_template_args['notices'] = EE_Error::get_notices();
3473
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3474
+		if (! $this->request->isAjax() || $sticky_notices) {
3475
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3476
+			$this->_add_transient(
3477
+				$route,
3478
+				$this->_template_args['notices'],
3479
+				true,
3480
+				$skip_route_verify
3481
+			);
3482
+		}
3483
+	}
3484
+
3485
+
3486
+	/**
3487
+	 * get_action_link_or_button
3488
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3489
+	 *
3490
+	 * @param string $action        use this to indicate which action the url is generated with.
3491
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3492
+	 *                              property.
3493
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3494
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3495
+	 * @param string $base_url      If this is not provided
3496
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3497
+	 *                              Otherwise this value will be used.
3498
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3499
+	 * @return string
3500
+	 * @throws InvalidArgumentException
3501
+	 * @throws InvalidInterfaceException
3502
+	 * @throws InvalidDataTypeException
3503
+	 * @throws EE_Error
3504
+	 */
3505
+	public function get_action_link_or_button(
3506
+		$action,
3507
+		$type = 'add',
3508
+		$extra_request = [],
3509
+		$class = 'button button--primary',
3510
+		$base_url = '',
3511
+		$exclude_nonce = false
3512
+	) {
3513
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3514
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3515
+			throw new EE_Error(
3516
+				sprintf(
3517
+					esc_html__(
3518
+						'There is no page route for given action for the button.  This action was given: %s',
3519
+						'event_espresso'
3520
+					),
3521
+					$action
3522
+				)
3523
+			);
3524
+		}
3525
+		if (! isset($this->_labels['buttons'][ $type ])) {
3526
+			throw new EE_Error(
3527
+				sprintf(
3528
+					esc_html__(
3529
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3530
+						'event_espresso'
3531
+					),
3532
+					$type
3533
+				)
3534
+			);
3535
+		}
3536
+		// finally check user access for this button.
3537
+		$has_access = $this->check_user_access($action, true);
3538
+		if (! $has_access) {
3539
+			return '';
3540
+		}
3541
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3542
+		$query_args = [
3543
+			'action' => $action,
3544
+		];
3545
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3546
+		if (! empty($extra_request)) {
3547
+			$query_args = array_merge($extra_request, $query_args);
3548
+		}
3549
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3550
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3551
+	}
3552
+
3553
+
3554
+	/**
3555
+	 * _per_page_screen_option
3556
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3557
+	 *
3558
+	 * @return void
3559
+	 * @throws InvalidArgumentException
3560
+	 * @throws InvalidInterfaceException
3561
+	 * @throws InvalidDataTypeException
3562
+	 */
3563
+	protected function _per_page_screen_option()
3564
+	{
3565
+		$option = 'per_page';
3566
+		$args   = [
3567
+			'label'   => apply_filters(
3568
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3569
+				$this->_admin_page_title,
3570
+				$this
3571
+			),
3572
+			'default' => (int) apply_filters(
3573
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3574
+				20
3575
+			),
3576
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3577
+		];
3578
+		// ONLY add the screen option if the user has access to it.
3579
+		if ($this->check_user_access($this->_current_view, true)) {
3580
+			add_screen_option($option, $args);
3581
+		}
3582
+	}
3583
+
3584
+
3585
+	/**
3586
+	 * set_per_page_screen_option
3587
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3588
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3589
+	 * admin_menu.
3590
+	 *
3591
+	 * @return void
3592
+	 */
3593
+	private function _set_per_page_screen_options()
3594
+	{
3595
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3596
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3597
+			if (! $user = wp_get_current_user()) {
3598
+				return;
3599
+			}
3600
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3601
+			if (! $option) {
3602
+				return;
3603
+			}
3604
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3605
+			$map_option = $option;
3606
+			$option     = str_replace('-', '_', $option);
3607
+			switch ($map_option) {
3608
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3609
+					$max_value = apply_filters(
3610
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3611
+						999,
3612
+						$this->_current_page,
3613
+						$this->_current_view
3614
+					);
3615
+					if ($value < 1) {
3616
+						return;
3617
+					}
3618
+					$value = min($value, $max_value);
3619
+					break;
3620
+				default:
3621
+					$value = apply_filters(
3622
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3623
+						false,
3624
+						$option,
3625
+						$value
3626
+					);
3627
+					if (false === $value) {
3628
+						return;
3629
+					}
3630
+					break;
3631
+			}
3632
+			update_user_meta($user->ID, $option, $value);
3633
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3634
+			exit;
3635
+		}
3636
+	}
3637
+
3638
+
3639
+	/**
3640
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3641
+	 *
3642
+	 * @param array $data array that will be assigned to template args.
3643
+	 */
3644
+	public function set_template_args($data)
3645
+	{
3646
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3647
+	}
3648
+
3649
+
3650
+	/**
3651
+	 * This makes available the WP transient system for temporarily moving data between routes
3652
+	 *
3653
+	 * @param string $route             the route that should receive the transient
3654
+	 * @param array  $data              the data that gets sent
3655
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3656
+	 *                                  normal route transient.
3657
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3658
+	 *                                  when we are adding a transient before page_routes have been defined.
3659
+	 * @return void
3660
+	 * @throws EE_Error
3661
+	 */
3662
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3663
+	{
3664
+		$user_id = get_current_user_id();
3665
+		if (! $skip_route_verify) {
3666
+			$this->_verify_route($route);
3667
+		}
3668
+		// now let's set the string for what kind of transient we're setting
3669
+		$transient = $notices
3670
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3671
+			: 'rte_tx_' . $route . '_' . $user_id;
3672
+		$data      = $notices ? ['notices' => $data] : $data;
3673
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3674
+		$existing = is_multisite() && is_network_admin()
3675
+			? get_site_transient($transient)
3676
+			: get_transient($transient);
3677
+		if ($existing) {
3678
+			$data = array_merge((array) $data, (array) $existing);
3679
+		}
3680
+		if (is_multisite() && is_network_admin()) {
3681
+			set_site_transient($transient, $data, 8);
3682
+		} else {
3683
+			set_transient($transient, $data, 8);
3684
+		}
3685
+	}
3686
+
3687
+
3688
+	/**
3689
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3690
+	 *
3691
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3692
+	 * @param string $route
3693
+	 * @return mixed data
3694
+	 */
3695
+	protected function _get_transient($notices = false, $route = '')
3696
+	{
3697
+		$user_id   = get_current_user_id();
3698
+		$route     = ! $route ? $this->_req_action : $route;
3699
+		$transient = $notices
3700
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3701
+			: 'rte_tx_' . $route . '_' . $user_id;
3702
+		$data      = is_multisite() && is_network_admin()
3703
+			? get_site_transient($transient)
3704
+			: get_transient($transient);
3705
+		// delete transient after retrieval (just in case it hasn't expired);
3706
+		if (is_multisite() && is_network_admin()) {
3707
+			delete_site_transient($transient);
3708
+		} else {
3709
+			delete_transient($transient);
3710
+		}
3711
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3712
+	}
3713
+
3714
+
3715
+	/**
3716
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3717
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3718
+	 * default route callback on the EE_Admin page you want it run.)
3719
+	 *
3720
+	 * @return void
3721
+	 */
3722
+	protected function _transient_garbage_collection()
3723
+	{
3724
+		global $wpdb;
3725
+		// retrieve all existing transients
3726
+		$query =
3727
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3728
+		if ($results = $wpdb->get_results($query)) {
3729
+			foreach ($results as $result) {
3730
+				$transient = str_replace('_transient_', '', $result->option_name);
3731
+				get_transient($transient);
3732
+				if (is_multisite() && is_network_admin()) {
3733
+					get_site_transient($transient);
3734
+				}
3735
+			}
3736
+		}
3737
+	}
3738
+
3739
+
3740
+	/**
3741
+	 * get_view
3742
+	 *
3743
+	 * @return string content of _view property
3744
+	 */
3745
+	public function get_view()
3746
+	{
3747
+		return $this->_view;
3748
+	}
3749
+
3750
+
3751
+	/**
3752
+	 * getter for the protected $_views property
3753
+	 *
3754
+	 * @return array
3755
+	 */
3756
+	public function get_views()
3757
+	{
3758
+		return $this->_views;
3759
+	}
3760
+
3761
+
3762
+	/**
3763
+	 * get_current_page
3764
+	 *
3765
+	 * @return string _current_page property value
3766
+	 */
3767
+	public function get_current_page()
3768
+	{
3769
+		return $this->_current_page;
3770
+	}
3771
+
3772
+
3773
+	/**
3774
+	 * get_current_view
3775
+	 *
3776
+	 * @return string _current_view property value
3777
+	 */
3778
+	public function get_current_view()
3779
+	{
3780
+		return $this->_current_view;
3781
+	}
3782
+
3783
+
3784
+	/**
3785
+	 * get_current_screen
3786
+	 *
3787
+	 * @return object The current WP_Screen object
3788
+	 */
3789
+	public function get_current_screen()
3790
+	{
3791
+		return $this->_current_screen;
3792
+	}
3793
+
3794
+
3795
+	/**
3796
+	 * get_current_page_view_url
3797
+	 *
3798
+	 * @return string This returns the url for the current_page_view.
3799
+	 */
3800
+	public function get_current_page_view_url()
3801
+	{
3802
+		return $this->_current_page_view_url;
3803
+	}
3804
+
3805
+
3806
+	/**
3807
+	 * just returns the Request
3808
+	 *
3809
+	 * @return RequestInterface
3810
+	 */
3811
+	public function get_request()
3812
+	{
3813
+		return $this->request;
3814
+	}
3815
+
3816
+
3817
+	/**
3818
+	 * just returns the _req_data property
3819
+	 *
3820
+	 * @return array
3821
+	 */
3822
+	public function get_request_data()
3823
+	{
3824
+		return $this->request->requestParams();
3825
+	}
3826
+
3827
+
3828
+	/**
3829
+	 * returns the _req_data protected property
3830
+	 *
3831
+	 * @return string
3832
+	 */
3833
+	public function get_req_action()
3834
+	{
3835
+		return $this->_req_action;
3836
+	}
3837
+
3838
+
3839
+	/**
3840
+	 * @return bool  value of $_is_caf property
3841
+	 */
3842
+	public function is_caf()
3843
+	{
3844
+		return $this->_is_caf;
3845
+	}
3846
+
3847
+
3848
+	/**
3849
+	 * @return mixed
3850
+	 */
3851
+	public function default_espresso_metaboxes()
3852
+	{
3853
+		return $this->_default_espresso_metaboxes;
3854
+	}
3855
+
3856
+
3857
+	/**
3858
+	 * @return mixed
3859
+	 */
3860
+	public function admin_base_url()
3861
+	{
3862
+		return $this->_admin_base_url;
3863
+	}
3864
+
3865
+
3866
+	/**
3867
+	 * @return mixed
3868
+	 */
3869
+	public function wp_page_slug()
3870
+	{
3871
+		return $this->_wp_page_slug;
3872
+	}
3873
+
3874
+
3875
+	/**
3876
+	 * updates  espresso configuration settings
3877
+	 *
3878
+	 * @param string                   $tab
3879
+	 * @param EE_Config_Base|EE_Config $config
3880
+	 * @param string                   $file file where error occurred
3881
+	 * @param string                   $func function  where error occurred
3882
+	 * @param string                   $line line no where error occurred
3883
+	 * @return boolean
3884
+	 */
3885
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3886
+	{
3887
+		// remove any options that are NOT going to be saved with the config settings.
3888
+		if (isset($config->core->ee_ueip_optin)) {
3889
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3890
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3891
+			update_option('ee_ueip_has_notified', true);
3892
+		}
3893
+		// and save it (note we're also doing the network save here)
3894
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3895
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3896
+		if ($config_saved && $net_saved) {
3897
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3898
+			return true;
3899
+		}
3900
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3901
+		return false;
3902
+	}
3903
+
3904
+
3905
+	/**
3906
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3907
+	 *
3908
+	 * @return array
3909
+	 */
3910
+	public function get_yes_no_values()
3911
+	{
3912
+		return $this->_yes_no_values;
3913
+	}
3914
+
3915
+
3916
+	protected function _get_dir()
3917
+	{
3918
+		$reflector = new ReflectionClass(get_class($this));
3919
+		return dirname($reflector->getFileName());
3920
+	}
3921
+
3922
+
3923
+	/**
3924
+	 * A helper for getting a "next link".
3925
+	 *
3926
+	 * @param string $url   The url to link to
3927
+	 * @param string $class The class to use.
3928
+	 * @return string
3929
+	 */
3930
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3931
+	{
3932
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3933
+	}
3934
+
3935
+
3936
+	/**
3937
+	 * A helper for getting a "previous link".
3938
+	 *
3939
+	 * @param string $url   The url to link to
3940
+	 * @param string $class The class to use.
3941
+	 * @return string
3942
+	 */
3943
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3944
+	{
3945
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3946
+	}
3947
+
3948
+
3949
+
3950
+
3951
+
3952
+
3953
+
3954
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3955
+
3956
+
3957
+	/**
3958
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
3959
+	 * 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
3960
+	 * _req_data array.
3961
+	 *
3962
+	 * @return bool success/fail
3963
+	 * @throws EE_Error
3964
+	 * @throws InvalidArgumentException
3965
+	 * @throws ReflectionException
3966
+	 * @throws InvalidDataTypeException
3967
+	 * @throws InvalidInterfaceException
3968
+	 */
3969
+	protected function _process_resend_registration()
3970
+	{
3971
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3972
+		do_action(
3973
+			'AHEE__EE_Admin_Page___process_resend_registration',
3974
+			$this->_template_args['success'],
3975
+			$this->request->requestParams()
3976
+		);
3977
+		return $this->_template_args['success'];
3978
+	}
3979
+
3980
+
3981
+	/**
3982
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3983
+	 *
3984
+	 * @param EE_Payment $payment
3985
+	 * @return bool success/fail
3986
+	 */
3987
+	protected function _process_payment_notification(EE_Payment $payment)
3988
+	{
3989
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3990
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3991
+		$this->_template_args['success'] = apply_filters(
3992
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
3993
+			false,
3994
+			$payment
3995
+		);
3996
+		return $this->_template_args['success'];
3997
+	}
3998
+
3999
+
4000
+	/**
4001
+	 * @param EEM_Base      $entity_model
4002
+	 * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4003
+	 * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4004
+	 * @param string        $delete_column  name of the field that denotes whether entity is trashed
4005
+	 * @param callable|null $callback       called after entity is trashed, restored, or deleted
4006
+	 * @return int|float
4007
+	 * @throws EE_Error
4008
+	 */
4009
+	protected function trashRestoreDeleteEntities(
4010
+		EEM_Base $entity_model,
4011
+		$entity_PK_name,
4012
+		$action = EE_Admin_List_Table::ACTION_DELETE,
4013
+		$delete_column = '',
4014
+		callable $callback = null
4015
+	) {
4016
+		$entity_PK      = $entity_model->get_primary_key_field();
4017
+		$entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4018
+		$entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4019
+		// grab ID if deleting a single entity
4020
+		if ($this->request->requestParamIsSet($entity_PK_name)) {
4021
+			$ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4022
+			return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4023
+		}
4024
+		// or grab checkbox array if bulk deleting
4025
+		$checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4026
+		if (empty($checkboxes)) {
4027
+			return 0;
4028
+		}
4029
+		$success = 0;
4030
+		$IDs     = array_keys($checkboxes);
4031
+		// cycle thru bulk action checkboxes
4032
+		foreach ($IDs as $ID) {
4033
+			// increment $success
4034
+			if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4035
+				$success++;
4036
+			}
4037
+		}
4038
+		$count = (int) count($checkboxes);
4039
+		// if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4040
+		// otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4041
+		return $success === $count ? $count : $success / $count;
4042
+	}
4043
+
4044
+
4045
+	/**
4046
+	 * @param EE_Primary_Key_Field_Base $entity_PK
4047
+	 * @return string
4048
+	 * @throws EE_Error
4049
+	 * @since   4.10.30.p
4050
+	 */
4051
+	private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK)
4052
+	{
4053
+		$entity_PK_type = $entity_PK->getSchemaType();
4054
+		switch ($entity_PK_type) {
4055
+			case 'boolean':
4056
+				return 'bool';
4057
+			case 'integer':
4058
+				return 'int';
4059
+			case 'number':
4060
+				return 'float';
4061
+			case 'string':
4062
+				return 'string';
4063
+		}
4064
+		throw new RuntimeException(
4065
+			sprintf(
4066
+				esc_html__(
4067
+					'"%1$s" is an invalid schema type for the %2$s primary key.',
4068
+					'event_espresso'
4069
+				),
4070
+				$entity_PK_type,
4071
+				$entity_PK->get_name()
4072
+			)
4073
+		);
4074
+	}
4075
+
4076
+
4077
+	/**
4078
+	 * @param EEM_Base      $entity_model
4079
+	 * @param int|string    $entity_ID
4080
+	 * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4081
+	 * @param string        $delete_column name of the field that denotes whether entity is trashed
4082
+	 * @param callable|null $callback      called after entity is trashed, restored, or deleted
4083
+	 * @return bool
4084
+	 */
4085
+	protected function trashRestoreDeleteEntity(
4086
+		EEM_Base $entity_model,
4087
+		$entity_ID,
4088
+		$action,
4089
+		$delete_column,
4090
+		callable $callback = null
4091
+	) {
4092
+		$entity_ID = absint($entity_ID);
4093
+		if (! $entity_ID) {
4094
+			$this->trashRestoreDeleteError($action, $entity_model);
4095
+		}
4096
+		$result = 0;
4097
+		try {
4098
+			$entity = $entity_model->get_one_by_ID($entity_ID);
4099
+			if (! $entity instanceof EE_Base_Class) {
4100
+				throw new DomainException(
4101
+					sprintf(
4102
+						esc_html__(
4103
+							'Missing or invalid %1$s entity with ID of "%2$s" returned from db.',
4104
+							'event_espresso'
4105
+						),
4106
+						str_replace('EEM_', '', $entity_model->get_this_model_name()),
4107
+						$entity_ID
4108
+					)
4109
+				);
4110
+			}
4111
+			switch ($action) {
4112
+				case EE_Admin_List_Table::ACTION_DELETE:
4113
+					$result = (bool) $entity->delete_permanently();
4114
+					break;
4115
+				case EE_Admin_List_Table::ACTION_RESTORE:
4116
+					$result = $entity->delete_or_restore(false);
4117
+					break;
4118
+				case EE_Admin_List_Table::ACTION_TRASH:
4119
+					$result = $entity->delete_or_restore();
4120
+					break;
4121
+			}
4122
+		} catch (Exception $exception) {
4123
+			$this->trashRestoreDeleteError($action, $entity_model, $exception);
4124
+		}
4125
+		if (is_callable($callback)) {
4126
+			call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4127
+		}
4128
+		return $result;
4129
+	}
4130
+
4131
+
4132
+	/**
4133
+	 * @param EEM_Base $entity_model
4134
+	 * @param string   $delete_column
4135
+	 * @since 4.10.30.p
4136
+	 */
4137
+	private function validateDeleteColumn(EEM_Base $entity_model, $delete_column)
4138
+	{
4139
+		if (empty($delete_column)) {
4140
+			throw new DomainException(
4141
+				sprintf(
4142
+					esc_html__(
4143
+						'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4144
+						'event_espresso'
4145
+					),
4146
+					$entity_model->get_this_model_name()
4147
+				)
4148
+			);
4149
+		}
4150
+		if (! $entity_model->has_field($delete_column)) {
4151
+			throw new DomainException(
4152
+				sprintf(
4153
+					esc_html__(
4154
+						'The %1$s field does not exist on the %2$s model.',
4155
+						'event_espresso'
4156
+					),
4157
+					$delete_column,
4158
+					$entity_model->get_this_model_name()
4159
+				)
4160
+			);
4161
+		}
4162
+	}
4163
+
4164
+
4165
+	/**
4166
+	 * @param EEM_Base       $entity_model
4167
+	 * @param Exception|null $exception
4168
+	 * @param string         $action
4169
+	 * @since 4.10.30.p
4170
+	 */
4171
+	private function trashRestoreDeleteError($action, EEM_Base $entity_model, Exception $exception = null)
4172
+	{
4173
+		if ($exception instanceof Exception) {
4174
+			throw new RuntimeException(
4175
+				sprintf(
4176
+					esc_html__(
4177
+						'Could not %1$s the %2$s because the following error occurred: %3$s',
4178
+						'event_espresso'
4179
+					),
4180
+					$action,
4181
+					$entity_model->get_this_model_name(),
4182
+					$exception->getMessage()
4183
+				)
4184
+			);
4185
+		}
4186
+		throw new RuntimeException(
4187
+			sprintf(
4188
+				esc_html__(
4189
+					'Could not %1$s the %2$s because an invalid ID was received.',
4190
+					'event_espresso'
4191
+				),
4192
+				$action,
4193
+				$entity_model->get_this_model_name()
4194
+			)
4195
+		);
4196
+	}
4197 4197
 }
Please login to merge, or discard this patch.
form_sections/strategies/layout/EE_Form_Section_Layout_Base.strategy.php 2 patches
Indentation   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -13,287 +13,287 @@
 block discarded – undo
13 13
  */
14 14
 abstract class EE_Form_Section_Layout_Base
15 15
 {
16
-    /**
17
-     * Form section to lay out
18
-     *
19
-     * @var EE_Form_Section_Proper
20
-     */
21
-    protected $_form_section;
22
-
23
-
24
-
25
-    /**
26
-     *  __construct
27
-     */
28
-    public function __construct()
29
-    {
30
-    }
31
-
32
-
33
-
34
-    /**
35
-     * The form section on which this strategy is to perform
36
-     *
37
-     * @param EE_Form_Section_Proper $form
38
-     */
39
-    public function _construct_finalize(EE_Form_Section_Proper $form)
40
-    {
41
-        $this->_form_section = $form;
42
-    }
43
-
44
-
45
-
46
-    /**
47
-     * @return EE_Form_Section_Proper
48
-     */
49
-    public function form_section()
50
-    {
51
-        return $this->_form_section;
52
-    }
53
-
54
-
55
-
56
-    /**
57
-     * Also has teh side effect of enqueuing any needed JS and CSS for
58
-     * this form.
59
-     * Creates all the HTML necessary for displaying this form, its inputs, and
60
-     * proper subsections.
61
-     * Returns the HTML
62
-     *
63
-     * @return string HTML for displaying
64
-     * @throws EE_Error
65
-     */
66
-    public function layout_form()
67
-    {
68
-        $html = '';
69
-        // layout_form_begin
70
-        $html .= apply_filters(
71
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
72
-            $this->layout_form_begin(),
73
-            $this->_form_section
74
-        );
75
-        // layout_form_loop
76
-        $html .= apply_filters(
77
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
78
-            $this->layout_form_loop(),
79
-            $this->_form_section
80
-        );
81
-        // layout_form_end
82
-        $html .= apply_filters(
83
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
84
-            $this->layout_form_end(),
85
-            $this->_form_section
86
-        );
87
-        return $this->add_form_section_hooks_and_filters($html);
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     * @return string
94
-     * @throws EE_Error
95
-     */
96
-    public function layout_form_loop()
97
-    {
98
-        $html = '';
99
-        foreach ($this->_form_section->subsections() as $name => $subsection) {
100
-            if ($subsection instanceof EE_Form_Input_Base) {
101
-                $html .= apply_filters(
102
-                    'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
103
-                    . $name . '__in_' . $this->_form_section->name(),
104
-                    $this->layout_input($subsection),
105
-                    $this->_form_section,
106
-                    $subsection
107
-                );
108
-            } elseif ($subsection instanceof EE_Form_Section_Base) {
109
-                $html .= apply_filters(
110
-                    'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
111
-                    . $name . '__in_' . $this->_form_section->name(),
112
-                    $this->layout_subsection($subsection),
113
-                    $this->_form_section,
114
-                    $subsection
115
-                );
116
-            }
117
-        }
118
-        return $html;
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * Should be used to start teh form section (Eg a table tag, or a div tag, etc.)
125
-     *
126
-     * @return string
127
-     */
128
-    abstract public function layout_form_begin();
129
-
130
-
131
-
132
-    /**
133
-     * Should be used to end the form section (eg a /table tag, or a /div tag, etc.)
134
-     *
135
-     * @return string
136
-     */
137
-    abstract public function layout_form_end();
138
-
139
-
140
-
141
-    /**
142
-     * Should be used internally by layout_form() to lay out each input (eg, if this layout
143
-     * is putting each input in a row of its own, this should probably be called by a
144
-     *  foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop.
145
-     * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely
146
-     * customize the form's layout, but would like to make use of it for laying out
147
-     * 'easy-to-layout' inputs
148
-     *
149
-     * @param EE_Form_Input_Base $input
150
-     * @return string html
151
-     */
152
-    abstract public function layout_input($input);
153
-
154
-
155
-
156
-    /**
157
-     * Similar to layout_input(), should be used internally by layout_form() within a
158
-     * loop to lay out each proper subsection. Unlike layout_input(), however, it is assumed
159
-     * that the proper subsection will lay out its container, label, etc on its own.
160
-     *
161
-     * @param EE_Form_Section_Base $subsection
162
-     * @return string html
163
-     */
164
-    abstract public function layout_subsection($subsection);
165
-
166
-
167
-    /**
168
-     * Gets the HTML for the label tag and its contents for the input
169
-     *
170
-     * @param EE_Form_Input_Base $input
171
-     * @return string
172
-     * @throws EE_Error
173
-     */
174
-    public function display_label($input)
175
-    {
176
-        if ($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
177
-            return '';
178
-        }
179
-        $class = $input->required()
180
-            ? 'ee-required-label ' . $input->html_label_class()
181
-            : $input->html_label_class();
182
-        $label_text = $input->required()
183
-            ? $input->html_label_text() . '<span class="ee-asterisk">*</span>'
184
-            : $input->html_label_text();
185
-        return '<label id="'
186
-               . $input->html_label_id()
187
-               . '" class="'
188
-               . $class
189
-               . '" style="'
190
-               . $input->html_label_style()
191
-               . '" for="' . $input->html_id()
192
-               . '">'
193
-               . $label_text
194
-               . '</label>';
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * Gets the HTML for all the form's form-wide errors (ie, errors which
201
-     * are not for specific inputs. E.g., if two inputs somehow disagree,
202
-     * those errors would probably be on the form section, not one of its inputs)
203
-     * @return string
204
-     */
205
-    public function display_form_wide_errors()
206
-    {
207
-        $html = '';
208
-        if ($this->_form_section->get_validation_errors()) {
209
-            $html .= "<div class='ee-form-wide-errors'>";
210
-            // get all the errors on THIS form section (errors which aren't
211
-            // for specific inputs, but instead for the entire form section)
212
-            foreach ($this->_form_section->get_validation_errors() as $error) {
213
-                $html .= $error->getMessage() . '<br>';
214
-            }
215
-            $html .= '</div>';
216
-        }
217
-        return apply_filters(
218
-            'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors',
219
-            $html,
220
-            $this
221
-        );
222
-    }
223
-
224
-
225
-    /**
226
-     * returns the HTML for the server-side validation errors for the specified input
227
-     * Note that if JS is enabled, it should remove these and instead
228
-     * populate the form's errors in the jquery validate fashion
229
-     * using the localized data provided to the JS
230
-     *
231
-     * @param EE_Form_Input_Base $input
232
-     * @return string
233
-     * @throws EE_Error
234
-     */
235
-    public function display_errors($input)
236
-    {
237
-        if ($input->get_validation_errors()) {
238
-            return "<label id='"
239
-                   . esc_attr($input->html_id())
240
-                   . "-error' class='error' for='" . esc_attr($input->html_name()) . "'>"
241
-                   . wp_kses($input->get_validation_error_string(), AllowedTags::getAllowedTags())
242
-                   . '</label>';
243
-        }
244
-        return '';
245
-    }
246
-
247
-
248
-    /**
249
-     * Displays the help span for the specified input
250
-     *
251
-     * @param EE_Form_Input_Base $input
252
-     * @return string
253
-     * @throws EE_Error
254
-     */
255
-    public function display_help_text($input)
256
-    {
257
-        $help_text  = $input->html_help_text();
258
-        if ($help_text !== '' && $help_text !== null) {
259
-            $tag = is_admin() ? 'p' : 'span';
260
-            return '<'
261
-                   . $tag
262
-                   . ' id="'
263
-                   . $input->html_id()
264
-                   . '-help" class="'
265
-                   . $input->html_help_class()
266
-                   . '" style="'
267
-                   . $input->html_help_style()
268
-                   . '">'
269
-                   . $help_text
270
-                   . '</'
271
-                   . $tag
272
-                   . '>';
273
-        }
274
-        return '';
275
-    }
276
-
277
-
278
-    /**
279
-     * Does an action and hook onto the end of teh form
280
-     *
281
-     * @param string $html
282
-     * @return string
283
-     * @throws EE_Error
284
-     */
285
-    public function add_form_section_hooks_and_filters($html)
286
-    {
287
-        // replace dashes and spaces with underscores
288
-        $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
289
-        do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
290
-        $html = (string) apply_filters(
291
-            'AFEE__Form_Section_Layout__' . $hook_name . '__html',
292
-            $html,
293
-            $this->_form_section
294
-        );
295
-        $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
296
-        $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
297
-        return $html;
298
-    }
16
+	/**
17
+	 * Form section to lay out
18
+	 *
19
+	 * @var EE_Form_Section_Proper
20
+	 */
21
+	protected $_form_section;
22
+
23
+
24
+
25
+	/**
26
+	 *  __construct
27
+	 */
28
+	public function __construct()
29
+	{
30
+	}
31
+
32
+
33
+
34
+	/**
35
+	 * The form section on which this strategy is to perform
36
+	 *
37
+	 * @param EE_Form_Section_Proper $form
38
+	 */
39
+	public function _construct_finalize(EE_Form_Section_Proper $form)
40
+	{
41
+		$this->_form_section = $form;
42
+	}
43
+
44
+
45
+
46
+	/**
47
+	 * @return EE_Form_Section_Proper
48
+	 */
49
+	public function form_section()
50
+	{
51
+		return $this->_form_section;
52
+	}
53
+
54
+
55
+
56
+	/**
57
+	 * Also has teh side effect of enqueuing any needed JS and CSS for
58
+	 * this form.
59
+	 * Creates all the HTML necessary for displaying this form, its inputs, and
60
+	 * proper subsections.
61
+	 * Returns the HTML
62
+	 *
63
+	 * @return string HTML for displaying
64
+	 * @throws EE_Error
65
+	 */
66
+	public function layout_form()
67
+	{
68
+		$html = '';
69
+		// layout_form_begin
70
+		$html .= apply_filters(
71
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
72
+			$this->layout_form_begin(),
73
+			$this->_form_section
74
+		);
75
+		// layout_form_loop
76
+		$html .= apply_filters(
77
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
78
+			$this->layout_form_loop(),
79
+			$this->_form_section
80
+		);
81
+		// layout_form_end
82
+		$html .= apply_filters(
83
+			'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
84
+			$this->layout_form_end(),
85
+			$this->_form_section
86
+		);
87
+		return $this->add_form_section_hooks_and_filters($html);
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 * @return string
94
+	 * @throws EE_Error
95
+	 */
96
+	public function layout_form_loop()
97
+	{
98
+		$html = '';
99
+		foreach ($this->_form_section->subsections() as $name => $subsection) {
100
+			if ($subsection instanceof EE_Form_Input_Base) {
101
+				$html .= apply_filters(
102
+					'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
103
+					. $name . '__in_' . $this->_form_section->name(),
104
+					$this->layout_input($subsection),
105
+					$this->_form_section,
106
+					$subsection
107
+				);
108
+			} elseif ($subsection instanceof EE_Form_Section_Base) {
109
+				$html .= apply_filters(
110
+					'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
111
+					. $name . '__in_' . $this->_form_section->name(),
112
+					$this->layout_subsection($subsection),
113
+					$this->_form_section,
114
+					$subsection
115
+				);
116
+			}
117
+		}
118
+		return $html;
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * Should be used to start teh form section (Eg a table tag, or a div tag, etc.)
125
+	 *
126
+	 * @return string
127
+	 */
128
+	abstract public function layout_form_begin();
129
+
130
+
131
+
132
+	/**
133
+	 * Should be used to end the form section (eg a /table tag, or a /div tag, etc.)
134
+	 *
135
+	 * @return string
136
+	 */
137
+	abstract public function layout_form_end();
138
+
139
+
140
+
141
+	/**
142
+	 * Should be used internally by layout_form() to lay out each input (eg, if this layout
143
+	 * is putting each input in a row of its own, this should probably be called by a
144
+	 *  foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop.
145
+	 * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely
146
+	 * customize the form's layout, but would like to make use of it for laying out
147
+	 * 'easy-to-layout' inputs
148
+	 *
149
+	 * @param EE_Form_Input_Base $input
150
+	 * @return string html
151
+	 */
152
+	abstract public function layout_input($input);
153
+
154
+
155
+
156
+	/**
157
+	 * Similar to layout_input(), should be used internally by layout_form() within a
158
+	 * loop to lay out each proper subsection. Unlike layout_input(), however, it is assumed
159
+	 * that the proper subsection will lay out its container, label, etc on its own.
160
+	 *
161
+	 * @param EE_Form_Section_Base $subsection
162
+	 * @return string html
163
+	 */
164
+	abstract public function layout_subsection($subsection);
165
+
166
+
167
+	/**
168
+	 * Gets the HTML for the label tag and its contents for the input
169
+	 *
170
+	 * @param EE_Form_Input_Base $input
171
+	 * @return string
172
+	 * @throws EE_Error
173
+	 */
174
+	public function display_label($input)
175
+	{
176
+		if ($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
177
+			return '';
178
+		}
179
+		$class = $input->required()
180
+			? 'ee-required-label ' . $input->html_label_class()
181
+			: $input->html_label_class();
182
+		$label_text = $input->required()
183
+			? $input->html_label_text() . '<span class="ee-asterisk">*</span>'
184
+			: $input->html_label_text();
185
+		return '<label id="'
186
+			   . $input->html_label_id()
187
+			   . '" class="'
188
+			   . $class
189
+			   . '" style="'
190
+			   . $input->html_label_style()
191
+			   . '" for="' . $input->html_id()
192
+			   . '">'
193
+			   . $label_text
194
+			   . '</label>';
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * Gets the HTML for all the form's form-wide errors (ie, errors which
201
+	 * are not for specific inputs. E.g., if two inputs somehow disagree,
202
+	 * those errors would probably be on the form section, not one of its inputs)
203
+	 * @return string
204
+	 */
205
+	public function display_form_wide_errors()
206
+	{
207
+		$html = '';
208
+		if ($this->_form_section->get_validation_errors()) {
209
+			$html .= "<div class='ee-form-wide-errors'>";
210
+			// get all the errors on THIS form section (errors which aren't
211
+			// for specific inputs, but instead for the entire form section)
212
+			foreach ($this->_form_section->get_validation_errors() as $error) {
213
+				$html .= $error->getMessage() . '<br>';
214
+			}
215
+			$html .= '</div>';
216
+		}
217
+		return apply_filters(
218
+			'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors',
219
+			$html,
220
+			$this
221
+		);
222
+	}
223
+
224
+
225
+	/**
226
+	 * returns the HTML for the server-side validation errors for the specified input
227
+	 * Note that if JS is enabled, it should remove these and instead
228
+	 * populate the form's errors in the jquery validate fashion
229
+	 * using the localized data provided to the JS
230
+	 *
231
+	 * @param EE_Form_Input_Base $input
232
+	 * @return string
233
+	 * @throws EE_Error
234
+	 */
235
+	public function display_errors($input)
236
+	{
237
+		if ($input->get_validation_errors()) {
238
+			return "<label id='"
239
+				   . esc_attr($input->html_id())
240
+				   . "-error' class='error' for='" . esc_attr($input->html_name()) . "'>"
241
+				   . wp_kses($input->get_validation_error_string(), AllowedTags::getAllowedTags())
242
+				   . '</label>';
243
+		}
244
+		return '';
245
+	}
246
+
247
+
248
+	/**
249
+	 * Displays the help span for the specified input
250
+	 *
251
+	 * @param EE_Form_Input_Base $input
252
+	 * @return string
253
+	 * @throws EE_Error
254
+	 */
255
+	public function display_help_text($input)
256
+	{
257
+		$help_text  = $input->html_help_text();
258
+		if ($help_text !== '' && $help_text !== null) {
259
+			$tag = is_admin() ? 'p' : 'span';
260
+			return '<'
261
+				   . $tag
262
+				   . ' id="'
263
+				   . $input->html_id()
264
+				   . '-help" class="'
265
+				   . $input->html_help_class()
266
+				   . '" style="'
267
+				   . $input->html_help_style()
268
+				   . '">'
269
+				   . $help_text
270
+				   . '</'
271
+				   . $tag
272
+				   . '>';
273
+		}
274
+		return '';
275
+	}
276
+
277
+
278
+	/**
279
+	 * Does an action and hook onto the end of teh form
280
+	 *
281
+	 * @param string $html
282
+	 * @return string
283
+	 * @throws EE_Error
284
+	 */
285
+	public function add_form_section_hooks_and_filters($html)
286
+	{
287
+		// replace dashes and spaces with underscores
288
+		$hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
289
+		do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
290
+		$html = (string) apply_filters(
291
+			'AFEE__Form_Section_Layout__' . $hook_name . '__html',
292
+			$html,
293
+			$this->_form_section
294
+		);
295
+		$html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
296
+		$html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
297
+		return $html;
298
+	}
299 299
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
         $html = '';
69 69
         // layout_form_begin
70 70
         $html .= apply_filters(
71
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(),
71
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(),
72 72
             $this->layout_form_begin(),
73 73
             $this->_form_section
74 74
         );
75 75
         // layout_form_loop
76 76
         $html .= apply_filters(
77
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(),
77
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(),
78 78
             $this->layout_form_loop(),
79 79
             $this->_form_section
80 80
         );
81 81
         // layout_form_end
82 82
         $html .= apply_filters(
83
-            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(),
83
+            'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(),
84 84
             $this->layout_form_end(),
85 85
             $this->_form_section
86 86
         );
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
             if ($subsection instanceof EE_Form_Input_Base) {
101 101
                 $html .= apply_filters(
102 102
                     'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_'
103
-                    . $name . '__in_' . $this->_form_section->name(),
103
+                    . $name.'__in_'.$this->_form_section->name(),
104 104
                     $this->layout_input($subsection),
105 105
                     $this->_form_section,
106 106
                     $subsection
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
             } elseif ($subsection instanceof EE_Form_Section_Base) {
109 109
                 $html .= apply_filters(
110 110
                     'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_'
111
-                    . $name . '__in_' . $this->_form_section->name(),
111
+                    . $name.'__in_'.$this->_form_section->name(),
112 112
                     $this->layout_subsection($subsection),
113 113
                     $this->_form_section,
114 114
                     $subsection
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
             return '';
178 178
         }
179 179
         $class = $input->required()
180
-            ? 'ee-required-label ' . $input->html_label_class()
180
+            ? 'ee-required-label '.$input->html_label_class()
181 181
             : $input->html_label_class();
182 182
         $label_text = $input->required()
183
-            ? $input->html_label_text() . '<span class="ee-asterisk">*</span>'
183
+            ? $input->html_label_text().'<span class="ee-asterisk">*</span>'
184 184
             : $input->html_label_text();
185 185
         return '<label id="'
186 186
                . $input->html_label_id()
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
                . $class
189 189
                . '" style="'
190 190
                . $input->html_label_style()
191
-               . '" for="' . $input->html_id()
191
+               . '" for="'.$input->html_id()
192 192
                . '">'
193 193
                . $label_text
194 194
                . '</label>';
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
             // get all the errors on THIS form section (errors which aren't
211 211
             // for specific inputs, but instead for the entire form section)
212 212
             foreach ($this->_form_section->get_validation_errors() as $error) {
213
-                $html .= $error->getMessage() . '<br>';
213
+                $html .= $error->getMessage().'<br>';
214 214
             }
215 215
             $html .= '</div>';
216 216
         }
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         if ($input->get_validation_errors()) {
238 238
             return "<label id='"
239 239
                    . esc_attr($input->html_id())
240
-                   . "-error' class='error' for='" . esc_attr($input->html_name()) . "'>"
240
+                   . "-error' class='error' for='".esc_attr($input->html_name())."'>"
241 241
                    . wp_kses($input->get_validation_error_string(), AllowedTags::getAllowedTags())
242 242
                    . '</label>';
243 243
         }
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      */
255 255
     public function display_help_text($input)
256 256
     {
257
-        $help_text  = $input->html_help_text();
257
+        $help_text = $input->html_help_text();
258 258
         if ($help_text !== '' && $help_text !== null) {
259 259
             $tag = is_admin() ? 'p' : 'span';
260 260
             return '<'
@@ -286,14 +286,14 @@  discard block
 block discarded – undo
286 286
     {
287 287
         // replace dashes and spaces with underscores
288 288
         $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id());
289
-        do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section);
289
+        do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section);
290 290
         $html = (string) apply_filters(
291
-            'AFEE__Form_Section_Layout__' . $hook_name . '__html',
291
+            'AFEE__Form_Section_Layout__'.$hook_name.'__html',
292 292
             $html,
293 293
             $this->_form_section
294 294
         );
295
-        $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->';
296
-        $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->';
295
+        $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->';
296
+        $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->';
297 297
         return $html;
298 298
     }
299 299
 }
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Hidden_Display_Strategy.strategy.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,16 +11,16 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Hidden_Display_Strategy extends EE_Display_Strategy_Base
13 13
 {
14
-    /**
15
-     *
16
-     * @return string of html to display the HIDDEN field
17
-     * @throws EE_Error
18
-     */
19
-    public function display()
20
-    {
21
-        $input = $this->_input;
22
-        return "<input type='hidden' id='" . esc_attr($input->html_id()) . "' name='" . esc_attr($input->html_name()) . "' 
14
+	/**
15
+	 *
16
+	 * @return string of html to display the HIDDEN field
17
+	 * @throws EE_Error
18
+	 */
19
+	public function display()
20
+	{
21
+		$input = $this->_input;
22
+		return "<input type='hidden' id='" . esc_attr($input->html_id()) . "' name='" . esc_attr($input->html_name()) . "' 
23 23
         class='" . esc_attr($input->html_class()) . "' style='" . esc_attr($input->html_style()) . "' 
24 24
         value='" . esc_attr($input->raw_value_in_form()) . "' {$input->other_html_attributes()}/>";
25
-    }
25
+	}
26 26
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
     public function display()
20 20
     {
21 21
         $input = $this->_input;
22
-        return "<input type='hidden' id='" . esc_attr($input->html_id()) . "' name='" . esc_attr($input->html_name()) . "' 
23
-        class='" . esc_attr($input->html_class()) . "' style='" . esc_attr($input->html_style()) . "' 
24
-        value='" . esc_attr($input->raw_value_in_form()) . "' {$input->other_html_attributes()}/>";
22
+        return "<input type='hidden' id='".esc_attr($input->html_id())."' name='".esc_attr($input->html_name())."' 
23
+        class='" . esc_attr($input->html_class())."' style='".esc_attr($input->html_style())."' 
24
+        value='" . esc_attr($input->raw_value_in_form())."' {$input->other_html_attributes()}/>";
25 25
     }
26 26
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 2 patches
Indentation   +923 added lines, -923 removed lines patch added patch discarded remove patch
@@ -7,36 +7,36 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\services\request\sanitizers\AllowedTags;
8 8
 
9 9
 if (! function_exists('espresso_get_template_part')) {
10
-    /**
11
-     * espresso_get_template_part
12
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
13
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
14
-     *
15
-     * @param string $slug The slug name for the generic template.
16
-     * @param string $name The name of the specialised template.
17
-     */
18
-    function espresso_get_template_part($slug = null, $name = null)
19
-    {
20
-        EEH_Template::get_template_part($slug, $name);
21
-    }
10
+	/**
11
+	 * espresso_get_template_part
12
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
13
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
14
+	 *
15
+	 * @param string $slug The slug name for the generic template.
16
+	 * @param string $name The name of the specialised template.
17
+	 */
18
+	function espresso_get_template_part($slug = null, $name = null)
19
+	{
20
+		EEH_Template::get_template_part($slug, $name);
21
+	}
22 22
 }
23 23
 
24 24
 
25 25
 if (! function_exists('espresso_get_object_css_class')) {
26
-    /**
27
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
28
-     *
29
-     * @param EE_Base_Class $object the EE object the css class is being generated for
30
-     * @param string        $prefix added to the beginning of the generated class
31
-     * @param string        $suffix added to the end of the generated class
32
-     * @return string
33
-     * @throws EE_Error
34
-     * @throws ReflectionException
35
-     */
36
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
37
-    {
38
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
39
-    }
26
+	/**
27
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
28
+	 *
29
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
30
+	 * @param string        $prefix added to the beginning of the generated class
31
+	 * @param string        $suffix added to the end of the generated class
32
+	 * @return string
33
+	 * @throws EE_Error
34
+	 * @throws ReflectionException
35
+	 */
36
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
37
+	{
38
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
39
+	}
40 40
 }
41 41
 
42 42
 
@@ -50,637 +50,637 @@  discard block
 block discarded – undo
50 50
  */
51 51
 class EEH_Template
52 52
 {
53
-    private static $_espresso_themes = [];
54
-
55
-
56
-    /**
57
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
58
-     *
59
-     * @return boolean
60
-     */
61
-    public static function is_espresso_theme()
62
-    {
63
-        return wp_get_theme()->get('TextDomain') === 'event_espresso';
64
-    }
65
-
66
-
67
-    /**
68
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
69
-     *    load its functions.php file ( if not already loaded )
70
-     *
71
-     * @return void
72
-     */
73
-    public static function load_espresso_theme_functions()
74
-    {
75
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
78
-            }
79
-        }
80
-    }
81
-
82
-
83
-    /**
84
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
85
-     *
86
-     * @return array
87
-     */
88
-    public static function get_espresso_themes()
89
-    {
90
-        if (empty(EEH_Template::$_espresso_themes)) {
91
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
92
-            if (empty($espresso_themes)) {
93
-                return [];
94
-            }
95
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
-                unset($espresso_themes[ $key ]);
97
-            }
98
-            EEH_Template::$_espresso_themes = [];
99
-            foreach ($espresso_themes as $espresso_theme) {
100
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
101
-            }
102
-        }
103
-        return EEH_Template::$_espresso_themes;
104
-    }
105
-
106
-
107
-    /**
108
-     * EEH_Template::get_template_part
109
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
110
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
111
-     * filtering based off of the entire template part name
112
-     *
113
-     * @param string $slug The slug name for the generic template.
114
-     * @param string $name The name of the specialised template.
115
-     * @param array  $template_args
116
-     * @param bool   $return_string
117
-     * @return string        the html output for the formatted money value
118
-     */
119
-    public static function get_template_part(
120
-        $slug = null,
121
-        $name = null,
122
-        $template_args = [],
123
-        $return_string = false
124
-    ) {
125
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
126
-        $templates = [];
127
-        $name      = (string) $name;
128
-        if ($name != '') {
129
-            $templates[] = "{$slug}-{$name}.php";
130
-        }
131
-        // allow template parts to be turned off via something like:
132
-        // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
133
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
134
-            return EEH_Template::locate_template($templates, $template_args, true, $return_string);
135
-        }
136
-        return '';
137
-    }
138
-
139
-
140
-    /**
141
-     *    locate_template
142
-     *    locate a template file by looking in the following places, in the following order:
143
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
144
-     *        <assumed full absolute server path>
145
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
146
-     *        <server path up to>/wp-content/uploads/espresso/templates/
147
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
148
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
149
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
150
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
151
-     *        Example:
152
-     *          You are using the WordPress Twenty Sixteen theme,
153
-     *        and you want to customize the "some-event.template.php" template,
154
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
155
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
156
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
157
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
158
-     *        /relative/path/to/some-event.template.php
159
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
160
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
161
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
162
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
163
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
164
-     *          Had you passed an absolute path to your template that was in some other location,
165
-     *        ie: "/absolute/path/to/some-event.template.php"
166
-     *          then the search would have been :
167
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
168
-     *        /absolute/path/to/some-event.template.php
169
-     *          and stopped there upon finding it in the second location
170
-     *
171
-     * @param array|string $templates       array of template file names including extension (or just a single string)
172
-     * @param array        $template_args   an array of arguments to be extracted for use in the template
173
-     * @param boolean      $load            whether to pass the located template path on to the
174
-     *                                      EEH_Template::display_template() method or simply return it
175
-     * @param boolean      $return_string   whether to send output immediately to screen, or capture and return as a
176
-     *                                      string
177
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
178
-     *                                      generate a custom template or not. Used in places where you don't actually
179
-     *                                      load the template, you just want to know if there's a custom version of it.
180
-     * @return mixed
181
-     * @throws DomainException
182
-     * @throws InvalidArgumentException
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     */
186
-    public static function locate_template(
187
-        $templates = [],
188
-        $template_args = [],
189
-        $load = true,
190
-        $return_string = true,
191
-        $check_if_custom = false
192
-    ) {
193
-        // first use WP locate_template to check for template in the current theme folder
194
-        $template_path = locate_template($templates);
195
-
196
-        if ($check_if_custom && ! empty($template_path)) {
197
-            return true;
198
-        }
199
-
200
-        // not in the theme
201
-        if (empty($template_path)) {
202
-            // not even a template to look for ?
203
-            if (empty($templates)) {
204
-                $loader = LoaderFactory::getLoader();
205
-                /** @var RequestInterface $request */
206
-                $request = $loader->getShared(RequestInterface::class);
207
-                // get post_type
208
-                $post_type = $request->getRequestParam('post_type');
209
-                /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
210
-                $custom_post_types = $loader->getShared(
211
-                    'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
212
-                );
213
-                // get array of EE Custom Post Types
214
-                $EE_CPTs = $custom_post_types->getDefinitions();
215
-                // build template name based on request
216
-                if (isset($EE_CPTs[ $post_type ])) {
217
-                    $archive_or_single = is_archive() ? 'archive' : '';
218
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
219
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
220
-                }
221
-            }
222
-            // currently active EE template theme
223
-            $current_theme = EE_Config::get_current_theme();
224
-
225
-            // array of paths to folders that may contain templates
226
-            $template_folder_paths = [
227
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
229
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
230
-                EVENT_ESPRESSO_TEMPLATE_DIR,
231
-            ];
232
-
233
-            // add core plugin folders for checking only if we're not $check_if_custom
234
-            if (! $check_if_custom) {
235
-                $core_paths            = [
236
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
-                    EE_PUBLIC . $current_theme,
238
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
-                    EE_TEMPLATES . $current_theme,
240
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241
-                    EE_PLUGIN_DIR_PATH,
242
-                ];
243
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
244
-            }
245
-
246
-            // now filter that array
247
-            $template_folder_paths = apply_filters(
248
-                'FHEE__EEH_Template__locate_template__template_folder_paths',
249
-                $template_folder_paths
250
-            );
251
-            $templates             = is_array($templates) ? $templates : [$templates];
252
-            $template_folder_paths =
253
-                is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths];
254
-            // array to hold all possible template paths
255
-            $full_template_paths = [];
256
-            $file_name           = '';
257
-
258
-            // loop through $templates
259
-            foreach ($templates as $template) {
260
-                // normalize directory separators
261
-                $template                      = EEH_File::standardise_directory_separators($template);
262
-                $file_name                     = basename($template);
263
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
264
-                // while looping through all template folder paths
265
-                foreach ($template_folder_paths as $template_folder_path) {
266
-                    // normalize directory separators
267
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
268
-                    // determine if any common base path exists between the two paths
269
-                    $common_base_path = EEH_Template::_find_common_base_path(
270
-                        [$template_folder_path, $template_path_minus_file_name]
271
-                    );
272
-                    if ($common_base_path !== '') {
273
-                        // both paths have a common base, so just tack the filename onto our search path
274
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
275
-                    } else {
276
-                        // no common base path, so let's just concatenate
277
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
278
-                    }
279
-                    // build up our template locations array by adding our resolved paths
280
-                    $full_template_paths[] = $resolved_path;
281
-                }
282
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283
-                array_unshift($full_template_paths, $template);
284
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
286
-            }
287
-            // filter final array of full template paths
288
-            $full_template_paths = apply_filters(
289
-                'FHEE__EEH_Template__locate_template__full_template_paths',
290
-                $full_template_paths,
291
-                $file_name
292
-            );
293
-            // now loop through our final array of template location paths and check each location
294
-            foreach ((array) $full_template_paths as $full_template_path) {
295
-                if (is_readable($full_template_path)) {
296
-                    $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path);
297
-                    break;
298
-                }
299
-            }
300
-        }
301
-
302
-        // hook that can be used to display the full template path that will be used
303
-        do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
304
-
305
-        // if we got it and you want to see it...
306
-        if ($template_path && $load && ! $check_if_custom) {
307
-            if ($return_string) {
308
-                return EEH_Template::display_template($template_path, $template_args, true);
309
-            }
310
-            EEH_Template::display_template($template_path, $template_args);
311
-        }
312
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
313
-    }
314
-
315
-
316
-    /**
317
-     * _find_common_base_path
318
-     * given two paths, this determines if there is a common base path between the two
319
-     *
320
-     * @param array $paths
321
-     * @return string
322
-     */
323
-    protected static function _find_common_base_path($paths)
324
-    {
325
-        $last_offset      = 0;
326
-        $common_base_path = '';
327
-        while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
328
-            $dir_length = $index - $last_offset + 1;
329
-            $directory  = substr($paths[0], $last_offset, $dir_length);
330
-            foreach ($paths as $path) {
331
-                if (substr($path, $last_offset, $dir_length) != $directory) {
332
-                    return $common_base_path;
333
-                }
334
-            }
335
-            $common_base_path .= $directory;
336
-            $last_offset      = $index + 1;
337
-        }
338
-        return substr($common_base_path, 0, -1);
339
-    }
340
-
341
-
342
-    /**
343
-     * load and display a template
344
-     *
345
-     * @param bool|string $template_path    server path to the file to be loaded, including file name and extension
346
-     * @param array       $template_args    an array of arguments to be extracted for use in the template
347
-     * @param boolean     $return_string    whether to send output immediately to screen, or capture and return as a
348
-     *                                      string
349
-     * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
350
-     *                                      not found or is not readable
351
-     * @return string
352
-     * @throws DomainException
353
-     */
354
-    public static function display_template(
355
-        $template_path = false,
356
-        $template_args = [],
357
-        $return_string = false,
358
-        $throw_exceptions = false
359
-    ) {
360
-
361
-        /**
362
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
363
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
364
-         * the display_template method are templates we DON'T want modified (usually because of js
365
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
366
-         * using this.
367
-         *
368
-         * @since 4.6.0
369
-         */
370
-        $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
371
-        $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372
-
373
-        // you gimme nuttin - YOU GET NUTTIN !!
374
-        if (! $template_path || ! is_readable($template_path)) {
375
-            // ignore whether template is accessible ?
376
-            if ($throw_exceptions) {
377
-                throw new DomainException(
378
-                    esc_html__('Invalid, unreadable, or missing file.', 'event_espresso')
379
-                );
380
-            }
381
-            return '';
382
-        }
383
-        // if $template_args are not in an array, then make it so
384
-        if (! is_array($template_args) && ! is_object($template_args)) {
385
-            $template_args = [$template_args];
386
-        }
387
-        extract($template_args, EXTR_SKIP);
388
-
389
-        if ($return_string) {
390
-            // because we want to return a string, we are going to capture the output
391
-            ob_start();
392
-            include($template_path);
393
-            return ob_get_clean();
394
-        }
395
-        include($template_path);
396
-        return '';
397
-    }
398
-
399
-
400
-    /**
401
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
402
-     *
403
-     * @param EE_Base_Class $object the EE object the css class is being generated for
404
-     * @param string        $prefix added to the beginning of the generated class
405
-     * @param string        $suffix added to the end of the generated class
406
-     * @return string
407
-     * @throws EE_Error
408
-     * @throws ReflectionException
409
-     */
410
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411
-    {
412
-        // in the beginning...
413
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
414
-        // da muddle
415
-        $class = '';
416
-        // the end
417
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
418
-        // is the passed object an EE object ?
419
-        if ($object instanceof EE_Base_Class) {
420
-            // grab the exact type of object
421
-            $obj_class = get_class($object);
422
-            // depending on the type of object...
423
-            switch ($obj_class) {
424
-                // no specifics just yet...
425
-                default:
426
-                    $class = strtolower(str_replace('_', '-', $obj_class));
427
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
428
-            }
429
-        }
430
-        return $prefix . $class . $suffix;
431
-    }
432
-
433
-
434
-    /**
435
-     * EEH_Template::format_currency
436
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
437
-     * the country currency settings from the supplied country ISO code
438
-     *
439
-     * @param float   $amount       raw money value
440
-     * @param boolean $return_raw   whether to return the formatted float value only with no currency sign or code
441
-     * @param boolean $display_code whether to display the country code (USD). Default = TRUE
442
-     * @param string  $CNT_ISO      2 letter ISO code for a country
443
-     * @param string  $cur_code_span_class
444
-     * @return string        the html output for the formatted money value
445
-     */
446
-    public static function format_currency(
447
-        $amount = null,
448
-        $return_raw = false,
449
-        $display_code = true,
450
-        $CNT_ISO = '',
451
-        $cur_code_span_class = 'currency-code'
452
-    ) {
453
-        // ensure amount was received
454
-        if ($amount === null) {
455
-            $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso');
456
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
457
-            return '';
458
-        }
459
-        // ensure amount is float
460
-        $amount  = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
461
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
462
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
463
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464
-        // still a number, or was amount converted to a string like "free" ?
465
-        if (! is_float($amount_formatted)) {
466
-            return esc_html($amount_formatted);
467
-        }
468
-        try {
469
-            // was a country ISO code passed ? if so generate currency config object for that country
470
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
471
-        } catch (Exception $e) {
472
-            // eat exception
473
-            $mny = null;
474
-        }
475
-        // verify results
476
-        if (! $mny instanceof EE_Currency_Config) {
477
-            // set default config country currency settings
478
-            $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479
-                ? EE_Registry::instance()->CFG->currency
480
-                : new EE_Currency_Config();
481
-        }
482
-        // format float
483
-        $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484
-        // add formatting ?
485
-        if (! $return_raw) {
486
-            // add currency sign
487
-            if ($mny->sign_b4) {
488
-                if ($amount >= 0) {
489
-                    $amount_formatted = $mny->sign . $amount_formatted;
490
-                } else {
491
-                    $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
492
-                }
493
-            } else {
494
-                $amount_formatted = $amount_formatted . $mny->sign;
495
-            }
496
-
497
-            // filter to allow global setting of display_code
498
-            $display_code = (bool) apply_filters(
499
-                'FHEE__EEH_Template__format_currency__display_code',
500
-                $display_code
501
-            );
502
-
503
-            // add currency code ?
504
-            $amount_formatted = $display_code
505
-                ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
506
-                : $amount_formatted;
507
-        }
508
-        // filter results
509
-        $amount_formatted = apply_filters(
510
-            'FHEE__EEH_Template__format_currency__amount_formatted',
511
-            $amount_formatted,
512
-            $mny,
513
-            $return_raw
514
-        );
515
-        // clean up vars
516
-        unset($mny);
517
-        // return formatted currency amount
518
-        return $amount_formatted;
519
-    }
520
-
521
-
522
-    /**
523
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
524
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
525
-     * related status model or model object (i.e. in documentation etc.)
526
-     *
527
-     * @param string  $status_id  Status ID matching a registered status in the esp_status table.  If there is no
528
-     *                            match, then 'Unknown' will be returned.
529
-     * @param boolean $plural     Whether to return plural or not
530
-     * @param string  $schema     'UPPER', 'lower', or 'Sentence'
531
-     * @return string             The localized label for the status id.
532
-     * @throws EE_Error
533
-     */
534
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
535
-    {
536
-        $status = EEM_Status::instance()->localized_status(
537
-            [$status_id => esc_html__('unknown', 'event_espresso')],
538
-            $plural,
539
-            $schema
540
-        );
541
-        return $status[ $status_id ];
542
-    }
543
-
544
-
545
-    /**
546
-     * This helper just returns a button or link for the given parameters
547
-     *
548
-     * @param string $url   the url for the link, note that `esc_url` will be called on it
549
-     * @param string $label What is the label you want displayed for the button
550
-     * @param string $class what class is used for the button (defaults to 'button-primary')
551
-     * @param string $icon
552
-     * @param string $title
553
-     * @return string the html output for the button
554
-     */
555
-    public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '')
556
-    {
557
-        $icon_html = '';
558
-        if (! empty($icon)) {
559
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
560
-            $dashicons = array_filter($dashicons);
561
-            $count     = count($dashicons);
562
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563
-            foreach ($dashicons as $dashicon) {
564
-                $type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
566
-            }
567
-            $icon_html .= $count > 1 ? '</span>' : '';
568
-        }
569
-        // sanitize & escape
570
-        $id    = sanitize_title_with_dashes($label);
571
-        $label = esc_html($label);
572
-        return "<a id='" . esc_attr($id) . "' href='" . esc_url_raw($url) . "' class='" . esc_attr($class) . "' title='" . esc_attr($title) . "'>" . wp_kses($icon_html, AllowedTags::getAllowedTags()) . esc_html($label) . "</a>";
573
-    }
574
-
575
-
576
-    /**
577
-     * This returns a generated link that will load the related help tab on admin pages.
578
-     *
579
-     * @param string      $help_tab_id the id for the connected help tab
580
-     * @param bool|string $page        The page identifier for the page the help tab is on
581
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
582
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
583
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
584
-     * @return string              generated link
585
-     */
586
-    public static function get_help_tab_link(
587
-        $help_tab_id,
588
-        $page = false,
589
-        $action = false,
590
-        $icon_style = false,
591
-        $help_text = false
592
-    ) {
593
-        $allowedtags = AllowedTags::getAllowedTags();
594
-        /** @var RequestInterface $request */
595
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
596
-        $page    = $page ?: $request->getRequestParam('page', '', 'key');
597
-        $action  = $action ?: $request->getRequestParam('action', 'default', 'key');
598
-
599
-
600
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
601
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
602
-        $help_text    = ! $help_text ? '' : $help_text;
603
-        return '<a id="'
604
-               . esc_attr($help_tab_lnk)
605
-               . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'
606
-               . esc_attr($icon)
607
-               . '" title="'
608
-               . esc_attr__(
609
-                   'Click to open the \'Help\' tab for more information about this feature.',
610
-                   'event_espresso'
611
-               )
612
-               . '" > '
613
-               . wp_kses($help_text, $allowedtags)
614
-               . ' </a>';
615
-    }
616
-
617
-
618
-    /**
619
-     * This is a helper method to generate a status legend for a given status array.
620
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
621
-     * status_array.
622
-     *
623
-     * @param array  $status_array   array of statuses that will make up the legend. In format:
624
-     *                               array(
625
-     *                               'status_item' => 'status_name'
626
-     *                               )
627
-     * @param string $active_status  This is used to indicate what the active status is IF that is to be highlighted in
628
-     *                               the legend.
629
-     * @return string               html structure for status.
630
-     * @throws EE_Error
631
-     */
632
-    public static function status_legend($status_array, $active_status = '')
633
-    {
634
-        if (! is_array($status_array)) {
635
-            throw new EE_Error(
636
-                esc_html__(
637
-                    'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
638
-                    'event_espresso'
639
-                )
640
-            );
641
-        }
642
-
643
-        $content = '
53
+	private static $_espresso_themes = [];
54
+
55
+
56
+	/**
57
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
58
+	 *
59
+	 * @return boolean
60
+	 */
61
+	public static function is_espresso_theme()
62
+	{
63
+		return wp_get_theme()->get('TextDomain') === 'event_espresso';
64
+	}
65
+
66
+
67
+	/**
68
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
69
+	 *    load its functions.php file ( if not already loaded )
70
+	 *
71
+	 * @return void
72
+	 */
73
+	public static function load_espresso_theme_functions()
74
+	{
75
+		if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
78
+			}
79
+		}
80
+	}
81
+
82
+
83
+	/**
84
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
85
+	 *
86
+	 * @return array
87
+	 */
88
+	public static function get_espresso_themes()
89
+	{
90
+		if (empty(EEH_Template::$_espresso_themes)) {
91
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
92
+			if (empty($espresso_themes)) {
93
+				return [];
94
+			}
95
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
+				unset($espresso_themes[ $key ]);
97
+			}
98
+			EEH_Template::$_espresso_themes = [];
99
+			foreach ($espresso_themes as $espresso_theme) {
100
+				EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
101
+			}
102
+		}
103
+		return EEH_Template::$_espresso_themes;
104
+	}
105
+
106
+
107
+	/**
108
+	 * EEH_Template::get_template_part
109
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
110
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
111
+	 * filtering based off of the entire template part name
112
+	 *
113
+	 * @param string $slug The slug name for the generic template.
114
+	 * @param string $name The name of the specialised template.
115
+	 * @param array  $template_args
116
+	 * @param bool   $return_string
117
+	 * @return string        the html output for the formatted money value
118
+	 */
119
+	public static function get_template_part(
120
+		$slug = null,
121
+		$name = null,
122
+		$template_args = [],
123
+		$return_string = false
124
+	) {
125
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
126
+		$templates = [];
127
+		$name      = (string) $name;
128
+		if ($name != '') {
129
+			$templates[] = "{$slug}-{$name}.php";
130
+		}
131
+		// allow template parts to be turned off via something like:
132
+		// add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
133
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
134
+			return EEH_Template::locate_template($templates, $template_args, true, $return_string);
135
+		}
136
+		return '';
137
+	}
138
+
139
+
140
+	/**
141
+	 *    locate_template
142
+	 *    locate a template file by looking in the following places, in the following order:
143
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
144
+	 *        <assumed full absolute server path>
145
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
146
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
147
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
148
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
149
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
150
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
151
+	 *        Example:
152
+	 *          You are using the WordPress Twenty Sixteen theme,
153
+	 *        and you want to customize the "some-event.template.php" template,
154
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
155
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
156
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
157
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
158
+	 *        /relative/path/to/some-event.template.php
159
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
160
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
161
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
162
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
163
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
164
+	 *          Had you passed an absolute path to your template that was in some other location,
165
+	 *        ie: "/absolute/path/to/some-event.template.php"
166
+	 *          then the search would have been :
167
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
168
+	 *        /absolute/path/to/some-event.template.php
169
+	 *          and stopped there upon finding it in the second location
170
+	 *
171
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
172
+	 * @param array        $template_args   an array of arguments to be extracted for use in the template
173
+	 * @param boolean      $load            whether to pass the located template path on to the
174
+	 *                                      EEH_Template::display_template() method or simply return it
175
+	 * @param boolean      $return_string   whether to send output immediately to screen, or capture and return as a
176
+	 *                                      string
177
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
178
+	 *                                      generate a custom template or not. Used in places where you don't actually
179
+	 *                                      load the template, you just want to know if there's a custom version of it.
180
+	 * @return mixed
181
+	 * @throws DomainException
182
+	 * @throws InvalidArgumentException
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 */
186
+	public static function locate_template(
187
+		$templates = [],
188
+		$template_args = [],
189
+		$load = true,
190
+		$return_string = true,
191
+		$check_if_custom = false
192
+	) {
193
+		// first use WP locate_template to check for template in the current theme folder
194
+		$template_path = locate_template($templates);
195
+
196
+		if ($check_if_custom && ! empty($template_path)) {
197
+			return true;
198
+		}
199
+
200
+		// not in the theme
201
+		if (empty($template_path)) {
202
+			// not even a template to look for ?
203
+			if (empty($templates)) {
204
+				$loader = LoaderFactory::getLoader();
205
+				/** @var RequestInterface $request */
206
+				$request = $loader->getShared(RequestInterface::class);
207
+				// get post_type
208
+				$post_type = $request->getRequestParam('post_type');
209
+				/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
210
+				$custom_post_types = $loader->getShared(
211
+					'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
212
+				);
213
+				// get array of EE Custom Post Types
214
+				$EE_CPTs = $custom_post_types->getDefinitions();
215
+				// build template name based on request
216
+				if (isset($EE_CPTs[ $post_type ])) {
217
+					$archive_or_single = is_archive() ? 'archive' : '';
218
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
219
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
220
+				}
221
+			}
222
+			// currently active EE template theme
223
+			$current_theme = EE_Config::get_current_theme();
224
+
225
+			// array of paths to folders that may contain templates
226
+			$template_folder_paths = [
227
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
229
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
230
+				EVENT_ESPRESSO_TEMPLATE_DIR,
231
+			];
232
+
233
+			// add core plugin folders for checking only if we're not $check_if_custom
234
+			if (! $check_if_custom) {
235
+				$core_paths            = [
236
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
+					EE_PUBLIC . $current_theme,
238
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
+					EE_TEMPLATES . $current_theme,
240
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241
+					EE_PLUGIN_DIR_PATH,
242
+				];
243
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
244
+			}
245
+
246
+			// now filter that array
247
+			$template_folder_paths = apply_filters(
248
+				'FHEE__EEH_Template__locate_template__template_folder_paths',
249
+				$template_folder_paths
250
+			);
251
+			$templates             = is_array($templates) ? $templates : [$templates];
252
+			$template_folder_paths =
253
+				is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths];
254
+			// array to hold all possible template paths
255
+			$full_template_paths = [];
256
+			$file_name           = '';
257
+
258
+			// loop through $templates
259
+			foreach ($templates as $template) {
260
+				// normalize directory separators
261
+				$template                      = EEH_File::standardise_directory_separators($template);
262
+				$file_name                     = basename($template);
263
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
264
+				// while looping through all template folder paths
265
+				foreach ($template_folder_paths as $template_folder_path) {
266
+					// normalize directory separators
267
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
268
+					// determine if any common base path exists between the two paths
269
+					$common_base_path = EEH_Template::_find_common_base_path(
270
+						[$template_folder_path, $template_path_minus_file_name]
271
+					);
272
+					if ($common_base_path !== '') {
273
+						// both paths have a common base, so just tack the filename onto our search path
274
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
275
+					} else {
276
+						// no common base path, so let's just concatenate
277
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
278
+					}
279
+					// build up our template locations array by adding our resolved paths
280
+					$full_template_paths[] = $resolved_path;
281
+				}
282
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283
+				array_unshift($full_template_paths, $template);
284
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
+				array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
286
+			}
287
+			// filter final array of full template paths
288
+			$full_template_paths = apply_filters(
289
+				'FHEE__EEH_Template__locate_template__full_template_paths',
290
+				$full_template_paths,
291
+				$file_name
292
+			);
293
+			// now loop through our final array of template location paths and check each location
294
+			foreach ((array) $full_template_paths as $full_template_path) {
295
+				if (is_readable($full_template_path)) {
296
+					$template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path);
297
+					break;
298
+				}
299
+			}
300
+		}
301
+
302
+		// hook that can be used to display the full template path that will be used
303
+		do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
304
+
305
+		// if we got it and you want to see it...
306
+		if ($template_path && $load && ! $check_if_custom) {
307
+			if ($return_string) {
308
+				return EEH_Template::display_template($template_path, $template_args, true);
309
+			}
310
+			EEH_Template::display_template($template_path, $template_args);
311
+		}
312
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
313
+	}
314
+
315
+
316
+	/**
317
+	 * _find_common_base_path
318
+	 * given two paths, this determines if there is a common base path between the two
319
+	 *
320
+	 * @param array $paths
321
+	 * @return string
322
+	 */
323
+	protected static function _find_common_base_path($paths)
324
+	{
325
+		$last_offset      = 0;
326
+		$common_base_path = '';
327
+		while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
328
+			$dir_length = $index - $last_offset + 1;
329
+			$directory  = substr($paths[0], $last_offset, $dir_length);
330
+			foreach ($paths as $path) {
331
+				if (substr($path, $last_offset, $dir_length) != $directory) {
332
+					return $common_base_path;
333
+				}
334
+			}
335
+			$common_base_path .= $directory;
336
+			$last_offset      = $index + 1;
337
+		}
338
+		return substr($common_base_path, 0, -1);
339
+	}
340
+
341
+
342
+	/**
343
+	 * load and display a template
344
+	 *
345
+	 * @param bool|string $template_path    server path to the file to be loaded, including file name and extension
346
+	 * @param array       $template_args    an array of arguments to be extracted for use in the template
347
+	 * @param boolean     $return_string    whether to send output immediately to screen, or capture and return as a
348
+	 *                                      string
349
+	 * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
350
+	 *                                      not found or is not readable
351
+	 * @return string
352
+	 * @throws DomainException
353
+	 */
354
+	public static function display_template(
355
+		$template_path = false,
356
+		$template_args = [],
357
+		$return_string = false,
358
+		$throw_exceptions = false
359
+	) {
360
+
361
+		/**
362
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
363
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
364
+		 * the display_template method are templates we DON'T want modified (usually because of js
365
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
366
+		 * using this.
367
+		 *
368
+		 * @since 4.6.0
369
+		 */
370
+		$template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
371
+		$template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372
+
373
+		// you gimme nuttin - YOU GET NUTTIN !!
374
+		if (! $template_path || ! is_readable($template_path)) {
375
+			// ignore whether template is accessible ?
376
+			if ($throw_exceptions) {
377
+				throw new DomainException(
378
+					esc_html__('Invalid, unreadable, or missing file.', 'event_espresso')
379
+				);
380
+			}
381
+			return '';
382
+		}
383
+		// if $template_args are not in an array, then make it so
384
+		if (! is_array($template_args) && ! is_object($template_args)) {
385
+			$template_args = [$template_args];
386
+		}
387
+		extract($template_args, EXTR_SKIP);
388
+
389
+		if ($return_string) {
390
+			// because we want to return a string, we are going to capture the output
391
+			ob_start();
392
+			include($template_path);
393
+			return ob_get_clean();
394
+		}
395
+		include($template_path);
396
+		return '';
397
+	}
398
+
399
+
400
+	/**
401
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
402
+	 *
403
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
404
+	 * @param string        $prefix added to the beginning of the generated class
405
+	 * @param string        $suffix added to the end of the generated class
406
+	 * @return string
407
+	 * @throws EE_Error
408
+	 * @throws ReflectionException
409
+	 */
410
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411
+	{
412
+		// in the beginning...
413
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
414
+		// da muddle
415
+		$class = '';
416
+		// the end
417
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
418
+		// is the passed object an EE object ?
419
+		if ($object instanceof EE_Base_Class) {
420
+			// grab the exact type of object
421
+			$obj_class = get_class($object);
422
+			// depending on the type of object...
423
+			switch ($obj_class) {
424
+				// no specifics just yet...
425
+				default:
426
+					$class = strtolower(str_replace('_', '-', $obj_class));
427
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
428
+			}
429
+		}
430
+		return $prefix . $class . $suffix;
431
+	}
432
+
433
+
434
+	/**
435
+	 * EEH_Template::format_currency
436
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
437
+	 * the country currency settings from the supplied country ISO code
438
+	 *
439
+	 * @param float   $amount       raw money value
440
+	 * @param boolean $return_raw   whether to return the formatted float value only with no currency sign or code
441
+	 * @param boolean $display_code whether to display the country code (USD). Default = TRUE
442
+	 * @param string  $CNT_ISO      2 letter ISO code for a country
443
+	 * @param string  $cur_code_span_class
444
+	 * @return string        the html output for the formatted money value
445
+	 */
446
+	public static function format_currency(
447
+		$amount = null,
448
+		$return_raw = false,
449
+		$display_code = true,
450
+		$CNT_ISO = '',
451
+		$cur_code_span_class = 'currency-code'
452
+	) {
453
+		// ensure amount was received
454
+		if ($amount === null) {
455
+			$msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso');
456
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
457
+			return '';
458
+		}
459
+		// ensure amount is float
460
+		$amount  = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
461
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
462
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
463
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464
+		// still a number, or was amount converted to a string like "free" ?
465
+		if (! is_float($amount_formatted)) {
466
+			return esc_html($amount_formatted);
467
+		}
468
+		try {
469
+			// was a country ISO code passed ? if so generate currency config object for that country
470
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
471
+		} catch (Exception $e) {
472
+			// eat exception
473
+			$mny = null;
474
+		}
475
+		// verify results
476
+		if (! $mny instanceof EE_Currency_Config) {
477
+			// set default config country currency settings
478
+			$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479
+				? EE_Registry::instance()->CFG->currency
480
+				: new EE_Currency_Config();
481
+		}
482
+		// format float
483
+		$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484
+		// add formatting ?
485
+		if (! $return_raw) {
486
+			// add currency sign
487
+			if ($mny->sign_b4) {
488
+				if ($amount >= 0) {
489
+					$amount_formatted = $mny->sign . $amount_formatted;
490
+				} else {
491
+					$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
492
+				}
493
+			} else {
494
+				$amount_formatted = $amount_formatted . $mny->sign;
495
+			}
496
+
497
+			// filter to allow global setting of display_code
498
+			$display_code = (bool) apply_filters(
499
+				'FHEE__EEH_Template__format_currency__display_code',
500
+				$display_code
501
+			);
502
+
503
+			// add currency code ?
504
+			$amount_formatted = $display_code
505
+				? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
506
+				: $amount_formatted;
507
+		}
508
+		// filter results
509
+		$amount_formatted = apply_filters(
510
+			'FHEE__EEH_Template__format_currency__amount_formatted',
511
+			$amount_formatted,
512
+			$mny,
513
+			$return_raw
514
+		);
515
+		// clean up vars
516
+		unset($mny);
517
+		// return formatted currency amount
518
+		return $amount_formatted;
519
+	}
520
+
521
+
522
+	/**
523
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
524
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
525
+	 * related status model or model object (i.e. in documentation etc.)
526
+	 *
527
+	 * @param string  $status_id  Status ID matching a registered status in the esp_status table.  If there is no
528
+	 *                            match, then 'Unknown' will be returned.
529
+	 * @param boolean $plural     Whether to return plural or not
530
+	 * @param string  $schema     'UPPER', 'lower', or 'Sentence'
531
+	 * @return string             The localized label for the status id.
532
+	 * @throws EE_Error
533
+	 */
534
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
535
+	{
536
+		$status = EEM_Status::instance()->localized_status(
537
+			[$status_id => esc_html__('unknown', 'event_espresso')],
538
+			$plural,
539
+			$schema
540
+		);
541
+		return $status[ $status_id ];
542
+	}
543
+
544
+
545
+	/**
546
+	 * This helper just returns a button or link for the given parameters
547
+	 *
548
+	 * @param string $url   the url for the link, note that `esc_url` will be called on it
549
+	 * @param string $label What is the label you want displayed for the button
550
+	 * @param string $class what class is used for the button (defaults to 'button-primary')
551
+	 * @param string $icon
552
+	 * @param string $title
553
+	 * @return string the html output for the button
554
+	 */
555
+	public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '')
556
+	{
557
+		$icon_html = '';
558
+		if (! empty($icon)) {
559
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
560
+			$dashicons = array_filter($dashicons);
561
+			$count     = count($dashicons);
562
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563
+			foreach ($dashicons as $dashicon) {
564
+				$type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
566
+			}
567
+			$icon_html .= $count > 1 ? '</span>' : '';
568
+		}
569
+		// sanitize & escape
570
+		$id    = sanitize_title_with_dashes($label);
571
+		$label = esc_html($label);
572
+		return "<a id='" . esc_attr($id) . "' href='" . esc_url_raw($url) . "' class='" . esc_attr($class) . "' title='" . esc_attr($title) . "'>" . wp_kses($icon_html, AllowedTags::getAllowedTags()) . esc_html($label) . "</a>";
573
+	}
574
+
575
+
576
+	/**
577
+	 * This returns a generated link that will load the related help tab on admin pages.
578
+	 *
579
+	 * @param string      $help_tab_id the id for the connected help tab
580
+	 * @param bool|string $page        The page identifier for the page the help tab is on
581
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
582
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
583
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
584
+	 * @return string              generated link
585
+	 */
586
+	public static function get_help_tab_link(
587
+		$help_tab_id,
588
+		$page = false,
589
+		$action = false,
590
+		$icon_style = false,
591
+		$help_text = false
592
+	) {
593
+		$allowedtags = AllowedTags::getAllowedTags();
594
+		/** @var RequestInterface $request */
595
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
596
+		$page    = $page ?: $request->getRequestParam('page', '', 'key');
597
+		$action  = $action ?: $request->getRequestParam('action', 'default', 'key');
598
+
599
+
600
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
601
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
602
+		$help_text    = ! $help_text ? '' : $help_text;
603
+		return '<a id="'
604
+			   . esc_attr($help_tab_lnk)
605
+			   . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'
606
+			   . esc_attr($icon)
607
+			   . '" title="'
608
+			   . esc_attr__(
609
+				   'Click to open the \'Help\' tab for more information about this feature.',
610
+				   'event_espresso'
611
+			   )
612
+			   . '" > '
613
+			   . wp_kses($help_text, $allowedtags)
614
+			   . ' </a>';
615
+	}
616
+
617
+
618
+	/**
619
+	 * This is a helper method to generate a status legend for a given status array.
620
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
621
+	 * status_array.
622
+	 *
623
+	 * @param array  $status_array   array of statuses that will make up the legend. In format:
624
+	 *                               array(
625
+	 *                               'status_item' => 'status_name'
626
+	 *                               )
627
+	 * @param string $active_status  This is used to indicate what the active status is IF that is to be highlighted in
628
+	 *                               the legend.
629
+	 * @return string               html structure for status.
630
+	 * @throws EE_Error
631
+	 */
632
+	public static function status_legend($status_array, $active_status = '')
633
+	{
634
+		if (! is_array($status_array)) {
635
+			throw new EE_Error(
636
+				esc_html__(
637
+					'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
638
+					'event_espresso'
639
+				)
640
+			);
641
+		}
642
+
643
+		$content = '
644 644
             <div class="ee-list-table-legend-container">
645 645
                 <h4 class="status-legend-title">
646 646
                     ' . esc_html__('Status Legend', 'event_espresso') . '
647 647
                 </h4>
648 648
                 <dl class="ee-list-table-legend">';
649 649
 
650
-        foreach ($status_array as $item => $status) {
651
-            $active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
652
-            $content      .= '
650
+		foreach ($status_array as $item => $status) {
651
+			$active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
652
+			$content      .= '
653 653
                     <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '>
654 654
                         <span class="' . esc_attr('ee-status-legend ee-status-legend-' . $status) . '"></span>
655 655
                         <span class="ee-legend-description">
656 656
                             ' . EEH_Template::pretty_status($status, false, 'sentence') . '
657 657
                         </span>
658 658
                     </dt>';
659
-        }
659
+		}
660 660
 
661
-        $content .= '
661
+		$content .= '
662 662
                 </dl>
663 663
             </div>
664 664
 ';
665
-        return $content;
666
-    }
667
-
668
-
669
-    /**
670
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
671
-     * that's nice for presenting in the wp admin
672
-     *
673
-     * @param mixed $data
674
-     * @return string
675
-     */
676
-    public static function layout_array_as_table($data)
677
-    {
678
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
679
-            $data = (array) $data;
680
-        }
681
-        ob_start();
682
-        if (is_array($data)) {
683
-            if (EEH_Array::is_associative_array($data)) { ?>
665
+		return $content;
666
+	}
667
+
668
+
669
+	/**
670
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
671
+	 * that's nice for presenting in the wp admin
672
+	 *
673
+	 * @param mixed $data
674
+	 * @return string
675
+	 */
676
+	public static function layout_array_as_table($data)
677
+	{
678
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
679
+			$data = (array) $data;
680
+		}
681
+		ob_start();
682
+		if (is_array($data)) {
683
+			if (EEH_Array::is_associative_array($data)) { ?>
684 684
                 <table class="widefat">
685 685
                     <tbody>
686 686
                     <?php foreach ($data as $data_key => $data_values) { ?>
@@ -698,292 +698,292 @@  discard block
 block discarded – undo
698 698
             <?php } else { ?>
699 699
                 <ul>
700 700
                     <?php
701
-                    foreach ($data as $datum) {
702
-                        echo "<li>";
703
-                        echo self::layout_array_as_table($datum);
704
-                        echo "</li>";
705
-                    } ?>
701
+					foreach ($data as $datum) {
702
+						echo "<li>";
703
+						echo self::layout_array_as_table($datum);
704
+						echo "</li>";
705
+					} ?>
706 706
                 </ul>
707 707
             <?php }
708
-        } else {
709
-            // simple value
710
-            echo esc_html($data);
711
-        }
712
-        return ob_get_clean();
713
-    }
714
-
715
-
716
-    /**
717
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
718
-     *
719
-     * @param        $total_items
720
-     * @param        $current
721
-     * @param        $per_page
722
-     * @param        $url
723
-     * @param bool   $show_num_field
724
-     * @param string $paged_arg_name
725
-     * @param array  $items_label
726
-     * @see   self:get_paging_html() for argument docs.
727
-     * @since 4.4.0
728
-     */
729
-    public static function paging_html(
730
-        $total_items,
731
-        $current,
732
-        $per_page,
733
-        $url,
734
-        $show_num_field = true,
735
-        $paged_arg_name = 'paged',
736
-        $items_label = []
737
-    ) {
738
-        echo self::get_paging_html(
739
-            $total_items,
740
-            $current,
741
-            $per_page,
742
-            $url,
743
-            $show_num_field,
744
-            $paged_arg_name,
745
-            $items_label
746
-        );
747
-    }
748
-
749
-
750
-    /**
751
-     * A method for generating paging similar to WP_List_Table
752
-     *
753
-     * @param integer $total_items      How many total items there are to page.
754
-     * @param integer $current          What the current page is.
755
-     * @param integer $per_page         How many items per page.
756
-     * @param string  $url              What the base url for page links is.
757
-     * @param boolean $show_num_field   Whether to show the input for changing page number.
758
-     * @param string  $paged_arg_name   The name of the key for the paged query argument.
759
-     * @param array   $items_label      An array of singular/plural values for the items label:
760
-     *                                  array(
761
-     *                                  'single' => 'item',
762
-     *                                  'plural' => 'items'
763
-     *                                  )
764
-     * @return  string
765
-     * @since    4.4.0
766
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
767
-     */
768
-    public static function get_paging_html(
769
-        $total_items,
770
-        $current,
771
-        $per_page,
772
-        $url,
773
-        $show_num_field = true,
774
-        $paged_arg_name = 'paged',
775
-        $items_label = []
776
-    ) {
777
-        $page_links     = [];
778
-        $disable_first  = $disable_last = '';
779
-        $total_items    = (int) $total_items;
780
-        $per_page       = (int) $per_page;
781
-        $current        = (int) $current;
782
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
783
-
784
-        // filter items_label
785
-        $items_label = apply_filters(
786
-            'FHEE__EEH_Template__get_paging_html__items_label',
787
-            $items_label
788
-        );
789
-
790
-        if (
791
-            empty($items_label)
792
-            || ! is_array($items_label)
793
-            || ! isset($items_label['single'])
794
-            || ! isset($items_label['plural'])
795
-        ) {
796
-            $items_label = [
797
-                'single' => esc_html__('1 item', 'event_espresso'),
798
-                'plural' => esc_html__('%s items', 'event_espresso'),
799
-            ];
800
-        } else {
801
-            $items_label = [
802
-                'single' => '1 ' . esc_html($items_label['single']),
803
-                'plural' => '%s ' . esc_html($items_label['plural']),
804
-            ];
805
-        }
806
-
807
-        $total_pages = ceil($total_items / $per_page);
808
-
809
-        if ($total_pages <= 1) {
810
-            return '';
811
-        }
812
-
813
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
814
-
815
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
816
-
817
-        if ($current === 1) {
818
-            $disable_first = ' disabled';
819
-        }
820
-        if ($current == $total_pages) {
821
-            $disable_last = ' disabled';
822
-        }
823
-
824
-        $page_links[] = sprintf(
825
-            "<a class='%s' title='%s' href='%s'>%s</a>",
826
-            'first-page' . $disable_first,
827
-            esc_attr__('Go to the first page', 'event_espresso'),
828
-            esc_url_raw(remove_query_arg($paged_arg_name, $url)),
829
-            '&laquo;'
830
-        );
831
-
832
-        $page_links[] = sprintf(
833
-            '<a class="%s" title="%s" href="%s">%s</a>',
834
-            'prev-page' . $disable_first,
835
-            esc_attr__('Go to the previous page', 'event_espresso'),
836
-            esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
837
-            '&lsaquo;'
838
-        );
839
-
840
-        if (! $show_num_field) {
841
-            $html_current_page = $current;
842
-        } else {
843
-            $html_current_page = sprintf(
844
-                "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
845
-                esc_attr__('Current page', 'event_espresso'),
846
-                esc_attr($current),
847
-                strlen($total_pages)
848
-            );
849
-        }
850
-
851
-        $html_total_pages = sprintf(
852
-            '<span class="total-pages">%s</span>',
853
-            number_format_i18n($total_pages)
854
-        );
855
-        $page_links[]     = sprintf(
856
-            _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
857
-            $html_current_page,
858
-            $html_total_pages,
859
-            '<span class="paging-input">',
860
-            '</span>'
861
-        );
862
-
863
-        $page_links[] = sprintf(
864
-            '<a class="%s" title="%s" href="%s">%s</a>',
865
-            'next-page' . $disable_last,
866
-            esc_attr__('Go to the next page', 'event_espresso'),
867
-            esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
868
-            '&rsaquo;'
869
-        );
870
-
871
-        $page_links[] = sprintf(
872
-            '<a class="%s" title="%s" href="%s">%s</a>',
873
-            'last-page' . $disable_last,
874
-            esc_attr__('Go to the last page', 'event_espresso'),
875
-            esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
876
-            '&raquo;'
877
-        );
878
-
879
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
880
-        // set page class
881
-        if ($total_pages) {
882
-            $page_class = $total_pages < 2 ? ' one-page' : '';
883
-        } else {
884
-            $page_class = ' no-pages';
885
-        }
886
-
887
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
888
-    }
889
-
890
-
891
-    /**
892
-     * @param string $wrap_class
893
-     * @param string $wrap_id
894
-     * @return string
895
-     */
896
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = [])
897
-    {
898
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
899
-        if (
900
-            ! $admin
901
-            && ! apply_filters(
902
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
903
-                EE_Registry::instance()->CFG->admin->show_reg_footer
904
-            )
905
-        ) {
906
-            return '';
907
-        }
908
-        $tag        = $admin ? 'span' : 'div';
909
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
910
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
911
-        $attributes .= ! empty($wrap_class)
912
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
913
-            : ' class="powered-by-event-espresso-credit"';
914
-        $query_args = array_merge(
915
-            [
916
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
917
-                'utm_source'   => 'powered_by_event_espresso',
918
-                'utm_medium'   => 'link',
919
-                'utm_campaign' => 'powered_by',
920
-            ],
921
-            $query_args
922
-        );
923
-        $powered_by = apply_filters(
924
-            'FHEE__EEH_Template__powered_by_event_espresso_text',
925
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
926
-        );
927
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
928
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
929
-        return (string) apply_filters(
930
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
931
-            sprintf(
932
-                esc_html_x(
933
-                    '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
934
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
935
-                    'event_espresso'
936
-                ),
937
-                "<{$tag}{$attributes}>",
938
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
939
-                $admin ? '' : '<br />'
940
-            ),
941
-            $wrap_class,
942
-            $wrap_id
943
-        );
944
-    }
945
-
946
-
947
-    /**
948
-     * @param string $image_name
949
-     * @return string|null
950
-     * @since   4.10.14.p
951
-     */
952
-    public static function getScreenshotUrl($image_name)
953
-    {
954
-        return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
955
-    }
708
+		} else {
709
+			// simple value
710
+			echo esc_html($data);
711
+		}
712
+		return ob_get_clean();
713
+	}
714
+
715
+
716
+	/**
717
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
718
+	 *
719
+	 * @param        $total_items
720
+	 * @param        $current
721
+	 * @param        $per_page
722
+	 * @param        $url
723
+	 * @param bool   $show_num_field
724
+	 * @param string $paged_arg_name
725
+	 * @param array  $items_label
726
+	 * @see   self:get_paging_html() for argument docs.
727
+	 * @since 4.4.0
728
+	 */
729
+	public static function paging_html(
730
+		$total_items,
731
+		$current,
732
+		$per_page,
733
+		$url,
734
+		$show_num_field = true,
735
+		$paged_arg_name = 'paged',
736
+		$items_label = []
737
+	) {
738
+		echo self::get_paging_html(
739
+			$total_items,
740
+			$current,
741
+			$per_page,
742
+			$url,
743
+			$show_num_field,
744
+			$paged_arg_name,
745
+			$items_label
746
+		);
747
+	}
748
+
749
+
750
+	/**
751
+	 * A method for generating paging similar to WP_List_Table
752
+	 *
753
+	 * @param integer $total_items      How many total items there are to page.
754
+	 * @param integer $current          What the current page is.
755
+	 * @param integer $per_page         How many items per page.
756
+	 * @param string  $url              What the base url for page links is.
757
+	 * @param boolean $show_num_field   Whether to show the input for changing page number.
758
+	 * @param string  $paged_arg_name   The name of the key for the paged query argument.
759
+	 * @param array   $items_label      An array of singular/plural values for the items label:
760
+	 *                                  array(
761
+	 *                                  'single' => 'item',
762
+	 *                                  'plural' => 'items'
763
+	 *                                  )
764
+	 * @return  string
765
+	 * @since    4.4.0
766
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
767
+	 */
768
+	public static function get_paging_html(
769
+		$total_items,
770
+		$current,
771
+		$per_page,
772
+		$url,
773
+		$show_num_field = true,
774
+		$paged_arg_name = 'paged',
775
+		$items_label = []
776
+	) {
777
+		$page_links     = [];
778
+		$disable_first  = $disable_last = '';
779
+		$total_items    = (int) $total_items;
780
+		$per_page       = (int) $per_page;
781
+		$current        = (int) $current;
782
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
783
+
784
+		// filter items_label
785
+		$items_label = apply_filters(
786
+			'FHEE__EEH_Template__get_paging_html__items_label',
787
+			$items_label
788
+		);
789
+
790
+		if (
791
+			empty($items_label)
792
+			|| ! is_array($items_label)
793
+			|| ! isset($items_label['single'])
794
+			|| ! isset($items_label['plural'])
795
+		) {
796
+			$items_label = [
797
+				'single' => esc_html__('1 item', 'event_espresso'),
798
+				'plural' => esc_html__('%s items', 'event_espresso'),
799
+			];
800
+		} else {
801
+			$items_label = [
802
+				'single' => '1 ' . esc_html($items_label['single']),
803
+				'plural' => '%s ' . esc_html($items_label['plural']),
804
+			];
805
+		}
806
+
807
+		$total_pages = ceil($total_items / $per_page);
808
+
809
+		if ($total_pages <= 1) {
810
+			return '';
811
+		}
812
+
813
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
814
+
815
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
816
+
817
+		if ($current === 1) {
818
+			$disable_first = ' disabled';
819
+		}
820
+		if ($current == $total_pages) {
821
+			$disable_last = ' disabled';
822
+		}
823
+
824
+		$page_links[] = sprintf(
825
+			"<a class='%s' title='%s' href='%s'>%s</a>",
826
+			'first-page' . $disable_first,
827
+			esc_attr__('Go to the first page', 'event_espresso'),
828
+			esc_url_raw(remove_query_arg($paged_arg_name, $url)),
829
+			'&laquo;'
830
+		);
831
+
832
+		$page_links[] = sprintf(
833
+			'<a class="%s" title="%s" href="%s">%s</a>',
834
+			'prev-page' . $disable_first,
835
+			esc_attr__('Go to the previous page', 'event_espresso'),
836
+			esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
837
+			'&lsaquo;'
838
+		);
839
+
840
+		if (! $show_num_field) {
841
+			$html_current_page = $current;
842
+		} else {
843
+			$html_current_page = sprintf(
844
+				"<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
845
+				esc_attr__('Current page', 'event_espresso'),
846
+				esc_attr($current),
847
+				strlen($total_pages)
848
+			);
849
+		}
850
+
851
+		$html_total_pages = sprintf(
852
+			'<span class="total-pages">%s</span>',
853
+			number_format_i18n($total_pages)
854
+		);
855
+		$page_links[]     = sprintf(
856
+			_x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
857
+			$html_current_page,
858
+			$html_total_pages,
859
+			'<span class="paging-input">',
860
+			'</span>'
861
+		);
862
+
863
+		$page_links[] = sprintf(
864
+			'<a class="%s" title="%s" href="%s">%s</a>',
865
+			'next-page' . $disable_last,
866
+			esc_attr__('Go to the next page', 'event_espresso'),
867
+			esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
868
+			'&rsaquo;'
869
+		);
870
+
871
+		$page_links[] = sprintf(
872
+			'<a class="%s" title="%s" href="%s">%s</a>',
873
+			'last-page' . $disable_last,
874
+			esc_attr__('Go to the last page', 'event_espresso'),
875
+			esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
876
+			'&raquo;'
877
+		);
878
+
879
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
880
+		// set page class
881
+		if ($total_pages) {
882
+			$page_class = $total_pages < 2 ? ' one-page' : '';
883
+		} else {
884
+			$page_class = ' no-pages';
885
+		}
886
+
887
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
888
+	}
889
+
890
+
891
+	/**
892
+	 * @param string $wrap_class
893
+	 * @param string $wrap_id
894
+	 * @return string
895
+	 */
896
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = [])
897
+	{
898
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
899
+		if (
900
+			! $admin
901
+			&& ! apply_filters(
902
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
903
+				EE_Registry::instance()->CFG->admin->show_reg_footer
904
+			)
905
+		) {
906
+			return '';
907
+		}
908
+		$tag        = $admin ? 'span' : 'div';
909
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
910
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
911
+		$attributes .= ! empty($wrap_class)
912
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
913
+			: ' class="powered-by-event-espresso-credit"';
914
+		$query_args = array_merge(
915
+			[
916
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
917
+				'utm_source'   => 'powered_by_event_espresso',
918
+				'utm_medium'   => 'link',
919
+				'utm_campaign' => 'powered_by',
920
+			],
921
+			$query_args
922
+		);
923
+		$powered_by = apply_filters(
924
+			'FHEE__EEH_Template__powered_by_event_espresso_text',
925
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
926
+		);
927
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
928
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
929
+		return (string) apply_filters(
930
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
931
+			sprintf(
932
+				esc_html_x(
933
+					'%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
934
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
935
+					'event_espresso'
936
+				),
937
+				"<{$tag}{$attributes}>",
938
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
939
+				$admin ? '' : '<br />'
940
+			),
941
+			$wrap_class,
942
+			$wrap_id
943
+		);
944
+	}
945
+
946
+
947
+	/**
948
+	 * @param string $image_name
949
+	 * @return string|null
950
+	 * @since   4.10.14.p
951
+	 */
952
+	public static function getScreenshotUrl($image_name)
953
+	{
954
+		return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
955
+	}
956 956
 }
957 957
 
958 958
 
959 959
 if (! function_exists('espresso_pagination')) {
960
-    /**
961
-     *    espresso_pagination
962
-     *
963
-     * @access    public
964
-     * @return    void
965
-     */
966
-    function espresso_pagination()
967
-    {
968
-        global $wp_query;
969
-        $big        = 999999999; // need an unlikely integer
970
-        $pagination = paginate_links(
971
-            [
972
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
973
-                'format'       => '?paged=%#%',
974
-                'current'      => max(1, get_query_var('paged')),
975
-                'total'        => $wp_query->max_num_pages,
976
-                'show_all'     => true,
977
-                'end_size'     => 10,
978
-                'mid_size'     => 6,
979
-                'prev_next'    => true,
980
-                'prev_text'    => esc_html__('&lsaquo; PREV', 'event_espresso'),
981
-                'next_text'    => esc_html__('NEXT &rsaquo;', 'event_espresso'),
982
-                'type'         => 'plain',
983
-                'add_args'     => false,
984
-                'add_fragment' => '',
985
-            ]
986
-        );
987
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
988
-    }
960
+	/**
961
+	 *    espresso_pagination
962
+	 *
963
+	 * @access    public
964
+	 * @return    void
965
+	 */
966
+	function espresso_pagination()
967
+	{
968
+		global $wp_query;
969
+		$big        = 999999999; // need an unlikely integer
970
+		$pagination = paginate_links(
971
+			[
972
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
973
+				'format'       => '?paged=%#%',
974
+				'current'      => max(1, get_query_var('paged')),
975
+				'total'        => $wp_query->max_num_pages,
976
+				'show_all'     => true,
977
+				'end_size'     => 10,
978
+				'mid_size'     => 6,
979
+				'prev_next'    => true,
980
+				'prev_text'    => esc_html__('&lsaquo; PREV', 'event_espresso'),
981
+				'next_text'    => esc_html__('NEXT &rsaquo;', 'event_espresso'),
982
+				'type'         => 'plain',
983
+				'add_args'     => false,
984
+				'add_fragment' => '',
985
+			]
986
+		);
987
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
988
+	}
989 989
 }
990 990
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\request\RequestInterface;
7 7
 use EventEspresso\core\services\request\sanitizers\AllowedTags;
8 8
 
9
-if (! function_exists('espresso_get_template_part')) {
9
+if ( ! function_exists('espresso_get_template_part')) {
10 10
     /**
11 11
      * espresso_get_template_part
12 12
      * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 }
23 23
 
24 24
 
25
-if (! function_exists('espresso_get_object_css_class')) {
25
+if ( ! function_exists('espresso_get_object_css_class')) {
26 26
     /**
27 27
      * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
28 28
      *
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public static function load_espresso_theme_functions()
74 74
     {
75
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
75
+        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) {
77
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php');
78 78
             }
79 79
         }
80 80
     }
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
     public static function get_espresso_themes()
89 89
     {
90 90
         if (empty(EEH_Template::$_espresso_themes)) {
91
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
91
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
92 92
             if (empty($espresso_themes)) {
93 93
                 return [];
94 94
             }
95 95
             if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
-                unset($espresso_themes[ $key ]);
96
+                unset($espresso_themes[$key]);
97 97
             }
98 98
             EEH_Template::$_espresso_themes = [];
99 99
             foreach ($espresso_themes as $espresso_theme) {
100
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
100
+                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
101 101
             }
102 102
         }
103 103
         return EEH_Template::$_espresso_themes;
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
                 // get array of EE Custom Post Types
214 214
                 $EE_CPTs = $custom_post_types->getDefinitions();
215 215
                 // build template name based on request
216
-                if (isset($EE_CPTs[ $post_type ])) {
216
+                if (isset($EE_CPTs[$post_type])) {
217 217
                     $archive_or_single = is_archive() ? 'archive' : '';
218 218
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
219
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
219
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
220 220
                 }
221 221
             }
222 222
             // currently active EE template theme
@@ -225,18 +225,18 @@  discard block
 block discarded – undo
225 225
             // array of paths to folders that may contain templates
226 226
             $template_folder_paths = [
227 227
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
228
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
229 229
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
230 230
                 EVENT_ESPRESSO_TEMPLATE_DIR,
231 231
             ];
232 232
 
233 233
             // add core plugin folders for checking only if we're not $check_if_custom
234
-            if (! $check_if_custom) {
235
-                $core_paths            = [
234
+            if ( ! $check_if_custom) {
235
+                $core_paths = [
236 236
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
-                    EE_PUBLIC . $current_theme,
237
+                    EE_PUBLIC.$current_theme,
238 238
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
-                    EE_TEMPLATES . $current_theme,
239
+                    EE_TEMPLATES.$current_theme,
240 240
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241 241
                     EE_PLUGIN_DIR_PATH,
242 242
                 ];
@@ -271,10 +271,10 @@  discard block
 block discarded – undo
271 271
                     );
272 272
                     if ($common_base_path !== '') {
273 273
                         // both paths have a common base, so just tack the filename onto our search path
274
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
274
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
275 275
                     } else {
276 276
                         // no common base path, so let's just concatenate
277
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
277
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
278 278
                     }
279 279
                     // build up our template locations array by adding our resolved paths
280 280
                     $full_template_paths[] = $resolved_path;
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283 283
                 array_unshift($full_template_paths, $template);
284 284
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
285
+                array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name);
286 286
             }
287 287
             // filter final array of full template paths
288 288
             $full_template_paths = apply_filters(
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                 }
334 334
             }
335 335
             $common_base_path .= $directory;
336
-            $last_offset      = $index + 1;
336
+            $last_offset = $index + 1;
337 337
         }
338 338
         return substr($common_base_path, 0, -1);
339 339
     }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372 372
 
373 373
         // you gimme nuttin - YOU GET NUTTIN !!
374
-        if (! $template_path || ! is_readable($template_path)) {
374
+        if ( ! $template_path || ! is_readable($template_path)) {
375 375
             // ignore whether template is accessible ?
376 376
             if ($throw_exceptions) {
377 377
                 throw new DomainException(
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
             return '';
382 382
         }
383 383
         // if $template_args are not in an array, then make it so
384
-        if (! is_array($template_args) && ! is_object($template_args)) {
384
+        if ( ! is_array($template_args) && ! is_object($template_args)) {
385 385
             $template_args = [$template_args];
386 386
         }
387 387
         extract($template_args, EXTR_SKIP);
@@ -410,11 +410,11 @@  discard block
 block discarded – undo
410 410
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411 411
     {
412 412
         // in the beginning...
413
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
413
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
414 414
         // da muddle
415 415
         $class = '';
416 416
         // the end
417
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
417
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
418 418
         // is the passed object an EE object ?
419 419
         if ($object instanceof EE_Base_Class) {
420 420
             // grab the exact type of object
@@ -424,10 +424,10 @@  discard block
 block discarded – undo
424 424
                 // no specifics just yet...
425 425
                 default:
426 426
                     $class = strtolower(str_replace('_', '-', $obj_class));
427
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
427
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
428 428
             }
429 429
         }
430
-        return $prefix . $class . $suffix;
430
+        return $prefix.$class.$suffix;
431 431
     }
432 432
 
433 433
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         // filter raw amount (allows 0.00 to be changed to "free" for example)
463 463
         $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464 464
         // still a number, or was amount converted to a string like "free" ?
465
-        if (! is_float($amount_formatted)) {
465
+        if ( ! is_float($amount_formatted)) {
466 466
             return esc_html($amount_formatted);
467 467
         }
468 468
         try {
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
             $mny = null;
474 474
         }
475 475
         // verify results
476
-        if (! $mny instanceof EE_Currency_Config) {
476
+        if ( ! $mny instanceof EE_Currency_Config) {
477 477
             // set default config country currency settings
478 478
             $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479 479
                 ? EE_Registry::instance()->CFG->currency
@@ -482,16 +482,16 @@  discard block
 block discarded – undo
482 482
         // format float
483 483
         $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484 484
         // add formatting ?
485
-        if (! $return_raw) {
485
+        if ( ! $return_raw) {
486 486
             // add currency sign
487 487
             if ($mny->sign_b4) {
488 488
                 if ($amount >= 0) {
489
-                    $amount_formatted = $mny->sign . $amount_formatted;
489
+                    $amount_formatted = $mny->sign.$amount_formatted;
490 490
                 } else {
491
-                    $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
491
+                    $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
492 492
                 }
493 493
             } else {
494
-                $amount_formatted = $amount_formatted . $mny->sign;
494
+                $amount_formatted = $amount_formatted.$mny->sign;
495 495
             }
496 496
 
497 497
             // filter to allow global setting of display_code
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 
503 503
             // add currency code ?
504 504
             $amount_formatted = $display_code
505
-                ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
505
+                ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>'
506 506
                 : $amount_formatted;
507 507
         }
508 508
         // filter results
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
             $plural,
539 539
             $schema
540 540
         );
541
-        return $status[ $status_id ];
541
+        return $status[$status_id];
542 542
     }
543 543
 
544 544
 
@@ -555,21 +555,21 @@  discard block
 block discarded – undo
555 555
     public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '')
556 556
     {
557 557
         $icon_html = '';
558
-        if (! empty($icon)) {
558
+        if ( ! empty($icon)) {
559 559
             $dashicons = preg_split("(ee-icon |dashicons )", $icon);
560 560
             $dashicons = array_filter($dashicons);
561 561
             $count     = count($dashicons);
562 562
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563 563
             foreach ($dashicons as $dashicon) {
564
-                $type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
564
+                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
566 566
             }
567 567
             $icon_html .= $count > 1 ? '</span>' : '';
568 568
         }
569 569
         // sanitize & escape
570 570
         $id    = sanitize_title_with_dashes($label);
571 571
         $label = esc_html($label);
572
-        return "<a id='" . esc_attr($id) . "' href='" . esc_url_raw($url) . "' class='" . esc_attr($class) . "' title='" . esc_attr($title) . "'>" . wp_kses($icon_html, AllowedTags::getAllowedTags()) . esc_html($label) . "</a>";
572
+        return "<a id='".esc_attr($id)."' href='".esc_url_raw($url)."' class='".esc_attr($class)."' title='".esc_attr($title)."'>".wp_kses($icon_html, AllowedTags::getAllowedTags()).esc_html($label)."</a>";
573 573
     }
574 574
 
575 575
 
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
         $action  = $action ?: $request->getRequestParam('action', 'default', 'key');
598 598
 
599 599
 
600
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
600
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
601 601
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
602 602
         $help_text    = ! $help_text ? '' : $help_text;
603 603
         return '<a id="'
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
      */
632 632
     public static function status_legend($status_array, $active_status = '')
633 633
     {
634
-        if (! is_array($status_array)) {
634
+        if ( ! is_array($status_array)) {
635 635
             throw new EE_Error(
636 636
                 esc_html__(
637 637
                     'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
@@ -643,17 +643,17 @@  discard block
 block discarded – undo
643 643
         $content = '
644 644
             <div class="ee-list-table-legend-container">
645 645
                 <h4 class="status-legend-title">
646
-                    ' . esc_html__('Status Legend', 'event_espresso') . '
646
+                    ' . esc_html__('Status Legend', 'event_espresso').'
647 647
                 </h4>
648 648
                 <dl class="ee-list-table-legend">';
649 649
 
650 650
         foreach ($status_array as $item => $status) {
651 651
             $active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
652
-            $content      .= '
653
-                    <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '>
654
-                        <span class="' . esc_attr('ee-status-legend ee-status-legend-' . $status) . '"></span>
652
+            $content .= '
653
+                    <dt id="' . esc_attr('ee-legend-item-tooltip-'.$item).'" '.$active_class.'>
654
+                        <span class="' . esc_attr('ee-status-legend ee-status-legend-'.$status).'"></span>
655 655
                         <span class="ee-legend-description">
656
-                            ' . EEH_Template::pretty_status($status, false, 'sentence') . '
656
+                            ' . EEH_Template::pretty_status($status, false, 'sentence').'
657 657
                         </span>
658 658
                     </dt>';
659 659
         }
@@ -799,8 +799,8 @@  discard block
 block discarded – undo
799 799
             ];
800 800
         } else {
801 801
             $items_label = [
802
-                'single' => '1 ' . esc_html($items_label['single']),
803
-                'plural' => '%s ' . esc_html($items_label['plural']),
802
+                'single' => '1 '.esc_html($items_label['single']),
803
+                'plural' => '%s '.esc_html($items_label['plural']),
804 804
             ];
805 805
         }
806 806
 
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
 
813 813
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
814 814
 
815
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
815
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
816 816
 
817 817
         if ($current === 1) {
818 818
             $disable_first = ' disabled';
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 
824 824
         $page_links[] = sprintf(
825 825
             "<a class='%s' title='%s' href='%s'>%s</a>",
826
-            'first-page' . $disable_first,
826
+            'first-page'.$disable_first,
827 827
             esc_attr__('Go to the first page', 'event_espresso'),
828 828
             esc_url_raw(remove_query_arg($paged_arg_name, $url)),
829 829
             '&laquo;'
@@ -831,13 +831,13 @@  discard block
 block discarded – undo
831 831
 
832 832
         $page_links[] = sprintf(
833 833
             '<a class="%s" title="%s" href="%s">%s</a>',
834
-            'prev-page' . $disable_first,
834
+            'prev-page'.$disable_first,
835 835
             esc_attr__('Go to the previous page', 'event_espresso'),
836 836
             esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
837 837
             '&lsaquo;'
838 838
         );
839 839
 
840
-        if (! $show_num_field) {
840
+        if ( ! $show_num_field) {
841 841
             $html_current_page = $current;
842 842
         } else {
843 843
             $html_current_page = sprintf(
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
             '<span class="total-pages">%s</span>',
853 853
             number_format_i18n($total_pages)
854 854
         );
855
-        $page_links[]     = sprintf(
855
+        $page_links[] = sprintf(
856 856
             _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
857 857
             $html_current_page,
858 858
             $html_total_pages,
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
 
863 863
         $page_links[] = sprintf(
864 864
             '<a class="%s" title="%s" href="%s">%s</a>',
865
-            'next-page' . $disable_last,
865
+            'next-page'.$disable_last,
866 866
             esc_attr__('Go to the next page', 'event_espresso'),
867 867
             esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
868 868
             '&rsaquo;'
@@ -870,13 +870,13 @@  discard block
 block discarded – undo
870 870
 
871 871
         $page_links[] = sprintf(
872 872
             '<a class="%s" title="%s" href="%s">%s</a>',
873
-            'last-page' . $disable_last,
873
+            'last-page'.$disable_last,
874 874
             esc_attr__('Go to the last page', 'event_espresso'),
875 875
             esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
876 876
             '&raquo;'
877 877
         );
878 878
 
879
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
879
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
880 880
         // set page class
881 881
         if ($total_pages) {
882 882
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
             $page_class = ' no-pages';
885 885
         }
886 886
 
887
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
887
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
888 888
     }
889 889
 
890 890
 
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
         );
923 923
         $powered_by = apply_filters(
924 924
             'FHEE__EEH_Template__powered_by_event_espresso_text',
925
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
925
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'
926 926
         );
927 927
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
928 928
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
@@ -951,12 +951,12 @@  discard block
 block discarded – undo
951 951
      */
952 952
     public static function getScreenshotUrl($image_name)
953 953
     {
954
-        return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
954
+        return esc_url_raw(EE_GLOBAL_ASSETS_URL.'images/screenshots/'.$image_name.'.jpg');
955 955
     }
956 956
 }
957 957
 
958 958
 
959
-if (! function_exists('espresso_pagination')) {
959
+if ( ! function_exists('espresso_pagination')) {
960 960
     /**
961 961
      *    espresso_pagination
962 962
      *
@@ -984,6 +984,6 @@  discard block
 block discarded – undo
984 984
                 'add_fragment' => '',
985 985
             ]
986 986
         );
987
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
987
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
988 988
     }
989 989
 }
990 990
\ No newline at end of file
Please login to merge, or discard this patch.
core/helpers/EEH_Form_Fields.helper.php 2 patches
Indentation   +1946 added lines, -1946 removed lines patch added patch discarded remove patch
@@ -27,1973 +27,1973 @@
 block discarded – undo
27 27
  */
28 28
 class EEH_Form_Fields
29 29
 {
30
-    /**
31
-     *  Generates HTML for the forms used on admin pages
32
-     *
33
-     *
34
-     * @static
35
-     * @access public
36
-     * @param array $input_vars - array of input field details
37
-     *                          format:
38
-     *                          $template_form_fields['field-id'] = array(
39
-     *                          'name' => 'name_attribute',
40
-     *                          'label' => esc_html__('Field Label', 'event_espresso'), //or false
41
-     *                          'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden',
42
-     *                          'checkbox', 'wp_editor'
43
-     *                          'type' => 'int', //what "type" the value is (i.e. string, int etc)
44
-     *                          'required' => false, //boolean for whether the field is required
45
-     *                          'validation' => true, //boolean, whether to validate the field (todo)
46
-     *                          'value' => 'some_value_for_field', //what value is used for field
47
-     *                          'format' => '%d', //what format the value is (%d, %f, or %s)
48
-     *                          'db-col' => 'column_in_db' //used to indicate which column the field corresponds with
49
-     *                          in the db
50
-     *                          'options' => optiona, optionb || array('value' => 'label', '') //if the input type is
51
-     *                          "select", this allows you to set the args for the different <option> tags.
52
-     *                          'tabindex' => 1 //this allows you to set the tabindex for the field.
53
-     *                          'append_content' => '' //this allows you to send in html content to append to the
54
-     *                          field.
55
-     *                          )
56
-     * @param array $form_id    - used for defining unique identifiers for the form.
57
-     * @return string
58
-     * @todo   : at some point we can break this down into other static methods to abstract it a bit better.
59
-     */
60
-    public static function get_form_fields($input_vars = [], $form_id = false)
61
-    {
62
-
63
-        if (empty($input_vars)) {
64
-            EE_Error::add_error(
65
-                esc_html__('missing required variables for the form field generator', 'event_espresso'),
66
-                __FILE__,
67
-                __FUNCTION__,
68
-                __LINE__
69
-            );
70
-            return false;
71
-        }
72
-
73
-        $output        = "";
74
-        $inputs        = [];
75
-        $hidden_inputs = [];
76
-
77
-        // cycle thru inputs
78
-        foreach ($input_vars as $input_key => $input_value) {
79
-            $defaults = [
80
-                'append_content' => '',
81
-                'css_class'      => '',
82
-                'cols'           => 80,
83
-                'db-col'         => 'column_in_db',
84
-                'format'         => '%d',
85
-                'input'          => 'hidden',
86
-                'label'          => esc_html__('No label', 'event_espresso'),
87
-                'name'           => $input_key,
88
-                'options'        => [],
89
-                'required'       => false,
90
-                'tabindex'       => 0,
91
-                'rows'           => 10,
92
-                'type'           => 'int',
93
-                'validation'     => true,
94
-                'value'          => 'some_value_for_field',
95
-            ];
96
-
97
-            $input_value = wp_parse_args($input_value, $defaults);
98
-
99
-            $append_content = $input_value['append_content'];
100
-            $css_class      = $input_value['css_class'];
101
-            $cols           = $input_value['cols'];
102
-            $label          = $input_value['label'];
103
-            $name           = $input_value['name'];
104
-            $options        = $input_value['options'];
105
-            $required       = $input_value['required'];
106
-            $tab_index      = $input_value['tabindex'];
107
-            $rows           = $input_value['rows'];
108
-            $type           = $input_value['input'];
109
-            $value          = $input_value['value'];
110
-
111
-            $id    = $form_id ? $form_id . '-' . $input_key : $input_key;
112
-            $class = $required ? 'required ' . $css_class : $css_class;
113
-
114
-            // what type of input are we dealing with ?
115
-            switch ($type) {
116
-                case 'checkbox':
117
-                case 'radio':
118
-                    $field = self::adminMulti($value, $class, $id, $name, $required, $tab_index, $type, 1, $label);
119
-                    $field .= $append_content ?: '';
120
-                    break;
121
-
122
-                case 'hidden':
123
-                    $field           = null;
124
-                    $hidden_inputs[] = self::adminHidden($css_class, $id, $name, $value);
125
-                    break;
126
-
127
-                case 'select':
128
-                    $options = is_array($options) ? $options : explode(',', $options);
129
-                    $field   = self::adminLabel($id, $label, $required);
130
-                    $field   .= self::adminSelect($value, $class, $id, $name, $required, $tab_index, $options);
131
-                    $field   .= $append_content ?: '';
132
-                    break;
133
-
134
-                case 'textarea':
135
-                    $field = self::adminLabel($id, $label, $required);
136
-                    $field .= self::adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value);
137
-                    $field .= $append_content ?: '';
138
-                    break;
139
-
140
-                case 'wp_editor':
141
-                    $label = esc_html($label);
142
-                    $field = "<h4>{$label}</h4>";
143
-                    $field .= $append_content ?: '';
144
-                    $field .= self::adminWpEditor(
145
-                        $class,
146
-                        $id,
147
-                        $name,
148
-                        $rows,
149
-                        $tab_index,
150
-                        $value
151
-                    );
152
-                    break;
153
-
154
-                default:
155
-                    $field = self::adminLabel($id, $label, $required);
156
-                    $field .= self::adminText($class, $id, $name, $required, $tab_index, $value);
157
-                    $field .= $append_content ?: '';
158
-            }
159
-            if ($field) {
160
-                $inputs[] = $field;
161
-            }
162
-        } // end foreach( $input_vars as $input_key => $input_value )
163
-
164
-        if (! empty($inputs)) {
165
-            $glue   = "
30
+	/**
31
+	 *  Generates HTML for the forms used on admin pages
32
+	 *
33
+	 *
34
+	 * @static
35
+	 * @access public
36
+	 * @param array $input_vars - array of input field details
37
+	 *                          format:
38
+	 *                          $template_form_fields['field-id'] = array(
39
+	 *                          'name' => 'name_attribute',
40
+	 *                          'label' => esc_html__('Field Label', 'event_espresso'), //or false
41
+	 *                          'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden',
42
+	 *                          'checkbox', 'wp_editor'
43
+	 *                          'type' => 'int', //what "type" the value is (i.e. string, int etc)
44
+	 *                          'required' => false, //boolean for whether the field is required
45
+	 *                          'validation' => true, //boolean, whether to validate the field (todo)
46
+	 *                          'value' => 'some_value_for_field', //what value is used for field
47
+	 *                          'format' => '%d', //what format the value is (%d, %f, or %s)
48
+	 *                          'db-col' => 'column_in_db' //used to indicate which column the field corresponds with
49
+	 *                          in the db
50
+	 *                          'options' => optiona, optionb || array('value' => 'label', '') //if the input type is
51
+	 *                          "select", this allows you to set the args for the different <option> tags.
52
+	 *                          'tabindex' => 1 //this allows you to set the tabindex for the field.
53
+	 *                          'append_content' => '' //this allows you to send in html content to append to the
54
+	 *                          field.
55
+	 *                          )
56
+	 * @param array $form_id    - used for defining unique identifiers for the form.
57
+	 * @return string
58
+	 * @todo   : at some point we can break this down into other static methods to abstract it a bit better.
59
+	 */
60
+	public static function get_form_fields($input_vars = [], $form_id = false)
61
+	{
62
+
63
+		if (empty($input_vars)) {
64
+			EE_Error::add_error(
65
+				esc_html__('missing required variables for the form field generator', 'event_espresso'),
66
+				__FILE__,
67
+				__FUNCTION__,
68
+				__LINE__
69
+			);
70
+			return false;
71
+		}
72
+
73
+		$output        = "";
74
+		$inputs        = [];
75
+		$hidden_inputs = [];
76
+
77
+		// cycle thru inputs
78
+		foreach ($input_vars as $input_key => $input_value) {
79
+			$defaults = [
80
+				'append_content' => '',
81
+				'css_class'      => '',
82
+				'cols'           => 80,
83
+				'db-col'         => 'column_in_db',
84
+				'format'         => '%d',
85
+				'input'          => 'hidden',
86
+				'label'          => esc_html__('No label', 'event_espresso'),
87
+				'name'           => $input_key,
88
+				'options'        => [],
89
+				'required'       => false,
90
+				'tabindex'       => 0,
91
+				'rows'           => 10,
92
+				'type'           => 'int',
93
+				'validation'     => true,
94
+				'value'          => 'some_value_for_field',
95
+			];
96
+
97
+			$input_value = wp_parse_args($input_value, $defaults);
98
+
99
+			$append_content = $input_value['append_content'];
100
+			$css_class      = $input_value['css_class'];
101
+			$cols           = $input_value['cols'];
102
+			$label          = $input_value['label'];
103
+			$name           = $input_value['name'];
104
+			$options        = $input_value['options'];
105
+			$required       = $input_value['required'];
106
+			$tab_index      = $input_value['tabindex'];
107
+			$rows           = $input_value['rows'];
108
+			$type           = $input_value['input'];
109
+			$value          = $input_value['value'];
110
+
111
+			$id    = $form_id ? $form_id . '-' . $input_key : $input_key;
112
+			$class = $required ? 'required ' . $css_class : $css_class;
113
+
114
+			// what type of input are we dealing with ?
115
+			switch ($type) {
116
+				case 'checkbox':
117
+				case 'radio':
118
+					$field = self::adminMulti($value, $class, $id, $name, $required, $tab_index, $type, 1, $label);
119
+					$field .= $append_content ?: '';
120
+					break;
121
+
122
+				case 'hidden':
123
+					$field           = null;
124
+					$hidden_inputs[] = self::adminHidden($css_class, $id, $name, $value);
125
+					break;
126
+
127
+				case 'select':
128
+					$options = is_array($options) ? $options : explode(',', $options);
129
+					$field   = self::adminLabel($id, $label, $required);
130
+					$field   .= self::adminSelect($value, $class, $id, $name, $required, $tab_index, $options);
131
+					$field   .= $append_content ?: '';
132
+					break;
133
+
134
+				case 'textarea':
135
+					$field = self::adminLabel($id, $label, $required);
136
+					$field .= self::adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value);
137
+					$field .= $append_content ?: '';
138
+					break;
139
+
140
+				case 'wp_editor':
141
+					$label = esc_html($label);
142
+					$field = "<h4>{$label}</h4>";
143
+					$field .= $append_content ?: '';
144
+					$field .= self::adminWpEditor(
145
+						$class,
146
+						$id,
147
+						$name,
148
+						$rows,
149
+						$tab_index,
150
+						$value
151
+					);
152
+					break;
153
+
154
+				default:
155
+					$field = self::adminLabel($id, $label, $required);
156
+					$field .= self::adminText($class, $id, $name, $required, $tab_index, $value);
157
+					$field .= $append_content ?: '';
158
+			}
159
+			if ($field) {
160
+				$inputs[] = $field;
161
+			}
162
+		} // end foreach( $input_vars as $input_key => $input_value )
163
+
164
+		if (! empty($inputs)) {
165
+			$glue   = "
166 166
                 </li>
167 167
                 <li>
168 168
                     ";
169
-            $inputs = implode($glue, $inputs);
170
-            $output = "
169
+			$inputs = implode($glue, $inputs);
170
+			$output = "
171 171
             <ul>
172 172
                 <li>
173 173
                 {$inputs} 
174 174
                 </li>
175 175
             </ul>
176 176
             ";
177
-        }
178
-        return $output . implode("\n", $hidden_inputs);
179
-    }
180
-
181
-
182
-    /**
183
-     * form_fields_array
184
-     * This utility function assembles form fields from a given structured array with field information.
185
-     * //TODO: This is an alternate generator that we may want to use instead.
186
-     *
187
-     * @param array $fields structured array of fields to assemble in the following format:
188
-     *                      [field_name] => array(
189
-     *                      ['label'] => 'label for field',
190
-     *                      ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select
191
-     *                      type of field you can indicated the labels for each option via this index
192
-     *                      ['extra_desc'] => 'extra description for the field', //optional
193
-     *                      ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults
194
-     *                      to text
195
-     *                      ['value'] => 'value that goes in the field', //(if multi then this is an array of values
196
-     *                      and the 'default' paramater will be used for what is selected)
197
-     *                      ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)',
198
-     *                      ['class'] => 'name-of-class(es)-for-input',
199
-     *                      ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi
200
-     *                      select type of field you can indicate the css class for each option via this index.
201
-     *                      ['id'] => 'css-id-for-input') //defaults to 'field_name'
202
-     *                      ['unique_id'] => 1 //defaults to empty string.  This is useful for when the fields
203
-     *                      generated are going to be used in a loop and you want to make sure that the field
204
-     *                      identifiers are unique from each other.
205
-     *                      ['dimensions'] => array(100,300), //defaults to empty array.  This is used by field types
206
-     *                      such as textarea to indicate cols/rows.
207
-     *                      ['tabindex'] => '' //this allows you to set the tabindex for the field.
208
-     *                      ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally
209
-     *                      contain an array of arguments for the editor setup.
210
-     *
211
-     * @return array         an array of inputs for form indexed by field name, and in the following structure:
212
-     *     [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}'
213
-     */
214
-    public static function get_form_fields_array($fields)
215
-    {
216
-
217
-        $form_fields = [];
218
-        $fields      = (array) $fields;
219
-
220
-        foreach ($fields as $field_name => $field_atts) {
221
-            // defaults:
222
-            $defaults = [
223
-                'class'         => '',
224
-                'classes'       => '',
225
-                'default'       => '',
226
-                'dimensions'    => ['10', '5'],
227
-                'extra_desc'    => '',
228
-                'id'            => $field_name,
229
-                'label'         => '',
230
-                'labels'        => '',
231
-                'required'      => false,
232
-                'tabindex'      => 0,
233
-                'type'          => 'text',
234
-                'unique_id'     => '',
235
-                'value'         => '',
236
-                'wpeditor_args' => [],
237
-            ];
238
-            // merge defaults with passed arguments
239
-            $_fields = wp_parse_args($field_atts, $defaults);
240
-
241
-            $class          = $_fields['class'];
242
-            $classes        = $_fields['classes'];
243
-            $default        = $_fields['default'];
244
-            $dims           = $_fields['dimensions'];
245
-            $extra_desc     = $_fields['extra_desc'];
246
-            $id             = $_fields['id'];
247
-            $label          = $_fields['label'];
248
-            $labels         = $_fields['labels'];
249
-            $required       = $_fields['required'];
250
-            $tab_index      = $_fields['tabindex'];
251
-            $type           = $_fields['type'];
252
-            $unique_id      = $_fields['unique_id'];
253
-            $value          = $_fields['value'];
254
-            $wp_editor_args = $_fields['wpeditor_args'];
255
-
256
-            // generate label
257
-            $label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
258
-            // generate field name
259
-            $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
260
-
261
-            // we determine what we're building based on the type
262
-            switch ($type) {
263
-                case 'checkbox':
264
-                case 'radio':
265
-                    if (is_array($value)) {
266
-                        $c_input = '';
267
-                        foreach ($value as $key => $val) {
268
-                            $c_input .= self::adminMulti(
269
-                                $default,
270
-                                isset($classes[ $key ]) ? $classes[ $key ] : '',
271
-                                $field_name . '_' . $value,
272
-                                $name,
273
-                                $required,
274
-                                $tab_index,
275
-                                $type,
276
-                                $val,
277
-                                isset($labels[ $key ]) ? $labels[ $key ] : ''
278
-                            );
279
-                        }
280
-                        $field = $c_input;
281
-                    } else {
282
-                        $field = self::adminMulti(
283
-                            $default,
284
-                            $class,
285
-                            $id,
286
-                            $name,
287
-                            $required,
288
-                            $tab_index,
289
-                            $type,
290
-                            $value,
291
-                            $_fields['label']
292
-                        );
293
-                    }
294
-                    break;
295
-
296
-                case 'hidden':
297
-                    $field = self::adminHidden($class, $id, $name, $value);
298
-                    break;
299
-
300
-                case 'select':
301
-                    $options = [];
302
-                    foreach ($value as $key => $val) {
303
-                        $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
304
-                    }
305
-                    $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
306
-                    break;
307
-
308
-                case 'textarea':
309
-                    $field =
310
-                        self::adminTextarea($class, $dims[0], $id, $name, $required, $dims[1], $tab_index, $value);
311
-                    break;
312
-
313
-                case 'wp_editor':
314
-                    $field = self::adminWpEditor(
315
-                        $class,
316
-                        $_fields['id'],
317
-                        $name,
318
-                        $dims[1],
319
-                        $tab_index,
320
-                        $value,
321
-                        $wp_editor_args
322
-                    );
323
-                    break;
324
-
325
-                default:
326
-                    $field = self::adminText($class, $id, $name, $required, $tab_index, $value);
327
-            }
328
-
329
-            $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
330
-        }
331
-
332
-        return $form_fields;
333
-    }
334
-
335
-
336
-    /**
337
-     * @param string $class
338
-     * @param string $id
339
-     * @param string $name
340
-     * @param string $value
341
-     * @return string
342
-     * @since   4.10.14.p
343
-     */
344
-    private static function adminHidden($class, $id, $name, $value)
345
-    {
346
-        return "
177
+		}
178
+		return $output . implode("\n", $hidden_inputs);
179
+	}
180
+
181
+
182
+	/**
183
+	 * form_fields_array
184
+	 * This utility function assembles form fields from a given structured array with field information.
185
+	 * //TODO: This is an alternate generator that we may want to use instead.
186
+	 *
187
+	 * @param array $fields structured array of fields to assemble in the following format:
188
+	 *                      [field_name] => array(
189
+	 *                      ['label'] => 'label for field',
190
+	 *                      ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select
191
+	 *                      type of field you can indicated the labels for each option via this index
192
+	 *                      ['extra_desc'] => 'extra description for the field', //optional
193
+	 *                      ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults
194
+	 *                      to text
195
+	 *                      ['value'] => 'value that goes in the field', //(if multi then this is an array of values
196
+	 *                      and the 'default' paramater will be used for what is selected)
197
+	 *                      ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)',
198
+	 *                      ['class'] => 'name-of-class(es)-for-input',
199
+	 *                      ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi
200
+	 *                      select type of field you can indicate the css class for each option via this index.
201
+	 *                      ['id'] => 'css-id-for-input') //defaults to 'field_name'
202
+	 *                      ['unique_id'] => 1 //defaults to empty string.  This is useful for when the fields
203
+	 *                      generated are going to be used in a loop and you want to make sure that the field
204
+	 *                      identifiers are unique from each other.
205
+	 *                      ['dimensions'] => array(100,300), //defaults to empty array.  This is used by field types
206
+	 *                      such as textarea to indicate cols/rows.
207
+	 *                      ['tabindex'] => '' //this allows you to set the tabindex for the field.
208
+	 *                      ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally
209
+	 *                      contain an array of arguments for the editor setup.
210
+	 *
211
+	 * @return array         an array of inputs for form indexed by field name, and in the following structure:
212
+	 *     [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}'
213
+	 */
214
+	public static function get_form_fields_array($fields)
215
+	{
216
+
217
+		$form_fields = [];
218
+		$fields      = (array) $fields;
219
+
220
+		foreach ($fields as $field_name => $field_atts) {
221
+			// defaults:
222
+			$defaults = [
223
+				'class'         => '',
224
+				'classes'       => '',
225
+				'default'       => '',
226
+				'dimensions'    => ['10', '5'],
227
+				'extra_desc'    => '',
228
+				'id'            => $field_name,
229
+				'label'         => '',
230
+				'labels'        => '',
231
+				'required'      => false,
232
+				'tabindex'      => 0,
233
+				'type'          => 'text',
234
+				'unique_id'     => '',
235
+				'value'         => '',
236
+				'wpeditor_args' => [],
237
+			];
238
+			// merge defaults with passed arguments
239
+			$_fields = wp_parse_args($field_atts, $defaults);
240
+
241
+			$class          = $_fields['class'];
242
+			$classes        = $_fields['classes'];
243
+			$default        = $_fields['default'];
244
+			$dims           = $_fields['dimensions'];
245
+			$extra_desc     = $_fields['extra_desc'];
246
+			$id             = $_fields['id'];
247
+			$label          = $_fields['label'];
248
+			$labels         = $_fields['labels'];
249
+			$required       = $_fields['required'];
250
+			$tab_index      = $_fields['tabindex'];
251
+			$type           = $_fields['type'];
252
+			$unique_id      = $_fields['unique_id'];
253
+			$value          = $_fields['value'];
254
+			$wp_editor_args = $_fields['wpeditor_args'];
255
+
256
+			// generate label
257
+			$label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
258
+			// generate field name
259
+			$name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
260
+
261
+			// we determine what we're building based on the type
262
+			switch ($type) {
263
+				case 'checkbox':
264
+				case 'radio':
265
+					if (is_array($value)) {
266
+						$c_input = '';
267
+						foreach ($value as $key => $val) {
268
+							$c_input .= self::adminMulti(
269
+								$default,
270
+								isset($classes[ $key ]) ? $classes[ $key ] : '',
271
+								$field_name . '_' . $value,
272
+								$name,
273
+								$required,
274
+								$tab_index,
275
+								$type,
276
+								$val,
277
+								isset($labels[ $key ]) ? $labels[ $key ] : ''
278
+							);
279
+						}
280
+						$field = $c_input;
281
+					} else {
282
+						$field = self::adminMulti(
283
+							$default,
284
+							$class,
285
+							$id,
286
+							$name,
287
+							$required,
288
+							$tab_index,
289
+							$type,
290
+							$value,
291
+							$_fields['label']
292
+						);
293
+					}
294
+					break;
295
+
296
+				case 'hidden':
297
+					$field = self::adminHidden($class, $id, $name, $value);
298
+					break;
299
+
300
+				case 'select':
301
+					$options = [];
302
+					foreach ($value as $key => $val) {
303
+						$options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
304
+					}
305
+					$field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
306
+					break;
307
+
308
+				case 'textarea':
309
+					$field =
310
+						self::adminTextarea($class, $dims[0], $id, $name, $required, $dims[1], $tab_index, $value);
311
+					break;
312
+
313
+				case 'wp_editor':
314
+					$field = self::adminWpEditor(
315
+						$class,
316
+						$_fields['id'],
317
+						$name,
318
+						$dims[1],
319
+						$tab_index,
320
+						$value,
321
+						$wp_editor_args
322
+					);
323
+					break;
324
+
325
+				default:
326
+					$field = self::adminText($class, $id, $name, $required, $tab_index, $value);
327
+			}
328
+
329
+			$form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
330
+		}
331
+
332
+		return $form_fields;
333
+	}
334
+
335
+
336
+	/**
337
+	 * @param string $class
338
+	 * @param string $id
339
+	 * @param string $name
340
+	 * @param string $value
341
+	 * @return string
342
+	 * @since   4.10.14.p
343
+	 */
344
+	private static function adminHidden($class, $id, $name, $value)
345
+	{
346
+		return "
347 347
         <input name='" . esc_attr($name) . "' type='hidden' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' 
348 348
         value='" . esc_attr($value) . "' />";
349
-    }
350
-
351
-
352
-    /**
353
-     * @param string $id
354
-     * @param string $label
355
-     * @param string $required
356
-     * @return string
357
-     * @since   4.10.14.p
358
-     */
359
-    private static function adminLabel($id, $label, $required)
360
-    {
361
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : '';
362
-        return "<label for='" . esc_attr($id) . "'>" . esc_html($label) . $required . "</label>";
363
-    }
364
-
365
-
366
-    /**
367
-     * @param string $default
368
-     * @param string $class
369
-     * @param string $id
370
-     * @param string $name
371
-     * @param string $required
372
-     * @param int    $tab_index
373
-     * @param string $type
374
-     * @param string $value
375
-     * @param string $label
376
-     * @return string
377
-     * @since   4.10.14.p
378
-     */
379
-    private static function adminMulti($default, $class, $id, $name, $required, $tab_index, $type, $value, $label = '')
380
-    {
381
-        $checked   = ! empty($default) && $default == $value ? 'checked ' : '';
382
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
383
-        $input     = "
349
+	}
350
+
351
+
352
+	/**
353
+	 * @param string $id
354
+	 * @param string $label
355
+	 * @param string $required
356
+	 * @return string
357
+	 * @since   4.10.14.p
358
+	 */
359
+	private static function adminLabel($id, $label, $required)
360
+	{
361
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : '';
362
+		return "<label for='" . esc_attr($id) . "'>" . esc_html($label) . $required . "</label>";
363
+	}
364
+
365
+
366
+	/**
367
+	 * @param string $default
368
+	 * @param string $class
369
+	 * @param string $id
370
+	 * @param string $name
371
+	 * @param string $required
372
+	 * @param int    $tab_index
373
+	 * @param string $type
374
+	 * @param string $value
375
+	 * @param string $label
376
+	 * @return string
377
+	 * @since   4.10.14.p
378
+	 */
379
+	private static function adminMulti($default, $class, $id, $name, $required, $tab_index, $type, $value, $label = '')
380
+	{
381
+		$checked   = ! empty($default) && $default == $value ? 'checked ' : '';
382
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
383
+		$input     = "
384 384
         <input name='" . esc_attr($name) . "[]' type='" . esc_attr($type) . "' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' value='" . esc_attr($value) . "' {$checked} {$required} tabindex='" . absint($tab_index) . "'/>";
385
-        if ($label === '') {
386
-            return $input;
387
-        }
388
-        $label = esc_html($label);
389
-        return "
385
+		if ($label === '') {
386
+			return $input;
387
+		}
388
+		$label = esc_html($label);
389
+		return "
390 390
         <label for='$id'>
391 391
             {$input}
392 392
             {$label}
393 393
         </label>";
394
-    }
395
-
396
-
397
-    /**
398
-     * @param string $default
399
-     * @param string $class
400
-     * @param string $id
401
-     * @param string $name
402
-     * @param string $required
403
-     * @param int    $tab_index
404
-     * @param array  $options
405
-     * @return string
406
-     * @since   4.10.14.p
407
-     */
408
-    private static function adminSelect($default, $class, $id, $name, $required, $tab_index, $options = [])
409
-    {
410
-        $options_array = [];
411
-        foreach ($options as $value => $label) {
412
-            $selected        = ! empty($default) && $default == $value ? 'selected' : '';
413
-            $label           = wp_strip_all_tags($label);
414
-            $options_array[] = "<option value='" . esc_attr($value) . "' {$selected}>{$label}</option>";
415
-        }
416
-        $options_html = implode($options_array, "\n");
417
-        $required     = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
418
-        return "
394
+	}
395
+
396
+
397
+	/**
398
+	 * @param string $default
399
+	 * @param string $class
400
+	 * @param string $id
401
+	 * @param string $name
402
+	 * @param string $required
403
+	 * @param int    $tab_index
404
+	 * @param array  $options
405
+	 * @return string
406
+	 * @since   4.10.14.p
407
+	 */
408
+	private static function adminSelect($default, $class, $id, $name, $required, $tab_index, $options = [])
409
+	{
410
+		$options_array = [];
411
+		foreach ($options as $value => $label) {
412
+			$selected        = ! empty($default) && $default == $value ? 'selected' : '';
413
+			$label           = wp_strip_all_tags($label);
414
+			$options_array[] = "<option value='" . esc_attr($value) . "' {$selected}>{$label}</option>";
415
+		}
416
+		$options_html = implode($options_array, "\n");
417
+		$required     = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
418
+		return "
419 419
         <select name='" . esc_attr($name) . "' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' {$required} 
420 420
         tabindex='" . absint($tab_index) . "'>
421 421
             {$options_html}
422 422
         </select>";
423
-    }
424
-
425
-
426
-    /**
427
-     * @param string $class
428
-     * @param string $id
429
-     * @param string $name
430
-     * @param string $required
431
-     * @param int    $tab_index
432
-     * @param string $value
433
-     * @return string
434
-     * @since   4.10.14.p
435
-     */
436
-    private static function adminText($class, $id, $name, $required, $tab_index, $value)
437
-    {
438
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
439
-        return "
423
+	}
424
+
425
+
426
+	/**
427
+	 * @param string $class
428
+	 * @param string $id
429
+	 * @param string $name
430
+	 * @param string $required
431
+	 * @param int    $tab_index
432
+	 * @param string $value
433
+	 * @return string
434
+	 * @since   4.10.14.p
435
+	 */
436
+	private static function adminText($class, $id, $name, $required, $tab_index, $value)
437
+	{
438
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
439
+		return "
440 440
         <input name='" . esc_attr($name) . "' type='text' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' 
441 441
         value='" . esc_attr($value) . "' {$required} tabindex='" . absint($tab_index) . "'/>";
442
-    }
443
-
444
-
445
-    /**
446
-     * @param string $class
447
-     * @param int    $cols
448
-     * @param string $id
449
-     * @param string $name
450
-     * @param string $required
451
-     * @param int    $rows
452
-     * @param int    $tab_index
453
-     * @param string $value
454
-     * @return string
455
-     * @since   4.10.14.p
456
-     */
457
-    private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value)
458
-    {
459
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
460
-        return "
442
+	}
443
+
444
+
445
+	/**
446
+	 * @param string $class
447
+	 * @param int    $cols
448
+	 * @param string $id
449
+	 * @param string $name
450
+	 * @param string $required
451
+	 * @param int    $rows
452
+	 * @param int    $tab_index
453
+	 * @param string $value
454
+	 * @return string
455
+	 * @since   4.10.14.p
456
+	 */
457
+	private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value)
458
+	{
459
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
460
+		return "
461 461
         <textarea name='" . esc_attr($name) . "' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' rows='" . absint($rows) . "' cols='" . absint($cols) . "' {$required} tabindex='" . absint($tab_index) . "'>" . esc_textarea($value) . "</textarea>";
462
-    }
463
-
464
-
465
-    /**
466
-     * @param string $class
467
-     * @param string $id
468
-     * @param string $name
469
-     * @param int    $rows
470
-     * @param int    $tab_index
471
-     * @param string $value
472
-     * @param array  $wp_editor_args
473
-     * @return false|string
474
-     * @since   4.10.14.p
475
-     */
476
-    private static function adminWpEditor($class, $id, $name, $rows, $tab_index, $value, $wp_editor_args = [])
477
-    {
478
-        $editor_settings = $wp_editor_args + [
479
-                'textarea_name' => esc_attr($name),
480
-                'textarea_rows' => absint($rows),
481
-                'editor_class'  => esc_attr($class),
482
-                'tabindex'      => absint($tab_index),
483
-            ];
484
-        ob_start();
485
-        wp_editor($value, esc_attr($id), $editor_settings);
486
-        return ob_get_clean();
487
-    }
488
-
489
-
490
-    /**
491
-     * espresso admin page select_input
492
-     * Turns an array into a select fields
493
-     *
494
-     * @static
495
-     * @access public
496
-     * @param string  $name       field name
497
-     * @param array   $values     option values, numbered array starting at 0, where each value is an array with a key
498
-     *                            'text' (meaning text to display' and 'id' (meaning the internal value) eg:
499
-     *                            array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or
500
-     *                            as an array of key-value pairs, where the key is to be used for the select input's
501
-     *                            name, and the value will be the text shown to the user.  Optionally you can also
502
-     *                            include an additional key of "class" which will add a specific class to the option
503
-     *                            for that value.
504
-     * @param string  $default    default value
505
-     * @param string  $parameters extra parameters
506
-     * @param string  $class      css class
507
-     * @param boolean $autosize   whether to autosize the select or not
508
-     * @return string              html string for the select input
509
-     */
510
-    public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
511
-    {
512
-        // if $values was submitted in the wrong format, convert it over
513
-        if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
514
-            $converted_values = [];
515
-            foreach ($values as $id => $text) {
516
-                $converted_values[] = ['id' => $id, 'text' => $text];
517
-            }
518
-            $values = $converted_values;
519
-        }
520
-
521
-        $field =
522
-            '<select id="' . EEH_Formatter::ee_tep_output_string($name)
523
-            . '" name="' . EEH_Formatter::ee_tep_output_string($name)
524
-            . '"';
525
-
526
-        if (EEH_Formatter::ee_tep_not_null($parameters)) {
527
-            $field .= ' ' . $parameters;
528
-        }
529
-        if ($autosize) {
530
-            $size = 'med';
531
-            for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
532
-                if ($values[ $ii ]['text']) {
533
-                    if (strlen($values[ $ii ]['text']) > 5) {
534
-                        $size = 'wide';
535
-                    }
536
-                }
537
-            }
538
-        } else {
539
-            $size = '';
540
-        }
541
-
542
-        $field .= ' class="' . $class . ' ' . $size . '">';
543
-
544
-        if (empty($default) && isset($GLOBALS[ $name ])) {
545
-            $default = stripslashes($GLOBALS[ $name ]);
546
-        }
547
-
548
-
549
-        for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
550
-            $field .= '<option value="' . $values[ $i ]['id'] . '"';
551
-            if ($default == $values[ $i ]['id']) {
552
-                $field .= ' selected = "selected"';
553
-            }
554
-            if (isset($values[ $i ]['class'])) {
555
-                $field .= ' class="' . $values[ $i ]['class'] . '"';
556
-            }
557
-            $field .= '>' . $values[ $i ]['text'] . '</option>';
558
-        }
559
-        $field .= '</select>';
560
-
561
-        return $field;
562
-    }
563
-
564
-
565
-    /**
566
-     * generate_question_groups_html
567
-     *
568
-     * @param array  $question_groups
569
-     * @param string $group_wrapper
570
-     * @return string HTML
571
-     * @throws EE_Error
572
-     * @throws ReflectionException
573
-     */
574
-    public static function generate_question_groups_html($question_groups = [], $group_wrapper = 'fieldset')
575
-    {
576
-
577
-        $html                            = '';
578
-        $before_question_group_questions =
579
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
580
-        $after_question_group_questions  =
581
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
582
-
583
-        if (! empty($question_groups)) {
584
-            // loop thru question groups
585
-            foreach ($question_groups as $QSG) {
586
-                // check that questions exist
587
-                if (! empty($QSG['QSG_questions'])) {
588
-                    // use fieldsets
589
-                    $html .= "\n\t"
590
-                             . '<'
591
-                             . $group_wrapper
592
-                             . ' class="espresso-question-group-wrap" id="'
593
-                             . $QSG['QSG_identifier']
594
-                             . '">';
595
-                    // group_name
596
-                    $html .= $QSG['QSG_show_group_name']
597
-                        ? "\n\t\t"
598
-                          . '<h5 class="espresso-question-group-title-h5 section-title">'
599
-                          . self::prep_answer($QSG['QSG_name'])
600
-                          . '</h5>'
601
-                        : '';
602
-                    // group_desc
603
-                    $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc'])
604
-                        ? '<div class="espresso-question-group-desc-pg">'
605
-                          . self::prep_answer($QSG['QSG_desc'])
606
-                          . '</div>'
607
-                        : '';
608
-
609
-                    $html .= $before_question_group_questions;
610
-                    // loop thru questions
611
-                    foreach ($QSG['QSG_questions'] as $question) {
612
-                        $QFI  = new EE_Question_Form_Input(
613
-                            $question['qst_obj'],
614
-                            $question['ans_obj'],
615
-                            $question
616
-                        );
617
-                        $html .= self::generate_form_input($QFI);
618
-                    }
619
-                    $html .= $after_question_group_questions;
620
-                    $html .= "\n\t" . '</' . $group_wrapper . '>';
621
-                }
622
-            }
623
-        }
624
-
625
-        return $html;
626
-    }
627
-
628
-
629
-    /**
630
-     * generate_question_groups_html
631
-     *
632
-     * @param array  $question_groups
633
-     * @param array  $q_meta
634
-     * @param bool   $from_admin
635
-     * @param string $group_wrapper
636
-     * @return string HTML
637
-     * @throws EE_Error
638
-     * @throws ReflectionException
639
-     */
640
-    public static function generate_question_groups_html2(
641
-        $question_groups = [],
642
-        $q_meta = [],
643
-        $from_admin = false,
644
-        $group_wrapper = 'fieldset'
645
-    ) {
646
-
647
-        $html                            = '';
648
-        $before_question_group_questions =
649
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
650
-        $after_question_group_questions  =
651
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
652
-
653
-        $default_q_meta = [
654
-            'att_nmbr'    => 1,
655
-            'ticket_id'   => '',
656
-            'input_name'  => '',
657
-            'input_id'    => '',
658
-            'input_class' => '',
659
-        ];
660
-        $q_meta         = array_merge($default_q_meta, $q_meta);
661
-
662
-        if (! empty($question_groups)) {
663
-            // loop thru question groups
664
-            foreach ($question_groups as $QSG) {
665
-                if ($QSG instanceof EE_Question_Group) {
666
-                    // check that questions exist
667
-
668
-                    $where = ['QST_deleted' => 0];
669
-                    if (! $from_admin) {
670
-                        $where['QST_admin_only'] = 0;
671
-                    }
672
-                    $questions =
673
-                        $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
674
-                    if (! empty($questions)) {
675
-                        // use fieldsets
676
-                        $html .= "\n\t"
677
-                                 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
678
-                                 . 'id="' . $QSG->get('QSG_identifier') . '">';
679
-                        // group_name
680
-                        if ($QSG->show_group_name()) {
681
-                            $html .= "\n\t\t"
682
-                                     . '<h5 class="espresso-question-group-title-h5 section-title">'
683
-                                     . $QSG->get_pretty('QSG_name')
684
-                                     . '</h5>';
685
-                        }
686
-                        // group_desc
687
-                        if ($QSG->show_group_desc()) {
688
-                            $html .= '<div class="espresso-question-group-desc-pg">'
689
-                                     . $QSG->get_pretty('QSG_desc')
690
-                                     . '</div>';
691
-                        }
692
-
693
-                        $html .= $before_question_group_questions;
694
-                        // loop thru questions
695
-                        foreach ($questions as $QST) {
696
-                            $qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID();
697
-
698
-                            $answer = null;
699
-
700
-                            /** @var RequestInterface $request */
701
-                            $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
702
-                            $request_qstn = $request->getRequestParam('qstn', [], 'string', true);
703
-                            if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
704
-                                // check for answer in $request_qstn in case we are reprocessing a form after an error
705
-                                if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
706
-                                    $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
707
-                                        ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
708
-                                        : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
709
-                                }
710
-                            } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
711
-                                // attendee data from the session
712
-                                $answer =
713
-                                    isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
714
-                            }
715
-
716
-
717
-                            $QFI  = new EE_Question_Form_Input(
718
-                                $QST,
719
-                                EE_Answer::new_instance(
720
-                                    [
721
-                                        'ANS_ID'    => 0,
722
-                                        'QST_ID'    => 0,
723
-                                        'REG_ID'    => 0,
724
-                                        'ANS_value' => $answer,
725
-                                    ]
726
-                                ),
727
-                                $q_meta
728
-                            );
729
-                            $html .= self::generate_form_input($QFI);
730
-                        }
731
-                        $html .= $after_question_group_questions;
732
-                        $html .= "\n\t" . '</' . $group_wrapper . '>';
733
-                    }
734
-                }
735
-            }
736
-        }
737
-        return $html;
738
-    }
739
-
740
-
741
-    /**
742
-     * generate_form_input
743
-     *
744
-     * @param EE_Question_Form_Input $QFI
745
-     * @return string HTML
746
-     * @throws EE_Error
747
-     * @throws ReflectionException
748
-     */
749
-    public static function generate_form_input(EE_Question_Form_Input $QFI)
750
-    {
751
-        if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) {
752
-            return '';
753
-        }
754
-        /** @var RequestInterface $request */
755
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
756
-
757
-        $QFI = self::_load_system_dropdowns($QFI);
758
-        $QFI = self::_load_specialized_dropdowns($QFI);
759
-
760
-        // we also need to verify
761
-
762
-        $display_text = $QFI->get('QST_display_text');
763
-        $input_name   = $QFI->get('QST_input_name');
764
-        $answer       = $request->getRequestParam($input_name, $QFI->get('ANS_value'));
765
-        $input_id     = $QFI->get('QST_input_id');
766
-        $input_class  = $QFI->get('QST_input_class');
767
-        //      $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : '';
768
-        $disabled          = $QFI->get('QST_disabled');
769
-        $required_label    = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
770
-        $QST_required      = $QFI->get('QST_required');
771
-        $required          =
772
-            $QST_required
773
-                ? ['label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required]
774
-                : [];
775
-        $use_html_entities = $QFI->get_meta('htmlentities');
776
-        $required_text     =
777
-            $QFI->get('QST_required_text') != ''
778
-                ? $QFI->get('QST_required_text')
779
-                : esc_html__('This field is required', 'event_espresso');
780
-        $required_text     = $QST_required
781
-            ? "\n\t\t\t"
782
-              . '<div class="required-text hidden">'
783
-              . self::prep_answer($required_text, $use_html_entities)
784
-              . '</div>'
785
-            : '';
786
-        $label_class       = 'espresso-form-input-lbl';
787
-        $QST_options       = $QFI->options(true, $answer);
788
-        $options           = is_array($QST_options) ? self::prep_answer_options($QST_options) : [];
789
-        $system_ID         = $QFI->get('QST_system');
790
-        $label_b4          = $QFI->get_meta('label_b4');
791
-        $use_desc_4_label  = $QFI->get_meta('use_desc_4_label');
792
-
793
-
794
-        switch ($QFI->get('QST_type')) {
795
-            case 'TEXTAREA':
796
-                return EEH_Form_Fields::textarea(
797
-                    $display_text,
798
-                    $answer,
799
-                    $input_name,
800
-                    $input_id,
801
-                    $input_class,
802
-                    [],
803
-                    $required,
804
-                    $required_text,
805
-                    $label_class,
806
-                    $disabled,
807
-                    $system_ID,
808
-                    $use_html_entities
809
-                );
810
-
811
-            case 'DROPDOWN':
812
-                return EEH_Form_Fields::select(
813
-                    $display_text,
814
-                    $answer,
815
-                    $options,
816
-                    $input_name,
817
-                    $input_id,
818
-                    $input_class,
819
-                    $required,
820
-                    $required_text,
821
-                    $label_class,
822
-                    $disabled,
823
-                    $system_ID,
824
-                    $use_html_entities,
825
-                    true
826
-                );
827
-
828
-
829
-            case 'RADIO_BTN':
830
-                return EEH_Form_Fields::radio(
831
-                    $display_text,
832
-                    $answer,
833
-                    $options,
834
-                    $input_name,
835
-                    $input_id,
836
-                    $input_class,
837
-                    $required,
838
-                    $required_text,
839
-                    $label_class,
840
-                    $disabled,
841
-                    $system_ID,
842
-                    $use_html_entities,
843
-                    $label_b4,
844
-                    $use_desc_4_label
845
-                );
846
-
847
-            case 'CHECKBOX':
848
-                return EEH_Form_Fields::checkbox(
849
-                    $display_text,
850
-                    $answer,
851
-                    $options,
852
-                    $input_name,
853
-                    $input_id,
854
-                    $input_class,
855
-                    $required,
856
-                    $required_text,
857
-                    $label_class,
858
-                    $disabled,
859
-                    $label_b4,
860
-                    $system_ID,
861
-                    $use_html_entities
862
-                );
863
-
864
-            case 'DATE':
865
-                return EEH_Form_Fields::datepicker(
866
-                    $display_text,
867
-                    $answer,
868
-                    $input_name,
869
-                    $input_id,
870
-                    $input_class,
871
-                    $required,
872
-                    $required_text,
873
-                    $label_class,
874
-                    $disabled,
875
-                    $system_ID,
876
-                    $use_html_entities
877
-                );
878
-
879
-            case 'TEXT':
880
-            default:
881
-                return EEH_Form_Fields::text(
882
-                    $display_text,
883
-                    $answer,
884
-                    $input_name,
885
-                    $input_id,
886
-                    $input_class,
887
-                    $required,
888
-                    $required_text,
889
-                    $label_class,
890
-                    $disabled,
891
-                    $system_ID,
892
-                    $use_html_entities
893
-                );
894
-        }
895
-    }
896
-
897
-
898
-    /**
899
-     * generates HTML for a form text input
900
-     *
901
-     * @param string $question    label content
902
-     * @param string $answer      form input value attribute
903
-     * @param string $name        form input name attribute
904
-     * @param string $id          form input css id attribute
905
-     * @param string $class       form input css class attribute
906
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
907
-     *                            required 'class', and required 'msg' attribute
908
-     * @param string $label_class css class attribute for the label
909
-     * @param string $disabled    disabled="disabled" or null
910
-     * @return string HTML
911
-     */
912
-    public static function text(
913
-        $question = false,
914
-        $answer = null,
915
-        $name = false,
916
-        $id = '',
917
-        $class = '',
918
-        $required = false,
919
-        $required_text = '',
920
-        $label_class = '',
921
-        $disabled = false,
922
-        $system_ID = false,
923
-        $use_html_entities = true
924
-    ) {
925
-        // need these
926
-        if (! $question || ! $name) {
927
-            return null;
928
-        }
929
-        // prep the answer
930
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
931
-        // prep the required array
932
-        $required = self::prep_required($required);
933
-        // set disabled tag
934
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
935
-        // ya gots ta have style man!!!
936
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
937
-        $class     = empty($class) ? $txt_class : $class;
938
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
939
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
940
-
941
-        $label_html =
942
-            $required_text
943
-            . "\n\t\t\t"
944
-            . '<label for="' . $name . '" class="' . $label_class . '">'
945
-            . self::prep_question($question)
946
-            . $required['label']
947
-            . '</label><br/>';
948
-        // filter label but ensure required text comes before it
949
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
950
-
951
-        $input_html =
952
-            "\n\t\t\t"
953
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
954
-            . 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  '
955
-            . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
956
-
957
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
958
-        return $label_html . $input_html;
959
-    }
960
-
961
-
962
-    /**
963
-     * generates HTML for a form textarea
964
-     *
965
-     * @param string $question    label content
966
-     * @param string $answer      form input value attribute
967
-     * @param string $name        form input name attribute
968
-     * @param string $id          form input css id attribute
969
-     * @param string $class       form input css class attribute
970
-     * @param array  $dimensions  array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 )
971
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
972
-     *                            required 'class', and required 'msg' attribute
973
-     * @param string $label_class css class attribute for the label
974
-     * @param string $disabled    disabled="disabled" or null
975
-     * @return string HTML
976
-     */
977
-    public static function textarea(
978
-        $question = false,
979
-        $answer = null,
980
-        $name = false,
981
-        $id = '',
982
-        $class = '',
983
-        $dimensions = false,
984
-        $required = false,
985
-        $required_text = '',
986
-        $label_class = '',
987
-        $disabled = false,
988
-        $system_ID = false,
989
-        $use_html_entities = true
990
-    ) {
991
-        // need these
992
-        if (! $question || ! $name) {
993
-            return null;
994
-        }
995
-        // prep the answer
996
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
997
-        // prep the required array
998
-        $required = self::prep_required($required);
999
-        // make sure $dimensions is an array
1000
-        $dimensions = is_array($dimensions) ? $dimensions : [];
1001
-        // and set some defaults
1002
-        $dimensions = array_merge(['rows' => 3, 'cols' => 40], $dimensions);
1003
-        // set disabled tag
1004
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1005
-        // ya gots ta have style man!!!
1006
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
1007
-        $class     = empty($class) ? $txt_class : $class;
1008
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1009
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1010
-
1011
-        $label_html =
1012
-            $required_text
1013
-            . "\n\t\t\t"
1014
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1015
-            . self::prep_question($question)
1016
-            . $required['label']
1017
-            . '</label><br/>';
1018
-        // filter label but ensure required text comes before it
1019
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1020
-
1021
-        $input_html =
1022
-            "\n\t\t\t"
1023
-            . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1024
-            . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1025
-            . 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1026
-            . esc_textarea($answer)
1027
-            . '</textarea>';
1028
-
1029
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1030
-        return $label_html . $input_html;
1031
-    }
1032
-
1033
-
1034
-    /**
1035
-     * generates HTML for a form select input
1036
-     *
1037
-     * @param string $question    label content
1038
-     * @param string $answer      form input value attribute
1039
-     * @param array  $options     array of answer options where array key = option value and array value = option
1040
-     *                            display text
1041
-     * @param string $name        form input name attribute
1042
-     * @param string $id          form input css id attribute
1043
-     * @param string $class       form input css class attribute
1044
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1045
-     *                            required 'class', and required 'msg' attribute
1046
-     * @param string $label_class css class attribute for the label
1047
-     * @param string $disabled    disabled="disabled" or null
1048
-     * @return string HTML
1049
-     */
1050
-    public static function select(
1051
-        $question = false,
1052
-        $answer = null,
1053
-        $options = false,
1054
-        $name = false,
1055
-        $id = '',
1056
-        $class = '',
1057
-        $required = false,
1058
-        $required_text = '',
1059
-        $label_class = '',
1060
-        $disabled = false,
1061
-        $system_ID = false,
1062
-        $use_html_entities = true,
1063
-        $add_please_select_option = false
1064
-    ) {
1065
-
1066
-        // need these
1067
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1068
-            return null;
1069
-        }
1070
-        // prep the answer
1071
-        $answer =
1072
-            is_array($answer)
1073
-                ? self::prep_answer(array_shift($answer), $use_html_entities)
1074
-                : self::prep_answer(
1075
-                    $answer,
1076
-                    $use_html_entities
1077
-                );
1078
-        // prep the required array
1079
-        $required = self::prep_required($required);
1080
-        // set disabled tag
1081
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1082
-        // ya gots ta have style man!!!
1083
-        $txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
1084
-        $class     = empty($class) ? $txt_class : $class;
1085
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1086
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1087
-
1088
-        $label_html =
1089
-            $required_text
1090
-            . "\n\t\t\t"
1091
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1092
-            . self::prep_question($question)
1093
-            . $required['label']
1094
-            . '</label><br/>';
1095
-        // filter label but ensure required text comes before it
1096
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1097
-
1098
-        $input_html =
1099
-            "\n\t\t\t"
1100
-            . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1101
-            . 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1102
-        // recursively count array elements, to determine total number of options
1103
-        $only_option = count($options, 1) == 1;
1104
-        if (! $only_option) {
1105
-            // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1106
-            $selected   = $answer === null ? ' selected' : '';
1107
-            $input_html .= $add_please_select_option
1108
-                ? "\n\t\t\t\t"
1109
-                  . '<option value=""' . $selected . '>'
1110
-                  . esc_html__(' - please select - ', 'event_espresso')
1111
-                  . '</option>'
1112
-                : '';
1113
-        }
1114
-        foreach ($options as $key => $value) {
1115
-            // if value is an array, then create option groups, else create regular ol' options
1116
-            $input_html .= is_array($value)
1117
-                ? self::_generate_select_option_group(
1118
-                    $key,
1119
-                    $value,
1120
-                    $answer,
1121
-                    $use_html_entities
1122
-                )
1123
-                : self::_generate_select_option(
1124
-                    $value->value(),
1125
-                    $value->desc(),
1126
-                    $answer,
1127
-                    $only_option,
1128
-                    $use_html_entities
1129
-                );
1130
-        }
1131
-
1132
-        $input_html .= "\n\t\t\t" . '</select>';
1133
-
1134
-        $input_html =
1135
-            apply_filters(
1136
-                'FHEE__EEH_Form_Fields__select__before_end_wrapper',
1137
-                $input_html,
1138
-                $question,
1139
-                $answer,
1140
-                $name,
1141
-                $id,
1142
-                $class,
1143
-                $system_ID
1144
-            );
1145
-
1146
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1147
-        return $label_html . $input_html;
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     *  _generate_select_option_group
1153
-     *
1154
-     *  if  $value for a select box is an array, then the key will be used as the optgroup label
1155
-     *  and the value array will be looped thru and the elements sent to _generate_select_option
1156
-     *
1157
-     * @param mixed   $opt_group
1158
-     * @param mixed   $QSOs
1159
-     * @param mixed   $answer
1160
-     * @param boolean $use_html_entities
1161
-     * @return string
1162
-     */
1163
-    private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1164
-    {
1165
-        $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1166
-        foreach ($QSOs as $QSO) {
1167
-            $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1168
-        }
1169
-        $html .= "\n\t\t\t\t" . '</optgroup>';
1170
-        return $html;
1171
-    }
1172
-
1173
-
1174
-    /**
1175
-     *  _generate_select_option
1176
-     *
1177
-     * @param mixed   $key
1178
-     * @param mixed   $value
1179
-     * @param mixed   $answer
1180
-     * @param int     $only_option
1181
-     * @param boolean $use_html_entities
1182
-     * @return string
1183
-     */
1184
-    private static function _generate_select_option(
1185
-        $key,
1186
-        $value,
1187
-        $answer,
1188
-        $only_option = false,
1189
-        $use_html_entities = true
1190
-    ) {
1191
-        $key      = self::prep_answer($key, $use_html_entities);
1192
-        $value    = self::prep_answer($value, $use_html_entities);
1193
-        $value    = ! empty($value) ? $value : $key;
1194
-        $selected = ($answer == $key || $only_option) ? 'selected' : '';
1195
-        return "\n\t\t\t\t"
1196
-               . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1197
-               . $value
1198
-               . '&nbsp;&nbsp;&nbsp;</option>';
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * generates HTML for form radio button inputs
1204
-     *
1205
-     * @param bool|string $question    label content
1206
-     * @param string      $answer      form input value attribute
1207
-     * @param array|bool  $options     array of answer options where array key = option value and array value = option
1208
-     *                                 display text
1209
-     * @param bool|string $name        form input name attribute
1210
-     * @param string      $id          form input css id attribute
1211
-     * @param string      $class       form input css class attribute
1212
-     * @param array|bool  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1213
-     *                                 required 'class', and required 'msg' attribute
1214
-     * @param string      $required_text
1215
-     * @param string      $label_class css class attribute for the label
1216
-     * @param bool|string $disabled    disabled="disabled" or null
1217
-     * @param bool        $system_ID
1218
-     * @param bool        $use_html_entities
1219
-     * @param bool        $label_b4
1220
-     * @param bool        $use_desc_4_label
1221
-     * @return string HTML
1222
-     */
1223
-    public static function radio(
1224
-        $question = false,
1225
-        $answer = null,
1226
-        $options = false,
1227
-        $name = false,
1228
-        $id = '',
1229
-        $class = '',
1230
-        $required = false,
1231
-        $required_text = '',
1232
-        $label_class = '',
1233
-        $disabled = false,
1234
-        $system_ID = false,
1235
-        $use_html_entities = true,
1236
-        $label_b4 = false,
1237
-        $use_desc_4_label = false
1238
-    ) {
1239
-        // need these
1240
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1241
-            return null;
1242
-        }
1243
-        // prep the answer
1244
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1245
-        // prep the required array
1246
-        $required = self::prep_required($required);
1247
-        // set disabled tag
1248
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1249
-        // ya gots ta have style man!!!
1250
-        $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1251
-        $class       = ! empty($class) ? $class : 'espresso-radio-btn-inp';
1252
-        $extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1253
-
1254
-        $label_html =
1255
-            $required_text
1256
-            . "\n\t\t\t"
1257
-            . '<label class="' . $label_class . '">'
1258
-            . self::prep_question($question)
1259
-            . $required['label']
1260
-            . '</label> ';
1261
-        // filter label but ensure required text comes before it
1262
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1263
-
1264
-        $input_html =
1265
-            "\n\t\t\t"
1266
-            . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
1267
-
1268
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1269
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1270
-
1271
-        foreach ($options as $OPT) {
1272
-            if ($OPT instanceof EE_Question_Option) {
1273
-                $value   = self::prep_option_value($OPT->value());
1274
-                $label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1275
-                $size    = $use_desc_4_label
1276
-                    ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1277
-                    : self::get_label_size_class($OPT->value());
1278
-                $desc    = $OPT->desc();// no self::prep_answer
1279
-                $answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1280
-                $checked = (string) $value == (string) $answer ? ' checked' : '';
1281
-                $opt     = '-' . sanitize_key($value);
1282
-
1283
-                $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1284
-                $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1285
-                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
1286
-                $input_html .= "\n\t\t\t\t\t\t"
1287
-                               . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1288
-                               . 'class="' . $class . '" value="' . $value . '" '
1289
-                               . 'title="' . esc_attr($required['msg']) . '" ' . $disabled
1290
-                               . $checked . ' ' . $extra . '/>';
1291
-                $input_html .= ! $label_b4
1292
-                    ? "\n\t\t\t\t\t\t"
1293
-                      . '<span class="espresso-radio-btn-desc">'
1294
-                      . $label
1295
-                      . '</span>'
1296
-                    : '';
1297
-                $input_html .= "\n\t\t\t\t\t" . '</label>';
1298
-                $input_html .= $use_desc_4_label
1299
-                    ? ''
1300
-                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1301
-                $input_html .= "\n\t\t\t\t" . '</li>';
1302
-            }
1303
-        }
1304
-
1305
-        $input_html .= "\n\t\t\t" . '</ul>';
1306
-
1307
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1308
-        return $label_html . $input_html;
1309
-    }
1310
-
1311
-
1312
-    /**
1313
-     * generates HTML for form checkbox inputs
1314
-     *
1315
-     * @param string $question    label content
1316
-     * @param string $answer      form input value attribute
1317
-     * @param array  $options     array of options where array key = option value and array value = option display text
1318
-     * @param string $name        form input name attribute
1319
-     * @param string $id          form input css id attribute
1320
-     * @param string $class       form input css class attribute
1321
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1322
-     *                            required 'class', and required 'msg' attribute
1323
-     * @param string $label_class css class attribute for the label
1324
-     * @param string $disabled    disabled="disabled" or null
1325
-     * @return string HTML
1326
-     */
1327
-    public static function checkbox(
1328
-        $question = false,
1329
-        $answer = null,
1330
-        $options = false,
1331
-        $name = false,
1332
-        $id = '',
1333
-        $class = '',
1334
-        $required = false,
1335
-        $required_text = '',
1336
-        $label_class = '',
1337
-        $disabled = false,
1338
-        $label_b4 = false,
1339
-        $system_ID = false,
1340
-        $use_html_entities = true
1341
-    ) {
1342
-        // need these
1343
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1344
-            return null;
1345
-        }
1346
-        $answer = maybe_unserialize($answer);
1347
-
1348
-        // prep the answer(s)
1349
-        $answer = is_array($answer) ? $answer : [sanitize_key($answer) => $answer];
1350
-
1351
-        foreach ($answer as $key => $value) {
1352
-            $key            = self::prep_option_value($key);
1353
-            $answer[ $key ] = self::prep_answer($value, $use_html_entities);
1354
-        }
1355
-
1356
-        // prep the required array
1357
-        $required = self::prep_required($required);
1358
-        // set disabled tag
1359
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1360
-        // ya gots ta have style man!!!
1361
-        $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1362
-        $class       = empty($class) ? 'espresso-radio-btn-inp' : $class;
1363
-        $extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1364
-
1365
-        $label_html =
1366
-            $required_text
1367
-            . "\n\t\t\t"
1368
-            . '<label class="' . $label_class . '">'
1369
-            . self::prep_question($question)
1370
-            . $required['label']
1371
-            . '</label> ';
1372
-        // filter label but ensure required text comes before it
1373
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1374
-
1375
-        $input_html =
1376
-            "\n\t\t\t"
1377
-            . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
1378
-
1379
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1380
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1381
-
1382
-        foreach ($options as $OPT) {
1383
-            $value = $OPT->value();// self::prep_option_value( $OPT->value() );
1384
-            $size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1385
-            $text  = self::prep_answer($OPT->value());
1386
-            $desc  = $OPT->desc();
1387
-            $opt   = '-' . sanitize_key($value);
1388
-
1389
-            $checked = is_array($answer) && in_array($text, $answer) ? ' checked' : '';
1390
-
1391
-            $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1392
-            $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1393
-            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1394
-            $input_html .= "\n\t\t\t\t\t\t"
1395
-                           . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1396
-                           . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1397
-                           . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1398
-            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1399
-            $input_html .= "\n\t\t\t\t\t" . '</label>';
1400
-            if (! empty($desc) && $desc != $text) {
1401
-                $input_html .= "\n\t\t\t\t\t"
1402
-                               . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1403
-                               . $desc
1404
-                               . '</div>';
1405
-            }
1406
-            $input_html .= "\n\t\t\t\t" . '</li>';
1407
-        }
1408
-
1409
-        $input_html .= "\n\t\t\t" . '</ul>';
1410
-
1411
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1412
-        return $label_html . $input_html;
1413
-    }
1414
-
1415
-
1416
-    /**
1417
-     * generates HTML for a form datepicker input
1418
-     *
1419
-     * @param string $question    label content
1420
-     * @param string $answer      form input value attribute
1421
-     * @param string $name        form input name attribute
1422
-     * @param string $id          form input css id attribute
1423
-     * @param string $class       form input css class attribute
1424
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1425
-     *                            required 'class', and required 'msg' attribute
1426
-     * @param string $label_class css class attribute for the label
1427
-     * @param string $disabled    disabled="disabled" or null
1428
-     * @return string HTML
1429
-     */
1430
-    public static function datepicker(
1431
-        $question = false,
1432
-        $answer = null,
1433
-        $name = false,
1434
-        $id = '',
1435
-        $class = '',
1436
-        $required = false,
1437
-        $required_text = '',
1438
-        $label_class = '',
1439
-        $disabled = false,
1440
-        $system_ID = false,
1441
-        $use_html_entities = true
1442
-    ) {
1443
-        // need these
1444
-        if (! $question || ! $name) {
1445
-            return null;
1446
-        }
1447
-        // prep the answer
1448
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1449
-        // prep the required array
1450
-        $required = self::prep_required($required);
1451
-        // set disabled tag
1452
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1453
-        // ya gots ta have style man!!!
1454
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1455
-        $class     = empty($class) ? $txt_class : $class;
1456
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1457
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1458
-
1459
-        $label_html =
1460
-            $required_text
1461
-            . "\n\t\t\t"
1462
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1463
-            . self::prep_question($question)
1464
-            . $required['label']
1465
-            . '</label><br/>';
1466
-        // filter label but ensure required text comes before it
1467
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1468
-
1469
-        $input_html =
1470
-            "\n\t\t\t"
1471
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
1472
-            . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1473
-            . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1474
-
1475
-        // enqueue scripts
1476
-        wp_register_style(
1477
-            'espresso-ui-theme',
1478
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1479
-            [],
1480
-            EVENT_ESPRESSO_VERSION
1481
-        );
1482
-        wp_enqueue_style('espresso-ui-theme');
1483
-        wp_enqueue_script('jquery-ui-datepicker');
1484
-
1485
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1486
-        return $label_html . $input_html;
1487
-    }
1488
-
1489
-
1490
-    /**
1491
-     *  remove_label_keep_required_msg
1492
-     *  this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label
1493
-     *
1494
-     * @access public
1495
-     * @return     string
1496
-     */
1497
-    public static function remove_label_keep_required_msg($label_html, $required_text)
1498
-    {
1499
-        return $required_text;
1500
-    }
1501
-
1502
-
1503
-    /**
1504
-     * Simply returns the HTML for a hidden input of the given name and value.
1505
-     *
1506
-     * @param string $name
1507
-     * @param string $value
1508
-     * @return string HTML
1509
-     */
1510
-    public static function hidden_input($name, $value, $id = '')
1511
-    {
1512
-        $id = ! empty($id) ? $id : $name;
1513
-        return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * prep_question
1519
-     *
1520
-     * @param string $question
1521
-     * @return string
1522
-     */
1523
-    public static function prep_question($question)
1524
-    {
1525
-        return $question;
1526
-    }
1527
-
1528
-
1529
-    /**
1530
-     *  prep_answer
1531
-     *
1532
-     * @param mixed $answer
1533
-     * @return string
1534
-     */
1535
-    public static function prep_answer($answer, $use_html_entities = true)
1536
-    {
1537
-        // make sure we convert bools first.  Otherwise (bool) false becomes an empty string which is NOT desired,
1538
-        // we want "0".
1539
-        if (is_bool($answer)) {
1540
-            $answer = $answer ? 1 : 0;
1541
-        }
1542
-        $answer = trim(stripslashes(str_replace('&#039;', "'", $answer)));
1543
-        return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer;
1544
-    }
1545
-
1546
-
1547
-    /**
1548
-     *  prep_answer_options
1549
-     *
1550
-     * @param array $QSOs array of EE_Question_Option objects
1551
-     * @return array
1552
-     */
1553
-    public static function prep_answer_options($QSOs = [])
1554
-    {
1555
-        $prepped_answer_options = [];
1556
-        if (is_array($QSOs) && ! empty($QSOs)) {
1557
-            foreach ($QSOs as $key => $QSO) {
1558
-                if (! $QSO instanceof EE_Question_Option) {
1559
-                    $QSO = EE_Question_Option::new_instance(
1560
-                        [
1561
-                            'QSO_value' => is_array($QSO) && isset($QSO['id'])
1562
-                                ? (string) $QSO['id']
1563
-                                : (string) $key,
1564
-                            'QSO_desc'  => is_array($QSO) && isset($QSO['text'])
1565
-                                ? (string) $QSO['text']
1566
-                                : (string) $QSO,
1567
-                        ]
1568
-                    );
1569
-                }
1570
-                if ($QSO->opt_group()) {
1571
-                    $prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1572
-                } else {
1573
-                    $prepped_answer_options[] = $QSO;
1574
-                }
1575
-            }
1576
-        }
1577
-        //      d( $prepped_answer_options );
1578
-        return $prepped_answer_options;
1579
-    }
1580
-
1581
-
1582
-    /**
1583
-     *  prep_option_value
1584
-     *
1585
-     * @param string $option_value
1586
-     * @return string
1587
-     */
1588
-    public static function prep_option_value($option_value)
1589
-    {
1590
-        return esc_attr(trim(stripslashes($option_value)));
1591
-    }
1592
-
1593
-
1594
-    /**
1595
-     *  prep_required
1596
-     *
1597
-     * @param string|array $required
1598
-     * @return array
1599
-     */
1600
-    public static function prep_required($required = [])
1601
-    {
1602
-        // make sure required is an array
1603
-        $required = is_array($required) ? $required : [];
1604
-        // and set some defaults
1605
-        return array_merge(['label' => '', 'class' => '', 'msg' => ''], $required);
1606
-    }
1607
-
1608
-
1609
-    /**
1610
-     *  get_label_size_class
1611
-     *
1612
-     * @param string $value
1613
-     * @return string
1614
-     */
1615
-    public static function get_label_size_class($value = false)
1616
-    {
1617
-        if ($value === false || $value === '') {
1618
-            return ' class="medium-lbl"';
1619
-        }
1620
-        // determine length of option value
1621
-        $val_size = strlen($value);
1622
-        switch ($val_size) {
1623
-            case $val_size < 3:
1624
-                $size = ' class="nano-lbl"';
1625
-                break;
1626
-            case $val_size < 6:
1627
-                $size = ' class="micro-lbl"';
1628
-                break;
1629
-            case $val_size < 12:
1630
-                $size = ' class="tiny-lbl"';
1631
-                break;
1632
-            case $val_size < 25:
1633
-                $size = ' class="small-lbl"';
1634
-                break;
1635
-            case $val_size > 100:
1636
-                $size = ' class="big-lbl"';
1637
-                break;
1638
-            default:
1639
-                $size = ' class="medium-lbl"';
1640
-                break;
1641
-        }
1642
-        return $size;
1643
-    }
1644
-
1645
-
1646
-    /**
1647
-     *  _load_system_dropdowns
1648
-     *
1649
-     * @param EE_Question_Form_Input $QFI
1650
-     * @return array
1651
-     * @throws EE_Error
1652
-     * @throws ReflectionException
1653
-     */
1654
-    private static function _load_system_dropdowns($QFI)
1655
-    {
1656
-        $QST_system = $QFI->get('QST_system');
1657
-        switch ($QST_system) {
1658
-            case 'state':
1659
-                $QFI = self::generate_state_dropdown($QFI);
1660
-                break;
1661
-            case 'country':
1662
-                $QFI = self::generate_country_dropdown($QFI);
1663
-                break;
1664
-            case 'admin-state':
1665
-                $QFI = self::generate_state_dropdown($QFI, true);
1666
-                break;
1667
-            case 'admin-country':
1668
-                $QFI = self::generate_country_dropdown($QFI, true);
1669
-                break;
1670
-        }
1671
-        return $QFI;
1672
-    }
1673
-
1674
-
1675
-    /**
1676
-     * This preps dropdowns that are specialized.
1677
-     *
1678
-     * @param EE_Question_Form_Input $QFI
1679
-     *
1680
-     * @return EE_Question_Form_Input
1681
-     * @throws EE_Error
1682
-     * @throws ReflectionException
1683
-     * @since  4.6.0
1684
-     */
1685
-    protected static function _load_specialized_dropdowns($QFI)
1686
-    {
1687
-        switch ($QFI->get('QST_type')) {
1688
-            case 'STATE':
1689
-                $QFI = self::generate_state_dropdown($QFI);
1690
-                break;
1691
-            case 'COUNTRY':
1692
-                $QFI = self::generate_country_dropdown($QFI);
1693
-                break;
1694
-        }
1695
-        return $QFI;
1696
-    }
1697
-
1698
-
1699
-    /**
1700
-     *    generate_state_dropdown
1701
-     *
1702
-     * @param EE_Question_Form_Input $QST
1703
-     * @param bool                   $get_all
1704
-     * @return EE_Question_Form_Input
1705
-     * @throws EE_Error
1706
-     * @throws ReflectionException
1707
-     */
1708
-    public static function generate_state_dropdown($QST, $get_all = false)
1709
-    {
1710
-        $states = $get_all
1711
-            ? EEM_State::instance()->get_all_states()
1712
-            : EEM_State::instance()->get_all_states_of_active_countries();
1713
-        if ($states && count($states) != count($QST->options())) {
1714
-            $QST->set('QST_type', 'DROPDOWN');
1715
-            // if multiple countries, we'll create option groups within the dropdown
1716
-            foreach ($states as $state) {
1717
-                if ($state instanceof EE_State) {
1718
-                    $QSO = EE_Question_Option::new_instance(
1719
-                        [
1720
-                            'QSO_value'   => $state->ID(),
1721
-                            'QSO_desc'    => $state->name(),
1722
-                            'QST_ID'      => $QST->get('QST_ID'),
1723
-                            'QSO_deleted' => false,
1724
-                        ]
1725
-                    );
1726
-                    // set option group
1727
-                    $QSO->set_opt_group($state->country()->name());
1728
-                    // add option to question
1729
-                    $QST->add_temp_option($QSO);
1730
-                }
1731
-            }
1732
-        }
1733
-        return $QST;
1734
-    }
1735
-
1736
-
1737
-    /**
1738
-     *    generate_country_dropdown
1739
-     *
1740
-     * @param      $QST
1741
-     * @param bool $get_all
1742
-     * @return array
1743
-     * @throws EE_Error
1744
-     * @throws ReflectionException
1745
-     * @internal param array $question
1746
-     */
1747
-    public static function generate_country_dropdown($QST, $get_all = false)
1748
-    {
1749
-        $countries = $get_all
1750
-            ? EEM_Country::instance()->get_all_countries()
1751
-            : EEM_Country::instance()->get_all_active_countries();
1752
-        if ($countries && count($countries) != count($QST->options())) {
1753
-            $QST->set('QST_type', 'DROPDOWN');
1754
-            // now add countries
1755
-            foreach ($countries as $country) {
1756
-                if ($country instanceof EE_Country) {
1757
-                    $QSO = EE_Question_Option::new_instance(
1758
-                        [
1759
-                            'QSO_value'   => $country->ID(),
1760
-                            'QSO_desc'    => $country->name(),
1761
-                            'QST_ID'      => $QST->get('QST_ID'),
1762
-                            'QSO_deleted' => false,
1763
-                        ]
1764
-                    );
1765
-                    $QST->add_temp_option($QSO);
1766
-                }
1767
-            }
1768
-        }
1769
-        return $QST;
1770
-    }
1771
-
1772
-
1773
-    /**
1774
-     *  generates options for a month dropdown selector with numbers from 01 to 12
1775
-     *
1776
-     * @return array()
1777
-     */
1778
-    public static function two_digit_months_dropdown_options()
1779
-    {
1780
-        $options = [];
1781
-        for ($x = 1; $x <= 12; $x++) {
1782
-            $mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1783
-            $options[ $mm ] = $mm;
1784
-        }
1785
-        return EEH_Form_Fields::prep_answer_options($options);
1786
-    }
1787
-
1788
-
1789
-    /**
1790
-     *  generates a year dropdown selector with numbers for the next ten years
1791
-     *
1792
-     * @return array
1793
-     */
1794
-    public static function next_decade_two_digit_year_dropdown_options()
1795
-    {
1796
-        $options      = [];
1797
-        $current_year = date('y');
1798
-        $next_decade  = $current_year + 10;
1799
-        for ($x = $current_year; $x <= $next_decade; $x++) {
1800
-            $yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1801
-            $options[ $yy ] = $yy;
1802
-        }
1803
-        return EEH_Form_Fields::prep_answer_options($options);
1804
-    }
1805
-
1806
-
1807
-    /**
1808
-     * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for
1809
-     * list table filter.
1810
-     *
1811
-     * @param string  $cur_date     any currently selected date can be entered here.
1812
-     * @param string  $status       Registration status
1813
-     * @param integer $evt_category Event Category ID if the Event Category filter is selected
1814
-     * @return string                html
1815
-     * @throws EE_Error
1816
-     */
1817
-    public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1818
-    {
1819
-        $_where = [];
1820
-        if (! empty($status)) {
1821
-            $_where['STS_ID'] = $status;
1822
-        }
1823
-
1824
-        if ($evt_category > 0) {
1825
-            $_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1826
-        }
1827
-
1828
-        $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1829
-
1830
-        // setup vals for select input helper
1831
-        $options = [
1832
-            0 => [
1833
-                'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1834
-                'id'   => '',
1835
-            ],
1836
-        ];
1837
-
1838
-        foreach ($regdtts as $regdtt) {
1839
-            $date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1840
-            $options[] = [
1841
-                'text' => $date,
1842
-                'id'   => $date,
1843
-            ];
1844
-        }
1845
-
1846
-        return self::select_input('month_range', $options, $cur_date, '', 'wide');
1847
-    }
1848
-
1849
-
1850
-    /**
1851
-     * generates a month/year dropdown selector for all events matching the given criteria
1852
-     * Typically used for list table filter
1853
-     *
1854
-     * @param string $cur_date          any currently selected date can be entered here.
1855
-     * @param string $status            "view" (i.e. all, today, month, draft)
1856
-     * @param int    $evt_category      category event belongs to
1857
-     * @param string $evt_active_status "upcoming", "expired", "active", or "inactive"
1858
-     * @return string                    html
1859
-     * @throws EE_Error
1860
-     */
1861
-    public static function generate_event_months_dropdown(
1862
-        $cur_date = '',
1863
-        $status = null,
1864
-        $evt_category = null,
1865
-        $evt_active_status = null
1866
-    ) {
1867
-        // determine what post_status our condition will have for the query.
1868
-        // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1869
-        switch ($status) {
1870
-            case 'month':
1871
-            case 'today':
1872
-            case null:
1873
-            case 'all':
1874
-                $where['Event.status'] = ['NOT IN', ['trash']];
1875
-                break;
1876
-            case 'draft':
1877
-                $where['Event.status'] = ['IN', ['draft', 'auto-draft']];
1878
-                break;
1879
-            default:
1880
-                $where['Event.status'] = $status;
1881
-        }
1882
-
1883
-        // phpcs:enable
1884
-
1885
-        // categories?
1886
-
1887
-
1888
-        if (! empty($evt_category)) {
1889
-            $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1890
-            $where['Event.Term_Taxonomy.term_id']  = $evt_category;
1891
-        }
1892
-
1893
-
1894
-        //      $where['DTT_is_primary'] = 1;
1895
-
1896
-        $DTTS = EEM_Datetime::instance()->get_dtt_months_and_years($where, $evt_active_status);
1897
-
1898
-        // let's setup vals for select input helper
1899
-        $options = [
1900
-            0 => [
1901
-                'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1902
-                'id'   => "",
1903
-            ],
1904
-        ];
1905
-
1906
-
1907
-        // translate month and date
1908
-        global $wp_locale;
1909
-
1910
-        foreach ($DTTS as $DTT) {
1911
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1912
-            $id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1913
-            $options[]      = [
1914
-                'text' => $localized_date,
1915
-                'id'   => $id,
1916
-            ];
1917
-        }
1918
-
1919
-
1920
-        return self::select_input('month_range', $options, $cur_date, '', 'wide');
1921
-    }
1922
-
1923
-
1924
-    /**
1925
-     * generates the dropdown selector for event categories
1926
-     * typically used as a filter on list tables.
1927
-     *
1928
-     * @param integer $current_cat currently selected category
1929
-     * @return string               html for dropdown
1930
-     * @throws EE_Error
1931
-     * @throws ReflectionException
1932
-     */
1933
-    public static function generate_event_category_dropdown($current_cat = -1)
1934
-    {
1935
-        $categories = EEM_Term::instance()->get_all_ee_categories(true);
1936
-        $options    = [
1937
-            '0' => [
1938
-                'text' => esc_html__('All Categories', 'event_espresso'),
1939
-                'id'   => -1,
1940
-            ],
1941
-        ];
1942
-
1943
-        // setup categories for dropdown
1944
-        foreach ($categories as $category) {
1945
-            $options[] = [
1946
-                'text' => $category->get('name'),
1947
-                'id'   => $category->ID(),
1948
-            ];
1949
-        }
1950
-
1951
-        return self::select_input('EVT_CAT', $options, $current_cat);
1952
-    }
1953
-
1954
-
1955
-    /**
1956
-     *    generate a submit button with or without it's own microform
1957
-     *    this is the only way to create buttons that are compatible across all themes
1958
-     *
1959
-     * @access    public
1960
-     * @param string      $url              - the form action
1961
-     * @param string      $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm"
1962
-     *                                      for the form
1963
-     * @param string      $class            - css classes (separated by spaces if more than one)
1964
-     * @param string      $text             - what appears on the button
1965
-     * @param string      $nonce_action     - if using nonces
1966
-     * @param bool|string $input_only       - whether to print form header and footer. TRUE returns the input without
1967
-     *                                      the form
1968
-     * @param string      $extra_attributes - any extra attributes that need to be attached to the form input
1969
-     * @return    string
1970
-     */
1971
-    public static function submit_button(
1972
-        $url = '',
1973
-        $ID = '',
1974
-        $class = '',
1975
-        $text = '',
1976
-        $nonce_action = '',
1977
-        $input_only = false,
1978
-        $extra_attributes = ''
1979
-    ) {
1980
-        $btn = '';
1981
-        if (empty($url) || empty($ID)) {
1982
-            return $btn;
1983
-        }
1984
-        $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
1985
-        $btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
1986
-                 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1987
-        if (! $input_only) {
1988
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1989
-            $btn_frm .= ! empty($nonce_action)
1990
-                ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
1991
-                : '';
1992
-            $btn_frm .= $btn;
1993
-            $btn_frm .= '</form>';
1994
-            $btn     = $btn_frm;
1995
-            unset($btn_frm);
1996
-        }
1997
-        return $btn;
1998
-    }
462
+	}
463
+
464
+
465
+	/**
466
+	 * @param string $class
467
+	 * @param string $id
468
+	 * @param string $name
469
+	 * @param int    $rows
470
+	 * @param int    $tab_index
471
+	 * @param string $value
472
+	 * @param array  $wp_editor_args
473
+	 * @return false|string
474
+	 * @since   4.10.14.p
475
+	 */
476
+	private static function adminWpEditor($class, $id, $name, $rows, $tab_index, $value, $wp_editor_args = [])
477
+	{
478
+		$editor_settings = $wp_editor_args + [
479
+				'textarea_name' => esc_attr($name),
480
+				'textarea_rows' => absint($rows),
481
+				'editor_class'  => esc_attr($class),
482
+				'tabindex'      => absint($tab_index),
483
+			];
484
+		ob_start();
485
+		wp_editor($value, esc_attr($id), $editor_settings);
486
+		return ob_get_clean();
487
+	}
488
+
489
+
490
+	/**
491
+	 * espresso admin page select_input
492
+	 * Turns an array into a select fields
493
+	 *
494
+	 * @static
495
+	 * @access public
496
+	 * @param string  $name       field name
497
+	 * @param array   $values     option values, numbered array starting at 0, where each value is an array with a key
498
+	 *                            'text' (meaning text to display' and 'id' (meaning the internal value) eg:
499
+	 *                            array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or
500
+	 *                            as an array of key-value pairs, where the key is to be used for the select input's
501
+	 *                            name, and the value will be the text shown to the user.  Optionally you can also
502
+	 *                            include an additional key of "class" which will add a specific class to the option
503
+	 *                            for that value.
504
+	 * @param string  $default    default value
505
+	 * @param string  $parameters extra parameters
506
+	 * @param string  $class      css class
507
+	 * @param boolean $autosize   whether to autosize the select or not
508
+	 * @return string              html string for the select input
509
+	 */
510
+	public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
511
+	{
512
+		// if $values was submitted in the wrong format, convert it over
513
+		if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
514
+			$converted_values = [];
515
+			foreach ($values as $id => $text) {
516
+				$converted_values[] = ['id' => $id, 'text' => $text];
517
+			}
518
+			$values = $converted_values;
519
+		}
520
+
521
+		$field =
522
+			'<select id="' . EEH_Formatter::ee_tep_output_string($name)
523
+			. '" name="' . EEH_Formatter::ee_tep_output_string($name)
524
+			. '"';
525
+
526
+		if (EEH_Formatter::ee_tep_not_null($parameters)) {
527
+			$field .= ' ' . $parameters;
528
+		}
529
+		if ($autosize) {
530
+			$size = 'med';
531
+			for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
532
+				if ($values[ $ii ]['text']) {
533
+					if (strlen($values[ $ii ]['text']) > 5) {
534
+						$size = 'wide';
535
+					}
536
+				}
537
+			}
538
+		} else {
539
+			$size = '';
540
+		}
541
+
542
+		$field .= ' class="' . $class . ' ' . $size . '">';
543
+
544
+		if (empty($default) && isset($GLOBALS[ $name ])) {
545
+			$default = stripslashes($GLOBALS[ $name ]);
546
+		}
547
+
548
+
549
+		for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
550
+			$field .= '<option value="' . $values[ $i ]['id'] . '"';
551
+			if ($default == $values[ $i ]['id']) {
552
+				$field .= ' selected = "selected"';
553
+			}
554
+			if (isset($values[ $i ]['class'])) {
555
+				$field .= ' class="' . $values[ $i ]['class'] . '"';
556
+			}
557
+			$field .= '>' . $values[ $i ]['text'] . '</option>';
558
+		}
559
+		$field .= '</select>';
560
+
561
+		return $field;
562
+	}
563
+
564
+
565
+	/**
566
+	 * generate_question_groups_html
567
+	 *
568
+	 * @param array  $question_groups
569
+	 * @param string $group_wrapper
570
+	 * @return string HTML
571
+	 * @throws EE_Error
572
+	 * @throws ReflectionException
573
+	 */
574
+	public static function generate_question_groups_html($question_groups = [], $group_wrapper = 'fieldset')
575
+	{
576
+
577
+		$html                            = '';
578
+		$before_question_group_questions =
579
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
580
+		$after_question_group_questions  =
581
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
582
+
583
+		if (! empty($question_groups)) {
584
+			// loop thru question groups
585
+			foreach ($question_groups as $QSG) {
586
+				// check that questions exist
587
+				if (! empty($QSG['QSG_questions'])) {
588
+					// use fieldsets
589
+					$html .= "\n\t"
590
+							 . '<'
591
+							 . $group_wrapper
592
+							 . ' class="espresso-question-group-wrap" id="'
593
+							 . $QSG['QSG_identifier']
594
+							 . '">';
595
+					// group_name
596
+					$html .= $QSG['QSG_show_group_name']
597
+						? "\n\t\t"
598
+						  . '<h5 class="espresso-question-group-title-h5 section-title">'
599
+						  . self::prep_answer($QSG['QSG_name'])
600
+						  . '</h5>'
601
+						: '';
602
+					// group_desc
603
+					$html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc'])
604
+						? '<div class="espresso-question-group-desc-pg">'
605
+						  . self::prep_answer($QSG['QSG_desc'])
606
+						  . '</div>'
607
+						: '';
608
+
609
+					$html .= $before_question_group_questions;
610
+					// loop thru questions
611
+					foreach ($QSG['QSG_questions'] as $question) {
612
+						$QFI  = new EE_Question_Form_Input(
613
+							$question['qst_obj'],
614
+							$question['ans_obj'],
615
+							$question
616
+						);
617
+						$html .= self::generate_form_input($QFI);
618
+					}
619
+					$html .= $after_question_group_questions;
620
+					$html .= "\n\t" . '</' . $group_wrapper . '>';
621
+				}
622
+			}
623
+		}
624
+
625
+		return $html;
626
+	}
627
+
628
+
629
+	/**
630
+	 * generate_question_groups_html
631
+	 *
632
+	 * @param array  $question_groups
633
+	 * @param array  $q_meta
634
+	 * @param bool   $from_admin
635
+	 * @param string $group_wrapper
636
+	 * @return string HTML
637
+	 * @throws EE_Error
638
+	 * @throws ReflectionException
639
+	 */
640
+	public static function generate_question_groups_html2(
641
+		$question_groups = [],
642
+		$q_meta = [],
643
+		$from_admin = false,
644
+		$group_wrapper = 'fieldset'
645
+	) {
646
+
647
+		$html                            = '';
648
+		$before_question_group_questions =
649
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
650
+		$after_question_group_questions  =
651
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
652
+
653
+		$default_q_meta = [
654
+			'att_nmbr'    => 1,
655
+			'ticket_id'   => '',
656
+			'input_name'  => '',
657
+			'input_id'    => '',
658
+			'input_class' => '',
659
+		];
660
+		$q_meta         = array_merge($default_q_meta, $q_meta);
661
+
662
+		if (! empty($question_groups)) {
663
+			// loop thru question groups
664
+			foreach ($question_groups as $QSG) {
665
+				if ($QSG instanceof EE_Question_Group) {
666
+					// check that questions exist
667
+
668
+					$where = ['QST_deleted' => 0];
669
+					if (! $from_admin) {
670
+						$where['QST_admin_only'] = 0;
671
+					}
672
+					$questions =
673
+						$QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
674
+					if (! empty($questions)) {
675
+						// use fieldsets
676
+						$html .= "\n\t"
677
+								 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
678
+								 . 'id="' . $QSG->get('QSG_identifier') . '">';
679
+						// group_name
680
+						if ($QSG->show_group_name()) {
681
+							$html .= "\n\t\t"
682
+									 . '<h5 class="espresso-question-group-title-h5 section-title">'
683
+									 . $QSG->get_pretty('QSG_name')
684
+									 . '</h5>';
685
+						}
686
+						// group_desc
687
+						if ($QSG->show_group_desc()) {
688
+							$html .= '<div class="espresso-question-group-desc-pg">'
689
+									 . $QSG->get_pretty('QSG_desc')
690
+									 . '</div>';
691
+						}
692
+
693
+						$html .= $before_question_group_questions;
694
+						// loop thru questions
695
+						foreach ($questions as $QST) {
696
+							$qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID();
697
+
698
+							$answer = null;
699
+
700
+							/** @var RequestInterface $request */
701
+							$request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
702
+							$request_qstn = $request->getRequestParam('qstn', [], 'string', true);
703
+							if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
704
+								// check for answer in $request_qstn in case we are reprocessing a form after an error
705
+								if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
706
+									$answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
707
+										? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
708
+										: sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
709
+								}
710
+							} elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
711
+								// attendee data from the session
712
+								$answer =
713
+									isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
714
+							}
715
+
716
+
717
+							$QFI  = new EE_Question_Form_Input(
718
+								$QST,
719
+								EE_Answer::new_instance(
720
+									[
721
+										'ANS_ID'    => 0,
722
+										'QST_ID'    => 0,
723
+										'REG_ID'    => 0,
724
+										'ANS_value' => $answer,
725
+									]
726
+								),
727
+								$q_meta
728
+							);
729
+							$html .= self::generate_form_input($QFI);
730
+						}
731
+						$html .= $after_question_group_questions;
732
+						$html .= "\n\t" . '</' . $group_wrapper . '>';
733
+					}
734
+				}
735
+			}
736
+		}
737
+		return $html;
738
+	}
739
+
740
+
741
+	/**
742
+	 * generate_form_input
743
+	 *
744
+	 * @param EE_Question_Form_Input $QFI
745
+	 * @return string HTML
746
+	 * @throws EE_Error
747
+	 * @throws ReflectionException
748
+	 */
749
+	public static function generate_form_input(EE_Question_Form_Input $QFI)
750
+	{
751
+		if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) {
752
+			return '';
753
+		}
754
+		/** @var RequestInterface $request */
755
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
756
+
757
+		$QFI = self::_load_system_dropdowns($QFI);
758
+		$QFI = self::_load_specialized_dropdowns($QFI);
759
+
760
+		// we also need to verify
761
+
762
+		$display_text = $QFI->get('QST_display_text');
763
+		$input_name   = $QFI->get('QST_input_name');
764
+		$answer       = $request->getRequestParam($input_name, $QFI->get('ANS_value'));
765
+		$input_id     = $QFI->get('QST_input_id');
766
+		$input_class  = $QFI->get('QST_input_class');
767
+		//      $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : '';
768
+		$disabled          = $QFI->get('QST_disabled');
769
+		$required_label    = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
770
+		$QST_required      = $QFI->get('QST_required');
771
+		$required          =
772
+			$QST_required
773
+				? ['label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required]
774
+				: [];
775
+		$use_html_entities = $QFI->get_meta('htmlentities');
776
+		$required_text     =
777
+			$QFI->get('QST_required_text') != ''
778
+				? $QFI->get('QST_required_text')
779
+				: esc_html__('This field is required', 'event_espresso');
780
+		$required_text     = $QST_required
781
+			? "\n\t\t\t"
782
+			  . '<div class="required-text hidden">'
783
+			  . self::prep_answer($required_text, $use_html_entities)
784
+			  . '</div>'
785
+			: '';
786
+		$label_class       = 'espresso-form-input-lbl';
787
+		$QST_options       = $QFI->options(true, $answer);
788
+		$options           = is_array($QST_options) ? self::prep_answer_options($QST_options) : [];
789
+		$system_ID         = $QFI->get('QST_system');
790
+		$label_b4          = $QFI->get_meta('label_b4');
791
+		$use_desc_4_label  = $QFI->get_meta('use_desc_4_label');
792
+
793
+
794
+		switch ($QFI->get('QST_type')) {
795
+			case 'TEXTAREA':
796
+				return EEH_Form_Fields::textarea(
797
+					$display_text,
798
+					$answer,
799
+					$input_name,
800
+					$input_id,
801
+					$input_class,
802
+					[],
803
+					$required,
804
+					$required_text,
805
+					$label_class,
806
+					$disabled,
807
+					$system_ID,
808
+					$use_html_entities
809
+				);
810
+
811
+			case 'DROPDOWN':
812
+				return EEH_Form_Fields::select(
813
+					$display_text,
814
+					$answer,
815
+					$options,
816
+					$input_name,
817
+					$input_id,
818
+					$input_class,
819
+					$required,
820
+					$required_text,
821
+					$label_class,
822
+					$disabled,
823
+					$system_ID,
824
+					$use_html_entities,
825
+					true
826
+				);
827
+
828
+
829
+			case 'RADIO_BTN':
830
+				return EEH_Form_Fields::radio(
831
+					$display_text,
832
+					$answer,
833
+					$options,
834
+					$input_name,
835
+					$input_id,
836
+					$input_class,
837
+					$required,
838
+					$required_text,
839
+					$label_class,
840
+					$disabled,
841
+					$system_ID,
842
+					$use_html_entities,
843
+					$label_b4,
844
+					$use_desc_4_label
845
+				);
846
+
847
+			case 'CHECKBOX':
848
+				return EEH_Form_Fields::checkbox(
849
+					$display_text,
850
+					$answer,
851
+					$options,
852
+					$input_name,
853
+					$input_id,
854
+					$input_class,
855
+					$required,
856
+					$required_text,
857
+					$label_class,
858
+					$disabled,
859
+					$label_b4,
860
+					$system_ID,
861
+					$use_html_entities
862
+				);
863
+
864
+			case 'DATE':
865
+				return EEH_Form_Fields::datepicker(
866
+					$display_text,
867
+					$answer,
868
+					$input_name,
869
+					$input_id,
870
+					$input_class,
871
+					$required,
872
+					$required_text,
873
+					$label_class,
874
+					$disabled,
875
+					$system_ID,
876
+					$use_html_entities
877
+				);
878
+
879
+			case 'TEXT':
880
+			default:
881
+				return EEH_Form_Fields::text(
882
+					$display_text,
883
+					$answer,
884
+					$input_name,
885
+					$input_id,
886
+					$input_class,
887
+					$required,
888
+					$required_text,
889
+					$label_class,
890
+					$disabled,
891
+					$system_ID,
892
+					$use_html_entities
893
+				);
894
+		}
895
+	}
896
+
897
+
898
+	/**
899
+	 * generates HTML for a form text input
900
+	 *
901
+	 * @param string $question    label content
902
+	 * @param string $answer      form input value attribute
903
+	 * @param string $name        form input name attribute
904
+	 * @param string $id          form input css id attribute
905
+	 * @param string $class       form input css class attribute
906
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
907
+	 *                            required 'class', and required 'msg' attribute
908
+	 * @param string $label_class css class attribute for the label
909
+	 * @param string $disabled    disabled="disabled" or null
910
+	 * @return string HTML
911
+	 */
912
+	public static function text(
913
+		$question = false,
914
+		$answer = null,
915
+		$name = false,
916
+		$id = '',
917
+		$class = '',
918
+		$required = false,
919
+		$required_text = '',
920
+		$label_class = '',
921
+		$disabled = false,
922
+		$system_ID = false,
923
+		$use_html_entities = true
924
+	) {
925
+		// need these
926
+		if (! $question || ! $name) {
927
+			return null;
928
+		}
929
+		// prep the answer
930
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
931
+		// prep the required array
932
+		$required = self::prep_required($required);
933
+		// set disabled tag
934
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
935
+		// ya gots ta have style man!!!
936
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
937
+		$class     = empty($class) ? $txt_class : $class;
938
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
939
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
940
+
941
+		$label_html =
942
+			$required_text
943
+			. "\n\t\t\t"
944
+			. '<label for="' . $name . '" class="' . $label_class . '">'
945
+			. self::prep_question($question)
946
+			. $required['label']
947
+			. '</label><br/>';
948
+		// filter label but ensure required text comes before it
949
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
950
+
951
+		$input_html =
952
+			"\n\t\t\t"
953
+			. '<input type="text" name="' . $name . '" id="' . $id . '" '
954
+			. 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  '
955
+			. 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
956
+
957
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
958
+		return $label_html . $input_html;
959
+	}
960
+
961
+
962
+	/**
963
+	 * generates HTML for a form textarea
964
+	 *
965
+	 * @param string $question    label content
966
+	 * @param string $answer      form input value attribute
967
+	 * @param string $name        form input name attribute
968
+	 * @param string $id          form input css id attribute
969
+	 * @param string $class       form input css class attribute
970
+	 * @param array  $dimensions  array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 )
971
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
972
+	 *                            required 'class', and required 'msg' attribute
973
+	 * @param string $label_class css class attribute for the label
974
+	 * @param string $disabled    disabled="disabled" or null
975
+	 * @return string HTML
976
+	 */
977
+	public static function textarea(
978
+		$question = false,
979
+		$answer = null,
980
+		$name = false,
981
+		$id = '',
982
+		$class = '',
983
+		$dimensions = false,
984
+		$required = false,
985
+		$required_text = '',
986
+		$label_class = '',
987
+		$disabled = false,
988
+		$system_ID = false,
989
+		$use_html_entities = true
990
+	) {
991
+		// need these
992
+		if (! $question || ! $name) {
993
+			return null;
994
+		}
995
+		// prep the answer
996
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
997
+		// prep the required array
998
+		$required = self::prep_required($required);
999
+		// make sure $dimensions is an array
1000
+		$dimensions = is_array($dimensions) ? $dimensions : [];
1001
+		// and set some defaults
1002
+		$dimensions = array_merge(['rows' => 3, 'cols' => 40], $dimensions);
1003
+		// set disabled tag
1004
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1005
+		// ya gots ta have style man!!!
1006
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
1007
+		$class     = empty($class) ? $txt_class : $class;
1008
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1009
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1010
+
1011
+		$label_html =
1012
+			$required_text
1013
+			. "\n\t\t\t"
1014
+			. '<label for="' . $name . '" class="' . $label_class . '">'
1015
+			. self::prep_question($question)
1016
+			. $required['label']
1017
+			. '</label><br/>';
1018
+		// filter label but ensure required text comes before it
1019
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1020
+
1021
+		$input_html =
1022
+			"\n\t\t\t"
1023
+			. '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1024
+			. 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1025
+			. 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1026
+			. esc_textarea($answer)
1027
+			. '</textarea>';
1028
+
1029
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1030
+		return $label_html . $input_html;
1031
+	}
1032
+
1033
+
1034
+	/**
1035
+	 * generates HTML for a form select input
1036
+	 *
1037
+	 * @param string $question    label content
1038
+	 * @param string $answer      form input value attribute
1039
+	 * @param array  $options     array of answer options where array key = option value and array value = option
1040
+	 *                            display text
1041
+	 * @param string $name        form input name attribute
1042
+	 * @param string $id          form input css id attribute
1043
+	 * @param string $class       form input css class attribute
1044
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1045
+	 *                            required 'class', and required 'msg' attribute
1046
+	 * @param string $label_class css class attribute for the label
1047
+	 * @param string $disabled    disabled="disabled" or null
1048
+	 * @return string HTML
1049
+	 */
1050
+	public static function select(
1051
+		$question = false,
1052
+		$answer = null,
1053
+		$options = false,
1054
+		$name = false,
1055
+		$id = '',
1056
+		$class = '',
1057
+		$required = false,
1058
+		$required_text = '',
1059
+		$label_class = '',
1060
+		$disabled = false,
1061
+		$system_ID = false,
1062
+		$use_html_entities = true,
1063
+		$add_please_select_option = false
1064
+	) {
1065
+
1066
+		// need these
1067
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1068
+			return null;
1069
+		}
1070
+		// prep the answer
1071
+		$answer =
1072
+			is_array($answer)
1073
+				? self::prep_answer(array_shift($answer), $use_html_entities)
1074
+				: self::prep_answer(
1075
+					$answer,
1076
+					$use_html_entities
1077
+				);
1078
+		// prep the required array
1079
+		$required = self::prep_required($required);
1080
+		// set disabled tag
1081
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1082
+		// ya gots ta have style man!!!
1083
+		$txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
1084
+		$class     = empty($class) ? $txt_class : $class;
1085
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1086
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1087
+
1088
+		$label_html =
1089
+			$required_text
1090
+			. "\n\t\t\t"
1091
+			. '<label for="' . $name . '" class="' . $label_class . '">'
1092
+			. self::prep_question($question)
1093
+			. $required['label']
1094
+			. '</label><br/>';
1095
+		// filter label but ensure required text comes before it
1096
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1097
+
1098
+		$input_html =
1099
+			"\n\t\t\t"
1100
+			. '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1101
+			. 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1102
+		// recursively count array elements, to determine total number of options
1103
+		$only_option = count($options, 1) == 1;
1104
+		if (! $only_option) {
1105
+			// if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1106
+			$selected   = $answer === null ? ' selected' : '';
1107
+			$input_html .= $add_please_select_option
1108
+				? "\n\t\t\t\t"
1109
+				  . '<option value=""' . $selected . '>'
1110
+				  . esc_html__(' - please select - ', 'event_espresso')
1111
+				  . '</option>'
1112
+				: '';
1113
+		}
1114
+		foreach ($options as $key => $value) {
1115
+			// if value is an array, then create option groups, else create regular ol' options
1116
+			$input_html .= is_array($value)
1117
+				? self::_generate_select_option_group(
1118
+					$key,
1119
+					$value,
1120
+					$answer,
1121
+					$use_html_entities
1122
+				)
1123
+				: self::_generate_select_option(
1124
+					$value->value(),
1125
+					$value->desc(),
1126
+					$answer,
1127
+					$only_option,
1128
+					$use_html_entities
1129
+				);
1130
+		}
1131
+
1132
+		$input_html .= "\n\t\t\t" . '</select>';
1133
+
1134
+		$input_html =
1135
+			apply_filters(
1136
+				'FHEE__EEH_Form_Fields__select__before_end_wrapper',
1137
+				$input_html,
1138
+				$question,
1139
+				$answer,
1140
+				$name,
1141
+				$id,
1142
+				$class,
1143
+				$system_ID
1144
+			);
1145
+
1146
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1147
+		return $label_html . $input_html;
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 *  _generate_select_option_group
1153
+	 *
1154
+	 *  if  $value for a select box is an array, then the key will be used as the optgroup label
1155
+	 *  and the value array will be looped thru and the elements sent to _generate_select_option
1156
+	 *
1157
+	 * @param mixed   $opt_group
1158
+	 * @param mixed   $QSOs
1159
+	 * @param mixed   $answer
1160
+	 * @param boolean $use_html_entities
1161
+	 * @return string
1162
+	 */
1163
+	private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1164
+	{
1165
+		$html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1166
+		foreach ($QSOs as $QSO) {
1167
+			$html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1168
+		}
1169
+		$html .= "\n\t\t\t\t" . '</optgroup>';
1170
+		return $html;
1171
+	}
1172
+
1173
+
1174
+	/**
1175
+	 *  _generate_select_option
1176
+	 *
1177
+	 * @param mixed   $key
1178
+	 * @param mixed   $value
1179
+	 * @param mixed   $answer
1180
+	 * @param int     $only_option
1181
+	 * @param boolean $use_html_entities
1182
+	 * @return string
1183
+	 */
1184
+	private static function _generate_select_option(
1185
+		$key,
1186
+		$value,
1187
+		$answer,
1188
+		$only_option = false,
1189
+		$use_html_entities = true
1190
+	) {
1191
+		$key      = self::prep_answer($key, $use_html_entities);
1192
+		$value    = self::prep_answer($value, $use_html_entities);
1193
+		$value    = ! empty($value) ? $value : $key;
1194
+		$selected = ($answer == $key || $only_option) ? 'selected' : '';
1195
+		return "\n\t\t\t\t"
1196
+			   . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1197
+			   . $value
1198
+			   . '&nbsp;&nbsp;&nbsp;</option>';
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * generates HTML for form radio button inputs
1204
+	 *
1205
+	 * @param bool|string $question    label content
1206
+	 * @param string      $answer      form input value attribute
1207
+	 * @param array|bool  $options     array of answer options where array key = option value and array value = option
1208
+	 *                                 display text
1209
+	 * @param bool|string $name        form input name attribute
1210
+	 * @param string      $id          form input css id attribute
1211
+	 * @param string      $class       form input css class attribute
1212
+	 * @param array|bool  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1213
+	 *                                 required 'class', and required 'msg' attribute
1214
+	 * @param string      $required_text
1215
+	 * @param string      $label_class css class attribute for the label
1216
+	 * @param bool|string $disabled    disabled="disabled" or null
1217
+	 * @param bool        $system_ID
1218
+	 * @param bool        $use_html_entities
1219
+	 * @param bool        $label_b4
1220
+	 * @param bool        $use_desc_4_label
1221
+	 * @return string HTML
1222
+	 */
1223
+	public static function radio(
1224
+		$question = false,
1225
+		$answer = null,
1226
+		$options = false,
1227
+		$name = false,
1228
+		$id = '',
1229
+		$class = '',
1230
+		$required = false,
1231
+		$required_text = '',
1232
+		$label_class = '',
1233
+		$disabled = false,
1234
+		$system_ID = false,
1235
+		$use_html_entities = true,
1236
+		$label_b4 = false,
1237
+		$use_desc_4_label = false
1238
+	) {
1239
+		// need these
1240
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1241
+			return null;
1242
+		}
1243
+		// prep the answer
1244
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1245
+		// prep the required array
1246
+		$required = self::prep_required($required);
1247
+		// set disabled tag
1248
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1249
+		// ya gots ta have style man!!!
1250
+		$radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1251
+		$class       = ! empty($class) ? $class : 'espresso-radio-btn-inp';
1252
+		$extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1253
+
1254
+		$label_html =
1255
+			$required_text
1256
+			. "\n\t\t\t"
1257
+			. '<label class="' . $label_class . '">'
1258
+			. self::prep_question($question)
1259
+			. $required['label']
1260
+			. '</label> ';
1261
+		// filter label but ensure required text comes before it
1262
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1263
+
1264
+		$input_html =
1265
+			"\n\t\t\t"
1266
+			. '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
1267
+
1268
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1269
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1270
+
1271
+		foreach ($options as $OPT) {
1272
+			if ($OPT instanceof EE_Question_Option) {
1273
+				$value   = self::prep_option_value($OPT->value());
1274
+				$label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1275
+				$size    = $use_desc_4_label
1276
+					? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1277
+					: self::get_label_size_class($OPT->value());
1278
+				$desc    = $OPT->desc();// no self::prep_answer
1279
+				$answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1280
+				$checked = (string) $value == (string) $answer ? ' checked' : '';
1281
+				$opt     = '-' . sanitize_key($value);
1282
+
1283
+				$input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1284
+				$input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1285
+				$input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
1286
+				$input_html .= "\n\t\t\t\t\t\t"
1287
+							   . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1288
+							   . 'class="' . $class . '" value="' . $value . '" '
1289
+							   . 'title="' . esc_attr($required['msg']) . '" ' . $disabled
1290
+							   . $checked . ' ' . $extra . '/>';
1291
+				$input_html .= ! $label_b4
1292
+					? "\n\t\t\t\t\t\t"
1293
+					  . '<span class="espresso-radio-btn-desc">'
1294
+					  . $label
1295
+					  . '</span>'
1296
+					: '';
1297
+				$input_html .= "\n\t\t\t\t\t" . '</label>';
1298
+				$input_html .= $use_desc_4_label
1299
+					? ''
1300
+					: '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1301
+				$input_html .= "\n\t\t\t\t" . '</li>';
1302
+			}
1303
+		}
1304
+
1305
+		$input_html .= "\n\t\t\t" . '</ul>';
1306
+
1307
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1308
+		return $label_html . $input_html;
1309
+	}
1310
+
1311
+
1312
+	/**
1313
+	 * generates HTML for form checkbox inputs
1314
+	 *
1315
+	 * @param string $question    label content
1316
+	 * @param string $answer      form input value attribute
1317
+	 * @param array  $options     array of options where array key = option value and array value = option display text
1318
+	 * @param string $name        form input name attribute
1319
+	 * @param string $id          form input css id attribute
1320
+	 * @param string $class       form input css class attribute
1321
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1322
+	 *                            required 'class', and required 'msg' attribute
1323
+	 * @param string $label_class css class attribute for the label
1324
+	 * @param string $disabled    disabled="disabled" or null
1325
+	 * @return string HTML
1326
+	 */
1327
+	public static function checkbox(
1328
+		$question = false,
1329
+		$answer = null,
1330
+		$options = false,
1331
+		$name = false,
1332
+		$id = '',
1333
+		$class = '',
1334
+		$required = false,
1335
+		$required_text = '',
1336
+		$label_class = '',
1337
+		$disabled = false,
1338
+		$label_b4 = false,
1339
+		$system_ID = false,
1340
+		$use_html_entities = true
1341
+	) {
1342
+		// need these
1343
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1344
+			return null;
1345
+		}
1346
+		$answer = maybe_unserialize($answer);
1347
+
1348
+		// prep the answer(s)
1349
+		$answer = is_array($answer) ? $answer : [sanitize_key($answer) => $answer];
1350
+
1351
+		foreach ($answer as $key => $value) {
1352
+			$key            = self::prep_option_value($key);
1353
+			$answer[ $key ] = self::prep_answer($value, $use_html_entities);
1354
+		}
1355
+
1356
+		// prep the required array
1357
+		$required = self::prep_required($required);
1358
+		// set disabled tag
1359
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1360
+		// ya gots ta have style man!!!
1361
+		$radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1362
+		$class       = empty($class) ? 'espresso-radio-btn-inp' : $class;
1363
+		$extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1364
+
1365
+		$label_html =
1366
+			$required_text
1367
+			. "\n\t\t\t"
1368
+			. '<label class="' . $label_class . '">'
1369
+			. self::prep_question($question)
1370
+			. $required['label']
1371
+			. '</label> ';
1372
+		// filter label but ensure required text comes before it
1373
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1374
+
1375
+		$input_html =
1376
+			"\n\t\t\t"
1377
+			. '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
1378
+
1379
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1380
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1381
+
1382
+		foreach ($options as $OPT) {
1383
+			$value = $OPT->value();// self::prep_option_value( $OPT->value() );
1384
+			$size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1385
+			$text  = self::prep_answer($OPT->value());
1386
+			$desc  = $OPT->desc();
1387
+			$opt   = '-' . sanitize_key($value);
1388
+
1389
+			$checked = is_array($answer) && in_array($text, $answer) ? ' checked' : '';
1390
+
1391
+			$input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1392
+			$input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1393
+			$input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1394
+			$input_html .= "\n\t\t\t\t\t\t"
1395
+						   . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1396
+						   . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1397
+						   . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1398
+			$input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1399
+			$input_html .= "\n\t\t\t\t\t" . '</label>';
1400
+			if (! empty($desc) && $desc != $text) {
1401
+				$input_html .= "\n\t\t\t\t\t"
1402
+							   . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1403
+							   . $desc
1404
+							   . '</div>';
1405
+			}
1406
+			$input_html .= "\n\t\t\t\t" . '</li>';
1407
+		}
1408
+
1409
+		$input_html .= "\n\t\t\t" . '</ul>';
1410
+
1411
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1412
+		return $label_html . $input_html;
1413
+	}
1414
+
1415
+
1416
+	/**
1417
+	 * generates HTML for a form datepicker input
1418
+	 *
1419
+	 * @param string $question    label content
1420
+	 * @param string $answer      form input value attribute
1421
+	 * @param string $name        form input name attribute
1422
+	 * @param string $id          form input css id attribute
1423
+	 * @param string $class       form input css class attribute
1424
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1425
+	 *                            required 'class', and required 'msg' attribute
1426
+	 * @param string $label_class css class attribute for the label
1427
+	 * @param string $disabled    disabled="disabled" or null
1428
+	 * @return string HTML
1429
+	 */
1430
+	public static function datepicker(
1431
+		$question = false,
1432
+		$answer = null,
1433
+		$name = false,
1434
+		$id = '',
1435
+		$class = '',
1436
+		$required = false,
1437
+		$required_text = '',
1438
+		$label_class = '',
1439
+		$disabled = false,
1440
+		$system_ID = false,
1441
+		$use_html_entities = true
1442
+	) {
1443
+		// need these
1444
+		if (! $question || ! $name) {
1445
+			return null;
1446
+		}
1447
+		// prep the answer
1448
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1449
+		// prep the required array
1450
+		$required = self::prep_required($required);
1451
+		// set disabled tag
1452
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1453
+		// ya gots ta have style man!!!
1454
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1455
+		$class     = empty($class) ? $txt_class : $class;
1456
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1457
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1458
+
1459
+		$label_html =
1460
+			$required_text
1461
+			. "\n\t\t\t"
1462
+			. '<label for="' . $name . '" class="' . $label_class . '">'
1463
+			. self::prep_question($question)
1464
+			. $required['label']
1465
+			. '</label><br/>';
1466
+		// filter label but ensure required text comes before it
1467
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1468
+
1469
+		$input_html =
1470
+			"\n\t\t\t"
1471
+			. '<input type="text" name="' . $name . '" id="' . $id . '" '
1472
+			. 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1473
+			. 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1474
+
1475
+		// enqueue scripts
1476
+		wp_register_style(
1477
+			'espresso-ui-theme',
1478
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1479
+			[],
1480
+			EVENT_ESPRESSO_VERSION
1481
+		);
1482
+		wp_enqueue_style('espresso-ui-theme');
1483
+		wp_enqueue_script('jquery-ui-datepicker');
1484
+
1485
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1486
+		return $label_html . $input_html;
1487
+	}
1488
+
1489
+
1490
+	/**
1491
+	 *  remove_label_keep_required_msg
1492
+	 *  this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label
1493
+	 *
1494
+	 * @access public
1495
+	 * @return     string
1496
+	 */
1497
+	public static function remove_label_keep_required_msg($label_html, $required_text)
1498
+	{
1499
+		return $required_text;
1500
+	}
1501
+
1502
+
1503
+	/**
1504
+	 * Simply returns the HTML for a hidden input of the given name and value.
1505
+	 *
1506
+	 * @param string $name
1507
+	 * @param string $value
1508
+	 * @return string HTML
1509
+	 */
1510
+	public static function hidden_input($name, $value, $id = '')
1511
+	{
1512
+		$id = ! empty($id) ? $id : $name;
1513
+		return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * prep_question
1519
+	 *
1520
+	 * @param string $question
1521
+	 * @return string
1522
+	 */
1523
+	public static function prep_question($question)
1524
+	{
1525
+		return $question;
1526
+	}
1527
+
1528
+
1529
+	/**
1530
+	 *  prep_answer
1531
+	 *
1532
+	 * @param mixed $answer
1533
+	 * @return string
1534
+	 */
1535
+	public static function prep_answer($answer, $use_html_entities = true)
1536
+	{
1537
+		// make sure we convert bools first.  Otherwise (bool) false becomes an empty string which is NOT desired,
1538
+		// we want "0".
1539
+		if (is_bool($answer)) {
1540
+			$answer = $answer ? 1 : 0;
1541
+		}
1542
+		$answer = trim(stripslashes(str_replace('&#039;', "'", $answer)));
1543
+		return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer;
1544
+	}
1545
+
1546
+
1547
+	/**
1548
+	 *  prep_answer_options
1549
+	 *
1550
+	 * @param array $QSOs array of EE_Question_Option objects
1551
+	 * @return array
1552
+	 */
1553
+	public static function prep_answer_options($QSOs = [])
1554
+	{
1555
+		$prepped_answer_options = [];
1556
+		if (is_array($QSOs) && ! empty($QSOs)) {
1557
+			foreach ($QSOs as $key => $QSO) {
1558
+				if (! $QSO instanceof EE_Question_Option) {
1559
+					$QSO = EE_Question_Option::new_instance(
1560
+						[
1561
+							'QSO_value' => is_array($QSO) && isset($QSO['id'])
1562
+								? (string) $QSO['id']
1563
+								: (string) $key,
1564
+							'QSO_desc'  => is_array($QSO) && isset($QSO['text'])
1565
+								? (string) $QSO['text']
1566
+								: (string) $QSO,
1567
+						]
1568
+					);
1569
+				}
1570
+				if ($QSO->opt_group()) {
1571
+					$prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1572
+				} else {
1573
+					$prepped_answer_options[] = $QSO;
1574
+				}
1575
+			}
1576
+		}
1577
+		//      d( $prepped_answer_options );
1578
+		return $prepped_answer_options;
1579
+	}
1580
+
1581
+
1582
+	/**
1583
+	 *  prep_option_value
1584
+	 *
1585
+	 * @param string $option_value
1586
+	 * @return string
1587
+	 */
1588
+	public static function prep_option_value($option_value)
1589
+	{
1590
+		return esc_attr(trim(stripslashes($option_value)));
1591
+	}
1592
+
1593
+
1594
+	/**
1595
+	 *  prep_required
1596
+	 *
1597
+	 * @param string|array $required
1598
+	 * @return array
1599
+	 */
1600
+	public static function prep_required($required = [])
1601
+	{
1602
+		// make sure required is an array
1603
+		$required = is_array($required) ? $required : [];
1604
+		// and set some defaults
1605
+		return array_merge(['label' => '', 'class' => '', 'msg' => ''], $required);
1606
+	}
1607
+
1608
+
1609
+	/**
1610
+	 *  get_label_size_class
1611
+	 *
1612
+	 * @param string $value
1613
+	 * @return string
1614
+	 */
1615
+	public static function get_label_size_class($value = false)
1616
+	{
1617
+		if ($value === false || $value === '') {
1618
+			return ' class="medium-lbl"';
1619
+		}
1620
+		// determine length of option value
1621
+		$val_size = strlen($value);
1622
+		switch ($val_size) {
1623
+			case $val_size < 3:
1624
+				$size = ' class="nano-lbl"';
1625
+				break;
1626
+			case $val_size < 6:
1627
+				$size = ' class="micro-lbl"';
1628
+				break;
1629
+			case $val_size < 12:
1630
+				$size = ' class="tiny-lbl"';
1631
+				break;
1632
+			case $val_size < 25:
1633
+				$size = ' class="small-lbl"';
1634
+				break;
1635
+			case $val_size > 100:
1636
+				$size = ' class="big-lbl"';
1637
+				break;
1638
+			default:
1639
+				$size = ' class="medium-lbl"';
1640
+				break;
1641
+		}
1642
+		return $size;
1643
+	}
1644
+
1645
+
1646
+	/**
1647
+	 *  _load_system_dropdowns
1648
+	 *
1649
+	 * @param EE_Question_Form_Input $QFI
1650
+	 * @return array
1651
+	 * @throws EE_Error
1652
+	 * @throws ReflectionException
1653
+	 */
1654
+	private static function _load_system_dropdowns($QFI)
1655
+	{
1656
+		$QST_system = $QFI->get('QST_system');
1657
+		switch ($QST_system) {
1658
+			case 'state':
1659
+				$QFI = self::generate_state_dropdown($QFI);
1660
+				break;
1661
+			case 'country':
1662
+				$QFI = self::generate_country_dropdown($QFI);
1663
+				break;
1664
+			case 'admin-state':
1665
+				$QFI = self::generate_state_dropdown($QFI, true);
1666
+				break;
1667
+			case 'admin-country':
1668
+				$QFI = self::generate_country_dropdown($QFI, true);
1669
+				break;
1670
+		}
1671
+		return $QFI;
1672
+	}
1673
+
1674
+
1675
+	/**
1676
+	 * This preps dropdowns that are specialized.
1677
+	 *
1678
+	 * @param EE_Question_Form_Input $QFI
1679
+	 *
1680
+	 * @return EE_Question_Form_Input
1681
+	 * @throws EE_Error
1682
+	 * @throws ReflectionException
1683
+	 * @since  4.6.0
1684
+	 */
1685
+	protected static function _load_specialized_dropdowns($QFI)
1686
+	{
1687
+		switch ($QFI->get('QST_type')) {
1688
+			case 'STATE':
1689
+				$QFI = self::generate_state_dropdown($QFI);
1690
+				break;
1691
+			case 'COUNTRY':
1692
+				$QFI = self::generate_country_dropdown($QFI);
1693
+				break;
1694
+		}
1695
+		return $QFI;
1696
+	}
1697
+
1698
+
1699
+	/**
1700
+	 *    generate_state_dropdown
1701
+	 *
1702
+	 * @param EE_Question_Form_Input $QST
1703
+	 * @param bool                   $get_all
1704
+	 * @return EE_Question_Form_Input
1705
+	 * @throws EE_Error
1706
+	 * @throws ReflectionException
1707
+	 */
1708
+	public static function generate_state_dropdown($QST, $get_all = false)
1709
+	{
1710
+		$states = $get_all
1711
+			? EEM_State::instance()->get_all_states()
1712
+			: EEM_State::instance()->get_all_states_of_active_countries();
1713
+		if ($states && count($states) != count($QST->options())) {
1714
+			$QST->set('QST_type', 'DROPDOWN');
1715
+			// if multiple countries, we'll create option groups within the dropdown
1716
+			foreach ($states as $state) {
1717
+				if ($state instanceof EE_State) {
1718
+					$QSO = EE_Question_Option::new_instance(
1719
+						[
1720
+							'QSO_value'   => $state->ID(),
1721
+							'QSO_desc'    => $state->name(),
1722
+							'QST_ID'      => $QST->get('QST_ID'),
1723
+							'QSO_deleted' => false,
1724
+						]
1725
+					);
1726
+					// set option group
1727
+					$QSO->set_opt_group($state->country()->name());
1728
+					// add option to question
1729
+					$QST->add_temp_option($QSO);
1730
+				}
1731
+			}
1732
+		}
1733
+		return $QST;
1734
+	}
1735
+
1736
+
1737
+	/**
1738
+	 *    generate_country_dropdown
1739
+	 *
1740
+	 * @param      $QST
1741
+	 * @param bool $get_all
1742
+	 * @return array
1743
+	 * @throws EE_Error
1744
+	 * @throws ReflectionException
1745
+	 * @internal param array $question
1746
+	 */
1747
+	public static function generate_country_dropdown($QST, $get_all = false)
1748
+	{
1749
+		$countries = $get_all
1750
+			? EEM_Country::instance()->get_all_countries()
1751
+			: EEM_Country::instance()->get_all_active_countries();
1752
+		if ($countries && count($countries) != count($QST->options())) {
1753
+			$QST->set('QST_type', 'DROPDOWN');
1754
+			// now add countries
1755
+			foreach ($countries as $country) {
1756
+				if ($country instanceof EE_Country) {
1757
+					$QSO = EE_Question_Option::new_instance(
1758
+						[
1759
+							'QSO_value'   => $country->ID(),
1760
+							'QSO_desc'    => $country->name(),
1761
+							'QST_ID'      => $QST->get('QST_ID'),
1762
+							'QSO_deleted' => false,
1763
+						]
1764
+					);
1765
+					$QST->add_temp_option($QSO);
1766
+				}
1767
+			}
1768
+		}
1769
+		return $QST;
1770
+	}
1771
+
1772
+
1773
+	/**
1774
+	 *  generates options for a month dropdown selector with numbers from 01 to 12
1775
+	 *
1776
+	 * @return array()
1777
+	 */
1778
+	public static function two_digit_months_dropdown_options()
1779
+	{
1780
+		$options = [];
1781
+		for ($x = 1; $x <= 12; $x++) {
1782
+			$mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1783
+			$options[ $mm ] = $mm;
1784
+		}
1785
+		return EEH_Form_Fields::prep_answer_options($options);
1786
+	}
1787
+
1788
+
1789
+	/**
1790
+	 *  generates a year dropdown selector with numbers for the next ten years
1791
+	 *
1792
+	 * @return array
1793
+	 */
1794
+	public static function next_decade_two_digit_year_dropdown_options()
1795
+	{
1796
+		$options      = [];
1797
+		$current_year = date('y');
1798
+		$next_decade  = $current_year + 10;
1799
+		for ($x = $current_year; $x <= $next_decade; $x++) {
1800
+			$yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1801
+			$options[ $yy ] = $yy;
1802
+		}
1803
+		return EEH_Form_Fields::prep_answer_options($options);
1804
+	}
1805
+
1806
+
1807
+	/**
1808
+	 * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for
1809
+	 * list table filter.
1810
+	 *
1811
+	 * @param string  $cur_date     any currently selected date can be entered here.
1812
+	 * @param string  $status       Registration status
1813
+	 * @param integer $evt_category Event Category ID if the Event Category filter is selected
1814
+	 * @return string                html
1815
+	 * @throws EE_Error
1816
+	 */
1817
+	public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1818
+	{
1819
+		$_where = [];
1820
+		if (! empty($status)) {
1821
+			$_where['STS_ID'] = $status;
1822
+		}
1823
+
1824
+		if ($evt_category > 0) {
1825
+			$_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1826
+		}
1827
+
1828
+		$regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1829
+
1830
+		// setup vals for select input helper
1831
+		$options = [
1832
+			0 => [
1833
+				'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1834
+				'id'   => '',
1835
+			],
1836
+		];
1837
+
1838
+		foreach ($regdtts as $regdtt) {
1839
+			$date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1840
+			$options[] = [
1841
+				'text' => $date,
1842
+				'id'   => $date,
1843
+			];
1844
+		}
1845
+
1846
+		return self::select_input('month_range', $options, $cur_date, '', 'wide');
1847
+	}
1848
+
1849
+
1850
+	/**
1851
+	 * generates a month/year dropdown selector for all events matching the given criteria
1852
+	 * Typically used for list table filter
1853
+	 *
1854
+	 * @param string $cur_date          any currently selected date can be entered here.
1855
+	 * @param string $status            "view" (i.e. all, today, month, draft)
1856
+	 * @param int    $evt_category      category event belongs to
1857
+	 * @param string $evt_active_status "upcoming", "expired", "active", or "inactive"
1858
+	 * @return string                    html
1859
+	 * @throws EE_Error
1860
+	 */
1861
+	public static function generate_event_months_dropdown(
1862
+		$cur_date = '',
1863
+		$status = null,
1864
+		$evt_category = null,
1865
+		$evt_active_status = null
1866
+	) {
1867
+		// determine what post_status our condition will have for the query.
1868
+		// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1869
+		switch ($status) {
1870
+			case 'month':
1871
+			case 'today':
1872
+			case null:
1873
+			case 'all':
1874
+				$where['Event.status'] = ['NOT IN', ['trash']];
1875
+				break;
1876
+			case 'draft':
1877
+				$where['Event.status'] = ['IN', ['draft', 'auto-draft']];
1878
+				break;
1879
+			default:
1880
+				$where['Event.status'] = $status;
1881
+		}
1882
+
1883
+		// phpcs:enable
1884
+
1885
+		// categories?
1886
+
1887
+
1888
+		if (! empty($evt_category)) {
1889
+			$where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1890
+			$where['Event.Term_Taxonomy.term_id']  = $evt_category;
1891
+		}
1892
+
1893
+
1894
+		//      $where['DTT_is_primary'] = 1;
1895
+
1896
+		$DTTS = EEM_Datetime::instance()->get_dtt_months_and_years($where, $evt_active_status);
1897
+
1898
+		// let's setup vals for select input helper
1899
+		$options = [
1900
+			0 => [
1901
+				'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1902
+				'id'   => "",
1903
+			],
1904
+		];
1905
+
1906
+
1907
+		// translate month and date
1908
+		global $wp_locale;
1909
+
1910
+		foreach ($DTTS as $DTT) {
1911
+			$localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1912
+			$id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1913
+			$options[]      = [
1914
+				'text' => $localized_date,
1915
+				'id'   => $id,
1916
+			];
1917
+		}
1918
+
1919
+
1920
+		return self::select_input('month_range', $options, $cur_date, '', 'wide');
1921
+	}
1922
+
1923
+
1924
+	/**
1925
+	 * generates the dropdown selector for event categories
1926
+	 * typically used as a filter on list tables.
1927
+	 *
1928
+	 * @param integer $current_cat currently selected category
1929
+	 * @return string               html for dropdown
1930
+	 * @throws EE_Error
1931
+	 * @throws ReflectionException
1932
+	 */
1933
+	public static function generate_event_category_dropdown($current_cat = -1)
1934
+	{
1935
+		$categories = EEM_Term::instance()->get_all_ee_categories(true);
1936
+		$options    = [
1937
+			'0' => [
1938
+				'text' => esc_html__('All Categories', 'event_espresso'),
1939
+				'id'   => -1,
1940
+			],
1941
+		];
1942
+
1943
+		// setup categories for dropdown
1944
+		foreach ($categories as $category) {
1945
+			$options[] = [
1946
+				'text' => $category->get('name'),
1947
+				'id'   => $category->ID(),
1948
+			];
1949
+		}
1950
+
1951
+		return self::select_input('EVT_CAT', $options, $current_cat);
1952
+	}
1953
+
1954
+
1955
+	/**
1956
+	 *    generate a submit button with or without it's own microform
1957
+	 *    this is the only way to create buttons that are compatible across all themes
1958
+	 *
1959
+	 * @access    public
1960
+	 * @param string      $url              - the form action
1961
+	 * @param string      $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm"
1962
+	 *                                      for the form
1963
+	 * @param string      $class            - css classes (separated by spaces if more than one)
1964
+	 * @param string      $text             - what appears on the button
1965
+	 * @param string      $nonce_action     - if using nonces
1966
+	 * @param bool|string $input_only       - whether to print form header and footer. TRUE returns the input without
1967
+	 *                                      the form
1968
+	 * @param string      $extra_attributes - any extra attributes that need to be attached to the form input
1969
+	 * @return    string
1970
+	 */
1971
+	public static function submit_button(
1972
+		$url = '',
1973
+		$ID = '',
1974
+		$class = '',
1975
+		$text = '',
1976
+		$nonce_action = '',
1977
+		$input_only = false,
1978
+		$extra_attributes = ''
1979
+	) {
1980
+		$btn = '';
1981
+		if (empty($url) || empty($ID)) {
1982
+			return $btn;
1983
+		}
1984
+		$text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
1985
+		$btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
1986
+				 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1987
+		if (! $input_only) {
1988
+			$btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1989
+			$btn_frm .= ! empty($nonce_action)
1990
+				? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
1991
+				: '';
1992
+			$btn_frm .= $btn;
1993
+			$btn_frm .= '</form>';
1994
+			$btn     = $btn_frm;
1995
+			unset($btn_frm);
1996
+		}
1997
+		return $btn;
1998
+	}
1999 1999
 }
Please login to merge, or discard this patch.
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
             $type           = $input_value['input'];
109 109
             $value          = $input_value['value'];
110 110
 
111
-            $id    = $form_id ? $form_id . '-' . $input_key : $input_key;
112
-            $class = $required ? 'required ' . $css_class : $css_class;
111
+            $id    = $form_id ? $form_id.'-'.$input_key : $input_key;
112
+            $class = $required ? 'required '.$css_class : $css_class;
113 113
 
114 114
             // what type of input are we dealing with ?
115 115
             switch ($type) {
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
             }
162 162
         } // end foreach( $input_vars as $input_key => $input_value )
163 163
 
164
-        if (! empty($inputs)) {
165
-            $glue   = "
164
+        if ( ! empty($inputs)) {
165
+            $glue = "
166 166
                 </li>
167 167
                 <li>
168 168
                     ";
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             </ul>
176 176
             ";
177 177
         }
178
-        return $output . implode("\n", $hidden_inputs);
178
+        return $output.implode("\n", $hidden_inputs);
179 179
     }
180 180
 
181 181
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
             // generate label
257 257
             $label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
258 258
             // generate field name
259
-            $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
259
+            $name = ! empty($unique_id) ? $field_name.'['.$unique_id.']' : $field_name;
260 260
 
261 261
             // we determine what we're building based on the type
262 262
             switch ($type) {
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
                         foreach ($value as $key => $val) {
268 268
                             $c_input .= self::adminMulti(
269 269
                                 $default,
270
-                                isset($classes[ $key ]) ? $classes[ $key ] : '',
271
-                                $field_name . '_' . $value,
270
+                                isset($classes[$key]) ? $classes[$key] : '',
271
+                                $field_name.'_'.$value,
272 272
                                 $name,
273 273
                                 $required,
274 274
                                 $tab_index,
275 275
                                 $type,
276 276
                                 $val,
277
-                                isset($labels[ $key ]) ? $labels[ $key ] : ''
277
+                                isset($labels[$key]) ? $labels[$key] : ''
278 278
                             );
279 279
                         }
280 280
                         $field = $c_input;
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
                 case 'select':
301 301
                     $options = [];
302 302
                     foreach ($value as $key => $val) {
303
-                        $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
303
+                        $options[$val] = isset($labels[$key]) ? $labels[$key] : '';
304 304
                     }
305 305
                     $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
306 306
                     break;
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
                     $field = self::adminText($class, $id, $name, $required, $tab_index, $value);
327 327
             }
328 328
 
329
-            $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
329
+            $form_fields[$field_name] = ['label' => $label, 'field' => $field.$extra_desc];
330 330
         }
331 331
 
332 332
         return $form_fields;
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
     private static function adminHidden($class, $id, $name, $value)
345 345
     {
346 346
         return "
347
-        <input name='" . esc_attr($name) . "' type='hidden' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' 
348
-        value='" . esc_attr($value) . "' />";
347
+        <input name='" . esc_attr($name)."' type='hidden' id='".esc_attr($id)."' class='".esc_attr($class)."' 
348
+        value='" . esc_attr($value)."' />";
349 349
     }
350 350
 
351 351
 
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
     private static function adminLabel($id, $label, $required)
360 360
     {
361 361
         $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : '';
362
-        return "<label for='" . esc_attr($id) . "'>" . esc_html($label) . $required . "</label>";
362
+        return "<label for='".esc_attr($id)."'>".esc_html($label).$required."</label>";
363 363
     }
364 364
 
365 365
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
         $checked   = ! empty($default) && $default == $value ? 'checked ' : '';
382 382
         $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
383 383
         $input     = "
384
-        <input name='" . esc_attr($name) . "[]' type='" . esc_attr($type) . "' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' value='" . esc_attr($value) . "' {$checked} {$required} tabindex='" . absint($tab_index) . "'/>";
384
+        <input name='" . esc_attr($name)."[]' type='".esc_attr($type)."' id='".esc_attr($id)."' class='".esc_attr($class)."' value='".esc_attr($value)."' {$checked} {$required} tabindex='".absint($tab_index)."'/>";
385 385
         if ($label === '') {
386 386
             return $input;
387 387
         }
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
         foreach ($options as $value => $label) {
412 412
             $selected        = ! empty($default) && $default == $value ? 'selected' : '';
413 413
             $label           = wp_strip_all_tags($label);
414
-            $options_array[] = "<option value='" . esc_attr($value) . "' {$selected}>{$label}</option>";
414
+            $options_array[] = "<option value='".esc_attr($value)."' {$selected}>{$label}</option>";
415 415
         }
416 416
         $options_html = implode($options_array, "\n");
417 417
         $required     = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
418 418
         return "
419
-        <select name='" . esc_attr($name) . "' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' {$required} 
420
-        tabindex='" . absint($tab_index) . "'>
419
+        <select name='" . esc_attr($name)."' id='".esc_attr($id)."' class='".esc_attr($class)."' {$required} 
420
+        tabindex='".absint($tab_index)."'>
421 421
             {$options_html}
422 422
         </select>";
423 423
     }
@@ -435,10 +435,10 @@  discard block
 block discarded – undo
435 435
      */
436 436
     private static function adminText($class, $id, $name, $required, $tab_index, $value)
437 437
     {
438
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
438
+        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
439 439
         return "
440
-        <input name='" . esc_attr($name) . "' type='text' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' 
441
-        value='" . esc_attr($value) . "' {$required} tabindex='" . absint($tab_index) . "'/>";
440
+        <input name='" . esc_attr($name)."' type='text' id='".esc_attr($id)."' class='".esc_attr($class)."' 
441
+        value='" . esc_attr($value)."' {$required} tabindex='".absint($tab_index)."'/>";
442 442
     }
443 443
 
444 444
 
@@ -456,9 +456,9 @@  discard block
 block discarded – undo
456 456
      */
457 457
     private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value)
458 458
     {
459
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
459
+        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
460 460
         return "
461
-        <textarea name='" . esc_attr($name) . "' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' rows='" . absint($rows) . "' cols='" . absint($cols) . "' {$required} tabindex='" . absint($tab_index) . "'>" . esc_textarea($value) . "</textarea>";
461
+        <textarea name='" . esc_attr($name)."' id='".esc_attr($id)."' class='".esc_attr($class)."' rows='".absint($rows)."' cols='".absint($cols)."' {$required} tabindex='".absint($tab_index)."'>".esc_textarea($value)."</textarea>";
462 462
     }
463 463
 
464 464
 
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
     public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
511 511
     {
512 512
         // if $values was submitted in the wrong format, convert it over
513
-        if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
513
+        if ( ! empty($values) && ( ! array_key_exists(0, $values) || ! is_array($values[0]))) {
514 514
             $converted_values = [];
515 515
             foreach ($values as $id => $text) {
516 516
                 $converted_values[] = ['id' => $id, 'text' => $text];
@@ -519,18 +519,18 @@  discard block
 block discarded – undo
519 519
         }
520 520
 
521 521
         $field =
522
-            '<select id="' . EEH_Formatter::ee_tep_output_string($name)
523
-            . '" name="' . EEH_Formatter::ee_tep_output_string($name)
522
+            '<select id="'.EEH_Formatter::ee_tep_output_string($name)
523
+            . '" name="'.EEH_Formatter::ee_tep_output_string($name)
524 524
             . '"';
525 525
 
526 526
         if (EEH_Formatter::ee_tep_not_null($parameters)) {
527
-            $field .= ' ' . $parameters;
527
+            $field .= ' '.$parameters;
528 528
         }
529 529
         if ($autosize) {
530 530
             $size = 'med';
531 531
             for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
532
-                if ($values[ $ii ]['text']) {
533
-                    if (strlen($values[ $ii ]['text']) > 5) {
532
+                if ($values[$ii]['text']) {
533
+                    if (strlen($values[$ii]['text']) > 5) {
534 534
                         $size = 'wide';
535 535
                     }
536 536
                 }
@@ -539,22 +539,22 @@  discard block
 block discarded – undo
539 539
             $size = '';
540 540
         }
541 541
 
542
-        $field .= ' class="' . $class . ' ' . $size . '">';
542
+        $field .= ' class="'.$class.' '.$size.'">';
543 543
 
544
-        if (empty($default) && isset($GLOBALS[ $name ])) {
545
-            $default = stripslashes($GLOBALS[ $name ]);
544
+        if (empty($default) && isset($GLOBALS[$name])) {
545
+            $default = stripslashes($GLOBALS[$name]);
546 546
         }
547 547
 
548 548
 
549 549
         for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
550
-            $field .= '<option value="' . $values[ $i ]['id'] . '"';
551
-            if ($default == $values[ $i ]['id']) {
550
+            $field .= '<option value="'.$values[$i]['id'].'"';
551
+            if ($default == $values[$i]['id']) {
552 552
                 $field .= ' selected = "selected"';
553 553
             }
554
-            if (isset($values[ $i ]['class'])) {
555
-                $field .= ' class="' . $values[ $i ]['class'] . '"';
554
+            if (isset($values[$i]['class'])) {
555
+                $field .= ' class="'.$values[$i]['class'].'"';
556 556
             }
557
-            $field .= '>' . $values[ $i ]['text'] . '</option>';
557
+            $field .= '>'.$values[$i]['text'].'</option>';
558 558
         }
559 559
         $field .= '</select>';
560 560
 
@@ -580,11 +580,11 @@  discard block
 block discarded – undo
580 580
         $after_question_group_questions  =
581 581
             apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
582 582
 
583
-        if (! empty($question_groups)) {
583
+        if ( ! empty($question_groups)) {
584 584
             // loop thru question groups
585 585
             foreach ($question_groups as $QSG) {
586 586
                 // check that questions exist
587
-                if (! empty($QSG['QSG_questions'])) {
587
+                if ( ! empty($QSG['QSG_questions'])) {
588 588
                     // use fieldsets
589 589
                     $html .= "\n\t"
590 590
                              . '<'
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
                     $html .= $before_question_group_questions;
610 610
                     // loop thru questions
611 611
                     foreach ($QSG['QSG_questions'] as $question) {
612
-                        $QFI  = new EE_Question_Form_Input(
612
+                        $QFI = new EE_Question_Form_Input(
613 613
                             $question['qst_obj'],
614 614
                             $question['ans_obj'],
615 615
                             $question
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
                         $html .= self::generate_form_input($QFI);
618 618
                     }
619 619
                     $html .= $after_question_group_questions;
620
-                    $html .= "\n\t" . '</' . $group_wrapper . '>';
620
+                    $html .= "\n\t".'</'.$group_wrapper.'>';
621 621
                 }
622 622
             }
623 623
         }
@@ -657,25 +657,25 @@  discard block
 block discarded – undo
657 657
             'input_id'    => '',
658 658
             'input_class' => '',
659 659
         ];
660
-        $q_meta         = array_merge($default_q_meta, $q_meta);
660
+        $q_meta = array_merge($default_q_meta, $q_meta);
661 661
 
662
-        if (! empty($question_groups)) {
662
+        if ( ! empty($question_groups)) {
663 663
             // loop thru question groups
664 664
             foreach ($question_groups as $QSG) {
665 665
                 if ($QSG instanceof EE_Question_Group) {
666 666
                     // check that questions exist
667 667
 
668 668
                     $where = ['QST_deleted' => 0];
669
-                    if (! $from_admin) {
669
+                    if ( ! $from_admin) {
670 670
                         $where['QST_admin_only'] = 0;
671 671
                     }
672 672
                     $questions =
673 673
                         $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
674
-                    if (! empty($questions)) {
674
+                    if ( ! empty($questions)) {
675 675
                         // use fieldsets
676 676
                         $html .= "\n\t"
677
-                                 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
678
-                                 . 'id="' . $QSG->get('QSG_identifier') . '">';
677
+                                 . '<'.$group_wrapper.' class="espresso-question-group-wrap" '
678
+                                 . 'id="'.$QSG->get('QSG_identifier').'">';
679 679
                         // group_name
680 680
                         if ($QSG->show_group_name()) {
681 681
                             $html .= "\n\t\t"
@@ -700,21 +700,21 @@  discard block
 block discarded – undo
700 700
                             /** @var RequestInterface $request */
701 701
                             $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
702 702
                             $request_qstn = $request->getRequestParam('qstn', [], 'string', true);
703
-                            if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
703
+                            if ( ! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
704 704
                                 // check for answer in $request_qstn in case we are reprocessing a form after an error
705
-                                if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
706
-                                    $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
707
-                                        ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
708
-                                        : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
705
+                                if (isset($request_qstn[$q_meta['input_id']][$qstn_id])) {
706
+                                    $answer = is_array($request_qstn[$q_meta['input_id']][$qstn_id])
707
+                                        ? $request_qstn[$q_meta['input_id']][$qstn_id]
708
+                                        : sanitize_text_field($request_qstn[$q_meta['input_id']][$qstn_id]);
709 709
                                 }
710 710
                             } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
711 711
                                 // attendee data from the session
712 712
                                 $answer =
713
-                                    isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
713
+                                    isset($q_meta['attendee'][$qstn_id]) ? $q_meta['attendee'][$qstn_id] : null;
714 714
                             }
715 715
 
716 716
 
717
-                            $QFI  = new EE_Question_Form_Input(
717
+                            $QFI = new EE_Question_Form_Input(
718 718
                                 $QST,
719 719
                                 EE_Answer::new_instance(
720 720
                                     [
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
                             $html .= self::generate_form_input($QFI);
730 730
                         }
731 731
                         $html .= $after_question_group_questions;
732
-                        $html .= "\n\t" . '</' . $group_wrapper . '>';
732
+                        $html .= "\n\t".'</'.$group_wrapper.'>';
733 733
                     }
734 734
                 }
735 735
             }
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
             $QFI->get('QST_required_text') != ''
778 778
                 ? $QFI->get('QST_required_text')
779 779
                 : esc_html__('This field is required', 'event_espresso');
780
-        $required_text     = $QST_required
780
+        $required_text = $QST_required
781 781
             ? "\n\t\t\t"
782 782
               . '<div class="required-text hidden">'
783 783
               . self::prep_answer($required_text, $use_html_entities)
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
         $use_html_entities = true
924 924
     ) {
925 925
         // need these
926
-        if (! $question || ! $name) {
926
+        if ( ! $question || ! $name) {
927 927
             return null;
928 928
         }
929 929
         // prep the answer
@@ -935,13 +935,13 @@  discard block
 block discarded – undo
935 935
         // ya gots ta have style man!!!
936 936
         $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
937 937
         $class     = empty($class) ? $txt_class : $class;
938
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
938
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
939 939
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
940 940
 
941 941
         $label_html =
942 942
             $required_text
943 943
             . "\n\t\t\t"
944
-            . '<label for="' . $name . '" class="' . $label_class . '">'
944
+            . '<label for="'.$name.'" class="'.$label_class.'">'
945 945
             . self::prep_question($question)
946 946
             . $required['label']
947 947
             . '</label><br/>';
@@ -950,12 +950,12 @@  discard block
 block discarded – undo
950 950
 
951 951
         $input_html =
952 952
             "\n\t\t\t"
953
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
954
-            . 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  '
955
-            . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
953
+            . '<input type="text" name="'.$name.'" id="'.$id.'" '
954
+            . 'class="'.$class.' '.$required['class'].'" value="'.esc_attr($answer).'"  '
955
+            . 'title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>';
956 956
 
957 957
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
958
-        return $label_html . $input_html;
958
+        return $label_html.$input_html;
959 959
     }
960 960
 
961 961
 
@@ -989,7 +989,7 @@  discard block
 block discarded – undo
989 989
         $use_html_entities = true
990 990
     ) {
991 991
         // need these
992
-        if (! $question || ! $name) {
992
+        if ( ! $question || ! $name) {
993 993
             return null;
994 994
         }
995 995
         // prep the answer
@@ -1005,13 +1005,13 @@  discard block
 block discarded – undo
1005 1005
         // ya gots ta have style man!!!
1006 1006
         $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
1007 1007
         $class     = empty($class) ? $txt_class : $class;
1008
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1008
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
1009 1009
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1010 1010
 
1011 1011
         $label_html =
1012 1012
             $required_text
1013 1013
             . "\n\t\t\t"
1014
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1014
+            . '<label for="'.$name.'" class="'.$label_class.'">'
1015 1015
             . self::prep_question($question)
1016 1016
             . $required['label']
1017 1017
             . '</label><br/>';
@@ -1020,14 +1020,14 @@  discard block
 block discarded – undo
1020 1020
 
1021 1021
         $input_html =
1022 1022
             "\n\t\t\t"
1023
-            . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1024
-            . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1025
-            . 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1023
+            . '<textarea name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" '
1024
+            . 'rows="'.$dimensions['rows'].'" cols="'.$dimensions['cols'].'"  '
1025
+            . 'title="'.$required['msg'].'" '.$disabled.' '.$extra.'>'
1026 1026
             . esc_textarea($answer)
1027 1027
             . '</textarea>';
1028 1028
 
1029 1029
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1030
-        return $label_html . $input_html;
1030
+        return $label_html.$input_html;
1031 1031
     }
1032 1032
 
1033 1033
 
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
     ) {
1065 1065
 
1066 1066
         // need these
1067
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1067
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1068 1068
             return null;
1069 1069
         }
1070 1070
         // prep the answer
@@ -1082,13 +1082,13 @@  discard block
 block discarded – undo
1082 1082
         // ya gots ta have style man!!!
1083 1083
         $txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
1084 1084
         $class     = empty($class) ? $txt_class : $class;
1085
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1085
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
1086 1086
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1087 1087
 
1088 1088
         $label_html =
1089 1089
             $required_text
1090 1090
             . "\n\t\t\t"
1091
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1091
+            . '<label for="'.$name.'" class="'.$label_class.'">'
1092 1092
             . self::prep_question($question)
1093 1093
             . $required['label']
1094 1094
             . '</label><br/>';
@@ -1097,16 +1097,16 @@  discard block
 block discarded – undo
1097 1097
 
1098 1098
         $input_html =
1099 1099
             "\n\t\t\t"
1100
-            . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1101
-            . 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1100
+            . '<select name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" '
1101
+            . 'title="'.esc_attr($required['msg']).'"'.$disabled.' '.$extra.'>';
1102 1102
         // recursively count array elements, to determine total number of options
1103 1103
         $only_option = count($options, 1) == 1;
1104
-        if (! $only_option) {
1104
+        if ( ! $only_option) {
1105 1105
             // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1106
-            $selected   = $answer === null ? ' selected' : '';
1106
+            $selected = $answer === null ? ' selected' : '';
1107 1107
             $input_html .= $add_please_select_option
1108 1108
                 ? "\n\t\t\t\t"
1109
-                  . '<option value=""' . $selected . '>'
1109
+                  . '<option value=""'.$selected.'>'
1110 1110
                   . esc_html__(' - please select - ', 'event_espresso')
1111 1111
                   . '</option>'
1112 1112
                 : '';
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
                 );
1130 1130
         }
1131 1131
 
1132
-        $input_html .= "\n\t\t\t" . '</select>';
1132
+        $input_html .= "\n\t\t\t".'</select>';
1133 1133
 
1134 1134
         $input_html =
1135 1135
             apply_filters(
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
             );
1145 1145
 
1146 1146
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1147
-        return $label_html . $input_html;
1147
+        return $label_html.$input_html;
1148 1148
     }
1149 1149
 
1150 1150
 
@@ -1162,11 +1162,11 @@  discard block
 block discarded – undo
1162 1162
      */
1163 1163
     private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1164 1164
     {
1165
-        $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1165
+        $html = "\n\t\t\t\t".'<optgroup label="'.self::prep_option_value($opt_group).'">';
1166 1166
         foreach ($QSOs as $QSO) {
1167 1167
             $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1168 1168
         }
1169
-        $html .= "\n\t\t\t\t" . '</optgroup>';
1169
+        $html .= "\n\t\t\t\t".'</optgroup>';
1170 1170
         return $html;
1171 1171
     }
1172 1172
 
@@ -1193,7 +1193,7 @@  discard block
 block discarded – undo
1193 1193
         $value    = ! empty($value) ? $value : $key;
1194 1194
         $selected = ($answer == $key || $only_option) ? 'selected' : '';
1195 1195
         return "\n\t\t\t\t"
1196
-               . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1196
+               . '<option value="'.self::prep_option_value($key).'" '.$selected.'> '
1197 1197
                . $value
1198 1198
                . '&nbsp;&nbsp;&nbsp;</option>';
1199 1199
     }
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
         $use_desc_4_label = false
1238 1238
     ) {
1239 1239
         // need these
1240
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1240
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1241 1241
             return null;
1242 1242
         }
1243 1243
         // prep the answer
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
         $label_html =
1255 1255
             $required_text
1256 1256
             . "\n\t\t\t"
1257
-            . '<label class="' . $label_class . '">'
1257
+            . '<label class="'.$label_class.'">'
1258 1258
             . self::prep_question($question)
1259 1259
             . $required['label']
1260 1260
             . '</label> ';
@@ -1263,49 +1263,49 @@  discard block
 block discarded – undo
1263 1263
 
1264 1264
         $input_html =
1265 1265
             "\n\t\t\t"
1266
-            . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
1266
+            . '<ul id="'.$id.'-ul" class="espresso-radio-btn-options-ul '.$label_class.' '.$class.'-ul">';
1267 1267
 
1268
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1269
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1268
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1269
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
1270 1270
 
1271 1271
         foreach ($options as $OPT) {
1272 1272
             if ($OPT instanceof EE_Question_Option) {
1273 1273
                 $value   = self::prep_option_value($OPT->value());
1274 1274
                 $label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1275 1275
                 $size    = $use_desc_4_label
1276
-                    ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1276
+                    ? self::get_label_size_class($OPT->value().' '.$OPT->desc())
1277 1277
                     : self::get_label_size_class($OPT->value());
1278
-                $desc    = $OPT->desc();// no self::prep_answer
1278
+                $desc    = $OPT->desc(); // no self::prep_answer
1279 1279
                 $answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1280 1280
                 $checked = (string) $value == (string) $answer ? ' checked' : '';
1281
-                $opt     = '-' . sanitize_key($value);
1281
+                $opt     = '-'.sanitize_key($value);
1282 1282
 
1283
-                $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1284
-                $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1285
-                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
1283
+                $input_html .= "\n\t\t\t\t".'<li'.$size.'>';
1284
+                $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-radio-btn-lbl">';
1285
+                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$label.'</span>' : '';
1286 1286
                 $input_html .= "\n\t\t\t\t\t\t"
1287
-                               . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1288
-                               . 'class="' . $class . '" value="' . $value . '" '
1289
-                               . 'title="' . esc_attr($required['msg']) . '" ' . $disabled
1290
-                               . $checked . ' ' . $extra . '/>';
1287
+                               . '<input type="radio" name="'.$name.'" id="'.$id.$opt.'" '
1288
+                               . 'class="'.$class.'" value="'.$value.'" '
1289
+                               . 'title="'.esc_attr($required['msg']).'" '.$disabled
1290
+                               . $checked.' '.$extra.'/>';
1291 1291
                 $input_html .= ! $label_b4
1292 1292
                     ? "\n\t\t\t\t\t\t"
1293 1293
                       . '<span class="espresso-radio-btn-desc">'
1294 1294
                       . $label
1295 1295
                       . '</span>'
1296 1296
                     : '';
1297
-                $input_html .= "\n\t\t\t\t\t" . '</label>';
1297
+                $input_html .= "\n\t\t\t\t\t".'</label>';
1298 1298
                 $input_html .= $use_desc_4_label
1299 1299
                     ? ''
1300
-                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1301
-                $input_html .= "\n\t\t\t\t" . '</li>';
1300
+                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">'.$desc.'</span>';
1301
+                $input_html .= "\n\t\t\t\t".'</li>';
1302 1302
             }
1303 1303
         }
1304 1304
 
1305
-        $input_html .= "\n\t\t\t" . '</ul>';
1305
+        $input_html .= "\n\t\t\t".'</ul>';
1306 1306
 
1307 1307
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1308
-        return $label_html . $input_html;
1308
+        return $label_html.$input_html;
1309 1309
     }
1310 1310
 
1311 1311
 
@@ -1340,7 +1340,7 @@  discard block
 block discarded – undo
1340 1340
         $use_html_entities = true
1341 1341
     ) {
1342 1342
         // need these
1343
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1343
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1344 1344
             return null;
1345 1345
         }
1346 1346
         $answer = maybe_unserialize($answer);
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
 
1351 1351
         foreach ($answer as $key => $value) {
1352 1352
             $key            = self::prep_option_value($key);
1353
-            $answer[ $key ] = self::prep_answer($value, $use_html_entities);
1353
+            $answer[$key] = self::prep_answer($value, $use_html_entities);
1354 1354
         }
1355 1355
 
1356 1356
         // prep the required array
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
         $label_html =
1366 1366
             $required_text
1367 1367
             . "\n\t\t\t"
1368
-            . '<label class="' . $label_class . '">'
1368
+            . '<label class="'.$label_class.'">'
1369 1369
             . self::prep_question($question)
1370 1370
             . $required['label']
1371 1371
             . '</label> ';
@@ -1374,42 +1374,42 @@  discard block
 block discarded – undo
1374 1374
 
1375 1375
         $input_html =
1376 1376
             "\n\t\t\t"
1377
-            . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
1377
+            . '<ul id="'.$id.'-ul" class="espresso-checkbox-options-ul '.$label_class.' '.$class.'-ul">';
1378 1378
 
1379
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1380
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1379
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1380
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
1381 1381
 
1382 1382
         foreach ($options as $OPT) {
1383
-            $value = $OPT->value();// self::prep_option_value( $OPT->value() );
1384
-            $size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1383
+            $value = $OPT->value(); // self::prep_option_value( $OPT->value() );
1384
+            $size  = self::get_label_size_class($OPT->value().' '.$OPT->desc());
1385 1385
             $text  = self::prep_answer($OPT->value());
1386 1386
             $desc  = $OPT->desc();
1387
-            $opt   = '-' . sanitize_key($value);
1387
+            $opt   = '-'.sanitize_key($value);
1388 1388
 
1389 1389
             $checked = is_array($answer) && in_array($text, $answer) ? ' checked' : '';
1390 1390
 
1391
-            $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1392
-            $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1393
-            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1391
+            $input_html .= "\n\t\t\t\t".'<li'.$size.'>';
1392
+            $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-checkbox-lbl">';
1393
+            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : '';
1394 1394
             $input_html .= "\n\t\t\t\t\t\t"
1395
-                           . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1396
-                           . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1397
-                           . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1398
-            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1399
-            $input_html .= "\n\t\t\t\t\t" . '</label>';
1400
-            if (! empty($desc) && $desc != $text) {
1395
+                           . '<input type="checkbox" name="'.$name.'['.$OPT->ID().']" '
1396
+                           . 'id="'.$id.$opt.'" class="'.$class.'" value="'.$value.'" '
1397
+                           . 'title="'.esc_attr($required['msg']).'" '.$disabled.$checked.' '.$extra.'/>';
1398
+            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : '';
1399
+            $input_html .= "\n\t\t\t\t\t".'</label>';
1400
+            if ( ! empty($desc) && $desc != $text) {
1401 1401
                 $input_html .= "\n\t\t\t\t\t"
1402 1402
                                . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1403 1403
                                . $desc
1404 1404
                                . '</div>';
1405 1405
             }
1406
-            $input_html .= "\n\t\t\t\t" . '</li>';
1406
+            $input_html .= "\n\t\t\t\t".'</li>';
1407 1407
         }
1408 1408
 
1409
-        $input_html .= "\n\t\t\t" . '</ul>';
1409
+        $input_html .= "\n\t\t\t".'</ul>';
1410 1410
 
1411 1411
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1412
-        return $label_html . $input_html;
1412
+        return $label_html.$input_html;
1413 1413
     }
1414 1414
 
1415 1415
 
@@ -1441,7 +1441,7 @@  discard block
 block discarded – undo
1441 1441
         $use_html_entities = true
1442 1442
     ) {
1443 1443
         // need these
1444
-        if (! $question || ! $name) {
1444
+        if ( ! $question || ! $name) {
1445 1445
             return null;
1446 1446
         }
1447 1447
         // prep the answer
@@ -1453,13 +1453,13 @@  discard block
 block discarded – undo
1453 1453
         // ya gots ta have style man!!!
1454 1454
         $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1455 1455
         $class     = empty($class) ? $txt_class : $class;
1456
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1456
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
1457 1457
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1458 1458
 
1459 1459
         $label_html =
1460 1460
             $required_text
1461 1461
             . "\n\t\t\t"
1462
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1462
+            . '<label for="'.$name.'" class="'.$label_class.'">'
1463 1463
             . self::prep_question($question)
1464 1464
             . $required['label']
1465 1465
             . '</label><br/>';
@@ -1468,14 +1468,14 @@  discard block
 block discarded – undo
1468 1468
 
1469 1469
         $input_html =
1470 1470
             "\n\t\t\t"
1471
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
1472
-            . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1473
-            . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1471
+            . '<input type="text" name="'.$name.'" id="'.$id.'" '
1472
+            . 'class="'.$class.' '.$required['class'].' datepicker" value="'.$answer.'"  '
1473
+            . 'title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>';
1474 1474
 
1475 1475
         // enqueue scripts
1476 1476
         wp_register_style(
1477 1477
             'espresso-ui-theme',
1478
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1478
+            EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1479 1479
             [],
1480 1480
             EVENT_ESPRESSO_VERSION
1481 1481
         );
@@ -1483,7 +1483,7 @@  discard block
 block discarded – undo
1483 1483
         wp_enqueue_script('jquery-ui-datepicker');
1484 1484
 
1485 1485
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1486
-        return $label_html . $input_html;
1486
+        return $label_html.$input_html;
1487 1487
     }
1488 1488
 
1489 1489
 
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
     public static function hidden_input($name, $value, $id = '')
1511 1511
     {
1512 1512
         $id = ! empty($id) ? $id : $name;
1513
-        return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1513
+        return '<input id="'.$id.'" type="hidden" name="'.$name.'" value="'.$value.'"/>';
1514 1514
     }
1515 1515
 
1516 1516
 
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
         $prepped_answer_options = [];
1556 1556
         if (is_array($QSOs) && ! empty($QSOs)) {
1557 1557
             foreach ($QSOs as $key => $QSO) {
1558
-                if (! $QSO instanceof EE_Question_Option) {
1558
+                if ( ! $QSO instanceof EE_Question_Option) {
1559 1559
                     $QSO = EE_Question_Option::new_instance(
1560 1560
                         [
1561 1561
                             'QSO_value' => is_array($QSO) && isset($QSO['id'])
@@ -1568,7 +1568,7 @@  discard block
 block discarded – undo
1568 1568
                     );
1569 1569
                 }
1570 1570
                 if ($QSO->opt_group()) {
1571
-                    $prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1571
+                    $prepped_answer_options[$QSO->opt_group()][] = $QSO;
1572 1572
                 } else {
1573 1573
                     $prepped_answer_options[] = $QSO;
1574 1574
                 }
@@ -1780,7 +1780,7 @@  discard block
 block discarded – undo
1780 1780
         $options = [];
1781 1781
         for ($x = 1; $x <= 12; $x++) {
1782 1782
             $mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1783
-            $options[ $mm ] = $mm;
1783
+            $options[$mm] = $mm;
1784 1784
         }
1785 1785
         return EEH_Form_Fields::prep_answer_options($options);
1786 1786
     }
@@ -1798,7 +1798,7 @@  discard block
 block discarded – undo
1798 1798
         $next_decade  = $current_year + 10;
1799 1799
         for ($x = $current_year; $x <= $next_decade; $x++) {
1800 1800
             $yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1801
-            $options[ $yy ] = $yy;
1801
+            $options[$yy] = $yy;
1802 1802
         }
1803 1803
         return EEH_Form_Fields::prep_answer_options($options);
1804 1804
     }
@@ -1817,7 +1817,7 @@  discard block
 block discarded – undo
1817 1817
     public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1818 1818
     {
1819 1819
         $_where = [];
1820
-        if (! empty($status)) {
1820
+        if ( ! empty($status)) {
1821 1821
             $_where['STS_ID'] = $status;
1822 1822
         }
1823 1823
 
@@ -1836,7 +1836,7 @@  discard block
 block discarded – undo
1836 1836
         ];
1837 1837
 
1838 1838
         foreach ($regdtts as $regdtt) {
1839
-            $date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1839
+            $date      = $regdtt->reg_month.' '.$regdtt->reg_year;
1840 1840
             $options[] = [
1841 1841
                 'text' => $date,
1842 1842
                 'id'   => $date,
@@ -1885,7 +1885,7 @@  discard block
 block discarded – undo
1885 1885
         // categories?
1886 1886
 
1887 1887
 
1888
-        if (! empty($evt_category)) {
1888
+        if ( ! empty($evt_category)) {
1889 1889
             $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1890 1890
             $where['Event.Term_Taxonomy.term_id']  = $evt_category;
1891 1891
         }
@@ -1908,8 +1908,8 @@  discard block
 block discarded – undo
1908 1908
         global $wp_locale;
1909 1909
 
1910 1910
         foreach ($DTTS as $DTT) {
1911
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1912
-            $id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1911
+            $localized_date = $wp_locale->get_month($DTT->dtt_month_num).' '.$DTT->dtt_year;
1912
+            $id             = $DTT->dtt_month.' '.$DTT->dtt_year;
1913 1913
             $options[]      = [
1914 1914
                 'text' => $localized_date,
1915 1915
                 'id'   => $id,
@@ -1982,16 +1982,16 @@  discard block
 block discarded – undo
1982 1982
             return $btn;
1983 1983
         }
1984 1984
         $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
1985
-        $btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
1986
-                 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
1987
-        if (! $input_only) {
1988
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
1985
+        $btn .= '<input id="'.$ID.'-btn" class="'.$class.'" '
1986
+                 . 'type="submit" value="'.$text.'" '.$extra_attributes.'/>';
1987
+        if ( ! $input_only) {
1988
+            $btn_frm = '<form id="'.$ID.'-frm" method="POST" action="'.$url.'">';
1989 1989
             $btn_frm .= ! empty($nonce_action)
1990
-                ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
1990
+                ? wp_nonce_field($nonce_action, $nonce_action.'_nonce', true, false)
1991 1991
                 : '';
1992 1992
             $btn_frm .= $btn;
1993 1993
             $btn_frm .= '</form>';
1994
-            $btn     = $btn_frm;
1994
+            $btn = $btn_frm;
1995 1995
             unset($btn_frm);
1996 1996
         }
1997 1997
         return $btn;
Please login to merge, or discard this patch.