Completed
Branch yet-another-batch-of-ui-fixes (f55645)
by
unknown
25:57 queued 18:23
created
core/admin/EE_Admin_List_Table.core.php 1 patch
Indentation   +916 added lines, -916 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\services\request\sanitizers\AllowedTags;
4 4
 
5 5
 if (! class_exists('WP_List_Table')) {
6
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 
@@ -21,481 +21,481 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class EE_Admin_List_Table extends WP_List_Table
23 23
 {
24
-    const ACTION_COPY    = 'duplicate';
25
-
26
-    const ACTION_DELETE  = 'delete';
27
-
28
-    const ACTION_EDIT    = 'edit';
29
-
30
-    const ACTION_RESTORE = 'restore';
31
-
32
-    const ACTION_TRASH   = 'trash';
33
-
34
-    protected static $actions = [
35
-        self::ACTION_COPY,
36
-        self::ACTION_DELETE,
37
-        self::ACTION_EDIT,
38
-        self::ACTION_RESTORE,
39
-        self::ACTION_TRASH,
40
-    ];
41
-
42
-    /**
43
-     * holds the data that will be processed for the table
44
-     *
45
-     * @var array $_data
46
-     */
47
-    protected $_data;
48
-
49
-
50
-    /**
51
-     * This holds the value of all the data available for the given view (for all pages).
52
-     *
53
-     * @var int $_all_data_count
54
-     */
55
-    protected $_all_data_count;
56
-
57
-
58
-    /**
59
-     * Will contain the count of trashed items for the view label.
60
-     *
61
-     * @var int $_trashed_count
62
-     */
63
-    protected $_trashed_count;
64
-
65
-
66
-    /**
67
-     * This is what will be referenced as the slug for the current screen
68
-     *
69
-     * @var string $_screen
70
-     */
71
-    protected $_screen;
72
-
73
-
74
-    /**
75
-     * this is the EE_Admin_Page object
76
-     *
77
-     * @var EE_Admin_Page $_admin_page
78
-     */
79
-    protected $_admin_page;
80
-
81
-
82
-    /**
83
-     * The current view
84
-     *
85
-     * @var string $_view
86
-     */
87
-    protected $_view;
88
-
89
-
90
-    /**
91
-     * array of possible views for this table
92
-     *
93
-     * @var array $_views
94
-     */
95
-    protected $_views;
96
-
97
-
98
-    /**
99
-     * An array of key => value pairs containing information about the current table
100
-     * array(
101
-     *        'plural' => 'plural label',
102
-     *        'singular' => 'singular label',
103
-     *        'ajax' => false, //whether to use ajax or not
104
-     *        'screen' => null, //string used to reference what screen this is
105
-     *        (WP_List_table converts to screen object)
106
-     * )
107
-     *
108
-     * @var array $_wp_list_args
109
-     */
110
-    protected $_wp_list_args;
111
-
112
-    /**
113
-     * an array of column names
114
-     * array(
115
-     *    'internal-name' => 'Title'
116
-     * )
117
-     *
118
-     * @var array $_columns
119
-     */
120
-    protected $_columns;
121
-
122
-    /**
123
-     * An array of sortable columns
124
-     * array(
125
-     *    'internal-name' => 'orderby' //or
126
-     *    'internal-name' => array( 'orderby', true )
127
-     * )
128
-     *
129
-     * @var array $_sortable_columns
130
-     */
131
-    protected $_sortable_columns;
132
-
133
-    /**
134
-     * callback method used to perform AJAX row reordering
135
-     *
136
-     * @var string $_ajax_sorting_callback
137
-     */
138
-    protected $_ajax_sorting_callback;
139
-
140
-    /**
141
-     * An array of hidden columns (if needed)
142
-     * array('internal-name', 'internal-name')
143
-     *
144
-     * @var array $_hidden_columns
145
-     */
146
-    protected $_hidden_columns;
147
-
148
-    /**
149
-     * holds the per_page value
150
-     *
151
-     * @var int $_per_page
152
-     */
153
-    protected $_per_page;
154
-
155
-    /**
156
-     * holds what page number is currently being viewed
157
-     *
158
-     * @var int $_current_page
159
-     */
160
-    protected $_current_page;
161
-
162
-    /**
163
-     * the reference string for the nonce_action
164
-     *
165
-     * @var string $_nonce_action_ref
166
-     */
167
-    protected $_nonce_action_ref;
168
-
169
-    /**
170
-     * property to hold incoming request data (as set by the admin_page_core)
171
-     *
172
-     * @var array $_req_data
173
-     */
174
-    protected $_req_data;
175
-
176
-
177
-    /**
178
-     * yes / no array for admin form fields
179
-     *
180
-     * @var array $_yes_no
181
-     */
182
-    protected $_yes_no = [];
183
-
184
-    /**
185
-     * Array describing buttons that should appear at the bottom of the page
186
-     * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
187
-     * and the values are another array with the following keys
188
-     * array(
189
-     *    'route' => 'page_route',
190
-     *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
191
-     * )
192
-     *
193
-     * @var array $_bottom_buttons
194
-     */
195
-    protected $_bottom_buttons = [];
196
-
197
-
198
-    /**
199
-     * Used to indicate what should be the primary column for the list table.
200
-     * If not present then falls back to what WP calculates
201
-     * as the primary column.
202
-     *
203
-     * @type string $_primary_column
204
-     */
205
-    protected $_primary_column = '';
206
-
207
-
208
-    /**
209
-     * Used to indicate whether the table has a checkbox column or not.
210
-     *
211
-     * @type bool $_has_checkbox_column
212
-     */
213
-    protected $_has_checkbox_column = false;
214
-
215
-
216
-    /**
217
-     * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
218
-     */
219
-    public function __construct(EE_Admin_Page $admin_page)
220
-    {
221
-        $this->_admin_page   = $admin_page;
222
-        $this->_req_data     = $this->_admin_page->get_request_data();
223
-        $this->_view         = $this->_admin_page->get_view();
224
-        $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
225
-        $this->_current_page = $this->get_pagenum();
226
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
227
-        $this->_yes_no       = [
228
-            esc_html__('No', 'event_espresso'),
229
-            esc_html__('Yes', 'event_espresso')
230
-        ];
231
-
232
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page');
233
-
234
-        $this->_setup_data();
235
-        $this->_add_view_counts();
236
-
237
-        $this->_nonce_action_ref = $this->_view;
238
-
239
-        $this->_set_properties();
240
-
241
-        // set primary column
242
-        add_filter('list_table_primary_column', [$this, 'set_primary_column']);
243
-
244
-        // set parent defaults
245
-        parent::__construct($this->_wp_list_args);
246
-
247
-        $this->prepare_items();
248
-    }
249
-
250
-
251
-    /**
252
-     * _setup_data
253
-     * this method is used to setup the $_data, $_all_data_count, and _per_page properties
254
-     *
255
-     * @return void
256
-     * @uses $this->_admin_page
257
-     */
258
-    abstract protected function _setup_data();
259
-
260
-
261
-    /**
262
-     * set the properties that this class needs to be able to execute wp_list_table properly
263
-     * properties set:
264
-     * _wp_list_args = what the arguments required for the parent _wp_list_table.
265
-     * _columns = set the columns in an array.
266
-     * _sortable_columns = columns that are sortable (array).
267
-     * _hidden_columns = columns that are hidden (array)
268
-     * _default_orderby = the default orderby for sorting.
269
-     *
270
-     * @abstract
271
-     * @access protected
272
-     * @return void
273
-     */
274
-    abstract protected function _set_properties();
275
-
276
-
277
-    /**
278
-     * _get_table_filters
279
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
280
-     * gets shown in the table.
281
-     *
282
-     * @abstract
283
-     * @access protected
284
-     * @return string
285
-     */
286
-    abstract protected function _get_table_filters();
287
-
288
-
289
-    /**
290
-     * this is a method that child class will do to add counts to the views array so when views are displayed the
291
-     * counts of the views is accurate.
292
-     *
293
-     * @abstract
294
-     * @access protected
295
-     * @return void
296
-     */
297
-    abstract protected function _add_view_counts();
298
-
299
-
300
-    /**
301
-     * _get_hidden_fields
302
-     * returns a html string of hidden fields so if any table filters are used the current view will be respected.
303
-     *
304
-     * @return string
305
-     */
306
-    protected function _get_hidden_fields()
307
-    {
308
-        $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
309
-        $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
310
-        // if action is STILL empty, then we set it to default
311
-        $action = empty($action) ? 'default' : $action;
312
-        $field  = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n";
313
-        $field  .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n";
314
-        $field  .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n";
315
-
316
-        $bulk_actions = $this->_get_bulk_actions();
317
-        foreach ($bulk_actions as $bulk_action => $label) {
318
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
319
-                      . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
320
-        }
321
-
322
-        return $field;
323
-    }
324
-
325
-
326
-    /**
327
-     * _set_column_info
328
-     * we're using this to set the column headers property.
329
-     *
330
-     * @access protected
331
-     * @return void
332
-     */
333
-    protected function _set_column_info()
334
-    {
335
-        $columns   = $this->get_columns();
336
-        $hidden    = $this->get_hidden_columns();
337
-        $_sortable = $this->get_sortable_columns();
338
-
339
-        /**
340
-         * Dynamic hook allowing for adding sortable columns in this list table.
341
-         * Note that $this->screen->id is in the format
342
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
343
-         * table it is: event-espresso_page_espresso_messages.
344
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
345
-         * hook prefix ("event-espresso") will be different.
346
-         *
347
-         * @var array
348
-         */
349
-        $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
350
-
351
-        $sortable = [];
352
-        foreach ($_sortable as $id => $data) {
353
-            if (empty($data)) {
354
-                continue;
355
-            }
356
-            // fix for offset errors with WP_List_Table default get_columninfo()
357
-            if (is_array($data)) {
358
-                $_data[0] = key($data);
359
-                $_data[1] = isset($data[1]) ? $data[1] : false;
360
-            } else {
361
-                $_data[0] = $data;
362
-            }
363
-
364
-            $data = (array) $data;
365
-
366
-            if (! isset($data[1])) {
367
-                $_data[1] = false;
368
-            }
369
-
370
-            $sortable[ $id ] = $_data;
371
-        }
372
-        $primary               = $this->get_primary_column_name();
373
-        $this->_column_headers = [$columns, $hidden, $sortable, $primary];
374
-    }
375
-
376
-
377
-    /**
378
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
379
-     *
380
-     * @return string
381
-     */
382
-    protected function get_primary_column_name()
383
-    {
384
-        foreach (class_parents($this) as $parent) {
385
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
386
-                return parent::get_primary_column_name();
387
-            }
388
-        }
389
-        return $this->_primary_column;
390
-    }
391
-
392
-
393
-    /**
394
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
395
-     *
396
-     * @param EE_Base_Class $item
397
-     * @param string        $column_name
398
-     * @param string        $primary
399
-     * @return string
400
-     */
401
-    protected function handle_row_actions($item, $column_name, $primary)
402
-    {
403
-        foreach (class_parents($this) as $parent) {
404
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
405
-                return parent::handle_row_actions($item, $column_name, $primary);
406
-            }
407
-        }
408
-        return '';
409
-    }
410
-
411
-
412
-    /**
413
-     * _get_bulk_actions
414
-     * This is a wrapper called by WP_List_Table::get_bulk_actions()
415
-     *
416
-     * @access protected
417
-     * @return array bulk_actions
418
-     */
419
-    protected function _get_bulk_actions(): array
420
-    {
421
-        $actions = [];
422
-        // the _views property should have the bulk_actions, so let's go through and extract them into a properly
423
-        // formatted array for the wp_list_table();
424
-        foreach ($this->_views as $view => $args) {
425
-            if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
426
-                // each bulk action will correspond with a admin page route, so we can check whatever the capability is
427
-                // for that page route and skip adding the bulk action if no access for the current logged in user.
428
-                foreach ($args['bulk_action'] as $route => $label) {
429
-                    if ($this->_admin_page->check_user_access($route, true)) {
430
-                        $actions[ $route ] = $label;
431
-                    }
432
-                }
433
-            }
434
-        }
435
-        return $actions;
436
-    }
437
-
438
-
439
-    /**
440
-     * Generate the table navigation above or below the table.
441
-     * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
442
-     *
443
-     * @throws EE_Error
444
-     * @since 4.9.44.rc.001
445
-     */
446
-    public function display_tablenav($which)
447
-    {
448
-        if ('top' === $which) {
449
-            wp_nonce_field('bulk-' . $this->_args['plural']);
450
-        }
451
-        ?>
24
+	const ACTION_COPY    = 'duplicate';
25
+
26
+	const ACTION_DELETE  = 'delete';
27
+
28
+	const ACTION_EDIT    = 'edit';
29
+
30
+	const ACTION_RESTORE = 'restore';
31
+
32
+	const ACTION_TRASH   = 'trash';
33
+
34
+	protected static $actions = [
35
+		self::ACTION_COPY,
36
+		self::ACTION_DELETE,
37
+		self::ACTION_EDIT,
38
+		self::ACTION_RESTORE,
39
+		self::ACTION_TRASH,
40
+	];
41
+
42
+	/**
43
+	 * holds the data that will be processed for the table
44
+	 *
45
+	 * @var array $_data
46
+	 */
47
+	protected $_data;
48
+
49
+
50
+	/**
51
+	 * This holds the value of all the data available for the given view (for all pages).
52
+	 *
53
+	 * @var int $_all_data_count
54
+	 */
55
+	protected $_all_data_count;
56
+
57
+
58
+	/**
59
+	 * Will contain the count of trashed items for the view label.
60
+	 *
61
+	 * @var int $_trashed_count
62
+	 */
63
+	protected $_trashed_count;
64
+
65
+
66
+	/**
67
+	 * This is what will be referenced as the slug for the current screen
68
+	 *
69
+	 * @var string $_screen
70
+	 */
71
+	protected $_screen;
72
+
73
+
74
+	/**
75
+	 * this is the EE_Admin_Page object
76
+	 *
77
+	 * @var EE_Admin_Page $_admin_page
78
+	 */
79
+	protected $_admin_page;
80
+
81
+
82
+	/**
83
+	 * The current view
84
+	 *
85
+	 * @var string $_view
86
+	 */
87
+	protected $_view;
88
+
89
+
90
+	/**
91
+	 * array of possible views for this table
92
+	 *
93
+	 * @var array $_views
94
+	 */
95
+	protected $_views;
96
+
97
+
98
+	/**
99
+	 * An array of key => value pairs containing information about the current table
100
+	 * array(
101
+	 *        'plural' => 'plural label',
102
+	 *        'singular' => 'singular label',
103
+	 *        'ajax' => false, //whether to use ajax or not
104
+	 *        'screen' => null, //string used to reference what screen this is
105
+	 *        (WP_List_table converts to screen object)
106
+	 * )
107
+	 *
108
+	 * @var array $_wp_list_args
109
+	 */
110
+	protected $_wp_list_args;
111
+
112
+	/**
113
+	 * an array of column names
114
+	 * array(
115
+	 *    'internal-name' => 'Title'
116
+	 * )
117
+	 *
118
+	 * @var array $_columns
119
+	 */
120
+	protected $_columns;
121
+
122
+	/**
123
+	 * An array of sortable columns
124
+	 * array(
125
+	 *    'internal-name' => 'orderby' //or
126
+	 *    'internal-name' => array( 'orderby', true )
127
+	 * )
128
+	 *
129
+	 * @var array $_sortable_columns
130
+	 */
131
+	protected $_sortable_columns;
132
+
133
+	/**
134
+	 * callback method used to perform AJAX row reordering
135
+	 *
136
+	 * @var string $_ajax_sorting_callback
137
+	 */
138
+	protected $_ajax_sorting_callback;
139
+
140
+	/**
141
+	 * An array of hidden columns (if needed)
142
+	 * array('internal-name', 'internal-name')
143
+	 *
144
+	 * @var array $_hidden_columns
145
+	 */
146
+	protected $_hidden_columns;
147
+
148
+	/**
149
+	 * holds the per_page value
150
+	 *
151
+	 * @var int $_per_page
152
+	 */
153
+	protected $_per_page;
154
+
155
+	/**
156
+	 * holds what page number is currently being viewed
157
+	 *
158
+	 * @var int $_current_page
159
+	 */
160
+	protected $_current_page;
161
+
162
+	/**
163
+	 * the reference string for the nonce_action
164
+	 *
165
+	 * @var string $_nonce_action_ref
166
+	 */
167
+	protected $_nonce_action_ref;
168
+
169
+	/**
170
+	 * property to hold incoming request data (as set by the admin_page_core)
171
+	 *
172
+	 * @var array $_req_data
173
+	 */
174
+	protected $_req_data;
175
+
176
+
177
+	/**
178
+	 * yes / no array for admin form fields
179
+	 *
180
+	 * @var array $_yes_no
181
+	 */
182
+	protected $_yes_no = [];
183
+
184
+	/**
185
+	 * Array describing buttons that should appear at the bottom of the page
186
+	 * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
187
+	 * and the values are another array with the following keys
188
+	 * array(
189
+	 *    'route' => 'page_route',
190
+	 *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
191
+	 * )
192
+	 *
193
+	 * @var array $_bottom_buttons
194
+	 */
195
+	protected $_bottom_buttons = [];
196
+
197
+
198
+	/**
199
+	 * Used to indicate what should be the primary column for the list table.
200
+	 * If not present then falls back to what WP calculates
201
+	 * as the primary column.
202
+	 *
203
+	 * @type string $_primary_column
204
+	 */
205
+	protected $_primary_column = '';
206
+
207
+
208
+	/**
209
+	 * Used to indicate whether the table has a checkbox column or not.
210
+	 *
211
+	 * @type bool $_has_checkbox_column
212
+	 */
213
+	protected $_has_checkbox_column = false;
214
+
215
+
216
+	/**
217
+	 * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
218
+	 */
219
+	public function __construct(EE_Admin_Page $admin_page)
220
+	{
221
+		$this->_admin_page   = $admin_page;
222
+		$this->_req_data     = $this->_admin_page->get_request_data();
223
+		$this->_view         = $this->_admin_page->get_view();
224
+		$this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
225
+		$this->_current_page = $this->get_pagenum();
226
+		$this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
227
+		$this->_yes_no       = [
228
+			esc_html__('No', 'event_espresso'),
229
+			esc_html__('Yes', 'event_espresso')
230
+		];
231
+
232
+		$this->_per_page = $this->get_items_per_page($this->_screen . '_per_page');
233
+
234
+		$this->_setup_data();
235
+		$this->_add_view_counts();
236
+
237
+		$this->_nonce_action_ref = $this->_view;
238
+
239
+		$this->_set_properties();
240
+
241
+		// set primary column
242
+		add_filter('list_table_primary_column', [$this, 'set_primary_column']);
243
+
244
+		// set parent defaults
245
+		parent::__construct($this->_wp_list_args);
246
+
247
+		$this->prepare_items();
248
+	}
249
+
250
+
251
+	/**
252
+	 * _setup_data
253
+	 * this method is used to setup the $_data, $_all_data_count, and _per_page properties
254
+	 *
255
+	 * @return void
256
+	 * @uses $this->_admin_page
257
+	 */
258
+	abstract protected function _setup_data();
259
+
260
+
261
+	/**
262
+	 * set the properties that this class needs to be able to execute wp_list_table properly
263
+	 * properties set:
264
+	 * _wp_list_args = what the arguments required for the parent _wp_list_table.
265
+	 * _columns = set the columns in an array.
266
+	 * _sortable_columns = columns that are sortable (array).
267
+	 * _hidden_columns = columns that are hidden (array)
268
+	 * _default_orderby = the default orderby for sorting.
269
+	 *
270
+	 * @abstract
271
+	 * @access protected
272
+	 * @return void
273
+	 */
274
+	abstract protected function _set_properties();
275
+
276
+
277
+	/**
278
+	 * _get_table_filters
279
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
280
+	 * gets shown in the table.
281
+	 *
282
+	 * @abstract
283
+	 * @access protected
284
+	 * @return string
285
+	 */
286
+	abstract protected function _get_table_filters();
287
+
288
+
289
+	/**
290
+	 * this is a method that child class will do to add counts to the views array so when views are displayed the
291
+	 * counts of the views is accurate.
292
+	 *
293
+	 * @abstract
294
+	 * @access protected
295
+	 * @return void
296
+	 */
297
+	abstract protected function _add_view_counts();
298
+
299
+
300
+	/**
301
+	 * _get_hidden_fields
302
+	 * returns a html string of hidden fields so if any table filters are used the current view will be respected.
303
+	 *
304
+	 * @return string
305
+	 */
306
+	protected function _get_hidden_fields()
307
+	{
308
+		$action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
309
+		$action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
310
+		// if action is STILL empty, then we set it to default
311
+		$action = empty($action) ? 'default' : $action;
312
+		$field  = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n";
313
+		$field  .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n";
314
+		$field  .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n";
315
+
316
+		$bulk_actions = $this->_get_bulk_actions();
317
+		foreach ($bulk_actions as $bulk_action => $label) {
318
+			$field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
319
+					  . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
320
+		}
321
+
322
+		return $field;
323
+	}
324
+
325
+
326
+	/**
327
+	 * _set_column_info
328
+	 * we're using this to set the column headers property.
329
+	 *
330
+	 * @access protected
331
+	 * @return void
332
+	 */
333
+	protected function _set_column_info()
334
+	{
335
+		$columns   = $this->get_columns();
336
+		$hidden    = $this->get_hidden_columns();
337
+		$_sortable = $this->get_sortable_columns();
338
+
339
+		/**
340
+		 * Dynamic hook allowing for adding sortable columns in this list table.
341
+		 * Note that $this->screen->id is in the format
342
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
343
+		 * table it is: event-espresso_page_espresso_messages.
344
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
345
+		 * hook prefix ("event-espresso") will be different.
346
+		 *
347
+		 * @var array
348
+		 */
349
+		$_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
350
+
351
+		$sortable = [];
352
+		foreach ($_sortable as $id => $data) {
353
+			if (empty($data)) {
354
+				continue;
355
+			}
356
+			// fix for offset errors with WP_List_Table default get_columninfo()
357
+			if (is_array($data)) {
358
+				$_data[0] = key($data);
359
+				$_data[1] = isset($data[1]) ? $data[1] : false;
360
+			} else {
361
+				$_data[0] = $data;
362
+			}
363
+
364
+			$data = (array) $data;
365
+
366
+			if (! isset($data[1])) {
367
+				$_data[1] = false;
368
+			}
369
+
370
+			$sortable[ $id ] = $_data;
371
+		}
372
+		$primary               = $this->get_primary_column_name();
373
+		$this->_column_headers = [$columns, $hidden, $sortable, $primary];
374
+	}
375
+
376
+
377
+	/**
378
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
379
+	 *
380
+	 * @return string
381
+	 */
382
+	protected function get_primary_column_name()
383
+	{
384
+		foreach (class_parents($this) as $parent) {
385
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
386
+				return parent::get_primary_column_name();
387
+			}
388
+		}
389
+		return $this->_primary_column;
390
+	}
391
+
392
+
393
+	/**
394
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
395
+	 *
396
+	 * @param EE_Base_Class $item
397
+	 * @param string        $column_name
398
+	 * @param string        $primary
399
+	 * @return string
400
+	 */
401
+	protected function handle_row_actions($item, $column_name, $primary)
402
+	{
403
+		foreach (class_parents($this) as $parent) {
404
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
405
+				return parent::handle_row_actions($item, $column_name, $primary);
406
+			}
407
+		}
408
+		return '';
409
+	}
410
+
411
+
412
+	/**
413
+	 * _get_bulk_actions
414
+	 * This is a wrapper called by WP_List_Table::get_bulk_actions()
415
+	 *
416
+	 * @access protected
417
+	 * @return array bulk_actions
418
+	 */
419
+	protected function _get_bulk_actions(): array
420
+	{
421
+		$actions = [];
422
+		// the _views property should have the bulk_actions, so let's go through and extract them into a properly
423
+		// formatted array for the wp_list_table();
424
+		foreach ($this->_views as $view => $args) {
425
+			if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
426
+				// each bulk action will correspond with a admin page route, so we can check whatever the capability is
427
+				// for that page route and skip adding the bulk action if no access for the current logged in user.
428
+				foreach ($args['bulk_action'] as $route => $label) {
429
+					if ($this->_admin_page->check_user_access($route, true)) {
430
+						$actions[ $route ] = $label;
431
+					}
432
+				}
433
+			}
434
+		}
435
+		return $actions;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Generate the table navigation above or below the table.
441
+	 * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
442
+	 *
443
+	 * @throws EE_Error
444
+	 * @since 4.9.44.rc.001
445
+	 */
446
+	public function display_tablenav($which)
447
+	{
448
+		if ('top' === $which) {
449
+			wp_nonce_field('bulk-' . $this->_args['plural']);
450
+		}
451
+		?>
452 452
         <div class="tablenav <?php echo esc_attr($which); ?>">
453 453
             <?php if ($this->_get_bulk_actions()) { ?>
454 454
                 <div class="alignleft actions bulkactions">
455 455
                     <?php $this->bulk_actions(); ?>
456 456
                 </div>
457 457
             <?php }
458
-            $this->extra_tablenav($which);
459
-            $this->pagination($which);
460
-            ?>
458
+			$this->extra_tablenav($which);
459
+			$this->pagination($which);
460
+			?>
461 461
 
462 462
             <br class="clear" />
463 463
         </div>
464 464
         <?php
465
-    }
466
-
467
-
468
-    /**
469
-     * _filters
470
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
471
-     * button.
472
-     *
473
-     * @access private
474
-     * @return void  echos html showing filters
475
-     */
476
-    private function _filters()
477
-    {
478
-        $classname = get_class($this);
479
-        $filters   = apply_filters(
480
-            "FHEE__{$classname}__filters",
481
-            (array) $this->_get_table_filters(),
482
-            $this,
483
-            $this->_screen
484
-        );
485
-
486
-        if (empty($filters)) {
487
-            return;
488
-        }
489
-
490
-        $filters_html = '';
491
-        foreach ($filters as $filter) {
492
-            $filters_html .= wp_kses($filter, AllowedTags::getWithFormTags());
493
-        }
494
-        $filter_submit_btn_text = esc_html__('Filter', 'event_espresso');
495
-        $filter_reset_btn_text = esc_html__('Reset Filters', 'event_espresso');
496
-        $filter_reset_btn_url = esc_url_raw($this->_admin_page->get_current_page_view_url());
497
-
498
-        echo "
465
+	}
466
+
467
+
468
+	/**
469
+	 * _filters
470
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
471
+	 * button.
472
+	 *
473
+	 * @access private
474
+	 * @return void  echos html showing filters
475
+	 */
476
+	private function _filters()
477
+	{
478
+		$classname = get_class($this);
479
+		$filters   = apply_filters(
480
+			"FHEE__{$classname}__filters",
481
+			(array) $this->_get_table_filters(),
482
+			$this,
483
+			$this->_screen
484
+		);
485
+
486
+		if (empty($filters)) {
487
+			return;
488
+		}
489
+
490
+		$filters_html = '';
491
+		foreach ($filters as $filter) {
492
+			$filters_html .= wp_kses($filter, AllowedTags::getWithFormTags());
493
+		}
494
+		$filter_submit_btn_text = esc_html__('Filter', 'event_espresso');
495
+		$filter_reset_btn_text = esc_html__('Reset Filters', 'event_espresso');
496
+		$filter_reset_btn_url = esc_url_raw($this->_admin_page->get_current_page_view_url());
497
+
498
+		echo "
499 499
         <div class='ee-list-table-filters actions alignleft'>
500 500
            $filters_html
501 501
             <span class='ee-list-table-filters__submit-buttons'>
@@ -510,444 +510,444 @@  discard block
 block discarded – undo
510 510
                 </a>
511 511
             </span>
512 512
         </div>";
513
-    }
514
-
515
-
516
-    /**
517
-     * Callback for 'list_table_primary_column' WordPress filter
518
-     * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
519
-     * column when class is instantiated.
520
-     *
521
-     * @param string $column_name
522
-     * @return string
523
-     * @see WP_List_Table::get_primary_column_name
524
-     */
525
-    public function set_primary_column($column_name)
526
-    {
527
-        return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
528
-    }
529
-
530
-
531
-    /**
532
-     *
533
-     */
534
-    public function prepare_items()
535
-    {
536
-        $this->_set_column_info();
537
-        // $this->_column_headers = $this->get_column_info();
538
-        $total_items = $this->_all_data_count;
539
-        $this->process_bulk_action();
540
-
541
-        $this->items = $this->_data;
542
-        $this->set_pagination_args(
543
-            [
544
-                'total_items' => $total_items,
545
-                'per_page'    => $this->_per_page,
546
-                'total_pages' => ceil($total_items / $this->_per_page),
547
-            ]
548
-        );
549
-    }
550
-
551
-
552
-    /**
553
-     * @param object|array $item
554
-     * @return string html content for the column
555
-     */
556
-    protected function column_cb($item)
557
-    {
558
-        return '';
559
-    }
560
-
561
-
562
-    /**
563
-     * This column is the default for when there is no defined column method for a registered column.
564
-     * This can be overridden by child classes, but allows for hooking in for custom columns.
565
-     *
566
-     * @param EE_Base_Class $item
567
-     * @param string        $column_name The column being called.
568
-     * @return string html content for the column
569
-     */
570
-    public function column_default($item, $column_name)
571
-    {
572
-        /**
573
-         * Dynamic hook allowing for adding additional column content in this list table.
574
-         * Note that $this->screen->id is in the format
575
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
576
-         * table it is: event-espresso_page_espresso_messages.
577
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
578
-         * hook prefix ("event-espresso") will be different.
579
-         */
580
-        ob_start();
581
-        do_action(
582
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
583
-            $item,
584
-            $this->_screen
585
-        );
586
-        return ob_get_clean();
587
-    }
588
-
589
-
590
-    /**
591
-     * Get a list of columns. The format is:
592
-     * 'internal-name' => 'Title'
593
-     *
594
-     * @return array
595
-     * @since  3.1.0
596
-     * @access public
597
-     * @abstract
598
-     */
599
-    public function get_columns()
600
-    {
601
-        /**
602
-         * Dynamic hook allowing for adding additional columns in this list table.
603
-         * Note that $this->screen->id is in the format
604
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
605
-         * table it is: event-espresso_page_espresso_messages.
606
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
607
-         * hook prefix ("event-espresso") will be different.
608
-         *
609
-         * @var array
610
-         */
611
-        return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
612
-    }
613
-
614
-
615
-    /**
616
-     * Get an associative array ( id => link ) with the list
617
-     * of views available on this table.
618
-     *
619
-     * @return array
620
-     * @since  3.1.0
621
-     * @access protected
622
-     */
623
-    public function get_views()
624
-    {
625
-        return $this->_views;
626
-    }
627
-
628
-
629
-    /**
630
-     * Generate the views html.
631
-     */
632
-    public function display_views()
633
-    {
634
-        $views           = $this->get_views();
635
-        $assembled_views = [];
636
-
637
-        if (empty($views)) {
638
-            return;
639
-        }
640
-        echo "<ul class='subsubsub'>\n";
641
-        foreach ($views as $view) {
642
-            $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
643
-            if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
644
-                $filter = "<li";
645
-                $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : '';
646
-                $filter .= ">";
647
-                $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>';
648
-                $filter .= '<span class="count">(' . $count . ')</span>';
649
-                $filter .= '</li>';
650
-                $assembled_views[ $view['slug'] ] = $filter;
651
-            }
652
-        }
653
-
654
-        echo ! empty($assembled_views)
655
-            ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views)
656
-            : '';
657
-        echo "</ul>";
658
-    }
659
-
660
-
661
-    /**
662
-     * Generates content for a single row of the table
663
-     *
664
-     * @param EE_Base_Class $item The current item
665
-     * @since  4.1
666
-     * @access public
667
-     */
668
-    public function single_row($item)
669
-    {
670
-        $row_class = $this->_get_row_class($item);
671
-        echo '<tr class="' . esc_attr($row_class) . '">';
672
-        $this->single_row_columns($item); // already escaped
673
-        echo '</tr>';
674
-    }
675
-
676
-
677
-    /**
678
-     * This simply sets up the row class for the table rows.
679
-     * Allows for easier overriding of child methods for setting up sorting.
680
-     *
681
-     * @param EE_Base_Class $item the current item
682
-     * @return string
683
-     */
684
-    protected function _get_row_class($item)
685
-    {
686
-        static $row_class = '';
687
-        $row_class = ($row_class === '' ? 'alternate' : '');
688
-
689
-        $new_row_class = $row_class;
690
-
691
-        if (! empty($this->_ajax_sorting_callback)) {
692
-            $new_row_class .= ' rowsortable';
693
-        }
694
-
695
-        return $new_row_class;
696
-    }
697
-
698
-
699
-    /**
700
-     * @return array
701
-     */
702
-    public function get_sortable_columns()
703
-    {
704
-        return (array) $this->_sortable_columns;
705
-    }
706
-
707
-
708
-    /**
709
-     * @return string
710
-     */
711
-    public function get_ajax_sorting_callback()
712
-    {
713
-        return $this->_ajax_sorting_callback;
714
-    }
715
-
716
-
717
-    /**
718
-     * @return array
719
-     */
720
-    public function get_hidden_columns()
721
-    {
722
-        $user_id     = get_current_user_id();
723
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
724
-        if (empty($has_default) && ! empty($this->_hidden_columns)) {
725
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
726
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
727
-        }
728
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
729
-        return (array) get_user_option($ref, $user_id);
730
-    }
731
-
732
-
733
-    /**
734
-     * Generates the columns for a single row of the table.
735
-     * Overridden from wp_list_table so as to allow us to filter the column content for a given
736
-     * column.
737
-     *
738
-     * @param EE_Base_Class $item The current item
739
-     * @since 3.1.0
740
-     */
741
-    public function single_row_columns($item)
742
-    {
743
-        [$columns, $hidden, $sortable, $primary] = $this->get_column_info();
744
-
745
-        foreach ($columns as $column_name => $column_display_name) {
746
-
747
-            /**
748
-             * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
749
-             * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
750
-             */
751
-            $hidden_class = in_array($column_name, $hidden) ? ' hidden' : '';
752
-
753
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
754
-            if ($primary === $column_name) {
755
-                $classes .= ' has-row-actions column-primary';
756
-            }
757
-
758
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
759
-
760
-            $class = 'class="' . esc_attr($classes) . '"';
761
-
762
-            $attributes = "{$class}{$data}";
763
-
764
-            if ($column_name === 'cb') {
765
-                echo '<th scope="row" class="check-column">';
766
-                echo apply_filters(
767
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
768
-                    $this->column_cb($item), // already escaped
769
-                    $item,
770
-                    $this
771
-                );
772
-                echo '</th>';
773
-            } elseif (method_exists($this, 'column_' . $column_name)) {
774
-                echo "<td $attributes>"; // already escaped
775
-                echo apply_filters(
776
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
777
-                    call_user_func([$this, 'column_' . $column_name], $item),
778
-                    $item,
779
-                    $this
780
-                );
781
-                echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
782
-                echo "</td>";
783
-            } else {
784
-                echo "<td $attributes>"; // already escaped
785
-                echo apply_filters(
786
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
787
-                    $this->column_default($item, $column_name),
788
-                    $item,
789
-                    $column_name,
790
-                    $this
791
-                );
792
-                echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
793
-                echo "</td>";
794
-            }
795
-        }
796
-    }
797
-
798
-
799
-    /**
800
-     * Extra controls to be displayed between bulk actions and pagination
801
-     *
802
-     * @access public
803
-     * @param string $which
804
-     * @throws EE_Error
805
-     */
806
-    public function extra_tablenav($which)
807
-    {
808
-        if ($which === 'top') {
809
-            $this->_filters();
810
-            echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags());
811
-        } else {
812
-            echo '<div class="list-table-bottom-buttons alignleft actions">';
813
-            foreach ($this->_bottom_buttons as $type => $action) {
814
-                $route         = $action['route'] ?? '';
815
-                $extra_request = $action['extra_request'] ?? '';
816
-                $btn_class     = $action['btn_class'] ?? 'button button--secondary';
817
-                // already escaped
818
-                echo wp_kses($this->_admin_page->get_action_link_or_button(
819
-                    $route,
820
-                    $type,
821
-                    $extra_request,
822
-                    $btn_class
823
-                ), AllowedTags::getWithFormTags());
824
-            }
825
-            do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
826
-            echo '</div>';
827
-        }
828
-    }
829
-
830
-
831
-    /**
832
-     * Get an associative array ( option_name => option_title ) with the list
833
-     * of bulk actions available on this table.
834
-     *
835
-     * @return array
836
-     * @since  3.1.0
837
-     * @access protected
838
-     */
839
-    public function get_bulk_actions()
840
-    {
841
-        return (array) $this->_get_bulk_actions();
842
-    }
843
-
844
-
845
-    /**
846
-     * Processing bulk actions.
847
-     */
848
-    public function process_bulk_action()
849
-    {
850
-        // this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
851
-        // reference in case there is a case where it gets used.
852
-    }
853
-
854
-
855
-    /**
856
-     * returns the EE admin page this list table is associated with
857
-     *
858
-     * @return EE_Admin_Page
859
-     */
860
-    public function get_admin_page()
861
-    {
862
-        return $this->_admin_page;
863
-    }
864
-
865
-
866
-    /**
867
-     * A "helper" function for all children to provide an html string of
868
-     * actions to output in their content.  It is preferable for child classes
869
-     * to use this method for generating their actions content so that it's
870
-     * filterable by plugins
871
-     *
872
-     * @param string        $action_container           what are the html container
873
-     *                                                  elements for this actions string?
874
-     * @param string        $action_class               What class is for the container
875
-     *                                                  element.
876
-     * @param string        $action_items               The contents for the action items
877
-     *                                                  container.  This is filtered before
878
-     *                                                  returned.
879
-     * @param string        $action_id                  What id (optional) is used for the
880
-     *                                                  container element.
881
-     * @param EE_Base_Class $item                       The object for the column displaying
882
-     *                                                  the actions.
883
-     * @return string The assembled action elements container.
884
-     */
885
-    protected function _action_string(
886
-        $action_items,
887
-        $item,
888
-        $action_container = 'ul',
889
-        $action_class = '',
890
-        $action_id = ''
891
-    ) {
892
-        $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : '';
893
-        $action_id    = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : '';
894
-        $open_tag     = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
895
-        $close_tag    = ! empty($action_container) ? '</' . $action_container . '>' : '';
896
-        try {
897
-            $content = apply_filters(
898
-                'FHEE__EE_Admin_List_Table___action_string__action_items',
899
-                $action_items,
900
-                $item,
901
-                $this
902
-            );
903
-        } catch (Exception $e) {
904
-            if (WP_DEBUG) {
905
-                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
906
-            }
907
-            $content = $action_items;
908
-        }
909
-        return "{$open_tag}{$content}{$close_tag}";
910
-    }
911
-
912
-
913
-    /**
914
-     * @return string
915
-     */
916
-    protected function getReturnUrl()
917
-    {
918
-        $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST');
919
-        $uri  = $this->_admin_page->get_request()->getServerParam('REQUEST_URI');
920
-        return urlencode(esc_url_raw("//{$host}{$uri}"));
921
-    }
922
-
923
-
924
-    /**
925
-     * @param string $id
926
-     * @param string $content
927
-     * @param string $align     start (default), center, end
928
-     * @return string
929
-     * @since   $VID:$
930
-     */
931
-    protected function columnContent($id, $content, $align = 'start')
932
-    {
933
-        if (! isset($this->_columns[ $id ])) {
934
-            throw new DomainException('missing column id');
935
-        }
936
-        $heading = $id !== 'cb' ? $this->_columns[ $id ] : '';
937
-        $align = in_array($align, ['start', 'center', 'end']) ? $align : 'start';
938
-        $align = "ee-responsive-table-cell--{$align}";
939
-
940
-        $html = "<div class='ee-responsive-table-cell ee-responsive-table-cell--column-{$id} {$align} ee-layout-row'>";
941
-        $html .= "<div class='ee-responsive-table-cell__heading'>{$heading}</div>";
942
-        $html .= "<div class='ee-responsive-table-cell__content ee-layout-row'>{$content}</div>";
943
-        $html .= "</div>";
944
-        return $html;
945
-    }
946
-
947
-
948
-    protected function actionsModalMenu($actions): string
949
-    {
950
-        return '
513
+	}
514
+
515
+
516
+	/**
517
+	 * Callback for 'list_table_primary_column' WordPress filter
518
+	 * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
519
+	 * column when class is instantiated.
520
+	 *
521
+	 * @param string $column_name
522
+	 * @return string
523
+	 * @see WP_List_Table::get_primary_column_name
524
+	 */
525
+	public function set_primary_column($column_name)
526
+	{
527
+		return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
528
+	}
529
+
530
+
531
+	/**
532
+	 *
533
+	 */
534
+	public function prepare_items()
535
+	{
536
+		$this->_set_column_info();
537
+		// $this->_column_headers = $this->get_column_info();
538
+		$total_items = $this->_all_data_count;
539
+		$this->process_bulk_action();
540
+
541
+		$this->items = $this->_data;
542
+		$this->set_pagination_args(
543
+			[
544
+				'total_items' => $total_items,
545
+				'per_page'    => $this->_per_page,
546
+				'total_pages' => ceil($total_items / $this->_per_page),
547
+			]
548
+		);
549
+	}
550
+
551
+
552
+	/**
553
+	 * @param object|array $item
554
+	 * @return string html content for the column
555
+	 */
556
+	protected function column_cb($item)
557
+	{
558
+		return '';
559
+	}
560
+
561
+
562
+	/**
563
+	 * This column is the default for when there is no defined column method for a registered column.
564
+	 * This can be overridden by child classes, but allows for hooking in for custom columns.
565
+	 *
566
+	 * @param EE_Base_Class $item
567
+	 * @param string        $column_name The column being called.
568
+	 * @return string html content for the column
569
+	 */
570
+	public function column_default($item, $column_name)
571
+	{
572
+		/**
573
+		 * Dynamic hook allowing for adding additional column content in this list table.
574
+		 * Note that $this->screen->id is in the format
575
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
576
+		 * table it is: event-espresso_page_espresso_messages.
577
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
578
+		 * hook prefix ("event-espresso") will be different.
579
+		 */
580
+		ob_start();
581
+		do_action(
582
+			'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
583
+			$item,
584
+			$this->_screen
585
+		);
586
+		return ob_get_clean();
587
+	}
588
+
589
+
590
+	/**
591
+	 * Get a list of columns. The format is:
592
+	 * 'internal-name' => 'Title'
593
+	 *
594
+	 * @return array
595
+	 * @since  3.1.0
596
+	 * @access public
597
+	 * @abstract
598
+	 */
599
+	public function get_columns()
600
+	{
601
+		/**
602
+		 * Dynamic hook allowing for adding additional columns in this list table.
603
+		 * Note that $this->screen->id is in the format
604
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
605
+		 * table it is: event-espresso_page_espresso_messages.
606
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
607
+		 * hook prefix ("event-espresso") will be different.
608
+		 *
609
+		 * @var array
610
+		 */
611
+		return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
612
+	}
613
+
614
+
615
+	/**
616
+	 * Get an associative array ( id => link ) with the list
617
+	 * of views available on this table.
618
+	 *
619
+	 * @return array
620
+	 * @since  3.1.0
621
+	 * @access protected
622
+	 */
623
+	public function get_views()
624
+	{
625
+		return $this->_views;
626
+	}
627
+
628
+
629
+	/**
630
+	 * Generate the views html.
631
+	 */
632
+	public function display_views()
633
+	{
634
+		$views           = $this->get_views();
635
+		$assembled_views = [];
636
+
637
+		if (empty($views)) {
638
+			return;
639
+		}
640
+		echo "<ul class='subsubsub'>\n";
641
+		foreach ($views as $view) {
642
+			$count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
643
+			if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
644
+				$filter = "<li";
645
+				$filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : '';
646
+				$filter .= ">";
647
+				$filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>';
648
+				$filter .= '<span class="count">(' . $count . ')</span>';
649
+				$filter .= '</li>';
650
+				$assembled_views[ $view['slug'] ] = $filter;
651
+			}
652
+		}
653
+
654
+		echo ! empty($assembled_views)
655
+			? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views)
656
+			: '';
657
+		echo "</ul>";
658
+	}
659
+
660
+
661
+	/**
662
+	 * Generates content for a single row of the table
663
+	 *
664
+	 * @param EE_Base_Class $item The current item
665
+	 * @since  4.1
666
+	 * @access public
667
+	 */
668
+	public function single_row($item)
669
+	{
670
+		$row_class = $this->_get_row_class($item);
671
+		echo '<tr class="' . esc_attr($row_class) . '">';
672
+		$this->single_row_columns($item); // already escaped
673
+		echo '</tr>';
674
+	}
675
+
676
+
677
+	/**
678
+	 * This simply sets up the row class for the table rows.
679
+	 * Allows for easier overriding of child methods for setting up sorting.
680
+	 *
681
+	 * @param EE_Base_Class $item the current item
682
+	 * @return string
683
+	 */
684
+	protected function _get_row_class($item)
685
+	{
686
+		static $row_class = '';
687
+		$row_class = ($row_class === '' ? 'alternate' : '');
688
+
689
+		$new_row_class = $row_class;
690
+
691
+		if (! empty($this->_ajax_sorting_callback)) {
692
+			$new_row_class .= ' rowsortable';
693
+		}
694
+
695
+		return $new_row_class;
696
+	}
697
+
698
+
699
+	/**
700
+	 * @return array
701
+	 */
702
+	public function get_sortable_columns()
703
+	{
704
+		return (array) $this->_sortable_columns;
705
+	}
706
+
707
+
708
+	/**
709
+	 * @return string
710
+	 */
711
+	public function get_ajax_sorting_callback()
712
+	{
713
+		return $this->_ajax_sorting_callback;
714
+	}
715
+
716
+
717
+	/**
718
+	 * @return array
719
+	 */
720
+	public function get_hidden_columns()
721
+	{
722
+		$user_id     = get_current_user_id();
723
+		$has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
724
+		if (empty($has_default) && ! empty($this->_hidden_columns)) {
725
+			update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
726
+			update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
727
+		}
728
+		$ref = 'manage' . $this->screen->id . 'columnshidden';
729
+		return (array) get_user_option($ref, $user_id);
730
+	}
731
+
732
+
733
+	/**
734
+	 * Generates the columns for a single row of the table.
735
+	 * Overridden from wp_list_table so as to allow us to filter the column content for a given
736
+	 * column.
737
+	 *
738
+	 * @param EE_Base_Class $item The current item
739
+	 * @since 3.1.0
740
+	 */
741
+	public function single_row_columns($item)
742
+	{
743
+		[$columns, $hidden, $sortable, $primary] = $this->get_column_info();
744
+
745
+		foreach ($columns as $column_name => $column_display_name) {
746
+
747
+			/**
748
+			 * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
749
+			 * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
750
+			 */
751
+			$hidden_class = in_array($column_name, $hidden) ? ' hidden' : '';
752
+
753
+			$classes = $column_name . ' column-' . $column_name . $hidden_class;
754
+			if ($primary === $column_name) {
755
+				$classes .= ' has-row-actions column-primary';
756
+			}
757
+
758
+			$data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
759
+
760
+			$class = 'class="' . esc_attr($classes) . '"';
761
+
762
+			$attributes = "{$class}{$data}";
763
+
764
+			if ($column_name === 'cb') {
765
+				echo '<th scope="row" class="check-column">';
766
+				echo apply_filters(
767
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
768
+					$this->column_cb($item), // already escaped
769
+					$item,
770
+					$this
771
+				);
772
+				echo '</th>';
773
+			} elseif (method_exists($this, 'column_' . $column_name)) {
774
+				echo "<td $attributes>"; // already escaped
775
+				echo apply_filters(
776
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
777
+					call_user_func([$this, 'column_' . $column_name], $item),
778
+					$item,
779
+					$this
780
+				);
781
+				echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
782
+				echo "</td>";
783
+			} else {
784
+				echo "<td $attributes>"; // already escaped
785
+				echo apply_filters(
786
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
787
+					$this->column_default($item, $column_name),
788
+					$item,
789
+					$column_name,
790
+					$this
791
+				);
792
+				echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
793
+				echo "</td>";
794
+			}
795
+		}
796
+	}
797
+
798
+
799
+	/**
800
+	 * Extra controls to be displayed between bulk actions and pagination
801
+	 *
802
+	 * @access public
803
+	 * @param string $which
804
+	 * @throws EE_Error
805
+	 */
806
+	public function extra_tablenav($which)
807
+	{
808
+		if ($which === 'top') {
809
+			$this->_filters();
810
+			echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags());
811
+		} else {
812
+			echo '<div class="list-table-bottom-buttons alignleft actions">';
813
+			foreach ($this->_bottom_buttons as $type => $action) {
814
+				$route         = $action['route'] ?? '';
815
+				$extra_request = $action['extra_request'] ?? '';
816
+				$btn_class     = $action['btn_class'] ?? 'button button--secondary';
817
+				// already escaped
818
+				echo wp_kses($this->_admin_page->get_action_link_or_button(
819
+					$route,
820
+					$type,
821
+					$extra_request,
822
+					$btn_class
823
+				), AllowedTags::getWithFormTags());
824
+			}
825
+			do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
826
+			echo '</div>';
827
+		}
828
+	}
829
+
830
+
831
+	/**
832
+	 * Get an associative array ( option_name => option_title ) with the list
833
+	 * of bulk actions available on this table.
834
+	 *
835
+	 * @return array
836
+	 * @since  3.1.0
837
+	 * @access protected
838
+	 */
839
+	public function get_bulk_actions()
840
+	{
841
+		return (array) $this->_get_bulk_actions();
842
+	}
843
+
844
+
845
+	/**
846
+	 * Processing bulk actions.
847
+	 */
848
+	public function process_bulk_action()
849
+	{
850
+		// this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
851
+		// reference in case there is a case where it gets used.
852
+	}
853
+
854
+
855
+	/**
856
+	 * returns the EE admin page this list table is associated with
857
+	 *
858
+	 * @return EE_Admin_Page
859
+	 */
860
+	public function get_admin_page()
861
+	{
862
+		return $this->_admin_page;
863
+	}
864
+
865
+
866
+	/**
867
+	 * A "helper" function for all children to provide an html string of
868
+	 * actions to output in their content.  It is preferable for child classes
869
+	 * to use this method for generating their actions content so that it's
870
+	 * filterable by plugins
871
+	 *
872
+	 * @param string        $action_container           what are the html container
873
+	 *                                                  elements for this actions string?
874
+	 * @param string        $action_class               What class is for the container
875
+	 *                                                  element.
876
+	 * @param string        $action_items               The contents for the action items
877
+	 *                                                  container.  This is filtered before
878
+	 *                                                  returned.
879
+	 * @param string        $action_id                  What id (optional) is used for the
880
+	 *                                                  container element.
881
+	 * @param EE_Base_Class $item                       The object for the column displaying
882
+	 *                                                  the actions.
883
+	 * @return string The assembled action elements container.
884
+	 */
885
+	protected function _action_string(
886
+		$action_items,
887
+		$item,
888
+		$action_container = 'ul',
889
+		$action_class = '',
890
+		$action_id = ''
891
+	) {
892
+		$action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : '';
893
+		$action_id    = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : '';
894
+		$open_tag     = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
895
+		$close_tag    = ! empty($action_container) ? '</' . $action_container . '>' : '';
896
+		try {
897
+			$content = apply_filters(
898
+				'FHEE__EE_Admin_List_Table___action_string__action_items',
899
+				$action_items,
900
+				$item,
901
+				$this
902
+			);
903
+		} catch (Exception $e) {
904
+			if (WP_DEBUG) {
905
+				EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
906
+			}
907
+			$content = $action_items;
908
+		}
909
+		return "{$open_tag}{$content}{$close_tag}";
910
+	}
911
+
912
+
913
+	/**
914
+	 * @return string
915
+	 */
916
+	protected function getReturnUrl()
917
+	{
918
+		$host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST');
919
+		$uri  = $this->_admin_page->get_request()->getServerParam('REQUEST_URI');
920
+		return urlencode(esc_url_raw("//{$host}{$uri}"));
921
+	}
922
+
923
+
924
+	/**
925
+	 * @param string $id
926
+	 * @param string $content
927
+	 * @param string $align     start (default), center, end
928
+	 * @return string
929
+	 * @since   $VID:$
930
+	 */
931
+	protected function columnContent($id, $content, $align = 'start')
932
+	{
933
+		if (! isset($this->_columns[ $id ])) {
934
+			throw new DomainException('missing column id');
935
+		}
936
+		$heading = $id !== 'cb' ? $this->_columns[ $id ] : '';
937
+		$align = in_array($align, ['start', 'center', 'end']) ? $align : 'start';
938
+		$align = "ee-responsive-table-cell--{$align}";
939
+
940
+		$html = "<div class='ee-responsive-table-cell ee-responsive-table-cell--column-{$id} {$align} ee-layout-row'>";
941
+		$html .= "<div class='ee-responsive-table-cell__heading'>{$heading}</div>";
942
+		$html .= "<div class='ee-responsive-table-cell__content ee-layout-row'>{$content}</div>";
943
+		$html .= "</div>";
944
+		return $html;
945
+	}
946
+
947
+
948
+	protected function actionsModalMenu($actions): string
949
+	{
950
+		return '
951 951
         <div class="ee-modal-menu">
952 952
             <button class="ee-modal-menu__button button button--secondary button--icon-only ee-aria-tooltip"
953 953
                     aria-label="' . esc_attr__('list table actions menu', 'event_espresso') . '"
@@ -959,24 +959,24 @@  discard block
 block discarded – undo
959 959
                 ' . $actions . '
960 960
             </div>
961 961
         </div>';
962
-    }
962
+	}
963 963
 
964 964
 
965
-    protected function actionsColumnHeader(): string
966
-    {
967
-        return '
965
+	protected function actionsColumnHeader(): string
966
+	{
967
+		return '
968 968
             <span class="ee-actions-column-header-wrap">
969 969
                 <span class="dashicons dashicons-screenoptions"></span>
970 970
                 <span class="ee-actions-column-header">' . esc_html__('Actions', 'event_espresso') . '</span>
971 971
             </span>';
972
-    }
972
+	}
973 973
 
974 974
 
975
-    protected function getActionLink(string $url, string $display_text, string $label, $class = ''): string
976
-    {
977
-        $class = ! empty($class) ? "{$class} ee-list-table-action" : 'ee-list-table-action';
978
-        $class = ! empty($label) ? "{$class} ee-aria-tooltip" : $class;
979
-        $label = ! empty($label) ? " aria-label='{$label}'" : '';
980
-        return "<a href='{$url}' class='{$class}'{$label}>{$display_text}</a>";
981
-    }
975
+	protected function getActionLink(string $url, string $display_text, string $label, $class = ''): string
976
+	{
977
+		$class = ! empty($class) ? "{$class} ee-list-table-action" : 'ee-list-table-action';
978
+		$class = ! empty($label) ? "{$class} ee-aria-tooltip" : $class;
979
+		$label = ! empty($label) ? " aria-label='{$label}'" : '';
980
+		return "<a href='{$url}' class='{$class}'{$label}>{$display_text}</a>";
981
+	}
982 982
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4645 added lines, -4645 removed lines patch added patch discarded remove patch
@@ -17,2688 +17,2688 @@  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
-                    'icon' => 'dashicons-email',
588
-                    'order' => 10,
589
-                ],
590
-                'list_table'    => 'EE_Message_List_Table',
591
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
592
-                'require_nonce' => false,
593
-            ],
594
-            'global_mtps'              => [
595
-                'nav'           => [
596
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
597
-                    'icon' => 'dashicons-layout',
598
-                    'order' => 20,
599
-                ],
600
-                'list_table'    => 'Messages_Template_List_Table',
601
-                'help_tabs'     => [
602
-                    'messages_overview_help_tab'                                => [
603
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
604
-                        'filename' => 'messages_overview',
605
-                    ],
606
-                    'messages_overview_messages_table_column_headings_help_tab' => [
607
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
608
-                        'filename' => 'messages_overview_table_column_headings',
609
-                    ],
610
-                    'messages_overview_messages_filters_help_tab'               => [
611
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
612
-                        'filename' => 'messages_overview_filters',
613
-                    ],
614
-                    'messages_overview_messages_views_help_tab'                 => [
615
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
616
-                        'filename' => 'messages_overview_views',
617
-                    ],
618
-                    'message_overview_message_types_help_tab'                   => [
619
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
620
-                        'filename' => 'messages_overview_types',
621
-                    ],
622
-                    'messages_overview_messengers_help_tab'                     => [
623
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
624
-                        'filename' => 'messages_overview_messengers',
625
-                    ],
626
-                ],
627
-                'require_nonce' => false,
628
-            ],
629
-            'custom_mtps'              => [
630
-                'nav'           => [
631
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
632
-                    'icon' => 'dashicons-admin-customizer',
633
-                    'order' => 30,
634
-                ],
635
-                'help_tabs'     => [],
636
-                'require_nonce' => false,
637
-            ],
638
-            'add_new_message_template' => [
639
-                'nav'           => [
640
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
641
-                    'icon' => 'dashicons-plus-alt',
642
-                    'order'      => 5,
643
-                    'persistent' => false,
644
-                ],
645
-                'require_nonce' => false,
646
-            ],
647
-            'edit_message_template'    => [
648
-                'labels'        => [
649
-                    'buttons'    => [
650
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
651
-                    ],
652
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
653
-                ],
654
-                'nav'           => [
655
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
656
-                    'icon' => 'dashicons-edit-large',
657
-                    'order'      => 5,
658
-                    'persistent' => false,
659
-                    'url'        => '',
660
-                ],
661
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
662
-                'has_metaboxes' => true,
663
-                'help_tabs'     => [
664
-                    'edit_message_template'            => [
665
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
666
-                        'callback' => 'edit_message_template_help_tab',
667
-                    ],
668
-                    'message_templates_help_tab'       => [
669
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
670
-                        'filename' => 'messages_templates',
671
-                    ],
672
-                    'message_template_shortcodes'      => [
673
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
674
-                        'callback' => 'message_template_shortcodes_help_tab',
675
-                    ],
676
-                    'message_preview_help_tab'         => [
677
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
678
-                        'filename' => 'messages_preview',
679
-                    ],
680
-                    'messages_overview_other_help_tab' => [
681
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
682
-                        'filename' => 'messages_overview_other',
683
-                    ],
684
-                ],
685
-                'require_nonce' => false,
686
-            ],
687
-            'display_preview_message'  => [
688
-                'nav'           => [
689
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
690
-                    'icon' => 'dashicons-visibility-bar',
691
-                    'order'      => 5,
692
-                    'url'        => '',
693
-                    'persistent' => false,
694
-                ],
695
-                'help_tabs'     => [
696
-                    'preview_message' => [
697
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
698
-                        'callback' => 'preview_message_help_tab',
699
-                    ],
700
-                ],
701
-                'require_nonce' => false,
702
-            ],
703
-            'settings'                 => [
704
-                'nav'           => [
705
-                    'label' => esc_html__('Settings', 'event_espresso'),
706
-                    'icon' => 'dashicons-admin-generic',
707
-                    'order' => 40,
708
-                ],
709
-                'metaboxes'     => ['_messages_settings_metaboxes'],
710
-                'help_tabs'     => [
711
-                    'messages_settings_help_tab'               => [
712
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
713
-                        'filename' => 'messages_settings',
714
-                    ],
715
-                    'messages_settings_message_types_help_tab' => [
716
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
717
-                        'filename' => 'messages_settings_message_types',
718
-                    ],
719
-                    'messages_settings_messengers_help_tab'    => [
720
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
721
-                        'filename' => 'messages_settings_messengers',
722
-                    ],
723
-                ],
724
-                'require_nonce' => false,
725
-            ],
726
-        ];
727
-    }
728
-
729
-
730
-    protected function _add_screen_options()
731
-    {
732
-        // todo
733
-    }
734
-
735
-
736
-    protected function _add_screen_options_global_mtps()
737
-    {
738
-        /**
739
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
740
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
741
-         */
742
-        $page_title              = $this->_admin_page_title;
743
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
744
-        $this->_per_page_screen_option();
745
-        $this->_admin_page_title = $page_title;
746
-    }
747
-
748
-
749
-    protected function _add_screen_options_default()
750
-    {
751
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
752
-        $this->_per_page_screen_option();
753
-    }
754
-
755
-
756
-    // none of the below group are currently used for Messages
757
-    protected function _add_feature_pointers()
758
-    {
759
-    }
760
-
761
-
762
-    public function admin_init()
763
-    {
764
-    }
765
-
766
-
767
-    public function admin_notices()
768
-    {
769
-    }
770
-
771
-
772
-    public function admin_footer_scripts()
773
-    {
774
-    }
775
-
776
-
777
-    public function messages_help_tab()
778
-    {
779
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
780
-    }
781
-
782
-
783
-    public function messengers_help_tab()
784
-    {
785
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
786
-    }
787
-
788
-
789
-    public function message_types_help_tab()
790
-    {
791
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
792
-    }
793
-
794
-
795
-    public function messages_overview_help_tab()
796
-    {
797
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
798
-    }
799
-
800
-
801
-    public function message_templates_help_tab()
802
-    {
803
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
804
-    }
805
-
806
-
807
-    public function edit_message_template_help_tab()
808
-    {
809
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
810
-                        . esc_attr__('Editor Title', 'event_espresso')
811
-                        . '" />';
812
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
813
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
814
-                        . '" />';
815
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
816
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
817
-                        . '" />';
818
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
819
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
820
-                        . '" />';
821
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
822
-                        . esc_attr__('Publish Metabox', 'event_espresso')
823
-                        . '" />';
824
-        EEH_Template::display_template(
825
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
826
-            $args
827
-        );
828
-    }
829
-
830
-
831
-    /**
832
-     * @throws ReflectionException
833
-     * @throws EE_Error
834
-     */
835
-    public function message_template_shortcodes_help_tab()
836
-    {
837
-        $this->_set_shortcodes();
838
-        $args['shortcodes'] = $this->_shortcodes;
839
-        EEH_Template::display_template(
840
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
841
-            $args
842
-        );
843
-    }
844
-
845
-
846
-    public function preview_message_help_tab()
847
-    {
848
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
849
-    }
850
-
851
-
852
-    public function settings_help_tab()
853
-    {
854
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
855
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
856
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
857
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
858
-        $args['img3'] = '<div class="ee-switch">'
859
-                        . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
860
-                        . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
861
-                        . '</div>';
862
-        $args['img4'] = '<div class="switch">'
863
-                        . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
864
-                        . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
865
-                        . '</div>';
866
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
867
-    }
868
-
869
-
870
-    public function load_scripts_styles()
871
-    {
872
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
873
-        wp_enqueue_style('espresso_ee_msg');
874
-
875
-        wp_register_script(
876
-            'ee-messages-settings',
877
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
878
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
879
-            EVENT_ESPRESSO_VERSION,
880
-            true
881
-        );
882
-        wp_register_script(
883
-            'ee-msg-list-table-js',
884
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
885
-            ['ee-dialog'],
886
-            EVENT_ESPRESSO_VERSION
887
-        );
888
-    }
889
-
890
-
891
-    public function load_scripts_styles_default()
892
-    {
893
-        wp_enqueue_script('ee-msg-list-table-js');
894
-    }
895
-
896
-
897
-    public function wp_editor_css($mce_css)
898
-    {
899
-        // if we're on the edit_message_template route
900
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
901
-            $message_type_name = $this->_active_message_type_name;
902
-
903
-            // we're going to REPLACE the existing mce css
904
-            // we need to get the css file location from the active messenger
905
-            $mce_css = $this->_active_messenger->get_variation(
906
-                $this->_template_pack,
907
-                $message_type_name,
908
-                true,
909
-                'wpeditor',
910
-                $this->_variation
911
-            );
912
-        }
913
-
914
-        return $mce_css;
915
-    }
916
-
917
-
918
-    /**
919
-     * @throws EE_Error
920
-     * @throws ReflectionException
921
-     */
922
-    public function load_scripts_styles_edit_message_template()
923
-    {
924
-
925
-        $this->_set_shortcodes();
926
-
927
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
928
-            esc_html__(
929
-                '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.',
930
-                'event_espresso'
931
-            ),
932
-            $this->_message_template_group->messenger_obj()->label['singular'],
933
-            $this->_message_template_group->message_type_obj()->label['singular']
934
-        );
935
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
936
-            '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?',
937
-            'event_espresso'
938
-        );
939
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
940
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
941
-            'event_espresso'
942
-        );
943
-
944
-        wp_register_script(
945
-            'ee_msgs_edit_js',
946
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
947
-            ['jquery'],
948
-            EVENT_ESPRESSO_VERSION
949
-        );
950
-
951
-        wp_enqueue_script('ee_admin_js');
952
-        wp_enqueue_script('ee_msgs_edit_js');
953
-
954
-        // add in special css for tiny_mce
955
-        add_filter('mce_css', [$this, 'wp_editor_css']);
956
-    }
957
-
958
-
959
-    /**
960
-     * @throws EE_Error
961
-     * @throws ReflectionException
962
-     */
963
-    public function load_scripts_styles_display_preview_message()
964
-    {
965
-        $this->_set_message_template_group();
966
-        if ($this->_active_messenger_name) {
967
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
968
-                $this->_active_messenger_name
969
-            );
970
-        }
971
-
972
-        wp_enqueue_style(
973
-            'espresso_preview_css',
974
-            $this->_active_messenger->get_variation(
975
-                $this->_template_pack,
976
-                $this->_active_message_type_name,
977
-                true,
978
-                'preview',
979
-                $this->_variation
980
-            )
981
-        );
982
-    }
983
-
984
-
985
-    public function load_scripts_styles_settings()
986
-    {
987
-        wp_register_style(
988
-            'ee-message-settings',
989
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
990
-            [],
991
-            EVENT_ESPRESSO_VERSION
992
-        );
993
-        wp_enqueue_style('ee-text-links');
994
-        wp_enqueue_style('ee-message-settings');
995
-        wp_enqueue_script('ee-messages-settings');
996
-    }
997
-
998
-
999
-    /**
1000
-     * set views array for List Table
1001
-     */
1002
-    public function _set_list_table_views_global_mtps()
1003
-    {
1004
-        $this->_views = [
1005
-            'in_use' => [
1006
-                'slug'  => 'in_use',
1007
-                'label' => esc_html__('In Use', 'event_espresso'),
1008
-                'count' => 0,
1009
-            ],
1010
-        ];
1011
-    }
1012
-
1013
-
1014
-    /**
1015
-     * Set views array for the Custom Template List Table
1016
-     */
1017
-    public function _set_list_table_views_custom_mtps()
1018
-    {
1019
-        $this->_set_list_table_views_global_mtps();
1020
-        $this->_views['in_use']['bulk_action'] = [
1021
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1022
-        ];
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * set views array for message queue list table
1028
-     *
1029
-     * @throws InvalidDataTypeException
1030
-     * @throws InvalidInterfaceException
1031
-     * @throws InvalidArgumentException
1032
-     * @throws EE_Error
1033
-     * @throws ReflectionException
1034
-     */
1035
-    public function _set_list_table_views_default()
1036
-    {
1037
-        EE_Registry::instance()->load_helper('Template');
1038
-
1039
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1040
-            'ee_send_message',
1041
-            'message_list_table_bulk_actions'
1042
-        )
1043
-            ? [
1044
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1045
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1046
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1047
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1048
-            ]
1049
-            : [];
1050
-
1051
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1052
-            'ee_delete_messages',
1053
-            'message_list_table_bulk_actions'
1054
-        )
1055
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1056
-            : [];
1057
-
1058
-
1059
-        $this->_views = [
1060
-            'all' => [
1061
-                'slug'        => 'all',
1062
-                'label'       => esc_html__('All', 'event_espresso'),
1063
-                'count'       => 0,
1064
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1065
-            ],
1066
-        ];
1067
-
1068
-
1069
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1070
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1071
-                continue;
1072
-            }
1073
-            $status_bulk_actions = $common_bulk_actions;
1074
-            // unset bulk actions not applying to status
1075
-            if (! empty($status_bulk_actions)) {
1076
-                switch ($status) {
1077
-                    case EEM_Message::status_idle:
1078
-                    case EEM_Message::status_resend:
1079
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1080
-                        break;
1081
-
1082
-                    case EEM_Message::status_failed:
1083
-                    case EEM_Message::status_debug_only:
1084
-                    case EEM_Message::status_messenger_executing:
1085
-                        $status_bulk_actions = [];
1086
-                        break;
1087
-
1088
-                    case EEM_Message::status_incomplete:
1089
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1090
-                        break;
1091
-
1092
-                    case EEM_Message::status_retry:
1093
-                    case EEM_Message::status_sent:
1094
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1095
-                        break;
1096
-                }
1097
-            }
1098
-
1099
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1100
-            if ($status === EEM_Message::status_messenger_executing) {
1101
-                continue;
1102
-            }
1103
-
1104
-            $this->_views[ strtolower($status) ] = [
1105
-                'slug'        => strtolower($status),
1106
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1107
-                'count'       => 0,
1108
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1109
-            ];
1110
-        }
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     * @throws EE_Error
1116
-     */
1117
-    protected function _ee_default_messages_overview_list_table()
1118
-    {
1119
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1120
-        $this->display_admin_list_table_page_with_no_sidebar();
1121
-    }
1122
-
1123
-
1124
-    /**
1125
-     * @throws EE_Error
1126
-     * @throws ReflectionException
1127
-     */
1128
-    protected function _message_queue_list_table()
1129
-    {
1130
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1131
-        $this->_template_args['per_column']        = 6;
1132
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1133
-        $message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1134
-        $this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1135
-        $this->display_admin_list_table_page_with_no_sidebar();
1136
-    }
1137
-
1138
-
1139
-    /**
1140
-     * @throws EE_Error
1141
-     */
1142
-    protected function _message_legend_items()
1143
-    {
1144
-
1145
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1146
-        $action_items       = [];
1147
-
1148
-        foreach ($action_css_classes as $action_item => $action_details) {
1149
-            if ($action_item === 'see_notifications_for') {
1150
-                continue;
1151
-            }
1152
-            $action_items[ $action_item ] = [
1153
-                'class' => $action_details['css_class'],
1154
-                'desc'  => $action_details['label'],
1155
-            ];
1156
-        }
1157
-
1158
-        /** @var array $status_items status legend setup */
1159
-        $status_items = [
1160
-            'sent_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1162
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1163
-            ],
1164
-            'idle_status'                => [
1165
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1166
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1167
-            ],
1168
-            'failed_status'              => [
1169
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1170
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1171
-            ],
1172
-            'messenger_executing_status' => [
1173
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1174
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1175
-            ],
1176
-            'resend_status'              => [
1177
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1178
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1179
-            ],
1180
-            'incomplete_status'          => [
1181
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1182
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1183
-            ],
1184
-            'retry_status'               => [
1185
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1186
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1187
-            ],
1188
-        ];
1189
-        if (EEM_Message::debug()) {
1190
-            $status_items['debug_only_status'] = [
1191
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1192
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1193
-            ];
1194
-        }
1195
-
1196
-        return array_merge($action_items, $status_items);
1197
-    }
1198
-
1199
-
1200
-    /**
1201
-     * @throws EE_Error
1202
-     */
1203
-    protected function _custom_mtps_preview()
1204
-    {
1205
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1206
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1207
-                                                . ' alt="' . esc_attr__(
1208
-                                                    'Preview Custom Message Templates screenshot',
1209
-                                                    'event_espresso'
1210
-                                                ) . '" />';
1211
-        $this->_template_args['preview_text'] = '<strong>'
1212
-                                                . esc_html__(
1213
-                                                    '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.',
1214
-                                                    'event_espresso'
1215
-                                                )
1216
-                                                . '</strong>';
1217
-
1218
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1219
-    }
1220
-
1221
-
1222
-    /**
1223
-     * get_message_templates
1224
-     * This gets all the message templates for listing on the overview list.
1225
-     *
1226
-     * @access public
1227
-     * @param int    $per_page the amount of templates groups to show per page
1228
-     * @param string $type     the current _view we're getting templates for
1229
-     * @param bool   $count    return count?
1230
-     * @param bool   $all      disregard any paging info (get all data);
1231
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1232
-     * @return array
1233
-     * @throws EE_Error
1234
-     * @throws InvalidArgumentException
1235
-     * @throws InvalidDataTypeException
1236
-     * @throws InvalidInterfaceException
1237
-     */
1238
-    public function get_message_templates(
1239
-        $per_page = 10,
1240
-        $type = 'in_use',
1241
-        $count = false,
1242
-        $all = false,
1243
-        $global = true
1244
-    ) {
1245
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1246
-        $this->request->setRequestParam('orderby', $orderby);
1247
-
1248
-        $order        = $this->request->getRequestParam('order', 'ASC');
1249
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1250
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1251
-
1252
-        $offset = ($current_page - 1) * $per_page;
1253
-        $limit  = $all ? null : [$offset, $per_page];
1254
-
1255
-        // options will match what is in the _views array property
1256
-        return $type === 'in_use'
1257
-            ? $this->getMtgModel()->get_all_active_message_templates(
1258
-                $orderby,
1259
-                $order,
1260
-                $limit,
1261
-                $count,
1262
-                $global,
1263
-                true
1264
-            )
1265
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1266
-                $orderby,
1267
-                $order,
1268
-                $limit,
1269
-                $count,
1270
-                $global
1271
-            );
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     * filters etc might need a list of installed message_types
1277
-     *
1278
-     * @return array an array of message type objects
1279
-     */
1280
-    public function get_installed_message_types()
1281
-    {
1282
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1283
-        $installed               = [];
1284
-
1285
-        foreach ($installed_message_types as $message_type) {
1286
-            $installed[ $message_type->name ] = $message_type;
1287
-        }
1288
-
1289
-        return $installed;
1290
-    }
1291
-
1292
-
1293
-    /**
1294
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1295
-     *
1296
-     * @param string $message_type
1297
-     * @param string $messenger
1298
-     * @param string $GRP_ID
1299
-     *
1300
-     * @throws EE_error
1301
-     * @throws ReflectionException
1302
-     */
1303
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1304
-    {
1305
-        // set values override any request data
1306
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1307
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1308
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1309
-
1310
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1311
-        if (empty($message_type) || empty($messenger)) {
1312
-            throw new EE_Error(
1313
-                esc_html__(
1314
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1315
-                    'event_espresso'
1316
-                )
1317
-            );
1318
-        }
1319
-
1320
-        // we need the GRP_ID for the template being used as the base for the new template
1321
-        if (empty($GRP_ID)) {
1322
-            throw new EE_Error(
1323
-                esc_html__(
1324
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1325
-                    'event_espresso'
1326
-                )
1327
-            );
1328
-        }
1329
-
1330
-        // let's just make sure the template gets generated!
1331
-
1332
-        // we need to reassign some variables for what the insert is expecting
1333
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1334
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1335
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1336
-
1337
-        $this->_insert_or_update_message_template(true);
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * @param string $message_type     message type slug
1343
-     * @param string $messenger        messenger slug
1344
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1345
-     *                                 off of.
1346
-     * @throws EE_error
1347
-     * @throws ReflectionException
1348
-     * @deprecated 4.10.29.p
1349
-     */
1350
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1351
-    {
1352
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1353
-    }
1354
-
1355
-
1356
-    /**
1357
-     * _edit_message_template
1358
-     *
1359
-     * @access protected
1360
-     * @return void
1361
-     * @throws InvalidIdentifierException
1362
-     * @throws DomainException
1363
-     * @throws EE_Error
1364
-     * @throws InvalidArgumentException
1365
-     * @throws ReflectionException
1366
-     * @throws InvalidDataTypeException
1367
-     * @throws InvalidInterfaceException
1368
-     */
1369
-    protected function _edit_message_template()
1370
-    {
1371
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1372
-        $template_fields = '';
1373
-        $sidebar_fields  = '';
1374
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1375
-        // valid html in the templates.
1376
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1377
-
1378
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1379
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1380
-
1381
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1382
-        $message_template_group = $this->_message_template_group;
1383
-        $c_label                = $message_template_group->context_label();
1384
-        $c_config               = $message_template_group->contexts_config();
1385
-
1386
-        reset($c_config);
1387
-        $context = $this->request->getRequestParam('context', key($c_config));
1388
-        $context = strtolower($context);
1389
-
1390
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1391
-
1392
-        $edit_message_template_form_url = add_query_arg(
1393
-            ['action' => $action, 'noheader' => true],
1394
-            EE_MSG_ADMIN_URL
1395
-        );
1396
-
1397
-        // set active messenger for this view
1398
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1399
-            $message_template_group->messenger()
1400
-        );
1401
-        $this->_active_message_type_name = $message_template_group->message_type();
1402
-
1403
-
1404
-        // Do we have any validation errors?
1405
-        $validators = $this->_get_transient();
1406
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1407
-
1408
-
1409
-        // we need to assemble the title from Various details
1410
-        $context_label = sprintf(
1411
-            esc_html__('(%s %s)', 'event_espresso'),
1412
-            $c_config[ $context ]['label'],
1413
-            ucwords($c_label['label'])
1414
-        );
1415
-
1416
-        $title = sprintf(
1417
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1418
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1419
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1420
-            $context_label
1421
-        );
1422
-
1423
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1424
-        $this->_template_args['message_template'] = $message_template_group;
1425
-        $this->_template_args['is_extra_fields']  = false;
1426
-
1427
-
1428
-        // let's get EEH_MSG_Template so we can get template form fields
1429
-        $template_field_structure = EEH_MSG_Template::get_fields(
1430
-            $message_template_group->messenger(),
1431
-            $message_template_group->message_type()
1432
-        );
1433
-
1434
-        if (! $template_field_structure) {
1435
-            $template_field_structure = false;
1436
-            $template_fields          = esc_html__(
1437
-                'There was an error in assembling the fields for this display (you should see an error message)',
1438
-                'event_espresso'
1439
-            );
1440
-        }
1441
-
1442
-
1443
-        $message_templates = $message_template_group->context_templates();
1444
-
1445
-
1446
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1447
-        // will get handled in the "extra" array.
1448
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1449
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1450
-                unset($template_field_structure[ $context ][ $reference_field ]);
1451
-            }
1452
-        }
1453
-
1454
-        // let's loop through the template_field_structure and actually assemble the input fields!
1455
-        if (! empty($template_field_structure)) {
1456
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1457
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1458
-                // the extra array and reset them.
1459
-                if ($template_field === 'extra') {
1460
-                    $this->_template_args['is_extra_fields'] = true;
1461
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1462
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1463
-                        $content          = $message_template instanceof EE_Message_Template
1464
-                            ? $message_template->get('MTP_content')
1465
-                            : '';
1466
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1467
-                            // let's verify if we need this extra field via the shortcodes parameter.
1468
-                            $continue = false;
1469
-                            if (isset($extra_array['shortcodes_required'])) {
1470
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1471
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1472
-                                        $continue = true;
1473
-                                    }
1474
-                                }
1475
-                                if ($continue) {
1476
-                                    continue;
1477
-                                }
1478
-                            }
1479
-
1480
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1481
-
1482
-                            $template_form_fields[ $field_id ]         = $extra_array;
1483
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1484
-                                                                         . $reference_field
1485
-                                                                         . '][content]['
1486
-                                                                         . $extra_field . ']';
1487
-                            $css_class                                 = isset($extra_array['css_class'])
1488
-                                ? $extra_array['css_class']
1489
-                                : '';
1490
-
1491
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1492
-                                                                              && in_array($extra_field, $v_fields, true)
1493
-                                                                              && (
1494
-                                                                                  is_array($validators[ $extra_field ])
1495
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1496
-                                                                              )
1497
-                                ? 'validate-error ' . $css_class
1498
-                                : $css_class;
1499
-
1500
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1501
-                                                                          && isset($content[ $extra_field ])
1502
-                                ? $content[ $extra_field ]
1503
-                                : '';
1504
-
1505
-                            // do we have a validation error?  if we do then let's use that value instead
1506
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1507
-                                ? $validators[ $extra_field ]['value']
1508
-                                : $template_form_fields[ $field_id ]['value'];
1509
-
1510
-
1511
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1512
-
1513
-                            // shortcode selector
1514
-                            $field_name_to_use                                   = $extra_field === 'main'
1515
-                                ? 'content'
1516
-                                : $extra_field;
1517
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1518
-                                $field_name_to_use,
1519
-                                $field_id
1520
-                            );
1521
-                        }
1522
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1523
-                        $template_field_template_name_id = $reference_field . '-name';
1524
-
1525
-                        $template_form_fields[ $template_field_MTP_id ] = [
1526
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1527
-                            'label'      => null,
1528
-                            'input'      => 'hidden',
1529
-                            'type'       => 'int',
1530
-                            'required'   => false,
1531
-                            'validation' => false,
1532
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1533
-                            'css_class'  => '',
1534
-                            'format'     => '%d',
1535
-                            'db-col'     => 'MTP_ID',
1536
-                        ];
1537
-
1538
-                        $template_form_fields[ $template_field_template_name_id ] = [
1539
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1540
-                            'label'      => null,
1541
-                            'input'      => 'hidden',
1542
-                            'type'       => 'string',
1543
-                            'required'   => false,
1544
-                            'validation' => true,
1545
-                            'value'      => $reference_field,
1546
-                            'css_class'  => '',
1547
-                            'format'     => '%s',
1548
-                            'db-col'     => 'MTP_template_field',
1549
-                        ];
1550
-                    }
1551
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1552
-                } else {
1553
-                    $field_id                                   = $template_field . '-content';
1554
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1555
-                    $template_form_fields[ $field_id ]['name']  =
1556
-                        'MTP_template_fields[' . $template_field . '][content]';
1557
-                    $message_template                           =
1558
-                        isset($message_templates[ $context ][ $template_field ])
1559
-                            ? $message_templates[ $context ][ $template_field ]
1560
-                            : null;
1561
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1562
-                                                                  && is_array($message_templates[ $context ])
1563
-                                                                  && $message_template instanceof EE_Message_Template
1564
-                        ? $message_template->get('MTP_content')
1565
-                        : '';
1566
-
1567
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1568
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1569
-                        ? $validators[ $template_field ]['value']
1570
-                        : $template_form_fields[ $field_id ]['value'];
1571
-
1572
-
1573
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1574
-                    $css_class                                      = isset($field_setup_array['css_class'])
1575
-                        ? $field_setup_array['css_class']
1576
-                        : '';
1577
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1578
-                                                                      && in_array($template_field, $v_fields, true)
1579
-                                                                      && isset($validators[ $template_field ]['msg'])
1580
-                        ? 'validate-error ' . $css_class
1581
-                        : $css_class;
1582
-
1583
-                    // shortcode selector
1584
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1585
-                        $template_field,
1586
-                        $field_id
1587
-                    );
1588
-                }
1589
-
1590
-                // k took care of content field(s) now let's take care of others.
1591
-
1592
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1593
-                $template_field_field_template_name_id = $template_field . '-name';
1594
-
1595
-                // foreach template field there are actually two form fields created
1596
-                $template_form_fields[ $template_field_MTP_id ] = [
1597
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1598
-                    'label'      => null,
1599
-                    'input'      => 'hidden',
1600
-                    'type'       => 'int',
1601
-                    'required'   => false,
1602
-                    'validation' => true,
1603
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1604
-                    'css_class'  => '',
1605
-                    'format'     => '%d',
1606
-                    'db-col'     => 'MTP_ID',
1607
-                ];
1608
-
1609
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1610
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1611
-                    'label'      => null,
1612
-                    'input'      => 'hidden',
1613
-                    'type'       => 'string',
1614
-                    'required'   => false,
1615
-                    'validation' => true,
1616
-                    'value'      => $template_field,
1617
-                    'css_class'  => '',
1618
-                    'format'     => '%s',
1619
-                    'db-col'     => 'MTP_template_field',
1620
-                ];
1621
-            }
1622
-
1623
-            // add other fields
1624
-            $template_form_fields['ee-msg-current-context'] = [
1625
-                'name'       => 'MTP_context',
1626
-                'label'      => null,
1627
-                'input'      => 'hidden',
1628
-                'type'       => 'string',
1629
-                'required'   => false,
1630
-                'validation' => true,
1631
-                'value'      => $context,
1632
-                'css_class'  => '',
1633
-                'format'     => '%s',
1634
-                'db-col'     => 'MTP_context',
1635
-            ];
1636
-
1637
-            $template_form_fields['ee-msg-grp-id'] = [
1638
-                'name'       => 'GRP_ID',
1639
-                'label'      => null,
1640
-                'input'      => 'hidden',
1641
-                'type'       => 'int',
1642
-                'required'   => false,
1643
-                'validation' => true,
1644
-                'value'      => $GRP_ID,
1645
-                'css_class'  => '',
1646
-                'format'     => '%d',
1647
-                'db-col'     => 'GRP_ID',
1648
-            ];
1649
-
1650
-            $template_form_fields['ee-msg-messenger'] = [
1651
-                'name'       => 'MTP_messenger',
1652
-                'label'      => null,
1653
-                'input'      => 'hidden',
1654
-                'type'       => 'string',
1655
-                'required'   => false,
1656
-                'validation' => true,
1657
-                'value'      => $message_template_group->messenger(),
1658
-                'css_class'  => '',
1659
-                'format'     => '%s',
1660
-                'db-col'     => 'MTP_messenger',
1661
-            ];
1662
-
1663
-            $template_form_fields['ee-msg-message-type'] = [
1664
-                'name'       => 'MTP_message_type',
1665
-                'label'      => null,
1666
-                'input'      => 'hidden',
1667
-                'type'       => 'string',
1668
-                'required'   => false,
1669
-                'validation' => true,
1670
-                'value'      => $message_template_group->message_type(),
1671
-                'css_class'  => '',
1672
-                'format'     => '%s',
1673
-                'db-col'     => 'MTP_message_type',
1674
-            ];
1675
-
1676
-            $sidebar_form_fields['ee-msg-is-global'] = [
1677
-                'name'       => 'MTP_is_global',
1678
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1679
-                'input'      => 'hidden',
1680
-                'type'       => 'int',
1681
-                'required'   => false,
1682
-                'validation' => true,
1683
-                'value'      => $message_template_group->get('MTP_is_global'),
1684
-                'css_class'  => '',
1685
-                'format'     => '%d',
1686
-                'db-col'     => 'MTP_is_global',
1687
-            ];
1688
-
1689
-            $sidebar_form_fields['ee-msg-is-override'] = [
1690
-                'name'       => 'MTP_is_override',
1691
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1692
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1693
-                'type'       => 'int',
1694
-                'required'   => false,
1695
-                'validation' => true,
1696
-                'value'      => $message_template_group->get('MTP_is_override'),
1697
-                'css_class'  => '',
1698
-                'format'     => '%d',
1699
-                'db-col'     => 'MTP_is_override',
1700
-            ];
1701
-
1702
-            $sidebar_form_fields['ee-msg-is-active'] = [
1703
-                'name'       => 'MTP_is_active',
1704
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1705
-                'input'      => 'hidden',
1706
-                'type'       => 'int',
1707
-                'required'   => false,
1708
-                'validation' => true,
1709
-                'value'      => $message_template_group->is_active(),
1710
-                'css_class'  => '',
1711
-                'format'     => '%d',
1712
-                'db-col'     => 'MTP_is_active',
1713
-            ];
1714
-
1715
-            $sidebar_form_fields['ee-msg-deleted'] = [
1716
-                'name'       => 'MTP_deleted',
1717
-                'label'      => null,
1718
-                'input'      => 'hidden',
1719
-                'type'       => 'int',
1720
-                'required'   => false,
1721
-                'validation' => true,
1722
-                'value'      => $message_template_group->get('MTP_deleted'),
1723
-                'css_class'  => '',
1724
-                'format'     => '%d',
1725
-                'db-col'     => 'MTP_deleted',
1726
-            ];
1727
-            $sidebar_form_fields['ee-msg-author']  = [
1728
-                'name'       => 'MTP_user_id',
1729
-                'label'      => esc_html__('Author', 'event_espresso'),
1730
-                'input'      => 'hidden',
1731
-                'type'       => 'int',
1732
-                'required'   => false,
1733
-                'validation' => false,
1734
-                'value'      => $message_template_group->user(),
1735
-                'format'     => '%d',
1736
-                'db-col'     => 'MTP_user_id',
1737
-            ];
1738
-
1739
-            $sidebar_form_fields['ee-msg-route'] = [
1740
-                'name'  => 'action',
1741
-                'input' => 'hidden',
1742
-                'type'  => 'string',
1743
-                'value' => $action,
1744
-            ];
1745
-
1746
-            $sidebar_form_fields['ee-msg-id']        = [
1747
-                'name'  => 'id',
1748
-                'input' => 'hidden',
1749
-                'type'  => 'int',
1750
-                'value' => $GRP_ID,
1751
-            ];
1752
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1753
-                'name'  => $action . '_nonce',
1754
-                'input' => 'hidden',
1755
-                'type'  => 'string',
1756
-                'value' => wp_create_nonce($action . '_nonce'),
1757
-            ];
1758
-
1759
-            $template_switch = $this->request->getRequestParam('template_switch');
1760
-            if ($template_switch) {
1761
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1762
-                    'name'  => 'template_switch',
1763
-                    'input' => 'hidden',
1764
-                    'type'  => 'int',
1765
-                    'value' => 1,
1766
-                ];
1767
-            }
1768
-
1769
-
1770
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1771
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1772
-        } //end if ( !empty($template_field_structure) )
1773
-
1774
-        // set extra content for publish box
1775
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1776
-        $this->_set_publish_post_box_vars(
1777
-            'id',
1778
-            $GRP_ID,
1779
-            false,
1780
-            add_query_arg(
1781
-                ['action' => 'global_mtps'],
1782
-                $this->_admin_base_url
1783
-            )
1784
-        );
1785
-
1786
-        // add preview button
1787
-        $preview_url    = parent::add_query_args_and_nonce(
1788
-            [
1789
-                'message_type' => $message_template_group->message_type(),
1790
-                'messenger'    => $message_template_group->messenger(),
1791
-                'context'      => $context,
1792
-                'GRP_ID'       => $GRP_ID,
1793
-                'evt_id'       => $EVT_ID ?: false,
1794
-                'action'       => 'preview_message',
1795
-            ],
1796
-            $this->_admin_base_url
1797
-        );
1798
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1799
-                          . esc_html__('Preview', 'event_espresso')
1800
-                          . '</a>';
1801
-
1802
-
1803
-        // setup context switcher
1804
-        $this->_set_context_switcher(
1805
-            $message_template_group,
1806
-            [
1807
-                'page'    => 'espresso_messages',
1808
-                'action'  => 'edit_message_template',
1809
-                'id'      => $GRP_ID,
1810
-                'evt_id'  => $EVT_ID,
1811
-                'context' => $context,
1812
-                'extra'   => $preview_button,
1813
-            ]
1814
-        );
1815
-
1816
-
1817
-        // main box
1818
-        $this->_template_args['template_fields']                         = $template_fields;
1819
-        $this->_template_args['sidebar_box_id']                          = 'details';
1820
-        $this->_template_args['action']                                  = $action;
1821
-        $this->_template_args['context']                                 = $context;
1822
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1823
-        $this->_template_args['learn_more_about_message_templates_link'] =
1824
-            $this->_learn_more_about_message_templates_link();
1825
-
1826
-
1827
-        $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1828
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1829
-            $message_template_group,
1830
-            $context,
1831
-            $context_label
1832
-        );
1833
-        $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1834
-        $this->_template_args['before_admin_page_content'] .= '</div>';
1835
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1836
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1837
-
1838
-        $this->_template_path = $this->_template_args['GRP_ID']
1839
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1840
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1841
-
1842
-        // send along EE_Message_Template_Group object for further template use.
1843
-        $this->_template_args['MTP'] = $message_template_group;
1844
-
1845
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1846
-            $this->_template_path,
1847
-            $this->_template_args,
1848
-            true
1849
-        );
1850
-
1851
-
1852
-        // finally, let's set the admin_page title
1853
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1854
-
1855
-
1856
-        // we need to take care of setting the shortcodes property for use elsewhere.
1857
-        $this->_set_shortcodes();
1858
-
1859
-
1860
-        // final template wrapper
1861
-        $this->display_admin_page_with_sidebar();
1862
-    }
1863
-
1864
-
1865
-    public function filter_tinymce_init($mceInit, $editor_id)
1866
-    {
1867
-        return $mceInit;
1868
-    }
1869
-
1870
-
1871
-    public function add_context_switcher()
1872
-    {
1873
-        return $this->_context_switcher;
1874
-    }
1875
-
1876
-
1877
-    /**
1878
-     * Adds the activation/deactivation toggle for the message template context.
1879
-     *
1880
-     * @param EE_Message_Template_Group $message_template_group
1881
-     * @param string                    $context
1882
-     * @param string                    $context_label
1883
-     * @return string
1884
-     * @throws DomainException
1885
-     * @throws EE_Error
1886
-     * @throws InvalidIdentifierException
1887
-     * @throws ReflectionException
1888
-     */
1889
-    protected function add_active_context_element(
1890
-        EE_Message_Template_Group $message_template_group,
1891
-        $context,
1892
-        $context_label
1893
-    ) {
1894
-        $template_args = [
1895
-            'context'                   => $context,
1896
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1897
-            'is_active'                 => $message_template_group->is_context_active($context),
1898
-            'on_off_action'             => $message_template_group->is_context_active($context)
1899
-                ? 'context-off'
1900
-                : 'context-on',
1901
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1902
-            'message_template_group_id' => $message_template_group->ID(),
1903
-        ];
1904
-        return EEH_Template::display_template(
1905
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1906
-            $template_args,
1907
-            true
1908
-        );
1909
-    }
1910
-
1911
-
1912
-    /**
1913
-     * Ajax callback for `toggle_context_template` ajax action.
1914
-     * Handles toggling the message context on or off.
1915
-     *
1916
-     * @throws EE_Error
1917
-     * @throws InvalidArgumentException
1918
-     * @throws InvalidDataTypeException
1919
-     * @throws InvalidIdentifierException
1920
-     * @throws InvalidInterfaceException
1921
-     */
1922
-    public function toggle_context_template()
1923
-    {
1924
-        $success = true;
1925
-        // check for required data
1926
-        if (
1927
-            ! (
1928
-                $this->request->requestParamIsSet('message_template_group_id')
1929
-                && $this->request->requestParamIsSet('context')
1930
-                && $this->request->requestParamIsSet('status')
1931
-            )
1932
-        ) {
1933
-            EE_Error::add_error(
1934
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1935
-                __FILE__,
1936
-                __FUNCTION__,
1937
-                __LINE__
1938
-            );
1939
-            $success = false;
1940
-        }
1941
-
1942
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1943
-        $context = $this->request->getRequestParam('context', '');
1944
-        $status  = $this->request->getRequestParam('status', '');
1945
-
1946
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1947
-
1948
-        if ($status !== 'off' && $status !== 'on') {
1949
-            EE_Error::add_error(
1950
-                sprintf(
1951
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1952
-                    $status
1953
-                ),
1954
-                __FILE__,
1955
-                __FUNCTION__,
1956
-                __LINE__
1957
-            );
1958
-            $success = false;
1959
-        }
1960
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1961
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1962
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1963
-            EE_Error::add_error(
1964
-                sprintf(
1965
-                    esc_html__(
1966
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1967
-                        'event_espresso'
1968
-                    ),
1969
-                    $message_template_group_id,
1970
-                    'EE_Message_Template_Group'
1971
-                ),
1972
-                __FILE__,
1973
-                __FUNCTION__,
1974
-                __LINE__
1975
-            );
1976
-            $success = false;
1977
-        }
1978
-        if ($success) {
1979
-            $success = $status === 'off'
1980
-                ? $message_template_group->deactivate_context($context)
1981
-                : $message_template_group->activate_context($context);
1982
-        }
1983
-        $this->_template_args['success'] = $success;
1984
-        $this->_return_json();
1985
-    }
1986
-
1987
-
1988
-    public function _add_form_element_before()
1989
-    {
1990
-        return '<form method="post" action="'
1991
-               . $this->_template_args['edit_message_template_form_url']
1992
-               . '" id="ee-msg-edit-frm">';
1993
-    }
1994
-
1995
-
1996
-    public function _add_form_element_after()
1997
-    {
1998
-        return '</form>';
1999
-    }
2000
-
2001
-
2002
-    /**
2003
-     * This executes switching the template pack for a message template.
2004
-     *
2005
-     * @throws EE_Error
2006
-     * @throws InvalidDataTypeException
2007
-     * @throws InvalidInterfaceException
2008
-     * @throws InvalidArgumentException
2009
-     * @throws ReflectionException
2010
-     * @since 4.5.0
2011
-     */
2012
-    public function switch_template_pack()
2013
-    {
2014
-
2015
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2016
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2017
-
2018
-        // verify we have needed values.
2019
-        if (empty($GRP_ID) || empty($template_pack)) {
2020
-            $this->_template_args['error'] = true;
2021
-            EE_Error::add_error(
2022
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2023
-                __FILE__,
2024
-                __FUNCTION__,
2025
-                __LINE__
2026
-            );
2027
-        } else {
2028
-            // get template, set the new template_pack and then reset to default
2029
-            /** @var EE_Message_Template_Group $message_template_group */
2030
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2031
-
2032
-            $message_template_group->set_template_pack_name($template_pack);
2033
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2034
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2035
-
2036
-            $query_args = $this->_reset_to_default_template();
2037
-
2038
-            if (empty($query_args['id'])) {
2039
-                EE_Error::add_error(
2040
-                    esc_html__(
2041
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2042
-                        'event_espresso'
2043
-                    ),
2044
-                    __FILE__,
2045
-                    __FUNCTION__,
2046
-                    __LINE__
2047
-                );
2048
-                $this->_template_args['error'] = true;
2049
-            } else {
2050
-                $template_label       = $message_template_group->get_template_pack()->label;
2051
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2052
-                EE_Error::add_success(
2053
-                    sprintf(
2054
-                        esc_html__(
2055
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2056
-                            'event_espresso'
2057
-                        ),
2058
-                        $template_label,
2059
-                        $template_pack_labels->template_pack
2060
-                    )
2061
-                );
2062
-                // generate the redirect url for js.
2063
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2064
-
2065
-                $this->_template_args['data']['redirect_url'] = $url;
2066
-                $this->_template_args['success']              = true;
2067
-            }
2068
-
2069
-            $this->_return_json();
2070
-        }
2071
-    }
2072
-
2073
-
2074
-    /**
2075
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2076
-     * they want.
2077
-     *
2078
-     * @access protected
2079
-     * @return array|void
2080
-     * @throws EE_Error
2081
-     * @throws InvalidArgumentException
2082
-     * @throws InvalidDataTypeException
2083
-     * @throws InvalidInterfaceException
2084
-     * @throws ReflectionException
2085
-     */
2086
-    protected function _reset_to_default_template()
2087
-    {
2088
-        $templates    = [];
2089
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2090
-        $messenger    = $this->request->getRequestParam('msgr');
2091
-        $message_type = $this->request->getRequestParam('mt');
2092
-        // we need to make sure we've got the info we need.
2093
-        if (! ($GRP_ID && $messenger && $message_type)) {
2094
-            EE_Error::add_error(
2095
-                esc_html__(
2096
-                    '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.',
2097
-                    'event_espresso'
2098
-                ),
2099
-                __FILE__,
2100
-                __FUNCTION__,
2101
-                __LINE__
2102
-            );
2103
-        }
2104
-
2105
-        // all templates will be reset to whatever the defaults are
2106
-        // for the global template matching the messenger and message type.
2107
-        $success = ! empty($GRP_ID);
2108
-
2109
-        if ($success) {
2110
-            // let's first determine if the incoming template is a global template,
2111
-            // if it isn't then we need to get the global template matching messenger and message type.
2112
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2113
-
2114
-
2115
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2116
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2117
-
2118
-            if ($success) {
2119
-                // if successfully deleted, lets generate the new ones.
2120
-                // Note. We set GLOBAL to true, because resets on ANY template
2121
-                // will use the related global template defaults for regeneration.
2122
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2123
-                // HOWEVER, we DO keep the template pack and template variation set
2124
-                // for the current custom template when resetting.
2125
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2126
-            }
2127
-        }
2128
-
2129
-        // any error messages?
2130
-        if (! $success) {
2131
-            EE_Error::add_error(
2132
-                esc_html__(
2133
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2134
-                    'event_espresso'
2135
-                ),
2136
-                __FILE__,
2137
-                __FUNCTION__,
2138
-                __LINE__
2139
-            );
2140
-        }
2141
-
2142
-        // all good, let's add a success message!
2143
-        if ($success && ! empty($templates)) {
2144
-            // the info for the template we generated is the first element in the returned array
2145
-            EE_Error::overwrite_success();
2146
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2147
-        }
2148
-
2149
-
2150
-        $query_args = [
2151
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2152
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2153
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2154
-        ];
2155
-
2156
-        // if called via ajax then we return query args otherwise redirect
2157
-        if ($this->request->isAjax()) {
2158
-            return $query_args;
2159
-        }
2160
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2161
-    }
2162
-
2163
-
2164
-    /**
2165
-     * Retrieve and set the message preview for display.
2166
-     *
2167
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2168
-     * @return string
2169
-     * @throws ReflectionException
2170
-     * @throws EE_Error
2171
-     * @throws InvalidArgumentException
2172
-     * @throws InvalidDataTypeException
2173
-     * @throws InvalidInterfaceException
2174
-     */
2175
-    public function _preview_message($send = false)
2176
-    {
2177
-        // first make sure we've got the necessary parameters
2178
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2179
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2180
-            EE_Error::add_error(
2181
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2182
-                __FILE__,
2183
-                __FUNCTION__,
2184
-                __LINE__
2185
-            );
2186
-        }
2187
-
2188
-        $context = $this->request->getRequestParam('context');
2189
-        // get the preview!
2190
-        $preview = EED_Messages::preview_message(
2191
-            $this->_active_message_type_name,
2192
-            $context,
2193
-            $this->_active_messenger_name,
2194
-            $send
2195
-        );
2196
-
2197
-        if ($send) {
2198
-            return $preview;
2199
-        }
2200
-
2201
-        // if we have an evt_id set on the request, use it.
2202
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2203
-
2204
-        // let's add a button to go back to the edit view
2205
-        $query_args             = [
2206
-            'id'      => $GRP_ID,
2207
-            'evt_id'  => $EVT_ID,
2208
-            'context' => $context,
2209
-            'action'  => 'edit_message_template',
2210
-        ];
2211
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2212
-        $preview_button         = '<a href="'
2213
-                                  . $go_back_url
2214
-                                  . '" class="button--secondary messages-preview-go-back-button">'
2215
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2216
-                                  . '</a>';
2217
-        $message_types          = $this->get_installed_message_types();
2218
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2219
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2220
-            ? ucwords($active_messenger->label['singular'])
2221
-            : esc_html__('Unknown Messenger', 'event_espresso');
2222
-        // let's provide a helpful title for context
2223
-        $preview_title = sprintf(
2224
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2225
-            $active_messenger_label,
2226
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2227
-        );
2228
-        if (empty($preview)) {
2229
-            $this->noEventsErrorMessage();
2230
-        }
2231
-        // setup display of preview.
2232
-        $this->_admin_page_title                    = $preview_title;
2233
-        $this->_template_args['admin_page_title']   = $preview_title;
2234
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2235
-        $this->_template_args['data']['force_json'] = true;
2236
-
2237
-        return '';
2238
-    }
2239
-
2240
-
2241
-    /**
2242
-     * Used to set an error if there are no events available for generating a preview/test send.
2243
-     *
2244
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2245
-     */
2246
-    protected function noEventsErrorMessage($test_send = false)
2247
-    {
2248
-        $events_url = parent::add_query_args_and_nonce(
2249
-            [
2250
-                'action' => 'default',
2251
-                'page'   => 'espresso_events',
2252
-            ],
2253
-            admin_url('admin.php')
2254
-        );
2255
-        $message    = $test_send
2256
-            ? esc_html__(
2257
-                '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!',
2258
-                'event_espresso'
2259
-            )
2260
-            : esc_html__(
2261
-                '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!',
2262
-                'event_espresso'
2263
-            );
2264
-
2265
-        EE_Error::add_attention(
2266
-            sprintf(
2267
-                $message,
2268
-                "<a href='{$events_url}'>",
2269
-                '</a>'
2270
-            )
2271
-        );
2272
-    }
2273
-
2274
-
2275
-    /**
2276
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2277
-     * gets called automatically.
2278
-     *
2279
-     * @return void
2280
-     * @throws EE_Error
2281
-     * @since 4.5.0
2282
-     *
2283
-     */
2284
-    protected function _display_preview_message()
2285
-    {
2286
-        $this->display_admin_page_with_no_sidebar();
2287
-    }
2288
-
2289
-
2290
-    /**
2291
-     * registers metaboxes that should show up on the "edit_message_template" page
2292
-     *
2293
-     * @access protected
2294
-     * @return void
2295
-     */
2296
-    protected function _register_edit_meta_boxes()
2297
-    {
2298
-        $this->addMetaBox(
2299
-            'mtp_valid_shortcodes',
2300
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2301
-            [$this, 'shortcode_meta_box'],
2302
-            $this->_current_screen->id,
2303
-            'side'
2304
-        );
2305
-        $this->addMetaBox(
2306
-            'mtp_extra_actions',
2307
-            esc_html__('Extra Actions', 'event_espresso'),
2308
-            [$this, 'extra_actions_meta_box'],
2309
-            $this->_current_screen->id,
2310
-            'side',
2311
-            'high'
2312
-        );
2313
-        $this->addMetaBox(
2314
-            'mtp_templates',
2315
-            esc_html__('Template Styles', 'event_espresso'),
2316
-            [$this, 'template_pack_meta_box'],
2317
-            $this->_current_screen->id,
2318
-            'side',
2319
-            'high'
2320
-        );
2321
-    }
2322
-
2323
-
2324
-    /**
2325
-     * metabox content for all template pack and variation selection.
2326
-     *
2327
-     * @return void
2328
-     * @throws DomainException
2329
-     * @throws EE_Error
2330
-     * @throws InvalidArgumentException
2331
-     * @throws ReflectionException
2332
-     * @throws InvalidDataTypeException
2333
-     * @throws InvalidInterfaceException
2334
-     * @since 4.5.0
2335
-     */
2336
-    public function template_pack_meta_box()
2337
-    {
2338
-        $this->_set_message_template_group();
2339
-
2340
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2341
-
2342
-        $tp_select_values = [];
2343
-
2344
-        foreach ($tp_collection as $tp) {
2345
-            // only include template packs that support this messenger and message type!
2346
-            $supports = $tp->get_supports();
2347
-            if (
2348
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2349
-                || ! in_array(
2350
-                    $this->_message_template_group->message_type(),
2351
-                    $supports[ $this->_message_template_group->messenger() ],
2352
-                    true
2353
-                )
2354
-            ) {
2355
-                // not supported
2356
-                continue;
2357
-            }
2358
-
2359
-            $tp_select_values[] = [
2360
-                'text' => $tp->label,
2361
-                'id'   => $tp->dbref,
2362
-            ];
2363
-        }
2364
-
2365
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2366
-        // the default template pack.  This still allows for the odd template pack to override.
2367
-        if (empty($tp_select_values)) {
2368
-            $tp_select_values[] = [
2369
-                'text' => esc_html__('Default', 'event_espresso'),
2370
-                'id'   => 'default',
2371
-            ];
2372
-        }
2373
-
2374
-        // setup variation select values for the currently selected template.
2375
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2376
-            $this->_message_template_group->messenger(),
2377
-            $this->_message_template_group->message_type()
2378
-        );
2379
-        $variations_select_values = [];
2380
-        foreach ($variations as $variation => $label) {
2381
-            $variations_select_values[] = [
2382
-                'text' => $label,
2383
-                'id'   => $variation,
2384
-            ];
2385
-        }
2386
-
2387
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2388
-
2389
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2390
-            'MTP_template_pack',
2391
-            $tp_select_values,
2392
-            $this->_message_template_group->get_template_pack_name()
2393
-        );
2394
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2395
-            'MTP_template_variation',
2396
-            $variations_select_values,
2397
-            $this->_message_template_group->get_template_pack_variation()
2398
-        );
2399
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2400
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2401
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2402
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2403
-
2404
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2405
-
2406
-        EEH_Template::display_template($template, $template_args);
2407
-    }
2408
-
2409
-
2410
-    /**
2411
-     * This meta box holds any extra actions related to Message Templates
2412
-     * For now, this includes Resetting templates to defaults and sending a test email.
2413
-     *
2414
-     * @access  public
2415
-     * @return void
2416
-     * @throws EE_Error
2417
-     */
2418
-    public function extra_actions_meta_box()
2419
-    {
2420
-        $template_form_fields = [];
2421
-
2422
-        $extra_args = [
2423
-            'msgr'   => $this->_message_template_group->messenger(),
2424
-            'mt'     => $this->_message_template_group->message_type(),
2425
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2426
-        ];
2427
-        // first we need to see if there are any fields
2428
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2429
-
2430
-        if (! empty($fields)) {
2431
-            // yup there be fields
2432
-            foreach ($fields as $field => $config) {
2433
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2434
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2435
-                $default  = isset($config['default']) ? $config['default'] : '';
2436
-                $default  = isset($config['value']) ? $config['value'] : $default;
2437
-
2438
-                // if type is hidden and the value is empty
2439
-                // something may have gone wrong so let's correct with the defaults
2440
-                $fix                = $config['input'] === 'hidden'
2441
-                                      && isset($existing[ $field ])
2442
-                                      && empty($existing[ $field ])
2443
-                    ? $default
2444
-                    : '';
2445
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2446
-                    ? $existing[ $field ]
2447
-                    : $fix;
2448
-
2449
-                $template_form_fields[ $field_id ] = [
2450
-                    'name'       => 'test_settings_fld[' . $field . ']',
2451
-                    'label'      => $config['label'],
2452
-                    'input'      => $config['input'],
2453
-                    'type'       => $config['type'],
2454
-                    'required'   => $config['required'],
2455
-                    'validation' => $config['validation'],
2456
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2457
-                    'css_class'  => $config['css_class'],
2458
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2459
-                    'default'    => $default,
2460
-                    'format'     => $config['format'],
2461
-                ];
2462
-            }
2463
-        }
2464
-
2465
-        $test_settings_html = ! empty($template_form_fields)
2466
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2467
-            : '';
2468
-
2469
-        // print out $test_settings_fields
2470
-        if (! empty($test_settings_html)) {
2471
-            $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2472
-            $test_settings_html .= 'name="test_button" value="';
2473
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2474
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2475
-        }
2476
-
2477
-        // and button
2478
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2479
-        $test_settings_html .= '<p>';
2480
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2481
-        $test_settings_html .= '</p>';
2482
-        $test_settings_html .= $this->get_action_link_or_button(
2483
-            'reset_to_default',
2484
-            'reset',
2485
-            $extra_args,
2486
-            'button--primary reset-default-button'
2487
-        );
2488
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2489
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2490
-    }
2491
-
2492
-
2493
-    /**
2494
-     * This returns the shortcode selector skeleton for a given context and field.
2495
-     *
2496
-     * @param string $field           The name of the field retrieving shortcodes for.
2497
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2498
-     * @return string
2499
-     * @throws DomainException
2500
-     * @throws EE_Error
2501
-     * @throws InvalidArgumentException
2502
-     * @throws ReflectionException
2503
-     * @throws InvalidDataTypeException
2504
-     * @throws InvalidInterfaceException
2505
-     * @since 4.9.rc.000
2506
-     */
2507
-    protected function _get_shortcode_selector($field, $linked_input_id)
2508
-    {
2509
-        $template_args = [
2510
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2511
-            'fieldname'       => $field,
2512
-            'linked_input_id' => $linked_input_id,
2513
-        ];
2514
-
2515
-        return EEH_Template::display_template(
2516
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2517
-            $template_args,
2518
-            true
2519
-        );
2520
-    }
2521
-
2522
-
2523
-    /**
2524
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2525
-     * page)
2526
-     *
2527
-     * @access public
2528
-     * @return void
2529
-     * @throws EE_Error
2530
-     * @throws InvalidArgumentException
2531
-     * @throws ReflectionException
2532
-     * @throws InvalidDataTypeException
2533
-     * @throws InvalidInterfaceException
2534
-     */
2535
-    public function shortcode_meta_box()
2536
-    {
2537
-        $shortcodes = $this->_get_shortcodes([], false);
2538
-        // just make sure the shortcodes property is set
2539
-        // $messenger = $this->_message_template_group->messenger_obj();
2540
-        // now let's set the content depending on the status of the shortcodes array
2541
-        if (empty($shortcodes)) {
2542
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2543
-            return;
2544
-        }
2545
-        ?>
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
+					'icon' => 'dashicons-email',
588
+					'order' => 10,
589
+				],
590
+				'list_table'    => 'EE_Message_List_Table',
591
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
592
+				'require_nonce' => false,
593
+			],
594
+			'global_mtps'              => [
595
+				'nav'           => [
596
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
597
+					'icon' => 'dashicons-layout',
598
+					'order' => 20,
599
+				],
600
+				'list_table'    => 'Messages_Template_List_Table',
601
+				'help_tabs'     => [
602
+					'messages_overview_help_tab'                                => [
603
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
604
+						'filename' => 'messages_overview',
605
+					],
606
+					'messages_overview_messages_table_column_headings_help_tab' => [
607
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
608
+						'filename' => 'messages_overview_table_column_headings',
609
+					],
610
+					'messages_overview_messages_filters_help_tab'               => [
611
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
612
+						'filename' => 'messages_overview_filters',
613
+					],
614
+					'messages_overview_messages_views_help_tab'                 => [
615
+						'title'    => esc_html__('Message Views', 'event_espresso'),
616
+						'filename' => 'messages_overview_views',
617
+					],
618
+					'message_overview_message_types_help_tab'                   => [
619
+						'title'    => esc_html__('Message Types', 'event_espresso'),
620
+						'filename' => 'messages_overview_types',
621
+					],
622
+					'messages_overview_messengers_help_tab'                     => [
623
+						'title'    => esc_html__('Messengers', 'event_espresso'),
624
+						'filename' => 'messages_overview_messengers',
625
+					],
626
+				],
627
+				'require_nonce' => false,
628
+			],
629
+			'custom_mtps'              => [
630
+				'nav'           => [
631
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
632
+					'icon' => 'dashicons-admin-customizer',
633
+					'order' => 30,
634
+				],
635
+				'help_tabs'     => [],
636
+				'require_nonce' => false,
637
+			],
638
+			'add_new_message_template' => [
639
+				'nav'           => [
640
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
641
+					'icon' => 'dashicons-plus-alt',
642
+					'order'      => 5,
643
+					'persistent' => false,
644
+				],
645
+				'require_nonce' => false,
646
+			],
647
+			'edit_message_template'    => [
648
+				'labels'        => [
649
+					'buttons'    => [
650
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
651
+					],
652
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
653
+				],
654
+				'nav'           => [
655
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
656
+					'icon' => 'dashicons-edit-large',
657
+					'order'      => 5,
658
+					'persistent' => false,
659
+					'url'        => '',
660
+				],
661
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
662
+				'has_metaboxes' => true,
663
+				'help_tabs'     => [
664
+					'edit_message_template'            => [
665
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
666
+						'callback' => 'edit_message_template_help_tab',
667
+					],
668
+					'message_templates_help_tab'       => [
669
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
670
+						'filename' => 'messages_templates',
671
+					],
672
+					'message_template_shortcodes'      => [
673
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
674
+						'callback' => 'message_template_shortcodes_help_tab',
675
+					],
676
+					'message_preview_help_tab'         => [
677
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
678
+						'filename' => 'messages_preview',
679
+					],
680
+					'messages_overview_other_help_tab' => [
681
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
682
+						'filename' => 'messages_overview_other',
683
+					],
684
+				],
685
+				'require_nonce' => false,
686
+			],
687
+			'display_preview_message'  => [
688
+				'nav'           => [
689
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
690
+					'icon' => 'dashicons-visibility-bar',
691
+					'order'      => 5,
692
+					'url'        => '',
693
+					'persistent' => false,
694
+				],
695
+				'help_tabs'     => [
696
+					'preview_message' => [
697
+						'title'    => esc_html__('About Previews', 'event_espresso'),
698
+						'callback' => 'preview_message_help_tab',
699
+					],
700
+				],
701
+				'require_nonce' => false,
702
+			],
703
+			'settings'                 => [
704
+				'nav'           => [
705
+					'label' => esc_html__('Settings', 'event_espresso'),
706
+					'icon' => 'dashicons-admin-generic',
707
+					'order' => 40,
708
+				],
709
+				'metaboxes'     => ['_messages_settings_metaboxes'],
710
+				'help_tabs'     => [
711
+					'messages_settings_help_tab'               => [
712
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
713
+						'filename' => 'messages_settings',
714
+					],
715
+					'messages_settings_message_types_help_tab' => [
716
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
717
+						'filename' => 'messages_settings_message_types',
718
+					],
719
+					'messages_settings_messengers_help_tab'    => [
720
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
721
+						'filename' => 'messages_settings_messengers',
722
+					],
723
+				],
724
+				'require_nonce' => false,
725
+			],
726
+		];
727
+	}
728
+
729
+
730
+	protected function _add_screen_options()
731
+	{
732
+		// todo
733
+	}
734
+
735
+
736
+	protected function _add_screen_options_global_mtps()
737
+	{
738
+		/**
739
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
740
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
741
+		 */
742
+		$page_title              = $this->_admin_page_title;
743
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
744
+		$this->_per_page_screen_option();
745
+		$this->_admin_page_title = $page_title;
746
+	}
747
+
748
+
749
+	protected function _add_screen_options_default()
750
+	{
751
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
752
+		$this->_per_page_screen_option();
753
+	}
754
+
755
+
756
+	// none of the below group are currently used for Messages
757
+	protected function _add_feature_pointers()
758
+	{
759
+	}
760
+
761
+
762
+	public function admin_init()
763
+	{
764
+	}
765
+
766
+
767
+	public function admin_notices()
768
+	{
769
+	}
770
+
771
+
772
+	public function admin_footer_scripts()
773
+	{
774
+	}
775
+
776
+
777
+	public function messages_help_tab()
778
+	{
779
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
780
+	}
781
+
782
+
783
+	public function messengers_help_tab()
784
+	{
785
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
786
+	}
787
+
788
+
789
+	public function message_types_help_tab()
790
+	{
791
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
792
+	}
793
+
794
+
795
+	public function messages_overview_help_tab()
796
+	{
797
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
798
+	}
799
+
800
+
801
+	public function message_templates_help_tab()
802
+	{
803
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
804
+	}
805
+
806
+
807
+	public function edit_message_template_help_tab()
808
+	{
809
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
810
+						. esc_attr__('Editor Title', 'event_espresso')
811
+						. '" />';
812
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
813
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
814
+						. '" />';
815
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
816
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
817
+						. '" />';
818
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
819
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
820
+						. '" />';
821
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
822
+						. esc_attr__('Publish Metabox', 'event_espresso')
823
+						. '" />';
824
+		EEH_Template::display_template(
825
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
826
+			$args
827
+		);
828
+	}
829
+
830
+
831
+	/**
832
+	 * @throws ReflectionException
833
+	 * @throws EE_Error
834
+	 */
835
+	public function message_template_shortcodes_help_tab()
836
+	{
837
+		$this->_set_shortcodes();
838
+		$args['shortcodes'] = $this->_shortcodes;
839
+		EEH_Template::display_template(
840
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
841
+			$args
842
+		);
843
+	}
844
+
845
+
846
+	public function preview_message_help_tab()
847
+	{
848
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
849
+	}
850
+
851
+
852
+	public function settings_help_tab()
853
+	{
854
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
855
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
856
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
857
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
858
+		$args['img3'] = '<div class="ee-switch">'
859
+						. '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
860
+						. '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
861
+						. '</div>';
862
+		$args['img4'] = '<div class="switch">'
863
+						. '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
864
+						. '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
865
+						. '</div>';
866
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
867
+	}
868
+
869
+
870
+	public function load_scripts_styles()
871
+	{
872
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
873
+		wp_enqueue_style('espresso_ee_msg');
874
+
875
+		wp_register_script(
876
+			'ee-messages-settings',
877
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
878
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
879
+			EVENT_ESPRESSO_VERSION,
880
+			true
881
+		);
882
+		wp_register_script(
883
+			'ee-msg-list-table-js',
884
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
885
+			['ee-dialog'],
886
+			EVENT_ESPRESSO_VERSION
887
+		);
888
+	}
889
+
890
+
891
+	public function load_scripts_styles_default()
892
+	{
893
+		wp_enqueue_script('ee-msg-list-table-js');
894
+	}
895
+
896
+
897
+	public function wp_editor_css($mce_css)
898
+	{
899
+		// if we're on the edit_message_template route
900
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
901
+			$message_type_name = $this->_active_message_type_name;
902
+
903
+			// we're going to REPLACE the existing mce css
904
+			// we need to get the css file location from the active messenger
905
+			$mce_css = $this->_active_messenger->get_variation(
906
+				$this->_template_pack,
907
+				$message_type_name,
908
+				true,
909
+				'wpeditor',
910
+				$this->_variation
911
+			);
912
+		}
913
+
914
+		return $mce_css;
915
+	}
916
+
917
+
918
+	/**
919
+	 * @throws EE_Error
920
+	 * @throws ReflectionException
921
+	 */
922
+	public function load_scripts_styles_edit_message_template()
923
+	{
924
+
925
+		$this->_set_shortcodes();
926
+
927
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
928
+			esc_html__(
929
+				'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.',
930
+				'event_espresso'
931
+			),
932
+			$this->_message_template_group->messenger_obj()->label['singular'],
933
+			$this->_message_template_group->message_type_obj()->label['singular']
934
+		);
935
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
936
+			'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?',
937
+			'event_espresso'
938
+		);
939
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
940
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
941
+			'event_espresso'
942
+		);
943
+
944
+		wp_register_script(
945
+			'ee_msgs_edit_js',
946
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
947
+			['jquery'],
948
+			EVENT_ESPRESSO_VERSION
949
+		);
950
+
951
+		wp_enqueue_script('ee_admin_js');
952
+		wp_enqueue_script('ee_msgs_edit_js');
953
+
954
+		// add in special css for tiny_mce
955
+		add_filter('mce_css', [$this, 'wp_editor_css']);
956
+	}
957
+
958
+
959
+	/**
960
+	 * @throws EE_Error
961
+	 * @throws ReflectionException
962
+	 */
963
+	public function load_scripts_styles_display_preview_message()
964
+	{
965
+		$this->_set_message_template_group();
966
+		if ($this->_active_messenger_name) {
967
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
968
+				$this->_active_messenger_name
969
+			);
970
+		}
971
+
972
+		wp_enqueue_style(
973
+			'espresso_preview_css',
974
+			$this->_active_messenger->get_variation(
975
+				$this->_template_pack,
976
+				$this->_active_message_type_name,
977
+				true,
978
+				'preview',
979
+				$this->_variation
980
+			)
981
+		);
982
+	}
983
+
984
+
985
+	public function load_scripts_styles_settings()
986
+	{
987
+		wp_register_style(
988
+			'ee-message-settings',
989
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
990
+			[],
991
+			EVENT_ESPRESSO_VERSION
992
+		);
993
+		wp_enqueue_style('ee-text-links');
994
+		wp_enqueue_style('ee-message-settings');
995
+		wp_enqueue_script('ee-messages-settings');
996
+	}
997
+
998
+
999
+	/**
1000
+	 * set views array for List Table
1001
+	 */
1002
+	public function _set_list_table_views_global_mtps()
1003
+	{
1004
+		$this->_views = [
1005
+			'in_use' => [
1006
+				'slug'  => 'in_use',
1007
+				'label' => esc_html__('In Use', 'event_espresso'),
1008
+				'count' => 0,
1009
+			],
1010
+		];
1011
+	}
1012
+
1013
+
1014
+	/**
1015
+	 * Set views array for the Custom Template List Table
1016
+	 */
1017
+	public function _set_list_table_views_custom_mtps()
1018
+	{
1019
+		$this->_set_list_table_views_global_mtps();
1020
+		$this->_views['in_use']['bulk_action'] = [
1021
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1022
+		];
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * set views array for message queue list table
1028
+	 *
1029
+	 * @throws InvalidDataTypeException
1030
+	 * @throws InvalidInterfaceException
1031
+	 * @throws InvalidArgumentException
1032
+	 * @throws EE_Error
1033
+	 * @throws ReflectionException
1034
+	 */
1035
+	public function _set_list_table_views_default()
1036
+	{
1037
+		EE_Registry::instance()->load_helper('Template');
1038
+
1039
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1040
+			'ee_send_message',
1041
+			'message_list_table_bulk_actions'
1042
+		)
1043
+			? [
1044
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1045
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1046
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1047
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1048
+			]
1049
+			: [];
1050
+
1051
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1052
+			'ee_delete_messages',
1053
+			'message_list_table_bulk_actions'
1054
+		)
1055
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1056
+			: [];
1057
+
1058
+
1059
+		$this->_views = [
1060
+			'all' => [
1061
+				'slug'        => 'all',
1062
+				'label'       => esc_html__('All', 'event_espresso'),
1063
+				'count'       => 0,
1064
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1065
+			],
1066
+		];
1067
+
1068
+
1069
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1070
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1071
+				continue;
1072
+			}
1073
+			$status_bulk_actions = $common_bulk_actions;
1074
+			// unset bulk actions not applying to status
1075
+			if (! empty($status_bulk_actions)) {
1076
+				switch ($status) {
1077
+					case EEM_Message::status_idle:
1078
+					case EEM_Message::status_resend:
1079
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1080
+						break;
1081
+
1082
+					case EEM_Message::status_failed:
1083
+					case EEM_Message::status_debug_only:
1084
+					case EEM_Message::status_messenger_executing:
1085
+						$status_bulk_actions = [];
1086
+						break;
1087
+
1088
+					case EEM_Message::status_incomplete:
1089
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1090
+						break;
1091
+
1092
+					case EEM_Message::status_retry:
1093
+					case EEM_Message::status_sent:
1094
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1095
+						break;
1096
+				}
1097
+			}
1098
+
1099
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1100
+			if ($status === EEM_Message::status_messenger_executing) {
1101
+				continue;
1102
+			}
1103
+
1104
+			$this->_views[ strtolower($status) ] = [
1105
+				'slug'        => strtolower($status),
1106
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1107
+				'count'       => 0,
1108
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1109
+			];
1110
+		}
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 * @throws EE_Error
1116
+	 */
1117
+	protected function _ee_default_messages_overview_list_table()
1118
+	{
1119
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1120
+		$this->display_admin_list_table_page_with_no_sidebar();
1121
+	}
1122
+
1123
+
1124
+	/**
1125
+	 * @throws EE_Error
1126
+	 * @throws ReflectionException
1127
+	 */
1128
+	protected function _message_queue_list_table()
1129
+	{
1130
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1131
+		$this->_template_args['per_column']        = 6;
1132
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1133
+		$message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());
1134
+		$this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : '';
1135
+		$this->display_admin_list_table_page_with_no_sidebar();
1136
+	}
1137
+
1138
+
1139
+	/**
1140
+	 * @throws EE_Error
1141
+	 */
1142
+	protected function _message_legend_items()
1143
+	{
1144
+
1145
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1146
+		$action_items       = [];
1147
+
1148
+		foreach ($action_css_classes as $action_item => $action_details) {
1149
+			if ($action_item === 'see_notifications_for') {
1150
+				continue;
1151
+			}
1152
+			$action_items[ $action_item ] = [
1153
+				'class' => $action_details['css_class'],
1154
+				'desc'  => $action_details['label'],
1155
+			];
1156
+		}
1157
+
1158
+		/** @var array $status_items status legend setup */
1159
+		$status_items = [
1160
+			'sent_status'                => [
1161
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1162
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1163
+			],
1164
+			'idle_status'                => [
1165
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1166
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1167
+			],
1168
+			'failed_status'              => [
1169
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1170
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1171
+			],
1172
+			'messenger_executing_status' => [
1173
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1174
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1175
+			],
1176
+			'resend_status'              => [
1177
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1178
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1179
+			],
1180
+			'incomplete_status'          => [
1181
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1182
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1183
+			],
1184
+			'retry_status'               => [
1185
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1186
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1187
+			],
1188
+		];
1189
+		if (EEM_Message::debug()) {
1190
+			$status_items['debug_only_status'] = [
1191
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1192
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1193
+			];
1194
+		}
1195
+
1196
+		return array_merge($action_items, $status_items);
1197
+	}
1198
+
1199
+
1200
+	/**
1201
+	 * @throws EE_Error
1202
+	 */
1203
+	protected function _custom_mtps_preview()
1204
+	{
1205
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1206
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1207
+												. ' alt="' . esc_attr__(
1208
+													'Preview Custom Message Templates screenshot',
1209
+													'event_espresso'
1210
+												) . '" />';
1211
+		$this->_template_args['preview_text'] = '<strong>'
1212
+												. esc_html__(
1213
+													'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.',
1214
+													'event_espresso'
1215
+												)
1216
+												. '</strong>';
1217
+
1218
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1219
+	}
1220
+
1221
+
1222
+	/**
1223
+	 * get_message_templates
1224
+	 * This gets all the message templates for listing on the overview list.
1225
+	 *
1226
+	 * @access public
1227
+	 * @param int    $per_page the amount of templates groups to show per page
1228
+	 * @param string $type     the current _view we're getting templates for
1229
+	 * @param bool   $count    return count?
1230
+	 * @param bool   $all      disregard any paging info (get all data);
1231
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1232
+	 * @return array
1233
+	 * @throws EE_Error
1234
+	 * @throws InvalidArgumentException
1235
+	 * @throws InvalidDataTypeException
1236
+	 * @throws InvalidInterfaceException
1237
+	 */
1238
+	public function get_message_templates(
1239
+		$per_page = 10,
1240
+		$type = 'in_use',
1241
+		$count = false,
1242
+		$all = false,
1243
+		$global = true
1244
+	) {
1245
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1246
+		$this->request->setRequestParam('orderby', $orderby);
1247
+
1248
+		$order        = $this->request->getRequestParam('order', 'ASC');
1249
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1250
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1251
+
1252
+		$offset = ($current_page - 1) * $per_page;
1253
+		$limit  = $all ? null : [$offset, $per_page];
1254
+
1255
+		// options will match what is in the _views array property
1256
+		return $type === 'in_use'
1257
+			? $this->getMtgModel()->get_all_active_message_templates(
1258
+				$orderby,
1259
+				$order,
1260
+				$limit,
1261
+				$count,
1262
+				$global,
1263
+				true
1264
+			)
1265
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1266
+				$orderby,
1267
+				$order,
1268
+				$limit,
1269
+				$count,
1270
+				$global
1271
+			);
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 * filters etc might need a list of installed message_types
1277
+	 *
1278
+	 * @return array an array of message type objects
1279
+	 */
1280
+	public function get_installed_message_types()
1281
+	{
1282
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1283
+		$installed               = [];
1284
+
1285
+		foreach ($installed_message_types as $message_type) {
1286
+			$installed[ $message_type->name ] = $message_type;
1287
+		}
1288
+
1289
+		return $installed;
1290
+	}
1291
+
1292
+
1293
+	/**
1294
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1295
+	 *
1296
+	 * @param string $message_type
1297
+	 * @param string $messenger
1298
+	 * @param string $GRP_ID
1299
+	 *
1300
+	 * @throws EE_error
1301
+	 * @throws ReflectionException
1302
+	 */
1303
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1304
+	{
1305
+		// set values override any request data
1306
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1307
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1308
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1309
+
1310
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1311
+		if (empty($message_type) || empty($messenger)) {
1312
+			throw new EE_Error(
1313
+				esc_html__(
1314
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1315
+					'event_espresso'
1316
+				)
1317
+			);
1318
+		}
1319
+
1320
+		// we need the GRP_ID for the template being used as the base for the new template
1321
+		if (empty($GRP_ID)) {
1322
+			throw new EE_Error(
1323
+				esc_html__(
1324
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1325
+					'event_espresso'
1326
+				)
1327
+			);
1328
+		}
1329
+
1330
+		// let's just make sure the template gets generated!
1331
+
1332
+		// we need to reassign some variables for what the insert is expecting
1333
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1334
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1335
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1336
+
1337
+		$this->_insert_or_update_message_template(true);
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * @param string $message_type     message type slug
1343
+	 * @param string $messenger        messenger slug
1344
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1345
+	 *                                 off of.
1346
+	 * @throws EE_error
1347
+	 * @throws ReflectionException
1348
+	 * @deprecated 4.10.29.p
1349
+	 */
1350
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1351
+	{
1352
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1353
+	}
1354
+
1355
+
1356
+	/**
1357
+	 * _edit_message_template
1358
+	 *
1359
+	 * @access protected
1360
+	 * @return void
1361
+	 * @throws InvalidIdentifierException
1362
+	 * @throws DomainException
1363
+	 * @throws EE_Error
1364
+	 * @throws InvalidArgumentException
1365
+	 * @throws ReflectionException
1366
+	 * @throws InvalidDataTypeException
1367
+	 * @throws InvalidInterfaceException
1368
+	 */
1369
+	protected function _edit_message_template()
1370
+	{
1371
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1372
+		$template_fields = '';
1373
+		$sidebar_fields  = '';
1374
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1375
+		// valid html in the templates.
1376
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1377
+
1378
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1379
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1380
+
1381
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1382
+		$message_template_group = $this->_message_template_group;
1383
+		$c_label                = $message_template_group->context_label();
1384
+		$c_config               = $message_template_group->contexts_config();
1385
+
1386
+		reset($c_config);
1387
+		$context = $this->request->getRequestParam('context', key($c_config));
1388
+		$context = strtolower($context);
1389
+
1390
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1391
+
1392
+		$edit_message_template_form_url = add_query_arg(
1393
+			['action' => $action, 'noheader' => true],
1394
+			EE_MSG_ADMIN_URL
1395
+		);
1396
+
1397
+		// set active messenger for this view
1398
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1399
+			$message_template_group->messenger()
1400
+		);
1401
+		$this->_active_message_type_name = $message_template_group->message_type();
1402
+
1403
+
1404
+		// Do we have any validation errors?
1405
+		$validators = $this->_get_transient();
1406
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1407
+
1408
+
1409
+		// we need to assemble the title from Various details
1410
+		$context_label = sprintf(
1411
+			esc_html__('(%s %s)', 'event_espresso'),
1412
+			$c_config[ $context ]['label'],
1413
+			ucwords($c_label['label'])
1414
+		);
1415
+
1416
+		$title = sprintf(
1417
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1418
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1419
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1420
+			$context_label
1421
+		);
1422
+
1423
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1424
+		$this->_template_args['message_template'] = $message_template_group;
1425
+		$this->_template_args['is_extra_fields']  = false;
1426
+
1427
+
1428
+		// let's get EEH_MSG_Template so we can get template form fields
1429
+		$template_field_structure = EEH_MSG_Template::get_fields(
1430
+			$message_template_group->messenger(),
1431
+			$message_template_group->message_type()
1432
+		);
1433
+
1434
+		if (! $template_field_structure) {
1435
+			$template_field_structure = false;
1436
+			$template_fields          = esc_html__(
1437
+				'There was an error in assembling the fields for this display (you should see an error message)',
1438
+				'event_espresso'
1439
+			);
1440
+		}
1441
+
1442
+
1443
+		$message_templates = $message_template_group->context_templates();
1444
+
1445
+
1446
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1447
+		// will get handled in the "extra" array.
1448
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1449
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1450
+				unset($template_field_structure[ $context ][ $reference_field ]);
1451
+			}
1452
+		}
1453
+
1454
+		// let's loop through the template_field_structure and actually assemble the input fields!
1455
+		if (! empty($template_field_structure)) {
1456
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1457
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1458
+				// the extra array and reset them.
1459
+				if ($template_field === 'extra') {
1460
+					$this->_template_args['is_extra_fields'] = true;
1461
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1462
+						$message_template = $message_templates[ $context ][ $reference_field ];
1463
+						$content          = $message_template instanceof EE_Message_Template
1464
+							? $message_template->get('MTP_content')
1465
+							: '';
1466
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1467
+							// let's verify if we need this extra field via the shortcodes parameter.
1468
+							$continue = false;
1469
+							if (isset($extra_array['shortcodes_required'])) {
1470
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1471
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1472
+										$continue = true;
1473
+									}
1474
+								}
1475
+								if ($continue) {
1476
+									continue;
1477
+								}
1478
+							}
1479
+
1480
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1481
+
1482
+							$template_form_fields[ $field_id ]         = $extra_array;
1483
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1484
+																		 . $reference_field
1485
+																		 . '][content]['
1486
+																		 . $extra_field . ']';
1487
+							$css_class                                 = isset($extra_array['css_class'])
1488
+								? $extra_array['css_class']
1489
+								: '';
1490
+
1491
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1492
+																			  && in_array($extra_field, $v_fields, true)
1493
+																			  && (
1494
+																				  is_array($validators[ $extra_field ])
1495
+																				  && isset($validators[ $extra_field ]['msg'])
1496
+																			  )
1497
+								? 'validate-error ' . $css_class
1498
+								: $css_class;
1499
+
1500
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1501
+																		  && isset($content[ $extra_field ])
1502
+								? $content[ $extra_field ]
1503
+								: '';
1504
+
1505
+							// do we have a validation error?  if we do then let's use that value instead
1506
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1507
+								? $validators[ $extra_field ]['value']
1508
+								: $template_form_fields[ $field_id ]['value'];
1509
+
1510
+
1511
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1512
+
1513
+							// shortcode selector
1514
+							$field_name_to_use                                   = $extra_field === 'main'
1515
+								? 'content'
1516
+								: $extra_field;
1517
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1518
+								$field_name_to_use,
1519
+								$field_id
1520
+							);
1521
+						}
1522
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1523
+						$template_field_template_name_id = $reference_field . '-name';
1524
+
1525
+						$template_form_fields[ $template_field_MTP_id ] = [
1526
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1527
+							'label'      => null,
1528
+							'input'      => 'hidden',
1529
+							'type'       => 'int',
1530
+							'required'   => false,
1531
+							'validation' => false,
1532
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1533
+							'css_class'  => '',
1534
+							'format'     => '%d',
1535
+							'db-col'     => 'MTP_ID',
1536
+						];
1537
+
1538
+						$template_form_fields[ $template_field_template_name_id ] = [
1539
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1540
+							'label'      => null,
1541
+							'input'      => 'hidden',
1542
+							'type'       => 'string',
1543
+							'required'   => false,
1544
+							'validation' => true,
1545
+							'value'      => $reference_field,
1546
+							'css_class'  => '',
1547
+							'format'     => '%s',
1548
+							'db-col'     => 'MTP_template_field',
1549
+						];
1550
+					}
1551
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1552
+				} else {
1553
+					$field_id                                   = $template_field . '-content';
1554
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1555
+					$template_form_fields[ $field_id ]['name']  =
1556
+						'MTP_template_fields[' . $template_field . '][content]';
1557
+					$message_template                           =
1558
+						isset($message_templates[ $context ][ $template_field ])
1559
+							? $message_templates[ $context ][ $template_field ]
1560
+							: null;
1561
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1562
+																  && is_array($message_templates[ $context ])
1563
+																  && $message_template instanceof EE_Message_Template
1564
+						? $message_template->get('MTP_content')
1565
+						: '';
1566
+
1567
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1568
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1569
+						? $validators[ $template_field ]['value']
1570
+						: $template_form_fields[ $field_id ]['value'];
1571
+
1572
+
1573
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1574
+					$css_class                                      = isset($field_setup_array['css_class'])
1575
+						? $field_setup_array['css_class']
1576
+						: '';
1577
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1578
+																	  && in_array($template_field, $v_fields, true)
1579
+																	  && isset($validators[ $template_field ]['msg'])
1580
+						? 'validate-error ' . $css_class
1581
+						: $css_class;
1582
+
1583
+					// shortcode selector
1584
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1585
+						$template_field,
1586
+						$field_id
1587
+					);
1588
+				}
1589
+
1590
+				// k took care of content field(s) now let's take care of others.
1591
+
1592
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1593
+				$template_field_field_template_name_id = $template_field . '-name';
1594
+
1595
+				// foreach template field there are actually two form fields created
1596
+				$template_form_fields[ $template_field_MTP_id ] = [
1597
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1598
+					'label'      => null,
1599
+					'input'      => 'hidden',
1600
+					'type'       => 'int',
1601
+					'required'   => false,
1602
+					'validation' => true,
1603
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1604
+					'css_class'  => '',
1605
+					'format'     => '%d',
1606
+					'db-col'     => 'MTP_ID',
1607
+				];
1608
+
1609
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1610
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1611
+					'label'      => null,
1612
+					'input'      => 'hidden',
1613
+					'type'       => 'string',
1614
+					'required'   => false,
1615
+					'validation' => true,
1616
+					'value'      => $template_field,
1617
+					'css_class'  => '',
1618
+					'format'     => '%s',
1619
+					'db-col'     => 'MTP_template_field',
1620
+				];
1621
+			}
1622
+
1623
+			// add other fields
1624
+			$template_form_fields['ee-msg-current-context'] = [
1625
+				'name'       => 'MTP_context',
1626
+				'label'      => null,
1627
+				'input'      => 'hidden',
1628
+				'type'       => 'string',
1629
+				'required'   => false,
1630
+				'validation' => true,
1631
+				'value'      => $context,
1632
+				'css_class'  => '',
1633
+				'format'     => '%s',
1634
+				'db-col'     => 'MTP_context',
1635
+			];
1636
+
1637
+			$template_form_fields['ee-msg-grp-id'] = [
1638
+				'name'       => 'GRP_ID',
1639
+				'label'      => null,
1640
+				'input'      => 'hidden',
1641
+				'type'       => 'int',
1642
+				'required'   => false,
1643
+				'validation' => true,
1644
+				'value'      => $GRP_ID,
1645
+				'css_class'  => '',
1646
+				'format'     => '%d',
1647
+				'db-col'     => 'GRP_ID',
1648
+			];
1649
+
1650
+			$template_form_fields['ee-msg-messenger'] = [
1651
+				'name'       => 'MTP_messenger',
1652
+				'label'      => null,
1653
+				'input'      => 'hidden',
1654
+				'type'       => 'string',
1655
+				'required'   => false,
1656
+				'validation' => true,
1657
+				'value'      => $message_template_group->messenger(),
1658
+				'css_class'  => '',
1659
+				'format'     => '%s',
1660
+				'db-col'     => 'MTP_messenger',
1661
+			];
1662
+
1663
+			$template_form_fields['ee-msg-message-type'] = [
1664
+				'name'       => 'MTP_message_type',
1665
+				'label'      => null,
1666
+				'input'      => 'hidden',
1667
+				'type'       => 'string',
1668
+				'required'   => false,
1669
+				'validation' => true,
1670
+				'value'      => $message_template_group->message_type(),
1671
+				'css_class'  => '',
1672
+				'format'     => '%s',
1673
+				'db-col'     => 'MTP_message_type',
1674
+			];
1675
+
1676
+			$sidebar_form_fields['ee-msg-is-global'] = [
1677
+				'name'       => 'MTP_is_global',
1678
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1679
+				'input'      => 'hidden',
1680
+				'type'       => 'int',
1681
+				'required'   => false,
1682
+				'validation' => true,
1683
+				'value'      => $message_template_group->get('MTP_is_global'),
1684
+				'css_class'  => '',
1685
+				'format'     => '%d',
1686
+				'db-col'     => 'MTP_is_global',
1687
+			];
1688
+
1689
+			$sidebar_form_fields['ee-msg-is-override'] = [
1690
+				'name'       => 'MTP_is_override',
1691
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1692
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1693
+				'type'       => 'int',
1694
+				'required'   => false,
1695
+				'validation' => true,
1696
+				'value'      => $message_template_group->get('MTP_is_override'),
1697
+				'css_class'  => '',
1698
+				'format'     => '%d',
1699
+				'db-col'     => 'MTP_is_override',
1700
+			];
1701
+
1702
+			$sidebar_form_fields['ee-msg-is-active'] = [
1703
+				'name'       => 'MTP_is_active',
1704
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1705
+				'input'      => 'hidden',
1706
+				'type'       => 'int',
1707
+				'required'   => false,
1708
+				'validation' => true,
1709
+				'value'      => $message_template_group->is_active(),
1710
+				'css_class'  => '',
1711
+				'format'     => '%d',
1712
+				'db-col'     => 'MTP_is_active',
1713
+			];
1714
+
1715
+			$sidebar_form_fields['ee-msg-deleted'] = [
1716
+				'name'       => 'MTP_deleted',
1717
+				'label'      => null,
1718
+				'input'      => 'hidden',
1719
+				'type'       => 'int',
1720
+				'required'   => false,
1721
+				'validation' => true,
1722
+				'value'      => $message_template_group->get('MTP_deleted'),
1723
+				'css_class'  => '',
1724
+				'format'     => '%d',
1725
+				'db-col'     => 'MTP_deleted',
1726
+			];
1727
+			$sidebar_form_fields['ee-msg-author']  = [
1728
+				'name'       => 'MTP_user_id',
1729
+				'label'      => esc_html__('Author', 'event_espresso'),
1730
+				'input'      => 'hidden',
1731
+				'type'       => 'int',
1732
+				'required'   => false,
1733
+				'validation' => false,
1734
+				'value'      => $message_template_group->user(),
1735
+				'format'     => '%d',
1736
+				'db-col'     => 'MTP_user_id',
1737
+			];
1738
+
1739
+			$sidebar_form_fields['ee-msg-route'] = [
1740
+				'name'  => 'action',
1741
+				'input' => 'hidden',
1742
+				'type'  => 'string',
1743
+				'value' => $action,
1744
+			];
1745
+
1746
+			$sidebar_form_fields['ee-msg-id']        = [
1747
+				'name'  => 'id',
1748
+				'input' => 'hidden',
1749
+				'type'  => 'int',
1750
+				'value' => $GRP_ID,
1751
+			];
1752
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1753
+				'name'  => $action . '_nonce',
1754
+				'input' => 'hidden',
1755
+				'type'  => 'string',
1756
+				'value' => wp_create_nonce($action . '_nonce'),
1757
+			];
1758
+
1759
+			$template_switch = $this->request->getRequestParam('template_switch');
1760
+			if ($template_switch) {
1761
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1762
+					'name'  => 'template_switch',
1763
+					'input' => 'hidden',
1764
+					'type'  => 'int',
1765
+					'value' => 1,
1766
+				];
1767
+			}
1768
+
1769
+
1770
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1771
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1772
+		} //end if ( !empty($template_field_structure) )
1773
+
1774
+		// set extra content for publish box
1775
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1776
+		$this->_set_publish_post_box_vars(
1777
+			'id',
1778
+			$GRP_ID,
1779
+			false,
1780
+			add_query_arg(
1781
+				['action' => 'global_mtps'],
1782
+				$this->_admin_base_url
1783
+			)
1784
+		);
1785
+
1786
+		// add preview button
1787
+		$preview_url    = parent::add_query_args_and_nonce(
1788
+			[
1789
+				'message_type' => $message_template_group->message_type(),
1790
+				'messenger'    => $message_template_group->messenger(),
1791
+				'context'      => $context,
1792
+				'GRP_ID'       => $GRP_ID,
1793
+				'evt_id'       => $EVT_ID ?: false,
1794
+				'action'       => 'preview_message',
1795
+			],
1796
+			$this->_admin_base_url
1797
+		);
1798
+		$preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1799
+						  . esc_html__('Preview', 'event_espresso')
1800
+						  . '</a>';
1801
+
1802
+
1803
+		// setup context switcher
1804
+		$this->_set_context_switcher(
1805
+			$message_template_group,
1806
+			[
1807
+				'page'    => 'espresso_messages',
1808
+				'action'  => 'edit_message_template',
1809
+				'id'      => $GRP_ID,
1810
+				'evt_id'  => $EVT_ID,
1811
+				'context' => $context,
1812
+				'extra'   => $preview_button,
1813
+			]
1814
+		);
1815
+
1816
+
1817
+		// main box
1818
+		$this->_template_args['template_fields']                         = $template_fields;
1819
+		$this->_template_args['sidebar_box_id']                          = 'details';
1820
+		$this->_template_args['action']                                  = $action;
1821
+		$this->_template_args['context']                                 = $context;
1822
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1823
+		$this->_template_args['learn_more_about_message_templates_link'] =
1824
+			$this->_learn_more_about_message_templates_link();
1825
+
1826
+
1827
+		$this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';
1828
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1829
+			$message_template_group,
1830
+			$context,
1831
+			$context_label
1832
+		);
1833
+		$this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1834
+		$this->_template_args['before_admin_page_content'] .= '</div>';
1835
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1836
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1837
+
1838
+		$this->_template_path = $this->_template_args['GRP_ID']
1839
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1840
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1841
+
1842
+		// send along EE_Message_Template_Group object for further template use.
1843
+		$this->_template_args['MTP'] = $message_template_group;
1844
+
1845
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1846
+			$this->_template_path,
1847
+			$this->_template_args,
1848
+			true
1849
+		);
1850
+
1851
+
1852
+		// finally, let's set the admin_page title
1853
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1854
+
1855
+
1856
+		// we need to take care of setting the shortcodes property for use elsewhere.
1857
+		$this->_set_shortcodes();
1858
+
1859
+
1860
+		// final template wrapper
1861
+		$this->display_admin_page_with_sidebar();
1862
+	}
1863
+
1864
+
1865
+	public function filter_tinymce_init($mceInit, $editor_id)
1866
+	{
1867
+		return $mceInit;
1868
+	}
1869
+
1870
+
1871
+	public function add_context_switcher()
1872
+	{
1873
+		return $this->_context_switcher;
1874
+	}
1875
+
1876
+
1877
+	/**
1878
+	 * Adds the activation/deactivation toggle for the message template context.
1879
+	 *
1880
+	 * @param EE_Message_Template_Group $message_template_group
1881
+	 * @param string                    $context
1882
+	 * @param string                    $context_label
1883
+	 * @return string
1884
+	 * @throws DomainException
1885
+	 * @throws EE_Error
1886
+	 * @throws InvalidIdentifierException
1887
+	 * @throws ReflectionException
1888
+	 */
1889
+	protected function add_active_context_element(
1890
+		EE_Message_Template_Group $message_template_group,
1891
+		$context,
1892
+		$context_label
1893
+	) {
1894
+		$template_args = [
1895
+			'context'                   => $context,
1896
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1897
+			'is_active'                 => $message_template_group->is_context_active($context),
1898
+			'on_off_action'             => $message_template_group->is_context_active($context)
1899
+				? 'context-off'
1900
+				: 'context-on',
1901
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1902
+			'message_template_group_id' => $message_template_group->ID(),
1903
+		];
1904
+		return EEH_Template::display_template(
1905
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1906
+			$template_args,
1907
+			true
1908
+		);
1909
+	}
1910
+
1911
+
1912
+	/**
1913
+	 * Ajax callback for `toggle_context_template` ajax action.
1914
+	 * Handles toggling the message context on or off.
1915
+	 *
1916
+	 * @throws EE_Error
1917
+	 * @throws InvalidArgumentException
1918
+	 * @throws InvalidDataTypeException
1919
+	 * @throws InvalidIdentifierException
1920
+	 * @throws InvalidInterfaceException
1921
+	 */
1922
+	public function toggle_context_template()
1923
+	{
1924
+		$success = true;
1925
+		// check for required data
1926
+		if (
1927
+			! (
1928
+				$this->request->requestParamIsSet('message_template_group_id')
1929
+				&& $this->request->requestParamIsSet('context')
1930
+				&& $this->request->requestParamIsSet('status')
1931
+			)
1932
+		) {
1933
+			EE_Error::add_error(
1934
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1935
+				__FILE__,
1936
+				__FUNCTION__,
1937
+				__LINE__
1938
+			);
1939
+			$success = false;
1940
+		}
1941
+
1942
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1943
+		$context = $this->request->getRequestParam('context', '');
1944
+		$status  = $this->request->getRequestParam('status', '');
1945
+
1946
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1947
+
1948
+		if ($status !== 'off' && $status !== 'on') {
1949
+			EE_Error::add_error(
1950
+				sprintf(
1951
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1952
+					$status
1953
+				),
1954
+				__FILE__,
1955
+				__FUNCTION__,
1956
+				__LINE__
1957
+			);
1958
+			$success = false;
1959
+		}
1960
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1961
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1962
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1963
+			EE_Error::add_error(
1964
+				sprintf(
1965
+					esc_html__(
1966
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1967
+						'event_espresso'
1968
+					),
1969
+					$message_template_group_id,
1970
+					'EE_Message_Template_Group'
1971
+				),
1972
+				__FILE__,
1973
+				__FUNCTION__,
1974
+				__LINE__
1975
+			);
1976
+			$success = false;
1977
+		}
1978
+		if ($success) {
1979
+			$success = $status === 'off'
1980
+				? $message_template_group->deactivate_context($context)
1981
+				: $message_template_group->activate_context($context);
1982
+		}
1983
+		$this->_template_args['success'] = $success;
1984
+		$this->_return_json();
1985
+	}
1986
+
1987
+
1988
+	public function _add_form_element_before()
1989
+	{
1990
+		return '<form method="post" action="'
1991
+			   . $this->_template_args['edit_message_template_form_url']
1992
+			   . '" id="ee-msg-edit-frm">';
1993
+	}
1994
+
1995
+
1996
+	public function _add_form_element_after()
1997
+	{
1998
+		return '</form>';
1999
+	}
2000
+
2001
+
2002
+	/**
2003
+	 * This executes switching the template pack for a message template.
2004
+	 *
2005
+	 * @throws EE_Error
2006
+	 * @throws InvalidDataTypeException
2007
+	 * @throws InvalidInterfaceException
2008
+	 * @throws InvalidArgumentException
2009
+	 * @throws ReflectionException
2010
+	 * @since 4.5.0
2011
+	 */
2012
+	public function switch_template_pack()
2013
+	{
2014
+
2015
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2016
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2017
+
2018
+		// verify we have needed values.
2019
+		if (empty($GRP_ID) || empty($template_pack)) {
2020
+			$this->_template_args['error'] = true;
2021
+			EE_Error::add_error(
2022
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2023
+				__FILE__,
2024
+				__FUNCTION__,
2025
+				__LINE__
2026
+			);
2027
+		} else {
2028
+			// get template, set the new template_pack and then reset to default
2029
+			/** @var EE_Message_Template_Group $message_template_group */
2030
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2031
+
2032
+			$message_template_group->set_template_pack_name($template_pack);
2033
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2034
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2035
+
2036
+			$query_args = $this->_reset_to_default_template();
2037
+
2038
+			if (empty($query_args['id'])) {
2039
+				EE_Error::add_error(
2040
+					esc_html__(
2041
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2042
+						'event_espresso'
2043
+					),
2044
+					__FILE__,
2045
+					__FUNCTION__,
2046
+					__LINE__
2047
+				);
2048
+				$this->_template_args['error'] = true;
2049
+			} else {
2050
+				$template_label       = $message_template_group->get_template_pack()->label;
2051
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2052
+				EE_Error::add_success(
2053
+					sprintf(
2054
+						esc_html__(
2055
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2056
+							'event_espresso'
2057
+						),
2058
+						$template_label,
2059
+						$template_pack_labels->template_pack
2060
+					)
2061
+				);
2062
+				// generate the redirect url for js.
2063
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2064
+
2065
+				$this->_template_args['data']['redirect_url'] = $url;
2066
+				$this->_template_args['success']              = true;
2067
+			}
2068
+
2069
+			$this->_return_json();
2070
+		}
2071
+	}
2072
+
2073
+
2074
+	/**
2075
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2076
+	 * they want.
2077
+	 *
2078
+	 * @access protected
2079
+	 * @return array|void
2080
+	 * @throws EE_Error
2081
+	 * @throws InvalidArgumentException
2082
+	 * @throws InvalidDataTypeException
2083
+	 * @throws InvalidInterfaceException
2084
+	 * @throws ReflectionException
2085
+	 */
2086
+	protected function _reset_to_default_template()
2087
+	{
2088
+		$templates    = [];
2089
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2090
+		$messenger    = $this->request->getRequestParam('msgr');
2091
+		$message_type = $this->request->getRequestParam('mt');
2092
+		// we need to make sure we've got the info we need.
2093
+		if (! ($GRP_ID && $messenger && $message_type)) {
2094
+			EE_Error::add_error(
2095
+				esc_html__(
2096
+					'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.',
2097
+					'event_espresso'
2098
+				),
2099
+				__FILE__,
2100
+				__FUNCTION__,
2101
+				__LINE__
2102
+			);
2103
+		}
2104
+
2105
+		// all templates will be reset to whatever the defaults are
2106
+		// for the global template matching the messenger and message type.
2107
+		$success = ! empty($GRP_ID);
2108
+
2109
+		if ($success) {
2110
+			// let's first determine if the incoming template is a global template,
2111
+			// if it isn't then we need to get the global template matching messenger and message type.
2112
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2113
+
2114
+
2115
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2116
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2117
+
2118
+			if ($success) {
2119
+				// if successfully deleted, lets generate the new ones.
2120
+				// Note. We set GLOBAL to true, because resets on ANY template
2121
+				// will use the related global template defaults for regeneration.
2122
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2123
+				// HOWEVER, we DO keep the template pack and template variation set
2124
+				// for the current custom template when resetting.
2125
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2126
+			}
2127
+		}
2128
+
2129
+		// any error messages?
2130
+		if (! $success) {
2131
+			EE_Error::add_error(
2132
+				esc_html__(
2133
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2134
+					'event_espresso'
2135
+				),
2136
+				__FILE__,
2137
+				__FUNCTION__,
2138
+				__LINE__
2139
+			);
2140
+		}
2141
+
2142
+		// all good, let's add a success message!
2143
+		if ($success && ! empty($templates)) {
2144
+			// the info for the template we generated is the first element in the returned array
2145
+			EE_Error::overwrite_success();
2146
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2147
+		}
2148
+
2149
+
2150
+		$query_args = [
2151
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2152
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2153
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2154
+		];
2155
+
2156
+		// if called via ajax then we return query args otherwise redirect
2157
+		if ($this->request->isAjax()) {
2158
+			return $query_args;
2159
+		}
2160
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2161
+	}
2162
+
2163
+
2164
+	/**
2165
+	 * Retrieve and set the message preview for display.
2166
+	 *
2167
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2168
+	 * @return string
2169
+	 * @throws ReflectionException
2170
+	 * @throws EE_Error
2171
+	 * @throws InvalidArgumentException
2172
+	 * @throws InvalidDataTypeException
2173
+	 * @throws InvalidInterfaceException
2174
+	 */
2175
+	public function _preview_message($send = false)
2176
+	{
2177
+		// first make sure we've got the necessary parameters
2178
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2179
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2180
+			EE_Error::add_error(
2181
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2182
+				__FILE__,
2183
+				__FUNCTION__,
2184
+				__LINE__
2185
+			);
2186
+		}
2187
+
2188
+		$context = $this->request->getRequestParam('context');
2189
+		// get the preview!
2190
+		$preview = EED_Messages::preview_message(
2191
+			$this->_active_message_type_name,
2192
+			$context,
2193
+			$this->_active_messenger_name,
2194
+			$send
2195
+		);
2196
+
2197
+		if ($send) {
2198
+			return $preview;
2199
+		}
2200
+
2201
+		// if we have an evt_id set on the request, use it.
2202
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2203
+
2204
+		// let's add a button to go back to the edit view
2205
+		$query_args             = [
2206
+			'id'      => $GRP_ID,
2207
+			'evt_id'  => $EVT_ID,
2208
+			'context' => $context,
2209
+			'action'  => 'edit_message_template',
2210
+		];
2211
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2212
+		$preview_button         = '<a href="'
2213
+								  . $go_back_url
2214
+								  . '" class="button--secondary messages-preview-go-back-button">'
2215
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2216
+								  . '</a>';
2217
+		$message_types          = $this->get_installed_message_types();
2218
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2219
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2220
+			? ucwords($active_messenger->label['singular'])
2221
+			: esc_html__('Unknown Messenger', 'event_espresso');
2222
+		// let's provide a helpful title for context
2223
+		$preview_title = sprintf(
2224
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2225
+			$active_messenger_label,
2226
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2227
+		);
2228
+		if (empty($preview)) {
2229
+			$this->noEventsErrorMessage();
2230
+		}
2231
+		// setup display of preview.
2232
+		$this->_admin_page_title                    = $preview_title;
2233
+		$this->_template_args['admin_page_title']   = $preview_title;
2234
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2235
+		$this->_template_args['data']['force_json'] = true;
2236
+
2237
+		return '';
2238
+	}
2239
+
2240
+
2241
+	/**
2242
+	 * Used to set an error if there are no events available for generating a preview/test send.
2243
+	 *
2244
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2245
+	 */
2246
+	protected function noEventsErrorMessage($test_send = false)
2247
+	{
2248
+		$events_url = parent::add_query_args_and_nonce(
2249
+			[
2250
+				'action' => 'default',
2251
+				'page'   => 'espresso_events',
2252
+			],
2253
+			admin_url('admin.php')
2254
+		);
2255
+		$message    = $test_send
2256
+			? esc_html__(
2257
+				'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!',
2258
+				'event_espresso'
2259
+			)
2260
+			: esc_html__(
2261
+				'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!',
2262
+				'event_espresso'
2263
+			);
2264
+
2265
+		EE_Error::add_attention(
2266
+			sprintf(
2267
+				$message,
2268
+				"<a href='{$events_url}'>",
2269
+				'</a>'
2270
+			)
2271
+		);
2272
+	}
2273
+
2274
+
2275
+	/**
2276
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2277
+	 * gets called automatically.
2278
+	 *
2279
+	 * @return void
2280
+	 * @throws EE_Error
2281
+	 * @since 4.5.0
2282
+	 *
2283
+	 */
2284
+	protected function _display_preview_message()
2285
+	{
2286
+		$this->display_admin_page_with_no_sidebar();
2287
+	}
2288
+
2289
+
2290
+	/**
2291
+	 * registers metaboxes that should show up on the "edit_message_template" page
2292
+	 *
2293
+	 * @access protected
2294
+	 * @return void
2295
+	 */
2296
+	protected function _register_edit_meta_boxes()
2297
+	{
2298
+		$this->addMetaBox(
2299
+			'mtp_valid_shortcodes',
2300
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2301
+			[$this, 'shortcode_meta_box'],
2302
+			$this->_current_screen->id,
2303
+			'side'
2304
+		);
2305
+		$this->addMetaBox(
2306
+			'mtp_extra_actions',
2307
+			esc_html__('Extra Actions', 'event_espresso'),
2308
+			[$this, 'extra_actions_meta_box'],
2309
+			$this->_current_screen->id,
2310
+			'side',
2311
+			'high'
2312
+		);
2313
+		$this->addMetaBox(
2314
+			'mtp_templates',
2315
+			esc_html__('Template Styles', 'event_espresso'),
2316
+			[$this, 'template_pack_meta_box'],
2317
+			$this->_current_screen->id,
2318
+			'side',
2319
+			'high'
2320
+		);
2321
+	}
2322
+
2323
+
2324
+	/**
2325
+	 * metabox content for all template pack and variation selection.
2326
+	 *
2327
+	 * @return void
2328
+	 * @throws DomainException
2329
+	 * @throws EE_Error
2330
+	 * @throws InvalidArgumentException
2331
+	 * @throws ReflectionException
2332
+	 * @throws InvalidDataTypeException
2333
+	 * @throws InvalidInterfaceException
2334
+	 * @since 4.5.0
2335
+	 */
2336
+	public function template_pack_meta_box()
2337
+	{
2338
+		$this->_set_message_template_group();
2339
+
2340
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2341
+
2342
+		$tp_select_values = [];
2343
+
2344
+		foreach ($tp_collection as $tp) {
2345
+			// only include template packs that support this messenger and message type!
2346
+			$supports = $tp->get_supports();
2347
+			if (
2348
+				! isset($supports[ $this->_message_template_group->messenger() ])
2349
+				|| ! in_array(
2350
+					$this->_message_template_group->message_type(),
2351
+					$supports[ $this->_message_template_group->messenger() ],
2352
+					true
2353
+				)
2354
+			) {
2355
+				// not supported
2356
+				continue;
2357
+			}
2358
+
2359
+			$tp_select_values[] = [
2360
+				'text' => $tp->label,
2361
+				'id'   => $tp->dbref,
2362
+			];
2363
+		}
2364
+
2365
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2366
+		// the default template pack.  This still allows for the odd template pack to override.
2367
+		if (empty($tp_select_values)) {
2368
+			$tp_select_values[] = [
2369
+				'text' => esc_html__('Default', 'event_espresso'),
2370
+				'id'   => 'default',
2371
+			];
2372
+		}
2373
+
2374
+		// setup variation select values for the currently selected template.
2375
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2376
+			$this->_message_template_group->messenger(),
2377
+			$this->_message_template_group->message_type()
2378
+		);
2379
+		$variations_select_values = [];
2380
+		foreach ($variations as $variation => $label) {
2381
+			$variations_select_values[] = [
2382
+				'text' => $label,
2383
+				'id'   => $variation,
2384
+			];
2385
+		}
2386
+
2387
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2388
+
2389
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2390
+			'MTP_template_pack',
2391
+			$tp_select_values,
2392
+			$this->_message_template_group->get_template_pack_name()
2393
+		);
2394
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2395
+			'MTP_template_variation',
2396
+			$variations_select_values,
2397
+			$this->_message_template_group->get_template_pack_variation()
2398
+		);
2399
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2400
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2401
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2402
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2403
+
2404
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2405
+
2406
+		EEH_Template::display_template($template, $template_args);
2407
+	}
2408
+
2409
+
2410
+	/**
2411
+	 * This meta box holds any extra actions related to Message Templates
2412
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2413
+	 *
2414
+	 * @access  public
2415
+	 * @return void
2416
+	 * @throws EE_Error
2417
+	 */
2418
+	public function extra_actions_meta_box()
2419
+	{
2420
+		$template_form_fields = [];
2421
+
2422
+		$extra_args = [
2423
+			'msgr'   => $this->_message_template_group->messenger(),
2424
+			'mt'     => $this->_message_template_group->message_type(),
2425
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2426
+		];
2427
+		// first we need to see if there are any fields
2428
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2429
+
2430
+		if (! empty($fields)) {
2431
+			// yup there be fields
2432
+			foreach ($fields as $field => $config) {
2433
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2434
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2435
+				$default  = isset($config['default']) ? $config['default'] : '';
2436
+				$default  = isset($config['value']) ? $config['value'] : $default;
2437
+
2438
+				// if type is hidden and the value is empty
2439
+				// something may have gone wrong so let's correct with the defaults
2440
+				$fix                = $config['input'] === 'hidden'
2441
+									  && isset($existing[ $field ])
2442
+									  && empty($existing[ $field ])
2443
+					? $default
2444
+					: '';
2445
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2446
+					? $existing[ $field ]
2447
+					: $fix;
2448
+
2449
+				$template_form_fields[ $field_id ] = [
2450
+					'name'       => 'test_settings_fld[' . $field . ']',
2451
+					'label'      => $config['label'],
2452
+					'input'      => $config['input'],
2453
+					'type'       => $config['type'],
2454
+					'required'   => $config['required'],
2455
+					'validation' => $config['validation'],
2456
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2457
+					'css_class'  => $config['css_class'],
2458
+					'options'    => isset($config['options']) ? $config['options'] : [],
2459
+					'default'    => $default,
2460
+					'format'     => $config['format'],
2461
+				];
2462
+			}
2463
+		}
2464
+
2465
+		$test_settings_html = ! empty($template_form_fields)
2466
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2467
+			: '';
2468
+
2469
+		// print out $test_settings_fields
2470
+		if (! empty($test_settings_html)) {
2471
+			$test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2472
+			$test_settings_html .= 'name="test_button" value="';
2473
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2474
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2475
+		}
2476
+
2477
+		// and button
2478
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2479
+		$test_settings_html .= '<p>';
2480
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2481
+		$test_settings_html .= '</p>';
2482
+		$test_settings_html .= $this->get_action_link_or_button(
2483
+			'reset_to_default',
2484
+			'reset',
2485
+			$extra_args,
2486
+			'button--primary reset-default-button'
2487
+		);
2488
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2489
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2490
+	}
2491
+
2492
+
2493
+	/**
2494
+	 * This returns the shortcode selector skeleton for a given context and field.
2495
+	 *
2496
+	 * @param string $field           The name of the field retrieving shortcodes for.
2497
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2498
+	 * @return string
2499
+	 * @throws DomainException
2500
+	 * @throws EE_Error
2501
+	 * @throws InvalidArgumentException
2502
+	 * @throws ReflectionException
2503
+	 * @throws InvalidDataTypeException
2504
+	 * @throws InvalidInterfaceException
2505
+	 * @since 4.9.rc.000
2506
+	 */
2507
+	protected function _get_shortcode_selector($field, $linked_input_id)
2508
+	{
2509
+		$template_args = [
2510
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2511
+			'fieldname'       => $field,
2512
+			'linked_input_id' => $linked_input_id,
2513
+		];
2514
+
2515
+		return EEH_Template::display_template(
2516
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2517
+			$template_args,
2518
+			true
2519
+		);
2520
+	}
2521
+
2522
+
2523
+	/**
2524
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2525
+	 * page)
2526
+	 *
2527
+	 * @access public
2528
+	 * @return void
2529
+	 * @throws EE_Error
2530
+	 * @throws InvalidArgumentException
2531
+	 * @throws ReflectionException
2532
+	 * @throws InvalidDataTypeException
2533
+	 * @throws InvalidInterfaceException
2534
+	 */
2535
+	public function shortcode_meta_box()
2536
+	{
2537
+		$shortcodes = $this->_get_shortcodes([], false);
2538
+		// just make sure the shortcodes property is set
2539
+		// $messenger = $this->_message_template_group->messenger_obj();
2540
+		// now let's set the content depending on the status of the shortcodes array
2541
+		if (empty($shortcodes)) {
2542
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2543
+			return;
2544
+		}
2545
+		?>
2546 2546
         <div style="float:right; margin-top:10px">
2547 2547
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2548
-            ?>
2548
+			?>
2549 2549
         </div>
2550 2550
         <p class="small-text">
2551 2551
             <?php printf(
2552
-                esc_html__(
2553
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2554
-                    'event_espresso'
2555
-                ),
2556
-                '<span class="dashicons dashicons-shortcode"></span>'
2557
-            ); ?>
2552
+				esc_html__(
2553
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2554
+					'event_espresso'
2555
+				),
2556
+				'<span class="dashicons dashicons-shortcode"></span>'
2557
+			); ?>
2558 2558
         </p>
2559 2559
         <?php
2560
-    }
2561
-
2562
-
2563
-    /**
2564
-     * used to set the $_shortcodes property for when its needed elsewhere.
2565
-     *
2566
-     * @access protected
2567
-     * @return void
2568
-     * @throws EE_Error
2569
-     * @throws InvalidArgumentException
2570
-     * @throws ReflectionException
2571
-     * @throws InvalidDataTypeException
2572
-     * @throws InvalidInterfaceException
2573
-     */
2574
-    protected function _set_shortcodes()
2575
-    {
2576
-
2577
-        // no need to run this if the property is already set
2578
-        if (! empty($this->_shortcodes)) {
2579
-            return;
2580
-        }
2581
-
2582
-        $this->_shortcodes = $this->_get_shortcodes();
2583
-    }
2584
-
2585
-
2586
-    /**
2587
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2588
-     * property)
2589
-     *
2590
-     * @access  protected
2591
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2592
-     *                         for. Defaults to all (for the given context)
2593
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2594
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2595
-     *                         true just an array of shortcode/label pairs.
2596
-     * @throws EE_Error
2597
-     * @throws InvalidArgumentException
2598
-     * @throws ReflectionException
2599
-     * @throws InvalidDataTypeException
2600
-     * @throws InvalidInterfaceException
2601
-     */
2602
-    protected function _get_shortcodes($fields = [], $merged = true)
2603
-    {
2604
-        $this->_set_message_template_group();
2605
-
2606
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2607
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2608
-        if (empty($GRP_ID)) {
2609
-            return [];
2610
-        }
2611
-        $context = $this->request->getRequestParam(
2612
-            'messenger',
2613
-            key($this->_message_template_group->contexts_config())
2614
-        );
2615
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2616
-    }
2617
-
2618
-
2619
-    /**
2620
-     * This sets the _message_template property (containing the called message_template object)
2621
-     *
2622
-     * @access protected
2623
-     * @return void
2624
-     * @throws EE_Error
2625
-     * @throws InvalidArgumentException
2626
-     * @throws ReflectionException
2627
-     * @throws InvalidDataTypeException
2628
-     * @throws InvalidInterfaceException
2629
-     */
2630
-    protected function _set_message_template_group()
2631
-    {
2632
-        // get out if this is already set.
2633
-        if (! empty($this->_message_template_group)) {
2634
-            return;
2635
-        }
2636
-
2637
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2638
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2639
-
2640
-        // let's get the message templates
2641
-        $this->_message_template_group = ! empty($GRP_ID)
2642
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2643
-            : $this->getMtgModel()->create_default_object();
2644
-
2645
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2646
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2647
-    }
2648
-
2649
-
2650
-    /**
2651
-     * sets up a context switcher for edit forms
2652
-     *
2653
-     * @access  protected
2654
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2655
-     * @param array                     $args                  various things the context switcher needs.
2656
-     * @throws EE_Error
2657
-     */
2658
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2659
-    {
2660
-        $context_details = $template_group_object->contexts_config();
2661
-        $context_label   = $template_group_object->context_label();
2662
-        ob_start();
2663
-        ?>
2560
+	}
2561
+
2562
+
2563
+	/**
2564
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2565
+	 *
2566
+	 * @access protected
2567
+	 * @return void
2568
+	 * @throws EE_Error
2569
+	 * @throws InvalidArgumentException
2570
+	 * @throws ReflectionException
2571
+	 * @throws InvalidDataTypeException
2572
+	 * @throws InvalidInterfaceException
2573
+	 */
2574
+	protected function _set_shortcodes()
2575
+	{
2576
+
2577
+		// no need to run this if the property is already set
2578
+		if (! empty($this->_shortcodes)) {
2579
+			return;
2580
+		}
2581
+
2582
+		$this->_shortcodes = $this->_get_shortcodes();
2583
+	}
2584
+
2585
+
2586
+	/**
2587
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2588
+	 * property)
2589
+	 *
2590
+	 * @access  protected
2591
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2592
+	 *                         for. Defaults to all (for the given context)
2593
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2594
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2595
+	 *                         true just an array of shortcode/label pairs.
2596
+	 * @throws EE_Error
2597
+	 * @throws InvalidArgumentException
2598
+	 * @throws ReflectionException
2599
+	 * @throws InvalidDataTypeException
2600
+	 * @throws InvalidInterfaceException
2601
+	 */
2602
+	protected function _get_shortcodes($fields = [], $merged = true)
2603
+	{
2604
+		$this->_set_message_template_group();
2605
+
2606
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2607
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2608
+		if (empty($GRP_ID)) {
2609
+			return [];
2610
+		}
2611
+		$context = $this->request->getRequestParam(
2612
+			'messenger',
2613
+			key($this->_message_template_group->contexts_config())
2614
+		);
2615
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2616
+	}
2617
+
2618
+
2619
+	/**
2620
+	 * This sets the _message_template property (containing the called message_template object)
2621
+	 *
2622
+	 * @access protected
2623
+	 * @return void
2624
+	 * @throws EE_Error
2625
+	 * @throws InvalidArgumentException
2626
+	 * @throws ReflectionException
2627
+	 * @throws InvalidDataTypeException
2628
+	 * @throws InvalidInterfaceException
2629
+	 */
2630
+	protected function _set_message_template_group()
2631
+	{
2632
+		// get out if this is already set.
2633
+		if (! empty($this->_message_template_group)) {
2634
+			return;
2635
+		}
2636
+
2637
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2638
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2639
+
2640
+		// let's get the message templates
2641
+		$this->_message_template_group = ! empty($GRP_ID)
2642
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2643
+			: $this->getMtgModel()->create_default_object();
2644
+
2645
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2646
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2647
+	}
2648
+
2649
+
2650
+	/**
2651
+	 * sets up a context switcher for edit forms
2652
+	 *
2653
+	 * @access  protected
2654
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2655
+	 * @param array                     $args                  various things the context switcher needs.
2656
+	 * @throws EE_Error
2657
+	 */
2658
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2659
+	{
2660
+		$context_details = $template_group_object->contexts_config();
2661
+		$context_label   = $template_group_object->context_label();
2662
+		ob_start();
2663
+		?>
2664 2664
         <div class="ee-msg-switcher-container">
2665 2665
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2666 2666
                 <?php
2667
-                foreach ($args as $name => $value) {
2668
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2669
-                        continue;
2670
-                    }
2671
-                    ?>
2667
+				foreach ($args as $name => $value) {
2668
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2669
+						continue;
2670
+					}
2671
+					?>
2672 2672
                     <input type="hidden"
2673 2673
                            name="<?php echo esc_attr($name); ?>"
2674 2674
                            value="<?php echo esc_attr($value); ?>"
2675 2675
                     />
2676 2676
                     <?php
2677
-                }
2678
-                // setup nonce_url
2679
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2680
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2681
-                ?>
2677
+				}
2678
+				// setup nonce_url
2679
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2680
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2681
+				?>
2682 2682
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2683 2683
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2684 2684
                 </label>
2685 2685
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2686 2686
                     <?php
2687
-                    $context_templates = $template_group_object->context_templates();
2688
-                    if (is_array($context_templates)) :
2689
-                        foreach ($context_templates as $context => $template_fields) :
2690
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2691
-                            ?>
2687
+					$context_templates = $template_group_object->context_templates();
2688
+					if (is_array($context_templates)) :
2689
+						foreach ($context_templates as $context => $template_fields) :
2690
+							$checked = ($context === $args['context']) ? 'selected' : '';
2691
+							?>
2692 2692
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2693 2693
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2694 2694
                             </option>
2695 2695
                         <?php endforeach;
2696
-                    endif; ?>
2696
+					endif; ?>
2697 2697
                 </select>
2698 2698
                 <?php $button_text = sprintf(
2699
-                    esc_html__('Switch %s', 'event_espresso'),
2700
-                    ucwords($context_label['label'])
2701
-                ); ?>
2699
+					esc_html__('Switch %s', 'event_espresso'),
2700
+					ucwords($context_label['label'])
2701
+				); ?>
2702 2702
                 <input class='button--secondary'
2703 2703
                        id="submit-msg-context-switcher-sbmt"
2704 2704
                        type="submit"
@@ -2708,1993 +2708,1993 @@  discard block
 block discarded – undo
2708 2708
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2709 2709
         </div> <!-- end .ee-msg-switcher-container -->
2710 2710
         <?php $this->_context_switcher = ob_get_clean();
2711
-    }
2712
-
2713
-
2714
-    /**
2715
-     * @param bool $new
2716
-     * @throws EE_Error
2717
-     * @throws ReflectionException
2718
-     */
2719
-    protected function _insert_or_update_message_template($new = false)
2720
-    {
2721
-        $form_data    = $this->getMessageTemplateFormData();
2722
-        $GRP_ID       = $form_data['GRP_ID'];
2723
-        $messenger    = $form_data['MTP_messenger'];
2724
-        $message_type = $form_data['MTP_message_type'];
2725
-        $context      = $form_data['MTP_context'];
2726
-
2727
-        // if this is "new" then we need to generate the default contexts
2728
-        // for the selected messenger/message_type for user to edit.
2729
-        [$success, $query_args] = $new
2730
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2731
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2732
-
2733
-        $success     = $success ? 1 : 0;
2734
-        $action_desc = $new ? 'created' : 'updated';
2735
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2736
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2737
-
2738
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2739
-    }
2740
-
2741
-
2742
-    /**
2743
-     * retrieve and sanitize form data
2744
-     *
2745
-     * @return array
2746
-     * @since 4.10.29.p
2747
-     */
2748
-    protected function getMessageTemplateFormData()
2749
-    {
2750
-        return [
2751
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2752
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2753
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2754
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2755
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2756
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2757
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2758
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2759
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2760
-        ];
2761
-    }
2762
-
2763
-
2764
-    /**
2765
-     * @param int    $GRP_ID
2766
-     * @param string $messenger
2767
-     * @param string $message_type
2768
-     * @return array no return on AJAX requests
2769
-     * @throws EE_Error
2770
-     * @throws ReflectionException
2771
-     * @since 4.10.29.p
2772
-     */
2773
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2774
-    {
2775
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2776
-        $success       = ! empty($new_templates);
2777
-
2778
-        // we return things differently if doing ajax
2779
-        if ($this->request->isAjax()) {
2780
-            $this->_template_args['success'] = $success;
2781
-            $this->_template_args['error']   = ! $success;
2782
-            $this->_template_args['content'] = '';
2783
-            $this->_template_args['data']    = [
2784
-                'grpID'        => $new_templates['GRP_ID'],
2785
-                'templateName' => $new_templates['template_name'],
2786
-            ];
2787
-            if ($success) {
2788
-                EE_Error::overwrite_success();
2789
-                EE_Error::add_success(
2790
-                    esc_html__(
2791
-                        '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.',
2792
-                        'event_espresso'
2793
-                    )
2794
-                );
2795
-            }
2796
-            $this->_return_json();
2797
-        }
2798
-        return [
2799
-            $success,
2800
-            // 'query_args'
2801
-            [
2802
-                'id'      => $new_templates['GRP_ID'],
2803
-                'context' => $new_templates['MTP_context'],
2804
-                'action'  => 'edit_message_template',
2805
-            ],
2806
-        ];
2807
-    }
2808
-
2809
-
2810
-    /**
2811
-     * @param int    $GRP_ID
2812
-     * @param string $messenger
2813
-     * @param string $message_type
2814
-     * @param string $context
2815
-     * @param array  $form_data
2816
-     * @return array
2817
-     * @throws EE_Error
2818
-     * @since 4.10.29.p
2819
-     */
2820
-    private function updateExistingTemplates(
2821
-        $GRP_ID,
2822
-        $messenger,
2823
-        $message_type,
2824
-        $context,
2825
-        array $form_data
2826
-    ) {
2827
-        $success         = false;
2828
-        $template_fields = $this->getTemplateFields();
2829
-        if ($template_fields) {
2830
-            // if field data is valid, then success will be true
2831
-            $success = $this->validateTemplateFields(
2832
-                $messenger,
2833
-                $message_type,
2834
-                $context,
2835
-                $template_fields
2836
-            );
2837
-            if ($success) {
2838
-                $field_data = [];
2839
-                foreach ($template_fields as $template_field => $content) {
2840
-                    // combine top-level form data with content for this field
2841
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2842
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2843
-                }
2844
-                // we can use the last set_column_values for the MTPG update
2845
-                // (because its the same for all of these specific MTPs)
2846
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2847
-            }
2848
-        }
2849
-
2850
-        return [
2851
-            $success,
2852
-            // 'query_args'
2853
-            [
2854
-                'id'      => $GRP_ID,
2855
-                'context' => $context,
2856
-                'action'  => 'edit_message_template',
2857
-            ],
2858
-        ];
2859
-    }
2860
-
2861
-
2862
-    /**
2863
-     * @return array
2864
-     * @since 4.10.29.p
2865
-     */
2866
-    private function getTemplateFields()
2867
-    {
2868
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2869
-        if (empty($template_fields)) {
2870
-            EE_Error::add_error(
2871
-                esc_html__(
2872
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2873
-                    'event_espresso'
2874
-                ),
2875
-                __FILE__,
2876
-                __FUNCTION__,
2877
-                __LINE__
2878
-            );
2879
-            return null;
2880
-        }
2881
-        // messages content is expected to be escaped
2882
-        return EEH_Array::addSlashesRecursively($template_fields);
2883
-    }
2884
-
2885
-
2886
-    /**
2887
-     * @param string $messenger
2888
-     * @param string $message_type
2889
-     * @param string $context
2890
-     * @param array  $template_fields
2891
-     * @return bool
2892
-     * @throws EE_Error
2893
-     * @since   4.10.29.p
2894
-     */
2895
-    private function validateTemplateFields(
2896
-        $messenger,
2897
-        $message_type,
2898
-        $context,
2899
-        array $template_fields
2900
-    ) {
2901
-        // first validate all fields!
2902
-        // this filter allows client code to add its own validation to the template fields as well.
2903
-        // returning an empty array means everything passed validation.
2904
-        // errors in validation should be represented in an array with the following shape:
2905
-        // array(
2906
-        //   'fieldname' => array(
2907
-        //          'msg' => 'error message'
2908
-        //          'value' => 'value for field producing error'
2909
-        // )
2910
-        $custom_validation = (array) apply_filters(
2911
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2912
-            [],
2913
-            $template_fields,
2914
-            $context,
2915
-            $messenger,
2916
-            $message_type
2917
-        );
2918
-
2919
-        $system_validation = $this->getMtgModel()->validate(
2920
-            $template_fields,
2921
-            $context,
2922
-            $messenger,
2923
-            $message_type
2924
-        );
2925
-
2926
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2927
-        $validates         = array_merge($custom_validation, $system_validation);
2928
-
2929
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2930
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2931
-        //  WE need to make sure there is no actual error messages in validates.
2932
-        if (empty($validates)) {
2933
-            return true;
2934
-        }
2935
-
2936
-        // add the transient so when the form loads we know which fields to highlight
2937
-        $this->_add_transient('edit_message_template', $validates);
2938
-        // setup notices
2939
-        foreach ($validates as $error) {
2940
-            if (isset($error['msg'])) {
2941
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2942
-            }
2943
-        }
2944
-        return false;
2945
-    }
2946
-
2947
-
2948
-    /**
2949
-     * @param array $field_data
2950
-     * @param array $form_data
2951
-     * @return array
2952
-     * @since   4.10.29.p
2953
-     */
2954
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2955
-    {
2956
-        return $form_data + [
2957
-                'MTP_ID'             => $field_data['MTP_ID'],
2958
-                'MTP_template_field' => $field_data['name'],
2959
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2960
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2961
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2962
-                    : $field_data['content'],
2963
-            ];
2964
-    }
2965
-
2966
-
2967
-    /**
2968
-     * @param string $template_field
2969
-     * @param array  $form_data
2970
-     * @return bool
2971
-     * @throws EE_Error
2972
-     * @since 4.10.29.p
2973
-     */
2974
-    private function updateMessageTemplates($template_field, array $form_data)
2975
-    {
2976
-        $MTP_ID                  = $form_data['MTP_ID'];
2977
-        $message_template_fields = [
2978
-            'GRP_ID'             => $form_data['GRP_ID'],
2979
-            'MTP_template_field' => $form_data['MTP_template_field'],
2980
-            'MTP_context'        => $form_data['MTP_context'],
2981
-            'MTP_content'        => $form_data['MTP_content'],
2982
-        ];
2983
-
2984
-        $hasMtpID = ! empty($MTP_ID);
2985
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2986
-        // this has already been through the template field validator and sanitized, so it will be
2987
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2988
-        // message template field in a messenger/message type and existing users don't have the
2989
-        // default setup for it.
2990
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2991
-        $updated = $hasMtpID
2992
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2993
-            : $this->getMtpModel()->insert($message_template_fields);
2994
-
2995
-        $insert_failed = ! $hasMtpID && ! $updated;
2996
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2997
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2998
-        $update_failed = $hasMtpID && $updated === false;
2999
-
3000
-        if ($insert_failed || $update_failed) {
3001
-            EE_Error::add_error(
3002
-                sprintf(
3003
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
3004
-                    $template_field
3005
-                ),
3006
-                __FILE__,
3007
-                __FUNCTION__,
3008
-                __LINE__
3009
-            );
3010
-            return false;
3011
-        }
3012
-        return true;
3013
-    }
3014
-
3015
-
3016
-    /**
3017
-     * @param array $form_data
3018
-     * @return bool
3019
-     * @throws EE_Error
3020
-     * @since 4.10.29.p
3021
-     */
3022
-    private function updateMessageTemplateGroup(array $form_data)
3023
-    {
3024
-        $GRP_ID  = $form_data['GRP_ID'];
3025
-        $updated = $this->getMtgModel()->update(
3026
-        // fields and values
3027
-            [
3028
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3029
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3030
-                'MTP_message_type' => $form_data['MTP_message_type'],
3031
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3032
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3033
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3034
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3035
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3036
-                'MTP_description'  => $this->request->getRequestParam(
3037
-                    'ee_msg_non_global_fields[MTP_description]',
3038
-                    ''
3039
-                ),
3040
-            ],
3041
-            // where
3042
-            [['GRP_ID' => $GRP_ID]]
3043
-        );
3044
-
3045
-        if ($updated === false) {
3046
-            EE_Error::add_error(
3047
-                sprintf(
3048
-                    esc_html__(
3049
-                        'The Message Template Group (%d) was NOT updated for some reason',
3050
-                        'event_espresso'
3051
-                    ),
3052
-                    $form_data['GRP_ID']
3053
-                ),
3054
-                __FILE__,
3055
-                __FUNCTION__,
3056
-                __LINE__
3057
-            );
3058
-            return false;
3059
-        }
3060
-        // k now we need to ensure the template_pack and template_variation fields are set.
3061
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3062
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3063
-
3064
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3065
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3066
-            $message_template_group->set_template_pack_name($template_pack);
3067
-            $message_template_group->set_template_pack_variation($template_variation);
3068
-        }
3069
-        return true;
3070
-    }
3071
-
3072
-
3073
-    /**
3074
-     * recursively runs wp_kses() on message template content in a model safe manner
3075
-     *
3076
-     * @param array|string $content
3077
-     * @return array|string
3078
-     * @since   4.10.29.p
3079
-     */
3080
-    private function sanitizeMessageTemplateContent($content)
3081
-    {
3082
-        if (is_array($content)) {
3083
-            foreach ($content as $key => $value) {
3084
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3085
-            }
3086
-            return $content;
3087
-        }
3088
-        // remove slashes so wp_kses() works properly
3089
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3090
-        // so attributes using single quotes always appear invalid.
3091
-        $content = stripslashes($content);
3092
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3093
-        // But currently the models expect slashed data, so after wp_kses()
3094
-        // runs we need to re-slash the data. Sheesh.
3095
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3096
-        return addslashes($content);
3097
-    }
3098
-
3099
-
3100
-    /**
3101
-     * @param string $messenger
3102
-     * @param string $message_type
3103
-     * @param string $context
3104
-     * @return string
3105
-     * @since 4.10.29.p
3106
-     */
3107
-    private function generateUpdateDescription($messenger, $message_type, $context)
3108
-    {
3109
-        // need the message type and messenger objects to be able to use the labels for the notices
3110
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3111
-        $messenger_label  = $messenger_object instanceof EE_messenger
3112
-            ? ucwords($messenger_object->label['singular'])
3113
-            : '';
3114
-
3115
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3116
-        $message_type_label  = $message_type_object instanceof EE_message_type
3117
-            ? ucwords($message_type_object->label['singular'])
3118
-            : '';
3119
-
3120
-        $context   = ucwords(str_replace('_', ' ', $context));
3121
-        $item_desc = $messenger_label && $message_type_label
3122
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3123
-            : '';
3124
-        $item_desc .= 'Message Template';
3125
-        return $item_desc;
3126
-    }
3127
-
3128
-
3129
-    /**
3130
-     * @param string $messenger
3131
-     * @param string $message_type
3132
-     * @param string $context
3133
-     * @return bool
3134
-     * @throws EE_Error
3135
-     * @throws ReflectionException
3136
-     * @since 4.10.29.p
3137
-     */
3138
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3139
-    {
3140
-        // was a test send triggered?
3141
-        if ($this->request->requestParamIsSet('test_button')) {
3142
-            EE_Error::overwrite_success();
3143
-            $this->_do_test_send($context, $messenger, $message_type);
3144
-            return true;
3145
-        }
3146
-        return false;
3147
-    }
3148
-
3149
-
3150
-    /**
3151
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3152
-     *
3153
-     * @param string $context      what context being tested
3154
-     * @param string $messenger    messenger being tested
3155
-     * @param string $message_type message type being tested
3156
-     * @throws EE_Error
3157
-     * @throws InvalidArgumentException
3158
-     * @throws InvalidDataTypeException
3159
-     * @throws InvalidInterfaceException
3160
-     * @throws ReflectionException
3161
-     */
3162
-    protected function _do_test_send($context, $messenger, $message_type)
3163
-    {
3164
-        // set things up for preview
3165
-        $this->request->setRequestParam('messenger', $messenger);
3166
-        $this->request->setRequestParam('message_type', $message_type);
3167
-        $this->request->setRequestParam('context', $context);
3168
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3169
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3170
-
3171
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3172
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3173
-
3174
-        // let's save any existing fields that might be required by the messenger
3175
-        if (
3176
-            ! empty($test_settings_fld)
3177
-            && $active_messenger instanceof EE_messenger
3178
-            && apply_filters(
3179
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3180
-                true,
3181
-                $test_settings_fld,
3182
-                $active_messenger
3183
-            )
3184
-        ) {
3185
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3186
-        }
3187
-
3188
-        /**
3189
-         * Use filter to add additional controls on whether message can send or not
3190
-         */
3191
-        if (
3192
-            apply_filters(
3193
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3194
-                true,
3195
-                $context,
3196
-                $this->request->requestParams(),
3197
-                $messenger,
3198
-                $message_type
3199
-            )
3200
-        ) {
3201
-            if (EEM_Event::instance()->count() > 0) {
3202
-                $success = $this->_preview_message(true);
3203
-                if ($success) {
3204
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3205
-                } else {
3206
-                    EE_Error::add_error(
3207
-                        esc_html__('The test message was not sent', 'event_espresso'),
3208
-                        __FILE__,
3209
-                        __FUNCTION__,
3210
-                        __LINE__
3211
-                    );
3212
-                }
3213
-            } else {
3214
-                $this->noEventsErrorMessage(true);
3215
-            }
3216
-        }
3217
-    }
3218
-
3219
-
3220
-    /**
3221
-     * _generate_new_templates
3222
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3223
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3224
-     * for the event.
3225
-     *
3226
-     *
3227
-     * @param string $messenger      the messenger we are generating templates for
3228
-     * @param array  $message_types  array of message types that the templates are generated for.
3229
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3230
-     *                               indicate the message_template_group being used as the base.
3231
-     *
3232
-     * @param bool   $global
3233
-     *
3234
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3235
-     *                               encountering problems.
3236
-     * @throws EE_Error
3237
-     * @throws ReflectionException
3238
-     */
3239
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3240
-    {
3241
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3242
-        // just don't generate any templates.
3243
-        if (empty($message_types)) {
3244
-            return [];
3245
-        }
3246
-
3247
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3248
-        return $templates[0];
3249
-    }
3250
-
3251
-
3252
-    /**
3253
-     * [_trash_or_restore_message_template]
3254
-     *
3255
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3256
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3257
-     *                        an individual context (FALSE).
3258
-     * @return void
3259
-     * @throws EE_Error
3260
-     * @throws InvalidArgumentException
3261
-     * @throws InvalidDataTypeException
3262
-     * @throws InvalidInterfaceException
3263
-     */
3264
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3265
-    {
3266
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3267
-
3268
-        $success = 1;
3269
-
3270
-        // incoming GRP_IDs
3271
-        if ($all) {
3272
-            // Checkboxes
3273
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3274
-            if (! empty($checkboxes)) {
3275
-                // if array has more than one element then success message should be plural.
3276
-                // todo: what about nonce?
3277
-                $success = count($checkboxes) > 1 ? 2 : 1;
3278
-
3279
-                // cycle through checkboxes
3280
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3281
-                    $trashed_or_restored = $trash
3282
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3283
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3284
-                    if (! $trashed_or_restored) {
3285
-                        $success = 0;
3286
-                    }
3287
-                }
3288
-            } else {
3289
-                // grab single GRP_ID and handle
3290
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3291
-                if (! empty($GRP_ID)) {
3292
-                    $trashed_or_restored = $trash
3293
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3294
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3295
-                    if (! $trashed_or_restored) {
3296
-                        $success = 0;
3297
-                    }
3298
-                } else {
3299
-                    $success = 0;
3300
-                }
3301
-            }
3302
-        }
3303
-
3304
-        $action_desc = $trash
3305
-            ? esc_html__('moved to the trash', 'event_espresso')
3306
-            : esc_html__('restored', 'event_espresso');
3307
-
3308
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3309
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3310
-
3311
-        $item_desc = $all ? _n(
3312
-            'Message Template Group',
3313
-            'Message Template Groups',
3314
-            $success,
3315
-            'event_espresso'
3316
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3317
-
3318
-        $item_desc = $template_switch
3319
-            ? _n('template', 'templates', $success, 'event_espresso')
3320
-            : $item_desc;
3321
-
3322
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3323
-    }
3324
-
3325
-
3326
-    /**
3327
-     * [_delete_message_template]
3328
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3329
-     *
3330
-     * @return void
3331
-     * @throws EE_Error
3332
-     * @throws InvalidArgumentException
3333
-     * @throws InvalidDataTypeException
3334
-     * @throws InvalidInterfaceException
3335
-     * @throws ReflectionException
3336
-     */
3337
-    protected function _delete_message_template()
3338
-    {
3339
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3340
-
3341
-        // checkboxes
3342
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3343
-        if (! empty($checkboxes)) {
3344
-            // if array has more than one element then success message should be plural
3345
-            $success = count($checkboxes) > 1 ? 2 : 1;
3346
-
3347
-            // cycle through bulk action checkboxes
3348
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3349
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3350
-            }
3351
-        } else {
3352
-            // grab single grp_id and delete
3353
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3354
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3355
-        }
3356
-
3357
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3358
-    }
3359
-
3360
-
3361
-    /**
3362
-     * helper for permanently deleting a mtP group and all related message_templates
3363
-     *
3364
-     * @param int  $GRP_ID        The group being deleted
3365
-     * @param bool $include_group whether to delete the Message Template Group as well.
3366
-     * @return bool boolean to indicate the success of the deletes or not.
3367
-     * @throws EE_Error
3368
-     * @throws InvalidArgumentException
3369
-     * @throws InvalidDataTypeException
3370
-     * @throws InvalidInterfaceException
3371
-     * @throws ReflectionException
3372
-     * @throws ReflectionException
3373
-     */
3374
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3375
-    {
3376
-        $success = true;
3377
-        // first let's GET this group
3378
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3379
-        // then delete permanently all the related Message Templates
3380
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3381
-
3382
-        if ($deleted === 0) {
3383
-            $success = false;
3384
-        }
3385
-
3386
-        // now delete permanently this particular group
3387
-
3388
-        if ($include_group && ! $MTG->delete_permanently()) {
3389
-            $success = false;
3390
-        }
3391
-
3392
-        return $success;
3393
-    }
3394
-
3395
-
3396
-    /**
3397
-     *    _learn_more_about_message_templates_link
3398
-     *
3399
-     * @access protected
3400
-     * @return string
3401
-     */
3402
-    protected function _learn_more_about_message_templates_link()
3403
-    {
3404
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3405
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3406
-               . '</a>';
3407
-    }
3408
-
3409
-
3410
-    /**
3411
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3412
-     * ajax and other routes.
3413
-     *
3414
-     * @return void
3415
-     * @throws DomainException
3416
-     * @throws EE_Error
3417
-     */
3418
-    protected function _settings()
3419
-    {
3420
-        $this->_set_m_mt_settings();
3421
-
3422
-        // let's setup the messenger tabs
3423
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3424
-            $this->_m_mt_settings['messenger_tabs'],
3425
-            'messenger_links',
3426
-            '|',
3427
-            $this->request->getRequestParam('selected_messenger', 'email')
3428
-        );
3429
-
3430
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3431
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3432
-
3433
-        $this->display_admin_page_with_sidebar();
3434
-    }
3435
-
3436
-
3437
-    /**
3438
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3439
-     *
3440
-     * @access protected
3441
-     * @return void
3442
-     * @throws DomainException
3443
-     */
3444
-    protected function _set_m_mt_settings()
3445
-    {
3446
-        // first if this is already set then lets get out no need to regenerate data.
3447
-        if (! empty($this->_m_mt_settings)) {
3448
-            return;
3449
-        }
3450
-
3451
-        // get all installed messengers and message_types
3452
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3453
-        $message_types = $this->_message_resource_manager->installed_message_types();
3454
-
3455
-
3456
-        // assemble the array for the _tab_text_links helper
3457
-
3458
-        foreach ($messengers as $messenger) {
3459
-            $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3460
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3461
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3462
-                'label' => ucwords($messenger->label['singular']),
3463
-                'class' => $active ? "{$class} messenger-active" : $class,
3464
-                'href'  => $messenger->name,
3465
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3466
-                'slug'  => $messenger->name,
3467
-                'obj'   => $messenger,
3468
-                'icon' => $active
3469
-                    ? '<span class="dashicons dashicons-yes-alt"></span>'
3470
-                    : '<span class="dashicons dashicons-remove"></span>',
3471
-            ];
3472
-
3473
-
3474
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3475
-
3476
-            foreach ($message_types as $message_type) {
3477
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3478
-                // it shouldn't show in either the inactive OR active metabox.
3479
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3480
-                    continue;
3481
-                }
3482
-
3483
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3484
-                    $messenger->name,
3485
-                    $message_type->name
3486
-                )
3487
-                    ? 'active'
3488
-                    : 'inactive';
3489
-
3490
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3491
-                    'label'    => ucwords($message_type->label['singular']),
3492
-                    'class'    => 'message-type-' . $a_or_i,
3493
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3494
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3495
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3496
-                    'title'    => $a_or_i === 'active'
3497
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3498
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3499
-                    'content'  => $a_or_i === 'active'
3500
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3501
-                        : $this->_message_type_settings_content($message_type, $messenger),
3502
-                    'slug'     => $message_type->name,
3503
-                    'active'   => $a_or_i === 'active',
3504
-                    'obj'      => $message_type,
3505
-                ];
3506
-            }
3507
-        }
3508
-    }
3509
-
3510
-
3511
-    /**
3512
-     * This just prepares the content for the message type settings
3513
-     *
3514
-     * @param EE_message_type $message_type The message type object
3515
-     * @param EE_messenger    $messenger    The messenger object
3516
-     * @param boolean         $active       Whether the message type is active or not
3517
-     * @return string html output for the content
3518
-     * @throws DomainException
3519
-     */
3520
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3521
-    {
3522
-        // get message type fields
3523
-        $fields                                         = $message_type->get_admin_settings_fields();
3524
-        $settings_template_args['template_form_fields'] = '';
3525
-
3526
-        if (! empty($fields) && $active) {
3527
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3528
-            foreach ($fields as $fldname => $fldprops) {
3529
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3530
-                $template_form_field[ $field_id ] = [
3531
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3532
-                    'label'      => $fldprops['label'],
3533
-                    'input'      => $fldprops['field_type'],
3534
-                    'type'       => $fldprops['value_type'],
3535
-                    'required'   => $fldprops['required'],
3536
-                    'validation' => $fldprops['validation'],
3537
-                    'value'      => isset($existing_settings[ $fldname ])
3538
-                        ? $existing_settings[ $fldname ]
3539
-                        : $fldprops['default'],
3540
-                    'options'    => isset($fldprops['options'])
3541
-                        ? $fldprops['options']
3542
-                        : [],
3543
-                    'default'    => isset($existing_settings[ $fldname ])
3544
-                        ? $existing_settings[ $fldname ]
3545
-                        : $fldprops['default'],
3546
-                    'css_class'  => 'no-drag',
3547
-                    'format'     => $fldprops['format'],
3548
-                ];
3549
-            }
3550
-
3551
-
3552
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3553
-                ? $this->_generate_admin_form_fields(
3554
-                    $template_form_field,
3555
-                    'string',
3556
-                    'ee_mt_activate_form'
3557
-                )
3558
-                : '';
3559
-        }
3560
-
3561
-        $settings_template_args['description'] = $message_type->description;
3562
-        // we also need some hidden fields
3563
-        $hidden_fields = [
3564
-            'message_type_settings[messenger]' . $message_type->name    => [
3565
-                'type'  => 'hidden',
3566
-                'value' => $messenger->name,
3567
-            ],
3568
-            'message_type_settings[message_type]' . $message_type->name => [
3569
-                'type'  => 'hidden',
3570
-                'value' => $message_type->name,
3571
-            ],
3572
-            'type' . $message_type->name                                => [
3573
-                'type'  => 'hidden',
3574
-                'value' => 'message_type',
3575
-            ],
3576
-        ];
3577
-
3578
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3579
-            $hidden_fields,
3580
-            'array'
3581
-        );
3582
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3583
-            ? ' hidden'
3584
-            : '';
3585
-
3586
-
3587
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3588
-        return EEH_Template::display_template($template, $settings_template_args, true);
3589
-    }
3590
-
3591
-
3592
-    /**
3593
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3594
-     *
3595
-     * @access protected
3596
-     * @return void
3597
-     * @throws DomainException
3598
-     */
3599
-    protected function _messages_settings_metaboxes()
3600
-    {
3601
-        $this->_set_m_mt_settings();
3602
-        $m_boxes         = $mt_boxes = [];
3603
-        $m_template_args = $mt_template_args = [];
3604
-
3605
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3606
-
3607
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3608
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3609
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3610
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3611
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3612
-
3613
-                // messenger meta boxes
3614
-                $active         = $selected_messenger === $messenger;
3615
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3616
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3617
-                    : '';
3618
-
3619
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3620
-                    esc_html__('%s Settings', 'event_espresso'),
3621
-                    $tab_array['label']
3622
-                );
3623
-
3624
-                $m_template_args[ $messenger . '_a_box' ] = [
3625
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3626
-                    'inactive_message_types' => isset(
3627
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3628
-                    )
3629
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3630
-                        : '',
3631
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3632
-                    'hidden'                 => $active ? '' : ' hidden',
3633
-                    'hide_on_message'        => $hide_on_message,
3634
-                    'messenger'              => $messenger,
3635
-                    'active'                 => $active,
3636
-                ];
3637
-
3638
-                // message type meta boxes
3639
-                // (which is really just the inactive container for each messenger
3640
-                // showing inactive message types for that messenger)
3641
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3642
-                $mt_template_args[ $messenger . '_i_box' ] = [
3643
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3644
-                    'inactive_message_types' => isset(
3645
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3646
-                    )
3647
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3648
-                        : '',
3649
-                    'hidden'                 => $active ? '' : ' hidden',
3650
-                    'hide_on_message'        => $hide_on_message,
3651
-                    'hide_off_message'       => $hide_off_message,
3652
-                    'messenger'              => $messenger,
3653
-                    'active'                 => $active,
3654
-                ];
3655
-            }
3656
-        }
3657
-
3658
-
3659
-        // register messenger metaboxes
3660
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3661
-        foreach ($m_boxes as $box => $label) {
3662
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3663
-            $msgr          = str_replace('_a_box', '', $box);
3664
-            $this->addMetaBox(
3665
-                'espresso_' . $msgr . '_settings',
3666
-                $label,
3667
-                function ($post, $metabox) {
3668
-                    EEH_Template::display_template(
3669
-                        $metabox['args']['template_path'],
3670
-                        $metabox['args']['template_args']
3671
-                    );
3672
-                },
3673
-                $this->_current_screen->id,
3674
-                'normal',
3675
-                'high',
3676
-                $callback_args
3677
-            );
3678
-        }
3679
-
3680
-        // register message type metaboxes
3681
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3682
-        foreach ($mt_boxes as $box => $label) {
3683
-            $callback_args = [
3684
-                'template_path' => $mt_template_path,
3685
-                'template_args' => $mt_template_args[ $box ],
3686
-            ];
3687
-            $mt            = str_replace('_i_box', '', $box);
3688
-            $this->addMetaBox(
3689
-                'espresso_' . $mt . '_inactive_mts',
3690
-                $label,
3691
-                function ($post, $metabox) {
3692
-                    EEH_Template::display_template(
3693
-                        $metabox['args']['template_path'],
3694
-                        $metabox['args']['template_args']
3695
-                    );
3696
-                },
3697
-                $this->_current_screen->id,
3698
-                'side',
3699
-                'high',
3700
-                $callback_args
3701
-            );
3702
-        }
3703
-
3704
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3705
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3706
-        if (is_main_site()) {
3707
-            $this->addMetaBox(
3708
-                'espresso_global_message_settings',
3709
-                esc_html__('Global Message Settings', 'event_espresso'),
3710
-                [$this, 'global_messages_settings_metabox_content'],
3711
-                $this->_current_screen->id,
3712
-                'normal',
3713
-                'low',
3714
-                []
3715
-            );
3716
-        }
3717
-    }
3718
-
3719
-
3720
-    /**
3721
-     *  This generates the content for the global messages settings metabox.
3722
-     *
3723
-     * @return void
3724
-     * @throws EE_Error
3725
-     * @throws InvalidArgumentException
3726
-     * @throws ReflectionException
3727
-     * @throws InvalidDataTypeException
3728
-     * @throws InvalidInterfaceException
3729
-     */
3730
-    public function global_messages_settings_metabox_content()
3731
-    {
3732
-        $form = $this->_generate_global_settings_form();
3733
-        echo wp_kses(
3734
-            $form->form_open(
3735
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3736
-                'POST'
3737
-            ),
3738
-            AllowedTags::getWithFormTags()
3739
-        );
3740
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3741
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3742
-    }
3743
-
3744
-
3745
-    /**
3746
-     * This generates and returns the form object for the global messages settings.
3747
-     *
3748
-     * @return EE_Form_Section_Proper
3749
-     * @throws EE_Error
3750
-     * @throws InvalidArgumentException
3751
-     * @throws ReflectionException
3752
-     * @throws InvalidDataTypeException
3753
-     * @throws InvalidInterfaceException
3754
-     */
3755
-    protected function _generate_global_settings_form()
3756
-    {
3757
-        /** @var EE_Network_Core_Config $network_config */
3758
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3759
-
3760
-        return new EE_Form_Section_Proper(
3761
-            [
3762
-                'name'            => 'global_messages_settings',
3763
-                'html_id'         => 'global_messages_settings',
3764
-                'html_class'      => 'form-table',
3765
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3766
-                'subsections'     => apply_filters(
3767
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3768
-                    [
3769
-                        'do_messages_on_same_request' => new EE_Select_Input(
3770
-                            [
3771
-                                true  => esc_html__('On the same request', 'event_espresso'),
3772
-                                false => esc_html__('On a separate request', 'event_espresso'),
3773
-                            ],
3774
-                            [
3775
-                                'default'         => $network_config->do_messages_on_same_request,
3776
-                                'html_label_text' => esc_html__(
3777
-                                    'Generate and send all messages:',
3778
-                                    'event_espresso'
3779
-                                ),
3780
-                                'html_help_text'  => esc_html__(
3781
-                                    '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.',
3782
-                                    'event_espresso'
3783
-                                ),
3784
-                            ]
3785
-                        ),
3786
-                        'delete_threshold'            => new EE_Select_Input(
3787
-                            [
3788
-                                0  => esc_html__('Forever', 'event_espresso'),
3789
-                                3  => esc_html__('3 Months', 'event_espresso'),
3790
-                                6  => esc_html__('6 Months', 'event_espresso'),
3791
-                                9  => esc_html__('9 Months', 'event_espresso'),
3792
-                                12 => esc_html__('12 Months', 'event_espresso'),
3793
-                                24 => esc_html__('24 Months', 'event_espresso'),
3794
-                                36 => esc_html__('36 Months', 'event_espresso'),
3795
-                            ],
3796
-                            [
3797
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3798
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3799
-                                'html_help_text'  => esc_html__(
3800
-                                    'You can control how long a record of processed messages is kept via this option.',
3801
-                                    'event_espresso'
3802
-                                ),
3803
-                            ]
3804
-                        ),
3805
-                        'update_settings'             => new EE_Submit_Input(
3806
-                            [
3807
-                                'default'         => esc_html__('Update', 'event_espresso'),
3808
-                                'html_label_text' => '',
3809
-                            ]
3810
-                        ),
3811
-                    ]
3812
-                ),
3813
-            ]
3814
-        );
3815
-    }
3816
-
3817
-
3818
-    /**
3819
-     * This handles updating the global settings set on the admin page.
3820
-     *
3821
-     * @throws EE_Error
3822
-     * @throws InvalidDataTypeException
3823
-     * @throws InvalidInterfaceException
3824
-     * @throws InvalidArgumentException
3825
-     * @throws ReflectionException
3826
-     */
3827
-    protected function _update_global_settings()
3828
-    {
3829
-        /** @var EE_Network_Core_Config $network_config */
3830
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3831
-        $messages_config = EE_Registry::instance()->CFG->messages;
3832
-        $form            = $this->_generate_global_settings_form();
3833
-        if ($form->was_submitted()) {
3834
-            $form->receive_form_submission();
3835
-            if ($form->is_valid()) {
3836
-                $valid_data = $form->valid_data();
3837
-                foreach ($valid_data as $property => $value) {
3838
-                    $setter = 'set_' . $property;
3839
-                    if (method_exists($network_config, $setter)) {
3840
-                        $network_config->{$setter}($value);
3841
-                    } elseif (
3842
-                        property_exists($network_config, $property)
3843
-                        && $network_config->{$property} !== $value
3844
-                    ) {
3845
-                        $network_config->{$property} = $value;
3846
-                    } elseif (
3847
-                        property_exists($messages_config, $property)
3848
-                        && $messages_config->{$property} !== $value
3849
-                    ) {
3850
-                        $messages_config->{$property} = $value;
3851
-                    }
3852
-                }
3853
-                // only update if the form submission was valid!
3854
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3855
-                EE_Registry::instance()->CFG->update_espresso_config();
3856
-                EE_Error::overwrite_success();
3857
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3858
-            }
3859
-        }
3860
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3861
-    }
3862
-
3863
-
3864
-    /**
3865
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3866
-     *
3867
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3868
-     * @return string html formatted tabs
3869
-     * @throws DomainException
3870
-     */
3871
-    protected function _get_mt_tabs($tab_array)
3872
-    {
3873
-        $tab_array = (array) $tab_array;
3874
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3875
-        $tabs      = '';
3876
-
3877
-        foreach ($tab_array as $tab) {
3878
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3879
-        }
3880
-
3881
-        return $tabs;
3882
-    }
3883
-
3884
-
3885
-    /**
3886
-     * This prepares the content of the messenger meta box admin settings
3887
-     *
3888
-     * @param EE_messenger $messenger The messenger we're setting up content for
3889
-     * @return string html formatted content
3890
-     * @throws DomainException
3891
-     */
3892
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3893
-    {
3894
-
3895
-        $fields = $messenger->get_admin_settings_fields();
3896
-
3897
-        $settings_template_args['template_form_fields'] = '';
3898
-        // is $messenger active?
3899
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3900
-
3901
-
3902
-        if (! empty($fields)) {
3903
-            $existing_settings = $messenger->get_existing_admin_settings();
3904
-
3905
-            foreach ($fields as $field_name => $field_props) {
3906
-                $field_id                         = $messenger->name . '-' . $field_name;
3907
-                $template_form_field[ $field_id ] = [
3908
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3909
-                    'label'      => $field_props['label'],
3910
-                    'input'      => $field_props['field_type'],
3911
-                    'type'       => $field_props['value_type'],
3912
-                    'required'   => $field_props['required'],
3913
-                    'validation' => $field_props['validation'],
3914
-                    'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3915
-                    'css_class'  => '',
3916
-                    'format'     => $field_props['format'],
3917
-                ];
3918
-            }
3919
-
3920
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3921
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3922
-                : '';
3923
-        }
3924
-
3925
-        // we also need some hidden fields
3926
-        $settings_template_args['hidden_fields'] = [
3927
-            'messenger_settings[messenger]' . $messenger->name => [
3928
-                'type'  => 'hidden',
3929
-                'value' => $messenger->name,
3930
-            ],
3931
-            'type' . $messenger->name                          => [
3932
-                'type'  => 'hidden',
3933
-                'value' => 'messenger',
3934
-            ],
3935
-        ];
3936
-
3937
-        // make sure any active message types that are existing are included in the hidden fields
3938
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3939
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3940
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3941
-                    'type'  => 'hidden',
3942
-                    'value' => $mt,
3943
-                ];
3944
-            }
3945
-        }
3946
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3947
-            $settings_template_args['hidden_fields'],
3948
-            'array'
3949
-        );
3950
-        $active                                  =
3951
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3952
-
3953
-        $settings_template_args['messenger']           = $messenger->name;
3954
-        $settings_template_args['description']         = $messenger->description;
3955
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3956
-
3957
-
3958
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3959
-            $messenger->name
3960
-        )
3961
-            ? $settings_template_args['show_hide_edit_form']
3962
-            : ' hidden';
3963
-
3964
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3965
-            ? ' hidden'
3966
-            : $settings_template_args['show_hide_edit_form'];
3967
-
3968
-
3969
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3970
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3971
-        $settings_template_args['on_off_status'] = $active;
3972
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3973
-        return EEH_Template::display_template(
3974
-            $template,
3975
-            $settings_template_args,
3976
-            true
3977
-        );
3978
-    }
3979
-
3980
-
3981
-    /**
3982
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3983
-     *
3984
-     * @throws DomainException
3985
-     * @throws EE_Error
3986
-     * @throws InvalidDataTypeException
3987
-     * @throws InvalidInterfaceException
3988
-     * @throws InvalidArgumentException
3989
-     * @throws ReflectionException
3990
-     */
3991
-    public function activate_messenger_toggle()
3992
-    {
3993
-        $success = true;
3994
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3995
-        // let's check that we have required data
3996
-
3997
-        if (! $this->_active_messenger_name) {
3998
-            EE_Error::add_error(
3999
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4000
-                __FILE__,
4001
-                __FUNCTION__,
4002
-                __LINE__
4003
-            );
4004
-            $success = false;
4005
-        }
4006
-
4007
-        // do a nonce check here since we're not arriving via a normal route
4008
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4009
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4010
-
4011
-        $this->_verify_nonce($nonce, $nonce_ref);
4012
-
4013
-
4014
-        $status = $this->request->getRequestParam('status');
4015
-        if (! $status) {
4016
-            EE_Error::add_error(
4017
-                esc_html__(
4018
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4019
-                    'event_espresso'
4020
-                ),
4021
-                __FILE__,
4022
-                __FUNCTION__,
4023
-                __LINE__
4024
-            );
4025
-            $success = false;
4026
-        }
4027
-
4028
-        // do check to verify we have a valid status.
4029
-        if ($status !== 'off' && $status !== 'on') {
4030
-            EE_Error::add_error(
4031
-                sprintf(
4032
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4033
-                    $status
4034
-                ),
4035
-                __FILE__,
4036
-                __FUNCTION__,
4037
-                __LINE__
4038
-            );
4039
-            $success = false;
4040
-        }
4041
-
4042
-        if ($success) {
4043
-            // made it here?  Stop dawdling then!!
4044
-            $success = $status === 'off'
4045
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4046
-                : $this->_activate_messenger($this->_active_messenger_name);
4047
-        }
4048
-
4049
-        $this->_template_args['success'] = $success;
4050
-
4051
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4052
-        $this->_return_json();
4053
-    }
4054
-
4055
-
4056
-    /**
4057
-     * used by ajax from the messages settings page to activate|deactivate a message type
4058
-     *
4059
-     * @throws DomainException
4060
-     * @throws EE_Error
4061
-     * @throws ReflectionException
4062
-     * @throws InvalidDataTypeException
4063
-     * @throws InvalidInterfaceException
4064
-     * @throws InvalidArgumentException
4065
-     */
4066
-    public function activate_mt_toggle()
4067
-    {
4068
-        $success = true;
4069
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4070
-
4071
-        // let's make sure we have the necessary data
4072
-        if (! $this->_active_message_type_name) {
4073
-            EE_Error::add_error(
4074
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4075
-                __FILE__,
4076
-                __FUNCTION__,
4077
-                __LINE__
4078
-            );
4079
-            $success = false;
4080
-        }
4081
-
4082
-        if (! $this->_active_messenger_name) {
4083
-            EE_Error::add_error(
4084
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4085
-                __FILE__,
4086
-                __FUNCTION__,
4087
-                __LINE__
4088
-            );
4089
-            $success = false;
4090
-        }
4091
-
4092
-        $status = $this->request->getRequestParam('status');
4093
-        if (! $status) {
4094
-            EE_Error::add_error(
4095
-                esc_html__(
4096
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4097
-                    'event_espresso'
4098
-                ),
4099
-                __FILE__,
4100
-                __FUNCTION__,
4101
-                __LINE__
4102
-            );
4103
-            $success = false;
4104
-        }
4105
-
4106
-
4107
-        // do check to verify we have a valid status.
4108
-        if ($status !== 'activate' && $status !== 'deactivate') {
4109
-            EE_Error::add_error(
4110
-                sprintf(
4111
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4112
-                    $status
4113
-                ),
4114
-                __FILE__,
4115
-                __FUNCTION__,
4116
-                __LINE__
4117
-            );
4118
-            $success = false;
4119
-        }
4120
-
4121
-
4122
-        // do a nonce check here since we're not arriving via a normal route
4123
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4124
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4125
-
4126
-        if ($success) {
4127
-            // made it here? um, what are you waiting for then?
4128
-            $success = $status === 'deactivate'
4129
-                ? $this->_deactivate_message_type_for_messenger(
4130
-                    $this->_active_messenger_name,
4131
-                    $this->_active_message_type_name
4132
-                )
4133
-                : $this->_activate_message_type_for_messenger(
4134
-                    $this->_active_messenger_name,
4135
-                    $this->_active_message_type_name
4136
-                );
4137
-        }
4138
-
4139
-        $this->_template_args['success'] = $success;
4140
-        $this->_return_json();
4141
-    }
4142
-
4143
-
4144
-    /**
4145
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4146
-     *
4147
-     * @param string $messenger_name The name of the messenger being activated
4148
-     * @return bool
4149
-     * @throws DomainException
4150
-     * @throws EE_Error
4151
-     * @throws InvalidArgumentException
4152
-     * @throws ReflectionException
4153
-     * @throws InvalidDataTypeException
4154
-     * @throws InvalidInterfaceException
4155
-     */
4156
-    protected function _activate_messenger($messenger_name)
4157
-    {
4158
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4159
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4160
-            ? $active_messenger->get_default_message_types()
4161
-            : [];
4162
-
4163
-        // ensure is active
4164
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4165
-
4166
-        // set response_data for reload
4167
-        foreach ($message_types_to_activate as $message_type_name) {
4168
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4169
-            if (
4170
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4171
-                    $messenger_name,
4172
-                    $message_type_name
4173
-                )
4174
-                && $message_type instanceof EE_message_type
4175
-            ) {
4176
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4177
-                if ($message_type->get_admin_settings_fields()) {
4178
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4179
-                }
4180
-            }
4181
-        }
4182
-
4183
-        // add success message for activating messenger
4184
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4185
-    }
4186
-
4187
-
4188
-    /**
4189
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4190
-     *
4191
-     * @param string $messenger_name The name of the messenger being activated
4192
-     * @return bool
4193
-     * @throws DomainException
4194
-     * @throws EE_Error
4195
-     * @throws InvalidArgumentException
4196
-     * @throws ReflectionException
4197
-     * @throws InvalidDataTypeException
4198
-     * @throws InvalidInterfaceException
4199
-     */
4200
-    protected function _deactivate_messenger($messenger_name)
4201
-    {
4202
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4203
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4204
-
4205
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4206
-    }
4207
-
4208
-
4209
-    /**
4210
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4211
-     *
4212
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4213
-     * @param string $message_type_name The name of the message type being activated for the messenger
4214
-     * @return bool
4215
-     * @throws DomainException
4216
-     * @throws EE_Error
4217
-     * @throws InvalidArgumentException
4218
-     * @throws ReflectionException
4219
-     * @throws InvalidDataTypeException
4220
-     * @throws InvalidInterfaceException
4221
-     */
4222
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4223
-    {
4224
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4225
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4226
-
4227
-        // ensure is active
4228
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4229
-
4230
-        // set response for load
4231
-        if (
4232
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4233
-                $messenger_name,
4234
-                $message_type_name
4235
-            )
4236
-        ) {
4237
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4238
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4239
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4240
-            }
4241
-        }
4242
-
4243
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4244
-            $active_messenger,
4245
-            $message_type_to_activate
4246
-        );
4247
-    }
4248
-
4249
-
4250
-    /**
4251
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4252
-     *
4253
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4254
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4255
-     * @return bool
4256
-     * @throws DomainException
4257
-     * @throws EE_Error
4258
-     * @throws InvalidArgumentException
4259
-     * @throws ReflectionException
4260
-     * @throws InvalidDataTypeException
4261
-     * @throws InvalidInterfaceException
4262
-     */
4263
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4264
-    {
4265
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4266
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4267
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4268
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4269
-
4270
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4271
-            $active_messenger,
4272
-            $message_type_to_deactivate
4273
-        );
4274
-    }
4275
-
4276
-
4277
-    /**
4278
-     * This just initializes the defaults for activating messenger and message type responses.
4279
-     */
4280
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4281
-    {
4282
-        $this->_template_args['data']['active_mts'] = [];
4283
-        $this->_template_args['data']['mt_reload']  = [];
4284
-    }
4285
-
4286
-
4287
-    /**
4288
-     * Setup appropriate response for activating a messenger and/or message types
4289
-     *
4290
-     * @param EE_messenger         $messenger
4291
-     * @param EE_message_type|null $message_type
4292
-     * @return bool
4293
-     * @throws DomainException
4294
-     * @throws EE_Error
4295
-     * @throws InvalidArgumentException
4296
-     * @throws ReflectionException
4297
-     * @throws InvalidDataTypeException
4298
-     * @throws InvalidInterfaceException
4299
-     */
4300
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4301
-        $messenger,
4302
-        EE_Message_Type $message_type = null
4303
-    ) {
4304
-        // if $messenger isn't a valid messenger object then get out.
4305
-        if (! $messenger instanceof EE_Messenger) {
4306
-            EE_Error::add_error(
4307
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4308
-                __FILE__,
4309
-                __FUNCTION__,
4310
-                __LINE__
4311
-            );
4312
-            return false;
4313
-        }
4314
-        // activated
4315
-        if ($this->_template_args['data']['active_mts']) {
4316
-            EE_Error::overwrite_success();
4317
-            // activated a message type with the messenger
4318
-            if ($message_type instanceof EE_message_type) {
4319
-                EE_Error::add_success(
4320
-                    sprintf(
4321
-                        esc_html__(
4322
-                            '%s message type has been successfully activated with the %s messenger',
4323
-                            'event_espresso'
4324
-                        ),
4325
-                        ucwords($message_type->label['singular']),
4326
-                        ucwords($messenger->label['singular'])
4327
-                    )
4328
-                );
4329
-
4330
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4331
-                if ($message_type->name === 'invoice') {
4332
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4333
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4334
-                    if ($pm instanceof EE_Payment_Method) {
4335
-                        EE_Error::add_attention(
4336
-                            esc_html__(
4337
-                                '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.',
4338
-                                'event_espresso'
4339
-                            )
4340
-                        );
4341
-                    }
4342
-                }
4343
-                // just toggles the entire messenger
4344
-            } else {
4345
-                EE_Error::add_success(
4346
-                    sprintf(
4347
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4348
-                        ucwords($messenger->label['singular'])
4349
-                    )
4350
-                );
4351
-            }
4352
-
4353
-            return true;
4354
-
4355
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4356
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4357
-            // in which case we just give a success message for the messenger being successfully activated.
4358
-        } else {
4359
-            if (! $messenger->get_default_message_types()) {
4360
-                // messenger doesn't have any default message types so still a success.
4361
-                EE_Error::add_success(
4362
-                    sprintf(
4363
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4364
-                        ucwords($messenger->label['singular'])
4365
-                    )
4366
-                );
4367
-
4368
-                return true;
4369
-            } else {
4370
-                EE_Error::add_error(
4371
-                    $message_type instanceof EE_message_type
4372
-                    ? sprintf(
4373
-                        esc_html__(
4374
-                            '%s message type was not successfully activated with the %s messenger',
4375
-                            'event_espresso'
4376
-                        ),
4377
-                        ucwords($message_type->label['singular']),
4378
-                        ucwords($messenger->label['singular'])
4379
-                    )
4380
-                    : sprintf(
4381
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4382
-                        ucwords($messenger->label['singular'])
4383
-                    ),
4384
-                    __FILE__,
4385
-                    __FUNCTION__,
4386
-                    __LINE__
4387
-                );
4388
-
4389
-                return false;
4390
-            }
4391
-        }
4392
-    }
4393
-
4394
-
4395
-    /**
4396
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4397
-     *
4398
-     * @param EE_messenger         $messenger
4399
-     * @param EE_message_type|null $message_type
4400
-     * @return bool
4401
-     * @throws DomainException
4402
-     * @throws EE_Error
4403
-     * @throws InvalidArgumentException
4404
-     * @throws ReflectionException
4405
-     * @throws InvalidDataTypeException
4406
-     * @throws InvalidInterfaceException
4407
-     */
4408
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4409
-        $messenger,
4410
-        EE_message_type $message_type = null
4411
-    ) {
4412
-        EE_Error::overwrite_success();
4413
-
4414
-        // if $messenger isn't a valid messenger object then get out.
4415
-        if (! $messenger instanceof EE_Messenger) {
4416
-            EE_Error::add_error(
4417
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4418
-                __FILE__,
4419
-                __FUNCTION__,
4420
-                __LINE__
4421
-            );
4422
-
4423
-            return false;
4424
-        }
4425
-
4426
-        if ($message_type instanceof EE_message_type) {
4427
-            $message_type_name = $message_type->name;
4428
-            EE_Error::add_success(
4429
-                sprintf(
4430
-                    esc_html__(
4431
-                        '%s message type has been successfully deactivated for the %s messenger.',
4432
-                        'event_espresso'
4433
-                    ),
4434
-                    ucwords($message_type->label['singular']),
4435
-                    ucwords($messenger->label['singular'])
4436
-                )
4437
-            );
4438
-        } else {
4439
-            $message_type_name = '';
4440
-            EE_Error::add_success(
4441
-                sprintf(
4442
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4443
-                    ucwords($messenger->label['singular'])
4444
-                )
4445
-            );
4446
-        }
4447
-
4448
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4449
-        if (
4450
-            $messenger->name === 'html'
4451
-            && (
4452
-                is_null($message_type)
4453
-                || $message_type_name === 'invoice'
4454
-            )
4455
-        ) {
4456
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4457
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4458
-            if ($count_updated > 0) {
4459
-                $msg = $message_type_name === 'invoice'
4460
-                    ? esc_html__(
4461
-                        '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.',
4462
-                        'event_espresso'
4463
-                    )
4464
-                    : esc_html__(
4465
-                        '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.',
4466
-                        'event_espresso'
4467
-                    );
4468
-                EE_Error::add_attention($msg);
4469
-            }
4470
-        }
4471
-
4472
-        return true;
4473
-    }
4474
-
4475
-
4476
-    /**
4477
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4478
-     *
4479
-     * @throws DomainException
4480
-     * @throws EE_Error
4481
-     * @throws EE_Error
4482
-     */
4483
-    public function update_mt_form()
4484
-    {
4485
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4486
-            EE_Error::add_error(
4487
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4488
-                __FILE__,
4489
-                __FUNCTION__,
4490
-                __LINE__
4491
-            );
4492
-            $this->_return_json();
4493
-        }
4494
-
4495
-        $message_types = $this->get_installed_message_types();
4496
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4497
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4498
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4499
-
4500
-        $this->_template_args['success'] = true;
4501
-        $this->_template_args['content'] = $content;
4502
-        $this->_return_json();
4503
-    }
4504
-
4505
-
4506
-    /**
4507
-     * this handles saving the settings for a messenger or message type
4508
-     *
4509
-     * @throws EE_Error
4510
-     * @throws EE_Error
4511
-     */
4512
-    public function save_settings()
4513
-    {
4514
-        $type = $this->request->getRequestParam('type');
4515
-        if (! $type) {
4516
-            EE_Error::add_error(
4517
-                esc_html__(
4518
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4519
-                    'event_espresso'
4520
-                ),
4521
-                __FILE__,
4522
-                __FUNCTION__,
4523
-                __LINE__
4524
-            );
4525
-            $this->_template_args['error'] = true;
4526
-            $this->_return_json();
4527
-        }
4528
-
4529
-
4530
-        if ($type === 'messenger') {
4531
-            // this should be an array.
4532
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4533
-            $messenger = $settings['messenger'];
4534
-            // remove messenger and message_types from settings array
4535
-            unset($settings['messenger'], $settings['message_types']);
4536
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4537
-        } elseif ($type === 'message_type') {
4538
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4539
-            $messenger    = $settings['messenger'];
4540
-            $message_type = $settings['message_type'];
4541
-            // remove messenger and message_types from settings array
4542
-            unset($settings['messenger'], $settings['message_types']);
4543
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4544
-        }
4545
-
4546
-        // okay we should have the data all setup.  Now we just update!
4547
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4548
-
4549
-        if ($success) {
4550
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4551
-        } else {
4552
-            EE_Error::add_error(
4553
-                esc_html__('Settings did not get updated', 'event_espresso'),
4554
-                __FILE__,
4555
-                __FUNCTION__,
4556
-                __LINE__
4557
-            );
4558
-        }
4559
-
4560
-        $this->_template_args['success'] = $success;
4561
-        $this->_return_json();
4562
-    }
4563
-
4564
-
4565
-
4566
-
4567
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4568
-
4569
-
4570
-    /**
4571
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4572
-     * However, this does not send immediately, it just queues for sending.
4573
-     *
4574
-     * @throws EE_Error
4575
-     * @throws InvalidDataTypeException
4576
-     * @throws InvalidInterfaceException
4577
-     * @throws InvalidArgumentException
4578
-     * @throws ReflectionException
4579
-     * @since 4.9.0
4580
-     */
4581
-    protected function _generate_now()
4582
-    {
4583
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4584
-        $this->_redirect_after_action(false, '', '', [], true);
4585
-    }
4586
-
4587
-
4588
-    /**
4589
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4590
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4591
-     *
4592
-     * @throws EE_Error
4593
-     * @throws InvalidDataTypeException
4594
-     * @throws InvalidInterfaceException
4595
-     * @throws InvalidArgumentException
4596
-     * @throws ReflectionException
4597
-     * @since 4.9.0
4598
-     */
4599
-    protected function _generate_and_send_now()
4600
-    {
4601
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4602
-        $this->_redirect_after_action(false, '', '', [], true);
4603
-    }
4604
-
4605
-
4606
-    /**
4607
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4608
-     *
4609
-     * @throws EE_Error
4610
-     * @throws InvalidDataTypeException
4611
-     * @throws InvalidInterfaceException
4612
-     * @throws InvalidArgumentException
4613
-     * @throws ReflectionException
4614
-     * @since 4.9.0
4615
-     */
4616
-    protected function _queue_for_resending()
4617
-    {
4618
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4619
-        $this->_redirect_after_action(false, '', '', [], true);
4620
-    }
4621
-
4622
-
4623
-    /**
4624
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4625
-     *
4626
-     * @throws EE_Error
4627
-     * @throws InvalidDataTypeException
4628
-     * @throws InvalidInterfaceException
4629
-     * @throws InvalidArgumentException
4630
-     * @throws ReflectionException
4631
-     * @since 4.9.0
4632
-     */
4633
-    protected function _send_now()
4634
-    {
4635
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4636
-        $this->_redirect_after_action(false, '', '', [], true);
4637
-    }
4638
-
4639
-
4640
-    /**
4641
-     * Deletes EE_messages for IDs in the request.
4642
-     *
4643
-     * @throws EE_Error
4644
-     * @throws InvalidDataTypeException
4645
-     * @throws InvalidInterfaceException
4646
-     * @throws InvalidArgumentException
4647
-     * @since 4.9.0
4648
-     */
4649
-    protected function _delete_ee_messages()
4650
-    {
4651
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4652
-        $deleted_count = 0;
4653
-        foreach ($MSG_IDs as $MSG_ID) {
4654
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4655
-                $deleted_count++;
4656
-            }
4657
-        }
4658
-        if ($deleted_count) {
4659
-            EE_Error::add_success(
4660
-                esc_html(
4661
-                    _n(
4662
-                        'Message successfully deleted',
4663
-                        'Messages successfully deleted',
4664
-                        $deleted_count,
4665
-                        'event_espresso'
4666
-                    )
4667
-                )
4668
-            );
4669
-        } else {
4670
-            EE_Error::add_error(
4671
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4672
-                __FILE__,
4673
-                __FUNCTION__,
4674
-                __LINE__
4675
-            );
4676
-        }
4677
-        $this->_redirect_after_action(false, '', '', [], true);
4678
-    }
4679
-
4680
-
4681
-    /**
4682
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4683
-     *
4684
-     * @return array
4685
-     * @since 4.9.0
4686
-     */
4687
-    protected function _get_msg_ids_from_request()
4688
-    {
4689
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4690
-        if (empty($MSG_IDs)) {
4691
-            return [];
4692
-        }
4693
-        // if 'MSG_ID' was just a single ID (not an array)
4694
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4695
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4696
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4697
-            ? $MSG_IDs
4698
-            : array_keys($MSG_IDs);
4699
-    }
2711
+	}
2712
+
2713
+
2714
+	/**
2715
+	 * @param bool $new
2716
+	 * @throws EE_Error
2717
+	 * @throws ReflectionException
2718
+	 */
2719
+	protected function _insert_or_update_message_template($new = false)
2720
+	{
2721
+		$form_data    = $this->getMessageTemplateFormData();
2722
+		$GRP_ID       = $form_data['GRP_ID'];
2723
+		$messenger    = $form_data['MTP_messenger'];
2724
+		$message_type = $form_data['MTP_message_type'];
2725
+		$context      = $form_data['MTP_context'];
2726
+
2727
+		// if this is "new" then we need to generate the default contexts
2728
+		// for the selected messenger/message_type for user to edit.
2729
+		[$success, $query_args] = $new
2730
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2731
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2732
+
2733
+		$success     = $success ? 1 : 0;
2734
+		$action_desc = $new ? 'created' : 'updated';
2735
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2736
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2737
+
2738
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2739
+	}
2740
+
2741
+
2742
+	/**
2743
+	 * retrieve and sanitize form data
2744
+	 *
2745
+	 * @return array
2746
+	 * @since 4.10.29.p
2747
+	 */
2748
+	protected function getMessageTemplateFormData()
2749
+	{
2750
+		return [
2751
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2752
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2753
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2754
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2755
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2756
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2757
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2758
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2759
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2760
+		];
2761
+	}
2762
+
2763
+
2764
+	/**
2765
+	 * @param int    $GRP_ID
2766
+	 * @param string $messenger
2767
+	 * @param string $message_type
2768
+	 * @return array no return on AJAX requests
2769
+	 * @throws EE_Error
2770
+	 * @throws ReflectionException
2771
+	 * @since 4.10.29.p
2772
+	 */
2773
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2774
+	{
2775
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2776
+		$success       = ! empty($new_templates);
2777
+
2778
+		// we return things differently if doing ajax
2779
+		if ($this->request->isAjax()) {
2780
+			$this->_template_args['success'] = $success;
2781
+			$this->_template_args['error']   = ! $success;
2782
+			$this->_template_args['content'] = '';
2783
+			$this->_template_args['data']    = [
2784
+				'grpID'        => $new_templates['GRP_ID'],
2785
+				'templateName' => $new_templates['template_name'],
2786
+			];
2787
+			if ($success) {
2788
+				EE_Error::overwrite_success();
2789
+				EE_Error::add_success(
2790
+					esc_html__(
2791
+						'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.',
2792
+						'event_espresso'
2793
+					)
2794
+				);
2795
+			}
2796
+			$this->_return_json();
2797
+		}
2798
+		return [
2799
+			$success,
2800
+			// 'query_args'
2801
+			[
2802
+				'id'      => $new_templates['GRP_ID'],
2803
+				'context' => $new_templates['MTP_context'],
2804
+				'action'  => 'edit_message_template',
2805
+			],
2806
+		];
2807
+	}
2808
+
2809
+
2810
+	/**
2811
+	 * @param int    $GRP_ID
2812
+	 * @param string $messenger
2813
+	 * @param string $message_type
2814
+	 * @param string $context
2815
+	 * @param array  $form_data
2816
+	 * @return array
2817
+	 * @throws EE_Error
2818
+	 * @since 4.10.29.p
2819
+	 */
2820
+	private function updateExistingTemplates(
2821
+		$GRP_ID,
2822
+		$messenger,
2823
+		$message_type,
2824
+		$context,
2825
+		array $form_data
2826
+	) {
2827
+		$success         = false;
2828
+		$template_fields = $this->getTemplateFields();
2829
+		if ($template_fields) {
2830
+			// if field data is valid, then success will be true
2831
+			$success = $this->validateTemplateFields(
2832
+				$messenger,
2833
+				$message_type,
2834
+				$context,
2835
+				$template_fields
2836
+			);
2837
+			if ($success) {
2838
+				$field_data = [];
2839
+				foreach ($template_fields as $template_field => $content) {
2840
+					// combine top-level form data with content for this field
2841
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2842
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2843
+				}
2844
+				// we can use the last set_column_values for the MTPG update
2845
+				// (because its the same for all of these specific MTPs)
2846
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2847
+			}
2848
+		}
2849
+
2850
+		return [
2851
+			$success,
2852
+			// 'query_args'
2853
+			[
2854
+				'id'      => $GRP_ID,
2855
+				'context' => $context,
2856
+				'action'  => 'edit_message_template',
2857
+			],
2858
+		];
2859
+	}
2860
+
2861
+
2862
+	/**
2863
+	 * @return array
2864
+	 * @since 4.10.29.p
2865
+	 */
2866
+	private function getTemplateFields()
2867
+	{
2868
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2869
+		if (empty($template_fields)) {
2870
+			EE_Error::add_error(
2871
+				esc_html__(
2872
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2873
+					'event_espresso'
2874
+				),
2875
+				__FILE__,
2876
+				__FUNCTION__,
2877
+				__LINE__
2878
+			);
2879
+			return null;
2880
+		}
2881
+		// messages content is expected to be escaped
2882
+		return EEH_Array::addSlashesRecursively($template_fields);
2883
+	}
2884
+
2885
+
2886
+	/**
2887
+	 * @param string $messenger
2888
+	 * @param string $message_type
2889
+	 * @param string $context
2890
+	 * @param array  $template_fields
2891
+	 * @return bool
2892
+	 * @throws EE_Error
2893
+	 * @since   4.10.29.p
2894
+	 */
2895
+	private function validateTemplateFields(
2896
+		$messenger,
2897
+		$message_type,
2898
+		$context,
2899
+		array $template_fields
2900
+	) {
2901
+		// first validate all fields!
2902
+		// this filter allows client code to add its own validation to the template fields as well.
2903
+		// returning an empty array means everything passed validation.
2904
+		// errors in validation should be represented in an array with the following shape:
2905
+		// array(
2906
+		//   'fieldname' => array(
2907
+		//          'msg' => 'error message'
2908
+		//          'value' => 'value for field producing error'
2909
+		// )
2910
+		$custom_validation = (array) apply_filters(
2911
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2912
+			[],
2913
+			$template_fields,
2914
+			$context,
2915
+			$messenger,
2916
+			$message_type
2917
+		);
2918
+
2919
+		$system_validation = $this->getMtgModel()->validate(
2920
+			$template_fields,
2921
+			$context,
2922
+			$messenger,
2923
+			$message_type
2924
+		);
2925
+
2926
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2927
+		$validates         = array_merge($custom_validation, $system_validation);
2928
+
2929
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2930
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2931
+		//  WE need to make sure there is no actual error messages in validates.
2932
+		if (empty($validates)) {
2933
+			return true;
2934
+		}
2935
+
2936
+		// add the transient so when the form loads we know which fields to highlight
2937
+		$this->_add_transient('edit_message_template', $validates);
2938
+		// setup notices
2939
+		foreach ($validates as $error) {
2940
+			if (isset($error['msg'])) {
2941
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2942
+			}
2943
+		}
2944
+		return false;
2945
+	}
2946
+
2947
+
2948
+	/**
2949
+	 * @param array $field_data
2950
+	 * @param array $form_data
2951
+	 * @return array
2952
+	 * @since   4.10.29.p
2953
+	 */
2954
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2955
+	{
2956
+		return $form_data + [
2957
+				'MTP_ID'             => $field_data['MTP_ID'],
2958
+				'MTP_template_field' => $field_data['name'],
2959
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2960
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2961
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2962
+					: $field_data['content'],
2963
+			];
2964
+	}
2965
+
2966
+
2967
+	/**
2968
+	 * @param string $template_field
2969
+	 * @param array  $form_data
2970
+	 * @return bool
2971
+	 * @throws EE_Error
2972
+	 * @since 4.10.29.p
2973
+	 */
2974
+	private function updateMessageTemplates($template_field, array $form_data)
2975
+	{
2976
+		$MTP_ID                  = $form_data['MTP_ID'];
2977
+		$message_template_fields = [
2978
+			'GRP_ID'             => $form_data['GRP_ID'],
2979
+			'MTP_template_field' => $form_data['MTP_template_field'],
2980
+			'MTP_context'        => $form_data['MTP_context'],
2981
+			'MTP_content'        => $form_data['MTP_content'],
2982
+		];
2983
+
2984
+		$hasMtpID = ! empty($MTP_ID);
2985
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2986
+		// this has already been through the template field validator and sanitized, so it will be
2987
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2988
+		// message template field in a messenger/message type and existing users don't have the
2989
+		// default setup for it.
2990
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2991
+		$updated = $hasMtpID
2992
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2993
+			: $this->getMtpModel()->insert($message_template_fields);
2994
+
2995
+		$insert_failed = ! $hasMtpID && ! $updated;
2996
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2997
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2998
+		$update_failed = $hasMtpID && $updated === false;
2999
+
3000
+		if ($insert_failed || $update_failed) {
3001
+			EE_Error::add_error(
3002
+				sprintf(
3003
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
3004
+					$template_field
3005
+				),
3006
+				__FILE__,
3007
+				__FUNCTION__,
3008
+				__LINE__
3009
+			);
3010
+			return false;
3011
+		}
3012
+		return true;
3013
+	}
3014
+
3015
+
3016
+	/**
3017
+	 * @param array $form_data
3018
+	 * @return bool
3019
+	 * @throws EE_Error
3020
+	 * @since 4.10.29.p
3021
+	 */
3022
+	private function updateMessageTemplateGroup(array $form_data)
3023
+	{
3024
+		$GRP_ID  = $form_data['GRP_ID'];
3025
+		$updated = $this->getMtgModel()->update(
3026
+		// fields and values
3027
+			[
3028
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3029
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3030
+				'MTP_message_type' => $form_data['MTP_message_type'],
3031
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3032
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3033
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3034
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3035
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3036
+				'MTP_description'  => $this->request->getRequestParam(
3037
+					'ee_msg_non_global_fields[MTP_description]',
3038
+					''
3039
+				),
3040
+			],
3041
+			// where
3042
+			[['GRP_ID' => $GRP_ID]]
3043
+		);
3044
+
3045
+		if ($updated === false) {
3046
+			EE_Error::add_error(
3047
+				sprintf(
3048
+					esc_html__(
3049
+						'The Message Template Group (%d) was NOT updated for some reason',
3050
+						'event_espresso'
3051
+					),
3052
+					$form_data['GRP_ID']
3053
+				),
3054
+				__FILE__,
3055
+				__FUNCTION__,
3056
+				__LINE__
3057
+			);
3058
+			return false;
3059
+		}
3060
+		// k now we need to ensure the template_pack and template_variation fields are set.
3061
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3062
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3063
+
3064
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3065
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3066
+			$message_template_group->set_template_pack_name($template_pack);
3067
+			$message_template_group->set_template_pack_variation($template_variation);
3068
+		}
3069
+		return true;
3070
+	}
3071
+
3072
+
3073
+	/**
3074
+	 * recursively runs wp_kses() on message template content in a model safe manner
3075
+	 *
3076
+	 * @param array|string $content
3077
+	 * @return array|string
3078
+	 * @since   4.10.29.p
3079
+	 */
3080
+	private function sanitizeMessageTemplateContent($content)
3081
+	{
3082
+		if (is_array($content)) {
3083
+			foreach ($content as $key => $value) {
3084
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3085
+			}
3086
+			return $content;
3087
+		}
3088
+		// remove slashes so wp_kses() works properly
3089
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3090
+		// so attributes using single quotes always appear invalid.
3091
+		$content = stripslashes($content);
3092
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3093
+		// But currently the models expect slashed data, so after wp_kses()
3094
+		// runs we need to re-slash the data. Sheesh.
3095
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3096
+		return addslashes($content);
3097
+	}
3098
+
3099
+
3100
+	/**
3101
+	 * @param string $messenger
3102
+	 * @param string $message_type
3103
+	 * @param string $context
3104
+	 * @return string
3105
+	 * @since 4.10.29.p
3106
+	 */
3107
+	private function generateUpdateDescription($messenger, $message_type, $context)
3108
+	{
3109
+		// need the message type and messenger objects to be able to use the labels for the notices
3110
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3111
+		$messenger_label  = $messenger_object instanceof EE_messenger
3112
+			? ucwords($messenger_object->label['singular'])
3113
+			: '';
3114
+
3115
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3116
+		$message_type_label  = $message_type_object instanceof EE_message_type
3117
+			? ucwords($message_type_object->label['singular'])
3118
+			: '';
3119
+
3120
+		$context   = ucwords(str_replace('_', ' ', $context));
3121
+		$item_desc = $messenger_label && $message_type_label
3122
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3123
+			: '';
3124
+		$item_desc .= 'Message Template';
3125
+		return $item_desc;
3126
+	}
3127
+
3128
+
3129
+	/**
3130
+	 * @param string $messenger
3131
+	 * @param string $message_type
3132
+	 * @param string $context
3133
+	 * @return bool
3134
+	 * @throws EE_Error
3135
+	 * @throws ReflectionException
3136
+	 * @since 4.10.29.p
3137
+	 */
3138
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3139
+	{
3140
+		// was a test send triggered?
3141
+		if ($this->request->requestParamIsSet('test_button')) {
3142
+			EE_Error::overwrite_success();
3143
+			$this->_do_test_send($context, $messenger, $message_type);
3144
+			return true;
3145
+		}
3146
+		return false;
3147
+	}
3148
+
3149
+
3150
+	/**
3151
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3152
+	 *
3153
+	 * @param string $context      what context being tested
3154
+	 * @param string $messenger    messenger being tested
3155
+	 * @param string $message_type message type being tested
3156
+	 * @throws EE_Error
3157
+	 * @throws InvalidArgumentException
3158
+	 * @throws InvalidDataTypeException
3159
+	 * @throws InvalidInterfaceException
3160
+	 * @throws ReflectionException
3161
+	 */
3162
+	protected function _do_test_send($context, $messenger, $message_type)
3163
+	{
3164
+		// set things up for preview
3165
+		$this->request->setRequestParam('messenger', $messenger);
3166
+		$this->request->setRequestParam('message_type', $message_type);
3167
+		$this->request->setRequestParam('context', $context);
3168
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3169
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3170
+
3171
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3172
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3173
+
3174
+		// let's save any existing fields that might be required by the messenger
3175
+		if (
3176
+			! empty($test_settings_fld)
3177
+			&& $active_messenger instanceof EE_messenger
3178
+			&& apply_filters(
3179
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3180
+				true,
3181
+				$test_settings_fld,
3182
+				$active_messenger
3183
+			)
3184
+		) {
3185
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3186
+		}
3187
+
3188
+		/**
3189
+		 * Use filter to add additional controls on whether message can send or not
3190
+		 */
3191
+		if (
3192
+			apply_filters(
3193
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3194
+				true,
3195
+				$context,
3196
+				$this->request->requestParams(),
3197
+				$messenger,
3198
+				$message_type
3199
+			)
3200
+		) {
3201
+			if (EEM_Event::instance()->count() > 0) {
3202
+				$success = $this->_preview_message(true);
3203
+				if ($success) {
3204
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3205
+				} else {
3206
+					EE_Error::add_error(
3207
+						esc_html__('The test message was not sent', 'event_espresso'),
3208
+						__FILE__,
3209
+						__FUNCTION__,
3210
+						__LINE__
3211
+					);
3212
+				}
3213
+			} else {
3214
+				$this->noEventsErrorMessage(true);
3215
+			}
3216
+		}
3217
+	}
3218
+
3219
+
3220
+	/**
3221
+	 * _generate_new_templates
3222
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3223
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3224
+	 * for the event.
3225
+	 *
3226
+	 *
3227
+	 * @param string $messenger      the messenger we are generating templates for
3228
+	 * @param array  $message_types  array of message types that the templates are generated for.
3229
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3230
+	 *                               indicate the message_template_group being used as the base.
3231
+	 *
3232
+	 * @param bool   $global
3233
+	 *
3234
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3235
+	 *                               encountering problems.
3236
+	 * @throws EE_Error
3237
+	 * @throws ReflectionException
3238
+	 */
3239
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3240
+	{
3241
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3242
+		// just don't generate any templates.
3243
+		if (empty($message_types)) {
3244
+			return [];
3245
+		}
3246
+
3247
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3248
+		return $templates[0];
3249
+	}
3250
+
3251
+
3252
+	/**
3253
+	 * [_trash_or_restore_message_template]
3254
+	 *
3255
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3256
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3257
+	 *                        an individual context (FALSE).
3258
+	 * @return void
3259
+	 * @throws EE_Error
3260
+	 * @throws InvalidArgumentException
3261
+	 * @throws InvalidDataTypeException
3262
+	 * @throws InvalidInterfaceException
3263
+	 */
3264
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3265
+	{
3266
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3267
+
3268
+		$success = 1;
3269
+
3270
+		// incoming GRP_IDs
3271
+		if ($all) {
3272
+			// Checkboxes
3273
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3274
+			if (! empty($checkboxes)) {
3275
+				// if array has more than one element then success message should be plural.
3276
+				// todo: what about nonce?
3277
+				$success = count($checkboxes) > 1 ? 2 : 1;
3278
+
3279
+				// cycle through checkboxes
3280
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3281
+					$trashed_or_restored = $trash
3282
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3283
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3284
+					if (! $trashed_or_restored) {
3285
+						$success = 0;
3286
+					}
3287
+				}
3288
+			} else {
3289
+				// grab single GRP_ID and handle
3290
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3291
+				if (! empty($GRP_ID)) {
3292
+					$trashed_or_restored = $trash
3293
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3294
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3295
+					if (! $trashed_or_restored) {
3296
+						$success = 0;
3297
+					}
3298
+				} else {
3299
+					$success = 0;
3300
+				}
3301
+			}
3302
+		}
3303
+
3304
+		$action_desc = $trash
3305
+			? esc_html__('moved to the trash', 'event_espresso')
3306
+			: esc_html__('restored', 'event_espresso');
3307
+
3308
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3309
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3310
+
3311
+		$item_desc = $all ? _n(
3312
+			'Message Template Group',
3313
+			'Message Template Groups',
3314
+			$success,
3315
+			'event_espresso'
3316
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3317
+
3318
+		$item_desc = $template_switch
3319
+			? _n('template', 'templates', $success, 'event_espresso')
3320
+			: $item_desc;
3321
+
3322
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3323
+	}
3324
+
3325
+
3326
+	/**
3327
+	 * [_delete_message_template]
3328
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3329
+	 *
3330
+	 * @return void
3331
+	 * @throws EE_Error
3332
+	 * @throws InvalidArgumentException
3333
+	 * @throws InvalidDataTypeException
3334
+	 * @throws InvalidInterfaceException
3335
+	 * @throws ReflectionException
3336
+	 */
3337
+	protected function _delete_message_template()
3338
+	{
3339
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3340
+
3341
+		// checkboxes
3342
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3343
+		if (! empty($checkboxes)) {
3344
+			// if array has more than one element then success message should be plural
3345
+			$success = count($checkboxes) > 1 ? 2 : 1;
3346
+
3347
+			// cycle through bulk action checkboxes
3348
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3349
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3350
+			}
3351
+		} else {
3352
+			// grab single grp_id and delete
3353
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3354
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3355
+		}
3356
+
3357
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3358
+	}
3359
+
3360
+
3361
+	/**
3362
+	 * helper for permanently deleting a mtP group and all related message_templates
3363
+	 *
3364
+	 * @param int  $GRP_ID        The group being deleted
3365
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3366
+	 * @return bool boolean to indicate the success of the deletes or not.
3367
+	 * @throws EE_Error
3368
+	 * @throws InvalidArgumentException
3369
+	 * @throws InvalidDataTypeException
3370
+	 * @throws InvalidInterfaceException
3371
+	 * @throws ReflectionException
3372
+	 * @throws ReflectionException
3373
+	 */
3374
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3375
+	{
3376
+		$success = true;
3377
+		// first let's GET this group
3378
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3379
+		// then delete permanently all the related Message Templates
3380
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3381
+
3382
+		if ($deleted === 0) {
3383
+			$success = false;
3384
+		}
3385
+
3386
+		// now delete permanently this particular group
3387
+
3388
+		if ($include_group && ! $MTG->delete_permanently()) {
3389
+			$success = false;
3390
+		}
3391
+
3392
+		return $success;
3393
+	}
3394
+
3395
+
3396
+	/**
3397
+	 *    _learn_more_about_message_templates_link
3398
+	 *
3399
+	 * @access protected
3400
+	 * @return string
3401
+	 */
3402
+	protected function _learn_more_about_message_templates_link()
3403
+	{
3404
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3405
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3406
+			   . '</a>';
3407
+	}
3408
+
3409
+
3410
+	/**
3411
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3412
+	 * ajax and other routes.
3413
+	 *
3414
+	 * @return void
3415
+	 * @throws DomainException
3416
+	 * @throws EE_Error
3417
+	 */
3418
+	protected function _settings()
3419
+	{
3420
+		$this->_set_m_mt_settings();
3421
+
3422
+		// let's setup the messenger tabs
3423
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3424
+			$this->_m_mt_settings['messenger_tabs'],
3425
+			'messenger_links',
3426
+			'|',
3427
+			$this->request->getRequestParam('selected_messenger', 'email')
3428
+		);
3429
+
3430
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3431
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3432
+
3433
+		$this->display_admin_page_with_sidebar();
3434
+	}
3435
+
3436
+
3437
+	/**
3438
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3439
+	 *
3440
+	 * @access protected
3441
+	 * @return void
3442
+	 * @throws DomainException
3443
+	 */
3444
+	protected function _set_m_mt_settings()
3445
+	{
3446
+		// first if this is already set then lets get out no need to regenerate data.
3447
+		if (! empty($this->_m_mt_settings)) {
3448
+			return;
3449
+		}
3450
+
3451
+		// get all installed messengers and message_types
3452
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3453
+		$message_types = $this->_message_resource_manager->installed_message_types();
3454
+
3455
+
3456
+		// assemble the array for the _tab_text_links helper
3457
+
3458
+		foreach ($messengers as $messenger) {
3459
+			$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3460
+			$class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3461
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3462
+				'label' => ucwords($messenger->label['singular']),
3463
+				'class' => $active ? "{$class} messenger-active" : $class,
3464
+				'href'  => $messenger->name,
3465
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3466
+				'slug'  => $messenger->name,
3467
+				'obj'   => $messenger,
3468
+				'icon' => $active
3469
+					? '<span class="dashicons dashicons-yes-alt"></span>'
3470
+					: '<span class="dashicons dashicons-remove"></span>',
3471
+			];
3472
+
3473
+
3474
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3475
+
3476
+			foreach ($message_types as $message_type) {
3477
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3478
+				// it shouldn't show in either the inactive OR active metabox.
3479
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3480
+					continue;
3481
+				}
3482
+
3483
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3484
+					$messenger->name,
3485
+					$message_type->name
3486
+				)
3487
+					? 'active'
3488
+					: 'inactive';
3489
+
3490
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3491
+					'label'    => ucwords($message_type->label['singular']),
3492
+					'class'    => 'message-type-' . $a_or_i,
3493
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3494
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3495
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3496
+					'title'    => $a_or_i === 'active'
3497
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3498
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3499
+					'content'  => $a_or_i === 'active'
3500
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3501
+						: $this->_message_type_settings_content($message_type, $messenger),
3502
+					'slug'     => $message_type->name,
3503
+					'active'   => $a_or_i === 'active',
3504
+					'obj'      => $message_type,
3505
+				];
3506
+			}
3507
+		}
3508
+	}
3509
+
3510
+
3511
+	/**
3512
+	 * This just prepares the content for the message type settings
3513
+	 *
3514
+	 * @param EE_message_type $message_type The message type object
3515
+	 * @param EE_messenger    $messenger    The messenger object
3516
+	 * @param boolean         $active       Whether the message type is active or not
3517
+	 * @return string html output for the content
3518
+	 * @throws DomainException
3519
+	 */
3520
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3521
+	{
3522
+		// get message type fields
3523
+		$fields                                         = $message_type->get_admin_settings_fields();
3524
+		$settings_template_args['template_form_fields'] = '';
3525
+
3526
+		if (! empty($fields) && $active) {
3527
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3528
+			foreach ($fields as $fldname => $fldprops) {
3529
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3530
+				$template_form_field[ $field_id ] = [
3531
+					'name'       => 'message_type_settings[' . $fldname . ']',
3532
+					'label'      => $fldprops['label'],
3533
+					'input'      => $fldprops['field_type'],
3534
+					'type'       => $fldprops['value_type'],
3535
+					'required'   => $fldprops['required'],
3536
+					'validation' => $fldprops['validation'],
3537
+					'value'      => isset($existing_settings[ $fldname ])
3538
+						? $existing_settings[ $fldname ]
3539
+						: $fldprops['default'],
3540
+					'options'    => isset($fldprops['options'])
3541
+						? $fldprops['options']
3542
+						: [],
3543
+					'default'    => isset($existing_settings[ $fldname ])
3544
+						? $existing_settings[ $fldname ]
3545
+						: $fldprops['default'],
3546
+					'css_class'  => 'no-drag',
3547
+					'format'     => $fldprops['format'],
3548
+				];
3549
+			}
3550
+
3551
+
3552
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3553
+				? $this->_generate_admin_form_fields(
3554
+					$template_form_field,
3555
+					'string',
3556
+					'ee_mt_activate_form'
3557
+				)
3558
+				: '';
3559
+		}
3560
+
3561
+		$settings_template_args['description'] = $message_type->description;
3562
+		// we also need some hidden fields
3563
+		$hidden_fields = [
3564
+			'message_type_settings[messenger]' . $message_type->name    => [
3565
+				'type'  => 'hidden',
3566
+				'value' => $messenger->name,
3567
+			],
3568
+			'message_type_settings[message_type]' . $message_type->name => [
3569
+				'type'  => 'hidden',
3570
+				'value' => $message_type->name,
3571
+			],
3572
+			'type' . $message_type->name                                => [
3573
+				'type'  => 'hidden',
3574
+				'value' => 'message_type',
3575
+			],
3576
+		];
3577
+
3578
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3579
+			$hidden_fields,
3580
+			'array'
3581
+		);
3582
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3583
+			? ' hidden'
3584
+			: '';
3585
+
3586
+
3587
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3588
+		return EEH_Template::display_template($template, $settings_template_args, true);
3589
+	}
3590
+
3591
+
3592
+	/**
3593
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3594
+	 *
3595
+	 * @access protected
3596
+	 * @return void
3597
+	 * @throws DomainException
3598
+	 */
3599
+	protected function _messages_settings_metaboxes()
3600
+	{
3601
+		$this->_set_m_mt_settings();
3602
+		$m_boxes         = $mt_boxes = [];
3603
+		$m_template_args = $mt_template_args = [];
3604
+
3605
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3606
+
3607
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3608
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3609
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3610
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3611
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3612
+
3613
+				// messenger meta boxes
3614
+				$active         = $selected_messenger === $messenger;
3615
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3616
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3617
+					: '';
3618
+
3619
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3620
+					esc_html__('%s Settings', 'event_espresso'),
3621
+					$tab_array['label']
3622
+				);
3623
+
3624
+				$m_template_args[ $messenger . '_a_box' ] = [
3625
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3626
+					'inactive_message_types' => isset(
3627
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3628
+					)
3629
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3630
+						: '',
3631
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3632
+					'hidden'                 => $active ? '' : ' hidden',
3633
+					'hide_on_message'        => $hide_on_message,
3634
+					'messenger'              => $messenger,
3635
+					'active'                 => $active,
3636
+				];
3637
+
3638
+				// message type meta boxes
3639
+				// (which is really just the inactive container for each messenger
3640
+				// showing inactive message types for that messenger)
3641
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3642
+				$mt_template_args[ $messenger . '_i_box' ] = [
3643
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3644
+					'inactive_message_types' => isset(
3645
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3646
+					)
3647
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3648
+						: '',
3649
+					'hidden'                 => $active ? '' : ' hidden',
3650
+					'hide_on_message'        => $hide_on_message,
3651
+					'hide_off_message'       => $hide_off_message,
3652
+					'messenger'              => $messenger,
3653
+					'active'                 => $active,
3654
+				];
3655
+			}
3656
+		}
3657
+
3658
+
3659
+		// register messenger metaboxes
3660
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3661
+		foreach ($m_boxes as $box => $label) {
3662
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3663
+			$msgr          = str_replace('_a_box', '', $box);
3664
+			$this->addMetaBox(
3665
+				'espresso_' . $msgr . '_settings',
3666
+				$label,
3667
+				function ($post, $metabox) {
3668
+					EEH_Template::display_template(
3669
+						$metabox['args']['template_path'],
3670
+						$metabox['args']['template_args']
3671
+					);
3672
+				},
3673
+				$this->_current_screen->id,
3674
+				'normal',
3675
+				'high',
3676
+				$callback_args
3677
+			);
3678
+		}
3679
+
3680
+		// register message type metaboxes
3681
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3682
+		foreach ($mt_boxes as $box => $label) {
3683
+			$callback_args = [
3684
+				'template_path' => $mt_template_path,
3685
+				'template_args' => $mt_template_args[ $box ],
3686
+			];
3687
+			$mt            = str_replace('_i_box', '', $box);
3688
+			$this->addMetaBox(
3689
+				'espresso_' . $mt . '_inactive_mts',
3690
+				$label,
3691
+				function ($post, $metabox) {
3692
+					EEH_Template::display_template(
3693
+						$metabox['args']['template_path'],
3694
+						$metabox['args']['template_args']
3695
+					);
3696
+				},
3697
+				$this->_current_screen->id,
3698
+				'side',
3699
+				'high',
3700
+				$callback_args
3701
+			);
3702
+		}
3703
+
3704
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3705
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3706
+		if (is_main_site()) {
3707
+			$this->addMetaBox(
3708
+				'espresso_global_message_settings',
3709
+				esc_html__('Global Message Settings', 'event_espresso'),
3710
+				[$this, 'global_messages_settings_metabox_content'],
3711
+				$this->_current_screen->id,
3712
+				'normal',
3713
+				'low',
3714
+				[]
3715
+			);
3716
+		}
3717
+	}
3718
+
3719
+
3720
+	/**
3721
+	 *  This generates the content for the global messages settings metabox.
3722
+	 *
3723
+	 * @return void
3724
+	 * @throws EE_Error
3725
+	 * @throws InvalidArgumentException
3726
+	 * @throws ReflectionException
3727
+	 * @throws InvalidDataTypeException
3728
+	 * @throws InvalidInterfaceException
3729
+	 */
3730
+	public function global_messages_settings_metabox_content()
3731
+	{
3732
+		$form = $this->_generate_global_settings_form();
3733
+		echo wp_kses(
3734
+			$form->form_open(
3735
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3736
+				'POST'
3737
+			),
3738
+			AllowedTags::getWithFormTags()
3739
+		);
3740
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3741
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3742
+	}
3743
+
3744
+
3745
+	/**
3746
+	 * This generates and returns the form object for the global messages settings.
3747
+	 *
3748
+	 * @return EE_Form_Section_Proper
3749
+	 * @throws EE_Error
3750
+	 * @throws InvalidArgumentException
3751
+	 * @throws ReflectionException
3752
+	 * @throws InvalidDataTypeException
3753
+	 * @throws InvalidInterfaceException
3754
+	 */
3755
+	protected function _generate_global_settings_form()
3756
+	{
3757
+		/** @var EE_Network_Core_Config $network_config */
3758
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3759
+
3760
+		return new EE_Form_Section_Proper(
3761
+			[
3762
+				'name'            => 'global_messages_settings',
3763
+				'html_id'         => 'global_messages_settings',
3764
+				'html_class'      => 'form-table',
3765
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3766
+				'subsections'     => apply_filters(
3767
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3768
+					[
3769
+						'do_messages_on_same_request' => new EE_Select_Input(
3770
+							[
3771
+								true  => esc_html__('On the same request', 'event_espresso'),
3772
+								false => esc_html__('On a separate request', 'event_espresso'),
3773
+							],
3774
+							[
3775
+								'default'         => $network_config->do_messages_on_same_request,
3776
+								'html_label_text' => esc_html__(
3777
+									'Generate and send all messages:',
3778
+									'event_espresso'
3779
+								),
3780
+								'html_help_text'  => esc_html__(
3781
+									'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.',
3782
+									'event_espresso'
3783
+								),
3784
+							]
3785
+						),
3786
+						'delete_threshold'            => new EE_Select_Input(
3787
+							[
3788
+								0  => esc_html__('Forever', 'event_espresso'),
3789
+								3  => esc_html__('3 Months', 'event_espresso'),
3790
+								6  => esc_html__('6 Months', 'event_espresso'),
3791
+								9  => esc_html__('9 Months', 'event_espresso'),
3792
+								12 => esc_html__('12 Months', 'event_espresso'),
3793
+								24 => esc_html__('24 Months', 'event_espresso'),
3794
+								36 => esc_html__('36 Months', 'event_espresso'),
3795
+							],
3796
+							[
3797
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3798
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3799
+								'html_help_text'  => esc_html__(
3800
+									'You can control how long a record of processed messages is kept via this option.',
3801
+									'event_espresso'
3802
+								),
3803
+							]
3804
+						),
3805
+						'update_settings'             => new EE_Submit_Input(
3806
+							[
3807
+								'default'         => esc_html__('Update', 'event_espresso'),
3808
+								'html_label_text' => '',
3809
+							]
3810
+						),
3811
+					]
3812
+				),
3813
+			]
3814
+		);
3815
+	}
3816
+
3817
+
3818
+	/**
3819
+	 * This handles updating the global settings set on the admin page.
3820
+	 *
3821
+	 * @throws EE_Error
3822
+	 * @throws InvalidDataTypeException
3823
+	 * @throws InvalidInterfaceException
3824
+	 * @throws InvalidArgumentException
3825
+	 * @throws ReflectionException
3826
+	 */
3827
+	protected function _update_global_settings()
3828
+	{
3829
+		/** @var EE_Network_Core_Config $network_config */
3830
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3831
+		$messages_config = EE_Registry::instance()->CFG->messages;
3832
+		$form            = $this->_generate_global_settings_form();
3833
+		if ($form->was_submitted()) {
3834
+			$form->receive_form_submission();
3835
+			if ($form->is_valid()) {
3836
+				$valid_data = $form->valid_data();
3837
+				foreach ($valid_data as $property => $value) {
3838
+					$setter = 'set_' . $property;
3839
+					if (method_exists($network_config, $setter)) {
3840
+						$network_config->{$setter}($value);
3841
+					} elseif (
3842
+						property_exists($network_config, $property)
3843
+						&& $network_config->{$property} !== $value
3844
+					) {
3845
+						$network_config->{$property} = $value;
3846
+					} elseif (
3847
+						property_exists($messages_config, $property)
3848
+						&& $messages_config->{$property} !== $value
3849
+					) {
3850
+						$messages_config->{$property} = $value;
3851
+					}
3852
+				}
3853
+				// only update if the form submission was valid!
3854
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3855
+				EE_Registry::instance()->CFG->update_espresso_config();
3856
+				EE_Error::overwrite_success();
3857
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3858
+			}
3859
+		}
3860
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3861
+	}
3862
+
3863
+
3864
+	/**
3865
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3866
+	 *
3867
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3868
+	 * @return string html formatted tabs
3869
+	 * @throws DomainException
3870
+	 */
3871
+	protected function _get_mt_tabs($tab_array)
3872
+	{
3873
+		$tab_array = (array) $tab_array;
3874
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3875
+		$tabs      = '';
3876
+
3877
+		foreach ($tab_array as $tab) {
3878
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3879
+		}
3880
+
3881
+		return $tabs;
3882
+	}
3883
+
3884
+
3885
+	/**
3886
+	 * This prepares the content of the messenger meta box admin settings
3887
+	 *
3888
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3889
+	 * @return string html formatted content
3890
+	 * @throws DomainException
3891
+	 */
3892
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3893
+	{
3894
+
3895
+		$fields = $messenger->get_admin_settings_fields();
3896
+
3897
+		$settings_template_args['template_form_fields'] = '';
3898
+		// is $messenger active?
3899
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3900
+
3901
+
3902
+		if (! empty($fields)) {
3903
+			$existing_settings = $messenger->get_existing_admin_settings();
3904
+
3905
+			foreach ($fields as $field_name => $field_props) {
3906
+				$field_id                         = $messenger->name . '-' . $field_name;
3907
+				$template_form_field[ $field_id ] = [
3908
+					'name'       => 'messenger_settings[' . $field_id . ']',
3909
+					'label'      => $field_props['label'],
3910
+					'input'      => $field_props['field_type'],
3911
+					'type'       => $field_props['value_type'],
3912
+					'required'   => $field_props['required'],
3913
+					'validation' => $field_props['validation'],
3914
+					'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3915
+					'css_class'  => '',
3916
+					'format'     => $field_props['format'],
3917
+				];
3918
+			}
3919
+
3920
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3921
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3922
+				: '';
3923
+		}
3924
+
3925
+		// we also need some hidden fields
3926
+		$settings_template_args['hidden_fields'] = [
3927
+			'messenger_settings[messenger]' . $messenger->name => [
3928
+				'type'  => 'hidden',
3929
+				'value' => $messenger->name,
3930
+			],
3931
+			'type' . $messenger->name                          => [
3932
+				'type'  => 'hidden',
3933
+				'value' => 'messenger',
3934
+			],
3935
+		];
3936
+
3937
+		// make sure any active message types that are existing are included in the hidden fields
3938
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3939
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3940
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3941
+					'type'  => 'hidden',
3942
+					'value' => $mt,
3943
+				];
3944
+			}
3945
+		}
3946
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3947
+			$settings_template_args['hidden_fields'],
3948
+			'array'
3949
+		);
3950
+		$active                                  =
3951
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3952
+
3953
+		$settings_template_args['messenger']           = $messenger->name;
3954
+		$settings_template_args['description']         = $messenger->description;
3955
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3956
+
3957
+
3958
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3959
+			$messenger->name
3960
+		)
3961
+			? $settings_template_args['show_hide_edit_form']
3962
+			: ' hidden';
3963
+
3964
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3965
+			? ' hidden'
3966
+			: $settings_template_args['show_hide_edit_form'];
3967
+
3968
+
3969
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3970
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3971
+		$settings_template_args['on_off_status'] = $active;
3972
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3973
+		return EEH_Template::display_template(
3974
+			$template,
3975
+			$settings_template_args,
3976
+			true
3977
+		);
3978
+	}
3979
+
3980
+
3981
+	/**
3982
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3983
+	 *
3984
+	 * @throws DomainException
3985
+	 * @throws EE_Error
3986
+	 * @throws InvalidDataTypeException
3987
+	 * @throws InvalidInterfaceException
3988
+	 * @throws InvalidArgumentException
3989
+	 * @throws ReflectionException
3990
+	 */
3991
+	public function activate_messenger_toggle()
3992
+	{
3993
+		$success = true;
3994
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3995
+		// let's check that we have required data
3996
+
3997
+		if (! $this->_active_messenger_name) {
3998
+			EE_Error::add_error(
3999
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4000
+				__FILE__,
4001
+				__FUNCTION__,
4002
+				__LINE__
4003
+			);
4004
+			$success = false;
4005
+		}
4006
+
4007
+		// do a nonce check here since we're not arriving via a normal route
4008
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4009
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4010
+
4011
+		$this->_verify_nonce($nonce, $nonce_ref);
4012
+
4013
+
4014
+		$status = $this->request->getRequestParam('status');
4015
+		if (! $status) {
4016
+			EE_Error::add_error(
4017
+				esc_html__(
4018
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4019
+					'event_espresso'
4020
+				),
4021
+				__FILE__,
4022
+				__FUNCTION__,
4023
+				__LINE__
4024
+			);
4025
+			$success = false;
4026
+		}
4027
+
4028
+		// do check to verify we have a valid status.
4029
+		if ($status !== 'off' && $status !== 'on') {
4030
+			EE_Error::add_error(
4031
+				sprintf(
4032
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4033
+					$status
4034
+				),
4035
+				__FILE__,
4036
+				__FUNCTION__,
4037
+				__LINE__
4038
+			);
4039
+			$success = false;
4040
+		}
4041
+
4042
+		if ($success) {
4043
+			// made it here?  Stop dawdling then!!
4044
+			$success = $status === 'off'
4045
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4046
+				: $this->_activate_messenger($this->_active_messenger_name);
4047
+		}
4048
+
4049
+		$this->_template_args['success'] = $success;
4050
+
4051
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4052
+		$this->_return_json();
4053
+	}
4054
+
4055
+
4056
+	/**
4057
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4058
+	 *
4059
+	 * @throws DomainException
4060
+	 * @throws EE_Error
4061
+	 * @throws ReflectionException
4062
+	 * @throws InvalidDataTypeException
4063
+	 * @throws InvalidInterfaceException
4064
+	 * @throws InvalidArgumentException
4065
+	 */
4066
+	public function activate_mt_toggle()
4067
+	{
4068
+		$success = true;
4069
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4070
+
4071
+		// let's make sure we have the necessary data
4072
+		if (! $this->_active_message_type_name) {
4073
+			EE_Error::add_error(
4074
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4075
+				__FILE__,
4076
+				__FUNCTION__,
4077
+				__LINE__
4078
+			);
4079
+			$success = false;
4080
+		}
4081
+
4082
+		if (! $this->_active_messenger_name) {
4083
+			EE_Error::add_error(
4084
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4085
+				__FILE__,
4086
+				__FUNCTION__,
4087
+				__LINE__
4088
+			);
4089
+			$success = false;
4090
+		}
4091
+
4092
+		$status = $this->request->getRequestParam('status');
4093
+		if (! $status) {
4094
+			EE_Error::add_error(
4095
+				esc_html__(
4096
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4097
+					'event_espresso'
4098
+				),
4099
+				__FILE__,
4100
+				__FUNCTION__,
4101
+				__LINE__
4102
+			);
4103
+			$success = false;
4104
+		}
4105
+
4106
+
4107
+		// do check to verify we have a valid status.
4108
+		if ($status !== 'activate' && $status !== 'deactivate') {
4109
+			EE_Error::add_error(
4110
+				sprintf(
4111
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4112
+					$status
4113
+				),
4114
+				__FILE__,
4115
+				__FUNCTION__,
4116
+				__LINE__
4117
+			);
4118
+			$success = false;
4119
+		}
4120
+
4121
+
4122
+		// do a nonce check here since we're not arriving via a normal route
4123
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4124
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4125
+
4126
+		if ($success) {
4127
+			// made it here? um, what are you waiting for then?
4128
+			$success = $status === 'deactivate'
4129
+				? $this->_deactivate_message_type_for_messenger(
4130
+					$this->_active_messenger_name,
4131
+					$this->_active_message_type_name
4132
+				)
4133
+				: $this->_activate_message_type_for_messenger(
4134
+					$this->_active_messenger_name,
4135
+					$this->_active_message_type_name
4136
+				);
4137
+		}
4138
+
4139
+		$this->_template_args['success'] = $success;
4140
+		$this->_return_json();
4141
+	}
4142
+
4143
+
4144
+	/**
4145
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4146
+	 *
4147
+	 * @param string $messenger_name The name of the messenger being activated
4148
+	 * @return bool
4149
+	 * @throws DomainException
4150
+	 * @throws EE_Error
4151
+	 * @throws InvalidArgumentException
4152
+	 * @throws ReflectionException
4153
+	 * @throws InvalidDataTypeException
4154
+	 * @throws InvalidInterfaceException
4155
+	 */
4156
+	protected function _activate_messenger($messenger_name)
4157
+	{
4158
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4159
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4160
+			? $active_messenger->get_default_message_types()
4161
+			: [];
4162
+
4163
+		// ensure is active
4164
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4165
+
4166
+		// set response_data for reload
4167
+		foreach ($message_types_to_activate as $message_type_name) {
4168
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4169
+			if (
4170
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4171
+					$messenger_name,
4172
+					$message_type_name
4173
+				)
4174
+				&& $message_type instanceof EE_message_type
4175
+			) {
4176
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4177
+				if ($message_type->get_admin_settings_fields()) {
4178
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4179
+				}
4180
+			}
4181
+		}
4182
+
4183
+		// add success message for activating messenger
4184
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4185
+	}
4186
+
4187
+
4188
+	/**
4189
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4190
+	 *
4191
+	 * @param string $messenger_name The name of the messenger being activated
4192
+	 * @return bool
4193
+	 * @throws DomainException
4194
+	 * @throws EE_Error
4195
+	 * @throws InvalidArgumentException
4196
+	 * @throws ReflectionException
4197
+	 * @throws InvalidDataTypeException
4198
+	 * @throws InvalidInterfaceException
4199
+	 */
4200
+	protected function _deactivate_messenger($messenger_name)
4201
+	{
4202
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4203
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4204
+
4205
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4206
+	}
4207
+
4208
+
4209
+	/**
4210
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4211
+	 *
4212
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4213
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4214
+	 * @return bool
4215
+	 * @throws DomainException
4216
+	 * @throws EE_Error
4217
+	 * @throws InvalidArgumentException
4218
+	 * @throws ReflectionException
4219
+	 * @throws InvalidDataTypeException
4220
+	 * @throws InvalidInterfaceException
4221
+	 */
4222
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4223
+	{
4224
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4225
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4226
+
4227
+		// ensure is active
4228
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4229
+
4230
+		// set response for load
4231
+		if (
4232
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4233
+				$messenger_name,
4234
+				$message_type_name
4235
+			)
4236
+		) {
4237
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4238
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4239
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4240
+			}
4241
+		}
4242
+
4243
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4244
+			$active_messenger,
4245
+			$message_type_to_activate
4246
+		);
4247
+	}
4248
+
4249
+
4250
+	/**
4251
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4252
+	 *
4253
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4254
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4255
+	 * @return bool
4256
+	 * @throws DomainException
4257
+	 * @throws EE_Error
4258
+	 * @throws InvalidArgumentException
4259
+	 * @throws ReflectionException
4260
+	 * @throws InvalidDataTypeException
4261
+	 * @throws InvalidInterfaceException
4262
+	 */
4263
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4264
+	{
4265
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4266
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4267
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4268
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4269
+
4270
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4271
+			$active_messenger,
4272
+			$message_type_to_deactivate
4273
+		);
4274
+	}
4275
+
4276
+
4277
+	/**
4278
+	 * This just initializes the defaults for activating messenger and message type responses.
4279
+	 */
4280
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4281
+	{
4282
+		$this->_template_args['data']['active_mts'] = [];
4283
+		$this->_template_args['data']['mt_reload']  = [];
4284
+	}
4285
+
4286
+
4287
+	/**
4288
+	 * Setup appropriate response for activating a messenger and/or message types
4289
+	 *
4290
+	 * @param EE_messenger         $messenger
4291
+	 * @param EE_message_type|null $message_type
4292
+	 * @return bool
4293
+	 * @throws DomainException
4294
+	 * @throws EE_Error
4295
+	 * @throws InvalidArgumentException
4296
+	 * @throws ReflectionException
4297
+	 * @throws InvalidDataTypeException
4298
+	 * @throws InvalidInterfaceException
4299
+	 */
4300
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4301
+		$messenger,
4302
+		EE_Message_Type $message_type = null
4303
+	) {
4304
+		// if $messenger isn't a valid messenger object then get out.
4305
+		if (! $messenger instanceof EE_Messenger) {
4306
+			EE_Error::add_error(
4307
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4308
+				__FILE__,
4309
+				__FUNCTION__,
4310
+				__LINE__
4311
+			);
4312
+			return false;
4313
+		}
4314
+		// activated
4315
+		if ($this->_template_args['data']['active_mts']) {
4316
+			EE_Error::overwrite_success();
4317
+			// activated a message type with the messenger
4318
+			if ($message_type instanceof EE_message_type) {
4319
+				EE_Error::add_success(
4320
+					sprintf(
4321
+						esc_html__(
4322
+							'%s message type has been successfully activated with the %s messenger',
4323
+							'event_espresso'
4324
+						),
4325
+						ucwords($message_type->label['singular']),
4326
+						ucwords($messenger->label['singular'])
4327
+					)
4328
+				);
4329
+
4330
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4331
+				if ($message_type->name === 'invoice') {
4332
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4333
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4334
+					if ($pm instanceof EE_Payment_Method) {
4335
+						EE_Error::add_attention(
4336
+							esc_html__(
4337
+								'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.',
4338
+								'event_espresso'
4339
+							)
4340
+						);
4341
+					}
4342
+				}
4343
+				// just toggles the entire messenger
4344
+			} else {
4345
+				EE_Error::add_success(
4346
+					sprintf(
4347
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4348
+						ucwords($messenger->label['singular'])
4349
+					)
4350
+				);
4351
+			}
4352
+
4353
+			return true;
4354
+
4355
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4356
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4357
+			// in which case we just give a success message for the messenger being successfully activated.
4358
+		} else {
4359
+			if (! $messenger->get_default_message_types()) {
4360
+				// messenger doesn't have any default message types so still a success.
4361
+				EE_Error::add_success(
4362
+					sprintf(
4363
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4364
+						ucwords($messenger->label['singular'])
4365
+					)
4366
+				);
4367
+
4368
+				return true;
4369
+			} else {
4370
+				EE_Error::add_error(
4371
+					$message_type instanceof EE_message_type
4372
+					? sprintf(
4373
+						esc_html__(
4374
+							'%s message type was not successfully activated with the %s messenger',
4375
+							'event_espresso'
4376
+						),
4377
+						ucwords($message_type->label['singular']),
4378
+						ucwords($messenger->label['singular'])
4379
+					)
4380
+					: sprintf(
4381
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4382
+						ucwords($messenger->label['singular'])
4383
+					),
4384
+					__FILE__,
4385
+					__FUNCTION__,
4386
+					__LINE__
4387
+				);
4388
+
4389
+				return false;
4390
+			}
4391
+		}
4392
+	}
4393
+
4394
+
4395
+	/**
4396
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4397
+	 *
4398
+	 * @param EE_messenger         $messenger
4399
+	 * @param EE_message_type|null $message_type
4400
+	 * @return bool
4401
+	 * @throws DomainException
4402
+	 * @throws EE_Error
4403
+	 * @throws InvalidArgumentException
4404
+	 * @throws ReflectionException
4405
+	 * @throws InvalidDataTypeException
4406
+	 * @throws InvalidInterfaceException
4407
+	 */
4408
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4409
+		$messenger,
4410
+		EE_message_type $message_type = null
4411
+	) {
4412
+		EE_Error::overwrite_success();
4413
+
4414
+		// if $messenger isn't a valid messenger object then get out.
4415
+		if (! $messenger instanceof EE_Messenger) {
4416
+			EE_Error::add_error(
4417
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4418
+				__FILE__,
4419
+				__FUNCTION__,
4420
+				__LINE__
4421
+			);
4422
+
4423
+			return false;
4424
+		}
4425
+
4426
+		if ($message_type instanceof EE_message_type) {
4427
+			$message_type_name = $message_type->name;
4428
+			EE_Error::add_success(
4429
+				sprintf(
4430
+					esc_html__(
4431
+						'%s message type has been successfully deactivated for the %s messenger.',
4432
+						'event_espresso'
4433
+					),
4434
+					ucwords($message_type->label['singular']),
4435
+					ucwords($messenger->label['singular'])
4436
+				)
4437
+			);
4438
+		} else {
4439
+			$message_type_name = '';
4440
+			EE_Error::add_success(
4441
+				sprintf(
4442
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4443
+					ucwords($messenger->label['singular'])
4444
+				)
4445
+			);
4446
+		}
4447
+
4448
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4449
+		if (
4450
+			$messenger->name === 'html'
4451
+			&& (
4452
+				is_null($message_type)
4453
+				|| $message_type_name === 'invoice'
4454
+			)
4455
+		) {
4456
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4457
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4458
+			if ($count_updated > 0) {
4459
+				$msg = $message_type_name === 'invoice'
4460
+					? esc_html__(
4461
+						'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.',
4462
+						'event_espresso'
4463
+					)
4464
+					: esc_html__(
4465
+						'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.',
4466
+						'event_espresso'
4467
+					);
4468
+				EE_Error::add_attention($msg);
4469
+			}
4470
+		}
4471
+
4472
+		return true;
4473
+	}
4474
+
4475
+
4476
+	/**
4477
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4478
+	 *
4479
+	 * @throws DomainException
4480
+	 * @throws EE_Error
4481
+	 * @throws EE_Error
4482
+	 */
4483
+	public function update_mt_form()
4484
+	{
4485
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4486
+			EE_Error::add_error(
4487
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4488
+				__FILE__,
4489
+				__FUNCTION__,
4490
+				__LINE__
4491
+			);
4492
+			$this->_return_json();
4493
+		}
4494
+
4495
+		$message_types = $this->get_installed_message_types();
4496
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4497
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4498
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4499
+
4500
+		$this->_template_args['success'] = true;
4501
+		$this->_template_args['content'] = $content;
4502
+		$this->_return_json();
4503
+	}
4504
+
4505
+
4506
+	/**
4507
+	 * this handles saving the settings for a messenger or message type
4508
+	 *
4509
+	 * @throws EE_Error
4510
+	 * @throws EE_Error
4511
+	 */
4512
+	public function save_settings()
4513
+	{
4514
+		$type = $this->request->getRequestParam('type');
4515
+		if (! $type) {
4516
+			EE_Error::add_error(
4517
+				esc_html__(
4518
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4519
+					'event_espresso'
4520
+				),
4521
+				__FILE__,
4522
+				__FUNCTION__,
4523
+				__LINE__
4524
+			);
4525
+			$this->_template_args['error'] = true;
4526
+			$this->_return_json();
4527
+		}
4528
+
4529
+
4530
+		if ($type === 'messenger') {
4531
+			// this should be an array.
4532
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4533
+			$messenger = $settings['messenger'];
4534
+			// remove messenger and message_types from settings array
4535
+			unset($settings['messenger'], $settings['message_types']);
4536
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4537
+		} elseif ($type === 'message_type') {
4538
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4539
+			$messenger    = $settings['messenger'];
4540
+			$message_type = $settings['message_type'];
4541
+			// remove messenger and message_types from settings array
4542
+			unset($settings['messenger'], $settings['message_types']);
4543
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4544
+		}
4545
+
4546
+		// okay we should have the data all setup.  Now we just update!
4547
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4548
+
4549
+		if ($success) {
4550
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4551
+		} else {
4552
+			EE_Error::add_error(
4553
+				esc_html__('Settings did not get updated', 'event_espresso'),
4554
+				__FILE__,
4555
+				__FUNCTION__,
4556
+				__LINE__
4557
+			);
4558
+		}
4559
+
4560
+		$this->_template_args['success'] = $success;
4561
+		$this->_return_json();
4562
+	}
4563
+
4564
+
4565
+
4566
+
4567
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4568
+
4569
+
4570
+	/**
4571
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4572
+	 * However, this does not send immediately, it just queues for sending.
4573
+	 *
4574
+	 * @throws EE_Error
4575
+	 * @throws InvalidDataTypeException
4576
+	 * @throws InvalidInterfaceException
4577
+	 * @throws InvalidArgumentException
4578
+	 * @throws ReflectionException
4579
+	 * @since 4.9.0
4580
+	 */
4581
+	protected function _generate_now()
4582
+	{
4583
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4584
+		$this->_redirect_after_action(false, '', '', [], true);
4585
+	}
4586
+
4587
+
4588
+	/**
4589
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4590
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4591
+	 *
4592
+	 * @throws EE_Error
4593
+	 * @throws InvalidDataTypeException
4594
+	 * @throws InvalidInterfaceException
4595
+	 * @throws InvalidArgumentException
4596
+	 * @throws ReflectionException
4597
+	 * @since 4.9.0
4598
+	 */
4599
+	protected function _generate_and_send_now()
4600
+	{
4601
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4602
+		$this->_redirect_after_action(false, '', '', [], true);
4603
+	}
4604
+
4605
+
4606
+	/**
4607
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4608
+	 *
4609
+	 * @throws EE_Error
4610
+	 * @throws InvalidDataTypeException
4611
+	 * @throws InvalidInterfaceException
4612
+	 * @throws InvalidArgumentException
4613
+	 * @throws ReflectionException
4614
+	 * @since 4.9.0
4615
+	 */
4616
+	protected function _queue_for_resending()
4617
+	{
4618
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4619
+		$this->_redirect_after_action(false, '', '', [], true);
4620
+	}
4621
+
4622
+
4623
+	/**
4624
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4625
+	 *
4626
+	 * @throws EE_Error
4627
+	 * @throws InvalidDataTypeException
4628
+	 * @throws InvalidInterfaceException
4629
+	 * @throws InvalidArgumentException
4630
+	 * @throws ReflectionException
4631
+	 * @since 4.9.0
4632
+	 */
4633
+	protected function _send_now()
4634
+	{
4635
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4636
+		$this->_redirect_after_action(false, '', '', [], true);
4637
+	}
4638
+
4639
+
4640
+	/**
4641
+	 * Deletes EE_messages for IDs in the request.
4642
+	 *
4643
+	 * @throws EE_Error
4644
+	 * @throws InvalidDataTypeException
4645
+	 * @throws InvalidInterfaceException
4646
+	 * @throws InvalidArgumentException
4647
+	 * @since 4.9.0
4648
+	 */
4649
+	protected function _delete_ee_messages()
4650
+	{
4651
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4652
+		$deleted_count = 0;
4653
+		foreach ($MSG_IDs as $MSG_ID) {
4654
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4655
+				$deleted_count++;
4656
+			}
4657
+		}
4658
+		if ($deleted_count) {
4659
+			EE_Error::add_success(
4660
+				esc_html(
4661
+					_n(
4662
+						'Message successfully deleted',
4663
+						'Messages successfully deleted',
4664
+						$deleted_count,
4665
+						'event_espresso'
4666
+					)
4667
+				)
4668
+			);
4669
+		} else {
4670
+			EE_Error::add_error(
4671
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4672
+				__FILE__,
4673
+				__FUNCTION__,
4674
+				__LINE__
4675
+			);
4676
+		}
4677
+		$this->_redirect_after_action(false, '', '', [], true);
4678
+	}
4679
+
4680
+
4681
+	/**
4682
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4683
+	 *
4684
+	 * @return array
4685
+	 * @since 4.9.0
4686
+	 */
4687
+	protected function _get_msg_ids_from_request()
4688
+	{
4689
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4690
+		if (empty($MSG_IDs)) {
4691
+			return [];
4692
+		}
4693
+		// if 'MSG_ID' was just a single ID (not an array)
4694
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4695
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4696
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4697
+			? $MSG_IDs
4698
+			: array_keys($MSG_IDs);
4699
+	}
4700 4700
 }
Please login to merge, or discard this patch.
Spacing   +221 added lines, -221 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',
@@ -776,53 +776,53 @@  discard block
 block discarded – undo
776 776
 
777 777
     public function messages_help_tab()
778 778
     {
779
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
779
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
780 780
     }
781 781
 
782 782
 
783 783
     public function messengers_help_tab()
784 784
     {
785
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
785
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
786 786
     }
787 787
 
788 788
 
789 789
     public function message_types_help_tab()
790 790
     {
791
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
791
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
792 792
     }
793 793
 
794 794
 
795 795
     public function messages_overview_help_tab()
796 796
     {
797
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
797
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
798 798
     }
799 799
 
800 800
 
801 801
     public function message_templates_help_tab()
802 802
     {
803
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
803
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
804 804
     }
805 805
 
806 806
 
807 807
     public function edit_message_template_help_tab()
808 808
     {
809
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
809
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
810 810
                         . esc_attr__('Editor Title', 'event_espresso')
811 811
                         . '" />';
812
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
812
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
813 813
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
814 814
                         . '" />';
815
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
815
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
816 816
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
817 817
                         . '" />';
818
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
818
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
819 819
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
820 820
                         . '" />';
821
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
821
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
822 822
                         . esc_attr__('Publish Metabox', 'event_espresso')
823 823
                         . '" />';
824 824
         EEH_Template::display_template(
825
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
825
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
826 826
             $args
827 827
         );
828 828
     }
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
         $this->_set_shortcodes();
838 838
         $args['shortcodes'] = $this->_shortcodes;
839 839
         EEH_Template::display_template(
840
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
840
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
841 841
             $args
842 842
         );
843 843
     }
@@ -845,16 +845,16 @@  discard block
 block discarded – undo
845 845
 
846 846
     public function preview_message_help_tab()
847 847
     {
848
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
848
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
849 849
     }
850 850
 
851 851
 
852 852
     public function settings_help_tab()
853 853
     {
854
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
855
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
856
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
857
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
854
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
855
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
856
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
857
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
858 858
         $args['img3'] = '<div class="ee-switch">'
859 859
                         . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'
860 860
                         . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'
@@ -863,25 +863,25 @@  discard block
 block discarded – undo
863 863
                         . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'
864 864
                         . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'
865 865
                         . '</div>';
866
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
866
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
867 867
     }
868 868
 
869 869
 
870 870
     public function load_scripts_styles()
871 871
     {
872
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
872
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
873 873
         wp_enqueue_style('espresso_ee_msg');
874 874
 
875 875
         wp_register_script(
876 876
             'ee-messages-settings',
877
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
877
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
878 878
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
879 879
             EVENT_ESPRESSO_VERSION,
880 880
             true
881 881
         );
882 882
         wp_register_script(
883 883
             'ee-msg-list-table-js',
884
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
884
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
885 885
             ['ee-dialog'],
886 886
             EVENT_ESPRESSO_VERSION
887 887
         );
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 
925 925
         $this->_set_shortcodes();
926 926
 
927
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
927
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
928 928
             esc_html__(
929 929
                 '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.',
930 930
                 'event_espresso'
@@ -936,14 +936,14 @@  discard block
 block discarded – undo
936 936
             '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?',
937 937
             'event_espresso'
938 938
         );
939
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
939
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
940 940
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
941 941
             'event_espresso'
942 942
         );
943 943
 
944 944
         wp_register_script(
945 945
             'ee_msgs_edit_js',
946
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
946
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
947 947
             ['jquery'],
948 948
             EVENT_ESPRESSO_VERSION
949 949
         );
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
     {
987 987
         wp_register_style(
988 988
             'ee-message-settings',
989
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
989
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
990 990
             [],
991 991
             EVENT_ESPRESSO_VERSION
992 992
         );
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
             }
1073 1073
             $status_bulk_actions = $common_bulk_actions;
1074 1074
             // unset bulk actions not applying to status
1075
-            if (! empty($status_bulk_actions)) {
1075
+            if ( ! empty($status_bulk_actions)) {
1076 1076
                 switch ($status) {
1077 1077
                     case EEM_Message::status_idle:
1078 1078
                     case EEM_Message::status_resend:
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
                 continue;
1102 1102
             }
1103 1103
 
1104
-            $this->_views[ strtolower($status) ] = [
1104
+            $this->_views[strtolower($status)] = [
1105 1105
                 'slug'        => strtolower($status),
1106 1106
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1107 1107
                 'count'       => 0,
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
             if ($action_item === 'see_notifications_for') {
1150 1150
                 continue;
1151 1151
             }
1152
-            $action_items[ $action_item ] = [
1152
+            $action_items[$action_item] = [
1153 1153
                 'class' => $action_details['css_class'],
1154 1154
                 'desc'  => $action_details['label'],
1155 1155
             ];
@@ -1158,37 +1158,37 @@  discard block
 block discarded – undo
1158 1158
         /** @var array $status_items status legend setup */
1159 1159
         $status_items = [
1160 1160
             'sent_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,
1161
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_sent,
1162 1162
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1163 1163
             ],
1164 1164
             'idle_status'                => [
1165
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,
1165
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_idle,
1166 1166
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1167 1167
             ],
1168 1168
             'failed_status'              => [
1169
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,
1169
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_failed,
1170 1170
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1171 1171
             ],
1172 1172
             'messenger_executing_status' => [
1173
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,
1173
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_messenger_executing,
1174 1174
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1175 1175
             ],
1176 1176
             'resend_status'              => [
1177
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,
1177
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_resend,
1178 1178
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1179 1179
             ],
1180 1180
             'incomplete_status'          => [
1181
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,
1181
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_incomplete,
1182 1182
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1183 1183
             ],
1184 1184
             'retry_status'               => [
1185
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,
1185
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_retry,
1186 1186
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1187 1187
             ],
1188 1188
         ];
1189 1189
         if (EEM_Message::debug()) {
1190 1190
             $status_items['debug_only_status'] = [
1191
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,
1191
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_debug_only,
1192 1192
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1193 1193
             ];
1194 1194
         }
@@ -1203,11 +1203,11 @@  discard block
 block discarded – undo
1203 1203
     protected function _custom_mtps_preview()
1204 1204
     {
1205 1205
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1206
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1207
-                                                . ' alt="' . esc_attr__(
1206
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1207
+                                                . ' alt="'.esc_attr__(
1208 1208
                                                     'Preview Custom Message Templates screenshot',
1209 1209
                                                     'event_espresso'
1210
-                                                ) . '" />';
1210
+                                                ).'" />';
1211 1211
         $this->_template_args['preview_text'] = '<strong>'
1212 1212
                                                 . esc_html__(
1213 1213
                                                     '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.',
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
         $installed               = [];
1284 1284
 
1285 1285
         foreach ($installed_message_types as $message_type) {
1286
-            $installed[ $message_type->name ] = $message_type;
1286
+            $installed[$message_type->name] = $message_type;
1287 1287
         }
1288 1288
 
1289 1289
         return $installed;
@@ -1409,7 +1409,7 @@  discard block
 block discarded – undo
1409 1409
         // we need to assemble the title from Various details
1410 1410
         $context_label = sprintf(
1411 1411
             esc_html__('(%s %s)', 'event_espresso'),
1412
-            $c_config[ $context ]['label'],
1412
+            $c_config[$context]['label'],
1413 1413
             ucwords($c_label['label'])
1414 1414
         );
1415 1415
 
@@ -1431,7 +1431,7 @@  discard block
 block discarded – undo
1431 1431
             $message_template_group->message_type()
1432 1432
         );
1433 1433
 
1434
-        if (! $template_field_structure) {
1434
+        if ( ! $template_field_structure) {
1435 1435
             $template_field_structure = false;
1436 1436
             $template_fields          = esc_html__(
1437 1437
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1445,21 +1445,21 @@  discard block
 block discarded – undo
1445 1445
 
1446 1446
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1447 1447
         // will get handled in the "extra" array.
1448
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1449
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1450
-                unset($template_field_structure[ $context ][ $reference_field ]);
1448
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1449
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1450
+                unset($template_field_structure[$context][$reference_field]);
1451 1451
             }
1452 1452
         }
1453 1453
 
1454 1454
         // let's loop through the template_field_structure and actually assemble the input fields!
1455
-        if (! empty($template_field_structure)) {
1456
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1455
+        if ( ! empty($template_field_structure)) {
1456
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1457 1457
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1458 1458
                 // the extra array and reset them.
1459 1459
                 if ($template_field === 'extra') {
1460 1460
                     $this->_template_args['is_extra_fields'] = true;
1461 1461
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1462
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1462
+                        $message_template = $message_templates[$context][$reference_field];
1463 1463
                         $content          = $message_template instanceof EE_Message_Template
1464 1464
                             ? $message_template->get('MTP_content')
1465 1465
                             : '';
@@ -1468,7 +1468,7 @@  discard block
 block discarded – undo
1468 1468
                             $continue = false;
1469 1469
                             if (isset($extra_array['shortcodes_required'])) {
1470 1470
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1471
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1471
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1472 1472
                                         $continue = true;
1473 1473
                                     }
1474 1474
                                 }
@@ -1477,53 +1477,53 @@  discard block
 block discarded – undo
1477 1477
                                 }
1478 1478
                             }
1479 1479
 
1480
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1480
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1481 1481
 
1482
-                            $template_form_fields[ $field_id ]         = $extra_array;
1483
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1482
+                            $template_form_fields[$field_id]         = $extra_array;
1483
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1484 1484
                                                                          . $reference_field
1485 1485
                                                                          . '][content]['
1486
-                                                                         . $extra_field . ']';
1487
-                            $css_class                                 = isset($extra_array['css_class'])
1486
+                                                                         . $extra_field.']';
1487
+                            $css_class = isset($extra_array['css_class'])
1488 1488
                                 ? $extra_array['css_class']
1489 1489
                                 : '';
1490 1490
 
1491
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1491
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1492 1492
                                                                               && in_array($extra_field, $v_fields, true)
1493 1493
                                                                               && (
1494
-                                                                                  is_array($validators[ $extra_field ])
1495
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1494
+                                                                                  is_array($validators[$extra_field])
1495
+                                                                                  && isset($validators[$extra_field]['msg'])
1496 1496
                                                                               )
1497
-                                ? 'validate-error ' . $css_class
1497
+                                ? 'validate-error '.$css_class
1498 1498
                                 : $css_class;
1499 1499
 
1500
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1501
-                                                                          && isset($content[ $extra_field ])
1502
-                                ? $content[ $extra_field ]
1500
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1501
+                                                                          && isset($content[$extra_field])
1502
+                                ? $content[$extra_field]
1503 1503
                                 : '';
1504 1504
 
1505 1505
                             // do we have a validation error?  if we do then let's use that value instead
1506
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1507
-                                ? $validators[ $extra_field ]['value']
1508
-                                : $template_form_fields[ $field_id ]['value'];
1506
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1507
+                                ? $validators[$extra_field]['value']
1508
+                                : $template_form_fields[$field_id]['value'];
1509 1509
 
1510 1510
 
1511
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1511
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1512 1512
 
1513 1513
                             // shortcode selector
1514 1514
                             $field_name_to_use                                   = $extra_field === 'main'
1515 1515
                                 ? 'content'
1516 1516
                                 : $extra_field;
1517
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1517
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1518 1518
                                 $field_name_to_use,
1519 1519
                                 $field_id
1520 1520
                             );
1521 1521
                         }
1522
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1523
-                        $template_field_template_name_id = $reference_field . '-name';
1522
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1523
+                        $template_field_template_name_id = $reference_field.'-name';
1524 1524
 
1525
-                        $template_form_fields[ $template_field_MTP_id ] = [
1526
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1525
+                        $template_form_fields[$template_field_MTP_id] = [
1526
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1527 1527
                             'label'      => null,
1528 1528
                             'input'      => 'hidden',
1529 1529
                             'type'       => 'int',
@@ -1535,8 +1535,8 @@  discard block
 block discarded – undo
1535 1535
                             'db-col'     => 'MTP_ID',
1536 1536
                         ];
1537 1537
 
1538
-                        $template_form_fields[ $template_field_template_name_id ] = [
1539
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1538
+                        $template_form_fields[$template_field_template_name_id] = [
1539
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1540 1540
                             'label'      => null,
1541 1541
                             'input'      => 'hidden',
1542 1542
                             'type'       => 'string',
@@ -1550,38 +1550,38 @@  discard block
 block discarded – undo
1550 1550
                     }
1551 1551
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1552 1552
                 } else {
1553
-                    $field_id                                   = $template_field . '-content';
1554
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1555
-                    $template_form_fields[ $field_id ]['name']  =
1556
-                        'MTP_template_fields[' . $template_field . '][content]';
1553
+                    $field_id                                   = $template_field.'-content';
1554
+                    $template_form_fields[$field_id]          = $field_setup_array;
1555
+                    $template_form_fields[$field_id]['name']  =
1556
+                        'MTP_template_fields['.$template_field.'][content]';
1557 1557
                     $message_template                           =
1558
-                        isset($message_templates[ $context ][ $template_field ])
1559
-                            ? $message_templates[ $context ][ $template_field ]
1558
+                        isset($message_templates[$context][$template_field])
1559
+                            ? $message_templates[$context][$template_field]
1560 1560
                             : null;
1561
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1562
-                                                                  && is_array($message_templates[ $context ])
1561
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1562
+                                                                  && is_array($message_templates[$context])
1563 1563
                                                                   && $message_template instanceof EE_Message_Template
1564 1564
                         ? $message_template->get('MTP_content')
1565 1565
                         : '';
1566 1566
 
1567 1567
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1568
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1569
-                        ? $validators[ $template_field ]['value']
1570
-                        : $template_form_fields[ $field_id ]['value'];
1568
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1569
+                        ? $validators[$template_field]['value']
1570
+                        : $template_form_fields[$field_id]['value'];
1571 1571
 
1572 1572
 
1573
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1573
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1574 1574
                     $css_class                                      = isset($field_setup_array['css_class'])
1575 1575
                         ? $field_setup_array['css_class']
1576 1576
                         : '';
1577
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1577
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1578 1578
                                                                       && in_array($template_field, $v_fields, true)
1579
-                                                                      && isset($validators[ $template_field ]['msg'])
1580
-                        ? 'validate-error ' . $css_class
1579
+                                                                      && isset($validators[$template_field]['msg'])
1580
+                        ? 'validate-error '.$css_class
1581 1581
                         : $css_class;
1582 1582
 
1583 1583
                     // shortcode selector
1584
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1584
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1585 1585
                         $template_field,
1586 1586
                         $field_id
1587 1587
                     );
@@ -1589,12 +1589,12 @@  discard block
 block discarded – undo
1589 1589
 
1590 1590
                 // k took care of content field(s) now let's take care of others.
1591 1591
 
1592
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1593
-                $template_field_field_template_name_id = $template_field . '-name';
1592
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1593
+                $template_field_field_template_name_id = $template_field.'-name';
1594 1594
 
1595 1595
                 // foreach template field there are actually two form fields created
1596
-                $template_form_fields[ $template_field_MTP_id ] = [
1597
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1596
+                $template_form_fields[$template_field_MTP_id] = [
1597
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1598 1598
                     'label'      => null,
1599 1599
                     'input'      => 'hidden',
1600 1600
                     'type'       => 'int',
@@ -1606,8 +1606,8 @@  discard block
 block discarded – undo
1606 1606
                     'db-col'     => 'MTP_ID',
1607 1607
                 ];
1608 1608
 
1609
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1610
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1609
+                $template_form_fields[$template_field_field_template_name_id] = [
1610
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1611 1611
                     'label'      => null,
1612 1612
                     'input'      => 'hidden',
1613 1613
                     'type'       => 'string',
@@ -1724,7 +1724,7 @@  discard block
 block discarded – undo
1724 1724
                 'format'     => '%d',
1725 1725
                 'db-col'     => 'MTP_deleted',
1726 1726
             ];
1727
-            $sidebar_form_fields['ee-msg-author']  = [
1727
+            $sidebar_form_fields['ee-msg-author'] = [
1728 1728
                 'name'       => 'MTP_user_id',
1729 1729
                 'label'      => esc_html__('Author', 'event_espresso'),
1730 1730
                 'input'      => 'hidden',
@@ -1743,17 +1743,17 @@  discard block
 block discarded – undo
1743 1743
                 'value' => $action,
1744 1744
             ];
1745 1745
 
1746
-            $sidebar_form_fields['ee-msg-id']        = [
1746
+            $sidebar_form_fields['ee-msg-id'] = [
1747 1747
                 'name'  => 'id',
1748 1748
                 'input' => 'hidden',
1749 1749
                 'type'  => 'int',
1750 1750
                 'value' => $GRP_ID,
1751 1751
             ];
1752 1752
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1753
-                'name'  => $action . '_nonce',
1753
+                'name'  => $action.'_nonce',
1754 1754
                 'input' => 'hidden',
1755 1755
                 'type'  => 'string',
1756
-                'value' => wp_create_nonce($action . '_nonce'),
1756
+                'value' => wp_create_nonce($action.'_nonce'),
1757 1757
             ];
1758 1758
 
1759 1759
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1784,7 +1784,7 @@  discard block
 block discarded – undo
1784 1784
         );
1785 1785
 
1786 1786
         // add preview button
1787
-        $preview_url    = parent::add_query_args_and_nonce(
1787
+        $preview_url = parent::add_query_args_and_nonce(
1788 1788
             [
1789 1789
                 'message_type' => $message_template_group->message_type(),
1790 1790
                 'messenger'    => $message_template_group->messenger(),
@@ -1795,7 +1795,7 @@  discard block
 block discarded – undo
1795 1795
             ],
1796 1796
             $this->_admin_base_url
1797 1797
         );
1798
-        $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'
1798
+        $preview_button = '<a href="'.$preview_url.'" class="button--secondary messages-preview-button">'
1799 1799
                           . esc_html__('Preview', 'event_espresso')
1800 1800
                           . '</a>';
1801 1801
 
@@ -1833,11 +1833,11 @@  discard block
 block discarded – undo
1833 1833
         $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();
1834 1834
         $this->_template_args['before_admin_page_content'] .= '</div>';
1835 1835
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1836
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1836
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1837 1837
 
1838 1838
         $this->_template_path = $this->_template_args['GRP_ID']
1839 1839
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1840
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1840
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1841 1841
 
1842 1842
         // send along EE_Message_Template_Group object for further template use.
1843 1843
         $this->_template_args['MTP'] = $message_template_group;
@@ -1893,7 +1893,7 @@  discard block
 block discarded – undo
1893 1893
     ) {
1894 1894
         $template_args = [
1895 1895
             'context'                   => $context,
1896
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1896
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1897 1897
             'is_active'                 => $message_template_group->is_context_active($context),
1898 1898
             'on_off_action'             => $message_template_group->is_context_active($context)
1899 1899
                 ? 'context-off'
@@ -1902,7 +1902,7 @@  discard block
 block discarded – undo
1902 1902
             'message_template_group_id' => $message_template_group->ID(),
1903 1903
         ];
1904 1904
         return EEH_Template::display_template(
1905
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1905
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1906 1906
             $template_args,
1907 1907
             true
1908 1908
         );
@@ -1959,7 +1959,7 @@  discard block
 block discarded – undo
1959 1959
         }
1960 1960
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1961 1961
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1962
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1962
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1963 1963
             EE_Error::add_error(
1964 1964
                 sprintf(
1965 1965
                     esc_html__(
@@ -2090,7 +2090,7 @@  discard block
 block discarded – undo
2090 2090
         $messenger    = $this->request->getRequestParam('msgr');
2091 2091
         $message_type = $this->request->getRequestParam('mt');
2092 2092
         // we need to make sure we've got the info we need.
2093
-        if (! ($GRP_ID && $messenger && $message_type)) {
2093
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2094 2094
             EE_Error::add_error(
2095 2095
                 esc_html__(
2096 2096
                     '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.',
@@ -2127,7 +2127,7 @@  discard block
 block discarded – undo
2127 2127
         }
2128 2128
 
2129 2129
         // any error messages?
2130
-        if (! $success) {
2130
+        if ( ! $success) {
2131 2131
             EE_Error::add_error(
2132 2132
                 esc_html__(
2133 2133
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
     {
2177 2177
         // first make sure we've got the necessary parameters
2178 2178
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2179
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2179
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2180 2180
             EE_Error::add_error(
2181 2181
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2182 2182
                 __FILE__,
@@ -2202,7 +2202,7 @@  discard block
 block discarded – undo
2202 2202
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2203 2203
 
2204 2204
         // let's add a button to go back to the edit view
2205
-        $query_args             = [
2205
+        $query_args = [
2206 2206
             'id'      => $GRP_ID,
2207 2207
             'evt_id'  => $EVT_ID,
2208 2208
             'context' => $context,
@@ -2223,7 +2223,7 @@  discard block
 block discarded – undo
2223 2223
         $preview_title = sprintf(
2224 2224
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2225 2225
             $active_messenger_label,
2226
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2226
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2227 2227
         );
2228 2228
         if (empty($preview)) {
2229 2229
             $this->noEventsErrorMessage();
@@ -2231,7 +2231,7 @@  discard block
 block discarded – undo
2231 2231
         // setup display of preview.
2232 2232
         $this->_admin_page_title                    = $preview_title;
2233 2233
         $this->_template_args['admin_page_title']   = $preview_title;
2234
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2234
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2235 2235
         $this->_template_args['data']['force_json'] = true;
2236 2236
 
2237 2237
         return '';
@@ -2252,7 +2252,7 @@  discard block
 block discarded – undo
2252 2252
             ],
2253 2253
             admin_url('admin.php')
2254 2254
         );
2255
-        $message    = $test_send
2255
+        $message = $test_send
2256 2256
             ? esc_html__(
2257 2257
                 '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!',
2258 2258
                 'event_espresso'
@@ -2345,10 +2345,10 @@  discard block
 block discarded – undo
2345 2345
             // only include template packs that support this messenger and message type!
2346 2346
             $supports = $tp->get_supports();
2347 2347
             if (
2348
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2348
+                ! isset($supports[$this->_message_template_group->messenger()])
2349 2349
                 || ! in_array(
2350 2350
                     $this->_message_template_group->message_type(),
2351
-                    $supports[ $this->_message_template_group->messenger() ],
2351
+                    $supports[$this->_message_template_group->messenger()],
2352 2352
                     true
2353 2353
                 )
2354 2354
             ) {
@@ -2372,7 +2372,7 @@  discard block
 block discarded – undo
2372 2372
         }
2373 2373
 
2374 2374
         // setup variation select values for the currently selected template.
2375
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2375
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2376 2376
             $this->_message_template_group->messenger(),
2377 2377
             $this->_message_template_group->message_type()
2378 2378
         );
@@ -2386,12 +2386,12 @@  discard block
 block discarded – undo
2386 2386
 
2387 2387
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2388 2388
 
2389
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2389
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2390 2390
             'MTP_template_pack',
2391 2391
             $tp_select_values,
2392 2392
             $this->_message_template_group->get_template_pack_name()
2393 2393
         );
2394
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2394
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2395 2395
             'MTP_template_variation',
2396 2396
             $variations_select_values,
2397 2397
             $this->_message_template_group->get_template_pack_variation()
@@ -2401,7 +2401,7 @@  discard block
 block discarded – undo
2401 2401
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2402 2402
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2403 2403
 
2404
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2404
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2405 2405
 
2406 2406
         EEH_Template::display_template($template, $template_args);
2407 2407
     }
@@ -2427,33 +2427,33 @@  discard block
 block discarded – undo
2427 2427
         // first we need to see if there are any fields
2428 2428
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2429 2429
 
2430
-        if (! empty($fields)) {
2430
+        if ( ! empty($fields)) {
2431 2431
             // yup there be fields
2432 2432
             foreach ($fields as $field => $config) {
2433
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2433
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2434 2434
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2435 2435
                 $default  = isset($config['default']) ? $config['default'] : '';
2436 2436
                 $default  = isset($config['value']) ? $config['value'] : $default;
2437 2437
 
2438 2438
                 // if type is hidden and the value is empty
2439 2439
                 // something may have gone wrong so let's correct with the defaults
2440
-                $fix                = $config['input'] === 'hidden'
2441
-                                      && isset($existing[ $field ])
2442
-                                      && empty($existing[ $field ])
2440
+                $fix = $config['input'] === 'hidden'
2441
+                                      && isset($existing[$field])
2442
+                                      && empty($existing[$field])
2443 2443
                     ? $default
2444 2444
                     : '';
2445
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2446
-                    ? $existing[ $field ]
2445
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2446
+                    ? $existing[$field]
2447 2447
                     : $fix;
2448 2448
 
2449
-                $template_form_fields[ $field_id ] = [
2450
-                    'name'       => 'test_settings_fld[' . $field . ']',
2449
+                $template_form_fields[$field_id] = [
2450
+                    'name'       => 'test_settings_fld['.$field.']',
2451 2451
                     'label'      => $config['label'],
2452 2452
                     'input'      => $config['input'],
2453 2453
                     'type'       => $config['type'],
2454 2454
                     'required'   => $config['required'],
2455 2455
                     'validation' => $config['validation'],
2456
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2456
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2457 2457
                     'css_class'  => $config['css_class'],
2458 2458
                     'options'    => isset($config['options']) ? $config['options'] : [],
2459 2459
                     'default'    => $default,
@@ -2467,7 +2467,7 @@  discard block
 block discarded – undo
2467 2467
             : '';
2468 2468
 
2469 2469
         // print out $test_settings_fields
2470
-        if (! empty($test_settings_html)) {
2470
+        if ( ! empty($test_settings_html)) {
2471 2471
             $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';
2472 2472
             $test_settings_html .= 'name="test_button" value="';
2473 2473
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2513,7 +2513,7 @@  discard block
 block discarded – undo
2513 2513
         ];
2514 2514
 
2515 2515
         return EEH_Template::display_template(
2516
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2516
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2517 2517
             $template_args,
2518 2518
             true
2519 2519
         );
@@ -2539,7 +2539,7 @@  discard block
 block discarded – undo
2539 2539
         // $messenger = $this->_message_template_group->messenger_obj();
2540 2540
         // now let's set the content depending on the status of the shortcodes array
2541 2541
         if (empty($shortcodes)) {
2542
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2542
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2543 2543
             return;
2544 2544
         }
2545 2545
         ?>
@@ -2575,7 +2575,7 @@  discard block
 block discarded – undo
2575 2575
     {
2576 2576
 
2577 2577
         // no need to run this if the property is already set
2578
-        if (! empty($this->_shortcodes)) {
2578
+        if ( ! empty($this->_shortcodes)) {
2579 2579
             return;
2580 2580
         }
2581 2581
 
@@ -2630,7 +2630,7 @@  discard block
 block discarded – undo
2630 2630
     protected function _set_message_template_group()
2631 2631
     {
2632 2632
         // get out if this is already set.
2633
-        if (! empty($this->_message_template_group)) {
2633
+        if ( ! empty($this->_message_template_group)) {
2634 2634
             return;
2635 2635
         }
2636 2636
 
@@ -2676,8 +2676,8 @@  discard block
 block discarded – undo
2676 2676
                     <?php
2677 2677
                 }
2678 2678
                 // setup nonce_url
2679
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2680
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2679
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2680
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2681 2681
                 ?>
2682 2682
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2683 2683
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2690,7 +2690,7 @@  discard block
 block discarded – undo
2690 2690
                             $checked = ($context === $args['context']) ? 'selected' : '';
2691 2691
                             ?>
2692 2692
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2693
-                                <?php echo esc_html($context_details[ $context ]['label']); ?>
2693
+                                <?php echo esc_html($context_details[$context]['label']); ?>
2694 2694
                             </option>
2695 2695
                         <?php endforeach;
2696 2696
                     endif; ?>
@@ -3081,7 +3081,7 @@  discard block
 block discarded – undo
3081 3081
     {
3082 3082
         if (is_array($content)) {
3083 3083
             foreach ($content as $key => $value) {
3084
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3084
+                $content[$key] = $this->sanitizeMessageTemplateContent($value);
3085 3085
             }
3086 3086
             return $content;
3087 3087
         }
@@ -3119,7 +3119,7 @@  discard block
 block discarded – undo
3119 3119
 
3120 3120
         $context   = ucwords(str_replace('_', ' ', $context));
3121 3121
         $item_desc = $messenger_label && $message_type_label
3122
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3122
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
3123 3123
             : '';
3124 3124
         $item_desc .= 'Message Template';
3125 3125
         return $item_desc;
@@ -3271,7 +3271,7 @@  discard block
 block discarded – undo
3271 3271
         if ($all) {
3272 3272
             // Checkboxes
3273 3273
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3274
-            if (! empty($checkboxes)) {
3274
+            if ( ! empty($checkboxes)) {
3275 3275
                 // if array has more than one element then success message should be plural.
3276 3276
                 // todo: what about nonce?
3277 3277
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3281,18 +3281,18 @@  discard block
 block discarded – undo
3281 3281
                     $trashed_or_restored = $trash
3282 3282
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3283 3283
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3284
-                    if (! $trashed_or_restored) {
3284
+                    if ( ! $trashed_or_restored) {
3285 3285
                         $success = 0;
3286 3286
                     }
3287 3287
                 }
3288 3288
             } else {
3289 3289
                 // grab single GRP_ID and handle
3290 3290
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3291
-                if (! empty($GRP_ID)) {
3291
+                if ( ! empty($GRP_ID)) {
3292 3292
                     $trashed_or_restored = $trash
3293 3293
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3294 3294
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3295
-                    if (! $trashed_or_restored) {
3295
+                    if ( ! $trashed_or_restored) {
3296 3296
                         $success = 0;
3297 3297
                     }
3298 3298
                 } else {
@@ -3340,7 +3340,7 @@  discard block
 block discarded – undo
3340 3340
 
3341 3341
         // checkboxes
3342 3342
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3343
-        if (! empty($checkboxes)) {
3343
+        if ( ! empty($checkboxes)) {
3344 3344
             // if array has more than one element then success message should be plural
3345 3345
             $success = count($checkboxes) > 1 ? 2 : 1;
3346 3346
 
@@ -3444,7 +3444,7 @@  discard block
 block discarded – undo
3444 3444
     protected function _set_m_mt_settings()
3445 3445
     {
3446 3446
         // first if this is already set then lets get out no need to regenerate data.
3447
-        if (! empty($this->_m_mt_settings)) {
3447
+        if ( ! empty($this->_m_mt_settings)) {
3448 3448
             return;
3449 3449
         }
3450 3450
 
@@ -3457,8 +3457,8 @@  discard block
 block discarded – undo
3457 3457
 
3458 3458
         foreach ($messengers as $messenger) {
3459 3459
             $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3460
-            $class = 'ee-messenger-' .  sanitize_key($messenger->label['singular']);
3461
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3460
+            $class = 'ee-messenger-'.sanitize_key($messenger->label['singular']);
3461
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3462 3462
                 'label' => ucwords($messenger->label['singular']),
3463 3463
                 'class' => $active ? "{$class} messenger-active" : $class,
3464 3464
                 'href'  => $messenger->name,
@@ -3476,7 +3476,7 @@  discard block
 block discarded – undo
3476 3476
             foreach ($message_types as $message_type) {
3477 3477
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3478 3478
                 // it shouldn't show in either the inactive OR active metabox.
3479
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3479
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3480 3480
                     continue;
3481 3481
                 }
3482 3482
 
@@ -3487,12 +3487,12 @@  discard block
 block discarded – undo
3487 3487
                     ? 'active'
3488 3488
                     : 'inactive';
3489 3489
 
3490
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3490
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3491 3491
                     'label'    => ucwords($message_type->label['singular']),
3492
-                    'class'    => 'message-type-' . $a_or_i,
3493
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3494
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3495
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3492
+                    'class'    => 'message-type-'.$a_or_i,
3493
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3494
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3495
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3496 3496
                     'title'    => $a_or_i === 'active'
3497 3497
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3498 3498
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3523,25 +3523,25 @@  discard block
 block discarded – undo
3523 3523
         $fields                                         = $message_type->get_admin_settings_fields();
3524 3524
         $settings_template_args['template_form_fields'] = '';
3525 3525
 
3526
-        if (! empty($fields) && $active) {
3526
+        if ( ! empty($fields) && $active) {
3527 3527
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3528 3528
             foreach ($fields as $fldname => $fldprops) {
3529
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3530
-                $template_form_field[ $field_id ] = [
3531
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3529
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3530
+                $template_form_field[$field_id] = [
3531
+                    'name'       => 'message_type_settings['.$fldname.']',
3532 3532
                     'label'      => $fldprops['label'],
3533 3533
                     'input'      => $fldprops['field_type'],
3534 3534
                     'type'       => $fldprops['value_type'],
3535 3535
                     'required'   => $fldprops['required'],
3536 3536
                     'validation' => $fldprops['validation'],
3537
-                    'value'      => isset($existing_settings[ $fldname ])
3538
-                        ? $existing_settings[ $fldname ]
3537
+                    'value'      => isset($existing_settings[$fldname])
3538
+                        ? $existing_settings[$fldname]
3539 3539
                         : $fldprops['default'],
3540 3540
                     'options'    => isset($fldprops['options'])
3541 3541
                         ? $fldprops['options']
3542 3542
                         : [],
3543
-                    'default'    => isset($existing_settings[ $fldname ])
3544
-                        ? $existing_settings[ $fldname ]
3543
+                    'default'    => isset($existing_settings[$fldname])
3544
+                        ? $existing_settings[$fldname]
3545 3545
                         : $fldprops['default'],
3546 3546
                     'css_class'  => 'no-drag',
3547 3547
                     'format'     => $fldprops['format'],
@@ -3561,15 +3561,15 @@  discard block
 block discarded – undo
3561 3561
         $settings_template_args['description'] = $message_type->description;
3562 3562
         // we also need some hidden fields
3563 3563
         $hidden_fields = [
3564
-            'message_type_settings[messenger]' . $message_type->name    => [
3564
+            'message_type_settings[messenger]'.$message_type->name    => [
3565 3565
                 'type'  => 'hidden',
3566 3566
                 'value' => $messenger->name,
3567 3567
             ],
3568
-            'message_type_settings[message_type]' . $message_type->name => [
3568
+            'message_type_settings[message_type]'.$message_type->name => [
3569 3569
                 'type'  => 'hidden',
3570 3570
                 'value' => $message_type->name,
3571 3571
             ],
3572
-            'type' . $message_type->name                                => [
3572
+            'type'.$message_type->name                                => [
3573 3573
                 'type'  => 'hidden',
3574 3574
                 'value' => 'message_type',
3575 3575
             ],
@@ -3579,12 +3579,12 @@  discard block
 block discarded – undo
3579 3579
             $hidden_fields,
3580 3580
             'array'
3581 3581
         );
3582
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3582
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3583 3583
             ? ' hidden'
3584 3584
             : '';
3585 3585
 
3586 3586
 
3587
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3587
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3588 3588
         return EEH_Template::display_template($template, $settings_template_args, true);
3589 3589
     }
3590 3590
 
@@ -3612,21 +3612,21 @@  discard block
 block discarded – undo
3612 3612
 
3613 3613
                 // messenger meta boxes
3614 3614
                 $active         = $selected_messenger === $messenger;
3615
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3616
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3615
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3616
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3617 3617
                     : '';
3618 3618
 
3619
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3619
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3620 3620
                     esc_html__('%s Settings', 'event_espresso'),
3621 3621
                     $tab_array['label']
3622 3622
                 );
3623 3623
 
3624
-                $m_template_args[ $messenger . '_a_box' ] = [
3624
+                $m_template_args[$messenger.'_a_box'] = [
3625 3625
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3626 3626
                     'inactive_message_types' => isset(
3627
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3627
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3628 3628
                     )
3629
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3629
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3630 3630
                         : '',
3631 3631
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3632 3632
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3638,13 +3638,13 @@  discard block
 block discarded – undo
3638 3638
                 // message type meta boxes
3639 3639
                 // (which is really just the inactive container for each messenger
3640 3640
                 // showing inactive message types for that messenger)
3641
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3642
-                $mt_template_args[ $messenger . '_i_box' ] = [
3641
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3642
+                $mt_template_args[$messenger.'_i_box'] = [
3643 3643
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3644 3644
                     'inactive_message_types' => isset(
3645
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3645
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3646 3646
                     )
3647
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3647
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3648 3648
                         : '',
3649 3649
                     'hidden'                 => $active ? '' : ' hidden',
3650 3650
                     'hide_on_message'        => $hide_on_message,
@@ -3657,14 +3657,14 @@  discard block
 block discarded – undo
3657 3657
 
3658 3658
 
3659 3659
         // register messenger metaboxes
3660
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3660
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3661 3661
         foreach ($m_boxes as $box => $label) {
3662
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3662
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3663 3663
             $msgr          = str_replace('_a_box', '', $box);
3664 3664
             $this->addMetaBox(
3665
-                'espresso_' . $msgr . '_settings',
3665
+                'espresso_'.$msgr.'_settings',
3666 3666
                 $label,
3667
-                function ($post, $metabox) {
3667
+                function($post, $metabox) {
3668 3668
                     EEH_Template::display_template(
3669 3669
                         $metabox['args']['template_path'],
3670 3670
                         $metabox['args']['template_args']
@@ -3678,17 +3678,17 @@  discard block
 block discarded – undo
3678 3678
         }
3679 3679
 
3680 3680
         // register message type metaboxes
3681
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3681
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3682 3682
         foreach ($mt_boxes as $box => $label) {
3683 3683
             $callback_args = [
3684 3684
                 'template_path' => $mt_template_path,
3685
-                'template_args' => $mt_template_args[ $box ],
3685
+                'template_args' => $mt_template_args[$box],
3686 3686
             ];
3687
-            $mt            = str_replace('_i_box', '', $box);
3687
+            $mt = str_replace('_i_box', '', $box);
3688 3688
             $this->addMetaBox(
3689
-                'espresso_' . $mt . '_inactive_mts',
3689
+                'espresso_'.$mt.'_inactive_mts',
3690 3690
                 $label,
3691
-                function ($post, $metabox) {
3691
+                function($post, $metabox) {
3692 3692
                     EEH_Template::display_template(
3693 3693
                         $metabox['args']['template_path'],
3694 3694
                         $metabox['args']['template_args']
@@ -3835,7 +3835,7 @@  discard block
 block discarded – undo
3835 3835
             if ($form->is_valid()) {
3836 3836
                 $valid_data = $form->valid_data();
3837 3837
                 foreach ($valid_data as $property => $value) {
3838
-                    $setter = 'set_' . $property;
3838
+                    $setter = 'set_'.$property;
3839 3839
                     if (method_exists($network_config, $setter)) {
3840 3840
                         $network_config->{$setter}($value);
3841 3841
                     } elseif (
@@ -3871,7 +3871,7 @@  discard block
 block discarded – undo
3871 3871
     protected function _get_mt_tabs($tab_array)
3872 3872
     {
3873 3873
         $tab_array = (array) $tab_array;
3874
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3874
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3875 3875
         $tabs      = '';
3876 3876
 
3877 3877
         foreach ($tab_array as $tab) {
@@ -3899,19 +3899,19 @@  discard block
 block discarded – undo
3899 3899
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3900 3900
 
3901 3901
 
3902
-        if (! empty($fields)) {
3902
+        if ( ! empty($fields)) {
3903 3903
             $existing_settings = $messenger->get_existing_admin_settings();
3904 3904
 
3905 3905
             foreach ($fields as $field_name => $field_props) {
3906
-                $field_id                         = $messenger->name . '-' . $field_name;
3907
-                $template_form_field[ $field_id ] = [
3908
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3906
+                $field_id                         = $messenger->name.'-'.$field_name;
3907
+                $template_form_field[$field_id] = [
3908
+                    'name'       => 'messenger_settings['.$field_id.']',
3909 3909
                     'label'      => $field_props['label'],
3910 3910
                     'input'      => $field_props['field_type'],
3911 3911
                     'type'       => $field_props['value_type'],
3912 3912
                     'required'   => $field_props['required'],
3913 3913
                     'validation' => $field_props['validation'],
3914
-                    'value'      => $existing_settings[ $field_id ] ?? $field_props['default'],
3914
+                    'value'      => $existing_settings[$field_id] ?? $field_props['default'],
3915 3915
                     'css_class'  => '',
3916 3916
                     'format'     => $field_props['format'],
3917 3917
                 ];
@@ -3924,20 +3924,20 @@  discard block
 block discarded – undo
3924 3924
 
3925 3925
         // we also need some hidden fields
3926 3926
         $settings_template_args['hidden_fields'] = [
3927
-            'messenger_settings[messenger]' . $messenger->name => [
3927
+            'messenger_settings[messenger]'.$messenger->name => [
3928 3928
                 'type'  => 'hidden',
3929 3929
                 'value' => $messenger->name,
3930 3930
             ],
3931
-            'type' . $messenger->name                          => [
3931
+            'type'.$messenger->name                          => [
3932 3932
                 'type'  => 'hidden',
3933 3933
                 'value' => 'messenger',
3934 3934
             ],
3935 3935
         ];
3936 3936
 
3937 3937
         // make sure any active message types that are existing are included in the hidden fields
3938
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3939
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3940
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3938
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3939
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3940
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3941 3941
                     'type'  => 'hidden',
3942 3942
                     'value' => $mt,
3943 3943
                 ];
@@ -3947,7 +3947,7 @@  discard block
 block discarded – undo
3947 3947
             $settings_template_args['hidden_fields'],
3948 3948
             'array'
3949 3949
         );
3950
-        $active                                  =
3950
+        $active =
3951 3951
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3952 3952
 
3953 3953
         $settings_template_args['messenger']           = $messenger->name;
@@ -3967,9 +3967,9 @@  discard block
 block discarded – undo
3967 3967
 
3968 3968
 
3969 3969
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3970
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3970
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3971 3971
         $settings_template_args['on_off_status'] = $active;
3972
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3972
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3973 3973
         return EEH_Template::display_template(
3974 3974
             $template,
3975 3975
             $settings_template_args,
@@ -3994,7 +3994,7 @@  discard block
 block discarded – undo
3994 3994
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3995 3995
         // let's check that we have required data
3996 3996
 
3997
-        if (! $this->_active_messenger_name) {
3997
+        if ( ! $this->_active_messenger_name) {
3998 3998
             EE_Error::add_error(
3999 3999
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4000 4000
                 __FILE__,
@@ -4012,7 +4012,7 @@  discard block
 block discarded – undo
4012 4012
 
4013 4013
 
4014 4014
         $status = $this->request->getRequestParam('status');
4015
-        if (! $status) {
4015
+        if ( ! $status) {
4016 4016
             EE_Error::add_error(
4017 4017
                 esc_html__(
4018 4018
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4069,7 +4069,7 @@  discard block
 block discarded – undo
4069 4069
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4070 4070
 
4071 4071
         // let's make sure we have the necessary data
4072
-        if (! $this->_active_message_type_name) {
4072
+        if ( ! $this->_active_message_type_name) {
4073 4073
             EE_Error::add_error(
4074 4074
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4075 4075
                 __FILE__,
@@ -4079,7 +4079,7 @@  discard block
 block discarded – undo
4079 4079
             $success = false;
4080 4080
         }
4081 4081
 
4082
-        if (! $this->_active_messenger_name) {
4082
+        if ( ! $this->_active_messenger_name) {
4083 4083
             EE_Error::add_error(
4084 4084
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4085 4085
                 __FILE__,
@@ -4090,7 +4090,7 @@  discard block
 block discarded – undo
4090 4090
         }
4091 4091
 
4092 4092
         $status = $this->request->getRequestParam('status');
4093
-        if (! $status) {
4093
+        if ( ! $status) {
4094 4094
             EE_Error::add_error(
4095 4095
                 esc_html__(
4096 4096
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4302,7 +4302,7 @@  discard block
 block discarded – undo
4302 4302
         EE_Message_Type $message_type = null
4303 4303
     ) {
4304 4304
         // if $messenger isn't a valid messenger object then get out.
4305
-        if (! $messenger instanceof EE_Messenger) {
4305
+        if ( ! $messenger instanceof EE_Messenger) {
4306 4306
             EE_Error::add_error(
4307 4307
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4308 4308
                 __FILE__,
@@ -4356,7 +4356,7 @@  discard block
 block discarded – undo
4356 4356
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4357 4357
             // in which case we just give a success message for the messenger being successfully activated.
4358 4358
         } else {
4359
-            if (! $messenger->get_default_message_types()) {
4359
+            if ( ! $messenger->get_default_message_types()) {
4360 4360
                 // messenger doesn't have any default message types so still a success.
4361 4361
                 EE_Error::add_success(
4362 4362
                     sprintf(
@@ -4412,7 +4412,7 @@  discard block
 block discarded – undo
4412 4412
         EE_Error::overwrite_success();
4413 4413
 
4414 4414
         // if $messenger isn't a valid messenger object then get out.
4415
-        if (! $messenger instanceof EE_Messenger) {
4415
+        if ( ! $messenger instanceof EE_Messenger) {
4416 4416
             EE_Error::add_error(
4417 4417
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4418 4418
                 __FILE__,
@@ -4482,7 +4482,7 @@  discard block
 block discarded – undo
4482 4482
      */
4483 4483
     public function update_mt_form()
4484 4484
     {
4485
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4485
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4486 4486
             EE_Error::add_error(
4487 4487
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4488 4488
                 __FILE__,
@@ -4493,7 +4493,7 @@  discard block
 block discarded – undo
4493 4493
         }
4494 4494
 
4495 4495
         $message_types = $this->get_installed_message_types();
4496
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4496
+        $message_type  = $message_types[$this->_active_message_type_name];
4497 4497
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4498 4498
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4499 4499
 
@@ -4512,7 +4512,7 @@  discard block
 block discarded – undo
4512 4512
     public function save_settings()
4513 4513
     {
4514 4514
         $type = $this->request->getRequestParam('type');
4515
-        if (! $type) {
4515
+        if ( ! $type) {
4516 4516
             EE_Error::add_error(
4517 4517
                 esc_html__(
4518 4518
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.